2024-07-13 03:26:33 +01:00
|
|
|
( cards.tal )
|
|
|
|
|
|
|
|
( CARD LAYOUT )
|
|
|
|
( )
|
|
|
|
( cards are stored as 16-bit values. )
|
|
|
|
( the high byte holds the flags. )
|
|
|
|
( the low byte holds the card id. )
|
|
|
|
( )
|
2024-07-28 21:07:26 +01:00
|
|
|
( NOTE: this layout predates the one used by kodiak.tal )
|
|
|
|
( so, that file has functions to convert from its )
|
|
|
|
( card representation to this one for looking up tiles. )
|
|
|
|
( )
|
2024-07-13 03:26:33 +01:00
|
|
|
( FLAGS )
|
|
|
|
( bit 1: flipping, #80 face down, #00 face up )
|
|
|
|
( bits 2-6: unused )
|
|
|
|
( bits 7-8: rotation, #00 north, #01 east, #02 south, #03 west )
|
|
|
|
( )
|
|
|
|
( IDENTIFIER )
|
|
|
|
( 00: ace of spades )
|
|
|
|
( 01: two of spades )
|
|
|
|
( ... )
|
|
|
|
( 0c: king of spades )
|
|
|
|
( 0d: ace of hearts )
|
|
|
|
( 0e: two of hearts )
|
|
|
|
( ... )
|
|
|
|
( 19: king of hearts )
|
|
|
|
( 1a: ace of diamonds )
|
|
|
|
( 1b: two of diamonds )
|
|
|
|
( ... )
|
|
|
|
( 26: king of diamonds )
|
|
|
|
( 27: ace of clubs )
|
|
|
|
( 28: two of clubs )
|
|
|
|
( 33: king of clubs )
|
|
|
|
|
2024-07-16 15:06:58 +01:00
|
|
|
@set-fg ( -> ) #40 ,set-sprite/layer STR JMP2r
|
|
|
|
@set-bg ( -> ) #00 ,set-sprite/layer STR JMP2r
|
|
|
|
|
|
|
|
@set-sprite ( byte^ -> )
|
|
|
|
LIT [ &layer 00 ] ORA .Screen/sprite DEO JMP2r
|
|
|
|
|
|
|
|
@set-sprite-3x ( byte^ -> )
|
|
|
|
,set-sprite/layer LDR ORA .Screen/sprite DEOk DEOk DEO JMP2r
|
|
|
|
|
2024-07-13 03:26:33 +01:00
|
|
|
@draw-background ( -> )
|
2024-08-19 04:16:08 +01:00
|
|
|
#01 .Screen/auto DEO
|
|
|
|
#0000 .Screen/y DEO2
|
2024-07-13 03:26:33 +01:00
|
|
|
;tiles #0200 ADD2 .Screen/addr DEO2
|
2024-08-19 04:16:08 +01:00
|
|
|
.height LDZ2 #03 SFT2 #0000 &yloop
|
2024-07-13 03:26:33 +01:00
|
|
|
#0000 .Screen/x DEO2
|
2024-08-19 04:16:08 +01:00
|
|
|
.width LDZ2 #03 SFT2 #0000 &xloop
|
|
|
|
#81 .Screen/sprite DEO
|
|
|
|
INC2 GTH2k ?&xloop
|
|
|
|
POP2 POP2
|
|
|
|
.Screen/y DEI2 #0008 ADD2 .Screen/y DEO2
|
|
|
|
INC2 GTH2k ?&yloop
|
|
|
|
POP2 POP2 JMP2r
|
2024-07-13 03:26:33 +01:00
|
|
|
|
2024-07-16 15:06:58 +01:00
|
|
|
@draw-spot-down ( -> )
|
|
|
|
#16 .Screen/auto DEO ( ; draw 2 tiles, increment x and addr )
|
|
|
|
;masks #0100 ADD2 .Screen/addr DEO2
|
2024-07-17 01:49:19 +01:00
|
|
|
#8d set-sprite-3x
|
2024-07-16 15:06:58 +01:00
|
|
|
JMP2r
|
|
|
|
|
2024-07-13 03:26:33 +01:00
|
|
|
( assumes x/y already set )
|
|
|
|
@draw-mask-down ( -> )
|
|
|
|
#16 .Screen/auto DEO ( ; draw 2 tiles, increment x and addr )
|
2024-07-16 15:06:58 +01:00
|
|
|
;masks #0100 ADD2 .Screen/addr DEO2
|
2024-07-17 01:49:19 +01:00
|
|
|
#86 set-sprite-3x ( TODO fixme )
|
2024-07-13 03:26:33 +01:00
|
|
|
JMP2r
|
|
|
|
|
|
|
|
( assumes x/y already set )
|
|
|
|
@draw-face-down ( -> )
|
|
|
|
#16 .Screen/auto DEO ( ; draw 2 tiles, increment x and addr )
|
|
|
|
;tiles #0100 ADD2 .Screen/addr DEO2
|
2024-07-16 15:06:58 +01:00
|
|
|
#81 set-sprite-3x
|
2024-07-13 03:26:33 +01:00
|
|
|
JMP2r
|
|
|
|
|
|
|
|
@card-is-red ( idx* -> bool^ )
|
|
|
|
#000c DIV2
|
|
|
|
NIP #03 MUL #02 AND JMP2r ( [q*3]&2 )
|
|
|
|
|
|
|
|
@find-middle-addr ( idx* -> addr* )
|
|
|
|
#000d DIV2k STH2k MUL2 SUB2 ( r* [q*] )
|
|
|
|
DUP2 #000a LTH2 ?&normal
|
|
|
|
DUP2 #000a NEQ2 ?¬-j POP2 #0200 !&face
|
|
|
|
¬-j #000b NEQ2 ?¬-q #0100 !&face
|
|
|
|
¬-q #0000
|
|
|
|
&face ;tiles ADD2 #00c0 ADD2
|
|
|
|
STH2r card-is-red ?&is-red JMP2r
|
|
|
|
&is-red #0020 ADD2 JMP2r
|
|
|
|
&normal POP2 POP2r ;tiles #0020 ADD2 JMP2r
|
|
|
|
|
|
|
|
( assumes x/y already set )
|
|
|
|
@draw-mask-up ( idx* -> )
|
|
|
|
#16 .Screen/auto DEO ( ; draw 2 tiles, increment x and addr )
|
|
|
|
#00ff AND2 ( idx* ; remove rotation/flip info for now )
|
|
|
|
DUP2 ( idx* idx* )
|
|
|
|
#000d DIV2k STH2k MUL2 SUB2 ( idx* r* [q*] )
|
2024-07-16 15:06:58 +01:00
|
|
|
#0100 MUL2 ;masks #0300 ADD2 ( idx* 128r* card+384* [q*] )
|
|
|
|
ADD2 STH2r #0020 MUL2 ADD2 ( idx* a=card+384+128r+16q* )
|
2024-07-13 03:26:33 +01:00
|
|
|
STH2k .Screen/addr DEO2 ( idx* [a*] )
|
2024-07-17 01:49:19 +01:00
|
|
|
#86 set-sprite ( idx* [a*] ; draw top of card )
|
2024-07-13 03:26:33 +01:00
|
|
|
find-middle-addr ( mid* [a*] )
|
2024-07-16 15:06:58 +01:00
|
|
|
;tiles SUB2 ;masks ADD2
|
2024-07-13 03:26:33 +01:00
|
|
|
.Screen/addr DEO2 ( [a*] )
|
2024-07-17 01:49:19 +01:00
|
|
|
#86 set-sprite ( [a*] ; draw middle of card )
|
2024-07-16 15:06:58 +01:00
|
|
|
STH2r DUP2 #0010 ADD2 ( a* a+8* )
|
2024-07-13 03:26:33 +01:00
|
|
|
SWP2 #0008 .Screen/x DEI2 ADD2 .Screen/x DEO2
|
|
|
|
.Screen/addr DEO2 ( )
|
|
|
|
#01 .Screen/auto DEO ( ; draw 1 tile, increment x )
|
2024-07-17 01:49:19 +01:00
|
|
|
#b6 set-sprite ( ; draw bottom left of card )
|
2024-07-13 03:26:33 +01:00
|
|
|
.Screen/addr DEO2 ( )
|
2024-07-17 01:49:19 +01:00
|
|
|
#b6 set-sprite ( ; draw bottom right of card )
|
2024-07-13 03:26:33 +01:00
|
|
|
JMP2r
|
|
|
|
|
|
|
|
( assumes x/y already set )
|
|
|
|
@draw-face-up ( idx* -> )
|
|
|
|
#16 .Screen/auto DEO ( ; draw 2 tiles, increment x and addr )
|
|
|
|
#00ff AND2 ( idx* ; remove rotation/flip info for now )
|
|
|
|
DUP2 ( idx* idx* )
|
|
|
|
#000d DIV2k STH2k MUL2 SUB2 ( idx* r* [q*] )
|
|
|
|
#0100 MUL2 ;tiles #0300 ADD2 ( idx* 256r* card+768* [q*] )
|
|
|
|
ADD2 STH2r #0020 MUL2 ADD2 ( idx* a=card+768+256r+32q* )
|
|
|
|
STH2k .Screen/addr DEO2 ( idx* [a*] )
|
2024-07-16 15:06:58 +01:00
|
|
|
#81 set-sprite ( idx* [a*] ; draw top of card )
|
2024-07-13 03:26:33 +01:00
|
|
|
find-middle-addr ( mid* [a*] )
|
|
|
|
.Screen/addr DEO2 ( [a*] )
|
2024-07-16 15:06:58 +01:00
|
|
|
#81 set-sprite ( [a*] ; draw middle of card )
|
2024-07-13 03:26:33 +01:00
|
|
|
STH2r DUP2 #0010 ADD2 ( a* a+16* )
|
|
|
|
SWP2 #0008 .Screen/x DEI2 ADD2 .Screen/x DEO2
|
|
|
|
.Screen/addr DEO2 ( )
|
|
|
|
#01 .Screen/auto DEO ( ; draw 1 tile, increment x )
|
2024-07-16 15:06:58 +01:00
|
|
|
#b1 set-sprite ( ; draw bottom left of card )
|
2024-07-13 03:26:33 +01:00
|
|
|
.Screen/addr DEO2 ( )
|
2024-07-16 15:06:58 +01:00
|
|
|
#b1 set-sprite ( ; draw bottom right of card )
|
2024-07-13 03:26:33 +01:00
|
|
|
JMP2r
|
|
|
|
|
|
|
|
@init-rng-from-datetime ( -> )
|
|
|
|
#00 .DateTime/dow #5180 MUL2
|
|
|
|
#00 .DateTime/hr DEI #0e10 MUL2 ADD2
|
|
|
|
#00 .DateTime/min DEI #003c MUL2 ADD2
|
|
|
|
#00 .DateTime/sec DEI ADD2 ( s* )
|
2024-07-28 21:22:13 +01:00
|
|
|
DUP2 .DateTime/doy DEI2 EOR2 ( s* sdoy* )
|
2024-07-13 03:26:33 +01:00
|
|
|
#0001 ROT2 OVR2 ( y* 1* x* 1* )
|
2024-07-15 15:14:09 +01:00
|
|
|
ORA2 ;rng-x STA2 ( y* 1* )
|
|
|
|
ORA2 ;rng-x STA2 JMP2r ( )
|
2024-07-13 03:26:33 +01:00
|
|
|
|
|
|
|
@random ( -> x* )
|
2024-07-15 15:14:09 +01:00
|
|
|
;rng-x LDA2 DUP2 #50 SFT2 EOR2 ( t=x^[x<<5]* )
|
|
|
|
;rng-y LDA2 DUP2 ;rng-x STA2 ( t* y* ; x<-y )
|
2024-07-13 03:26:33 +01:00
|
|
|
DUP2 #01 SFT2 EOR2 ( t* u=y^[y>>1]* )
|
|
|
|
SWP2 DUP2 #03 SFT2 EOR2 ( u* v=t^[t>>3]* )
|
2024-07-15 15:14:09 +01:00
|
|
|
EOR2 DUP2 ;rng-y STA2 JMP2r ( u^v* ; y<-u^v )
|
2024-07-13 03:26:33 +01:00
|
|
|
|
|
|
|
( 52 cards x 4 bytes per card = 208 bytes )
|
|
|
|
( each card has: )
|
|
|
|
( )
|
|
|
|
( - byte 1: flags )
|
|
|
|
( - byte 2: card suit/value )
|
|
|
|
( - byte 3: x position )
|
|
|
|
( - byte 4: y position )
|
|
|
|
|
2024-07-15 15:14:09 +01:00
|
|
|
( @rng &x $2 &y $2 )
|
|
|
|
@rng-x $2
|
|
|
|
@rng-y $2
|
2024-07-13 03:26:33 +01:00
|
|
|
|
|
|
|
( each tile is 16 bytes: a 2-bit 8x8 image )
|
|
|
|
@tiles ~card-sprites.tal
|
|
|
|
|
2024-07-16 15:06:58 +01:00
|
|
|
( each mask tile is 16 bytes: a 2-bit 8x8 image )
|
|
|
|
@masks ~mask2.tal
|