... | ... |
@@ -186,37 +186,39 @@ makereference(char *scope, char *label, Uint16 addr) |
186 | 186 |
return 1; |
187 | 187 |
} |
188 | 188 |
|
189 |
-static void |
|
189 |
+static int |
|
190 | 190 |
writebyte(Uint8 b) |
191 | 191 |
{ |
192 |
- if(p.ptr < TRIM) |
|
192 |
+ if(p.ptr < TRIM) { |
|
193 | 193 |
fprintf(stderr, "-- Writing in zero-page: %02x\n", b); |
194 |
+ return 0; |
|
195 |
+ } |
|
194 | 196 |
p.data[p.ptr++] = b; |
195 | 197 |
p.length = p.ptr; |
196 | 198 |
litlast = 0; |
199 |
+ return 1; |
|
197 | 200 |
} |
198 | 201 |
|
199 |
-static void |
|
202 |
+static int |
|
200 | 203 |
writeshort(Uint16 s, int lit) |
201 | 204 |
{ |
202 | 205 |
if(lit) |
203 |
- writebyte(findopcode("LIT2")); |
|
204 |
- writebyte(s >> 8); |
|
205 |
- writebyte(s & 0xff); |
|
206 |
+ if(!writebyte(findopcode("LIT2"))) return 0; |
|
207 |
+ return writebyte(s >> 8) && writebyte(s & 0xff); |
|
206 | 208 |
} |
207 | 209 |
|
208 |
-static void |
|
210 |
+static int |
|
209 | 211 |
writelitbyte(Uint8 b) |
210 | 212 |
{ |
211 | 213 |
if(litlast) { /* combine literals */ |
212 | 214 |
Uint8 hb = p.data[p.ptr - 1]; |
213 | 215 |
p.ptr -= 2; |
214 |
- writeshort((hb << 8) + b, 1); |
|
215 |
- return; |
|
216 |
+ return writeshort((hb << 8) + b, 1); |
|
216 | 217 |
} |
217 |
- writebyte(findopcode("LIT")); |
|
218 |
- writebyte(b); |
|
218 |
+ if(!writebyte(findopcode("LIT"))) return 0; |
|
219 |
+ if(!writebyte(b)) return 0; |
|
219 | 220 |
litlast = 1; |
221 |
+ return 1; |
|
220 | 222 |
} |
221 | 223 |
|
222 | 224 |
static int |
... | ... |
@@ -288,47 +290,52 @@ parse(char *w, FILE *f) |
288 | 290 |
case '#': /* literals hex */ |
289 | 291 |
if(!sihx(w + 1) || (slen(w) != 3 && slen(w) != 5)) |
290 | 292 |
return error("Invalid hex literal", w); |
291 |
- if(slen(w) == 3) |
|
292 |
- writelitbyte(shex(w + 1)); |
|
293 |
- else if(slen(w) == 5) |
|
294 |
- writeshort(shex(w + 1), 1); |
|
293 |
+ if(slen(w) == 3) { |
|
294 |
+ if(!writelitbyte(shex(w + 1))) return 0; |
|
295 |
+ } |
|
296 |
+ else if(slen(w) == 5) { |
|
297 |
+ if(!writeshort(shex(w + 1), 1)) return 0; |
|
298 |
+ } |
|
295 | 299 |
break; |
296 | 300 |
case '.': /* literal byte zero-page */ |
297 | 301 |
makereference(p.scope, w, p.ptr - litlast); |
298 |
- writelitbyte(0xff); |
|
302 |
+ if(!writelitbyte(0xff)) return 0; |
|
299 | 303 |
break; |
300 | 304 |
case ',': /* literal byte relative */ |
301 | 305 |
makereference(p.scope, w, p.ptr - litlast); |
302 |
- writelitbyte(0xff); |
|
306 |
+ if(!writelitbyte(0xff)) return 0; |
|
303 | 307 |
break; |
304 | 308 |
case ';': /* literal short absolute */ |
305 | 309 |
makereference(p.scope, w, p.ptr); |
306 |
- writeshort(0xffff, 1); |
|
310 |
+ if(!writeshort(0xffff, 1)) return 0; |
|
307 | 311 |
break; |
308 | 312 |
case ':': /* raw short absolute */ |
309 | 313 |
makereference(p.scope, w, p.ptr); |
310 |
- writeshort(0xffff, 0); |
|
314 |
+ if(!writeshort(0xffff, 0)) return 0; |
|
311 | 315 |
break; |
312 | 316 |
case '\'': /* raw char */ |
313 |
- writebyte((Uint8)w[1]); |
|
317 |
+ if(!writebyte((Uint8)w[1])) return 0; |
|
314 | 318 |
break; |
315 | 319 |
case '"': /* raw string */ |
316 | 320 |
i = 0; |
317 | 321 |
while((c = w[++i])) |
318 |
- writebyte(c); |
|
322 |
+ if(!writebyte(c)) return 0; |
|
319 | 323 |
break; |
320 | 324 |
case '[': break; /* ignored */ |
321 | 325 |
case ']': break; /* ignored */ |
322 | 326 |
default: |
323 | 327 |
/* opcode */ |
324 |
- if(findopcode(w) || scmp(w, "BRK", 4)) |
|
325 |
- writebyte(findopcode(w)); |
|
328 |
+ if(findopcode(w) || scmp(w, "BRK", 4)) { |
|
329 |
+ if(!writebyte(findopcode(w))) return 0; |
|
330 |
+ } |
|
326 | 331 |
/* raw byte */ |
327 |
- else if(sihx(w) && slen(w) == 2) |
|
328 |
- writebyte(shex(w)); |
|
332 |
+ else if(sihx(w) && slen(w) == 2) { |
|
333 |
+ if(!writebyte(shex(w))) return 0; |
|
334 |
+ } |
|
329 | 335 |
/* raw short */ |
330 |
- else if(sihx(w) && slen(w) == 4) |
|
331 |
- writeshort(shex(w), 0); |
|
336 |
+ else if(sihx(w) && slen(w) == 4) { |
|
337 |
+ if(!writeshort(shex(w), 0)) return 0; |
|
338 |
+ } |
|
332 | 339 |
/* macro */ |
333 | 340 |
else if((m = findmacro(w))) { |
334 | 341 |
for(i = 0; i < m->len; i++) |