0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-05 13:55:06 +00:00
uxn/projects/examples/demos/hilbert.tal

77 lines
1.6 KiB
Tal
Raw Normal View History

2023-03-13 05:10:28 +00:00
|00 @System &vector $2 &wst $1 &rst $1 &eaddr $2 &ecode $1 &pad $1 &r $2 &g $2 &b $2 &debug $1 &halt $1
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
|0100
2024-01-21 16:39:29 +00:00
@on-reset ( -> )
( | theme )
2024-01-21 17:17:20 +00:00
#6fff .System/r DEO2
#7fff .System/g DEO2
#8fff .System/b DEO2
2024-01-21 16:39:29 +00:00
( | screen size )
2023-03-13 17:22:19 +00:00
#00c0
2024-01-21 16:39:29 +00:00
( ) DUP2 .Screen/width DEO2
( ) .Screen/height DEO2
2024-01-21 16:58:34 +00:00
( | pen )
#0020
( ) DUP2 .Screen/x DEO2
2024-01-21 17:38:25 +00:00
( ) .Screen/y DEO2
2024-01-21 16:39:29 +00:00
( | vector )
2023-03-13 17:22:19 +00:00
;on-frame .Screen/vector DEO2
2024-01-21 16:39:29 +00:00
BRK
2023-03-13 17:22:19 +00:00
@on-frame ( -> )
2024-01-21 17:38:25 +00:00
[ LIT2 &f $2 ] INC2 DUP2 ,&f STR2
DUP2 #0400 LTH2 ?{
POP2 #0000 .Screen/vector DEO2
BRK }
2024-01-21 16:58:34 +00:00
d2xy
2024-01-21 17:17:20 +00:00
( | draw line )
2024-01-21 17:38:25 +00:00
.Screen/y DEI2 diff ,&y STR2
.Screen/x DEI2 diff ,&x STR2
2024-01-21 17:17:20 +00:00
#0400
&l ( -- )
.Screen/x DEI2k [ LIT2 &x $2 ] ADD2 ROT DEO2
.Screen/y DEI2k [ LIT2 &y $2 ] ADD2 ROT DEO2
[ LIT2 01 -Screen/pixel ] DEO
INC GTHk ?&l
POP2 BRK
@diff ( a* b* -- dir* )
EQU2k ?{
2024-01-21 17:38:25 +00:00
LTH2 ?{ #0001 JMP2r }
2024-01-21 17:17:20 +00:00
#ffff JMP2r }
POP2 POP2 #0000 JMP2r
2023-03-13 05:10:28 +00:00
@d2xy ( d* -- x* y* )
,&t STR2
#0000
2024-01-21 16:39:29 +00:00
( ) DUP2 ,&x STR2
( ) ,&y STR2
2024-01-21 16:58:34 +00:00
#2001
&l ( -- )
#00 OVR STH2
[ LIT2 &t $2 ]
2024-01-21 17:38:25 +00:00
( ) DUP2k #01 SFT2 #0001 AND2 DUP2 ,&rx STR2
2024-01-21 16:58:34 +00:00
( ) EOR2 #0001 AND2 ,&ry STR2
( ) #02 SFT2 ,&t STR2
[ LIT2 &x $2 ] [ LIT2 &y $2 ] [ LIT2 &rx $2 ] [ LIT2 &ry $2 ]
( ) STH2kr rot
( ) STH2kr ,&ry LDR2 MUL2 ADD2 ,&y STR2
( ) STH2r ,&rx LDR2 MUL2 ADD2 ,&x STR2
DUP ADD GTHk ?&l
2023-03-13 17:22:19 +00:00
POP2
2024-01-21 16:39:29 +00:00
( ) ,&x LDR2 #20 SFT2 #0020 ADD2
( ) ,&y LDR2 #20 SFT2 #0020 ADD2 JMP2r
2023-03-13 05:10:28 +00:00
@rot ( x* y* rx* ry* n* -- x* y* )
2023-03-13 17:22:19 +00:00
#0001 SUB2 STH2
2023-03-13 05:10:28 +00:00
SWP2 ,&rx STR2
2024-01-21 16:39:29 +00:00
ORA ?{
[ LIT2 &rx $2 ] #0001 NEQ2 ?{
2023-03-13 05:10:28 +00:00
( rx-n-1 ) SWP2 STH2kr SWP2 SUB2
2024-01-21 16:39:29 +00:00
( ry-n-1 ) SWP2 STH2kr SWP2 SUB2 }
( swap ) SWP2 }
POP2r JMP2r
2023-03-13 05:10:28 +00:00