uxn/projects/examples/devices/screen.tal

148 lines
3.1 KiB
Tal
Raw Normal View History

2021-04-24 13:15:47 -04:00
( dev/screen )
%RTN { JMP2r }
( devices )
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ]
2021-04-24 13:15:47 -04:00
( variables )
|0000
@center [ &x $2 &y $2 ]
( init )
|0100 ( -> )
( theme )
#f07f .System/r DEO2
#f0e0 .System/g DEO2
#f0c0 .System/b DEO2
2021-04-24 13:15:47 -04:00
( find screen center )
2021-08-01 14:00:07 -04:00
.Screen/width DEI2 #01 SFT2 #0020 SUB2 .center/x STZ2
.Screen/height DEI2 #01 SFT2 .center/y STZ2
2021-04-24 13:15:47 -04:00
( draw )
2021-04-29 13:10:07 -04:00
;draw-table JSR2
2021-08-01 14:28:37 -04:00
;draw-sprites JSR2
2021-08-01 14:00:07 -04:00
;draw-1bpp JSR2
;draw-2bpp JSR2
;draw-pixels JSR2
2021-04-24 13:15:47 -04:00
BRK
2021-04-29 13:10:07 -04:00
@draw-table ( -- )
2021-08-02 11:59:16 -04:00
#10 #00
2021-04-29 13:10:07 -04:00
&loop
2021-08-02 11:59:16 -04:00
DUP #08 MUL #00 SWP ;font-hex ADD2 .Screen/addr DEO2
2021-04-29 13:10:07 -04:00
( x-axis )
2021-08-02 11:59:16 -04:00
DUP #08 MUL #00 SWP
2021-05-11 14:14:52 -04:00
.center/x LDZ2 #0040 SUB2 ADD2 .Screen/x DEO2
.center/y LDZ2 #0050 SUB2 .Screen/y DEO2
( draw ) #01 .Screen/sprite DEO
2021-04-29 13:10:07 -04:00
( y-axis )
2021-08-02 11:59:16 -04:00
DUP #08 MUL #00 SWP
2021-05-11 14:14:52 -04:00
.center/y LDZ2 #0040 SUB2 ADD2 .Screen/y DEO2
.center/x LDZ2 #0050 SUB2 .Screen/x DEO2
( draw ) #01 .Screen/sprite DEO
2021-08-02 11:59:16 -04:00
#01 ADD GTHk ,&loop JCN
2021-04-29 00:00:39 -04:00
POP2
2021-04-29 13:10:07 -04:00
RTN
@draw-sprites ( -- )
;preview_icn .Screen/addr DEO2
#00 #00
&loop
2021-08-02 11:59:16 -04:00
( move ) DUP #0f AND #40 SFT #02 DIV #00 SWP
.center/x LDZ2 #0040 SUB2 ADD2 .Screen/x DEO2
2021-08-02 11:59:16 -04:00
( move ) DUP #f0 AND #02 DIV #00 SWP
.center/y LDZ2 #0040 SUB2 ADD2 .Screen/y DEO2
2021-08-02 11:59:16 -04:00
( draw ) DUP .Screen/sprite DEO
( incr ) #01 ADD
NEQk ,&loop JCN
POP2
RTN
2021-08-01 14:00:07 -04:00
@draw-1bpp ( -- )
2021-08-02 11:59:16 -04:00
#10 #00
2021-08-01 14:00:07 -04:00
&loop
2021-08-02 11:59:16 -04:00
( color ) STHk
( y ) DUP #04 DIV [ #00 SWP ] #0010 MUL2
2021-08-01 14:00:07 -04:00
[ .center/y LDZ2 #0040 SUB2 ADD2 ] STH2
2021-08-02 11:59:16 -04:00
( x ) DUP #03 AND [ #00 SWP ] #0010 MUL2 #0040 ADD2
2021-08-01 14:00:07 -04:00
[ .center/x LDZ2 #0008 ADD2 ADD2 ]
STH2r STHr #00 ;draw-circle JSR2
2021-08-02 11:59:16 -04:00
#01 ADD GTHk ,&loop JCN
2021-08-01 14:00:07 -04:00
POP2
RTN
@draw-2bpp ( -- )
2021-08-02 11:59:16 -04:00
#10 #00
2021-08-01 14:00:07 -04:00
&loop
2021-08-02 11:59:16 -04:00
( color ) STHk
( y ) DUP #04 DIV [ #00 SWP ] #0010 MUL2
2021-08-01 14:00:07 -04:00
[ .center/y LDZ2 ADD2 ] STH2
2021-08-02 11:59:16 -04:00
( x ) DUP #03 AND [ #00 SWP ] #0010 MUL2 #0040 ADD2
2021-08-01 14:00:07 -04:00
[ .center/x LDZ2 #0008 ADD2 ADD2 ]
STH2r STHr #80 ;draw-circle JSR2
2021-08-02 11:59:16 -04:00
#01 ADD GTHk ,&loop JCN
2021-08-01 14:00:07 -04:00
POP2
2021-08-01 14:28:37 -04:00
2021-08-01 14:00:07 -04:00
RTN
@draw-circle ( x* y* color depth -- )
ADD STH
2021-04-29 13:10:07 -04:00
;preview_icn .Screen/addr DEO2
2021-08-01 14:00:07 -04:00
.Screen/y DEO2
.Screen/x DEO2
#00 STHkr ADD .Screen/sprite DEO
.Screen/x DEI2 #0008 ADD2 .Screen/x DEO2
#10 STHkr ADD .Screen/sprite DEO
.Screen/x DEI2 #0008 SUB2 .Screen/x DEO2
.Screen/y DEI2 #0008 ADD2 .Screen/y DEO2
#20 STHkr ADD .Screen/sprite DEO
.Screen/x DEI2 #0008 ADD2 .Screen/x DEO2
#30 STHr ADD .Screen/sprite DEO
RTN
@draw-pixels ( -- )
.center/y LDZ2 #0040 SUB2 .Screen/y DEO2
.center/x LDZ2 #0048 ADD2 .Screen/x DEO2
#00 .Screen/pixel DEO
.center/x LDZ2 #0049 ADD2 .Screen/x DEO2
#01 .Screen/pixel DEO
.center/x LDZ2 #004a ADD2 .Screen/x DEO2
#02 .Screen/pixel DEO
.center/x LDZ2 #004b ADD2 .Screen/x DEO2
#03 .Screen/pixel DEO
2021-04-29 13:10:07 -04:00
2021-04-24 13:15:47 -04:00
RTN
2021-05-12 21:28:45 -04:00
@preview_icn [
0f38 675f dfbf bfbf 0007 1820 2344 4848
2021-04-29 13:10:07 -04:00
2021-05-12 21:28:45 -04:00
@font-hex
2021-04-29 13:10:07 -04:00
007c 8282 8282 827c 0030 1010 1010 1010
007c 8202 7c80 80fe 007c 8202 1c02 827c
000c 1424 4484 fe04 00fe 8080 7c02 827c
007c 8280 fc82 827c 007c 8202 1e02 0202
007c 8282 7c82 827c 007c 8282 7e02 827c
007c 8202 7e82 827e 00fc 8282 fc82 82fc
007c 8280 8080 827c 00fc 8282 8282 82fc
007c 8280 f080 827c 007c 8280 f080 8080