From 0027296839eb50a7663aeff4e0c9c925e162003a Mon Sep 17 00:00:00 2001 From: neauoire Date: Mon, 1 Mar 2021 08:55:16 -0800 Subject: [PATCH] Improved hover example --- build.sh | 2 +- emulator.c | 6 +++++- examples/dev.console.usm | 6 +++--- examples/gui.hover.usm | 29 +++++++++++++++-------------- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/build.sh b/build.sh index a7b2e56..facb081 100755 --- 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 examples/dev.mouse.usm bin/boot.rom +./bin/assembler examples/gui.hover.usm bin/boot.rom ./bin/emulator bin/boot.rom diff --git a/emulator.c b/emulator.c index 74cd912..e06bd32 100644 --- a/emulator.c +++ b/emulator.c @@ -329,7 +329,11 @@ doctrl(Uxn *u, SDL_Event *event, int z) Uint8 console_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) { - printf("%c", b1); + switch(b0) { + case 0x08: printf("%c", b1); break; + case 0x09: printf("%02x", b1); break; + case 0x0a: printf("%d", b1); break; + } fflush(stdout); (void)m; (void)ptr; diff --git a/examples/dev.console.usm b/examples/dev.console.usm index cc52500..812533f 100644 --- a/examples/dev.console.usm +++ b/examples/dev.console.usm @@ -1,6 +1,6 @@ ( hello world ) -&Console { pad 8 stdio 1 } +&Console { pad 8 char 1 byte 1 } |0100 @RESET @@ -11,11 +11,11 @@ BRK @print-label ( text ) @cliloop - DUP2 LDR =dev/console.stdio ( write pointer value to console ) + DUP2 LDR =dev/console.char ( write pointer value to console ) #0001 ADD2 ( increment string pointer ) DUP2 LDR #00 NEQ ,cliloop ROT JMP? POP2 ( while *ptr!=0 goto loop ) POP2 - + RTS @text1 [ Hello World ] <1 .00 ( add text to memory, return 1 byte, add null byte ) diff --git a/examples/gui.hover.usm b/examples/gui.hover.usm index 3a2d5be..e192a54 100644 --- a/examples/gui.hover.usm +++ b/examples/gui.hover.usm @@ -22,31 +22,32 @@ BRK - |0200 @FRAME ,pointer_icn =cursor #01 =color - + ( matrix comparison ) ~dev/mouse.x ~r1.x1 GTH2 ~dev/mouse.x ~r1.x2 LTH2 #0101 EQU2 ~dev/mouse.y ~r1.y1 GTH2 ~dev/mouse.y ~r1.y2 LTH2 #0101 EQU2 - #0101 NEQ2 ,skip1 ROT JMP? POP2 #02 =color ,hand_icn =cursor @skip1 - ~r1.x1 ~r1.y1 ~r1.x2 ~r1.y2 ~color ,line-rect JSR + #0101 NEQ2 ,draw1 ROT JMP? POP2 #02 =color ,hand_icn =cursor + @draw1 ~r1.x1 ~r1.y1 ~r1.x2 ~r1.y2 ~color ,line-rect JSR #01 =color - - ~dev/mouse.x ~r2.x1 GTH2 ~dev/mouse.x ~r2.x2 LTH2 #0101 EQU2 - ~dev/mouse.y ~r2.y1 GTH2 ~dev/mouse.y ~r2.y2 LTH2 #0101 EQU2 - #0101 NEQ2 ,skip2 ROT JMP? POP2 #02 =color ,hand_icn =cursor @skip2 - ~r2.x1 ~r2.y1 ~r2.x2 ~r2.y2 ~color ,line-rect JSR + ( 2-step comparison ) + ,draw2 ~dev/mouse.x ~r2.x1 GTH2 ~dev/mouse.x ~r2.x2 LTH2 #0101 NEQ2 JMP? POP2 + ,draw2 ~dev/mouse.y ~r2.y1 GTH2 ~dev/mouse.y ~r2.y2 LTH2 #0101 NEQ2 JMP? POP2 + #03 =color ,hand_icn =cursor + @draw2 ~r2.x1 ~r2.y1 ~r2.x2 ~r2.y2 ~color ,line-rect JSR #01 =color - - ~dev/mouse.x ~r3.x1 GTH2 ~dev/mouse.x ~r3.x2 LTH2 #0101 EQU2 - ~dev/mouse.y ~r3.y1 GTH2 ~dev/mouse.y ~r3.y2 LTH2 #0101 EQU2 - #0101 NEQ2 ,skip3 ROT JMP? POP2 #02 =color ,hand_icn =cursor @skip3 - ~r3.x1 ~r3.y1 ~r3.x2 ~r3.y2 ~color ,line-rect JSR + ( 4-step comparison ) + ,draw3 ~dev/mouse.x ~r3.x1 LTH2 JMP? POP2 + ,draw3 ~dev/mouse.x ~r3.x2 GTH2 JMP? POP2 + ,draw3 ~dev/mouse.y ~r3.y1 LTH2 JMP? POP2 + ,draw3 ~dev/mouse.y ~r3.y2 GTH2 JMP? POP2 + #02 =color ,hand_icn =cursor + @draw3 ~r3.x1 ~r3.y1 ~r3.x2 ~r3.y2 ~color ,line-rect JSR ,draw-cursor JSR