annotate scn2k/scn2k_cmd.cc @ 47:5f548e5957a8

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