Stream characters from io instead of file

This commit is contained in:
neauoire 2023-09-05 16:38:16 -07:00
parent ea9e70b592
commit 1a03280a93
2 changed files with 23 additions and 62 deletions

View File

@ -1,84 +1,48 @@
( uxncli b64enc.rom file.bin )
( uxncli b64enc.rom "string" )
|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
@queue $1
|0100
@on-reset ( -> )
.Console/type DEI ?{ ;usage <print-err>/ #010f DEO }
;await-src .Console/vector DEO2
;on-console .Console/vector DEO2
BRK
@await-src ( -> )
.Console/read DEI .src skey ?on-ready
BRK
@on-ready ( -> )
;src .File/name DEO2
#0001 .File/length DEO2
&s ( -- )
;&b .File/read DEO2
.File/success DEI2 #0000 EQU2 ?&eof
[ LIT &b $1 ] b64enc !&s
&eof
( | pad )
.queue LDZ #00 EQU ?&>no-pad
#00 b64enc &>no-pad
#0a18 DEO
#800f DEO
@on-console ( -> )
.Console/read DEI DUP ?{
&terminate ( -> )
.queue LDZ #00 EQU ?{ #00 <b64enc> }
#800f DEO
BRK }
<b64enc>
.Console/type DEI #04 EQU ?&terminate
BRK
(
@|core )
@b64enc ( byte -- )
@<b64enc> ( byte -- )
,&buf STR
#0800
&l ( -- )
[ LIT &buf $1 ] OVR #07 SWP SUB SFT #01 AND
[ LIT &inc $1 ] INCk #06 DIVk MUL SUB ,&inc STR
( bit id -- )
( ) [ 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 }
( ) DUP2 LDZ #01 SFT ;MIME ADD2 LDA #18 DEO
( ) STZ }
INC GTHk ?&l
POP2 JMP2r
@MIME [
"ABCDEFGHIJKLMNOP
"QRSTUVWXYZabcdef
"ghijklmnopqrstuv
"QRSTUVWXYZabcdef
"ghijklmnopqrstuv
"wxyz0123456789+/ ]
(
@|stdlib )
@skey ( key buf -- proc )
OVR #21 LTH ?&eval
#00 SWP sput #00 JMP2r
&eval POP2 #01 JMP2r
@scap ( str* -- end* )
&w ( -- )
INC2 & LDAk ?&w
JMP2r
@sput ( chr str* -- )
scap/ ROT #00 SWP2 STA2
JMP2r
@<print-err> ( str* -- )
LDAk #19 DEO
INC2 & LDAk ?<print-err>
POP2 JMP2r
@usage "usage: 20 "b64enc.rom 20 "data 0a $1

View File

@ -1,4 +1,4 @@
#!/bin/sh -e
#!/bin/sh
ID="b64enc"
ASM="uxncli $HOME/roms/drifblim.rom"
@ -7,7 +7,7 @@ LIN="uxncli $HOME/roms/uxnlin.rom"
SRC="${ID}.tal"
DST="${ID}.rom"
CPY="$HOME/roms"
ARG="test.txt"
ARG="Many hands make light work."
if [[ "$*" == *"--lint"* ]]
then
@ -21,12 +21,9 @@ then
cp $DST $CPY
fi
$EMU $DST
echo -n "source: "
cat test.txt
echo ""
echo "source: ${ARG}"
echo "target: TWFueSBoYW5kcyBtYWtlIGxpZ2h0IHdvcmsu"
echo -n "result: "
$EMU $DST $ARG
echo -n "${ARG}" | $EMU $DST
echo ""