diff --git a/assembler.c b/assembler.c index 9482f38..14af8ff 100644 --- a/assembler.c +++ b/assembler.c @@ -169,7 +169,7 @@ pass1(FILE *f) case '#': addr += 4; break; case '.': addr += 2; break; case ',': - addr += (slen(w + 1) == 2 ? 1 : 2); + addr += (sihx(w + 1) && slen(w + 1) == 2 ? 1 : 2); addr += (sihx(w + 1) ? slen(w + 1) / 2 : 2); break; default: return error("Unknown label", w); diff --git a/build.sh b/build.sh index 7021d29..fe00044 100755 --- a/build.sh +++ b/build.sh @@ -24,5 +24,5 @@ rm -f ./bin/emulator cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined uxn.c emulator.c -L/usr/local/lib -lSDL2 -o bin/emulator # run -./bin/assembler examples/mouse.usm bin/boot.rom +./bin/assembler examples/test.usm bin/boot.rom ./bin/emulator bin/boot.rom diff --git a/examples/hello.usm b/examples/hello.usm index 6739817..6ca78b5 100644 --- a/examples/hello.usm +++ b/examples/hello.usm @@ -7,7 +7,7 @@ @word1 "hello_world ( len: 0x0b ) @loop - ,00 IOW ( write to device#0 ) + IOW ( write to device#0 ) ,incr JSR ( increment itr ) ,word1 ,strlen JSR ( get strlen ) NEQ ,loop ROT JSR? ( loop != strlen ) diff --git a/examples/test.usm b/examples/test.usm index 2c82c86..f5918f7 100644 --- a/examples/test.usm +++ b/examples/test.usm @@ -3,35 +3,26 @@ :dev/r fff8 ( std read port ) :dev/w fff9 ( std write port ) +;i ;x0 ;x1 ;y0 ;y1 + |0100 @RESET - ,02 ,dev/r STR ( set dev/read mouse#02 ) - ,01 ,dev/w STR ( set dev/write screen#01 ) - - ,00 ,01 ,0001 ,0000 ,putpixel JSR - ,00 ,01 ,0000 ,0001 ,putpixel JSR - ,00 ,01 ,0002 ,0001 ,putpixel JSR - ,01 ,02 ,0001 ,0002 ,putpixel JSR + ,01 ,dev/w STR ( set dev/write screen#01 ) BRK -|c000 @FRAME +|c000 @FRAME + + ,i LDR ,01 ADD ,i STR ( incr i ) - ( get mouse button, or break ) - ,04 IOR - ,01 NEQ - BRK? - - ( paint a white pixel ) - ,01 ,01 - ,getmouse JSR - ,putpixel JSR + ,i LDR ,x1 STR ( set x ) + + ,01 ,02 ,x0 LDR^ ,y0 LDR^ ,putpixel JSR BRK -@getmouse - ,02 IOR^ ( get mouse y ) - ,00 IOR^ ( get mouse x ) +@onrow + ,y1 LDR ,01 ADD ,y1 STR RTS @putpixel diff --git a/uxn.c b/uxn.c index 4ff5f47..44b31eb 100644 --- a/uxn.c +++ b/uxn.c @@ -157,6 +157,7 @@ stepuxn(Uxn *u, Uint8 instr) int evaluxn(Uxn *u, Uint16 vec) { + u->literal = 0; u->ram.ptr = vec; setflag(&u->status, FLAG_HALT, 0); while(!(u->status & FLAG_HALT)) {