uxn-utils/cli/base64/b64enc.tal

85 lines
1.4 KiB
Tal
Raw Normal View History

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