175 lines
5.5 KiB
Tal
175 lines
5.5 KiB
Tal
( cards.tal )
|
|
|
|
( CARD LAYOUT )
|
|
( )
|
|
( cards are stored as 16-bit values. )
|
|
( the high byte holds the flags. )
|
|
( the low byte holds the card id. )
|
|
( )
|
|
( 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. )
|
|
( )
|
|
( 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 )
|
|
|
|
@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
|
|
|
|
@draw-background ( -> )
|
|
#f2 .Screen/auto DEO
|
|
;tiles #0200 ADD2 .Screen/addr DEO2
|
|
#0080 .Screen/x DEO2
|
|
draw-background/twice
|
|
#0000 .Screen/x DEO2
|
|
&twice
|
|
#0000 .Screen/y DEO2
|
|
#81 .Screen/sprite
|
|
DEOk DEOk DEOk DEOk DEOk DEOk DEOk DEOk
|
|
DEOk DEOk DEOk DEOk DEOk DEOk DEOk DEOk
|
|
DEOk DEOk DEOk DEOk DEOk DEOk DEOk DEO JMP2r
|
|
|
|
@draw-spot-down ( -> )
|
|
#16 .Screen/auto DEO ( ; draw 2 tiles, increment x and addr )
|
|
;masks #0100 ADD2 .Screen/addr DEO2
|
|
#8d set-sprite-3x
|
|
JMP2r
|
|
|
|
( assumes x/y already set )
|
|
@draw-mask-down ( -> )
|
|
#16 .Screen/auto DEO ( ; draw 2 tiles, increment x and addr )
|
|
;masks #0100 ADD2 .Screen/addr DEO2
|
|
#86 set-sprite-3x ( TODO fixme )
|
|
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
|
|
#81 set-sprite-3x
|
|
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*] )
|
|
#0100 MUL2 ;masks #0300 ADD2 ( idx* 128r* card+384* [q*] )
|
|
ADD2 STH2r #0020 MUL2 ADD2 ( idx* a=card+384+128r+16q* )
|
|
STH2k .Screen/addr DEO2 ( idx* [a*] )
|
|
#86 set-sprite ( idx* [a*] ; draw top of card )
|
|
find-middle-addr ( mid* [a*] )
|
|
;tiles SUB2 ;masks ADD2
|
|
.Screen/addr DEO2 ( [a*] )
|
|
#86 set-sprite ( [a*] ; draw middle of card )
|
|
STH2r DUP2 #0010 ADD2 ( a* a+8* )
|
|
SWP2 #0008 .Screen/x DEI2 ADD2 .Screen/x DEO2
|
|
.Screen/addr DEO2 ( )
|
|
#01 .Screen/auto DEO ( ; draw 1 tile, increment x )
|
|
#b6 set-sprite ( ; draw bottom left of card )
|
|
.Screen/addr DEO2 ( )
|
|
#b6 set-sprite ( ; draw bottom right of card )
|
|
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*] )
|
|
#81 set-sprite ( idx* [a*] ; draw top of card )
|
|
find-middle-addr ( mid* [a*] )
|
|
.Screen/addr DEO2 ( [a*] )
|
|
#81 set-sprite ( [a*] ; draw middle of card )
|
|
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 )
|
|
#b1 set-sprite ( ; draw bottom left of card )
|
|
.Screen/addr DEO2 ( )
|
|
#b1 set-sprite ( ; draw bottom right of card )
|
|
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* )
|
|
DUP2 .DateTime/doy DEI2 EOR2 ( s* sdoy* )
|
|
#0001 ROT2 OVR2 ( y* 1* x* 1* )
|
|
ORA2 ;rng-x STA2 ( y* 1* )
|
|
ORA2 ;rng-x STA2 JMP2r ( )
|
|
|
|
@random ( -> x* )
|
|
;rng-x LDA2 DUP2 #50 SFT2 EOR2 ( t=x^[x<<5]* )
|
|
;rng-y LDA2 DUP2 ;rng-x STA2 ( t* y* ; x<-y )
|
|
DUP2 #01 SFT2 EOR2 ( t* u=y^[y>>1]* )
|
|
SWP2 DUP2 #03 SFT2 EOR2 ( u* v=t^[t>>3]* )
|
|
EOR2 DUP2 ;rng-y STA2 JMP2r ( u^v* ; y<-u^v )
|
|
|
|
( 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 )
|
|
|
|
@cursor 80c0 e0f0 f8e0 1000
|
|
( @cursox 7f3f 1f0f 071f efff )
|
|
@blank 0000 0000 0000 0000
|
|
|
|
( @rng &x $2 &y $2 )
|
|
@rng-x $2
|
|
@rng-y $2
|
|
|
|
( each tile is 16 bytes: a 2-bit 8x8 image )
|
|
@tiles ~card-sprites.tal
|
|
|
|
( each mask tile is 16 bytes: a 2-bit 8x8 image )
|
|
@masks ~mask2.tal
|