nxu/deck.tal

185 lines
4.9 KiB
Tal

( deck.tal )
( CARD LAYOUT )
( )
( cards are stored as 16-bit values. )
( the high byte holds the flags. )
( the low byte holds the card id. )
( )
( 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 )
( ... )
( 0b: king of spades )
( 0c: ace of hearts )
( 0d: 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 )
|00 @System [ &vect $2 &expansion $2 &title $2 &metadata $2 &r $2 &g $2 &b $2 ]
|10 @Console [ &vect $2 &r $1 &exec $2 &mode $1 &dead $1 &exit $1 &w $1 ]
|20 @Screen [ &vect $2 &w $2 &h $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &px $1 &sprite $1 ]
|80 @Controller [ &vect $2 &button $1 &key $1 &fn $1 ]
|90 @Mouse [ &vect $2 &x $2 &y $2 &state $1 &pad $3 &scrollx $2 &scrolly $2 ]
|a0 @File1 [ &vect $2 &ok $2 &stat $2 &del $1 &append $1 &name $2 &len $2 &r $2 &w $2 ]
|b0 @File2 [ &vect $2 &ok $2 &stat $2 &del $1 &append $1 &name $2 &len $2 &r $2 &w $2 ]
|c0 @DateTime [ &y $2 &m $1 &d $1 &hr $1 &min $1 &sec $1 &dow $1 &doy $2 &isdst $1 ]
( BUG: stack is growing, maybe redraw-all ? )
( TODO: move piles )
( TODO: shuffle deck only )
( TODO: try out rounded corners )
( - face down can use white as transparent )
( - face up black cards use red as transparent )
( - face up red cards use black as transparent )
( TODO: optional snap-to-grid setting? )
( ROTATION )
( N 00 to E 01: dx=+0 dy=+8 )
( 01 to 02: dx=+0 dy=+0 )
( 02 to 03: dx=-8 dy=+0 )
( 03 to 00: dx=+8 dy=-8 )
( will require unhardcoding bounding boxes )
( BUG: try moving the "whole deck" and get into a weird state )
|0000
@prev-button $1
@prev-mouse-state $1
@prev-mouse-x $2
@prev-mouse-y $2
@card-is-held $1
|0100
init-rng-from-datetime
init-cards
reset
#2d8b .System/r DEO2
#2d18 .System/g DEO2
#2d14 .System/b DEO2
#0100 .Screen/w DEO2
#00c0 .Screen/h DEO2
;on-key .Controller/vect DEO2
;on-mouse .Mouse/vect DEO2
draw-background
draw-cards
BRK
@on-mouse ( -> brk )
on-move
on-click-down
on-click-up
.Mouse/state DEI .prev-mouse-state STZ
BRK
@mouse-dx ( -> dx* ) .Mouse/x DEI2 .prev-mouse-x LDZ2 SUB2 JMP2r
@mouse-dy ( -> dy* ) .Mouse/y DEI2 .prev-mouse-y LDZ2 SUB2 JMP2r
@mouse-dx8 ( -> dx^ ) .Mouse/x DEI2 .prev-mouse-x LDZ2 SUB2 NIP JMP2r
@mouse-dy8 ( -> dy^ ) .Mouse/y DEI2 .prev-mouse-y LDZ2 SUB2 NIP JMP2r
@on-move ( -> )
.Mouse/x DEI2 .prev-mouse-x LDZ2 NEQ2 ?&redraw
.Mouse/y DEI2 .prev-mouse-y LDZ2 NEQ2 ?&redraw
JMP2r
&redraw
( TODO: working stack overflow? )
.card-is-held LDZ #00 EQU ?&not-dragging
mouse-dx8 mouse-dy8 STH2 ( [dxdy*] )
;cards/end held-end-offset ( limit* start* [dxdy*] )
&hloop
DUP2 STH2kr move-card ( limit* pos* [dxdy*] )
#0004 ADD2 GTH2k ?&hloop ( limit* pos+4* [dxdy*] )
POP2 POP2 POP2r
draw-background draw-cards ( TODO: fix me and remove this )
&not-dragging
#00 .Screen/auto DEO
clear-prev-mouse
( TODO: clear prev held card )
( TODO: draw curr held card )
draw-curr-mouse
JMP2r
@clear-prev-mouse ( -> )
.prev-mouse-x LDZ2 .Screen/x DEO2
.prev-mouse-y LDZ2 .Screen/y DEO2
;blank .Screen/addr DEO2
#41 .Screen/sprite DEO JMP2r
@draw-curr-mouse ( -> )
.Mouse/x DEI2 DUP2 .prev-mouse-x STZ2 .Screen/x DEO2
.Mouse/y DEI2 DUP2 .prev-mouse-y STZ2 .Screen/y DEO2
;cursor .Screen/addr DEO2
#43 .Screen/sprite DEO JMP2r
@on-click-down ( -> )
.Mouse/state DEI ( state^ )
.prev-mouse-state LDZ #ff EOR AND ( down^ )
#01 AND ( TODO: support more than one button )
?&click JMP2r ( TODO: check particular button )
&click
find-mouse-over-card
ORAk ?&found POP2 JMP2r
&found
raise-cards .card-is-held STZ
!draw-cards
@on-click-up ( -> )
.Mouse/state DEI #ff EOR ( not-state^ )
.prev-mouse-state LDZ AND ( up^ )
#01 AND ( TODO: support more than one button )
?&unclick JMP2r ( TODO: check particular button )
&unclick
#00 .card-is-held STZ
draw-background draw-cards
JMP2r
@on-key ( -> brk )
on-press on-release
.Controller/button DEI .prev-button STZ
BRK
@on-release ( -> )
.Controller/button DEI #ff EOR ( not-button^ )
.prev-button LDZ AND ( release^ )
DUP #00 EQU ?&skip
DUP #08 AND ?&start
&skip POP JMP2r
&start POP !draw-cards
@on-press ( -> )
.Controller/button DEI ( button^ )
.prev-button LDZ #ff EOR AND ( press^ )
DUP #00 EQU ?&skip
DUP #01 AND ?&ctrl
DUP #02 AND ?&alt
DUP #04 AND ?&select
DUP #08 AND ?&start
&skip POP JMP2r
&ctrl POP !try-to-flip
&alt POP !flip-all-cards
&select POP !randomize
&start POP !reset
~cards.tal