nxu/deck.tal

185 lines
4.9 KiB
Tal
Raw Normal View History

2023-05-11 10:48:17 -04:00
( 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 ]
2023-05-21 20:32:29 -04:00
|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 )
2023-05-11 10:48:17 -04:00
|0000
@prev-button $1
@prev-mouse-state $1
@prev-mouse-x $2
@prev-mouse-y $2
2023-05-18 10:27:55 -04:00
@card-is-held $1
2023-05-11 10:48:17 -04:00
|0100
2023-05-21 20:32:29 -04:00
init-rng-from-datetime
2023-05-11 10:48:17 -04:00
init-cards
2023-05-18 18:31:38 -04:00
reset
2023-05-11 10:48:17 -04:00
#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 )
2023-05-18 10:27:55 -04:00
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
2023-05-21 20:32:29 -04:00
@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
2023-05-18 10:27:55 -04:00
@on-move ( -> )
2023-05-11 10:48:17 -04:00
.Mouse/x DEI2 .prev-mouse-x LDZ2 NEQ2 ?&redraw
.Mouse/y DEI2 .prev-mouse-y LDZ2 NEQ2 ?&redraw
2023-05-18 10:27:55 -04:00
JMP2r
2023-05-11 10:48:17 -04:00
&redraw
2023-05-21 20:32:29 -04:00
( TODO: working stack overflow? )
2023-05-18 10:27:55 -04:00
.card-is-held LDZ #00 EQU ?&not-dragging
2023-05-21 20:32:29 -04:00
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
2023-05-18 10:27:55 -04:00
draw-background draw-cards ( TODO: fix me and remove this )
2023-05-21 20:32:29 -04:00
&not-dragging
2023-05-11 10:48:17 -04:00
#00 .Screen/auto DEO
2023-05-18 10:27:55 -04:00
clear-prev-mouse
( TODO: clear prev held card )
( TODO: draw curr held card )
draw-curr-mouse
JMP2r
@clear-prev-mouse ( -> )
2023-05-11 10:48:17 -04:00
.prev-mouse-x LDZ2 .Screen/x DEO2
.prev-mouse-y LDZ2 .Screen/y DEO2
;blank .Screen/addr DEO2
2023-09-13 13:13:05 -04:00
#41 .Screen/sprite DEO JMP2r
2023-05-18 10:27:55 -04:00
@draw-curr-mouse ( -> )
2023-05-11 10:48:17 -04:00
.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
2023-05-18 10:27:55 -04:00
#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
2023-05-21 20:32:29 -04:00
raise-cards .card-is-held STZ
!draw-cards
2023-05-11 10:48:17 -04:00
2023-05-18 10:27:55 -04:00
@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
2023-05-11 10:48:17 -04:00
@on-key ( -> brk )
2023-05-18 10:27:55 -04:00
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
2023-05-11 10:48:17 -04:00
DUP #01 AND ?&ctrl
DUP #02 AND ?&alt
DUP #04 AND ?&select
DUP #08 AND ?&start
2023-05-18 10:27:55 -04:00
&skip POP JMP2r
2023-05-21 20:32:29 -04:00
&ctrl POP !try-to-flip
2023-05-18 18:31:38 -04:00
&alt POP !flip-all-cards
2023-05-21 20:32:29 -04:00
&select POP !randomize
&start POP !reset
2023-05-18 18:31:38 -04:00
2023-06-08 16:25:40 -04:00
~cards.tal