uxn-utils/gui/sixels/icnsix.tal

124 lines
2.2 KiB
Tal

|10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1
|a0 @File &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
|0000
@src $40
|0100
@on-reset ( -> )
;on-console .Console/vector DEO2
BRK
@on-console ( -> )
.Console/read DEI DUP #20 LTH OVR #7f GTH ORA ?{
;src scap STA
BRK }
POP
( | get size )
;src scap #0009 SUB2 parse-size
( h ) ;img/height STA
( w ) ;img/width STA
( | get data )
;src .File/name DEO2
#00 ;img/width LDA #00 ;img/height LDA #30 SFT2 MUL2 .File/length DEO2
;img/data .File/read DEO2
<convert>
#010e DEO
#010f DEO
BRK
@parse-size ( 00x00* -- w h )
DUP2 sbyte #00 EQU ?&cancel
INC2k INC2 LDA LIT "x NEQ ?&cancel
INC2k INC2 INC2 sbyte #00 EQU ?&cancel
( y ) INC2k INC2 INC2 sbyte STH
( x ) sbyte STHr JMP2r
&cancel POP2 #0000 JMP2r
(
@| core )
@<convert> ( -- )
#00 ;img/height LDA #30 SFT2 #0000
&v ( -- )
STH2k
#00 ;img/width LDA #30 SFT2 #0000
&w ( -- )
( DUP2 phex #2018 DEO
STH2kr phex #2018 DEO )
DUP2 STH2kr get-sixel #18 DEO
( #0a18 DEO )
INC2 GTH2k ?&w
POP2 POP2 POP2r
[ LIT "- ] #18 DEO
#0006 ADD2 GTH2k ?&v
POP2 POP2
JMP2r
@get-sixel ( x* y* -- byte )
SWP2 ,&x STR2
[ LITr 00 ]
DUP2 #0006 ADD2 SWP2
&l ( -- )
[ LITr 10 ] SFTr
[ LIT2 &x $2 ] OVR2 get-pixel STH ORAr
INC2 GTH2k ?&l
POP2 POP2
STHr [ LIT "? ] ADD
JMP2r
@get-row ( x* y* -- row* )
STH2k
( ) #03 SFT2 SWP2
( ) #03 SFT2 SWP2
( ) #00 ;img/width LDA MUL2 ADD2 #30 SFT2
( ) STH2r #0007 AND2 ADD2
( ) ;img/data ADD2 JMP2r
@get-pixel ( x* y* -- b )
( keep x* ) OVR2 NIP #07 AND STH
( get byte ) get-row LDA
( flag ) #07 STHr SUB SFT #01 AND JMP2r
(
@|stdlib )
@sbyte ( str* -- byte )
( hn ) LDAk chex #40 SFT STH INC2
( ln ) LDA chex STHr ORA JMP2r
@chex ( c -- val? )
( dec ) [ LIT "0 ] SUB DUP #09 GTH ?{ JMP2r }
( hex ) #27 SUB DUP #0f GTH ?{ JMP2r }
( err ) POP #ff JMP2r
@slen ( str* -- len* )
DUP2 scap SWP2 SUB2 JMP2r
@scap ( str* -- end* )
LDAk #00 NEQ [ JMP JMP2r ] &w INC2 LDAk ?&w
JMP2r
@phex ( short* -- )
SWP phex/b &b DUP #04 SFT phex/c &c #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO
JMP2r
@<pstr> ( str* -- )
&w ( -- )
LDAk #18 DEO
INC2 LDAk ?&w
POP2 JMP2r
(
@|memory )
@img ( )
&size &width $1
&height $1
&data