(uxnasm) Experimental implementation of JM/JC/JS runes
This commit is contained in:
parent
5b6aad6be2
commit
0e7137e016
68
src/uxnasm.c
68
src/uxnasm.c
|
@ -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,39 +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 */
|
||||||
|
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 */
|
case '"': /* raw string */
|
||||||
i = 0;
|
i = 0;
|
||||||
while((c = w[++i]))
|
while((c = w[++i]))
|
||||||
|
@ -338,25 +333,24 @@ 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++)
|
||||||
if(!parse(m->items[i], f))
|
if(!parse(m->items[i], f))
|
||||||
return 0;
|
return 0;
|
||||||
return 1;
|
return 1;
|
||||||
} else
|
} else {
|
||||||
return error("Unknown token", w);
|
makereference(p.scope, w - 1, p.ptr);
|
||||||
|
return writebyte(0x60) && writeshort(0xffff, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -405,15 +399,13 @@ resolve(void)
|
||||||
p.data[r->addr + 1] = l->addr & 0xff;
|
p.data[r->addr + 1] = l->addr & 0xff;
|
||||||
l->refs++;
|
l->refs++;
|
||||||
break;
|
break;
|
||||||
case ';':
|
default:
|
||||||
if(!(l = findlabel(r->name)))
|
if(!(l = findlabel(r->name)))
|
||||||
return error("Unknown absolute reference", r->name);
|
return error("Unknown absolute reference", r->name);
|
||||||
p.data[r->addr + 1] = l->addr >> 0x8;
|
p.data[r->addr + 1] = l->addr >> 0x8;
|
||||||
p.data[r->addr + 2] = l->addr & 0xff;
|
p.data[r->addr + 2] = l->addr & 0xff;
|
||||||
l->refs++;
|
l->refs++;
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
return error("Unknown reference", r->name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in New Issue