From f3e920c54da6554f76ea321f9d745a35a0c38fb3 Mon Sep 17 00:00:00 2001 From: neauoire Date: Fri, 26 Mar 2021 11:45:10 -0700 Subject: [PATCH] Optimized examples to use relative jumping whenever available --- README.md | 6 ++--- build.sh | 2 +- projects/examples/dev.console.usm | 4 ++-- projects/examples/dev.controller.usm | 12 +++++----- projects/examples/dev.keys.usm | 4 ++-- projects/examples/dev.mouse.usm | 6 ++--- projects/examples/dev.screen.usm | 36 ++++++++++++++-------------- projects/examples/gui.editor.usm | 16 ++++++------- projects/examples/gui.hover.usm | 18 +++++++------- projects/examples/gui.label.usm | 10 ++++---- projects/examples/gui.picture.usm | 4 ++-- projects/examples/gui.shapes.usm | 22 ++++++++--------- 12 files changed, 70 insertions(+), 70 deletions(-) diff --git a/README.md b/README.md index da352cb..a2b0ac5 100644 --- a/README.md +++ b/README.md @@ -45,10 +45,10 @@ BRK @print-label ( text ) - $loop NOP - ( send ) DUP2 LDR =Console.char + $loop + ( send ) DUP2 PEK2 =Console.char ( incr ) #0001 ADD2 - ( loop ) DUP2 LDR #00 NEQ ^$loop MUL JMP + ( loop ) DUP2 PEK2 #00 NEQ ^$loop JNZ POP2 RTN diff --git a/build.sh b/build.sh index 99c7f9f..2a4522d 100755 --- a/build.sh +++ b/build.sh @@ -28,7 +28,7 @@ else fi echo "Assembling.." -./bin/assembler projects/software/noodle.usm bin/boot.rom +./bin/assembler projects/examples/gui.shapes.usm bin/boot.rom echo "Running.." if [ "${2}" = '--cli' ]; diff --git a/projects/examples/dev.console.usm b/projects/examples/dev.console.usm index 8406540..16d04df 100644 --- a/projects/examples/dev.console.usm +++ b/projects/examples/dev.console.usm @@ -21,10 +21,10 @@ BRK @print-label ( text ) - $loop NOP + $loop ( send ) DUP2 PEK2 =Console.char ( incr ) #0001 ADD2 - ( loop ) DUP2 PEK2 #00 NEQ ^$loop MUL JMP + ( loop ) DUP2 PEK2 #00 NEQ ^$loop JNZ POP2 RTN diff --git a/projects/examples/dev.controller.usm b/projects/examples/dev.controller.usm index 580ee20..9554e65 100644 --- a/projects/examples/dev.controller.usm +++ b/projects/examples/dev.controller.usm @@ -42,21 +42,21 @@ BRK ( hold ctrl key to change slime color ) ~Controller.p1 #0f AND - DUP #01 NEQ ,$no-ctrl JNZ2 #05 =slime $no-ctrl - DUP #02 NEQ ,$no-alt JNZ2 #0f =slime $no-alt + DUP #01 NEQ ^$no-ctrl JNZ #05 =slime $no-ctrl + DUP #02 NEQ ^$no-alt JNZ #0f =slime $no-alt POP ( clear ) #10 =Sprite.color ( detect movement ) ~Controller.p1 #f0 AND - DUP #04 SFT #01 AND #01 NEQ ,$no-up JNZ2 + DUP #04 SFT #01 AND #01 NEQ ^$no-up JNZ ( move ) ~Sprite.y -- =Sprite.y ,up_icn =Sprite.addr $no-up - DUP #05 SFT #01 AND #01 NEQ ,$no-down JNZ2 + DUP #05 SFT #01 AND #01 NEQ ^$no-down JNZ ( move ) ~Sprite.y ++ =Sprite.y ,down_icn =Sprite.addr $no-down - DUP #06 SFT #01 AND #01 NEQ ,$no-left JNZ2 + DUP #06 SFT #01 AND #01 NEQ ^$no-left JNZ ( move ) ~Sprite.x -- =Sprite.x ,left_icn =Sprite.addr $no-left - DUP #07 SFT #01 AND #01 NEQ ,$no-right JNZ2 + DUP #07 SFT #01 AND #01 NEQ ^$no-right JNZ ( move ) ~Sprite.x ++ =Sprite.x ,right_icn =Sprite.addr $no-right POP diff --git a/projects/examples/dev.keys.usm b/projects/examples/dev.keys.usm index 970a84a..3194a47 100644 --- a/projects/examples/dev.keys.usm +++ b/projects/examples/dev.keys.usm @@ -15,10 +15,10 @@ @FRAME - ~Keys #00 EQU ,$end JNZ2 + ~Keys #00 EQU ^$end JNZ ( enter key ) - ~Keys #0d NEQ ,$no-return JNZ2 + ~Keys #0d NEQ ^$no-return JNZ #0000 =Sprite.x ( incr ) ~Sprite.y 8+ =Sprite.y ( release ) #00 =Keys diff --git a/projects/examples/dev.mouse.usm b/projects/examples/dev.mouse.usm index 44fc69c..6047ae4 100644 --- a/projects/examples/dev.mouse.usm +++ b/projects/examples/dev.mouse.usm @@ -27,7 +27,7 @@ BRK ,draw-cursor JSR2 - ~Mouse.state #00 EQU ,$no-touch JNZ2 + ~Mouse.state #00 EQU ^$no-touch JNZ ~Mouse.x =circle.xc ~Mouse.y =circle.yc #0000 =circle.r @@ -65,7 +65,7 @@ RTN ( draw ) ,$seg JSR2 $loop ( incr ) ~circle.x ++ =circle.x - ~circle.d #0000 #0001 ADD2 LTS2 ,$else JNZ2 + ~circle.d #0000 #0001 ADD2 LTS2 ^$else JNZ ( decr ) ~circle.y -- =circle.y ~circle.x ~circle.y SUB2 #0004 MUL2 ~circle.d ADD2 #000a ADD2 =circle.d ,$end JMP2 @@ -73,7 +73,7 @@ RTN ~circle.x #0004 MUL2 ~circle.d ADD2 #0006 ADD2 =circle.d $end ( draw ) ,$seg JSR2 - ~circle.y ~circle.x #0001 SUB2 GTS2 ,$loop JNZ2 + ~circle.y ~circle.x #0001 SUB2 GTS2 ^$loop JNZ RTN $seg ~circle.xc ~circle.x ADD2 =Screen.x ~circle.yc ~circle.y ADD2 =Screen.y ~color =Screen.color diff --git a/projects/examples/dev.screen.usm b/projects/examples/dev.screen.usm index 09497b9..3a1adbc 100644 --- a/projects/examples/dev.screen.usm +++ b/projects/examples/dev.screen.usm @@ -86,24 +86,24 @@ BRK ~Mouse.y ~window.y1 SUB2 STEP8 - DUP2 #0010 NEQ2 ,$no-touch-red JNZ2 - ~Mouse.x ~window.x1 #0050 ADD2 LTH2 ,$no-touch-red JNZ2 - ~Mouse.x ~window.x1 #008c ADD2 GTH2 ,$no-touch-red JNZ2 + DUP2 #0010 NEQ2 ^$no-touch-red JNZ + ~Mouse.x ~window.x1 #0050 ADD2 LTH2 ^$no-touch-red JNZ + ~Mouse.x ~window.x1 #008c ADD2 GTH2 ^$no-touch-red JNZ ( get new value ) ~Mouse.x ~window.x1 SUB2 #0050 SUB2 #0004 DIV2 S2B ,theme.r1 #00 ~selection ADD2 POK2 $no-touch-red - DUP2 #0020 NEQ2 ,$no-touch-green JNZ2 - ~Mouse.x ~window.x1 #0050 ADD2 LTH2 ,$no-touch-green JNZ2 - ~Mouse.x ~window.x1 #008c ADD2 GTH2 ,$no-touch-green JNZ2 + DUP2 #0020 NEQ2 ^$no-touch-green JNZ + ~Mouse.x ~window.x1 #0050 ADD2 LTH2 ^$no-touch-green JNZ + ~Mouse.x ~window.x1 #008c ADD2 GTH2 ^$no-touch-green JNZ ( get new value ) ~Mouse.x ~window.x1 SUB2 #0050 SUB2 #0004 DIV2 S2B ,theme.g1 #00 ~selection ADD2 POK2 $no-touch-green - DUP2 #0030 NEQ2 ,$no-touch-blue JNZ2 - ~Mouse.x ~window.x1 #0050 ADD2 LTH2 ,$no-touch-blue JNZ2 - ~Mouse.x ~window.x1 #008c ADD2 GTH2 ,$no-touch-blue JNZ2 + DUP2 #0030 NEQ2 ^$no-touch-blue JNZ + ~Mouse.x ~window.x1 #0050 ADD2 LTH2 ^$no-touch-blue JNZ + ~Mouse.x ~window.x1 #008c ADD2 GTH2 ^$no-touch-blue JNZ ( get new value ) ~Mouse.x ~window.x1 SUB2 #0050 SUB2 #0004 DIV2 S2B ,theme.b1 #00 ~selection ADD2 POK2 $no-touch-blue - DUP2 #0040 NEQ2 ,$no-touch-radio JNZ2 - ~Mouse.x ~window.x1 #0050 ADD2 LTH2 ,$no-touch-radio JNZ2 - ~Mouse.x ~window.x1 #008c ADD2 GTH2 ,$no-touch-radio JNZ2 + DUP2 #0040 NEQ2 ^$no-touch-radio JNZ + ~Mouse.x ~window.x1 #0050 ADD2 LTH2 ^$no-touch-radio JNZ + ~Mouse.x ~window.x1 #008c ADD2 GTH2 ^$no-touch-radio JNZ ~Mouse.x ~window.x1 SUB2 #0050 SUB2 STEP8 2/ #0008 DIV2 S2B =selection $no-touch-radio @@ -228,7 +228,7 @@ RTN $loop ( incr ) ~Sprite.x 8+ =Sprite.x ( draw ) #05 =Sprite.color - ~Sprite.x ~slider.x2 #0008 ADD2 LTH2 ,$loop JNZ2 + ~Sprite.x ~slider.x2 #0008 ADD2 LTH2 ^$loop JNZ ( incr ) ~Sprite.x #0004 ADD2 =Sprite.x ,sliderc_icn =Sprite.addr @@ -248,9 +248,9 @@ RTN $hor ( draw ) ~color =Screen.color ( incr ) ~Screen.x ++ =Screen.x - ~Screen.x ~rect.x2 LTH2 ,$hor JNZ2 + ~Screen.x ~rect.x2 LTH2 ^$hor JNZ ( incr ) ~Screen.y ++ =Screen.y - ~Screen.y ~rect.y2 LTH2 ,$ver JNZ2 + ~Screen.y ~rect.y2 LTH2 ^$ver JNZ RTN @@ -261,13 +261,13 @@ RTN ( incr ) ~Screen.x ++ =Screen.x ( draw ) ~rect.y1 =Screen.y ~color =Screen.color ( draw ) ~rect.y2 =Screen.y ~color =Screen.color - ~Screen.x ~rect.x2 LTH2 ,$hor JNZ2 + ~Screen.x ~rect.x2 LTH2 ^$hor JNZ ~rect.y1 =Screen.y $ver ( draw ) ~rect.x1 =Screen.x ~color =Screen.color ( draw ) ~rect.x2 =Screen.x ~color =Screen.color ( incr ) ~Screen.y ++ =Screen.y - ~Screen.y ~rect.y2 ++ LTH2 ,$ver JNZ2 + ~Screen.y ~rect.y2 ++ LTH2 ^$ver JNZ RTN @@ -278,7 +278,7 @@ RTN ( draw ) DUP2 PEK2 #00 SWP #0008 MUL2 ,font ADD2 =Sprite.addr ~color =Sprite.color ( incr ) ++ ( incr ) ~Sprite.x 8+ =Sprite.x - DUP2 PEK2 #00 NEQ ,$loop JNZ2 + DUP2 PEK2 #00 NEQ ^$loop JNZ POP2 RTN diff --git a/projects/examples/gui.editor.usm b/projects/examples/gui.editor.usm index ceb55c2..4f63d6e 100644 --- a/projects/examples/gui.editor.usm +++ b/projects/examples/gui.editor.usm @@ -34,23 +34,23 @@ BRK @FRAME - ~Controller.buttons #00 EQU ,no-ctrl JNZ2 + ~Controller.buttons #00 EQU ^$no-ctrl JNZ - ~Controller.buttons #10 EQU ,no-ctrl-up JNZ2 + ~Controller.buttons #10 EQU ^$no-ctrl-up JNZ ~editor.addr #0001 ADD2 =editor.addr ,draw-window JSR2 ,draw-editor JSR2 - @no-ctrl-up + $no-ctrl-up - ~Controller.buttons #20 EQU ,no-ctrl-down JNZ2 + ~Controller.buttons #20 EQU ^$no-ctrl-down JNZ ~editor.addr #0001 SUB2 =editor.addr ,draw-window JSR2 ,draw-editor JSR2 - @no-ctrl-down + $no-ctrl-down - @no-ctrl + $no-ctrl - ~Mouse.state #00 EQU ,no-click JNZ2 + ~Mouse.state #00 EQU ^$no-click JNZ ( load ) ~editor.addr ~Mouse.y ~editor.y1 SUB2 #0008 DIV2 ADD2 PEK2 ( mask ) #01 #07 ~Mouse.x ~editor.x1 SUB2 #0008 DIV2 SWP POP SUB #40 SFT SFT @@ -60,7 +60,7 @@ BRK ,draw-window JSR2 ,draw-editor JSR2 - @no-click + $no-click ,draw-cursor JSR2 diff --git a/projects/examples/gui.hover.usm b/projects/examples/gui.hover.usm index 9a0d3f4..d3b5678 100644 --- a/projects/examples/gui.hover.usm +++ b/projects/examples/gui.hover.usm @@ -33,22 +33,22 @@ BRK ( matrix comparison ) ~Mouse.x ~r1.x1 GTH2 ~Mouse.x ~r1.x2 LTH2 #0101 EQU2 ~Mouse.y ~r1.y1 GTH2 ~Mouse.y ~r1.y2 LTH2 #0101 EQU2 - #0101 NEQ2 ,$draw1 JNZ2 #02 =color ,hand_icn =pointer.sprite + #0101 NEQ2 ^$draw1 JNZ #02 =color ,hand_icn =pointer.sprite $draw1 ~r1.x1 ~r1.y1 ~r1.x2 ~r1.y2 ~color ,line-rect JSR2 #01 =color ( 2-step comparison ) - ~Mouse.x ~r2.x1 GTH2 ~Mouse.x ~r2.x2 LTH2 #0101 NEQ2 ,$draw2 JNZ2 - ~Mouse.y ~r2.y1 GTH2 ~Mouse.y ~r2.y2 LTH2 #0101 NEQ2 ,$draw2 JNZ2 + ~Mouse.x ~r2.x1 GTH2 ~Mouse.x ~r2.x2 LTH2 #0101 NEQ2 ^$draw2 JNZ + ~Mouse.y ~r2.y1 GTH2 ~Mouse.y ~r2.y2 LTH2 #0101 NEQ2 ^$draw2 JNZ #03 =color ,hand_icn =pointer.sprite $draw2 ~r2.x1 ~r2.y1 ~r2.x2 ~r2.y2 ~color ,line-rect JSR2 #01 =color ( 4-step comparison ) - ~Mouse.x ~r3.x1 LTH2 ,$draw3 JNZ2 - ~Mouse.x ~r3.x2 GTH2 ,$draw3 JNZ2 - ~Mouse.y ~r3.y1 LTH2 ,$draw3 JNZ2 - ~Mouse.y ~r3.y2 GTH2 ,$draw3 JNZ2 + ~Mouse.x ~r3.x1 LTH2 ^$draw3 JNZ + ~Mouse.x ~r3.x2 GTH2 ^$draw3 JNZ + ~Mouse.y ~r3.y1 LTH2 ^$draw3 JNZ + ~Mouse.y ~r3.y2 GTH2 ^$draw3 JNZ #02 =color ,hand_icn =pointer.sprite $draw3 ~r3.x1 ~r3.y1 ~r3.x2 ~r3.y2 ~color ,line-rect JSR2 @@ -82,13 +82,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 JNZ2 + ~Screen.x ~rect.x2 LTH2 ^$hor JNZ ~rect.y1 =Screen.y $ver ( 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 JNZ2 + ~Screen.y ~rect.y2 #0001 ADD2 LTH2 ^$ver JNZ RTN diff --git a/projects/examples/gui.label.usm b/projects/examples/gui.label.usm index 7350993..114087b 100644 --- a/projects/examples/gui.label.usm +++ b/projects/examples/gui.label.usm @@ -23,7 +23,7 @@ $draw-ver ( draw ) #02 =Screen.color ( incr ) ~Screen.y #0002 ADD2 =Screen.y - ,$draw-ver ~Screen.y ~Screen.height LTH2 JNZ2 + ~Screen.y ~Screen.height LTH2 ^$draw-ver JNZ ~center.x ~center.y #0010 SUB2 #0c ,text1 ,draw-label-left JSR2 ~center.x ~center.y #0c ,text2 ,draw-label-middle JSR2 @@ -41,7 +41,7 @@ BRK ( draw ) DUP2 PEK2 #00 SWP #0008 MUL2 ,font ADD2 =Sprite.addr ~label.color =Sprite.color ( incr ) #0001 ADD2 ( incr ) ~Sprite.x #0008 ADD2 =Sprite.x - DUP2 PEK2 #00 NEQ ,$loop ROT JNZ2 + DUP2 PEK2 #00 NEQ ^$loop JNZ POP2 RTN @@ -55,7 +55,7 @@ RTN ( draw ) DUP2 PEK2 #00 SWP #0008 MUL2 ,font ADD2 =Sprite.addr ~label.color =Sprite.color ( incr ) #0001 ADD2 ( incr ) ~Sprite.x #0008 ADD2 =Sprite.x - DUP2 PEK2 #00 NEQ ,$loop ROT JNZ2 + DUP2 PEK2 #00 NEQ ^$loop JNZ POP2 RTN @@ -69,7 +69,7 @@ RTN ( draw ) DUP2 PEK2 #00 SWP #0008 MUL2 ,font ADD2 =Sprite.addr ~label.color =Sprite.color ( incr ) #0001 ADD2 ( incr ) ~Sprite.x #0008 ADD2 =Sprite.x - DUP2 PEK2 #00 NEQ ,$loop ROT JNZ2 + DUP2 PEK2 #00 NEQ ^$loop JNZ POP2 RTN @@ -79,7 +79,7 @@ RTN #0000 ( counter ) $loop ( incr ) #0001 ADD2 OVR2 OVR2 ADD2 - PEK2 #00 NEQ ,$loop ROT JNZ2 + PEK2 #00 NEQ ^$loop JNZ SWP2 POP2 RTN diff --git a/projects/examples/gui.picture.usm b/projects/examples/gui.picture.usm index 10cc493..f625f47 100644 --- a/projects/examples/gui.picture.usm +++ b/projects/examples/gui.picture.usm @@ -25,9 +25,9 @@ BRK ( draw ) ~pict.color =Sprite.color ( incr ) ~Sprite.x #0008 ADD2 =Sprite.x ( incr ) ~Sprite.addr #0008 ADD2 =Sprite.addr - ~Sprite.x ~pict.width ~pict.x ADD2 LTH2 ,$hor JNZ2 + ~Sprite.x ~pict.width ~pict.x ADD2 LTH2 ^$hor JNZ ( incr ) ~Sprite.y #0008 ADD2 =Sprite.y - ~Sprite.y ~pict.height ~pict.y ADD2 LTH2 ,$ver JNZ2 + ~Sprite.y ~pict.height ~pict.y ADD2 LTH2 ^$ver JNZ RTN diff --git a/projects/examples/gui.shapes.usm b/projects/examples/gui.shapes.usm index dfb31f1..0994d57 100644 --- a/projects/examples/gui.shapes.usm +++ b/projects/examples/gui.shapes.usm @@ -53,13 +53,13 @@ BRK ~line.dx ~line.dy ADD2 =line.e1 $loop ~line.x =Screen.x ~line.y =Screen.y ~color =Screen.color - ~line.x ~line.x0 EQU2 ~line.y ~line.y0 EQU2 #0101 EQU2 ,$end JNZ2 + ~line.x ~line.x0 EQU2 ~line.y ~line.y0 EQU2 #0101 EQU2 ^$end JNZ ~line.e1 #0002 MUL2 =line.e2 - ~line.e2 ~line.dy LTS2 ,$skipy JNZ2 + ~line.e2 ~line.dy LTS2 ^$skipy JNZ ~line.e1 ~line.dy ADD2 =line.e1 ~line.x ~line.sx ADD2 =line.x $skipy - ~line.e2 ~line.dx GTS2 ,$skipx JNZ2 + ~line.e2 ~line.dx GTS2 ^$skipx JNZ ~line.e1 ~line.dx ADD2 =line.e1 ~line.y ~line.sy ADD2 =line.y $skipx @@ -76,13 +76,13 @@ RTN ( incr ) ~Screen.x ++ =Screen.x ( draw ) ~rect.y1 =Screen.y ~color =Screen.color ( draw ) ~rect.y2 =Screen.y ~color =Screen.color - ~Screen.x ~rect.x2 LTH2 ,$hor JNZ2 + ~Screen.x ~rect.x2 LTH2 ^$hor JNZ ~rect.y1 =Screen.y $ver ( draw ) ~rect.x1 =Screen.x ~color =Screen.color ( draw ) ~rect.x2 =Screen.x ~color =Screen.color ( incr ) ~Screen.y ++ =Screen.y - ~Screen.y ~rect.y2 ++ LTH2 ,$ver JNZ2 + ~Screen.y ~rect.y2 ++ LTH2 ^$ver JNZ RTN @@ -94,9 +94,9 @@ RTN $hor ( draw ) ~color =Screen.color ( incr ) ~Screen.x ++ =Screen.x - ~Screen.x ~rect.x2 LTH2 ,$hor JNZ2 + ~Screen.x ~rect.x2 LTH2 ^$hor JNZ ( incr ) ~Screen.y ++ =Screen.y - ~Screen.y ~rect.y2 LTH2 ,$ver JNZ2 + ~Screen.y ~rect.y2 LTH2 ^$ver JNZ RTN @@ -109,9 +109,9 @@ RTN ( draw ) ~pict.color =Sprite.color ( incr ) ~Sprite.x 8+ =Sprite.x ( incr ) ~Sprite.addr 8+ =Sprite.addr - ~Sprite.x ~pict.width ~pict.x ADD2 LTH2 ,$hor JNZ2 + ~Sprite.x ~pict.width ~pict.x ADD2 LTH2 ^$hor JNZ ( incr ) ~Sprite.y 8+ =Sprite.y - ~Sprite.y ~pict.height ~pict.y ADD2 LTH2 ,$ver JNZ2 + ~Sprite.y ~pict.height ~pict.y ADD2 LTH2 ^$ver JNZ RTN @@ -123,7 +123,7 @@ RTN ( draw ) ,$seg JSR2 $loop ( incr ) ~circle.x ++ =circle.x - ~circle.d #0000 #0001 ADD2 LTS2 ,$else JNZ2 + ~circle.d #0000 #0001 ADD2 LTS2 ^$else JNZ ( decr ) ~circle.y -- =circle.y ~circle.x ~circle.y SUB2 #0004 MUL2 ~circle.d ADD2 #000a ADD2 =circle.d ,$end JMP2 @@ -131,7 +131,7 @@ RTN ~circle.x #0004 MUL2 ~circle.d ADD2 #0006 ADD2 =circle.d $end ( draw ) ,$seg JSR2 - ~circle.y ~circle.x #0001 SUB2 GTS2 ,$loop JNZ2 + ~circle.y ~circle.x #0001 SUB2 GTS2 ^$loop JNZ RTN $seg ~circle.xc ~circle.x ADD2 =Screen.x ~circle.yc ~circle.y ADD2 =Screen.y ~color =Screen.color