From 39a85b64a03ed7b8b08e15fb3bf7760c2a6e81ba Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Wed, 24 May 2023 09:46:15 -0700 Subject: [PATCH] base64 encoder --- cli/base64/b64enc.tal | 70 +++++++++++++++++++++++++++++++++++++++++++ cli/base64/build.sh | 25 ++++++++++++++++ cli/base64/test.txt | 1 + 3 files changed, 96 insertions(+) create mode 100644 cli/base64/b64enc.tal create mode 100755 cli/base64/build.sh create mode 100644 cli/base64/test.txt diff --git a/cli/base64/b64enc.tal b/cli/base64/b64enc.tal new file mode 100644 index 0000000..c870904 --- /dev/null +++ b/cli/base64/b64enc.tal @@ -0,0 +1,70 @@ +( 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 + +|0000 + + @src $40 + @queue $1 + +|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 + #0a18 DEO + #010f DEO + +BRK + &buf $1 + +@append ( c -- ) + + ,&chr STR + #0800 + &l + [ LIT &chr $1 ] OVR #07 SWP SUB SFT #01 AND + [ LIT &inc $1 ] INCk #06 DIVk MUL SUB ,&inc STR + ( bit id -- ) + SWP .queue LDZ ORA #10 SFT .queue STZ + ( output ) + #05 NEQ ?&no-cap + #00 .queue LDZ #01 SFT ;MIME ADD2 LDA #18 DEO + #00 .queue STZ + &no-cap + INC GTHk ?&l + POP2 + +JMP2r + +@MIME [ + "ABCDEFGHIJKLMNOP + "QRSTUVWXYZabcdef + "ghijklmnopqrstuv + "wxyz0123456789+/ ] + +@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 +@pstr ( str* -- ) &w LDAk #18 DEO INC2 LDAk ?&w POP2 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 + diff --git a/cli/base64/build.sh b/cli/base64/build.sh new file mode 100755 index 0000000..aae77d7 --- /dev/null +++ b/cli/base64/build.sh @@ -0,0 +1,25 @@ +#!/bin/sh -e + +ID="b64enc" +ASM="uxncli $HOME/roms/drifblim.rom" +EMU="uxncli" +LIN="uxncli $HOME/roms/uxnlin.rom" +SRC="${ID}.tal" +DST="${ID}.rom" +CPY="$HOME/roms" +ARG="test.txt" + +if [[ "$*" == *"--lint"* ]] +then + $LIN $SRC +fi + +$ASM $SRC $DST + +if [[ "$*" == *"--save"* ]] +then + cp $DST $CPY +fi + +$EMU $DST $ARG + diff --git a/cli/base64/test.txt b/cli/base64/test.txt new file mode 100644 index 0000000..a12a526 --- /dev/null +++ b/cli/base64/test.txt @@ -0,0 +1 @@ +Many hands make light work. \ No newline at end of file