uxn

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

commit 9597611918e265824bf0e1609266ea006175738a
parent f3426fa886dc8b199d07e3fdf549e030a2fe3614
Author: neauoire <aliceffekt@gmail.com>
Date:   Thu,  4 Feb 2021 15:23:04 -0800

Added padding

Diffstat:
Mexamples/core.usm | 27+++++++++++++++++++++++----
Muxn.c | 26++++++++++++--------------
Muxnasm.c | 12+++++++-----
3 files changed, 42 insertions(+), 23 deletions(-)

diff --git a/examples/core.usm b/examples/core.usm @@ -1,9 +1,29 @@ -( comment ) +( define some variables in the zero-page ) ;var1 ;var2 ;var3 -,ef ,var2 STR +,22 ,var1 STR ( store 0x22 in var1 ) +,var1 LDR ( load var2, put value on stack ) -:label1 -\ No newline at end of file +@0100 ( store program reset after zero-page ) + +:RESET ( --- ) + BRK + +@c000 ( much further.. ) + +:FRAME ( --- ) + BRK + +@d000 ( further still.. ) + +:ERROR ( --- ) + BRK + +@FFFA ( vectors, last 3 shorts ) + +.RESET +.FRAME +.ERROR diff --git a/uxn.c b/uxn.c @@ -31,7 +31,7 @@ typedef struct { typedef struct { Uint8 literal, status; - Uint16 counter; + Uint16 counter, vreset, vframe, verror; Stack wst, rst; Memory rom, ram; } Computer; @@ -85,6 +85,8 @@ echom(Memory *m, Uint8 len, char *name) /* clang-format off */ +Uint8 mempoke8(Uint16 p) { return cpu.rom.dat[p+1] & 0xff; } +Uint16 mempoke16(Uint16 p) { return (cpu.rom.dat[p] << 8) + (cpu.rom.dat[p+1] & 0xff); } void wspush(Uint8 b) { cpu.wst.dat[cpu.wst.ptr++] = b; } Uint8 wspop(void) { return cpu.wst.dat[--cpu.wst.ptr]; } void wspush16(Uint16 s) { @@ -120,7 +122,7 @@ void op_add() { wspush(wspop() + wspop()); } void op_sub() { wspush(wspop() - wspop()); } void op_mul() { wspush(wspop() * wspop()); } void op_div() { wspush(wspop() / wspop()); } -void op_ldr() { wspush16(wspop16()); } +void op_ldr() { wspush(cpu.ram.dat[wspop16()]); } void op_str() { cpu.ram.dat[wspop16()] = wspop(); } void (*ops[])(void) = { @@ -134,8 +136,7 @@ Uint8 opr[][2] = { {0,0}, {0,0}, {0,0}, {1,0}, {0,1}, {1,1}, {0,1}, {3,3}, {2,0}, {2,0}, {2,0}, {2,0}, {2,1}, {2,1}, {2,1}, {2,1}, {1,0}, {1,0}, {1,0}, {1,0}, {2,1}, {0,0}, {0,0}, {0,0}, - {2,1}, {2,1}, {2,1}, {2,1}, {2,1}, {2,1}, {2,1}, {2,1}, - {3,1}, {3,1} + {2,1}, {3,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0} }; /* clang-format on */ @@ -163,12 +164,6 @@ error(char *name) return 0; } -void -load(FILE *f) -{ - fread(cpu.rom.dat, sizeof(cpu.rom.dat), 1, f); -} - int eval() { @@ -195,8 +190,13 @@ eval() } void -run(void) +start(FILE *f) { + reset(); + fread(cpu.rom.dat, sizeof(cpu.rom.dat), 1, f); + cpu.vreset = mempoke16(0xfffa); + cpu.vframe = mempoke16(0xfffc); + cpu.verror = mempoke16(0xfffe); while(!(cpu.status & FLAG_HALT) && eval(cpu)) ; /* debug */ @@ -217,9 +217,7 @@ main(int argc, char *argv[]) return error("No input."); if(!(f = fopen(argv[1], "rb"))) return error("Missing input."); - reset(); - load(f); - run(); + start(f); /* print result */ echos(&cpu.wst, 0x40, "stack"); echom(&cpu.ram, 0x40, "ram"); diff --git a/uxnasm.c b/uxnasm.c @@ -178,7 +178,7 @@ findop(char *s) } int -makelabel(char *id, Uint8 addr) +makelabel(char *id, Uint16 addr) { Label *l; if(findlabel(id)) @@ -193,7 +193,8 @@ makelabel(char *id, Uint8 addr) int pass1(FILE *f) { - int skip = 0, addr = 0, vars = 0; + int skip = 0, vars = 0; + Uint16 addr = 0; char w[64]; while(fscanf(f, "%s", w) == 1) { if(iscomment(w, &skip)) continue; @@ -205,9 +206,9 @@ pass1(FILE *f) /* move addr ptr */ if(findop(w) || scmp(w, "BRK")) addr += 1; - else if(w[0] == '@') - addr += 0; - else if(w[0] == ':') + else if(w[0] == '@') { + addr = shex(w + 1); + } else if(w[0] == ':') addr += 0; else if(w[0] == ';') addr += 0; @@ -264,5 +265,6 @@ main(int argc, char *argv[]) return error("Assembly", "Failed"); fwrite(p.data, sizeof(p.data), 1, fopen(argv[2], "wb")); fclose(f); + printf("Assembled %s.\n", argv[2]); return 0; }