commit c2a5c8cac27755fe0bc7b5e55c81c6d02243e7a8
parent 823e0e8cda87e1aa6af01b1b2560239d0841596c
Author: neauoire <aliceffekt@gmail.com>
Date: Sun, 28 Mar 2021 09:48:00 -0700
Assembler will now use a single byte when on the zero-page
Diffstat:
1 file changed, 19 insertions(+), 9 deletions(-)
diff --git a/src/assembler.c b/src/assembler.c
@@ -263,11 +263,11 @@ walktoken(char *w)
if(findopcode(w) || scmp(w, "BRK", 4))
return 1;
switch(w[0]) {
- case '=': return 4; /* STR helper (lit addr-hb addr-lb str) */
- case '~': return 4; /* LDR helper (lit addr-hb addr-lb ldr) */
- case ',': return 3; /* lit2 addr-hb addr-lb */
- case '.': return 2; /* addr-hb addr-lb */
- case '^': return 2; /* Relative jump: lit addr-offset */
+ case '=': return 4 - (findlabeladdr(w + 1) < 0x0100); /* POK/STR helper (lit addr(1/2) str) */
+ case '~': return 4 - (findlabeladdr(w + 1) < 0x0100); /* PEK/LDR helper (lit addr(1/2) ldr) */
+ case ',': return 3; /* lit2 addr-hb addr-lb */
+ case '.': return 2; /* addr-hb addr-lb */
+ case '^': return 2; /* Relative jump: lit addr-offset */
case '#': return (slen(w + 1) == 2 ? 2 : 3);
}
if((m = findmacro(w))) {
@@ -298,15 +298,25 @@ parsetoken(char *w)
} else if(w[0] == '=' && (l = findlabel(w + 1))) {
if(!findlabellen(w + 1) || findlabellen(w + 1) > 2)
return error("Invalid store helper", w);
- pushshort(findlabeladdr(w + 1), 1);
- pushbyte(findopcode(findlabellen(w + 1) == 2 ? "STR2" : "POK2"), 0);
+ if(findlabeladdr(w + 1) < 0x0100) {
+ pushbyte(findlabeladdr(w + 1), 1);
+ pushbyte(findopcode(findlabellen(w + 1) == 2 ? "STR" : "POK"), 0);
+ } else {
+ pushshort(findlabeladdr(w + 1), 1);
+ pushbyte(findopcode(findlabellen(w + 1) == 2 ? "STR2" : "POK2"), 0);
+ }
l->refs++;
return 1;
} else if(w[0] == '~' && (l = findlabel(w + 1))) {
if(!findlabellen(w + 1) || findlabellen(w + 1) > 2)
return error("Invalid load helper", w);
- pushshort(findlabeladdr(w + 1), 1);
- pushbyte(findopcode(findlabellen(w + 1) == 2 ? "LDR2" : "PEK2"), 0);
+ if(findlabeladdr(w + 1) < 0x0100) {
+ pushbyte(findlabeladdr(w + 1), 1);
+ pushbyte(findopcode(findlabellen(w + 1) == 2 ? "LDR" : "PEK"), 0);
+ } else {
+ pushshort(findlabeladdr(w + 1), 1);
+ pushbyte(findopcode(findlabellen(w + 1) == 2 ? "LDR2" : "PEK2"), 0);
+ }
l->refs++;
return 1;
} else if((op = findopcode(w)) || scmp(w, "BRK", 4)) {