uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 0e7137e016114335ffe8278eb7a4e1648e10cbc4
parent 5b6aad6be2b62099bc512f60d44524030ebe5b2b
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date:   Mon,  2 Jan 2023 17:45:06 -0800

(uxnasm) Experimental implementation of JM/JC/JS runes

Diffstat:
Msrc/uxnasm.c | 68++++++++++++++++++++++++++++++--------------------------------------
1 file changed, 30 insertions(+), 38 deletions(-)

diff --git a/src/uxnasm.c b/src/uxnasm.c @@ -211,9 +211,7 @@ writebyte(Uint8 b) static int writeopcode(char *w) { - Uint8 res; - res = writebyte(findopcode(w)); - return res; + return writebyte(findopcode(w)); } static int @@ -227,9 +225,7 @@ writeshort(Uint16 s, int lit) static int writelitbyte(Uint8 b) { - if(!writebyte(findopcode("LIT"))) return 0; - if(!writebyte(b)) return 0; - return 1; + return writebyte(findopcode("LIT")) && writebyte(b); } static int @@ -295,39 +291,38 @@ parse(char *w, FILE *f) return error("Invalid sublabel", w); break; 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); - 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; case '_': /* raw byte relative */ makereference(p.scope, w, p.ptr); - if(!writebyte(0xff)) return 0; - break; + return writebyte(0xff); case ',': /* literal byte relative */ makereference(p.scope, w, p.ptr); - if(!writelitbyte(0xff)) return 0; - break; + return writelitbyte(0xff); case '-': /* raw byte absolute */ makereference(p.scope, w, p.ptr); - if(!writebyte(0xff)) return 0; - break; + return writebyte(0xff); case '.': /* literal byte zero-page */ makereference(p.scope, w, p.ptr); - if(!writelitbyte(0xff)) return 0; - break; + return writelitbyte(0xff); case ':': /* raw short absolute */ case '=': makereference(p.scope, w, p.ptr); - if(!writeshort(0xffff, 0)) return 0; - break; + return writeshort(0xffff, 0); case ';': /* literal short absolute */ makereference(p.scope, w, p.ptr); - if(!writeshort(0xffff, 1)) return 0; - break; + return writeshort(0xffff, 1); + case '!': /* JMI */ + makereference(p.scope, w, p.ptr); + return writebyte(0x20) && writeshort(0xffff, 0); + case '?': /* JCI */ + makereference(p.scope, w, p.ptr); + return writebyte(0x40) && writeshort(0xffff, 0); case '"': /* raw string */ i = 0; while((c = w[++i])) @@ -338,25 +333,24 @@ parse(char *w, FILE *f) if(slen(w) == 1) break; /* else fallthrough */ default: /* opcode */ - if(findopcode(w) || scmp(w, "BRK", 4)) { - if(!writeopcode(w)) return 0; - } + if(findopcode(w) || scmp(w, "BRK", 4)) + return writeopcode(w); /* raw byte */ - else if(sihx(w) && slen(w) == 2) { - if(!writebyte(shex(w))) return 0; - } + else if(sihx(w) && slen(w) == 2) + return writebyte(shex(w)); /* raw short */ - else if(sihx(w) && slen(w) == 4) { - if(!writeshort(shex(w), 0)) return 0; - } + else if(sihx(w) && slen(w) == 4) + return writeshort(shex(w), 0); /* macro */ else if((m = findmacro(w))) { for(i = 0; i < m->len; i++) if(!parse(m->items[i], f)) return 0; return 1; - } else - return error("Unknown token", w); + } else { + makereference(p.scope, w - 1, p.ptr); + return writebyte(0x60) && writeshort(0xffff, 0); + } } return 1; } @@ -405,15 +399,13 @@ resolve(void) p.data[r->addr + 1] = l->addr & 0xff; l->refs++; break; - case ';': + default: if(!(l = findlabel(r->name))) return error("Unknown absolute reference", r->name); p.data[r->addr + 1] = l->addr >> 0x8; p.data[r->addr + 2] = l->addr & 0xff; l->refs++; break; - default: - return error("Unknown reference", r->name); } } return 1;