uxn

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

commit d848cc1f541cd5b94f2efa6d644e1d879293577b
parent 82d1c276f9f26ec2faa7d0c29e6e3491be81dce5
Author: neauoire <aliceffekt@gmail.com>
Date:   Mon, 15 Mar 2021 18:08:41 -0700

Removing signed mode

Diffstat:
MREADME.md | 2+-
Massembler.c | 2+-
Mbuild.sh | 2+-
Mprojects/examples/dev.console.usm | 2+-
Mprojects/examples/dev.screen.usm | 6+++---
Mprojects/examples/gui.editor.usm | 14+++++++-------
Mprojects/software/left.usm | 40++++++++++++++++++++--------------------
Mprojects/software/nasu.usm | 8++++----
Mprojects/tests/cond.usm | 13++++++++++++-
Mprojects/tests/jump.usm | 12++++++------
Mprojects/tests/loop.usm | 8++++----
Muxn.c | 13+++++++------
12 files changed, 67 insertions(+), 55 deletions(-)

diff --git a/README.md b/README.md @@ -43,7 +43,7 @@ BRK $loop NOP ( send ) DUP2 LDR =Console.char ( incr ) #0001 ADD2 - ( loop ) DUP2 LDR #00 NEQ ^$loop MUL JMPS + ( loop ) DUP2 LDR #00 NEQ ^$loop MUL JMP POP2 RTN diff --git a/assembler.c b/assembler.c @@ -47,7 +47,7 @@ Program p; char ops[][4] = { "BRK", "NOP", "LIT", "LDR", "STR", "JMP", "JSR", "RTN", "EQU", "NEQ", "GTH", "LTH", "AND", "XOR", "ROL", "ROR", - "POP", "DUP", "SWP", "OVR", "ROT", "---", "WSR", "RSW", + "POP", "DUP", "SWP", "OVR", "ROT", "CLN", "WSR", "RSW", "ADD", "SUB", "MUL", "DIV", "---", "---", "---", "---" }; diff --git a/build.sh b/build.sh @@ -20,5 +20,5 @@ cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werr # cc uxn.c emulator.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -L/usr/local/lib -lSDL2 -o bin/emulator # run -./bin/assembler projects/software/left.usm bin/boot.rom +./bin/assembler projects/software/nasu.usm bin/boot.rom ./bin/emulator bin/boot.rom diff --git a/projects/examples/dev.console.usm b/projects/examples/dev.console.usm @@ -14,7 +14,7 @@ BRK $loop NOP ( send ) DUP2 LDR =Console.char ( incr ) #0001 ADD2 - ( loop ) DUP2 LDR #00 NEQ ^$loop MUL JMPS + ( loop ) DUP2 LDR #00 NEQ ^$loop MUL JMP POP2 RTN diff --git a/projects/examples/dev.screen.usm b/projects/examples/dev.screen.usm @@ -15,7 +15,7 @@ $draw-hor NOP ( draw ) #01 =Screen.color ( incr ) SWP2 #0002 ADD2 DUP2 =Screen.x SWP2 - OVR2 OVR2 LTH2 ^$draw-hor SWP JMPS? + OVR2 OVR2 LTH2 ^$draw-hor SWP JMP? POP2 POP2 ( draw ver line ) @@ -24,7 +24,7 @@ $draw-ver NOP ( draw ) #02 =Screen.color ( incr ) SWP2 #0002 ADD2 DUP2 =Screen.y SWP2 - OVR2 OVR2 LTH2 ^$draw-ver SWP JMPS? + OVR2 OVR2 LTH2 ^$draw-ver SWP JMP? POP2 POP2 ( draw blending modes ) @@ -34,7 +34,7 @@ ( move ) OVR #00 SWP #0008 MUL2 #0020 ADD2 =Sprite.x ( draw ) OVR =Sprite.color ( incr ) SWP #01 ADD SWP - DUP2 LTH ^$draw-blends SWP JMPS? + DUP2 LTH ^$draw-blends SWP JMP? POP POP BRK diff --git a/projects/examples/gui.editor.usm b/projects/examples/gui.editor.usm @@ -104,7 +104,7 @@ RTN ( draw ) DUP2 LDR #00 SWP #0008 MUL2 ,font ADD2 =Sprite.addr ~label.color =Sprite.color ( incr ) #0001 ADD2 ( incr ) ~Sprite.x #0007 ADD2 =Sprite.x - DUP2 LDR #00 NEQ ^$loop MUL JMPS + DUP2 LDR #00 NEQ ^$loop MUL JMP POP2 RTN @@ -117,9 +117,9 @@ RTN $hor NOP ( draw ) ~color =Screen.color ( incr ) ~Screen.x #0001 ADD2 =Screen.x - ~Screen.x ~rect.x2 LTH2 ^$hor MUL JMPS + ~Screen.x ~rect.x2 LTH2 ^$hor MUL JMP ( incr ) ~Screen.y #0001 ADD2 =Screen.y - ~Screen.y ~rect.y2 LTH2 ^$ver MUL JMPS + ~Screen.y ~rect.y2 LTH2 ^$ver MUL JMP RTN @@ -130,13 +130,13 @@ RTN ( incr ) ~Screen.x #0001 ADD2 =Screen.x ( draw ) ~rect.y1 =Screen.y ~color =Screen.color ( draw ) ~rect.y2 =Screen.y ~color =Screen.color - ~Screen.x ~rect.x2 LTH2 ^$hor MUL JMPS + ~Screen.x ~rect.x2 LTH2 ^$hor MUL JMP ~rect.y1 =Screen.y $ver NOP ( draw ) ~rect.x1 =Screen.x ~color =Screen.color ( draw ) ~rect.x2 =Screen.x ~color =Screen.color ( incr ) ~Screen.y #0001 ADD2 =Screen.y - ~Screen.y ~rect.y2 #0001 ADD2 LTH2 ^$ver MUL JMPS + ~Screen.y ~rect.y2 #0001 ADD2 LTH2 ^$ver MUL JMP RTN @@ -148,9 +148,9 @@ RTN $hor NOP ( draw ) ~color =Sprite.color ( incr ) ~Sprite.x #0008 ADD2 =Sprite.x - ~Sprite.x ~rect.x2 LTH2 ^$hor MUL JMPS + ~Sprite.x ~rect.x2 LTH2 ^$hor MUL JMP ( incr ) ~Sprite.y #0008 ADD2 =Sprite.y - ~Sprite.y ~rect.y2 LTH2 ^$ver MUL JMPS + ~Sprite.y ~rect.y2 LTH2 ^$ver MUL JMP RTN diff --git a/projects/software/left.usm b/projects/software/left.usm @@ -170,11 +170,11 @@ BRK ,$no-up ~Mouse.y #0008 GTH2 JMP2? ( decr ) ~scroll.y #00 ~scroll.y #0000 NEQ2 SUB2 =scroll.y - ^$end JMPS + ^$end JMP $no-up ,$no-down ~Mouse.y ~Screen.height #0008 SUB2 LTH2 JMP2? ( incr ) ~scroll.y #0001 ADD2 =scroll.y - ^$end JMPS + ^$end JMP $no-down ~Mouse.y #0008 SUB2 =scroll.y $end @@ -200,12 +200,12 @@ RTN ,$no-chord-cut ~Mouse.chord #01 NEQ JMP2? ,cut JSR2 ( release ) #00 DUP =Mouse.state =Mouse.chord - ^$end JMPS + ^$end JMP $no-chord-cut ,$no-chord-paste ~Mouse.chord #10 NEQ JMP2? ,paste JSR2 ( release ) #00 DUP =Mouse.state =Mouse.chord - ^$end JMPS + ^$end JMP $no-chord-paste ,$end ~Mouse.state #11 EQU JMP2? @@ -214,7 +214,7 @@ RTN ( on drag ) ,find-selection JSR2 #0001 ADD2 =selection.to ,clamp-selection JSR2 - ^$end JMPS + ^$end JMP $no-drag ( on click ) ,find-selection JSR2 DUP2 =selection.from #0001 ADD2 =selection.to @@ -231,7 +231,7 @@ RTN ,document.body =document.eof $loop NOP ( incr ) ~document.eof #0001 ADD2 =document.eof - ~document.eof LDR #00 NEQ ^$loop MUL JMPS + ~document.eof LDR #00 NEQ ^$loop MUL JMP RTN @@ -258,7 +258,7 @@ RTN $loop NOP ( move ) ~j ~i ADD2 LDR ~j STR ( incr ) ~j #0001 ADD2 =j - ~j ~document.eof LTH2 ^$loop MUL JMPS + ~j ~document.eof LTH2 ^$loop MUL JMP ~document.eof ~i SUB2 =document.eof RTN @@ -270,7 +270,7 @@ RTN $loop NOP ( move ) ~j ~i SUB2 LDR ~j STR ( decr ) ~j #0001 SUB2 =j - ~j ~selection.from GTH2 ^$loop MUL JMPS + ~j ~selection.from GTH2 ^$loop MUL JMP ~document.eof ~i ADD2 =document.eof RTN @@ -299,7 +299,7 @@ RTN ~selection.from #0001 SUB2 LDR #0a EQU RTN? ~selection.from #0001 SUB2 LDR #0d EQU RTN? ( decr ) ~selection.from DUP2 =selection.to #0001 SUB2 =selection.from - ~selection.from LDR #00 NEQ ^$loop MUL JMPS + ~selection.from LDR #00 NEQ ^$loop MUL JMP ( clamp at document body ) ~selection.from ,document.body GTH2 RTN? ,document.body DUP2 =selection.from #0001 ADD2 =selection.to @@ -312,7 +312,7 @@ RTN ~selection.from LDR #0a EQU RTN? ~selection.from LDR #0d EQU RTN? ( incr ) ~selection.from #0001 ADD2 DUP2 #0001 ADD2 =selection.to =selection.from - ~selection.from LDR #00 NEQ ^$loop MUL JMPS + ~selection.from LDR #00 NEQ ^$loop MUL JMP ( clamp at document body ) ~selection.from ,document.eof LTH2 RTN? ,document.eof #0001 SUB2 DUP2 =selection.from #0001 ADD2 =selection.to @@ -327,7 +327,7 @@ RTN ,$end ~j LDR #20 EQU JMP2? ,$end ~j LDR #0a EQU JMP2? ,$end ~j LDR #0d EQU JMP2? - ~j ,document.body GTH2 ^$loop MUL JMPS + ~j ,document.body GTH2 ^$loop MUL JMP $end ( return ) ~j #0001 SUB2 @@ -341,7 +341,7 @@ RTN ,$end ~j LDR #20 EQU JMP2? ,$end ~j LDR #0a EQU JMP2? ,$end ~j LDR #0d EQU JMP2? - ~j ,document.body GTH2 ^$loop MUL JMPS + ~j ,document.body GTH2 ^$loop MUL JMP $end ( return ) ~j #0001 ADD2 @@ -354,7 +354,7 @@ RTN ( incr ) ~j #0001 ADD2 =j ,$end ~selection.from ~j SUB2 LDR #0a EQU JMP2? ,$end ~selection.from ~j SUB2 LDR #0d EQU JMP2? - ~selection.from ~j SUB2 ,document.body GTH2 ^$loop MUL JMPS + ~selection.from ~j SUB2 ,document.body GTH2 ^$loop MUL JMP $end ( return ) ~j @@ -369,7 +369,7 @@ RTN ( incr ) ~pt.y #0001 ADD2 =pt.y $no-space ( incr ) ~j #0001 ADD2 =j - ~j LDR #00 NEQ ^$loop MUL JMPS + ~j LDR #00 NEQ ^$loop MUL JMP $end ( return ) ~j @@ -383,7 +383,7 @@ RTN ,$end ~j ~pt.x ADD2 LDR #0a EQU JMP2? ,$end ~j ~pt.x ADD2 LDR #0d EQU JMP2? ( incr ) ~pt.x #0001 ADD2 =pt.x - ~pt.x ~position.x #0001 SUB2 LTH2 ^$loop MUL JMPS + ~pt.x ~position.x #0001 SUB2 LTH2 ^$loop MUL JMP $end ( return ) ~pt.x ADD2 @@ -405,7 +405,7 @@ RTN $loop NOP ~selection.from ~i ADD2 LDR ,clip.body ~i ADD2 STR ( incr ) ~i #0001 ADD2 =i - ~i ~j LTH2 ^$loop MUL JMPS + ~i ~j LTH2 ^$loop MUL JMP RTN @@ -417,7 +417,7 @@ RTN $loop NOP ,clip.body ~i ADD2 LDR ~selection.from ~i ADD2 STR ( incr ) ~i #0001 ADD2 =i - ~i ~j LTH2 ^$loop MUL JMPS + ~i ~j LTH2 ^$loop MUL JMP RTN @@ -512,7 +512,7 @@ RTN ( incr ) ~j #0001 ADD2 =j $no-break ( incr ) ~textarea.addr #0001 ADD2 =textarea.addr - ~textarea.addr LDR #00 NEQ ^$find-offset MUL JMPS + ~textarea.addr LDR #00 NEQ ^$find-offset MUL JMP $find-offset-end #0018 =Sprite.x #0000 =Sprite.y @@ -577,7 +577,7 @@ RTN $loop NOP ( draw ) #08 =Sprite.color ( incr ) ~Sprite.y #0008 ADD2 =Sprite.y - ~Sprite.y ~Screen.height LTH2 ^$loop MUL JMPS + ~Sprite.y ~Screen.height LTH2 ^$loop MUL JMP #0000 =Sprite.y ,arrowup_icn =Sprite.addr @@ -603,7 +603,7 @@ RTN ( draw ) DUP2 LDR #00 SWP #20 SUB #0008 MUL2 ,font ADD2 =Sprite.addr ~label.color =Sprite.color ( incr ) #0001 ADD2 ( incr ) ~Sprite.x #0008 ADD2 =Sprite.x - DUP2 LDR #00 NEQ ^$loop MUL JMPS + DUP2 LDR #00 NEQ ^$loop MUL JMP POP2 ( selection ) ~selection.from ,document.body SUB2 ,draw-short JSR2 diff --git a/projects/software/nasu.usm b/projects/software/nasu.usm @@ -109,7 +109,7 @@ BRK ~MOUS.y ~bankview.y SUB2 #0008 DIV2 #0008 MUL2 #0010 MUL2 ADD2 ~bankview.addr ADD2 #00 ~i ADD2 STR ( incr ) ~i #01 ADD =i - ~i #08 LTH ^copy-loop MUL JMPS + ~i #08 LTH ^copy-loop MUL JMP ,redraw JSR2 ,click-end JMP2 @not-copy-mode @@ -122,7 +122,7 @@ BRK ~MOUS.y ~bankview.y SUB2 #0008 DIV2 #0008 MUL2 #0010 MUL2 ADD2 ~bankview.addr ADD2 #00 ~i ADD2 STR ( incr ) ~i #01 ADD =i - ~i #08 LTH ^erase-loop MUL JMPS + ~i #08 LTH ^erase-loop MUL JMP ,redraw JSR2 ,click-end JMP2 @not-erase-mode @@ -460,13 +460,13 @@ RTN ( incr ) ~SCRN.x #0001 ADD2 =SCRN.x ( draw ) ~rect.y1 =SCRN.y ~color =SCRN.color ( draw ) ~rect.y2 =SCRN.y ~color =SCRN.color - ~SCRN.x ~rect.x2 LTH2 ^$hor MUL JMPS + ~SCRN.x ~rect.x2 LTH2 ^$hor MUL JMP ~rect.y1 =SCRN.y $ver NOP ( draw ) ~rect.x1 =SCRN.x ~color =SCRN.color ( draw ) ~rect.x2 =SCRN.x ~color =SCRN.color ( incr ) ~SCRN.y #0001 ADD2 =SCRN.y - ~SCRN.y ~rect.y2 #0001 ADD2 LTH2 ^$ver MUL JMPS + ~SCRN.y ~rect.y2 #0001 ADD2 LTH2 ^$ver MUL JMP RTN diff --git a/projects/tests/cond.usm b/projects/tests/cond.usm @@ -1,16 +1,27 @@ ( tests/cond ) +%RTN { RSW2 JMP2 } +%RTN? { CLN2 JMP2? } + |0100 @RESET #00 #d0 + $loop NOP ( incr ) SWP #01 ADD SWP - DUP2 LTH ^$loop SWP JMPS? + DUP2 LTH ^$loop SWP JMP? POP =Console.byte + ,routine JSR2 + BRK @routine + + + CLN2 JMP2 + + #aa RTN diff --git a/projects/tests/jump.usm b/projects/tests/jump.usm @@ -12,12 +12,12 @@ BRK ( should print 11, 22, 33, 44 ) #11 =Console.byte - #03 JMPS BRK BRK BRK + #03 JMP BRK BRK BRK ( skip foward with id ) #22 =Console.byte - ^jump JMPS BRK BRK BRK @jump + ^jump JMP BRK BRK BRK @jump ( skip patterns ) @@ -27,7 +27,7 @@ BRK #ff =Console.byte @skip1 - #12 #34 LTH ^skip2 #04 SUB MUL JMPS + #12 #34 LTH ^skip2 #04 SUB MUL JMP #ff =Console.byte @skip2 @@ -41,9 +41,9 @@ RTN ( should print aa, bb, cc, dd ) - @label1 #aa =Console.byte ^label3 JMPS - @label2 #cc =Console.byte ^label4 JMPS - @label3 #bb =Console.byte ^label2 JMPS + @label1 #aa =Console.byte ^label3 JMP + @label2 #cc =Console.byte ^label4 JMP + @label3 #bb =Console.byte ^label2 JMP @label4 #dd =Console.byte BRK @end diff --git a/projects/tests/loop.usm b/projects/tests/loop.usm @@ -16,7 +16,7 @@ BRK $loop NOP ~a #01 ADD =a - ~a #d0 LTH ^$loop MUL JMPS + ~a #d0 LTH ^$loop MUL JMP ~a =Console.byte RTN @@ -34,7 +34,7 @@ RTN $loop NOP ~c #01 ADD =c - ~c #d0 LTH ^$loop SWP JMPS? + ~c #d0 LTH ^$loop SWP JMP? ~c =Console.byte RTN @@ -44,7 +44,7 @@ RTN #00 #d0 $loop NOP ( incr ) SWP #01 ADD SWP - DUP2 LTH ^$loop SWP JMPS? + DUP2 LTH ^$loop SWP JMP? POP =Console.byte RTN @@ -54,7 +54,7 @@ RTN #0000 #0d00 $loop NOP ( incr ) SWP2 #0001 ADD2 SWP2 - OVR2 OVR2 LTH2 ^$loop SWP JMPS? + OVR2 OVR2 LTH2 ^$loop SWP JMP? POP2 =Console.short RTN diff --git a/uxn.c b/uxn.c @@ -33,9 +33,8 @@ Uint16 peek16(Stack *s, Uint8 a) { return peek8(s, a * 2) + (peek8(s, a * 2 + 1) void op_brk(Uxn *u) { setflag(&u->status, FLAG_HALT, 1); } void op_lit(Uxn *u) { u->literal += 1; } void op_nop(Uxn *u) { (void)u; } -void op_jmp(Uxn *u) { Uint8 a = pop8(&u->wst); u->ram.ptr += getflag(&u->status, FLAG_SIGN) ? (Sint8)a : a; } - -void op_jsr(Uxn *u) { Uint8 a = pop8(&u->wst); push16(&u->rst, u->ram.ptr); u->ram.ptr += getflag(&u->status, FLAG_SIGN) ? (Sint8)a : a; } +void op_jmp(Uxn *u) { Uint8 a = pop8(&u->wst); u->ram.ptr += (Sint8)a; } +void op_jsr(Uxn *u) { Uint8 a = pop8(&u->wst); push16(&u->rst, u->ram.ptr); u->ram.ptr += (Sint8)a; } void op_rtn(Uxn *u) { u->ram.ptr = pop16(&u->rst); } void op_ldr(Uxn *u) { Uint16 a = pop16(&u->wst); push8(&u->wst, mempeek8(u, a)); } void op_str(Uxn *u) { Uint16 a = pop16(&u->wst); Uint8 b = pop8(&u->wst); mempoke8(u, a, b); } @@ -50,6 +49,7 @@ void op_dup(Uxn *u) { push8(&u->wst, peek8(&u->wst, 0)); } void op_swp(Uxn *u) { Uint8 b = pop8(&u->wst), a = pop8(&u->wst); push8(&u->wst, b); push8(&u->wst, a); } void op_ovr(Uxn *u) { push8(&u->wst, peek8(&u->wst, 1)); } void op_rot(Uxn *u) { Uint8 c = pop8(&u->wst), b = pop8(&u->wst), a = pop8(&u->wst); push8(&u->wst, b); push8(&u->wst, c); push8(&u->wst, a); } +void op_cln(Uxn *u) { push8(&u->wst, peek8(&u->rst, 0)); } void op_wsr(Uxn *u) { Uint8 a = pop8(&u->wst); push8(&u->rst, a); } void op_rsw(Uxn *u) { Uint8 a = pop8(&u->rst); push8(&u->wst, a); } /* Arithmetic */ @@ -78,6 +78,7 @@ void op_dup16(Uxn *u) { push16(&u->wst, peek16(&u->wst, 0)); } void op_swp16(Uxn *u) { Uint16 b = pop16(&u->wst), a = pop16(&u->wst); push16(&u->wst, b); push16(&u->wst, a); } void op_ovr16(Uxn *u) { push16(&u->wst, peek16(&u->wst, 1)); } void op_rot16(Uxn *u) { Uint16 c = pop16(&u->wst), b = pop16(&u->wst), a = pop16(&u->wst); push16(&u->wst, b); push16(&u->wst, c); push16(&u->wst, a); } +void op_cln16(Uxn *u) { push16(&u->wst, peek16(&u->rst, 0)); } void op_wsr16(Uxn *u) { Uint16 a = pop16(&u->wst); push16(&u->rst, a); } void op_rsw16(Uxn *u) { Uint16 a = pop16(&u->rst); push16(&u->wst, a); } /* Arithmetic(16-bits) */ @@ -93,12 +94,12 @@ void op_lth16(Uxn *u) { Uint16 a = pop16(&u->wst), b = pop16(&u->wst); push8(&u- void (*ops[])(Uxn *u) = { op_brk, op_nop, op_lit, op_ldr, op_str, op_jmp, op_jsr, op_rtn, op_equ, op_neq, op_gth, op_lth, op_and, op_xor, op_rol, op_ror, - op_pop, op_dup, op_swp, op_ovr, op_rot, op_nop, op_wsr, op_rsw, + op_pop, op_dup, op_swp, op_ovr, op_rot, op_cln, op_wsr, op_rsw, op_add, op_sub, op_mul, op_div, op_nop, op_nop, op_nop, op_nop, /* 16-bit */ op_brk, op_nop16, op_lit16, op_ldr16, op_str16, op_jmp16, op_jsr16, op_rtn, op_equ16, op_neq16, op_gth16, op_lth16, op_and16, op_xor16, op_rol16, op_ror16, - op_pop16, op_dup16, op_swp16, op_ovr16, op_rot16, op_nop, op_wsr16, op_rsw16, + op_pop16, op_dup16, op_swp16, op_ovr16, op_rot16, op_cln16, op_wsr16, op_rsw16, op_add16, op_sub16, op_mul16, op_div16, op_nop, op_nop, op_nop, op_nop }; @@ -155,7 +156,7 @@ opcuxn(Uxn *u, Uint8 instr) return haltuxn(u, "Return-stack overflow", instr); if(!fcond || (fcond && pop8(&u->wst))) (*ops[op])(u); - else if(opr[op][0] >= opr[op][1]) + else u->wst.ptr -= opr[op][0] - opr[op][1]; return 1; }