0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-19 04:15:10 +00:00

Minor cleanup in assembler

This commit is contained in:
neauoire 2021-04-19 09:29:39 -07:00
parent 5ccd4ae8b9
commit 6a6b6e9d93

View file

@ -301,8 +301,7 @@ parsetoken(char *w)
return 0; return 0;
} }
pushbyte((Sint8)(l->addr - p.ptr - 3), 1); pushbyte((Sint8)(l->addr - p.ptr - 3), 1);
l->refs++; return ++l->refs;
return 1;
} else if(w[0] == '=' && (l = findlabel(w + 1))) { } else if(w[0] == '=' && (l = findlabel(w + 1))) {
if(!findlabellen(w + 1) || findlabellen(w + 1) > 2) if(!findlabellen(w + 1) || findlabellen(w + 1) > 2)
return error("Invalid store helper", w); return error("Invalid store helper", w);
@ -313,8 +312,7 @@ parsetoken(char *w)
pushshort(findlabeladdr(w + 1), 1); pushshort(findlabeladdr(w + 1), 1);
pushbyte(findopcode(findlabellen(w + 1) == 2 ? "STR2" : "POK2"), 0); pushbyte(findopcode(findlabellen(w + 1) == 2 ? "STR2" : "POK2"), 0);
} }
l->refs++; return ++l->refs;
return 1;
} else if(w[0] == '~' && (l = findlabel(w + 1))) { } else if(w[0] == '~' && (l = findlabel(w + 1))) {
if(!findlabellen(w + 1) || findlabellen(w + 1) > 2) if(!findlabellen(w + 1) || findlabellen(w + 1) > 2)
return error("Invalid load helper", w); return error("Invalid load helper", w);
@ -325,18 +323,15 @@ parsetoken(char *w)
pushshort(findlabeladdr(w + 1), 1); pushshort(findlabeladdr(w + 1), 1);
pushbyte(findopcode(findlabellen(w + 1) == 2 ? "LDR2" : "PEK2"), 0); pushbyte(findopcode(findlabellen(w + 1) == 2 ? "LDR2" : "PEK2"), 0);
} }
l->refs++; return ++l->refs;
return 1;
} else if((op = findopcode(w)) || scmp(w, "BRK", 4)) {
pushbyte(op, 0);
return 1;
} else if(w[0] == '.' && (l = findlabel(w + 1))) { } else if(w[0] == '.' && (l = findlabel(w + 1))) {
pushshort(findlabeladdr(w + 1), 0); pushshort(findlabeladdr(w + 1), 0);
l->refs++; return ++l->refs;
return 1;
} else if(w[0] == ',' && (l = findlabel(w + 1))) { } else if(w[0] == ',' && (l = findlabel(w + 1))) {
pushshort(findlabeladdr(w + 1), 1); pushshort(findlabeladdr(w + 1), 1);
l->refs++; return ++l->refs;
} else if((op = findopcode(w)) || scmp(w, "BRK", 4)) {
pushbyte(op, 0);
return 1; return 1;
} else if(w[0] == '#') { } else if(w[0] == '#') {
if(slen(w + 1) == 1) if(slen(w + 1) == 1)
@ -425,9 +420,8 @@ pass2(FILE *f)
scpy(w + 1, scope, 64); scpy(w + 1, scope, 64);
continue; continue;
} }
if(w[1] == '$') { if(w[1] == '$')
scpy(sublabel(subw, scope, w + 2), w + 1, 64); scpy(sublabel(subw, scope, w + 2), w + 1, 64);
}
if(skipblock(w, &cbits, '[', ']')) { if(skipblock(w, &cbits, '[', ']')) {
if(w[0] == '[' || w[0] == ']') { continue; } if(w[0] == '[' || w[0] == ']') { continue; }
if(slen(w) == 4 && sihx(w)) if(slen(w) == 4 && sihx(w))
@ -436,10 +430,9 @@ pass2(FILE *f)
pushbyte(shex(w), 0); pushbyte(shex(w), 0);
else else
pushtext(w, 0); pushtext(w, 0);
} else if(!parsetoken(w)) { } else if(!parsetoken(w))
return error("Unknown label in second pass", w); return error("Unknown label in second pass", w);
} }
}
return 1; return 1;
} }
@ -460,18 +453,12 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
FILE *f; FILE *f;
if(argc < 3) { if(argc < 3)
error("Input", "Missing"); return !error("Input", "Missing");
return 1; if(!(f = fopen(argv[1], "r")))
} return !error("Open", "Failed");
if(!(f = fopen(argv[1], "r"))) { if(!pass1(f) || !pass2(f))
error("Open", "Failed"); return !error("Assembly", "Failed");
return 1;
}
if(!pass1(f) || !pass2(f)) {
error("Assembly", "Failed");
return 1;
}
fwrite(p.data + OFFSET, p.ptr - OFFSET, 1, fopen(argv[2], "wb")); fwrite(p.data + OFFSET, p.ptr - OFFSET, 1, fopen(argv[2], "wb"));
fclose(f); fclose(f);
cleanup(argv[2]); cleanup(argv[2]);