aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorla-ninpre <aaoth@aaoth.xyz>2023-08-28 15:53:21 +0300
committerla-ninpre <aaoth@aaoth.xyz>2023-08-28 15:53:21 +0300
commite55541a27cea7121d3c09ff10f99ade46d647bf4 (patch)
tree56367460d32fe8236230cf7ee942ec579208a02c
parentfb81c95b8347963840cf863a785f5d04146f8b48 (diff)
downloadtictactoe-e55541a27cea7121d3c09ff10f99ade46d647bf4.tar.gz
tictactoe-e55541a27cea7121d3c09ff10f99ade46d647bf4.zip
compact board drawing code
also make cursor change color in place
-rw-r--r--tictactoe.tal59
1 files changed, 33 insertions, 26 deletions
diff --git a/tictactoe.tal b/tictactoe.tal
index 4d496b6..168c870 100644
--- a/tictactoe.tal
+++ b/tictactoe.tal
@@ -25,24 +25,34 @@
#0050 .Screen/width DEO2
#0050 .Screen/height DEO2
( | draw board )
- ( ) #0010 #000f #3043 #01 draw-line-at
- ( ) #000f #0010 #3043 #02 draw-line-at
- ( ) #0010 #0040 #3043 #01 draw-line-at
- ( ) #0040 #0010 #3043 #02 draw-line-at
- ( | draw cells )
- ( ) #0010 #001f #3043 #01 draw-line-at
- ( ) #0010 #002f #3043 #01 draw-line-at
- ( ) #0010 #003f #3043 #01 draw-line-at
- ( ) #001f #0010 #3043 #02 draw-line-at
- ( ) #002f #0010 #3043 #02 draw-line-at
- ( ) #003f #0010 #3043 #02 draw-line-at
+ ( len 0x30 col 3 foreground ) #3043
+ ( horizontal, start at 000f ) #010f
+ ( multiplier ) LIT2r 0404
+ &hor ( -- )
+ OVR2 OVR2
+ ( x ) #0010 .Screen/x DEO2
+ ( y ) STHrk #01 SUB #40 SFT ADD #00 SWP .Screen/y DEO2
+ ( ) draw-line
+ ( ) LITr 01 SUBr STHrk ?&hor
+ POPr #0010 .Screen/y DEO2
+ ( shadow ) OVR2 OVR2 POP INC draw-line
+ ( vertical ) SWP INC SWP
+ &ver ( -- )
+ OVR2 OVR2
+ ( y ) #0010 .Screen/y DEO2
+ ( x ) STHrk #01 SUB #40 SFT ADD #00 SWP .Screen/x DEO2
+ ( ) draw-line
+ ( ) LITr 01 SUBr STHrk ?&ver
+ POPr #0010 .Screen/x DEO2
+ ( shadow ) POP2 #01 draw-line
&restart ( -> )
;on-controller .Controller/vector DEO2
init-game BRK
@on-controller ( -> )
[ LIT2 -game/y -game/x ] LDZ SWP LDZ
- ( ) .Controller/button DEI #01 ANDk NIP ?&play
+ ( ) .Controller/button DEI
+ ( ) #01 ANDk NIP ?&play
#10 ANDk NIP ?&up
#20 ANDk NIP ?&down
#40 ANDk NIP ?&left
@@ -55,19 +65,22 @@
( ) LDZk #00 EQU ?&draw
POP POP2 BRK
&draw ( x y addr -> )
- .game/current-player LDZ SWP STZk
- POP ROT ROT draw-move-at .game/moves LDZk INC SWP STZk
+ ( ) ROTk ROT clear-cursor POP2 POP
+ ( ) .game/current-player LDZ SWP STZk
+ ( ) POP ROT ROT STH2k draw-move-at
+ ( redraw ) STH2r .game/current-player LDZ draw-cursor-at
+ ( ) .game/moves LDZk INC SWP STZk
POP
( game can't be ended before 5 moves ) #05 LTH ?&end
check-win BRK
&up ( x y key -> )
- clear-cursor coord-dec !&redraw
+ POP clear-cursor coord-dec !&redraw
&down ( x y key -> )
- clear-cursor coord-inc !&redraw
+ POP clear-cursor coord-inc !&redraw
&left ( x y key -> )
- clear-cursor SWP coord-dec SWP !&redraw
+ POP clear-cursor SWP coord-dec SWP !&redraw
&right ( x y key -> )
- clear-cursor SWP coord-inc SWP
+ POP clear-cursor SWP coord-inc SWP
( >> )
&redraw ( x y -> )
( save x y ) SWPk .game/x STZk
@@ -158,12 +171,6 @@
[ LIT2 01 -game/current-player ] STZ
JMP2r
-@draw-line-at ( x* y* len col dir -- )
- STH2 STH .Screen/y DEO2
- .Screen/x DEO2
- STHr STH2r
- ( >> )
-
@draw-line ( len col dir -- )
.Screen/auto DEO
SWP &while SWP .Screen/pixel DEOk
@@ -174,8 +181,8 @@
(
@|utils )
-@clear-cursor ( x y key -- x y )
- POP DUP2 #00 !draw-cursor-at
+@clear-cursor ( x y -- x y )
+ DUP2 #00 !draw-cursor-at
@coord-dec ( c -- c' )
#00 EQUk NIP ?&end