diff options
Diffstat (limited to 'tictactoe.tal')
| -rw-r--r-- | tictactoe.tal | 102 |
1 files changed, 58 insertions, 44 deletions
diff --git a/tictactoe.tal b/tictactoe.tal index a23b95f..fff95f4 100644 --- a/tictactoe.tal +++ b/tictactoe.tal @@ -25,26 +25,31 @@ #0050 .Screen/width DEO2 #0050 .Screen/height DEO2 ( | draw board ) - ( len 0x30 col 3 foreground ) #3043 - ( horizontal, start at 000f ) #010f - ( multiplier ) LIT2r 0404 + ;line-h .Screen/addr DEO2 + [ LIT2 52 -Screen/auto ] DEO + [ LIT2r 0f -Screen/sprite ] #04 &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 + #0010 .Screen/x DEO2 + DUP #01 SUB #00 SWP #40 SFT2 #000f ADD2 .Screen/y DEO2 + DEOrk + #01 SUB DUP ?&hor + POP #0010 .Screen/x DEO2 + #0040 .Screen/y DEO2 + DEOrk + ;line-v .Screen/addr DEO2 + [ LIT2 51 -Screen/auto ] DEO + #04 &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 + #0010 .Screen/y DEO2 + DUP #01 SUB #00 SWP #40 SFT2 #000f ADD2 .Screen/x DEO2 + DEOrk + #01 SUB DUP ?&ver + POP #0010 .Screen/y DEO2 + #0040 .Screen/x DEO2 + DEOr + ( | what is that? :} ) + #fe ;line-h STA + #00 ;line-v/e STA &restart ( -> ) ;on-controller .Controller/vector DEO2 init-game BRK @@ -71,10 +76,9 @@ ( save move ) .game/current-player LDZk ROT STZk ( display ) POP STHk SWP2 STH2k draw-move-at ( swap player ) ROTr STHr #03 EOR SWPk STZ - ( update cursor ) STH2r ROT draw-cursor-at POP - ( ) .game/moves LDZk INC SWP STZk - POP - ( game can't be ended before 5 moves ) #05 LTH ?&end + ( update cursor ) STH2r ROT #05 MUL draw-cursor-at POP + ( if moves<5 => skip check ) .game/moves LDZk INC SWP STZk + POP #05 LTH ?&end check-win BRK &up ( x y key -> ) POP clear-cursor move/- !&redraw @@ -88,7 +92,7 @@ &redraw ( x y -> ) ( save x y ) SWPk .game/x STZk NIP INC STZ - .game/current-player LDZ draw-cursor-at + .game/current-player LDZ #05 MUL draw-cursor-at &end ( -> ) BRK @@ -109,19 +113,30 @@ ( | clear screen ) #0010 .Screen/x DEO2k INC2 INC2 DEO2 - [ LIT2 80 -Screen/pixel ] DEO - ( cursor draw ) #0101 #01 + [ LIT2 c0 -Screen/pixel ] DEO + ( cursor draw ) #0101 #05 ( >> ) @draw-cursor-at ( x y col -- ) - STH pos-to-xy OVR2 OVR2 .Screen/y DEO2 - .Screen/x DEO2 - ( top ) #0e STHrk #01 draw-line - ( right ) #0e STHrk #02 draw-line - ( reset pos ) .Screen/y DEO2 - .Screen/x DEO2 - ( left ) #0e STHrk #02 draw-line - ( bottom ) #0f STHr #01 !draw-line + #40 ORA STH pos-to-xy + ( ) .Screen/y DEO2k + POP SWP2 .Screen/x DEO2k + POP ;line-h .Screen/addr DEO2 + [ LIT2 12 -Screen/auto ] DEO + ( top ) LITr -Screen/sprite DEOrk + .Screen/x DEO2k + POP SWP2 #000e ADD2k NIP2 .Screen/y DEO2 + ( bottom ) DEOrk + ;line-v .Screen/addr DEO2 + [ LIT2 11 -Screen/auto ] DEO + .Screen/y DEO2k + POP SWP2 .Screen/x DEO2k + ( left ) POP DEOrk + #000e ADD2 .Screen/x DEO2 + .Screen/y DEO2 + ( right ) DEOr + [ LIT2 00 -Screen/auto ] DEO + JMP2r @draw-move-at ( player x y -- ) pos-to-xy @@ -159,11 +174,11 @@ ( align ) .Screen/x DEI2k #0008 SUB2 ROT DEO2 [ LIT2 05 -Screen/auto ] DEO ;tie DUP2 .Screen/addr DEO2 - [ LIT2 01 -Screen/sprite ] DEOk + [ LIT2 41 -Screen/sprite ] DEOk DEO .Screen/addr DEO2 [ LIT2 00 -Screen/auto ] DEO - [ LIT2 11 -Screen/sprite ] DEO + [ LIT2 51 -Screen/sprite ] DEO JMP2r &x ( fig -- ) ;x .Screen/addr DEO2 @@ -172,16 +187,9 @@ ;o .Screen/addr DEO2 ( >> ) &end ( col -- ) - .Screen/sprite DEO + #40 ORA .Screen/sprite DEO JMP2r - -@draw-line ( len col dir -- ) - .Screen/auto DEO - SWP &while SWP .Screen/pixel DEOk - POP SWP #01 SUB DUP ?&while - POP2 [ LIT2 00 -Screen/auto ] DEO - JMP2r - + ( @|utils ) @@ -219,3 +227,9 @@ [ 0000 e010 1008 0807 0824 1410 0146 3800 ] +@line-h + [ ff00 0000 0000 0000 ] + +@line-v + [ 8080 8080 8080 80 &e 80 ] + |
