working toward held cards

This commit is contained in:
~d6 2024-07-15 10:14:09 -04:00
parent d882d3bba6
commit bc608dc831
2 changed files with 75 additions and 60 deletions

View File

@ -381,15 +381,15 @@
( fall-through ) ( fall-through )
( @init-rng ( x* y* -> ) ) ( @init-rng ( x* y* -> ) )
#0001 ROT2 OVR2 ( y* 1* x* 1* ) #0001 ROT2 OVR2 ( y* 1* x* 1* )
ORA2 ;rng/x STA2 ( y* 1* ) ORA2 ;rng-x STA2 ( y* 1* )
ORA2 ;rng/x STA2 JMP2r ( ) ORA2 ;rng-x STA2 JMP2r ( )
@random ( -> x* ) @random ( -> x* )
;rng/x LDA2 DUP2 #50 SFT2 EOR2 ( t=x^[x<<5]* ) ;rng-x LDA2 DUP2 #50 SFT2 EOR2 ( t=x^[x<<5]* )
;rng/y LDA2 DUP2 ;rng/x STA2 ( t* y* ; x<-y ) ;rng-y LDA2 DUP2 ;rng-x STA2 ( t* y* ; x<-y )
DUP2 #01 SFT2 EOR2 ( t* u=y^[y>>1]* ) DUP2 #01 SFT2 EOR2 ( t* u=y^[y>>1]* )
SWP2 DUP2 #03 SFT2 EOR2 ( u* v=t^[t>>3]* ) SWP2 DUP2 #03 SFT2 EOR2 ( u* v=t^[t>>3]* )
EOR2 DUP2 ;rng/y STA2 JMP2r ( u^v* ; y<-u^v ) EOR2 DUP2 ;rng-y STA2 JMP2r ( u^v* ; y<-u^v )
( 52 cards x 4 bytes per card = 208 bytes ) ( 52 cards x 4 bytes per card = 208 bytes )
( each card has: ) ( each card has: )
@ -405,10 +405,12 @@
( @cards $0cc &last $4 &end ) ( @cards $0cc &last $4 &end )
@cursor 80c0 e0f0 f8e0 1000 @cursor 80c0 e0f0 f8e0 1000
@cursox 7f3f 1f0f 071f efff ( @cursox 7f3f 1f0f 071f efff )
@blank 0000 0000 0000 0000 @blank 0000 0000 0000 0000
@rng &x $2 &y $2 ( @rng &x $2 &y $2 )
@rng-x $2
@rng-y $2
( each tile is 16 bytes: a 2-bit 8x8 image ) ( each tile is 16 bytes: a 2-bit 8x8 image )
@tiles ~card-sprites.tal @tiles ~card-sprites.tal

View File

@ -30,10 +30,13 @@
@foundation $4 ( one per suit - 4 bytes, 4x1 ) @foundation $4 ( one per suit - 4 bytes, 4x1 )
@tableau $85 ( the main board - 133 bytes, 7x19 ) @tableau $85 ( the main board - 133 bytes, 7x19 )
@held $0d ( stack of up to 13 held cards ) @held $0d ( stack of up to 13 held cards )
@prev-button $1 ( previous button press ) @dragging [ $1 ( are we dragging? )
@prev-mouse-state $1 ( previous mouse state ) &x $2 ( x-coord for start of drag )
@prev-mouse-x $2 ( previous x-coordinate ) &y $2 ] ( y-coord for start of drag )
@prev-mouse-y $2 ( previous y-coordinate ) @prev [ &button $1 ( previous button press )
&mouse-state $1 ( previous mouse state )
&mouse-x $2 ( previous x-coordinate )
&mouse-y $2 ] ( previous y-coordinate )
|0100 |0100
#2d8b .System/r DEO2 #2d8b .System/r DEO2
@ -49,6 +52,8 @@
.foundation #04 initialize .foundation #04 initialize
.tableau #85 initialize .tableau #85 initialize
.held #0d initialize .held #0d initialize
.dragging #05 initialize
.prev #06 initialize
shuffle-stock shuffle-stock
deal-tableau deal-tableau
@ -64,11 +69,11 @@
draw-foundation draw-foundation
draw-tableau draw-tableau
;on-mouse .Mouse/vect DEO2 ;on-mouse .Mouse/vect DEO2
( ;on-key .Controller/vect DEO2 ) ;on-key .Controller/vect DEO2
BRK BRK
@not-holding-cards ( -> bool^ ) .held LDZ #00 EQU JMP2r ( @not-holding-cards ( -> bool^ ) .held LDZ #00 EQU JMP2r )
@holding-cards ( -> bool^ ) .held LDZ #00 NEQ JMP2r ( @holding-cards ( -> bool^ ) .held LDZ #00 NEQ JMP2r )
@initialize ( start^ count^ -> ) @initialize ( start^ count^ -> )
OVR ADD SWP STH2 #00 ( 0^ [lim=start+count^ start^] ) OVR ADD SWP STH2 #00 ( 0^ [lim=start+count^ start^] )
@ -112,13 +117,6 @@
#00 OVR STZ ( s^ ; s<-0 ) #00 OVR STZ ( s^ ; s<-0 )
#01 SUB JMP2r ( s-1^ ) #01 SUB JMP2r ( s-1^ )
@swap-c ( src^ dst^ -> )
LDZk STH ( src^ dst^ [d^] )
OVR LDZ ( src^ dst^ s^ [d^] )
SWP STZ ( src^ [d^] ; dst<-s )
STHr SWP ( d^ src^ )
STZ JMP2r ( ; src<-d )
@draw-stock ( -> ) @draw-stock ( -> )
#0008 ,&y STR2 ( ; y0<-8 ) #0008 ,&y STR2 ( ; y0<-8 )
.stock #34 OVR ADD SWP LITr 01 ( stock+52 stock^ [n^] ) .stock #34 OVR ADD SWP LITr 01 ( stock+52 stock^ [n^] )
@ -200,12 +198,12 @@
on-move on-move
on-click-down on-click-down
( on-click-up ) ( on-click-up )
.Mouse/state DEI .prev-mouse-state STZ .Mouse/state DEI .prev/mouse-state STZ
BRK BRK
@on-move ( -> ) @on-move ( -> )
.Mouse/x DEI2 .prev-mouse-x LDZ2 NEQ2 ?draw-mouse .Mouse/x DEI2 .prev/mouse-x LDZ2 NEQ2 ?draw-mouse
.Mouse/y DEI2 .prev-mouse-y LDZ2 NEQ2 ?draw-mouse .Mouse/y DEI2 .prev/mouse-y LDZ2 NEQ2 ?draw-mouse
JMP2r JMP2r
@draw-mouse ( -> ) @draw-mouse ( -> )
@ -213,25 +211,27 @@
clear-prev-mouse !draw-curr-mouse clear-prev-mouse !draw-curr-mouse
@clear-prev-mouse ( -> ) @clear-prev-mouse ( -> )
.prev-mouse-x LDZ2 .Screen/x DEO2 .prev/mouse-x LDZ2 .Screen/x DEO2
.prev-mouse-y LDZ2 .Screen/y DEO2 .prev/mouse-y LDZ2 .Screen/y DEO2
;blank .Screen/addr DEO2 ;blank .Screen/addr DEO2
#41 .Screen/sprite DEO JMP2r #41 .Screen/sprite DEO JMP2r
@draw-curr-mouse ( -> ) @draw-curr-mouse ( -> )
.Mouse/x DEI2 DUP2 .prev-mouse-x STZ2 .Screen/x DEO2 .Mouse/x DEI2 DUP2 .prev/mouse-x STZ2 .Screen/x DEO2
.Mouse/y DEI2 DUP2 .prev-mouse-y STZ2 .Screen/y DEO2 .Mouse/y DEI2 DUP2 .prev/mouse-y STZ2 .Screen/y DEO2
;cursor .Screen/addr DEO2 ;cursor .Screen/addr DEO2
#43 .Screen/sprite DEO JMP2r #43 .Screen/sprite DEO JMP2r
@on-click-down ( -> ) @on-click-down ( -> )
.Mouse/state DEI ( state^ ) .Mouse/state DEI ( state^ )
.prev-mouse-state LDZ #ff EOR AND ( down^ ) .prev/mouse-state LDZ #ff EOR AND ( down^ )
#01 AND ?&ok JMP2r &ok #01 AND ?&ok JMP2r &ok
maybe-select-stock ?&done maybe-select-stock ?&found
maybe-select-waste ?&done maybe-select-waste ?&found
maybe-select-tableau ?&done maybe-select-tableau ?&found
&done JMP2r ( not found )
.dragging #05 initialize
&found JMP2r
@find-top ( lim^ start^ -> zp^ ) @find-top ( lim^ start^ -> zp^ )
&loop LDZk ?&ok !&done &ok INC GTHk ?&loop &done NIP #01 SUB JMP2r &loop LDZk ?&ok !&done &ok INC GTHk ?&loop &done NIP #01 SUB JMP2r
@ -256,24 +256,32 @@
draw-stock #01 JMP2r ( 1^ ) draw-stock #01 JMP2r ( 1^ )
&no2 POPr &no1 #00 JMP2r ( 0^ ) &no2 POPr &no1 #00 JMP2r ( 0^ )
@start-drag ( x* y* -> )
( TODO: take t^ input, update t, update held )
.dragging/y STZ2 .dragging/x STZ2
#01 .dragging STZ JMP2r
@maybe-select-waste ( -> bool^ ) @maybe-select-waste ( -> bool^ )
.Mouse/y DEI2 #0008 LTH2 ?&no1 .Mouse/y DEI2 #0008 LTH2 ?&no1
.Mouse/y DEI2 #0020 GTH2 ?&no1 .Mouse/y DEI2 #0020 GTH2 ?&no1
top-waste STHk #00 EQU ?&no2 top-waste STHk #00 EQU ?&no2 ( [t^] )
#001c #00 STHkr .waste SUB #0008 MUL2 ADD2 ( 0x1c+8*index* ) #001c #00 STHkr .waste SUB #0008 MUL2 ADD2 ( w=0x1c+8*index* [t^ w*] )
.Mouse/x DEI2 GTH2 ?&no2 DUP2 ,&dx STR2 ( w* [t^ w*] ; dx<-w )
#002c #00 STHkr .waste SUB #0008 MUL2 ADD2 ( 0x2c+8*index* ) .Mouse/x DEI2 GTH2 ?&no2 ( [t^ w*] )
.Mouse/x DEI2 LTH2 ?&no2 #002c #00 STHkr .waste SUB #0008 MUL2 ADD2 ( 0x2c+8*index* [t^ w*] )
STHr LDZk #80 EOR SWP STZ draw-waste #01 JMP2r .Mouse/x DEI2 LTH2 ?&no2 ( [t^ w*] )
&no2 POPr &no1 #00 JMP2r LIT2 [ &dx $2 ] #0008 start-drag ( [^t] )
STHr LDZk #80 EOR SWP STZ draw-waste #01 JMP2r ( 1^ )
&no2 POP2r POPr &no1 #00 JMP2r ( 0^ )
@maybe-select-tableau ( -> bool^ ) @maybe-select-tableau ( -> bool^ )
.Mouse/y DEI2 #0024 LTH2 ?&no1 ( ) .Mouse/y DEI2 #0024 LTH2 ?&no1 ( )
.Mouse/x DEI2 #0030 LTH2 ?&no1 ( ) .Mouse/x DEI2 #0030 LTH2 ?&no1 ( )
.Mouse/x DEI2 #00cf GTH2 ?&no1 ( ) .Mouse/x DEI2 #00cf GTH2 ?&no1 ( )
#0040 LIT2r 0700 ( 64* [7^ 0^] ) #0040 LIT2r 0700 ( 64* [7^ 0^] )
&loop ( y* [lim^ i^] ) &loop ( x* [lim^ i^] )
.Mouse/x DEI2 OVR2 LTH2 ?&col ( y* [lim^ i^] ) DUP2 #0010 SUB2 ,&dx STR2 ( x* [lim^ i^] ; dx<-x )
.Mouse/x DEI2 OVR2 LTH2 ?&col ( x* [lim^ i^] )
#0008 ADD2 ( y1=y+8* [lim^ i^] ) #0008 ADD2 ( y1=y+8* [lim^ i^] )
.Mouse/x DEI2 OVR2 LTH2 ?&no2 ( y1* [lim^ i^] ) .Mouse/x DEI2 OVR2 LTH2 ?&no2 ( y1* [lim^ i^] )
#0010 ADD2 ( y2=y1+16* [lim^ i^] ) #0010 ADD2 ( y2=y1+16* [lim^ i^] )
@ -284,35 +292,40 @@
DUPk top-column STHk SWP bot-column ( i^ top^ bot^ [top^] ) DUPk top-column STHk SWP bot-column ( i^ top^ bot^ [top^] )
SUB #00 SWP ( i^ count* [top^] ) SUB #00 SWP ( i^ count* [top^] )
#0008 MUL2 #0024 ADD2 ( i^ min=0x24+8*i* [top^] ) #0008 MUL2 #0024 ADD2 ( i^ min=0x24+8*i* [top^] )
DUP2 ,&dy STR2 ( i^ min* [top^] ; dy<-min )
DUP2 #0018 ADD2 ( i^ min* max=min+0x18* [top^] ) DUP2 #0018 ADD2 ( i^ min* max=min+0x18* [top^] )
.Mouse/y DEI2 LTH2 #00 EQU STH ( i^ min* [top^ max>=y^] ) .Mouse/y DEI2 LTH2 #00 EQU STH ( i^ min* [top^ max>=y^] )
.Mouse/y DEI2 GTH2 #00 EQU STHr ( i^ min<=y^ max>=y^ [top^] ) .Mouse/y DEI2 GTH2 #00 EQU STHr ( i^ min<=y^ max>=y^ [top^] )
AND ?&ok ( i^ [top^] ) AND ?&ok ( i^ [top^] )
POP POPr #00 JMP2r ( 0^ ) POP POPr #00 JMP2r ( 0^ )
&ok STHr LDZk #80 EOR SWP STZ ( i^ ; top<-top^0x80 ) &ok LIT2 [ &dx $2 ] LIT2 [ &dy $2 ] ( i^ dx* dy* )
start-drag ( i^ )
STHr LDZk #80 EOR SWP STZ ( i^ ; top<-top^0x80 )
draw-column #01 JMP2r ( 1^ ) draw-column #01 JMP2r ( 1^ )
@on-click-up ( -> ) ( @on-click-up ( -> )
.Mouse/state DEI #ff EOR ( not-state^ ) .Mouse/state DEI #ff EOR ( not-state^ )
.prev-mouse-state LDZ AND ( up^ ) .prev/mouse-state LDZ AND ( up^ )
#01 AND ?{ JMP2r } JMP2r ( TODO: anything to do here? ) #01 AND ?{ JMP2r } JMP2r ( TODO: anything to do here? ) )
( @on-key ( -> brk ) @on-key ( -> brk )
on-press on-release on-press on-release
.Controller/button DEI .prev-button STZ .Controller/button DEI .prev/button STZ
BRK ) BRK
( @on-release ( -> ) @on-release ( -> )
.Controller/button DEI #ff EOR ( not-button^ ) JMP2r
.prev-button LDZ AND ( release^ ) ( .Controller/button DEI #ff EOR ( not-button^ )
.prev/button LDZ AND ( release^ )
DUP #00 EQU ?&skip DUP #00 EQU ?&skip
DUP #08 AND ?&start DUP #08 AND ?&start
&skip POP JMP2r &skip POP JMP2r
&start POP !draw-cards ) &start POP !draw-cards )
( @on-press ( -> ) @on-press ( -> )
.Controller/button DEI ( button^ ) JMP2r
.prev-button LDZ #ff EOR AND ( press^ ) ( .Controller/button DEI ( button^ )
.prev/button LDZ #ff EOR AND ( press^ )
DUP #00 EQU ?&skip DUP #00 EQU ?&skip
DUP #01 AND ?&ctrl DUP #01 AND ?&ctrl
DUP #02 AND ?&alt DUP #02 AND ?&alt