uxn-utils/cli/base64/b64enc.tal

68 lines
1.2 KiB
Tal
Raw Normal View History

2023-05-24 12:46:15 -04:00
( uxncli b64enc.rom file.bin )
|10 @Console &vector $2 &read $1 &pad $5 &write $1 &error $1
|a0 @File &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
2023-05-24 12:59:55 -04:00
|0000 @src $40 @queue $1
2023-05-24 12:46:15 -04:00
|0100 ( -> )
;await-src .Console/vector DEO2
BRK
@await-src ( -> )
.Console/read DEI .src skey ?on-ready
BRK
@on-ready ( -> )
;src .File/name DEO2
#0001 .File/length DEO2
;&buf
&stream
DUP2 .File/read DEO2
.File/success DEI2 #0000 EQU2 ?&eof
LDAk append
!&stream &eof
POP2
2023-05-24 12:59:55 -04:00
( pad )
.queue LDZ #00 EQU ?&no-pad
#00 append
&no-pad
2023-05-24 12:46:15 -04:00
#0a18 DEO
#010f DEO
BRK
&buf $1
2023-05-24 12:59:55 -04:00
(
@|core )
2023-05-24 12:46:15 -04:00
2023-05-24 13:06:34 -04:00
@append ( byte -- )
,&buf STR
2023-05-24 12:46:15 -04:00
#0800
&l
2023-05-24 13:06:34 -04:00
[ LIT &buf $1 ] OVR #07 SWP SUB SFT #01 AND
2023-05-24 12:46:15 -04:00
[ LIT &inc $1 ] INCk #06 DIVk MUL SUB ,&inc STR
( bit id -- )
2023-05-24 12:59:55 -04:00
SWP .queue LDZ ORA DUP ADD .queue STZ
2023-05-24 12:46:15 -04:00
#05 NEQ ?&no-cap
2023-05-24 12:59:55 -04:00
[ LIT2 00 -queue ]
DUP2 LDZ #01 SFT ;MIME ADD2 LDA #18 DEO
STZ
2023-05-24 12:46:15 -04:00
&no-cap
INC GTHk ?&l
POP2
JMP2r
@MIME [
"ABCDEFGHIJKLMNOP
"QRSTUVWXYZabcdef
"ghijklmnopqrstuv
"wxyz0123456789+/ ]
2023-05-24 12:59:55 -04:00
(
@|stdlib )
2023-05-24 12:46:15 -04:00
@skey ( key buf -- proc ) OVR #21 LTH ?&eval #00 SWP sput #00 JMP2r &eval POP2 #01 JMP2r
@scap ( str* -- end* ) LDAk #00 NEQ [ JMP JMP2r ] &w INC2 LDAk ?&w JMP2r
@sput ( chr str* -- ) scap INC2k #00 ROT ROT STA STA JMP2r