Housekeeping

This commit is contained in:
Devine Lu Linvega 2023-01-02 17:33:57 -08:00
parent 31360cf82d
commit 194e9c8949
1 changed files with 22 additions and 39 deletions

View File

@ -211,9 +211,7 @@ writebyte(Uint8 b)
static int static int
writeopcode(char *w) writeopcode(char *w)
{ {
Uint8 res; return writebyte(findopcode(w));
res = writebyte(findopcode(w));
return res;
} }
static int static int
@ -227,9 +225,7 @@ writeshort(Uint16 s, int lit)
static int static int
writelitbyte(Uint8 b) writelitbyte(Uint8 b)
{ {
if(!writebyte(findopcode("LIT"))) return 0; return writebyte(findopcode("LIT")) && writebyte(b);
if(!writebyte(b)) return 0;
return 1;
} }
static int static int
@ -295,47 +291,38 @@ parse(char *w, FILE *f)
return error("Invalid sublabel", w); return error("Invalid sublabel", w);
break; break;
case '#': /* literals hex */ case '#': /* literals hex */
if(!sihx(w + 1) || (slen(w) != 3 && slen(w) != 5)) if(sihx(w + 1) && slen(w) == 3)
return writelitbyte(shex(w + 1));
else if(sihx(w + 1) && slen(w) == 5)
return writeshort(shex(w + 1), 1);
else
return error("Invalid hex literal", w); return error("Invalid hex literal", w);
if(slen(w) == 3) {
if(!writelitbyte(shex(w + 1))) return 0;
} else if(slen(w) == 5) {
if(!writeshort(shex(w + 1), 1)) return 0;
}
break; break;
case '_': /* raw byte relative */ case '_': /* raw byte relative */
makereference(p.scope, w, p.ptr); makereference(p.scope, w, p.ptr);
if(!writebyte(0xff)) return 0; return writebyte(0xff);
break;
case ',': /* literal byte relative */ case ',': /* literal byte relative */
makereference(p.scope, w, p.ptr); makereference(p.scope, w, p.ptr);
if(!writelitbyte(0xff)) return 0; return writelitbyte(0xff);
break;
case '-': /* raw byte absolute */ case '-': /* raw byte absolute */
makereference(p.scope, w, p.ptr); makereference(p.scope, w, p.ptr);
if(!writebyte(0xff)) return 0; return writebyte(0xff);
break;
case '.': /* literal byte zero-page */ case '.': /* literal byte zero-page */
makereference(p.scope, w, p.ptr); makereference(p.scope, w, p.ptr);
if(!writelitbyte(0xff)) return 0; return writelitbyte(0xff);
break;
case ':': /* raw short absolute */ case ':': /* raw short absolute */
case '=': case '=':
makereference(p.scope, w, p.ptr); makereference(p.scope, w, p.ptr);
if(!writeshort(0xffff, 0)) return 0; return writeshort(0xffff, 0);
break;
case ';': /* literal short absolute */ case ';': /* literal short absolute */
makereference(p.scope, w, p.ptr); makereference(p.scope, w, p.ptr);
if(!writeshort(0xffff, 1)) return 0; return writeshort(0xffff, 1);
break;
case '!': /* JMI */ case '!': /* JMI */
makereference(p.scope, w, p.ptr); makereference(p.scope, w, p.ptr);
if(!writebyte(0x20) || !writeshort(0xffff, 0)) return 0; return writebyte(0x20) && writeshort(0xffff, 0);
break;
case '?': /* JCI */ case '?': /* JCI */
makereference(p.scope, w, p.ptr); makereference(p.scope, w, p.ptr);
if(!writebyte(0x40) || !writeshort(0xffff, 0)) return 0; return writebyte(0x40) && writeshort(0xffff, 0);
break;
case '"': /* raw string */ case '"': /* raw string */
i = 0; i = 0;
while((c = w[++i])) while((c = w[++i]))
@ -346,17 +333,14 @@ parse(char *w, FILE *f)
if(slen(w) == 1) break; /* else fallthrough */ if(slen(w) == 1) break; /* else fallthrough */
default: default:
/* opcode */ /* opcode */
if(findopcode(w) || scmp(w, "BRK", 4)) { if(findopcode(w) || scmp(w, "BRK", 4))
if(!writeopcode(w)) return 0; return writeopcode(w);
}
/* raw byte */ /* raw byte */
else if(sihx(w) && slen(w) == 2) { else if(sihx(w) && slen(w) == 2)
if(!writebyte(shex(w))) return 0; return writebyte(shex(w));
}
/* raw short */ /* raw short */
else if(sihx(w) && slen(w) == 4) { else if(sihx(w) && slen(w) == 4)
if(!writeshort(shex(w), 0)) return 0; return writeshort(shex(w), 0);
}
/* macro */ /* macro */
else if((m = findmacro(w))) { else if((m = findmacro(w))) {
for(i = 0; i < m->len; i++) for(i = 0; i < m->len; i++)
@ -365,8 +349,7 @@ parse(char *w, FILE *f)
return 1; return 1;
} else { } else {
makereference(p.scope, w - 1, p.ptr); makereference(p.scope, w - 1, p.ptr);
if(!writebyte(0x60) || !writeshort(0xffff, 0)) return writebyte(0x60) && writeshort(0xffff, 0);
return 0;
} }
} }
return 1; return 1;