annotate scn2k/scn2k_cmd.cc @ 57:6d9146f56ccf

* Move some opcodes * Merge last changes from xclannad
author Thibaut GIRKA <thib@sitedethib.com>
date Sat, 14 Nov 2009 23:31:51 +0100
parents d7cde171a1de
children 3b1593186f12
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
223b71206888 Initial import
thib
parents:
diff changeset
1 /*
223b71206888 Initial import
thib
parents:
diff changeset
2 * Copyright (c) 2004-2006 Kazunori "jagarl" Ueno
223b71206888 Initial import
thib
parents:
diff changeset
3 * All rights reserved.
223b71206888 Initial import
thib
parents:
diff changeset
4 *
223b71206888 Initial import
thib
parents:
diff changeset
5 * Redistribution and use in source and binary forms, with or without
223b71206888 Initial import
thib
parents:
diff changeset
6 * modification, are permitted provided that the following conditions
223b71206888 Initial import
thib
parents:
diff changeset
7 * are met:
223b71206888 Initial import
thib
parents:
diff changeset
8 * 1. Redistributions of source code must retain the above copyright
223b71206888 Initial import
thib
parents:
diff changeset
9 * notice, this list of conditions and the following disclaimer.
223b71206888 Initial import
thib
parents:
diff changeset
10 * 2. Redistributions in binary form must reproduce the above copyright
223b71206888 Initial import
thib
parents:
diff changeset
11 * notice, this list of conditions and the following disclaimer in the
223b71206888 Initial import
thib
parents:
diff changeset
12 * documentation and/or other materials provided with the distribution.
223b71206888 Initial import
thib
parents:
diff changeset
13 * 3. The name of the author may not be used to endorse or promote products
223b71206888 Initial import
thib
parents:
diff changeset
14 * derived from this software without specific prior written permission.
223b71206888 Initial import
thib
parents:
diff changeset
15 *
223b71206888 Initial import
thib
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
223b71206888 Initial import
thib
parents:
diff changeset
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
223b71206888 Initial import
thib
parents:
diff changeset
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
223b71206888 Initial import
thib
parents:
diff changeset
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
223b71206888 Initial import
thib
parents:
diff changeset
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
223b71206888 Initial import
thib
parents:
diff changeset
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
223b71206888 Initial import
thib
parents:
diff changeset
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
223b71206888 Initial import
thib
parents:
diff changeset
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
223b71206888 Initial import
thib
parents:
diff changeset
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
223b71206888 Initial import
thib
parents:
diff changeset
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
223b71206888 Initial import
thib
parents:
diff changeset
26 */
223b71206888 Initial import
thib
parents:
diff changeset
27
223b71206888 Initial import
thib
parents:
diff changeset
28
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
29 #include "scn2k.h"
0
223b71206888 Initial import
thib
parents:
diff changeset
30
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
31 #include <stdlib.h>
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
32 #include <stdarg.h>
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
33 #include <stdio.h>
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
34 #include <string.h>
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
35 #include <string>
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
36 #include "system/file.h"
0
223b71206888 Initial import
thib
parents:
diff changeset
37
223b71206888 Initial import
thib
parents:
diff changeset
38 using namespace std;
223b71206888 Initial import
thib
parents:
diff changeset
39
223b71206888 Initial import
thib
parents:
diff changeset
40
223b71206888 Initial import
thib
parents:
diff changeset
41 // #define SCN_DUMP
223b71206888 Initial import
thib
parents:
diff changeset
42 /* Ãí°ÕÅÀ¡§ @@@ ¤Çɽµ­ */
223b71206888 Initial import
thib
parents:
diff changeset
43
223b71206888 Initial import
thib
parents:
diff changeset
44
223b71206888 Initial import
thib
parents:
diff changeset
45
223b71206888 Initial import
thib
parents:
diff changeset
46 //bool debug_flag = true;
223b71206888 Initial import
thib
parents:
diff changeset
47 bool debug_flag = false;
223b71206888 Initial import
thib
parents:
diff changeset
48 void dprintf(const char* fmt, ...) {
223b71206888 Initial import
thib
parents:
diff changeset
49 if (debug_flag) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
50 va_list ap;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
51 va_start(ap, fmt);
0
223b71206888 Initial import
thib
parents:
diff changeset
52 vprintf(fmt, ap);
223b71206888 Initial import
thib
parents:
diff changeset
53 va_end(ap);
223b71206888 Initial import
thib
parents:
diff changeset
54 }
223b71206888 Initial import
thib
parents:
diff changeset
55 }
223b71206888 Initial import
thib
parents:
diff changeset
56
223b71206888 Initial import
thib
parents:
diff changeset
57
223b71206888 Initial import
thib
parents:
diff changeset
58 void eprintf(const char* fmt, ...) {
223b71206888 Initial import
thib
parents:
diff changeset
59 va_list ap; va_start(ap, fmt);
223b71206888 Initial import
thib
parents:
diff changeset
60 // vprintf(fmt, ap);
223b71206888 Initial import
thib
parents:
diff changeset
61 va_end(ap);
223b71206888 Initial import
thib
parents:
diff changeset
62 }
223b71206888 Initial import
thib
parents:
diff changeset
63
223b71206888 Initial import
thib
parents:
diff changeset
64 /**************************************************************
223b71206888 Initial import
thib
parents:
diff changeset
65 ** Flag
223b71206888 Initial import
thib
parents:
diff changeset
66 */
223b71206888 Initial import
thib
parents:
diff changeset
67
223b71206888 Initial import
thib
parents:
diff changeset
68 Flags::Flags(void) {
223b71206888 Initial import
thib
parents:
diff changeset
69 int i,j;
223b71206888 Initial import
thib
parents:
diff changeset
70 for (i=0; i<=TYPE_VARMAX; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
71 for (j=0; j<2000; j++) {
223b71206888 Initial import
thib
parents:
diff changeset
72 var[i][j] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
73 }
223b71206888 Initial import
thib
parents:
diff changeset
74 }
223b71206888 Initial import
thib
parents:
diff changeset
75 sys = 0;
223b71206888 Initial import
thib
parents:
diff changeset
76 }
223b71206888 Initial import
thib
parents:
diff changeset
77
223b71206888 Initial import
thib
parents:
diff changeset
78 bool Flags::IsInt(int type) const {
223b71206888 Initial import
thib
parents:
diff changeset
79 int v = type % 26;
43
01aa5ddf7dc8 A lot of very minor improvements (deleted some unused variables, and other things like that...)
thib
parents: 29
diff changeset
80 return (v >= 0 && v < 7) || v == 25;
0
223b71206888 Initial import
thib
parents:
diff changeset
81 }
223b71206888 Initial import
thib
parents:
diff changeset
82
223b71206888 Initial import
thib
parents:
diff changeset
83 int Flags::MaxIndex(int type) const {
223b71206888 Initial import
thib
parents:
diff changeset
84 switch (type / 26) {
223b71206888 Initial import
thib
parents:
diff changeset
85 case 1:
223b71206888 Initial import
thib
parents:
diff changeset
86 return 63999;
223b71206888 Initial import
thib
parents:
diff changeset
87 case 2:
223b71206888 Initial import
thib
parents:
diff changeset
88 return 31999;
223b71206888 Initial import
thib
parents:
diff changeset
89 case 3:
223b71206888 Initial import
thib
parents:
diff changeset
90 return 15999;
223b71206888 Initial import
thib
parents:
diff changeset
91 case 4:
223b71206888 Initial import
thib
parents:
diff changeset
92 return 7999;
223b71206888 Initial import
thib
parents:
diff changeset
93 default:
223b71206888 Initial import
thib
parents:
diff changeset
94 return 1999;
223b71206888 Initial import
thib
parents:
diff changeset
95 }
223b71206888 Initial import
thib
parents:
diff changeset
96 }
223b71206888 Initial import
thib
parents:
diff changeset
97
223b71206888 Initial import
thib
parents:
diff changeset
98 int Flags::operator()() const {
223b71206888 Initial import
thib
parents:
diff changeset
99 return sys; // rand() % 10000;
223b71206888 Initial import
thib
parents:
diff changeset
100 }
223b71206888 Initial import
thib
parents:
diff changeset
101
223b71206888 Initial import
thib
parents:
diff changeset
102 int Flags::operator() (VarInfo info) const {
223b71206888 Initial import
thib
parents:
diff changeset
103 return Get(info.type, info.number);
223b71206888 Initial import
thib
parents:
diff changeset
104 }
223b71206888 Initial import
thib
parents:
diff changeset
105
223b71206888 Initial import
thib
parents:
diff changeset
106 int Flags::Get(int type, int number) const {
223b71206888 Initial import
thib
parents:
diff changeset
107 int index = type % 26;
223b71206888 Initial import
thib
parents:
diff changeset
108 type /= 26;
223b71206888 Initial import
thib
parents:
diff changeset
109 if (index == 25) {
223b71206888 Initial import
thib
parents:
diff changeset
110 if (var[7][number] != 0) return var[7][number];
223b71206888 Initial import
thib
parents:
diff changeset
111 if (cgm_data.find(number) == cgm_data.end()) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
112 else return 1;
223b71206888 Initial import
thib
parents:
diff changeset
113 }
223b71206888 Initial import
thib
parents:
diff changeset
114 if (index == 10) index = 8;
223b71206888 Initial import
thib
parents:
diff changeset
115 if (index == 11) index = 9;
223b71206888 Initial import
thib
parents:
diff changeset
116 if (index > TYPE_VARMAX || uint(type) > 4) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
117 if (type == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
118 // A[]..G[], Z[] ¤òľ¤ËÆɤà
223b71206888 Initial import
thib
parents:
diff changeset
119 if (uint(number) >= 2000) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
120 return var[index][number];
223b71206888 Initial import
thib
parents:
diff changeset
121 } else {
223b71206888 Initial import
thib
parents:
diff changeset
122 // Ab[]..G4b[], Z8b[] ¤Ê¤É¤òÆɤà
223b71206888 Initial import
thib
parents:
diff changeset
123 int factor = 1 << (type - 1);
223b71206888 Initial import
thib
parents:
diff changeset
124 int eltsize = 32 / factor;
223b71206888 Initial import
thib
parents:
diff changeset
125 if (uint(number) >= (64000 / factor)) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
126 return (var[index][number / eltsize] >> ((number % eltsize) * factor)) & ((1 << factor) - 1);
223b71206888 Initial import
thib
parents:
diff changeset
127 }
223b71206888 Initial import
thib
parents:
diff changeset
128 }
223b71206888 Initial import
thib
parents:
diff changeset
129
223b71206888 Initial import
thib
parents:
diff changeset
130 void Flags::Set(VarInfo info, int value) {
223b71206888 Initial import
thib
parents:
diff changeset
131 int type = info.type / 26;
223b71206888 Initial import
thib
parents:
diff changeset
132 int index = info.type % 26;
223b71206888 Initial import
thib
parents:
diff changeset
133 if (index == 25) {
223b71206888 Initial import
thib
parents:
diff changeset
134 if (uint(info.number) >= 2000) return;
223b71206888 Initial import
thib
parents:
diff changeset
135 if (value == 0)
223b71206888 Initial import
thib
parents:
diff changeset
136 cgm_data.erase(info.number);
223b71206888 Initial import
thib
parents:
diff changeset
137 else
223b71206888 Initial import
thib
parents:
diff changeset
138 cgm_data.insert(info.number);
223b71206888 Initial import
thib
parents:
diff changeset
139 index = 7;
223b71206888 Initial import
thib
parents:
diff changeset
140 }
223b71206888 Initial import
thib
parents:
diff changeset
141 if (index == 10) index = 8;
223b71206888 Initial import
thib
parents:
diff changeset
142 if (index == 11) index = 9;
223b71206888 Initial import
thib
parents:
diff changeset
143 if (index < 0 || index > TYPE_VARMAX) {
223b71206888 Initial import
thib
parents:
diff changeset
144 fprintf(stderr,"Error: invalid access to Var<%d>[%d]\n",info.type,info.number);
223b71206888 Initial import
thib
parents:
diff changeset
145 }
223b71206888 Initial import
thib
parents:
diff changeset
146 if (type == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
147 // A[]..G[], Z[] ¤òľ¤Ë½ñ¤¯
223b71206888 Initial import
thib
parents:
diff changeset
148 if (uint(info.number) >= 2000) return;
223b71206888 Initial import
thib
parents:
diff changeset
149 var[index][info.number] = value;
223b71206888 Initial import
thib
parents:
diff changeset
150 } else {
223b71206888 Initial import
thib
parents:
diff changeset
151 // Ab[]..G4b[], Z8b[] ¤Ê¤É¤ò½ñ¤¯
223b71206888 Initial import
thib
parents:
diff changeset
152 int factor = 1 << (type - 1);
223b71206888 Initial import
thib
parents:
diff changeset
153 int eltsize = 32 / factor;
223b71206888 Initial import
thib
parents:
diff changeset
154 int eltmask = (1 << factor) - 1;
223b71206888 Initial import
thib
parents:
diff changeset
155 int shift = (info.number % eltsize) * factor;
223b71206888 Initial import
thib
parents:
diff changeset
156 if (uint(info.number) >= (64000 / factor)) return;
223b71206888 Initial import
thib
parents:
diff changeset
157 var[index][info.number / eltsize] =
223b71206888 Initial import
thib
parents:
diff changeset
158 (var[index][info.number / eltsize] & ~(eltmask << shift))
223b71206888 Initial import
thib
parents:
diff changeset
159 | (value & eltmask) << shift;
223b71206888 Initial import
thib
parents:
diff changeset
160 }
223b71206888 Initial import
thib
parents:
diff changeset
161 }
223b71206888 Initial import
thib
parents:
diff changeset
162
223b71206888 Initial import
thib
parents:
diff changeset
163 void Flags::SetSys(int value) {
223b71206888 Initial import
thib
parents:
diff changeset
164 sys = value;
223b71206888 Initial import
thib
parents:
diff changeset
165 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
166
0
223b71206888 Initial import
thib
parents:
diff changeset
167 void Flags::SetStr(VarInfo info, string val) {
223b71206888 Initial import
thib
parents:
diff changeset
168 switch(info.type) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
169 case TYPE_VARLOCSTR:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
170 if (info.number >= 3) return;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
171 loc_str[info.number] = val;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
172 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
173 case TYPE_VARSYSSTR:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
174 if (info.number >= 2000) return;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
175 sys_str[info.number] = val;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
176 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
177 case TYPE_VARSTR:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
178 if (info.number >= 2000) return;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
179 str[info.number] = val;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
180 break;
0
223b71206888 Initial import
thib
parents:
diff changeset
181 }
223b71206888 Initial import
thib
parents:
diff changeset
182 return;
223b71206888 Initial import
thib
parents:
diff changeset
183 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
184
0
223b71206888 Initial import
thib
parents:
diff changeset
185 void Flags::Str(int type, unsigned int number, char* buf, int sz) const {
223b71206888 Initial import
thib
parents:
diff changeset
186 if (sz <= 0) return;
223b71206888 Initial import
thib
parents:
diff changeset
187 buf[0] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
188 const string* sptr;
223b71206888 Initial import
thib
parents:
diff changeset
189 switch(type) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
190 case TYPE_VARLOCSTR:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
191 if (number >= 3) return;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
192 sptr = &loc_str[number];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
193 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
194 case TYPE_VARSYSSTR:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
195 if (number >= 2000) return;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
196 sptr = &sys_str[number];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
197 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
198 case TYPE_VARSTR:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
199 if (number >= 2000) return;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
200 sptr = &str[number];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
201 break;
0
223b71206888 Initial import
thib
parents:
diff changeset
202 }
223b71206888 Initial import
thib
parents:
diff changeset
203
223b71206888 Initial import
thib
parents:
diff changeset
204 int len = sptr->length();
223b71206888 Initial import
thib
parents:
diff changeset
205 if (sz-1 > len) sz = len;
223b71206888 Initial import
thib
parents:
diff changeset
206 sptr->copy(buf, sz, 0);
223b71206888 Initial import
thib
parents:
diff changeset
207 buf[sz] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
208 return;
223b71206888 Initial import
thib
parents:
diff changeset
209 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
210
0
223b71206888 Initial import
thib
parents:
diff changeset
211 string Flags::Str(int type, unsigned int number) const {
223b71206888 Initial import
thib
parents:
diff changeset
212 switch(type) {
223b71206888 Initial import
thib
parents:
diff changeset
213 case TYPE_VARLOCSTR:
223b71206888 Initial import
thib
parents:
diff changeset
214 if (number >= 3) return "";
223b71206888 Initial import
thib
parents:
diff changeset
215 return loc_str[number];
223b71206888 Initial import
thib
parents:
diff changeset
216 case TYPE_VARSYSSTR:
223b71206888 Initial import
thib
parents:
diff changeset
217 if (number >= 2000) return "";
223b71206888 Initial import
thib
parents:
diff changeset
218 return sys_str[number];
223b71206888 Initial import
thib
parents:
diff changeset
219 case TYPE_VARSTR:
223b71206888 Initial import
thib
parents:
diff changeset
220 if (number >= 2000) return "";
223b71206888 Initial import
thib
parents:
diff changeset
221 return str[number];
223b71206888 Initial import
thib
parents:
diff changeset
222 }
223b71206888 Initial import
thib
parents:
diff changeset
223 return "";
223b71206888 Initial import
thib
parents:
diff changeset
224 }
223b71206888 Initial import
thib
parents:
diff changeset
225
223b71206888 Initial import
thib
parents:
diff changeset
226 void Flags::Save(string& save) {
223b71206888 Initial import
thib
parents:
diff changeset
227 char buf[1024];
223b71206888 Initial import
thib
parents:
diff changeset
228 save = "\n[Flags]\n";
223b71206888 Initial import
thib
parents:
diff changeset
229 int i,j;
223b71206888 Initial import
thib
parents:
diff changeset
230 for (i=0; i<=TYPE_NONSYSVARMAX; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
231 for (j=0; j<2000; j++) {
223b71206888 Initial import
thib
parents:
diff changeset
232 if (var[i][j] != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
233 sprintf(buf, "V<%d>[%04d]=%d\n",i,j,var[i][j]);
223b71206888 Initial import
thib
parents:
diff changeset
234 save += buf;
223b71206888 Initial import
thib
parents:
diff changeset
235 }
223b71206888 Initial import
thib
parents:
diff changeset
236 }
223b71206888 Initial import
thib
parents:
diff changeset
237 }
223b71206888 Initial import
thib
parents:
diff changeset
238 for (j=0; j<2000; j++) {
223b71206888 Initial import
thib
parents:
diff changeset
239 if (str[j].length() != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
240 sprintf(buf, "V<C>[%04d]=%s\n", j, str[j].c_str());
223b71206888 Initial import
thib
parents:
diff changeset
241 save += buf;
223b71206888 Initial import
thib
parents:
diff changeset
242 }
223b71206888 Initial import
thib
parents:
diff changeset
243 }
223b71206888 Initial import
thib
parents:
diff changeset
244 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
245
0
223b71206888 Initial import
thib
parents:
diff changeset
246 void Flags::Load(const char* save) {
223b71206888 Initial import
thib
parents:
diff changeset
247 int i,j;
223b71206888 Initial import
thib
parents:
diff changeset
248 for (i=0; i<=TYPE_NONSYSVARMAX; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
249 for (j=0; j<2000; j++) {
223b71206888 Initial import
thib
parents:
diff changeset
250 var[i][j] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
251 }
223b71206888 Initial import
thib
parents:
diff changeset
252 }
223b71206888 Initial import
thib
parents:
diff changeset
253 sys = 0;
223b71206888 Initial import
thib
parents:
diff changeset
254 for (j=0; j<2000; j++) {
223b71206888 Initial import
thib
parents:
diff changeset
255 str[j] = "";
223b71206888 Initial import
thib
parents:
diff changeset
256 }
223b71206888 Initial import
thib
parents:
diff changeset
257
223b71206888 Initial import
thib
parents:
diff changeset
258 save = strstr(save, "\n[Flags]\n");
223b71206888 Initial import
thib
parents:
diff changeset
259
223b71206888 Initial import
thib
parents:
diff changeset
260 if (save) {
223b71206888 Initial import
thib
parents:
diff changeset
261 save += strlen("\n[Flags]\n");
223b71206888 Initial import
thib
parents:
diff changeset
262 do {
223b71206888 Initial import
thib
parents:
diff changeset
263 if (save[0] == '[') break; // next section
223b71206888 Initial import
thib
parents:
diff changeset
264 if (strncmp(save, "V<",2) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
265 if (strncmp(save, "V<C>[",5) == 0) { // string
223b71206888 Initial import
thib
parents:
diff changeset
266 char buf[1024];
223b71206888 Initial import
thib
parents:
diff changeset
267 int n;
223b71206888 Initial import
thib
parents:
diff changeset
268 if (sscanf(save, "V<C>[%04d]=",&n) == 1) {
223b71206888 Initial import
thib
parents:
diff changeset
269 char* s = strchr(save, '=');
223b71206888 Initial import
thib
parents:
diff changeset
270 s++;
223b71206888 Initial import
thib
parents:
diff changeset
271 char* send = strchr(s, '\n');
223b71206888 Initial import
thib
parents:
diff changeset
272 int slen = send - s;
223b71206888 Initial import
thib
parents:
diff changeset
273 strncpy(buf, s, slen);
223b71206888 Initial import
thib
parents:
diff changeset
274 buf[slen] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
275 if (n >= 0 && n < 2000) str[n] = buf;
223b71206888 Initial import
thib
parents:
diff changeset
276 }
223b71206888 Initial import
thib
parents:
diff changeset
277 } else if (save[2] >= '0' && save[2] <= '9') {
223b71206888 Initial import
thib
parents:
diff changeset
278 int c,n,v;
223b71206888 Initial import
thib
parents:
diff changeset
279 if (sscanf(save, "V<%d>[%04d]=%d\n",&c,&n,&v) == 3) {
223b71206888 Initial import
thib
parents:
diff changeset
280 if (c >= 0 && c <= TYPE_NONSYSVARMAX && n >= 0 && n < 2000)
223b71206888 Initial import
thib
parents:
diff changeset
281 var[c][n] = v;
223b71206888 Initial import
thib
parents:
diff changeset
282 }
223b71206888 Initial import
thib
parents:
diff changeset
283 }
223b71206888 Initial import
thib
parents:
diff changeset
284 }
223b71206888 Initial import
thib
parents:
diff changeset
285 save = strchr(save, '\n');
223b71206888 Initial import
thib
parents:
diff changeset
286 if (save) save++;
223b71206888 Initial import
thib
parents:
diff changeset
287 } while (save);
223b71206888 Initial import
thib
parents:
diff changeset
288 }
223b71206888 Initial import
thib
parents:
diff changeset
289 }
223b71206888 Initial import
thib
parents:
diff changeset
290
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
291 void Flags::SaveSys(string& save) { //FIXME: see how to factorize with Save
0
223b71206888 Initial import
thib
parents:
diff changeset
292 char buf[1024];
223b71206888 Initial import
thib
parents:
diff changeset
293 int j;
223b71206888 Initial import
thib
parents:
diff changeset
294 save = "\n[Flags]\n";
223b71206888 Initial import
thib
parents:
diff changeset
295 for (j=0; j<2000; j++) {
223b71206888 Initial import
thib
parents:
diff changeset
296 if (var[6][j] != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
297 sprintf(buf, "V<6>[%04d]=%d\n",j,var[6][j]);
223b71206888 Initial import
thib
parents:
diff changeset
298 save += buf;
223b71206888 Initial import
thib
parents:
diff changeset
299 }
223b71206888 Initial import
thib
parents:
diff changeset
300 }
223b71206888 Initial import
thib
parents:
diff changeset
301 for (j=0; j<2000; j++) {
223b71206888 Initial import
thib
parents:
diff changeset
302 if (var[7][j] != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
303 sprintf(buf, "V<25>[%04d]=%d\n",j,var[7][j]);
223b71206888 Initial import
thib
parents:
diff changeset
304 save += buf;
223b71206888 Initial import
thib
parents:
diff changeset
305 }
223b71206888 Initial import
thib
parents:
diff changeset
306 }
223b71206888 Initial import
thib
parents:
diff changeset
307 for (j=0; j<2000; j++) {
223b71206888 Initial import
thib
parents:
diff changeset
308 if (sys_str[j].length() != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
309 sprintf(buf, "V<M>[%04d]=%s\n", j, sys_str[j].c_str());
223b71206888 Initial import
thib
parents:
diff changeset
310 save += buf;
223b71206888 Initial import
thib
parents:
diff changeset
311 }
223b71206888 Initial import
thib
parents:
diff changeset
312 }
223b71206888 Initial import
thib
parents:
diff changeset
313 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
314
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
315 void Flags::LoadSys(const char* save) { //FIXME: Same as Save and SaveSys
0
223b71206888 Initial import
thib
parents:
diff changeset
316 int i,j;
223b71206888 Initial import
thib
parents:
diff changeset
317 for (i=6; i<=7; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
318 for (j=0; j<2000; j++) {
223b71206888 Initial import
thib
parents:
diff changeset
319 var[i][j] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
320 }
223b71206888 Initial import
thib
parents:
diff changeset
321 }
223b71206888 Initial import
thib
parents:
diff changeset
322 for (j=0; j<2000; j++) {
223b71206888 Initial import
thib
parents:
diff changeset
323 sys_str[j] = "";
223b71206888 Initial import
thib
parents:
diff changeset
324 }
223b71206888 Initial import
thib
parents:
diff changeset
325 sys = 0;
223b71206888 Initial import
thib
parents:
diff changeset
326
223b71206888 Initial import
thib
parents:
diff changeset
327 save = strstr(save, "\n[Flags]\n");
223b71206888 Initial import
thib
parents:
diff changeset
328
223b71206888 Initial import
thib
parents:
diff changeset
329 if (save) {
223b71206888 Initial import
thib
parents:
diff changeset
330 save += strlen("\n[Flags]\n");
223b71206888 Initial import
thib
parents:
diff changeset
331 do {
223b71206888 Initial import
thib
parents:
diff changeset
332 if (save[0] == '[') break; // next section
223b71206888 Initial import
thib
parents:
diff changeset
333 if (strncmp(save, "V<",2) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
334 if (strncmp(save, "V<M>[",5) == 0) { // string
223b71206888 Initial import
thib
parents:
diff changeset
335 char buf[1024];
223b71206888 Initial import
thib
parents:
diff changeset
336 int n;
223b71206888 Initial import
thib
parents:
diff changeset
337 if (sscanf(save, "V<M>[%04d]=",&n) == 1) {
223b71206888 Initial import
thib
parents:
diff changeset
338 char* s = strchr(save, '=');
223b71206888 Initial import
thib
parents:
diff changeset
339 s++;
223b71206888 Initial import
thib
parents:
diff changeset
340 char* send = strchr(s, '\n');
223b71206888 Initial import
thib
parents:
diff changeset
341 int slen = send - s;
223b71206888 Initial import
thib
parents:
diff changeset
342 strncpy(buf, s, slen);
223b71206888 Initial import
thib
parents:
diff changeset
343 buf[slen] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
344 if (n >= 0 && n < 2000) sys_str[n] = buf;
223b71206888 Initial import
thib
parents:
diff changeset
345 }
223b71206888 Initial import
thib
parents:
diff changeset
346 } else if (save[2] >= '0' && save[2] <= '9') {
223b71206888 Initial import
thib
parents:
diff changeset
347 int c,n,v;
223b71206888 Initial import
thib
parents:
diff changeset
348 if (sscanf(save, "V<%d>[%04d]=%d\n",&c,&n,&v) == 3) {
223b71206888 Initial import
thib
parents:
diff changeset
349 if (c == 6 && n >= 0 && n < 2000)
223b71206888 Initial import
thib
parents:
diff changeset
350 var[6][n] = v;
223b71206888 Initial import
thib
parents:
diff changeset
351 else if (c == 25 && n >= 0 && n < 2000)
223b71206888 Initial import
thib
parents:
diff changeset
352 var[7][n] = v;
223b71206888 Initial import
thib
parents:
diff changeset
353 }
223b71206888 Initial import
thib
parents:
diff changeset
354 }
223b71206888 Initial import
thib
parents:
diff changeset
355 }
223b71206888 Initial import
thib
parents:
diff changeset
356 save = strchr(save, '\n');
223b71206888 Initial import
thib
parents:
diff changeset
357 if (save) save++;
223b71206888 Initial import
thib
parents:
diff changeset
358 } while (save);
223b71206888 Initial import
thib
parents:
diff changeset
359 }
223b71206888 Initial import
thib
parents:
diff changeset
360 }
223b71206888 Initial import
thib
parents:
diff changeset
361
223b71206888 Initial import
thib
parents:
diff changeset
362 bool Flags::Exec(Cmd& cmd) {
223b71206888 Initial import
thib
parents:
diff changeset
363 if (cmd.cmd_type == CMD_FLAGS) { // ÂåÆþ±é»»
223b71206888 Initial import
thib
parents:
diff changeset
364 if (cmd.args.size() != 2) return false;
223b71206888 Initial import
thib
parents:
diff changeset
365 Set(cmd.args[0], cmd.args[1].value);
223b71206888 Initial import
thib
parents:
diff changeset
366 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
367 return true;
223b71206888 Initial import
thib
parents:
diff changeset
368 }
223b71206888 Initial import
thib
parents:
diff changeset
369 if (cmd.cmd1 == 1 && cmd.cmd2 == 0x0a) { // ʸ»úÎó±é»»
223b71206888 Initial import
thib
parents:
diff changeset
370 VarInfo arg1 = cmd.args[0];
223b71206888 Initial import
thib
parents:
diff changeset
371 switch(cmd.cmd3) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
372 case 0:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
373 if (cmd.cmd4 == 0) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
374 SetStr(arg1, cmd.Str(cmd.args[1]));
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
375 } else if (cmd.cmd4 == 1) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
376 string s = cmd.Str(cmd.args[1]);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
377 const char* sc = s.c_str();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
378 int len = cmd.args[2].value;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
379 int i;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
380 for (i=0; i < sc[i] && len != 0; i++, len--) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
381 if (sc[i]<0 && sc[i+1]!=0) i++;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
382 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
383 s.erase(i); // Á´³Ñ¤Ç len ʸ»ú¤Þ¤ÇÀÚ¤êµÍ¤á¤ë
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
384 SetStr(arg1, s);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
385 // fprintf(stderr,"Set[%d,%d]<-%s\n",arg1.type,arg1.number,s.c_str());
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
386 } else break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
387 cmd.clear();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
388 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
389 case 1:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
390 if (cmd.cmd4 == 0) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
391 SetStr(arg1, "");
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
392 cmd.clear();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
393 } else if (cmd.cmd4 == 1) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
394 // Îΰè»ØÄê¤Çʸ»úÎ󥯥ꥢ
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
395 VarInfo v1 = cmd.args[0];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
396 VarInfo v2 = cmd.args[1];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
397 eprintf("memclear(str). Var[%d]<%d> - Var[%d]<%d>\n",v1.type, v1.number, v2.type, v2.number);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
398 if (v1.type != v2.type || (v1.type != TYPE_VARSTR && v1.type != TYPE_VARSYSSTR && v1.type != TYPE_VARLOCSTR)) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
399 eprintf(" error: bad args\n");
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
400 } else {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
401 if (v1.number < 0) v1.number = 0;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
402 if (v2.number > 2000) v2.number = 2000;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
403 for (; v1.number <= v2.number; v1.number++) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
404 SetStr(v1, "");
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
405 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
406 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
407 cmd.clear();
0
223b71206888 Initial import
thib
parents:
diff changeset
408 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
409 case 2:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
410 SetStr(arg1, Str(arg1.type,arg1.number) + cmd.Str(cmd.args[1]));
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
411 // fprintf(stderr,"Append[%d,%d]<-%s(%d:%d)\n",arg1.type,arg1.number,Str(arg1.type,arg1.number).c_str(),cmd.args[1].type,cmd.args[1].number);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
412 cmd.clear();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
413 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
414 case 3:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
415 SetSys(strlen(cmd.Str(cmd.args[0])));
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
416 cmd.clear();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
417 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
418 case 4:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
419 { int v = strcmp(cmd.Str(cmd.args[0]), cmd.Str(cmd.args[1]));
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
420 // string s1=cmd.Str(cmd.args[0]);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
421 // string s2=cmd.Str(cmd.args[1]);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
422 // fprintf(stderr,"Cmp %s(%d:%d):%s(%d:%d):%d\n",s1.c_str(),cmd.args[0].type,cmd.args[0].number,s2.c_str(),cmd.args[1].type,cmd.args[1].number,v);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
423 if (v < 0) SetSys(-1);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
424 else if (v > 0) SetSys(1);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
425 else SetSys(0);
0
223b71206888 Initial import
thib
parents:
diff changeset
426 cmd.clear();
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
427 break; }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
428 case 5: // substring, index from left
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
429 case 6: // substring, index from right
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
430 // Á´³ÑÂбþ¤é¤·¤¤
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
431 //FIXME: Make sure it works properly
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
432 { int offset = cmd.args[2].value;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
433 int len = strlen(cmd.Str(cmd.args[1]));
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
434 string str = cmd.Str(cmd.args[1]);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
435 const char* s = str.c_str();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
436 if (cmd.cmd3 == 6) offset = len - offset;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
437 if (offset < 0) offset = 0;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
438 // ÀèƬ N ʸ»ú¤òÆɤßÈô¤Ð¤¹
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
439 int i;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
440 int offset_top = 0;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
441 for (i=0; i<offset && s[offset_top] != 0; i++) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
442 if (s[offset_top] < 0 && s[offset_top+1] != 0) offset_top += 2;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
443 else offset_top += 1;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
444 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
445 if (s[offset_top] == 0) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
446 SetStr(arg1, "");
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
447 } else if (cmd.cmd4 == 0) { // ŤµÀ©¸Â¤Ê¤·
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
448 SetStr(arg1, string(s, offset_top, len-offset_top));
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
449 } else { // cmd.cmd4 == 1
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
450 int slen = cmd.args[3].value;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
451 int offset_end = offset_top;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
452 for (i=0; i<slen && s[offset_end] != 0; i++) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
453 if (s[offset_end] < 0 && s[offset_end]+1 != 0) offset_end += 2;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
454 else offset_end += 1;
0
223b71206888 Initial import
thib
parents:
diff changeset
455 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
456 string result(s, offset_top, offset_end-offset_top);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
457 SetStr(arg1, result);
0
223b71206888 Initial import
thib
parents:
diff changeset
458 }
223b71206888 Initial import
thib
parents:
diff changeset
459 cmd.clear();
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
460 break; }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
461 case 7: {// strlen w/ kanji
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
462 const char* s = cmd.Str(cmd.args[0]); int i;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
463 for (i=0; *s != 0; i++) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
464 if (*s < 0 && s[1] != 0) s += 2;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
465 else s++;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
466 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
467 SetSys(i);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
468 cmd.clear();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
469 break; }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
470 case 8: // ʸ»úÎó¤òÀڤäÆû¤¯¤¹¤ë
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
471 if (cmd.args[1].value <= 0) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
472 SetStr(arg1, "");
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
473 } else if (cmd.args[1].value < strlen(cmd.Str(cmd.args[1]))) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
474 Str(arg1.type,arg1.number).erase(cmd.args[1].value);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
475 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
476 cmd.clear();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
477 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
478 case 0x0e: // ´Á»ú¥â¡¼¥É¤Çitoa
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
479 {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
480 int arg1 = cmd.args[0].value;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
481 string result;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
482 char wc[3]; wc[2]=0;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
483 char buf[20];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
484 if (cmd.cmd4 == 0) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
485 sprintf(buf, "%d", arg1);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
486 } else { // cmd.cmd4 == 1
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
487 char fmt[20];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
488 sprintf(fmt, "%%%dd", cmd.args[2].value);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
489 sprintf(buf, fmt, arg1);
0
223b71206888 Initial import
thib
parents:
diff changeset
490 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
491 int i;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
492 for (i=0; buf[i] != 0; i++) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
493 if (buf[i] == ' ') {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
494 wc[0] = 0x81; // ' ' in SHIFT_JIS
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
495 wc[1] = 0x40;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
496 } else if (buf[i] == '-') {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
497 wc[0] = 0x81; // '-' in SHIFT_JIS
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
498 wc[1] = 0x7c;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
499 } else if (isdigit(buf[i])) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
500 wc[0] = 0x82; // number in SHIFT_JIS
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
501 wc[1] = buf[i] - '0' + 0x4f;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
502 } else {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
503 continue;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
504 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
505 result += wc;
0
223b71206888 Initial import
thib
parents:
diff changeset
506 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
507 SetStr(cmd.args[1], result);
0
223b71206888 Initial import
thib
parents:
diff changeset
508 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
509 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
510 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
511 case 0x0f: case 0x11: // itoa (0x11 ¤ÎÊý¤Ï zero padding ¤¹¤ë¤Ã¤Ý¤¤)
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
512 if (cmd.cmd4 == 0) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
513 int arg1 = cmd.args[0].value;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
514 char buf[1024]; sprintf(buf, "%d", arg1);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
515 SetStr(cmd.args[1], buf);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
516 cmd.clear();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
517 } else if (cmd.cmd4 == 1) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
518 // ´Á»ú(SJIS) : 82 [4f+N]
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
519 // ¤ä¤Ï¤ê´Á»ú¤¸¤ã¤Ê¤¤¡©
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
520 int arg1 = cmd.args[0].value;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
521 char buf[1024]; char fmt[1024];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
522 if (cmd.cmd3 == 0x0f) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
523 sprintf(fmt, "%%%dd",cmd.args[2].value); /* ¶õÇò¤Ç¥Ñ¥Ç¥£¥ó¥° */
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
524 } else {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
525 sprintf(fmt, "%%0%dd",cmd.args[2].value);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
526 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
527 sprintf(buf, fmt, arg1);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
528 SetStr(cmd.args[1], buf);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
529 cmd.clear();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
530 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
531 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
532 case 0x64: // ʸ»úÎó¤Îɽ¼¨ : °ú¿ô¤ò¥Æ¥­¥¹¥È¥¦¥£¥ó¥É¥¦¤Ëɽ¼¨
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
533 if (cmd.cmd4 == 1) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
534 char buf[256];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
535 snprintf(buf, 255, "%d", Get(cmd.args[0].type, cmd.args[0].number));
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
536 cmd.args[0].type = TYPE_STR;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
537 cmd.args[0].value = cmd.AddStr(buf);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
538 cmd.cmd4 = 0;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
539 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
540 cmd.cmd_type = CMD_TEXT;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
541 break;
0
223b71206888 Initial import
thib
parents:
diff changeset
542 }
223b71206888 Initial import
thib
parents:
diff changeset
543 }
223b71206888 Initial import
thib
parents:
diff changeset
544 if (cmd.cmd1 == 1 && cmd.cmd2 == 0x0b) { // ¿ôÃÍÊÑ¿ô±é»»
223b71206888 Initial import
thib
parents:
diff changeset
545 if (cmd.cmd3 == 0 && cmd.cmd4 == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
546 /* Ê£¿ô¤ÎÊÑ¿ô¤ò¥»¥Ã¥È */
223b71206888 Initial import
thib
parents:
diff changeset
547 VarInfo v1 = cmd.args[0];
223b71206888 Initial import
thib
parents:
diff changeset
548 eprintf("set multiple-var Var[%d]<%d> <- ",v1.type, v1.number);
223b71206888 Initial import
thib
parents:
diff changeset
549 int i;
223b71206888 Initial import
thib
parents:
diff changeset
550 if (cmd.args.size() < cmd.argc) {
223b71206888 Initial import
thib
parents:
diff changeset
551 eprintf(" error: argsize changed %d -> %d\n",cmd.argc, cmd.args.size());
223b71206888 Initial import
thib
parents:
diff changeset
552 cmd.argc = cmd.args.size();
223b71206888 Initial import
thib
parents:
diff changeset
553 }
223b71206888 Initial import
thib
parents:
diff changeset
554 for (i=0; i<cmd.argc; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
555 eprintf("%d, ",cmd.args[i+1].value);
223b71206888 Initial import
thib
parents:
diff changeset
556 Set(v1, cmd.args[i+1].value);
223b71206888 Initial import
thib
parents:
diff changeset
557 v1.number++;
223b71206888 Initial import
thib
parents:
diff changeset
558 }
223b71206888 Initial import
thib
parents:
diff changeset
559 eprintf("\n");
223b71206888 Initial import
thib
parents:
diff changeset
560 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
561 } else if (cmd.cmd3 == 1 && cmd.cmd4 == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
562 /* Îΰè»ØÄê¤ÇÊÑ¿ô¤ò¥¯¥ê¥¢ */
223b71206888 Initial import
thib
parents:
diff changeset
563 VarInfo v1 = cmd.args[0];
223b71206888 Initial import
thib
parents:
diff changeset
564 VarInfo v2 = cmd.args[1];
223b71206888 Initial import
thib
parents:
diff changeset
565 eprintf("memclear. Var[%d]<%d> - Var[%d]<%d>\n",v1.type, v1.number, v2.type, v2.number);
223b71206888 Initial import
thib
parents:
diff changeset
566 if (v1.type != v2.type || !IsInt(v1.type)) eprintf(" error: bad args\n");
223b71206888 Initial import
thib
parents:
diff changeset
567 else {
223b71206888 Initial import
thib
parents:
diff changeset
568 if (v1.number < 0) v1.number = 0;
223b71206888 Initial import
thib
parents:
diff changeset
569 if (v2.number > MaxIndex(v2.type)) v2.number = MaxIndex(v2.type);
223b71206888 Initial import
thib
parents:
diff changeset
570 for (; v1.number <= v2.number; v1.number++)
223b71206888 Initial import
thib
parents:
diff changeset
571 Set(v1, 0);
223b71206888 Initial import
thib
parents:
diff changeset
572 }
223b71206888 Initial import
thib
parents:
diff changeset
573 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
574 } else if (cmd.cmd3 == 1 && cmd.cmd4 == 1) {
223b71206888 Initial import
thib
parents:
diff changeset
575 /* Îΰè»ØÄê¤ÇÊÑ¿ô¤ò¥»¥Ã¥È */
223b71206888 Initial import
thib
parents:
diff changeset
576 VarInfo v1 = cmd.args[0];
223b71206888 Initial import
thib
parents:
diff changeset
577 VarInfo v2 = cmd.args[1];
223b71206888 Initial import
thib
parents:
diff changeset
578 int value = cmd.args[2].value;
223b71206888 Initial import
thib
parents:
diff changeset
579 eprintf("memset. Var[%d]<%d> - Var[%d]<%d> <- %d\n",v1.type, v1.number, v2.type, v2.number, value);
223b71206888 Initial import
thib
parents:
diff changeset
580 if (v1.type != v2.type || !IsInt(v1.type)) eprintf(" error: bad args\n");
223b71206888 Initial import
thib
parents:
diff changeset
581 else {
223b71206888 Initial import
thib
parents:
diff changeset
582 if (v1.number < 0) v1.number = 0;
223b71206888 Initial import
thib
parents:
diff changeset
583 if (v2.number > MaxIndex(v2.type)) v2.number = MaxIndex(v2.type);
223b71206888 Initial import
thib
parents:
diff changeset
584 for (; v1.number <= v2.number; v1.number++)
223b71206888 Initial import
thib
parents:
diff changeset
585 Set(v1, value);
223b71206888 Initial import
thib
parents:
diff changeset
586 }
223b71206888 Initial import
thib
parents:
diff changeset
587 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
588 } else if (cmd.cmd3 == 4 && cmd.cmd4 == 1) { // Îΰ襯¥ê¥¢(sysfunc.txt)
223b71206888 Initial import
thib
parents:
diff changeset
589 VarInfo v1 = cmd.args[0];
223b71206888 Initial import
thib
parents:
diff changeset
590 int step = cmd.args[1].value;
223b71206888 Initial import
thib
parents:
diff changeset
591 int deal = cmd.args[2].value;
223b71206888 Initial import
thib
parents:
diff changeset
592 int val = cmd.args[3].value;
223b71206888 Initial import
thib
parents:
diff changeset
593 eprintf("memclear. Var[%d]<%d> step %d deal %d <- val %d\n",v1.type, v1.number, step, deal, val);
223b71206888 Initial import
thib
parents:
diff changeset
594 int i; for (i=0; i<deal; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
595 Set(v1, val);
223b71206888 Initial import
thib
parents:
diff changeset
596 v1.number += step;
223b71206888 Initial import
thib
parents:
diff changeset
597 }
223b71206888 Initial import
thib
parents:
diff changeset
598 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
599 } else if (cmd.cmd3 == 0x64 && cmd.cmd4 == 0) { //Îΰè¤Ç¿ôÃͤò¹ç·×¤¹¤ë
223b71206888 Initial import
thib
parents:
diff changeset
600 VarInfo v1 = cmd.args[0];
223b71206888 Initial import
thib
parents:
diff changeset
601 VarInfo v2 = cmd.args[1];
223b71206888 Initial import
thib
parents:
diff changeset
602 eprintf("sum var. Var[%d]<%d> - Var[%d]<%d>\n",v1.type, v1.number, v2.type, v2.number);
223b71206888 Initial import
thib
parents:
diff changeset
603 int sum = 0;
223b71206888 Initial import
thib
parents:
diff changeset
604 if (v1.type != v2.type || !IsInt(v1.type)) eprintf(" error: bad args\n");
223b71206888 Initial import
thib
parents:
diff changeset
605 else {
223b71206888 Initial import
thib
parents:
diff changeset
606 if (v1.number < 0) v1.number = 0;
223b71206888 Initial import
thib
parents:
diff changeset
607 if (v2.number > MaxIndex(v2.type)) v2.number = MaxIndex(v2.type);
223b71206888 Initial import
thib
parents:
diff changeset
608 for (; v1.number <= v2.number; v1.number++)
223b71206888 Initial import
thib
parents:
diff changeset
609 sum += (*this)(v1);
223b71206888 Initial import
thib
parents:
diff changeset
610 }
223b71206888 Initial import
thib
parents:
diff changeset
611 eprintf(" ret %d\n",sum);
223b71206888 Initial import
thib
parents:
diff changeset
612 cmd.SetSysvar(sum);
223b71206888 Initial import
thib
parents:
diff changeset
613 }
223b71206888 Initial import
thib
parents:
diff changeset
614 }
223b71206888 Initial import
thib
parents:
diff changeset
615 return false;
223b71206888 Initial import
thib
parents:
diff changeset
616 }
223b71206888 Initial import
thib
parents:
diff changeset
617
223b71206888 Initial import
thib
parents:
diff changeset
618 /*********************************************************************
54
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
619 ** SimpleCmd
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
620 */
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
621
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
622 SimpleCmd::SimpleCmd(int a, int b, int c)
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
623 {
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
624 cmd1 = a;
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
625 cmd2 = b;
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
626 cmd3 = c;
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
627 }
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
628
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
629 SimpleCmd::SimpleCmd(void)
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
630 {
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
631 cmd1 = cmd2 = cmd3 = 0;
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
632 }
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
633
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
634 bool SimpleCmd::operator<(const SimpleCmd& cmd) const
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
635 {
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
636 if (cmd1 < cmd.cmd1) return true;
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
637 else if (cmd1 > cmd.cmd1) return false;
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
638
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
639 if (cmd2 < cmd.cmd2) return true;
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
640 else if (cmd2 > cmd.cmd2) return false;
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
641
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
642 if (cmd3 < cmd.cmd3) return true;
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
643 else return false;
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
644 }
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
645
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
646 bool SimpleCmd::operator==(const SimpleCmd& cmd) const
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
647 {
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
648 return (cmd1 == cmd.cmd1 && cmd2 == cmd.cmd2 && cmd3 == cmd.cmd3);
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
649 }
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
650
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
651
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
652 /*********************************************************************
0
223b71206888 Initial import
thib
parents:
diff changeset
653 ** Cmd
223b71206888 Initial import
thib
parents:
diff changeset
654 */
223b71206888 Initial import
thib
parents:
diff changeset
655
223b71206888 Initial import
thib
parents:
diff changeset
656 /* ¿ôÃÍ num := 0x24 0xff <int num> */
223b71206888 Initial import
thib
parents:
diff changeset
657 /* ÊÑ¿ô var := 0x24 <uchar type> 0x5b <exp> 0x5d */
223b71206888 Initial import
thib
parents:
diff changeset
658 /* ¹à token := num | var | 0x28 <exp> 0x29 | <plus|minus> token */
223b71206888 Initial import
thib
parents:
diff changeset
659
223b71206888 Initial import
thib
parents:
diff changeset
660 int Cmd::GetLeftToken(const char*& d, VarInfo& info) {
223b71206888 Initial import
thib
parents:
diff changeset
661 bool var_flag = true;
223b71206888 Initial import
thib
parents:
diff changeset
662 int minus_flag = 0;
223b71206888 Initial import
thib
parents:
diff changeset
663 int value = 0;
223b71206888 Initial import
thib
parents:
diff changeset
664 if (d[0] == 0x5c && (d[1] == 1 || d[1] == 0) ) {
223b71206888 Initial import
thib
parents:
diff changeset
665 if (d[1] == 1) {dprintf("minus-"); minus_flag ^= 1;}
223b71206888 Initial import
thib
parents:
diff changeset
666 else dprintf("plus-");
223b71206888 Initial import
thib
parents:
diff changeset
667 d += 2;
223b71206888 Initial import
thib
parents:
diff changeset
668 var_flag = false;
223b71206888 Initial import
thib
parents:
diff changeset
669 }
223b71206888 Initial import
thib
parents:
diff changeset
670 if (d[0] == 0x24 && ((unsigned const char*)d)[1] == 0xff) {
223b71206888 Initial import
thib
parents:
diff changeset
671 // if ( (d[0] == 0x30 || d[0] == 0x31) && d[1] == 0x24 && ((unsigned const char*)d)[2] == 0xff) /* @@@ not supported; selection Æâ¤Ç¡¢0x30|0x31 ¤¬Éտ魯¤ë¤³¤È¤¬¤¢¤ë */
223b71206888 Initial import
thib
parents:
diff changeset
672 // numerical atom
223b71206888 Initial import
thib
parents:
diff changeset
673 d += 6;
223b71206888 Initial import
thib
parents:
diff changeset
674 value = read_little_endian_int(d-4);
223b71206888 Initial import
thib
parents:
diff changeset
675 dprintf("%d",value);
223b71206888 Initial import
thib
parents:
diff changeset
676 var_flag = false;
223b71206888 Initial import
thib
parents:
diff changeset
677 } else if (d[0] == 0x24 && *(unsigned char*)(d+1) == 0xc8) {
223b71206888 Initial import
thib
parents:
diff changeset
678 dprintf("V<sys>");
223b71206888 Initial import
thib
parents:
diff changeset
679 d += 2;
223b71206888 Initial import
thib
parents:
diff changeset
680 info.type = TYPE_SYS; info.number = 0;
223b71206888 Initial import
thib
parents:
diff changeset
681 value = info.value = flags();
223b71206888 Initial import
thib
parents:
diff changeset
682 } else if (d[0] == 0x24 && d[2] == 0x5b) {
223b71206888 Initial import
thib
parents:
diff changeset
683 // 0x24,<type>,0x5b,<expr>,0x5d-terminated term
223b71206888 Initial import
thib
parents:
diff changeset
684 info.type = *(unsigned char*)(d+1);
223b71206888 Initial import
thib
parents:
diff changeset
685 d += 3;
223b71206888 Initial import
thib
parents:
diff changeset
686 dprintf("V<%d>[",info.type);
223b71206888 Initial import
thib
parents:
diff changeset
687 info.number = GetExpression(d);
223b71206888 Initial import
thib
parents:
diff changeset
688 dprintf("]");
223b71206888 Initial import
thib
parents:
diff changeset
689 if (*d == 0x5d) d++;
223b71206888 Initial import
thib
parents:
diff changeset
690 else SetError();
223b71206888 Initial import
thib
parents:
diff changeset
691 if (info.type == TYPE_VARSTR || info.type == TYPE_VARSYSSTR || info.type == TYPE_VARLOCSTR) {
223b71206888 Initial import
thib
parents:
diff changeset
692 value = 0;
223b71206888 Initial import
thib
parents:
diff changeset
693 info.value = StrVar(info.type, info.number);
223b71206888 Initial import
thib
parents:
diff changeset
694 } else {
223b71206888 Initial import
thib
parents:
diff changeset
695 value = info.value = flags(info);
223b71206888 Initial import
thib
parents:
diff changeset
696 }
223b71206888 Initial import
thib
parents:
diff changeset
697 dprintf("(=%d)",value);
223b71206888 Initial import
thib
parents:
diff changeset
698 } else SetError();
223b71206888 Initial import
thib
parents:
diff changeset
699
223b71206888 Initial import
thib
parents:
diff changeset
700 if (minus_flag) value = -value;
223b71206888 Initial import
thib
parents:
diff changeset
701 if (!var_flag) {
223b71206888 Initial import
thib
parents:
diff changeset
702 info.type = TYPE_VAL;
223b71206888 Initial import
thib
parents:
diff changeset
703 info.value = value;
223b71206888 Initial import
thib
parents:
diff changeset
704 }
223b71206888 Initial import
thib
parents:
diff changeset
705 return value;
223b71206888 Initial import
thib
parents:
diff changeset
706 }
223b71206888 Initial import
thib
parents:
diff changeset
707
47
5f548e5957a8 * get rid of the "deprecated conversion from string constant to ‘char*’" warnings
thib
parents: 44
diff changeset
708 static const char* op_str[70] = {
0
223b71206888 Initial import
thib
parents:
diff changeset
709 // 0 1 2 3 4 5 6 7 8 9
223b71206888 Initial import
thib
parents:
diff changeset
710 "+", "-", "*", "/", "%", "&", "|", "^", "<<", ">>", // +00
223b71206888 Initial import
thib
parents:
diff changeset
711 "err.","err.","err.","err.","err.","err.","err.","err.","err.","err.", // +10
223b71206888 Initial import
thib
parents:
diff changeset
712 "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "<<=", ">>=", // +20
223b71206888 Initial import
thib
parents:
diff changeset
713 "=", "err.","err.","err.","err.","err.","err.","err.","err.","err.", // +30
223b71206888 Initial import
thib
parents:
diff changeset
714 "==", "!=", "<=", "<", ">=", ">", "err.","err.","err.","err.", // +40
223b71206888 Initial import
thib
parents:
diff changeset
715 "err.","err.","err.","err.","err.","err.","err.","err.","err.","err.", // +50
223b71206888 Initial import
thib
parents:
diff changeset
716 "&&", "||", "err.","err.","err.","err.","err.","err.","err.","err.", // +60
223b71206888 Initial import
thib
parents:
diff changeset
717 };
223b71206888 Initial import
thib
parents:
diff changeset
718
223b71206888 Initial import
thib
parents:
diff changeset
719 static int op_pri_tbl[12] = {
223b71206888 Initial import
thib
parents:
diff changeset
720 // + - * / % & | ^ << >>
223b71206888 Initial import
thib
parents:
diff changeset
721 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 10, 10};
223b71206888 Initial import
thib
parents:
diff changeset
722
223b71206888 Initial import
thib
parents:
diff changeset
723 inline int op_pri(int op) {
223b71206888 Initial import
thib
parents:
diff changeset
724 if (op > 11) return 10;
223b71206888 Initial import
thib
parents:
diff changeset
725 return op_pri_tbl[op];
223b71206888 Initial import
thib
parents:
diff changeset
726 }
223b71206888 Initial import
thib
parents:
diff changeset
727 inline int op_pri_cond(int op) {
223b71206888 Initial import
thib
parents:
diff changeset
728 if (op <= 11) return op_pri_tbl[op];
223b71206888 Initial import
thib
parents:
diff changeset
729 else if (op < 50) return 7;
223b71206888 Initial import
thib
parents:
diff changeset
730 else if (op == 60) return 8;
223b71206888 Initial import
thib
parents:
diff changeset
731 else if (op == 61) return 8;
223b71206888 Initial import
thib
parents:
diff changeset
732 else return 10;
223b71206888 Initial import
thib
parents:
diff changeset
733 }
223b71206888 Initial import
thib
parents:
diff changeset
734
223b71206888 Initial import
thib
parents:
diff changeset
735
223b71206888 Initial import
thib
parents:
diff changeset
736 inline int eval(int v1, int op, int v2) {
223b71206888 Initial import
thib
parents:
diff changeset
737 switch(op) {
223b71206888 Initial import
thib
parents:
diff changeset
738 case 0: return v1+v2;
223b71206888 Initial import
thib
parents:
diff changeset
739 case 1: return v1-v2;
223b71206888 Initial import
thib
parents:
diff changeset
740 case 2: return v1*v2;
223b71206888 Initial import
thib
parents:
diff changeset
741 case 3: return v2!=0 ? v1/v2 : v1;
223b71206888 Initial import
thib
parents:
diff changeset
742 case 4: return v2!=0 ? v1%v2 : v1;
223b71206888 Initial import
thib
parents:
diff changeset
743 case 5: return v1&v2;
223b71206888 Initial import
thib
parents:
diff changeset
744 case 6: return v1|v2;
223b71206888 Initial import
thib
parents:
diff changeset
745 case 7: return v1^v2;
223b71206888 Initial import
thib
parents:
diff changeset
746 case 8: return v1<<v2;
223b71206888 Initial import
thib
parents:
diff changeset
747 case 9: return v1>>v2;
223b71206888 Initial import
thib
parents:
diff changeset
748 case 40: return v1 == v2;
223b71206888 Initial import
thib
parents:
diff changeset
749 case 41: return v1 != v2;
223b71206888 Initial import
thib
parents:
diff changeset
750 case 42: return v1 <= v2;
223b71206888 Initial import
thib
parents:
diff changeset
751 case 43: return v1 < v2;
223b71206888 Initial import
thib
parents:
diff changeset
752 case 44: return v1 >= v2;
223b71206888 Initial import
thib
parents:
diff changeset
753 case 45: return v1 > v2;
223b71206888 Initial import
thib
parents:
diff changeset
754 case 60: return v1 && v2;
223b71206888 Initial import
thib
parents:
diff changeset
755 case 61: return v1 || v2;
223b71206888 Initial import
thib
parents:
diff changeset
756 }
223b71206888 Initial import
thib
parents:
diff changeset
757 return v2;
223b71206888 Initial import
thib
parents:
diff changeset
758 }
223b71206888 Initial import
thib
parents:
diff changeset
759
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
760 Cmd::Cmd(const Flags& f, int _sys_ver) : flags(f), system_version(_sys_ver) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
761 cmd_type = CMD_NOP;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
762 argc = 0;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
763 errorflag = false;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
764 cmdstr[0] = 0;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
765 strend = 0;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
766 pos = -1;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
767 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
768
0
223b71206888 Initial import
thib
parents:
diff changeset
769 /* ±é»»»Ò op := 0x5c <uchar op> */
223b71206888 Initial import
thib
parents:
diff changeset
770 /* ¿ô¼° exp: [op] <token> [op <token> [...]] */
223b71206888 Initial import
thib
parents:
diff changeset
771 int Cmd::GetExpression(const char*& d, VarInfo* info_ptr) {
223b71206888 Initial import
thib
parents:
diff changeset
772 #define STACK_DEPTH 1024
223b71206888 Initial import
thib
parents:
diff changeset
773 #define OP_LB 11
223b71206888 Initial import
thib
parents:
diff changeset
774 char op_stack[STACK_DEPTH];
223b71206888 Initial import
thib
parents:
diff changeset
775 int val_stack[STACK_DEPTH];
223b71206888 Initial import
thib
parents:
diff changeset
776 int stack_count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
777
223b71206888 Initial import
thib
parents:
diff changeset
778 // Âè°ì¹à¤ÎÆɤ߹þ¤ß
223b71206888 Initial import
thib
parents:
diff changeset
779 while(*d == 0x28) {
223b71206888 Initial import
thib
parents:
diff changeset
780 d++;
223b71206888 Initial import
thib
parents:
diff changeset
781 dprintf("(");
223b71206888 Initial import
thib
parents:
diff changeset
782 op_stack[stack_count++] = OP_LB;
223b71206888 Initial import
thib
parents:
diff changeset
783 }
223b71206888 Initial import
thib
parents:
diff changeset
784 VarInfo info;
223b71206888 Initial import
thib
parents:
diff changeset
785 int value = GetLeftToken(d, info);
223b71206888 Initial import
thib
parents:
diff changeset
786
223b71206888 Initial import
thib
parents:
diff changeset
787 while(*d == 0x29 && stack_count > 0 && op_stack[stack_count-1] == OP_LB) {
223b71206888 Initial import
thib
parents:
diff changeset
788 d++;
223b71206888 Initial import
thib
parents:
diff changeset
789 dprintf(")");
223b71206888 Initial import
thib
parents:
diff changeset
790 stack_count--;
223b71206888 Initial import
thib
parents:
diff changeset
791 }
223b71206888 Initial import
thib
parents:
diff changeset
792
223b71206888 Initial import
thib
parents:
diff changeset
793 if (*d != 0x5c && stack_count == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
794 if (info_ptr) *info_ptr = info;
223b71206888 Initial import
thib
parents:
diff changeset
795 return value; // ñ½ã¤Êleft-term¤Ï¤³¤³¤Ç½ªÎ»¡£Í­¸ú¤Êinfo_ptr¤òµ¢¤¹¡Ê²ÄǽÀ­¤¬¤¢¤ë¡Ë
223b71206888 Initial import
thib
parents:
diff changeset
796 }
223b71206888 Initial import
thib
parents:
diff changeset
797
223b71206888 Initial import
thib
parents:
diff changeset
798 while(*d == 0x5c) {
223b71206888 Initial import
thib
parents:
diff changeset
799 int op_type = *(unsigned char*)(d+1);
223b71206888 Initial import
thib
parents:
diff changeset
800 d += 2;
223b71206888 Initial import
thib
parents:
diff changeset
801 if (op_type < 70) dprintf("%s",op_str[op_type]);
223b71206888 Initial import
thib
parents:
diff changeset
802 else dprintf("err.");
223b71206888 Initial import
thib
parents:
diff changeset
803 if (op_type >= 10) SetError();
223b71206888 Initial import
thib
parents:
diff changeset
804 int cur_pri = op_pri(op_type);
223b71206888 Initial import
thib
parents:
diff changeset
805 while(stack_count != 0 && op_pri(op_stack[stack_count-1]) <= cur_pri) {
223b71206888 Initial import
thib
parents:
diff changeset
806 // Í¥Àè½ç°Ì¤Î¹â¤¤¡¢Àè¹Ô¤¹¤ë±é»»¤ò¹Ô¤¦
223b71206888 Initial import
thib
parents:
diff changeset
807 value = eval(val_stack[stack_count-1], op_stack[stack_count-1], value);
223b71206888 Initial import
thib
parents:
diff changeset
808 stack_count--;
223b71206888 Initial import
thib
parents:
diff changeset
809 }
223b71206888 Initial import
thib
parents:
diff changeset
810 val_stack[stack_count] = value;
223b71206888 Initial import
thib
parents:
diff changeset
811 op_stack[stack_count++] = op_type;
223b71206888 Initial import
thib
parents:
diff changeset
812 while(*d == 0x28) {
223b71206888 Initial import
thib
parents:
diff changeset
813 d++;
223b71206888 Initial import
thib
parents:
diff changeset
814 dprintf("(");
223b71206888 Initial import
thib
parents:
diff changeset
815 op_stack[stack_count++] = OP_LB;
223b71206888 Initial import
thib
parents:
diff changeset
816 }
223b71206888 Initial import
thib
parents:
diff changeset
817 if (stack_count >= STACK_DEPTH) SetError();
223b71206888 Initial import
thib
parents:
diff changeset
818 value = GetLeftToken(d, info);
223b71206888 Initial import
thib
parents:
diff changeset
819
223b71206888 Initial import
thib
parents:
diff changeset
820 while (*d != 0x5c && stack_count > 0) {
223b71206888 Initial import
thib
parents:
diff changeset
821 // ̤¼Â¹Ô¤Î±é»»¤ò½ª¤ï¤é¤»¤ë
223b71206888 Initial import
thib
parents:
diff changeset
822 if (op_stack[stack_count-1] != OP_LB) {
223b71206888 Initial import
thib
parents:
diff changeset
823 value = eval(val_stack[stack_count-1], op_stack[stack_count-1], value);
223b71206888 Initial import
thib
parents:
diff changeset
824 stack_count--;
223b71206888 Initial import
thib
parents:
diff changeset
825 } else if (*d == 0x29) { /* op_stack == OP_LB */
223b71206888 Initial import
thib
parents:
diff changeset
826 // bracket ½ªÃ¼¤¬¤¢¤ì¤Ð¡¢ÊĤ¸¤Æ¤ª¤¯
223b71206888 Initial import
thib
parents:
diff changeset
827 d++;
223b71206888 Initial import
thib
parents:
diff changeset
828 dprintf(")");
223b71206888 Initial import
thib
parents:
diff changeset
829 stack_count--;
223b71206888 Initial import
thib
parents:
diff changeset
830 } else break; // error
223b71206888 Initial import
thib
parents:
diff changeset
831 }
223b71206888 Initial import
thib
parents:
diff changeset
832 }
223b71206888 Initial import
thib
parents:
diff changeset
833 if (stack_count) SetError(); // unbalanced bracket
223b71206888 Initial import
thib
parents:
diff changeset
834 dprintf("(=%d)",value);
223b71206888 Initial import
thib
parents:
diff changeset
835 if (info_ptr) {
223b71206888 Initial import
thib
parents:
diff changeset
836 info_ptr->type = TYPE_VAL;
223b71206888 Initial import
thib
parents:
diff changeset
837 info_ptr->value = value;
223b71206888 Initial import
thib
parents:
diff changeset
838 }
223b71206888 Initial import
thib
parents:
diff changeset
839 return value;
223b71206888 Initial import
thib
parents:
diff changeset
840 }
223b71206888 Initial import
thib
parents:
diff changeset
841
223b71206888 Initial import
thib
parents:
diff changeset
842 // ¾ò·ïʬ´ôÀìÍѤˡ¢¾ò·ï±é»»¤È»»½Ñ±é»»¤Îº®¹ç¤ò¸¡ÃΤǤ­¤ëÀìÍѥ롼¥Á¥ó¡ÊËÜÍè¤ÏGetExpression¤Çº¹¤·»Ù¤¨¤Ê¤¤)
223b71206888 Initial import
thib
parents:
diff changeset
843 int Cmd::GetExpressionCond(const char*& d) {
223b71206888 Initial import
thib
parents:
diff changeset
844 char op_stack[STACK_DEPTH];
223b71206888 Initial import
thib
parents:
diff changeset
845 int val_stack[STACK_DEPTH];
223b71206888 Initial import
thib
parents:
diff changeset
846 int valattr_stack[STACK_DEPTH];
223b71206888 Initial import
thib
parents:
diff changeset
847 #define ATTR_VAL 0
223b71206888 Initial import
thib
parents:
diff changeset
848 #define ATTR_FLAG 1
223b71206888 Initial import
thib
parents:
diff changeset
849 int stack_count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
850
223b71206888 Initial import
thib
parents:
diff changeset
851 // Âè°ì¹à¤ÎÆɤ߹þ¤ß
223b71206888 Initial import
thib
parents:
diff changeset
852 while(*d == 0x28) {
223b71206888 Initial import
thib
parents:
diff changeset
853 d++;
223b71206888 Initial import
thib
parents:
diff changeset
854 dprintf("(");
223b71206888 Initial import
thib
parents:
diff changeset
855 op_stack[stack_count++] = OP_LB;
223b71206888 Initial import
thib
parents:
diff changeset
856 }
223b71206888 Initial import
thib
parents:
diff changeset
857 VarInfo info;
223b71206888 Initial import
thib
parents:
diff changeset
858 int value = GetLeftToken(d, info);
223b71206888 Initial import
thib
parents:
diff changeset
859 while(*d == 0x29 && stack_count > 0 && op_stack[stack_count-1] == OP_LB) {
223b71206888 Initial import
thib
parents:
diff changeset
860 d++;
223b71206888 Initial import
thib
parents:
diff changeset
861 dprintf(")");
223b71206888 Initial import
thib
parents:
diff changeset
862 stack_count--;
223b71206888 Initial import
thib
parents:
diff changeset
863 }
223b71206888 Initial import
thib
parents:
diff changeset
864 bool valattr = ATTR_VAL;
223b71206888 Initial import
thib
parents:
diff changeset
865
223b71206888 Initial import
thib
parents:
diff changeset
866 while(*d == 0x5c) {
223b71206888 Initial import
thib
parents:
diff changeset
867 int op_type = *(unsigned char*)(d+1);
223b71206888 Initial import
thib
parents:
diff changeset
868 d += 2;
223b71206888 Initial import
thib
parents:
diff changeset
869 if (op_type < 70) dprintf("%s",op_str[op_type]);
223b71206888 Initial import
thib
parents:
diff changeset
870 else dprintf("err.");
223b71206888 Initial import
thib
parents:
diff changeset
871 int cur_pri = op_pri_cond(op_type);
223b71206888 Initial import
thib
parents:
diff changeset
872 while(stack_count != 0 && op_pri_cond(op_stack[stack_count-1]) <= cur_pri) {
223b71206888 Initial import
thib
parents:
diff changeset
873 // Í¥Àè½ç°Ì¤Î¹â¤¤¡¢Àè¹Ô¤¹¤ë±é»»¤ò¹Ô¤¦
223b71206888 Initial import
thib
parents:
diff changeset
874 if (op_stack[stack_count-1] >= 60) {
223b71206888 Initial import
thib
parents:
diff changeset
875 if (valattr_stack[stack_count-1] != ATTR_FLAG || valattr != ATTR_FLAG) SetError();
223b71206888 Initial import
thib
parents:
diff changeset
876 } else {
223b71206888 Initial import
thib
parents:
diff changeset
877 if (valattr_stack[stack_count-1] != ATTR_VAL || valattr != ATTR_VAL) SetError();
223b71206888 Initial import
thib
parents:
diff changeset
878 }
223b71206888 Initial import
thib
parents:
diff changeset
879 value = eval(val_stack[stack_count-1], op_stack[stack_count-1], value);
223b71206888 Initial import
thib
parents:
diff changeset
880 if (op_stack[stack_count-1] >= 40) valattr = ATTR_FLAG;
223b71206888 Initial import
thib
parents:
diff changeset
881 stack_count--;
223b71206888 Initial import
thib
parents:
diff changeset
882 }
223b71206888 Initial import
thib
parents:
diff changeset
883 val_stack[stack_count] = value;
223b71206888 Initial import
thib
parents:
diff changeset
884 valattr_stack[stack_count] = valattr;
223b71206888 Initial import
thib
parents:
diff changeset
885 op_stack[stack_count++] = op_type;
223b71206888 Initial import
thib
parents:
diff changeset
886 while(*d == 0x28) {
223b71206888 Initial import
thib
parents:
diff changeset
887 d++;
223b71206888 Initial import
thib
parents:
diff changeset
888 dprintf("(");
223b71206888 Initial import
thib
parents:
diff changeset
889 op_stack[stack_count++] = OP_LB;
223b71206888 Initial import
thib
parents:
diff changeset
890 }
223b71206888 Initial import
thib
parents:
diff changeset
891 if (stack_count >= STACK_DEPTH) SetError();
223b71206888 Initial import
thib
parents:
diff changeset
892 value = GetLeftToken(d, info);
223b71206888 Initial import
thib
parents:
diff changeset
893 valattr = ATTR_VAL;
223b71206888 Initial import
thib
parents:
diff changeset
894
223b71206888 Initial import
thib
parents:
diff changeset
895 while (*d != 0x5c && stack_count > 0) {
223b71206888 Initial import
thib
parents:
diff changeset
896 // ̤¼Â¹Ô¤Î±é»»¤ò½ª¤ï¤é¤»¤ë
223b71206888 Initial import
thib
parents:
diff changeset
897 if (op_stack[stack_count-1] != OP_LB) {
223b71206888 Initial import
thib
parents:
diff changeset
898 if (op_stack[stack_count-1] >= 60) {
223b71206888 Initial import
thib
parents:
diff changeset
899 if (valattr_stack[stack_count-1] != ATTR_FLAG || valattr != ATTR_FLAG) SetError();
223b71206888 Initial import
thib
parents:
diff changeset
900 } else {
223b71206888 Initial import
thib
parents:
diff changeset
901 if (valattr_stack[stack_count-1] != ATTR_VAL || valattr != ATTR_VAL) SetError();
223b71206888 Initial import
thib
parents:
diff changeset
902 }
223b71206888 Initial import
thib
parents:
diff changeset
903 value = eval(val_stack[stack_count-1], op_stack[stack_count-1], value);
223b71206888 Initial import
thib
parents:
diff changeset
904 if (op_stack[stack_count-1] >= 40) valattr = ATTR_FLAG;
223b71206888 Initial import
thib
parents:
diff changeset
905 stack_count--;
223b71206888 Initial import
thib
parents:
diff changeset
906 // bracket ½ªÃ¼¤¬¤¢¤ì¤Ð¡¢ÊĤ¸¤Æ¤ª¤¯
223b71206888 Initial import
thib
parents:
diff changeset
907 } else if (*d == 0x29) { /* op_stack == OP_LB */
223b71206888 Initial import
thib
parents:
diff changeset
908 d++;
223b71206888 Initial import
thib
parents:
diff changeset
909 dprintf(")");
223b71206888 Initial import
thib
parents:
diff changeset
910 stack_count--;
223b71206888 Initial import
thib
parents:
diff changeset
911 } else break; // error
223b71206888 Initial import
thib
parents:
diff changeset
912 }
223b71206888 Initial import
thib
parents:
diff changeset
913 }
223b71206888 Initial import
thib
parents:
diff changeset
914 if (stack_count) SetError(); // unbalanced bracket
223b71206888 Initial import
thib
parents:
diff changeset
915 if (value) dprintf("(=true)");
223b71206888 Initial import
thib
parents:
diff changeset
916 else dprintf("(=false)");
223b71206888 Initial import
thib
parents:
diff changeset
917 return value;
223b71206888 Initial import
thib
parents:
diff changeset
918 }
223b71206888 Initial import
thib
parents:
diff changeset
919
223b71206888 Initial import
thib
parents:
diff changeset
920
223b71206888 Initial import
thib
parents:
diff changeset
921 /*
223b71206888 Initial import
thib
parents:
diff changeset
922 str =
223b71206888 Initial import
thib
parents:
diff changeset
923 arg =
223b71206888 Initial import
thib
parents:
diff changeset
924 args = 0x28 <exp> [[0x2c] <exp> [[0x2c] <exp> [...] ]]
223b71206888 Initial import
thib
parents:
diff changeset
925 */
223b71206888 Initial import
thib
parents:
diff changeset
926
223b71206888 Initial import
thib
parents:
diff changeset
927 int Cmd::GetArgs(const char*& d) {
223b71206888 Initial import
thib
parents:
diff changeset
928 if (*d != 0x28) return 0; /* °ú¿ô¤Ê¤· */
223b71206888 Initial import
thib
parents:
diff changeset
929 d++;
223b71206888 Initial import
thib
parents:
diff changeset
930 dprintf("args:");
223b71206888 Initial import
thib
parents:
diff changeset
931 VarInfo var;
223b71206888 Initial import
thib
parents:
diff changeset
932 int i; for (i=0; i<100 ; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
933 /* number, variable, string ¤Î¼ïÊ̤ʤ¯ÃͤòÆÀ¤ë */
223b71206888 Initial import
thib
parents:
diff changeset
934 if (*d == 0x61) { // ¤è¤¯¤ï¤«¤é¤Ê¤¤(ÃÒÂ奢¥Õ¥¿¡¼)
29
d229cce98f50 * no more (or, at least, less) duplicate code between scn2kdump and the rest
thib
parents: 21
diff changeset
935 dprintf("@%d",d[1]);
0
223b71206888 Initial import
thib
parents:
diff changeset
936 d += 2;
223b71206888 Initial import
thib
parents:
diff changeset
937 if (*d == 0x28) {
223b71206888 Initial import
thib
parents:
diff changeset
938 dprintf("{");
223b71206888 Initial import
thib
parents:
diff changeset
939 GetArgs(d); // (A,B,C)À᤬´Þ¤Þ¤ì¤ë¤³¤È¤¬¤¢¤ë
223b71206888 Initial import
thib
parents:
diff changeset
940 dprintf("}");
223b71206888 Initial import
thib
parents:
diff changeset
941 } else {
223b71206888 Initial import
thib
parents:
diff changeset
942 dprintf("{}");
223b71206888 Initial import
thib
parents:
diff changeset
943 }
223b71206888 Initial import
thib
parents:
diff changeset
944 } else if (d[0] == 0x0a || d[0] == 0x40) { // ¤è¤¯¤ï¤«¤é¤Ê¤¤ (Little Busters!)
223b71206888 Initial import
thib
parents:
diff changeset
945 int var;
223b71206888 Initial import
thib
parents:
diff changeset
946 if (system_version == 0) { var = read_little_endian_int(d+1); d += 5;}
223b71206888 Initial import
thib
parents:
diff changeset
947 else { var = read_little_endian_short(d+1); d += 3;}
223b71206888 Initial import
thib
parents:
diff changeset
948 dprintf("line %d; ",var);
223b71206888 Initial import
thib
parents:
diff changeset
949 } else if (*d == 0x24 || (*d == 0x5c && (d[1] == 1 || d[1] == 0)) || *d == 0x28) {
223b71206888 Initial import
thib
parents:
diff changeset
950 GetExpression(d, &var);
223b71206888 Initial import
thib
parents:
diff changeset
951 args.push_back(var);
223b71206888 Initial import
thib
parents:
diff changeset
952 } else if (StrType(d)) {
223b71206888 Initial import
thib
parents:
diff changeset
953 var.type = TYPE_STR;
223b71206888 Initial import
thib
parents:
diff changeset
954 var.value = GetString(d);
223b71206888 Initial import
thib
parents:
diff changeset
955 args.push_back(var);
223b71206888 Initial import
thib
parents:
diff changeset
956 } else SetError();
223b71206888 Initial import
thib
parents:
diff changeset
957 if (*d == 0x29) break;
223b71206888 Initial import
thib
parents:
diff changeset
958 if (*d == 0x2c) {d++;} // ¼¡¤Î arg ¤¬±é»»»Ò¤Ç»Ï¤Þ¤ë¡¢¤Ê¤É¤¬¤Ê¤±¤ì¤Ð¸ºß¤·¤Ê¤¤
223b71206888 Initial import
thib
parents:
diff changeset
959 dprintf(",");
223b71206888 Initial import
thib
parents:
diff changeset
960 }
223b71206888 Initial import
thib
parents:
diff changeset
961 if (*d == 0x29) d++;
223b71206888 Initial import
thib
parents:
diff changeset
962 else SetError();
223b71206888 Initial import
thib
parents:
diff changeset
963 return i;
223b71206888 Initial import
thib
parents:
diff changeset
964 }
223b71206888 Initial import
thib
parents:
diff changeset
965
223b71206888 Initial import
thib
parents:
diff changeset
966 int Cmd::GetArgsSpecial(int normal_args,const char*& d) {
223b71206888 Initial import
thib
parents:
diff changeset
967 if (*d != 0x28) return 0; /* °ú¿ô¤Ê¤· */
223b71206888 Initial import
thib
parents:
diff changeset
968 d++;
223b71206888 Initial import
thib
parents:
diff changeset
969 dprintf("args:");
223b71206888 Initial import
thib
parents:
diff changeset
970 int i; for (i=0; i<normal_args; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
971 /* number, variable, string ¤Î¼ïÊ̤ʤ¯ÃͤòÆÀ¤ë */
223b71206888 Initial import
thib
parents:
diff changeset
972 if (*d == 0x24 || (*d == 0x5c && (d[1] == 1 || d[1] == 0)) || *d == 0x28) {
223b71206888 Initial import
thib
parents:
diff changeset
973 GetExpression(d);
223b71206888 Initial import
thib
parents:
diff changeset
974 } else if (StrType(d)) {
223b71206888 Initial import
thib
parents:
diff changeset
975 GetString(d);
223b71206888 Initial import
thib
parents:
diff changeset
976 } else SetError();
223b71206888 Initial import
thib
parents:
diff changeset
977 if (*d == 0x29) break;
223b71206888 Initial import
thib
parents:
diff changeset
978 if (*d == 0x2c) {d++;} // ¼¡¤Î arg ¤¬±é»»»Ò¤Ç»Ï¤Þ¤ë¡¢¤Ê¤É¤¬¤Ê¤±¤ì¤Ð¸ºß¤·¤Ê¤¤
223b71206888 Initial import
thib
parents:
diff changeset
979 dprintf(",");
223b71206888 Initial import
thib
parents:
diff changeset
980 }
223b71206888 Initial import
thib
parents:
diff changeset
981 for (i=0; i<argc ; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
982 if (*d == 0x28) {
223b71206888 Initial import
thib
parents:
diff changeset
983 /*
223b71206888 Initial import
thib
parents:
diff changeset
984 ** cmd 01-22:0c1c, 01-22:0835
223b71206888 Initial import
thib
parents:
diff changeset
985 ** Princess Bride ¤Î¥«¡¼¥É¤¬Íî¤Á¤ë¥¢¥Ë¥á¤Î¾ìÌÌ
223b71206888 Initial import
thib
parents:
diff changeset
986 ** ¤Ê¤ª¡¢_PBCARDANM* ¤Î²èÁü¤Ï¤³¤Î¥³¥Þ¥ó¥É¤Ç¤Î¤ß»È¤ï¤ì¤Æ¤¤¤ë¤Î¤Ç¡¢Æüì½èÍý¤È¤·¤Æ̵»ë¤¹¤ë¤³¤È¤â²Äǽ
223b71206888 Initial import
thib
parents:
diff changeset
987 **
223b71206888 Initial import
thib
parents:
diff changeset
988 ** cmd 01-04:0276, 026c, 0270
223b71206888 Initial import
thib
parents:
diff changeset
989 ** Ê£¿ô¤Î enum ¤¬ args ¤Î¿ô¤À¤±Â³¤¯½èÍý¡£Æüì½èÍý¤È¤·¤ÆʬΥ¤¹¤ë
223b71206888 Initial import
thib
parents:
diff changeset
990 */
223b71206888 Initial import
thib
parents:
diff changeset
991 dprintf("enum.<");
223b71206888 Initial import
thib
parents:
diff changeset
992 /* (...) ¤ÏÎóµó·¿ or ¹½Â¤ÂΤβÄǽÀ­¤¬¤¢¤ë */
223b71206888 Initial import
thib
parents:
diff changeset
993 const char* d_orig = d;
223b71206888 Initial import
thib
parents:
diff changeset
994 int pt = args.size(); args.push_back(VarInfo(0));
223b71206888 Initial import
thib
parents:
diff changeset
995 int count = GetArgs(d);
223b71206888 Initial import
thib
parents:
diff changeset
996 args[pt] = VarInfo(count);
223b71206888 Initial import
thib
parents:
diff changeset
997 dprintf(">");
223b71206888 Initial import
thib
parents:
diff changeset
998 } else if (*d == 0x61 && (d[1] >= 0x00 && d[1] <= 0x04) && d[2] == 0x28 ) {
223b71206888 Initial import
thib
parents:
diff changeset
999 /* »È¤ï¤ì¤ë¥³¥Þ¥ó¥É¤Ï 01-21:004b, 01-28:0064 ¤Î¤¤¤º¤ì¤«¡ÊR,C,PB,LO)
223b71206888 Initial import
thib
parents:
diff changeset
1000 ** ¤½¤ì¤é¤Î¥³¥Þ¥ó¥É¤Ï
223b71206888 Initial import
thib
parents:
diff changeset
1001 ** arg1: ²èÁü¥Õ¥¡¥¤¥ë̾
223b71206888 Initial import
thib
parents:
diff changeset
1002 ** arg2 : Sel ÈÖ¹æ
223b71206888 Initial import
thib
parents:
diff changeset
1003 ** ¤é¤·¤¯¡¢arg3 °Ê¹ß¤¬ 0x61 <00-04> (a,b,c,...) ¤È¤Ê¤ë¡Ê¥À¥ó¥×¾å¤Ï enum ¤Èɽµ­¤µ¤ì¤ë)
223b71206888 Initial import
thib
parents:
diff changeset
1004 ** () Æâ¤Î°ú¿ô¤Ï¤µ¤Þ¤¶¤Þ¤Ç¡¢a ¤Î¤ß¡Ê²èÁü¥Õ¥¡¥¤¥ë̾¡Ë¡¢
223b71206888 Initial import
thib
parents:
diff changeset
1005 ** a,b b=SEL?
223b71206888 Initial import
thib
parents:
diff changeset
1006 ** a,b,c (b,c)=ºÂɸ¡©
223b71206888 Initial import
thib
parents:
diff changeset
1007 ** a,(b,c,d,e,f,g) b-g = src / dest?
223b71206888 Initial import
thib
parents:
diff changeset
1008 ** ¤é¤·¤¤
223b71206888 Initial import
thib
parents:
diff changeset
1009 */
223b71206888 Initial import
thib
parents:
diff changeset
1010 dprintf("kasane. #%d <",d[1]);
223b71206888 Initial import
thib
parents:
diff changeset
1011 d += 2;
223b71206888 Initial import
thib
parents:
diff changeset
1012 int pt = args.size(); args.push_back(VarInfo(0));
223b71206888 Initial import
thib
parents:
diff changeset
1013 int count = GetArgs(d);
223b71206888 Initial import
thib
parents:
diff changeset
1014 args[pt] = VarInfo(count);
223b71206888 Initial import
thib
parents:
diff changeset
1015 dprintf(">");
223b71206888 Initial import
thib
parents:
diff changeset
1016 } else if (*d == 0x24 || (*d == 0x5c && (d[1] == 1 || d[1] == 0))) {
223b71206888 Initial import
thib
parents:
diff changeset
1017 /* cmd 01-15:0028 ; »Ï¤á¤Ë 0x24 À᤬¤¢¤ê¡¢Â³¤¤¤Æ 0x28 Àá¤Ë¤Ê¤ë */
223b71206888 Initial import
thib
parents:
diff changeset
1018 VarInfo var;
223b71206888 Initial import
thib
parents:
diff changeset
1019 GetExpression(d, &var);
223b71206888 Initial import
thib
parents:
diff changeset
1020 args.push_back(var);
223b71206888 Initial import
thib
parents:
diff changeset
1021 i--; // ¤³¤Î°ú¿ô¤Ïargc ¤Î¿ô¤Ë¤ÏÆþ¤é¤Ê¤¤
223b71206888 Initial import
thib
parents:
diff changeset
1022 } else SetError();
223b71206888 Initial import
thib
parents:
diff changeset
1023 if (d[0] == 0x0a || d[0] == 0x40) {
223b71206888 Initial import
thib
parents:
diff changeset
1024 /* cmd 01-15:0028 ; 0x28 Àá¤Î¸å¤ËËè²ó 0x0a À᤬Íè¤ë */
223b71206888 Initial import
thib
parents:
diff changeset
1025 int var;
223b71206888 Initial import
thib
parents:
diff changeset
1026 if (system_version == 0) { var = read_little_endian_int(d+1); d += 5;}
223b71206888 Initial import
thib
parents:
diff changeset
1027 else { var = read_little_endian_short(d+1); d += 3;}
223b71206888 Initial import
thib
parents:
diff changeset
1028 dprintf("line %d; ",var);
223b71206888 Initial import
thib
parents:
diff changeset
1029 }
223b71206888 Initial import
thib
parents:
diff changeset
1030 if (*d == 0x29) break;
223b71206888 Initial import
thib
parents:
diff changeset
1031 if (*d == 0x2c) {d++;} // ¼¡¤Î arg ¤¬±é»»»Ò¤Ç»Ï¤Þ¤ë¡¢¤Ê¤É¤¬¤Ê¤±¤ì¤Ð¸ºß¤·¤Ê¤¤
223b71206888 Initial import
thib
parents:
diff changeset
1032 dprintf(",");
223b71206888 Initial import
thib
parents:
diff changeset
1033 }
223b71206888 Initial import
thib
parents:
diff changeset
1034 if (*d == 0x29) d++;
223b71206888 Initial import
thib
parents:
diff changeset
1035 else SetError();
223b71206888 Initial import
thib
parents:
diff changeset
1036 return 0;
223b71206888 Initial import
thib
parents:
diff changeset
1037 }
223b71206888 Initial import
thib
parents:
diff changeset
1038
223b71206888 Initial import
thib
parents:
diff changeset
1039 /* switch
223b71206888 Initial import
thib
parents:
diff changeset
1040 <exp>
223b71206888 Initial import
thib
parents:
diff changeset
1041 0x7b
223b71206888 Initial import
thib
parents:
diff changeset
1042 <exp> <int>
223b71206888 Initial import
thib
parents:
diff changeset
1043 ...
223b71206888 Initial import
thib
parents:
diff changeset
1044 0x7d
223b71206888 Initial import
thib
parents:
diff changeset
1045 */
223b71206888 Initial import
thib
parents:
diff changeset
1046
223b71206888 Initial import
thib
parents:
diff changeset
1047 int Cmd::GetSwitch(const char*& d) {
223b71206888 Initial import
thib
parents:
diff changeset
1048 if (*d != 0x28) {SetError(); return -1;}
223b71206888 Initial import
thib
parents:
diff changeset
1049 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1050 dprintf("switch. ");
223b71206888 Initial import
thib
parents:
diff changeset
1051 int var = GetExpression(d);
223b71206888 Initial import
thib
parents:
diff changeset
1052 if (*d != 0x29) {SetError(); return -1;}
223b71206888 Initial import
thib
parents:
diff changeset
1053 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1054 dprintf("->\n");
223b71206888 Initial import
thib
parents:
diff changeset
1055 if (*d == 0x7b) {
223b71206888 Initial import
thib
parents:
diff changeset
1056 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1057 } else SetError();
223b71206888 Initial import
thib
parents:
diff changeset
1058
223b71206888 Initial import
thib
parents:
diff changeset
1059 int default_jmp = -1; int jmpto = -1;
223b71206888 Initial import
thib
parents:
diff changeset
1060 int i; for (i=0; i<argc; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1061 dprintf("\t");
223b71206888 Initial import
thib
parents:
diff changeset
1062 if (*d++ != 0x28) {SetError(); return -1;}
223b71206888 Initial import
thib
parents:
diff changeset
1063 if (*d != 0x29) {
223b71206888 Initial import
thib
parents:
diff changeset
1064 int item = GetExpression(d);
223b71206888 Initial import
thib
parents:
diff changeset
1065 if (*d++ != 0x29) {SetError(); return -1;}
223b71206888 Initial import
thib
parents:
diff changeset
1066 int jmp = read_little_endian_int(d);
223b71206888 Initial import
thib
parents:
diff changeset
1067 if (var == item) {
223b71206888 Initial import
thib
parents:
diff changeset
1068 dprintf("(selected)");
223b71206888 Initial import
thib
parents:
diff changeset
1069 jmpto = jmp;
223b71206888 Initial import
thib
parents:
diff changeset
1070 }
223b71206888 Initial import
thib
parents:
diff changeset
1071 dprintf(" -> %d\n", jmp);
223b71206888 Initial import
thib
parents:
diff changeset
1072 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1073 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1074 default_jmp = read_little_endian_int(d);
223b71206888 Initial import
thib
parents:
diff changeset
1075 }
223b71206888 Initial import
thib
parents:
diff changeset
1076 d += 4;
223b71206888 Initial import
thib
parents:
diff changeset
1077 }
223b71206888 Initial import
thib
parents:
diff changeset
1078 if (default_jmp != -1) {
223b71206888 Initial import
thib
parents:
diff changeset
1079 dprintf("default -> %d\n",default_jmp);
223b71206888 Initial import
thib
parents:
diff changeset
1080 if (jmpto == -1) jmpto = default_jmp;
223b71206888 Initial import
thib
parents:
diff changeset
1081 }
223b71206888 Initial import
thib
parents:
diff changeset
1082 if (*d == 0x7d) {
223b71206888 Initial import
thib
parents:
diff changeset
1083 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1084 } else SetError();
223b71206888 Initial import
thib
parents:
diff changeset
1085 return jmpto;
223b71206888 Initial import
thib
parents:
diff changeset
1086 }
223b71206888 Initial import
thib
parents:
diff changeset
1087 /* simple switch
223b71206888 Initial import
thib
parents:
diff changeset
1088 <exp>
223b71206888 Initial import
thib
parents:
diff changeset
1089 0x7b
223b71206888 Initial import
thib
parents:
diff changeset
1090 <int>
223b71206888 Initial import
thib
parents:
diff changeset
1091 ...
223b71206888 Initial import
thib
parents:
diff changeset
1092 0x7d
223b71206888 Initial import
thib
parents:
diff changeset
1093 */
223b71206888 Initial import
thib
parents:
diff changeset
1094 int Cmd::GetSimpleSwitch(const char*& d) {
223b71206888 Initial import
thib
parents:
diff changeset
1095 if (*d != 0x28) {SetError(); return -1;}
223b71206888 Initial import
thib
parents:
diff changeset
1096 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1097 dprintf("simple switch. ");
223b71206888 Initial import
thib
parents:
diff changeset
1098 int var = GetExpression(d);
223b71206888 Initial import
thib
parents:
diff changeset
1099 if (*d != 0x29) {SetError(); return -1;}
223b71206888 Initial import
thib
parents:
diff changeset
1100 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1101 dprintf(" ->\n");
223b71206888 Initial import
thib
parents:
diff changeset
1102 int jumpto = -1;
223b71206888 Initial import
thib
parents:
diff changeset
1103 if (*d == 0x7b) {
223b71206888 Initial import
thib
parents:
diff changeset
1104 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1105 } else SetError();
223b71206888 Initial import
thib
parents:
diff changeset
1106 int i; for (i=0; i<argc; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1107 int j = read_little_endian_int(d);
223b71206888 Initial import
thib
parents:
diff changeset
1108 d += 4;
223b71206888 Initial import
thib
parents:
diff changeset
1109 dprintf("\t%d -> %d\n", i+1, j);
223b71206888 Initial import
thib
parents:
diff changeset
1110 if (var == i) jumpto = j;
223b71206888 Initial import
thib
parents:
diff changeset
1111 }
223b71206888 Initial import
thib
parents:
diff changeset
1112 if (*d == 0x7d) {
223b71206888 Initial import
thib
parents:
diff changeset
1113 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1114 } else SetError();
223b71206888 Initial import
thib
parents:
diff changeset
1115 return jumpto;
223b71206888 Initial import
thib
parents:
diff changeset
1116 }
223b71206888 Initial import
thib
parents:
diff changeset
1117
223b71206888 Initial import
thib
parents:
diff changeset
1118 /*
223b71206888 Initial import
thib
parents:
diff changeset
1119 selection
223b71206888 Initial import
thib
parents:
diff changeset
1120 ? <exp>
223b71206888 Initial import
thib
parents:
diff changeset
1121 0x7b
223b71206888 Initial import
thib
parents:
diff changeset
1122 <0x0a|0x40> <ushort | uint>
223b71206888 Initial import
thib
parents:
diff changeset
1123 */
223b71206888 Initial import
thib
parents:
diff changeset
1124 void Cmd::GetSelection(const char*& d) {
223b71206888 Initial import
thib
parents:
diff changeset
1125 dprintf("selection. ");
223b71206888 Initial import
thib
parents:
diff changeset
1126 if (*d == 0x28) {
223b71206888 Initial import
thib
parents:
diff changeset
1127 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1128 GetExpression(d);
223b71206888 Initial import
thib
parents:
diff changeset
1129 if (*d != 0x29) { SetError(); return;}
223b71206888 Initial import
thib
parents:
diff changeset
1130 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1131 }
223b71206888 Initial import
thib
parents:
diff changeset
1132 if (*d == 0x7b) {
223b71206888 Initial import
thib
parents:
diff changeset
1133 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1134 dprintf("{\n\t");
223b71206888 Initial import
thib
parents:
diff changeset
1135 } else SetError();
223b71206888 Initial import
thib
parents:
diff changeset
1136 int arg_count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1137 string text = "";
223b71206888 Initial import
thib
parents:
diff changeset
1138 int cond_result = false;
223b71206888 Initial import
thib
parents:
diff changeset
1139 int sel_no = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1140 while(*d != 0x7d) {
223b71206888 Initial import
thib
parents:
diff changeset
1141 if (d[0] == 0x0a || d[0] == 0x40) {
223b71206888 Initial import
thib
parents:
diff changeset
1142 int var;
223b71206888 Initial import
thib
parents:
diff changeset
1143 if (system_version == 0) { var = read_little_endian_int(d+1); d += 5;}
223b71206888 Initial import
thib
parents:
diff changeset
1144 else { var = read_little_endian_short(d+1); d += 3;}
223b71206888 Initial import
thib
parents:
diff changeset
1145 dprintf("Line %d; ",var);
223b71206888 Initial import
thib
parents:
diff changeset
1146 if (text.length() != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1147 if (cond_result) ; // ¾ò·ïÀ᤬ true ¤Ê¤éɽ¼¨¤·¤Ê¤¤
223b71206888 Initial import
thib
parents:
diff changeset
1148 else {
223b71206888 Initial import
thib
parents:
diff changeset
1149 const char* str = text.c_str();
223b71206888 Initial import
thib
parents:
diff changeset
1150 VarInfo var;
223b71206888 Initial import
thib
parents:
diff changeset
1151 var.type = TYPE_STR;
223b71206888 Initial import
thib
parents:
diff changeset
1152 var.value = CopyString(str);
223b71206888 Initial import
thib
parents:
diff changeset
1153 args.push_back(var);
223b71206888 Initial import
thib
parents:
diff changeset
1154 var.type = TYPE_VAL;
223b71206888 Initial import
thib
parents:
diff changeset
1155 var.value = sel_no;
223b71206888 Initial import
thib
parents:
diff changeset
1156 args.push_back(var);
223b71206888 Initial import
thib
parents:
diff changeset
1157 }
223b71206888 Initial import
thib
parents:
diff changeset
1158 sel_no++;
223b71206888 Initial import
thib
parents:
diff changeset
1159 }
223b71206888 Initial import
thib
parents:
diff changeset
1160 text = "";
223b71206888 Initial import
thib
parents:
diff changeset
1161 cond_result = false;
223b71206888 Initial import
thib
parents:
diff changeset
1162 } else if (d[0] == 0x2c) {
223b71206888 Initial import
thib
parents:
diff changeset
1163 dprintf(":comma:");
223b71206888 Initial import
thib
parents:
diff changeset
1164 } else if (d[0] == 0x28) {
223b71206888 Initial import
thib
parents:
diff changeset
1165 dprintf(":cond:");
223b71206888 Initial import
thib
parents:
diff changeset
1166 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1167 while(d[0] != 0x29) {
223b71206888 Initial import
thib
parents:
diff changeset
1168 int result = GetExpressionCond(d); // PRINT- Àá¤Ç¤Ê¤¤¤Ð¤¢¤¤¡¢¾ò·ïɽ¼¨¡£¼¡¤Ïʸ»úÀá¡¢¤Þ¤¿¤ÏPRINTÀá¤Î¤Ï¤º
223b71206888 Initial import
thib
parents:
diff changeset
1169 if (*d == 0x32) { // 0x32 ¤Ê¤é¡¢¸½ºß¤Î¾ò·ïÀá¤òɽ¼¨¤·¤Ê¤¤
223b71206888 Initial import
thib
parents:
diff changeset
1170 d++; dprintf("##");
223b71206888 Initial import
thib
parents:
diff changeset
1171 cond_result = result;
223b71206888 Initial import
thib
parents:
diff changeset
1172 } else if (*d == 0x31) { // 0x31 ¤Ê¤é¡¢¸½ºß¤Î¾ò·ïÀá¤òɽ¼¨¤¹¤ë
223b71206888 Initial import
thib
parents:
diff changeset
1173 // Little Busters! : ¤³¤Î¾ò·ï¤ÇÀµ¤·¤¤¤«¤Ï̤¸¡¾Ú
223b71206888 Initial import
thib
parents:
diff changeset
1174 d++; dprintf("***");
223b71206888 Initial import
thib
parents:
diff changeset
1175 cond_result = !result;
223b71206888 Initial import
thib
parents:
diff changeset
1176 }
223b71206888 Initial import
thib
parents:
diff changeset
1177 dprintf(":");
223b71206888 Initial import
thib
parents:
diff changeset
1178 }
223b71206888 Initial import
thib
parents:
diff changeset
1179 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1180 } else if (StrType(d)) {
223b71206888 Initial import
thib
parents:
diff changeset
1181 int strpt = GetString(d);
223b71206888 Initial import
thib
parents:
diff changeset
1182 text += strheap + strpt;
223b71206888 Initial import
thib
parents:
diff changeset
1183 arg_count++;
223b71206888 Initial import
thib
parents:
diff changeset
1184 dprintf("\n\t");
223b71206888 Initial import
thib
parents:
diff changeset
1185 } else if (*d == 0x23 && strncmp(d,"###PRINT",8) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1186 d += 8;
223b71206888 Initial import
thib
parents:
diff changeset
1187 if (d[0] != 0x28) SetError();
223b71206888 Initial import
thib
parents:
diff changeset
1188 else { // ʸ»úÊÑ¿ô¤ÎÆâÍƤÎɽ¼¨
223b71206888 Initial import
thib
parents:
diff changeset
1189 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1190 dprintf("Print.");
223b71206888 Initial import
thib
parents:
diff changeset
1191 VarInfo info;
223b71206888 Initial import
thib
parents:
diff changeset
1192 GetLeftToken(d, info);
223b71206888 Initial import
thib
parents:
diff changeset
1193 if (d[0] != 0x29 || info.type == -1) SetError();
223b71206888 Initial import
thib
parents:
diff changeset
1194 d++;
21
d1bb7b365816 Fixed dynamic strings in selections (Fuko Pranks for instance)
thib
parents: 13
diff changeset
1195 dprintf(";");/*
0
223b71206888 Initial import
thib
parents:
diff changeset
1196 // ¿ôÃͤòÁ´³Ñʸ»ú¤ËÊÑ´¹¤·¤ÆÅÐÏ¿
223b71206888 Initial import
thib
parents:
diff changeset
1197 char str[10], str2[20]; // itoa
223b71206888 Initial import
thib
parents:
diff changeset
1198 sprintf(str, "%d", info.value);
223b71206888 Initial import
thib
parents:
diff changeset
1199 int i; for (i=0; str[i] != 0; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1200 str2[i*2] = 0xa3;
223b71206888 Initial import
thib
parents:
diff changeset
1201 str2[i*2+1] = 0xb0 + str[i]-'0';
223b71206888 Initial import
thib
parents:
diff changeset
1202 }
21
d1bb7b365816 Fixed dynamic strings in selections (Fuko Pranks for instance)
thib
parents: 13
diff changeset
1203 str2[i*2] = 0;*/
d1bb7b365816 Fixed dynamic strings in selections (Fuko Pranks for instance)
thib
parents: 13
diff changeset
1204 text += strheap + info.value;
0
223b71206888 Initial import
thib
parents:
diff changeset
1205 }
223b71206888 Initial import
thib
parents:
diff changeset
1206 } else { SetError(); break;}
223b71206888 Initial import
thib
parents:
diff changeset
1207 }
223b71206888 Initial import
thib
parents:
diff changeset
1208 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1209 /* @@@ */
223b71206888 Initial import
thib
parents:
diff changeset
1210 /* °ìÃפ·¤Ê¤¤¾ì¹ç¤¬¤¢¤ë¤Î¤Ç¥³¥á¥ó¥È¥¢¥¦¥È */
223b71206888 Initial import
thib
parents:
diff changeset
1211 // if (arg_count != argc) SetError();
223b71206888 Initial import
thib
parents:
diff changeset
1212 dprintf("\n}\n");
223b71206888 Initial import
thib
parents:
diff changeset
1213 }
223b71206888 Initial import
thib
parents:
diff changeset
1214
223b71206888 Initial import
thib
parents:
diff changeset
1215 void Cmd::GetCmd(Flags& flags_orig, const char*& d ) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1216 if (d == NULL) { SetError(); return;}
0
223b71206888 Initial import
thib
parents:
diff changeset
1217 if (cmd_type != CMD_NOP) return;
223b71206888 Initial import
thib
parents:
diff changeset
1218
223b71206888 Initial import
thib
parents:
diff changeset
1219 cmdstr[0] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1220 rawdata = d;
223b71206888 Initial import
thib
parents:
diff changeset
1221 if (*d == 0x23) { /* ¥³¥Þ¥ó¥É */
223b71206888 Initial import
thib
parents:
diff changeset
1222 cmd_type = CMD_OTHER;
223b71206888 Initial import
thib
parents:
diff changeset
1223 cmd1 = *(unsigned const char*)(d+1);
223b71206888 Initial import
thib
parents:
diff changeset
1224 cmd2 = *(unsigned const char*)(d+2);
223b71206888 Initial import
thib
parents:
diff changeset
1225 cmd3 = read_little_endian_short(d+3);
223b71206888 Initial import
thib
parents:
diff changeset
1226 argc = read_little_endian_short(d+5);
223b71206888 Initial import
thib
parents:
diff changeset
1227 cmd4 = *(unsigned const char*)(d+7);
223b71206888 Initial import
thib
parents:
diff changeset
1228 d += 8;
223b71206888 Initial import
thib
parents:
diff changeset
1229 /* verbose */
223b71206888 Initial import
thib
parents:
diff changeset
1230 // dprintf(" 0x23 - cmd %02x-%02x:%04x:%02x[%2d] \n",cmd1,cmd2,cmd3,cmd4,argc);
29
d229cce98f50 * no more (or, at least, less) duplicate code between scn2kdump and the rest
thib
parents: 21
diff changeset
1231 sprintf(cmdstr, "%02x-%02x:%04x:%02x : %s",cmd1,cmd2,cmd3,cmd4, CmdDescr(cmd1,cmd2,cmd3,cmd4));
0
223b71206888 Initial import
thib
parents:
diff changeset
1232 /* °ú¿ô¤òÆÀ¤ë */
223b71206888 Initial import
thib
parents:
diff changeset
1233 /* Æüì°ú¿ô¤Î¤â¤Î */
223b71206888 Initial import
thib
parents:
diff changeset
1234 int is_special = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1235 if (cmd1 == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1236 if (cmd2 == 1) {
223b71206888 Initial import
thib
parents:
diff changeset
1237 int jump_arg = -1;
223b71206888 Initial import
thib
parents:
diff changeset
1238 if (cmd3 == 0 || cmd3 == 5) {
223b71206888 Initial import
thib
parents:
diff changeset
1239 /* gosub / goto */
223b71206888 Initial import
thib
parents:
diff changeset
1240 jump_arg =read_little_endian_int(d);
223b71206888 Initial import
thib
parents:
diff changeset
1241 d += 4;
223b71206888 Initial import
thib
parents:
diff changeset
1242 if (cmd3 == 0)
223b71206888 Initial import
thib
parents:
diff changeset
1243 dprintf("\tjmp -> %d\n", jump_arg);
223b71206888 Initial import
thib
parents:
diff changeset
1244 else /* cmd3 == 5 */
223b71206888 Initial import
thib
parents:
diff changeset
1245 dprintf("\tcall -> %d\n", jump_arg);
223b71206888 Initial import
thib
parents:
diff changeset
1246 is_special = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1247 } else if (cmd3 == 1 || cmd3 == 2) {
223b71206888 Initial import
thib
parents:
diff changeset
1248 /* conditional jump (if / unless) */
223b71206888 Initial import
thib
parents:
diff changeset
1249 if (*d++ != 0x28) { SetError(); return;}
223b71206888 Initial import
thib
parents:
diff changeset
1250 dprintf("\t");
223b71206888 Initial import
thib
parents:
diff changeset
1251 int cond = GetExpressionCond(d);
223b71206888 Initial import
thib
parents:
diff changeset
1252 if (cmd3 == 1) cond = !cond; // µÕ¤Ë¤Ê¤ë
223b71206888 Initial import
thib
parents:
diff changeset
1253 if (*d++ != 0x29) { SetError(); return; }
223b71206888 Initial import
thib
parents:
diff changeset
1254 int jumpto = read_little_endian_int(d);
223b71206888 Initial import
thib
parents:
diff changeset
1255 d += 4;
223b71206888 Initial import
thib
parents:
diff changeset
1256 dprintf("-> %d\n", jumpto);
223b71206888 Initial import
thib
parents:
diff changeset
1257 if (! cond) jump_arg = jumpto; /* condition ¤¬Ëþ¤¿¤µ¤ì¤Ê¤¤¾ì¹ç¡¢¥¸¥ã¥ó¥× */
223b71206888 Initial import
thib
parents:
diff changeset
1258 is_special = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1259 } else if (cmd3 == 4) {
223b71206888 Initial import
thib
parents:
diff changeset
1260 /* switch to */
223b71206888 Initial import
thib
parents:
diff changeset
1261 jump_arg = GetSwitch(d);
223b71206888 Initial import
thib
parents:
diff changeset
1262 is_special = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1263 } else if (cmd3 == 8 || cmd3 == 3) {
223b71206888 Initial import
thib
parents:
diff changeset
1264 /* switch to */
223b71206888 Initial import
thib
parents:
diff changeset
1265 jump_arg = GetSimpleSwitch(d);
223b71206888 Initial import
thib
parents:
diff changeset
1266 is_special = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1267 } else if (cmd3 == 16) { // call with parameters
223b71206888 Initial import
thib
parents:
diff changeset
1268 GetArgs(d);
223b71206888 Initial import
thib
parents:
diff changeset
1269 jump_arg = read_little_endian_int(d);
223b71206888 Initial import
thib
parents:
diff changeset
1270 d += 4;
223b71206888 Initial import
thib
parents:
diff changeset
1271 is_special = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1272 } else goto retry;
223b71206888 Initial import
thib
parents:
diff changeset
1273 if (jump_arg == -1) {
223b71206888 Initial import
thib
parents:
diff changeset
1274 cmd_type = CMD_NOP;
223b71206888 Initial import
thib
parents:
diff changeset
1275 }
223b71206888 Initial import
thib
parents:
diff changeset
1276 else {
223b71206888 Initial import
thib
parents:
diff changeset
1277 cmd_type = CMD_JMP;
223b71206888 Initial import
thib
parents:
diff changeset
1278 args.push_back(VarInfo(jump_arg));
223b71206888 Initial import
thib
parents:
diff changeset
1279 }
223b71206888 Initial import
thib
parents:
diff changeset
1280 } else if (cmd2 == 2 && (cmd3 == 0 || cmd3 == 1 || cmd3 == 2 || cmd3 == 3 || cmd3 == 0x0d) ) {
223b71206888 Initial import
thib
parents:
diff changeset
1281 /* selection */
223b71206888 Initial import
thib
parents:
diff changeset
1282 GetSelection(d);
223b71206888 Initial import
thib
parents:
diff changeset
1283 is_special = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1284 }
223b71206888 Initial import
thib
parents:
diff changeset
1285 }
223b71206888 Initial import
thib
parents:
diff changeset
1286 retry:
223b71206888 Initial import
thib
parents:
diff changeset
1287 /* °ìÈÌ°ú¿ô¤Î¤â¤Î */
223b71206888 Initial import
thib
parents:
diff changeset
1288 if (!is_special) {
29
d229cce98f50 * no more (or, at least, less) duplicate code between scn2kdump and the rest
thib
parents: 21
diff changeset
1289 dprintf(" 0x23 - cmd %02x-%02x:%04x:%02x[%2d] : %s\n",cmd1,cmd2,cmd3,cmd4,argc,CmdDescr(cmd1,cmd2,cmd3,cmd4));
0
223b71206888 Initial import
thib
parents:
diff changeset
1290 dprintf("\t");
223b71206888 Initial import
thib
parents:
diff changeset
1291 if (cmd1 == 1 && cmd2 == 0x22 && (cmd3 == 0xc1c || cmd3 == 0x835)) GetArgsSpecial(3, d);
223b71206888 Initial import
thib
parents:
diff changeset
1292 else if (cmd1 == 1 && cmd2 == 0x0b && cmd3 == 0x65) GetArgsSpecial(0, d);
223b71206888 Initial import
thib
parents:
diff changeset
1293 else if (cmd1 == 1 && cmd2 == 0x15 && cmd3 == 0x28) GetArgsSpecial(0, d);
223b71206888 Initial import
thib
parents:
diff changeset
1294 else if (cmd1 == 1 && cmd2 == 4 && (cmd3 == 0x26c || cmd3 == 0x26d || cmd3 == 0x270 || cmd3 == 0x276)) GetArgsSpecial(0, d);
223b71206888 Initial import
thib
parents:
diff changeset
1295 else if (cmd1 == 1 && cmd2 == 4 && cmd3 == 0x586) GetArgsSpecial(1, d);
43
01aa5ddf7dc8 A lot of very minor improvements (deleted some unused variables, and other things like that...)
thib
parents: 29
diff changeset
1296 else if (cmd1 == 1 && ((cmd2 == 0x21 && cmd3 == 0x4b) || (cmd2 == 0x28 && cmd3 == 0x64))) GetArgsSpecial(2,d);
0
223b71206888 Initial import
thib
parents:
diff changeset
1297 else GetArgs(d);
223b71206888 Initial import
thib
parents:
diff changeset
1298 dprintf("\n");
223b71206888 Initial import
thib
parents:
diff changeset
1299
223b71206888 Initial import
thib
parents:
diff changeset
1300 }
223b71206888 Initial import
thib
parents:
diff changeset
1301 } else if (*d == 0x24) { /* ÂåÆþ±é»» */
223b71206888 Initial import
thib
parents:
diff changeset
1302 if (d[1] == 0x12 || d[2] != 0x5b) SetError();
223b71206888 Initial import
thib
parents:
diff changeset
1303 dprintf("expr: ");
223b71206888 Initial import
thib
parents:
diff changeset
1304 sprintf(cmdstr, "expr");
223b71206888 Initial import
thib
parents:
diff changeset
1305
223b71206888 Initial import
thib
parents:
diff changeset
1306 VarInfo info;
223b71206888 Initial import
thib
parents:
diff changeset
1307 int value = GetLeftToken(d, info);
223b71206888 Initial import
thib
parents:
diff changeset
1308 if (d[0] != 0x5c) SetError();
223b71206888 Initial import
thib
parents:
diff changeset
1309 int type = d[1];
223b71206888 Initial import
thib
parents:
diff changeset
1310 if (type < 20 || type > 30) SetError();
223b71206888 Initial import
thib
parents:
diff changeset
1311 else dprintf("%s",op_str[type]);
223b71206888 Initial import
thib
parents:
diff changeset
1312 d += 2;
223b71206888 Initial import
thib
parents:
diff changeset
1313 int value2 = GetExpression(d);
223b71206888 Initial import
thib
parents:
diff changeset
1314 // ÂåÆþ¾ðÊó¤òËä¤á¹þ¤à
223b71206888 Initial import
thib
parents:
diff changeset
1315 if (type != 30) value2 = eval(value, type-20, value2);
223b71206888 Initial import
thib
parents:
diff changeset
1316 cmd_type = CMD_FLAGS;
223b71206888 Initial import
thib
parents:
diff changeset
1317 args.push_back(info);
223b71206888 Initial import
thib
parents:
diff changeset
1318 args.push_back(value2);
223b71206888 Initial import
thib
parents:
diff changeset
1319 dprintf("\n");
223b71206888 Initial import
thib
parents:
diff changeset
1320 } else if (StrType(d)) { /* ʸ»ú½ÐÎÏ */
223b71206888 Initial import
thib
parents:
diff changeset
1321 VarInfo info;
223b71206888 Initial import
thib
parents:
diff changeset
1322 info.type = TYPE_STR;
223b71206888 Initial import
thib
parents:
diff changeset
1323 info.value = GetString(d);
223b71206888 Initial import
thib
parents:
diff changeset
1324 args.push_back(info);
223b71206888 Initial import
thib
parents:
diff changeset
1325 cmd_type = CMD_TEXT;
223b71206888 Initial import
thib
parents:
diff changeset
1326 dprintf("\n");
223b71206888 Initial import
thib
parents:
diff changeset
1327 } else if (*d == 0x0a || *d == 0x40 || *d == 0x21) { /* ¥Ç¥Ð¥Ã¥°Íѥǡ¼¥¿¤È´ûÆɥե饰 */
223b71206888 Initial import
thib
parents:
diff changeset
1328 cmd_type = CMD_NOP;
223b71206888 Initial import
thib
parents:
diff changeset
1329 if (*d == 0x0a) {
223b71206888 Initial import
thib
parents:
diff changeset
1330 dprintf("line ");
223b71206888 Initial import
thib
parents:
diff changeset
1331 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1332 int l;
223b71206888 Initial import
thib
parents:
diff changeset
1333 if (system_version == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1334 l = read_little_endian_int(d);
223b71206888 Initial import
thib
parents:
diff changeset
1335 d += 4;
223b71206888 Initial import
thib
parents:
diff changeset
1336 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1337 l = read_little_endian_short(d);
223b71206888 Initial import
thib
parents:
diff changeset
1338 d += 2;
223b71206888 Initial import
thib
parents:
diff changeset
1339 }
223b71206888 Initial import
thib
parents:
diff changeset
1340 dprintf("%d\n", l);
223b71206888 Initial import
thib
parents:
diff changeset
1341 } else { /* 0x40, 0x21 */
223b71206888 Initial import
thib
parents:
diff changeset
1342 // ´ûÆÉ¥Þ¡¼¥«¡¼¤é¤·¤¤¡£¥¨¥ó¥È¥ê¡¼¥Ý¥¤¥ó¥È¤È¥»¡¼¥Ö¥Ý¥¤¥ó¥È¤â»È¤ï¤ì¤ë¡£
223b71206888 Initial import
thib
parents:
diff changeset
1343 // RealLive 1.2.5¤«¤é¡¢0x40¤Ï¥»¡¼¥Ö¥Ý¥¤¥ó¥È¡¢0x21¤Ï¥¨¥ó¥È¥ê¡¼¥Ý¥¤¥ó¥È¡£
223b71206888 Initial import
thib
parents:
diff changeset
1344 // 1.2.5°ÊÁ°¡¢¤É¤Á¤é¤â0x40¤¬»È¤ï¤ì¤ë¡£
223b71206888 Initial import
thib
parents:
diff changeset
1345 int kidoku_index;
223b71206888 Initial import
thib
parents:
diff changeset
1346 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1347 if (system_version == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1348 kidoku_index = read_little_endian_int(d);
223b71206888 Initial import
thib
parents:
diff changeset
1349 d += 4;
223b71206888 Initial import
thib
parents:
diff changeset
1350 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1351 kidoku_index = read_little_endian_short(d);
223b71206888 Initial import
thib
parents:
diff changeset
1352 d += 2;
223b71206888 Initial import
thib
parents:
diff changeset
1353 }
223b71206888 Initial import
thib
parents:
diff changeset
1354 dprintf("kidoku marker %d\n", kidoku_index);
223b71206888 Initial import
thib
parents:
diff changeset
1355 // text_readflag¤Ï¡¢¤³¤Îkidoku_index¤ò»È¤Ã¤¿¤éÎɤ¤¤«¤Ê¡£
223b71206888 Initial import
thib
parents:
diff changeset
1356 }
223b71206888 Initial import
thib
parents:
diff changeset
1357 } else if (*d == 0x2c) { /* ??? */
223b71206888 Initial import
thib
parents:
diff changeset
1358 dprintf("commd;0x2c\n"); // conditional jump ¤Î¹Ô¤­Àè¤Ë¤è¤¯¤¢¤ë¤é¤·¤¤¡Ê¾ï¤Ë¡¢¤«¤Ï¤ï¤«¤é¤Ê¤¤¡Ë
223b71206888 Initial import
thib
parents:
diff changeset
1359 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1360 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1361 SetError();
223b71206888 Initial import
thib
parents:
diff changeset
1362 }
223b71206888 Initial import
thib
parents:
diff changeset
1363 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1364
0
223b71206888 Initial import
thib
parents:
diff changeset
1365 void Cmd::clear(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1366 cmd_type = CMD_NOP;
223b71206888 Initial import
thib
parents:
diff changeset
1367 ResetString();
223b71206888 Initial import
thib
parents:
diff changeset
1368 args.clear();
223b71206888 Initial import
thib
parents:
diff changeset
1369 errorflag = false;
223b71206888 Initial import
thib
parents:
diff changeset
1370 pos = -1;
223b71206888 Initial import
thib
parents:
diff changeset
1371 }
223b71206888 Initial import
thib
parents:
diff changeset
1372
223b71206888 Initial import
thib
parents:
diff changeset
1373 char Cmd::strtype[256] = {
223b71206888 Initial import
thib
parents:
diff changeset
1374 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* +00 */
223b71206888 Initial import
thib
parents:
diff changeset
1375 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* +10 */ // 0123456789ABCDEF
223b71206888 Initial import
thib
parents:
diff changeset
1376 1,0,3,0, 0,0,0,1, 0,0,0,0, 0,1,1,0, /* +20 */ // !"#$%&'()*+,-./
223b71206888 Initial import
thib
parents:
diff changeset
1377 1,1,1,1, 1,1,1,1, 1,1,1,0, 0,0,0,1, /* +30 */ // 0123456789:;<=>?
223b71206888 Initial import
thib
parents:
diff changeset
1378 0,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, /* +40 */ // @ABCDEFGHIJKLMNO
223b71206888 Initial import
thib
parents:
diff changeset
1379 1,1,1,1, 1,1,1,1, 1,1,1,0, 0,0,0,1, /* +50 */ // PQRSTUVWXYZ[\]^_
223b71206888 Initial import
thib
parents:
diff changeset
1380 0,0,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, /* +60 */ // `abcdefghijklmno
223b71206888 Initial import
thib
parents:
diff changeset
1381 1,1,1,1, 1,1,1,1, 1,1,1,1, 0,0,0,0, /* +70 */ // pqrstuvwxyz{|}~
223b71206888 Initial import
thib
parents:
diff changeset
1382 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, /* +80 */
223b71206888 Initial import
thib
parents:
diff changeset
1383 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, /* +90 */
223b71206888 Initial import
thib
parents:
diff changeset
1384 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* +A0 */
223b71206888 Initial import
thib
parents:
diff changeset
1385 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* +B0 */
223b71206888 Initial import
thib
parents:
diff changeset
1386 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* +C0 */
223b71206888 Initial import
thib
parents:
diff changeset
1387 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* +D0 */
223b71206888 Initial import
thib
parents:
diff changeset
1388 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, /* +E0 */
223b71206888 Initial import
thib
parents:
diff changeset
1389 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,0,0 /* +F0 */
223b71206888 Initial import
thib
parents:
diff changeset
1390 };
223b71206888 Initial import
thib
parents:
diff changeset
1391
223b71206888 Initial import
thib
parents:
diff changeset
1392 int Cmd::GetString(const char*& d) {
223b71206888 Initial import
thib
parents:
diff changeset
1393 int retnum = -1;
223b71206888 Initial import
thib
parents:
diff changeset
1394 bool quote_flag = false;
223b71206888 Initial import
thib
parents:
diff changeset
1395 int stype;
223b71206888 Initial import
thib
parents:
diff changeset
1396 retnum = strend;
223b71206888 Initial import
thib
parents:
diff changeset
1397 while(1) {
223b71206888 Initial import
thib
parents:
diff changeset
1398 if (*d == '\\') {
223b71206888 Initial import
thib
parents:
diff changeset
1399 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1400 strheap[strend++] = *d++;
223b71206888 Initial import
thib
parents:
diff changeset
1401 } else if (*d == '"') {
223b71206888 Initial import
thib
parents:
diff changeset
1402 if (quote_flag) quote_flag = false;
223b71206888 Initial import
thib
parents:
diff changeset
1403 else quote_flag = true;
223b71206888 Initial import
thib
parents:
diff changeset
1404 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1405 } else if (quote_flag) {
223b71206888 Initial import
thib
parents:
diff changeset
1406 strheap[strend++] = *d++;
43
01aa5ddf7dc8 A lot of very minor improvements (deleted some unused variables, and other things like that...)
thib
parents: 29
diff changeset
1407 } else if ((stype = StrType(d))) {
0
223b71206888 Initial import
thib
parents:
diff changeset
1408 strheap[strend++] = *d++;
223b71206888 Initial import
thib
parents:
diff changeset
1409 if (stype == 2) strheap[strend++] = *d++;
223b71206888 Initial import
thib
parents:
diff changeset
1410 } else break;
223b71206888 Initial import
thib
parents:
diff changeset
1411 }
223b71206888 Initial import
thib
parents:
diff changeset
1412 strheap[strend++] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1413 dprintf("\"%s\"", strheap + retnum);
223b71206888 Initial import
thib
parents:
diff changeset
1414 if (strend >= STRHEAP_SIZE) {
223b71206888 Initial import
thib
parents:
diff changeset
1415 dprintf("Error: string heap overflow\n");
223b71206888 Initial import
thib
parents:
diff changeset
1416 }
223b71206888 Initial import
thib
parents:
diff changeset
1417 return retnum;
223b71206888 Initial import
thib
parents:
diff changeset
1418 }
223b71206888 Initial import
thib
parents:
diff changeset
1419
223b71206888 Initial import
thib
parents:
diff changeset
1420 int Cmd::CopyString(const char* d) {
223b71206888 Initial import
thib
parents:
diff changeset
1421 int retnum = strend;
223b71206888 Initial import
thib
parents:
diff changeset
1422 int len = strlen(d);
223b71206888 Initial import
thib
parents:
diff changeset
1423 memcpy(strheap+strend, d, len+1);
223b71206888 Initial import
thib
parents:
diff changeset
1424 strend += len+1;
223b71206888 Initial import
thib
parents:
diff changeset
1425 d += len+1;
223b71206888 Initial import
thib
parents:
diff changeset
1426 return retnum;
223b71206888 Initial import
thib
parents:
diff changeset
1427 }
223b71206888 Initial import
thib
parents:
diff changeset
1428
223b71206888 Initial import
thib
parents:
diff changeset
1429 int Cmd::StrVar(int type, int var_num) {
223b71206888 Initial import
thib
parents:
diff changeset
1430 int retnum = strend;
223b71206888 Initial import
thib
parents:
diff changeset
1431 flags.Str(type, var_num, strheap+strend, STRHEAP_SIZE-strend);
223b71206888 Initial import
thib
parents:
diff changeset
1432 strend += strlen(strheap+strend)+1;
223b71206888 Initial import
thib
parents:
diff changeset
1433 return retnum;
223b71206888 Initial import
thib
parents:
diff changeset
1434 }
223b71206888 Initial import
thib
parents:
diff changeset
1435
223b71206888 Initial import
thib
parents:
diff changeset
1436 void Cmd::SetSysvar(int n, int val) {
223b71206888 Initial import
thib
parents:
diff changeset
1437 VarInfo info;
223b71206888 Initial import
thib
parents:
diff changeset
1438 if (cmd_type != CMD_SYSVAR) {
223b71206888 Initial import
thib
parents:
diff changeset
1439 args.clear();
223b71206888 Initial import
thib
parents:
diff changeset
1440 }
223b71206888 Initial import
thib
parents:
diff changeset
1441 cmd_type = CMD_SYSVAR;
223b71206888 Initial import
thib
parents:
diff changeset
1442
223b71206888 Initial import
thib
parents:
diff changeset
1443 info.type = TYPE_SYS;
223b71206888 Initial import
thib
parents:
diff changeset
1444 info.number = n;
223b71206888 Initial import
thib
parents:
diff changeset
1445 info.value = val;
223b71206888 Initial import
thib
parents:
diff changeset
1446 args.push_back(info);
223b71206888 Initial import
thib
parents:
diff changeset
1447 }
223b71206888 Initial import
thib
parents:
diff changeset
1448 void Cmd::SetFlagvar(VarInfo info, int val) {
223b71206888 Initial import
thib
parents:
diff changeset
1449 if (cmd_type != CMD_SYSVAR) {
223b71206888 Initial import
thib
parents:
diff changeset
1450 args.clear();
223b71206888 Initial import
thib
parents:
diff changeset
1451 }
223b71206888 Initial import
thib
parents:
diff changeset
1452 cmd_type = CMD_SYSVAR;
223b71206888 Initial import
thib
parents:
diff changeset
1453
223b71206888 Initial import
thib
parents:
diff changeset
1454 info.value = val;
223b71206888 Initial import
thib
parents:
diff changeset
1455 args.push_back(info);
223b71206888 Initial import
thib
parents:
diff changeset
1456 }
223b71206888 Initial import
thib
parents:
diff changeset
1457
223b71206888 Initial import
thib
parents:
diff changeset
1458 void Cmd::SetStrvar(VarInfo info, const string& s) {
223b71206888 Initial import
thib
parents:
diff changeset
1459 if (cmd_type != CMD_SYSVAR) {
223b71206888 Initial import
thib
parents:
diff changeset
1460 args.clear();
223b71206888 Initial import
thib
parents:
diff changeset
1461 }
223b71206888 Initial import
thib
parents:
diff changeset
1462
223b71206888 Initial import
thib
parents:
diff changeset
1463 cmd_type = CMD_SYSVAR;
223b71206888 Initial import
thib
parents:
diff changeset
1464 const char* ss = s.c_str();
223b71206888 Initial import
thib
parents:
diff changeset
1465 info.value = CopyString(ss);
223b71206888 Initial import
thib
parents:
diff changeset
1466 args.push_back(info);
223b71206888 Initial import
thib
parents:
diff changeset
1467 }
223b71206888 Initial import
thib
parents:
diff changeset
1468
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1469
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1470 const char* Cmd::Str(const VarInfo& info) const {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1471 if (info.type != TYPE_STR && info.type != TYPE_VARSTR && info.type != TYPE_VARLOCSTR && info.type != TYPE_VARSYSSTR)
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1472 return "";
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1473 int pt = info.value;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1474 if (pt < 0 || pt >= STRHEAP_SIZE) return "";
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1475 return strheap + pt;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1476 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1477
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1478 int Cmd::AddStr(char* s) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1479 // 1-0a-0064 ¤Ï¤³¤¦¤¤¤¦¤â¤Î¤¬É¬Íפ餷¤¤
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1480 int start = strend;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1481 while (*s) strheap[strend++] = *s++;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1482 strheap[strend++] = 0;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1483 return start;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1484 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1485
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1486
0
223b71206888 Initial import
thib
parents:
diff changeset
1487 void Cmd::read(const CmdSimplified& from) {
223b71206888 Initial import
thib
parents:
diff changeset
1488 errorflag = false;
223b71206888 Initial import
thib
parents:
diff changeset
1489 ResetString();
223b71206888 Initial import
thib
parents:
diff changeset
1490
223b71206888 Initial import
thib
parents:
diff changeset
1491 cmd_type = Cmdtype(from.type);
223b71206888 Initial import
thib
parents:
diff changeset
1492 cmd1 = from.cmd1;
223b71206888 Initial import
thib
parents:
diff changeset
1493 cmd2 = from.cmd2;
223b71206888 Initial import
thib
parents:
diff changeset
1494 cmd3 = from.cmd3;
223b71206888 Initial import
thib
parents:
diff changeset
1495 cmd4 = from.cmd4;
223b71206888 Initial import
thib
parents:
diff changeset
1496 argc = from.argc;
223b71206888 Initial import
thib
parents:
diff changeset
1497 /* args ¤ÎÆɤ߹þ¤ß */
223b71206888 Initial import
thib
parents:
diff changeset
1498 args.clear();
223b71206888 Initial import
thib
parents:
diff changeset
1499 char* d = from.args;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1500 if (d == NULL) return;
0
223b71206888 Initial import
thib
parents:
diff changeset
1501 while(*d != TYPE_END) {
223b71206888 Initial import
thib
parents:
diff changeset
1502 VarInfo info;
223b71206888 Initial import
thib
parents:
diff changeset
1503 switch(*d) {
223b71206888 Initial import
thib
parents:
diff changeset
1504 case TYPE_VAL:
223b71206888 Initial import
thib
parents:
diff changeset
1505 info.type = TYPE_VAL;
223b71206888 Initial import
thib
parents:
diff changeset
1506 info.number = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1507 info.value = read_little_endian_int(d+1);
223b71206888 Initial import
thib
parents:
diff changeset
1508 d += 5;
223b71206888 Initial import
thib
parents:
diff changeset
1509 args.push_back(info);
223b71206888 Initial import
thib
parents:
diff changeset
1510 break;
223b71206888 Initial import
thib
parents:
diff changeset
1511 case TYPE_STR:
223b71206888 Initial import
thib
parents:
diff changeset
1512 info.type = TYPE_STR;
223b71206888 Initial import
thib
parents:
diff changeset
1513 info.number = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1514 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1515 info.value = CopyString( d);
223b71206888 Initial import
thib
parents:
diff changeset
1516 d += strlen(d)+1;
223b71206888 Initial import
thib
parents:
diff changeset
1517 args.push_back(info);
223b71206888 Initial import
thib
parents:
diff changeset
1518 break;
223b71206888 Initial import
thib
parents:
diff changeset
1519 default:
223b71206888 Initial import
thib
parents:
diff changeset
1520 fprintf(stderr,"Cmd::read: Invalid Load Data\n");
223b71206888 Initial import
thib
parents:
diff changeset
1521 *d = TYPE_END;
223b71206888 Initial import
thib
parents:
diff changeset
1522 }
223b71206888 Initial import
thib
parents:
diff changeset
1523 }
223b71206888 Initial import
thib
parents:
diff changeset
1524 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1525
0
223b71206888 Initial import
thib
parents:
diff changeset
1526 void Cmd::write(CmdSimplified& to, char*& buffer) const {
223b71206888 Initial import
thib
parents:
diff changeset
1527 /*
223b71206888 Initial import
thib
parents:
diff changeset
1528 if (cmd_type != CMD_OTHER) {
223b71206888 Initial import
thib
parents:
diff changeset
1529 fprintf(stderr,"Cmd::write: Invalid Cmd during Saving Data\n");
223b71206888 Initial import
thib
parents:
diff changeset
1530 to.cmd1 = 0; to.cmd2 = 0; to.cmd3 = 0; to.cmd4 = 0; to.argc = 0; to.args = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1531 return;
223b71206888 Initial import
thib
parents:
diff changeset
1532 }
223b71206888 Initial import
thib
parents:
diff changeset
1533 */
223b71206888 Initial import
thib
parents:
diff changeset
1534 to.type = cmd_type;
223b71206888 Initial import
thib
parents:
diff changeset
1535 to.cmd1 = cmd1;
223b71206888 Initial import
thib
parents:
diff changeset
1536 to.cmd2 = cmd2;
223b71206888 Initial import
thib
parents:
diff changeset
1537 to.cmd3 = cmd3;
223b71206888 Initial import
thib
parents:
diff changeset
1538 to.cmd4 = cmd4;
223b71206888 Initial import
thib
parents:
diff changeset
1539 to.argc = argc;
223b71206888 Initial import
thib
parents:
diff changeset
1540 /* args ¤Î½ñ¤­¹þ¤ß */
223b71206888 Initial import
thib
parents:
diff changeset
1541 if (args.empty()) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1542 to.args = NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
1543 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1544 to.args = buffer;
223b71206888 Initial import
thib
parents:
diff changeset
1545 char* d = to.args;
223b71206888 Initial import
thib
parents:
diff changeset
1546 vector<VarInfo>::const_iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1547 for (it = args.begin(); it != args.end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
1548 int type = it->type;
223b71206888 Initial import
thib
parents:
diff changeset
1549 if ( (type >= 0 && type < 7) || type == TYPE_VAL || type == char(TYPE_SYS)) { // digits
223b71206888 Initial import
thib
parents:
diff changeset
1550 *d++ = TYPE_VAL;
223b71206888 Initial import
thib
parents:
diff changeset
1551 write_little_endian_int(d, it->value);
223b71206888 Initial import
thib
parents:
diff changeset
1552 d += 4;
223b71206888 Initial import
thib
parents:
diff changeset
1553 } else if (type == TYPE_VARSTR || type == TYPE_VARSYSSTR || type == TYPE_VARLOCSTR || type == TYPE_STR) { // string
223b71206888 Initial import
thib
parents:
diff changeset
1554 *d++ = TYPE_STR;
223b71206888 Initial import
thib
parents:
diff changeset
1555 const char* s = Str(*it);
223b71206888 Initial import
thib
parents:
diff changeset
1556 int len = strlen(s);
223b71206888 Initial import
thib
parents:
diff changeset
1557 memcpy(d, s, len+1);
223b71206888 Initial import
thib
parents:
diff changeset
1558 d += len+1;
223b71206888 Initial import
thib
parents:
diff changeset
1559 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1560 fprintf(stderr,"Cmd::write: Invalid Cmd args during Saving Data\n");
223b71206888 Initial import
thib
parents:
diff changeset
1561 }
223b71206888 Initial import
thib
parents:
diff changeset
1562 }
223b71206888 Initial import
thib
parents:
diff changeset
1563 *d++ = TYPE_END;
223b71206888 Initial import
thib
parents:
diff changeset
1564 buffer = d;
223b71206888 Initial import
thib
parents:
diff changeset
1565 }
223b71206888 Initial import
thib
parents:
diff changeset
1566 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1567
0
223b71206888 Initial import
thib
parents:
diff changeset
1568 void CmdSimplified::copy(const CmdSimplified& from, char*& args_buffer) {
223b71206888 Initial import
thib
parents:
diff changeset
1569 *this = from;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1570 if (args == NULL) return;
0
223b71206888 Initial import
thib
parents:
diff changeset
1571 char* args_old = from.args;
223b71206888 Initial import
thib
parents:
diff changeset
1572 /* args ¤Î¥³¥Ô¡¼ */
223b71206888 Initial import
thib
parents:
diff changeset
1573 while(*args_old != TYPE_END) {
223b71206888 Initial import
thib
parents:
diff changeset
1574 if (*args_old == TYPE_VAL) {
223b71206888 Initial import
thib
parents:
diff changeset
1575 args_old += 5;
223b71206888 Initial import
thib
parents:
diff changeset
1576 } else { /* TYPE_STR */
223b71206888 Initial import
thib
parents:
diff changeset
1577 args_old += strlen(args_old)+1;
223b71206888 Initial import
thib
parents:
diff changeset
1578 }
223b71206888 Initial import
thib
parents:
diff changeset
1579 }
223b71206888 Initial import
thib
parents:
diff changeset
1580 args_old++;
223b71206888 Initial import
thib
parents:
diff changeset
1581 int args_len = args_old - from.args;
223b71206888 Initial import
thib
parents:
diff changeset
1582 memmove(args_buffer, from.args, args_len);
223b71206888 Initial import
thib
parents:
diff changeset
1583 args = args_buffer;
223b71206888 Initial import
thib
parents:
diff changeset
1584 args_buffer += args_len;
223b71206888 Initial import
thib
parents:
diff changeset
1585 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1586
0
223b71206888 Initial import
thib
parents:
diff changeset
1587 void CmdSimplified::Save(string& saveret) {
223b71206888 Initial import
thib
parents:
diff changeset
1588 char buf[1024];
223b71206888 Initial import
thib
parents:
diff changeset
1589 sprintf(buf, "%02x-%02x:%04x:%02x(%02d),", cmd1, cmd2, cmd3, cmd4, argc);
223b71206888 Initial import
thib
parents:
diff changeset
1590 saveret += buf;
223b71206888 Initial import
thib
parents:
diff changeset
1591
223b71206888 Initial import
thib
parents:
diff changeset
1592 /* args ¤Î¥³¥Ô¡¼ */
223b71206888 Initial import
thib
parents:
diff changeset
1593 char* d = args;
223b71206888 Initial import
thib
parents:
diff changeset
1594 while(d && *d != TYPE_END) {
223b71206888 Initial import
thib
parents:
diff changeset
1595 if (*d == TYPE_VAL) {
223b71206888 Initial import
thib
parents:
diff changeset
1596 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1597 sprintf(buf, "%d,", read_little_endian_int(d));
223b71206888 Initial import
thib
parents:
diff changeset
1598 d += 4;
223b71206888 Initial import
thib
parents:
diff changeset
1599 } else { /* TYPE_STR ¤È²¾Äê */
223b71206888 Initial import
thib
parents:
diff changeset
1600 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1601 if (strlen(d) > 1000) d[1000] = 0; // ¤¢¤ê¤¨¤Ê¤¤¡¦¡¦¡¦
223b71206888 Initial import
thib
parents:
diff changeset
1602 int i; int cnt = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1603 buf[cnt++] = '"';
223b71206888 Initial import
thib
parents:
diff changeset
1604 for (i=0; d[i] != 0; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1605 if (d[i] == '"') buf[cnt++] = '"';
223b71206888 Initial import
thib
parents:
diff changeset
1606 buf[cnt++] = d[i];
223b71206888 Initial import
thib
parents:
diff changeset
1607 }
223b71206888 Initial import
thib
parents:
diff changeset
1608 buf[cnt++]='"';
223b71206888 Initial import
thib
parents:
diff changeset
1609 buf[cnt++] = ',';
223b71206888 Initial import
thib
parents:
diff changeset
1610 buf[cnt++] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1611 d += strlen(d)+1;
223b71206888 Initial import
thib
parents:
diff changeset
1612 }
223b71206888 Initial import
thib
parents:
diff changeset
1613 saveret += buf;
223b71206888 Initial import
thib
parents:
diff changeset
1614 }
223b71206888 Initial import
thib
parents:
diff changeset
1615 saveret += 'E';
223b71206888 Initial import
thib
parents:
diff changeset
1616 }
223b71206888 Initial import
thib
parents:
diff changeset
1617
223b71206888 Initial import
thib
parents:
diff changeset
1618 void CmdSimplified::Load(const char* save, char*& args_buffer) {
223b71206888 Initial import
thib
parents:
diff changeset
1619 args = args_buffer;
223b71206888 Initial import
thib
parents:
diff changeset
1620
223b71206888 Initial import
thib
parents:
diff changeset
1621 type = CMD_OTHER;
223b71206888 Initial import
thib
parents:
diff changeset
1622 sscanf(save, "%02x-%02x:%04x:%02x(%02d),", &cmd1, &cmd2, &cmd3, &cmd4, &argc);
223b71206888 Initial import
thib
parents:
diff changeset
1623 save = strchr(save, ',');
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1624 if (save == NULL) {
0
223b71206888 Initial import
thib
parents:
diff changeset
1625 *args_buffer++ = TYPE_END;
223b71206888 Initial import
thib
parents:
diff changeset
1626 return;
223b71206888 Initial import
thib
parents:
diff changeset
1627 }
223b71206888 Initial import
thib
parents:
diff changeset
1628 save++;
223b71206888 Initial import
thib
parents:
diff changeset
1629 while(*save != 'E' && *save != '\n' && *save != '\0') {
223b71206888 Initial import
thib
parents:
diff changeset
1630 if (isdigit(*save)) {
223b71206888 Initial import
thib
parents:
diff changeset
1631 int v;
223b71206888 Initial import
thib
parents:
diff changeset
1632 sscanf(save,"%d,",&v);
223b71206888 Initial import
thib
parents:
diff changeset
1633 *args_buffer++ = TYPE_VAL;
223b71206888 Initial import
thib
parents:
diff changeset
1634 write_little_endian_int(args_buffer, v);
223b71206888 Initial import
thib
parents:
diff changeset
1635 args_buffer+= 4;
223b71206888 Initial import
thib
parents:
diff changeset
1636 save = strchr(save, ',');
223b71206888 Initial import
thib
parents:
diff changeset
1637 if (save) save++;
223b71206888 Initial import
thib
parents:
diff changeset
1638 } else { // *save == '"'
223b71206888 Initial import
thib
parents:
diff changeset
1639 save++;
223b71206888 Initial import
thib
parents:
diff changeset
1640 *args_buffer++ = TYPE_STR;
223b71206888 Initial import
thib
parents:
diff changeset
1641 while(1) {
223b71206888 Initial import
thib
parents:
diff changeset
1642 if (*save == 0) break;
223b71206888 Initial import
thib
parents:
diff changeset
1643 if (*save == '"') {
223b71206888 Initial import
thib
parents:
diff changeset
1644 if (save[1] != '"') break;
223b71206888 Initial import
thib
parents:
diff changeset
1645 save++;
223b71206888 Initial import
thib
parents:
diff changeset
1646 }
223b71206888 Initial import
thib
parents:
diff changeset
1647 *args_buffer++ = *save++;
223b71206888 Initial import
thib
parents:
diff changeset
1648 }
223b71206888 Initial import
thib
parents:
diff changeset
1649 save += 2;
223b71206888 Initial import
thib
parents:
diff changeset
1650 *args_buffer++ = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1651 }
223b71206888 Initial import
thib
parents:
diff changeset
1652 }
223b71206888 Initial import
thib
parents:
diff changeset
1653 *args_buffer++ = TYPE_END;
223b71206888 Initial import
thib
parents:
diff changeset
1654 }
223b71206888 Initial import
thib
parents:
diff changeset
1655
223b71206888 Initial import
thib
parents:
diff changeset
1656 #ifdef SCN_DUMP
223b71206888 Initial import
thib
parents:
diff changeset
1657 void usage(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1658 fprintf(stderr,"usage : scn2kdump [inputfile] [outputfile]\n");
223b71206888 Initial import
thib
parents:
diff changeset
1659 fprintf(stderr," inputfile: seen.txt(default)\n");
223b71206888 Initial import
thib
parents:
diff changeset
1660 fprintf(stderr," outputfile: seen.txt_out(default)\n");
223b71206888 Initial import
thib
parents:
diff changeset
1661 exit(-1);
223b71206888 Initial import
thib
parents:
diff changeset
1662 }
223b71206888 Initial import
thib
parents:
diff changeset
1663 int main(int argc, char** argv) {
223b71206888 Initial import
thib
parents:
diff changeset
1664 /* determine file names */
223b71206888 Initial import
thib
parents:
diff changeset
1665 bool verbose = false;
223b71206888 Initial import
thib
parents:
diff changeset
1666 char* inname = "seen.txt";
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1667 char* outname = NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
1668 if (argc > 2 && strcmp(argv[1],"-v") == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1669 int i; for (i=1; i<argc; i++) argv[i] = argv[i+1];
223b71206888 Initial import
thib
parents:
diff changeset
1670 argc--;
223b71206888 Initial import
thib
parents:
diff changeset
1671 verbose = true;
223b71206888 Initial import
thib
parents:
diff changeset
1672 }
223b71206888 Initial import
thib
parents:
diff changeset
1673 switch(argc) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1674 case 1: break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1675 case 2:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1676 inname = argv[1];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1677 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1678 case 3:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1679 inname = argv[1];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1680 outname = argv[2];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1681 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1682 default: usage();
0
223b71206888 Initial import
thib
parents:
diff changeset
1683 }
223b71206888 Initial import
thib
parents:
diff changeset
1684 /* open output file */
223b71206888 Initial import
thib
parents:
diff changeset
1685 FILE* outstream = stdout;
223b71206888 Initial import
thib
parents:
diff changeset
1686 /* create archive instance */
223b71206888 Initial import
thib
parents:
diff changeset
1687 SCN2kFILE archive(inname);
223b71206888 Initial import
thib
parents:
diff changeset
1688 archive.Init();
223b71206888 Initial import
thib
parents:
diff changeset
1689 if (archive.Deal() == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1690 fprintf(stderr,"Cannot open / Invalid archive file %s\n",inname);
223b71206888 Initial import
thib
parents:
diff changeset
1691 usage();
223b71206888 Initial import
thib
parents:
diff changeset
1692 }
223b71206888 Initial import
thib
parents:
diff changeset
1693 /* dump files */
223b71206888 Initial import
thib
parents:
diff changeset
1694 archive.InitList();
223b71206888 Initial import
thib
parents:
diff changeset
1695 char* fname;
223b71206888 Initial import
thib
parents:
diff changeset
1696 fprintf(stderr,"Dump start\n");
223b71206888 Initial import
thib
parents:
diff changeset
1697 int system_version = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1698 while( (fname = archive.ListItem()) != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1699 ARCINFO* info = archive.Find(fname,"");
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1700 if (info == NULL) continue;
0
223b71206888 Initial import
thib
parents:
diff changeset
1701 char* data = info->CopyRead();
223b71206888 Initial import
thib
parents:
diff changeset
1702 char* d = data;
223b71206888 Initial import
thib
parents:
diff changeset
1703 char* dend = d + info->Size();
223b71206888 Initial import
thib
parents:
diff changeset
1704 /* version ³Îǧ */
223b71206888 Initial import
thib
parents:
diff changeset
1705 if (read_little_endian_int(d) == 0x1cc) {
223b71206888 Initial import
thib
parents:
diff changeset
1706 system_version = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1707 } else if (read_little_endian_int(d) == 0x1d0) {
223b71206888 Initial import
thib
parents:
diff changeset
1708 system_version = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1709 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1710 continue;
223b71206888 Initial import
thib
parents:
diff changeset
1711 }
223b71206888 Initial import
thib
parents:
diff changeset
1712 if (read_little_endian_int(d+4) == 0x1adb2) ; // little busters!
223b71206888 Initial import
thib
parents:
diff changeset
1713 else if (read_little_endian_int(d+4) != 0x2712) continue;
223b71206888 Initial import
thib
parents:
diff changeset
1714 int header_size;
223b71206888 Initial import
thib
parents:
diff changeset
1715 if (system_version == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1716 header_size = 0x1cc + read_little_endian_int(d+0x20) * 4;
223b71206888 Initial import
thib
parents:
diff changeset
1717 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1718 header_size = read_little_endian_int(d+0x20);
223b71206888 Initial import
thib
parents:
diff changeset
1719 }
223b71206888 Initial import
thib
parents:
diff changeset
1720 d += header_size;
223b71206888 Initial import
thib
parents:
diff changeset
1721
223b71206888 Initial import
thib
parents:
diff changeset
1722 const char* dcur = d;
223b71206888 Initial import
thib
parents:
diff changeset
1723 const char* dstart = d;
223b71206888 Initial import
thib
parents:
diff changeset
1724 fprintf(stderr,"Dumping %s\n",fname);
223b71206888 Initial import
thib
parents:
diff changeset
1725 Flags flags;
223b71206888 Initial import
thib
parents:
diff changeset
1726 /* ºÇ½é¤«¤éºÇ¸å¤Þ¤Ç¥³¥Þ¥ó¥É¼èÆÀ -> ½ÐÎϤò·«¤êÊÖ¤¹ */
223b71206888 Initial import
thib
parents:
diff changeset
1727 while(dcur<dend) {
223b71206888 Initial import
thib
parents:
diff changeset
1728 const char* dprev = dcur;
223b71206888 Initial import
thib
parents:
diff changeset
1729 Cmd cmd(flags, system_version); cmd.ClearError();
223b71206888 Initial import
thib
parents:
diff changeset
1730
223b71206888 Initial import
thib
parents:
diff changeset
1731 /* end? */
223b71206888 Initial import
thib
parents:
diff changeset
1732 if (*dcur == -1) {
223b71206888 Initial import
thib
parents:
diff changeset
1733 /* 0xff x 32byte + 0x00 : end sign */
223b71206888 Initial import
thib
parents:
diff changeset
1734 int i; for (i=0; i<0x20; i++)
223b71206888 Initial import
thib
parents:
diff changeset
1735 if (dcur[i] != -1) break;
223b71206888 Initial import
thib
parents:
diff changeset
1736 if (i == 0x20 && dcur[i] == 0) break;
223b71206888 Initial import
thib
parents:
diff changeset
1737 }
223b71206888 Initial import
thib
parents:
diff changeset
1738 dprintf("%d : ",dcur-dstart);
223b71206888 Initial import
thib
parents:
diff changeset
1739 cmd.GetCmd(flags, dcur);
223b71206888 Initial import
thib
parents:
diff changeset
1740 if (cmd.IsError()) {
223b71206888 Initial import
thib
parents:
diff changeset
1741 fprintf(outstream, "Error at %6d\n",dprev-dstart);
223b71206888 Initial import
thib
parents:
diff changeset
1742 while(dcur < dend) {
223b71206888 Initial import
thib
parents:
diff changeset
1743 if (*dcur == 0x29 && dcur[1] == 0x0a) {dcur++;break;}
223b71206888 Initial import
thib
parents:
diff changeset
1744 dcur++;
223b71206888 Initial import
thib
parents:
diff changeset
1745 }
223b71206888 Initial import
thib
parents:
diff changeset
1746 dprev -= 2*16;
223b71206888 Initial import
thib
parents:
diff changeset
1747 int ilen = (dcur-dprev+15)/16;
223b71206888 Initial import
thib
parents:
diff changeset
1748 int i; for (i=0; i<ilen; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1749 fprintf(outstream, "%6d: ",dprev-dstart);
223b71206888 Initial import
thib
parents:
diff changeset
1750 int j; for (j=0; j<16; j++) {
223b71206888 Initial import
thib
parents:
diff changeset
1751 if (dprev >= dend) break;
223b71206888 Initial import
thib
parents:
diff changeset
1752 if (dprev < data) continue;
223b71206888 Initial import
thib
parents:
diff changeset
1753 fprintf(outstream, "%02x ",*(unsigned char*)(dprev));
223b71206888 Initial import
thib
parents:
diff changeset
1754 dprev++;
223b71206888 Initial import
thib
parents:
diff changeset
1755 }
223b71206888 Initial import
thib
parents:
diff changeset
1756 fprintf(outstream, "\n");
223b71206888 Initial import
thib
parents:
diff changeset
1757 }
223b71206888 Initial import
thib
parents:
diff changeset
1758 }
223b71206888 Initial import
thib
parents:
diff changeset
1759 }
223b71206888 Initial import
thib
parents:
diff changeset
1760 delete info;
223b71206888 Initial import
thib
parents:
diff changeset
1761 }
223b71206888 Initial import
thib
parents:
diff changeset
1762 return 0;
223b71206888 Initial import
thib
parents:
diff changeset
1763 }
223b71206888 Initial import
thib
parents:
diff changeset
1764 #endif
223b71206888 Initial import
thib
parents:
diff changeset
1765