uxn

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

commit 195a54c6d60ad88ca935540252fab69953e92fc1
parent ea8fa6e1ed074ab63280c4f092606c9d4bf9ec64
Author: neauoire <aliceffekt@gmail.com>
Date:   Sat, 20 Mar 2021 21:46:52 -0700

Experimenting with signed cmp

Diffstat:
Massembler.c | 2+-
Mbuild.sh | 2+-
Mprojects/examples/gui.shapes.usm | 49+++++++++++++++++++++++++++++++++++++++++++++++--
Mprojects/tests/draw.usm | 67+++++++++++++++++++++++++------------------------------------------
Muxn.c | 8++++++--
5 files changed, 80 insertions(+), 48 deletions(-)

diff --git a/assembler.c b/assembler.c @@ -48,7 +48,7 @@ char ops[][4] = { "BRK", "NOP", "LIT", "LDR", "STR", "---", "JMP", "JSR", "EQU", "NEQ", "GTH", "LTH", "AND", "ORA", "EOR", "SFT", "POP", "DUP", "SWP", "OVR", "ROT", "---", "CLN", "STH", - "ADD", "SUB", "MUL", "DIV", "---", "---", "---", "---" + "ADD", "SUB", "MUL", "DIV", "---", "---", "GTS", "LTS" }; int scin(char *s, char c) { int i = 0; while(s[i]) if(s[i++] == c) return i - 1; return -1; } /* string char index */ 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/nasu.usm bin/boot.rom +./bin/assembler projects/examples/gui.shapes.usm bin/boot.rom ./bin/emulator bin/boot.rom diff --git a/projects/examples/gui.shapes.usm b/projects/examples/gui.shapes.usm @@ -3,11 +3,19 @@ %RTN { JMP2r } %++ { #0001 ADD2 } %8+ { #0008 ADD2 } +%ABS2 { DUP2 #000f SFT2 #ffff SWP2 SWP POP MUL2? } ;label { x 2 y 2 color 1 addr 2 } ;pict { x 2 y 2 width 2 height 2 color 1 addr 2 } ;rect { x1 2 y1 2 x2 2 y2 2 } ;color { byte 1 } +( clean up ) +;a { x 2 y 2 } +;b { x 2 y 2 } +;s { x 2 y 2 } +;d { x 2 y 2 } +;err { short 2 } +;err2 { short 2 } |0100 @RESET @@ -27,6 +35,11 @@ #0038 #0078 #02 ,text ,draw-label JSR2 #0048 #0088 #03 ,text ,draw-label JSR2 #0058 #0098 #04 ,text ,draw-label JSR2 + + #0020 #0020 #0070 #0080 #01 ,draw-line JSR2 + #0020 #0080 #0070 #0030 #02 ,draw-line JSR2 + #00a0 #0020 #0050 #00b0 #03 ,draw-line JSR2 + #00b0 #0090 #0030 #0010 #01 ,draw-line JSR2 BRK @@ -88,6 +101,38 @@ RTN RTN +@draw-line ( x1 y1 x2 y2 ) + + =color + =b.y =b.x =a.y =a.x + ~b.x ~a.x SUB2 ABS2 =d.x + ~b.y ~a.y SUB2 ABS2 #0000 SWP2 SUB2 =d.y + #ffff #00 ~a.x ~b.x LTS2 #0002 MUL2 ADD2 =s.x + #ffff #00 ~a.y ~b.y LTS2 #0002 MUL2 ADD2 =s.y + ~d.x ~d.y ADD2 =err + + $loop + + ~a.x =Screen.x ~a.y =Screen.y ~color =Screen.color + ,$end ~a.x ~b.x EQU2 ~a.y ~b.y EQU2 #0101 EQU2 JMP2? + ~err #0002 MUL2 =err2 + + ,$skipy ~err2 ~d.y LTS2 JMP2? + ~err ~d.y ADD2 =err + ~a.x ~s.x ADD2 =a.x + $skipy + + ,$skipx ~err2 ~d.x GTS2 JMP2? + ~err ~d.x ADD2 =err + ~a.y ~s.y ADD2 =a.y + $skipx + + ,$loop JMP2 + + $end + +RTN + @pict_small [ ff80 8080 8080 8088 ffff fffc f8f9 f1f4 @@ -145,4 +190,4 @@ RTN |FF20 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 } |FFF0 .RESET .FRAME .ERROR ( vectors ) -|FFF8 [ 0f0f 0fff 0ff0 ] ( palette ) -\ No newline at end of file +|FFF8 [ 13fd 1ef3 1bf2 ] ( palette ) +\ No newline at end of file diff --git a/projects/tests/draw.usm b/projects/tests/draw.usm @@ -2,74 +2,51 @@ %RTN { JMP2r } %RTN? { JMP2r? } +%ABS { DUP #07 SHR #ff SWP MUL? } +%ABS2 { DUP2 #000f SFT2 #ffff SWP2 SWP POP MUL2? } ;cursor { x 2 y 2 } ;a { x 2 y 2 } ;b { x 2 y 2 } ;s { x 2 y 2 } +;d { x 2 y 2 } +;err { short 2 } +;err2 { short 2 } +;i { byte 1 } +;color { byte 1 } |0100 @RESET - #0020 #0020 #0070 #0080 ,draw-line JSR2 - #0020 #0080 #0070 #0030 ,draw-line JSR2 - #00a0 #0020 #0050 #00b0 ,draw-line JSR2 - #00b0 #0090 #0030 #0010 ,draw-line JSR2 + #0020 #0020 #0070 #0080 #01 ,draw-line JSR2 + #0020 #0080 #0070 #0030 #02 ,draw-line JSR2 + #00a0 #0020 #0050 #00b0 #03 ,draw-line JSR2 + #00b0 #0090 #0030 #0010 #01 ,draw-line JSR2 BRK @draw-line ( x1 y1 x2 y2 ) - - =b.y =b.x ( target, b ) - =a.y =a.x ( target, a ) - - ~a.x =Screen.x ~a.y =Screen.y #02 =Screen.color - ~b.x =Screen.x ~b.y =Screen.y #02 =Screen.color - - ( dx = abs[bx - ax] ) + + =color + =b.y =b.x =a.y =a.x ~b.x ~a.x SUB2 ABS2 =d.x - - ( dy = -abs[by - ay] ) ~b.y ~a.y SUB2 ABS2 #0000 SWP2 SUB2 =d.y - - ( sx = ax < bx ? 1 : -1; ) - #ffff #00 ~a.x ~b.x LTH2 #0002 MUL2 ADD2 =s.x - - ( sy = ay < by ? 1 : -1; ) - #ffff #00 ~a.y ~b.y LTH2 #0002 MUL2 ADD2 =s.y - - ( err = dx + dy ) + #ffff #00 ~a.x ~b.x LTS2 #0002 MUL2 ADD2 =s.x + #ffff #00 ~a.y ~b.y LTS2 #0002 MUL2 ADD2 =s.y ~d.x ~d.y ADD2 =err - ( loop ) $loop - ( putchr[ax, ay, color]; ) - ~a.x =Screen.x ~a.y =Screen.y #01 =Screen.color - - ( if[ax == bx && ay == by] break; ) + ~a.x =Screen.x ~a.y =Screen.y ~color =Screen.color ,$end ~a.x ~b.x EQU2 ~a.y ~b.y EQU2 #0101 EQU2 JMP2? - - ( fallback, remove ) - ,$end ~i #90 GTH JMP2? ~i #01 ADD =i - - ( err2 = 2 * err; ) ~err #0002 MUL2 =err2 - ~err2 =Console.short - - ( if[err2 >= dy] ) - ,$skipy ~err2 ~d.y LTH2 JMP2? - ( err += dy; ) + ,$skipy ~err2 ~d.y LTS2 JMP2? ~err ~d.y ADD2 =err - ( ax += sx; ) ~a.x ~s.x ADD2 =a.x $skipy - ( if[err2 <= dx] ) - ,$skipx ~err2 ~d.x GTH2 JMP2? - ( err += dx; ) + ,$skipx ~err2 ~d.x GTS2 JMP2? ~err ~d.x ADD2 =err - ( ay += sy; ) ~a.y ~s.y ADD2 =a.y $skipx @@ -83,6 +60,12 @@ RTN |d000 @ERROR |FF00 ;Console { pad 8 char 1 byte 1 short 2 } +|FF10 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 } +|FF20 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 } +|FF30 ;Controller { buttons 1 } +|FF40 ;Keys { key 1 } +|FF50 ;Mouse { x 2 y 2 state 1 chord 1 change 1 } +|FF60 ;File { pad 8 name 2 length 2 load 2 save 2 } |FFF0 .RESET .FRAME .ERROR ( vectors ) |FFF8 [ 13fd 1ef3 1bf2 ] ( palette ) \ No newline at end of file diff --git a/uxn.c b/uxn.c @@ -58,7 +58,9 @@ void op_div(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b void op_equ(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b == a); } void op_neq(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b != a); } void op_gth(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b > a); } +void op_gts(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, (Sint8)b > (Sint8)a); } void op_lth(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b < a); } +void op_lts(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, (Sint8)b < (Sint8)a); } /* --- */ void op_lit16(Uxn *u) { u->literal += 2; } void op_nop16(Uxn *u) { printf("%04x\n", pop16(u->src)); } @@ -87,18 +89,20 @@ void op_div16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->s void op_equ16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, b == a); } void op_neq16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, b != a); } void op_gth16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, b > a); } +void op_gts16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, (Sint16)b > (Sint16)a); } void op_lth16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, b < a); } +void op_lts16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, (Sint16)b < (Sint16)a); } void (*ops[])(Uxn *u) = { op_brk, op_nop, op_lit, op_ldr, op_str, op_nop, op_jmp, op_jsr, op_equ, op_neq, op_gth, op_lth, op_and, op_ora, op_eor, op_sft, op_pop, op_dup, op_swp, op_ovr, op_rot, op_nop, op_cln, op_sth, - op_add, op_sub, op_mul, op_div, op_nop, op_nop, op_nop, op_eor, + op_add, op_sub, op_mul, op_div, op_nop, op_nop, op_gts, op_lts, /* 16-bit */ op_brk, op_nop16, op_lit16, op_ldr16, op_str16, op_nop, op_jmp16, op_jsr16, op_equ16, op_neq16, op_gth16, op_lth16, op_and16, op_ora16, op_eor16, op_sft16, op_pop16, op_dup16, op_swp16, op_ovr16, op_rot16, op_nop, op_cln16, op_sth16, - op_add16, op_sub16, op_mul16, op_div16, op_nop, op_nop, op_nop, op_nop + op_add16, op_sub16, op_mul16, op_div16, op_nop, op_nop, op_gts16, op_lts16 }; Uint8 opr[][4] = { /* wstack-/+ rstack-/+ */