diff --git a/format-c/build.sh b/format-c/build.sh new file mode 100755 index 0000000..7db5711 --- /dev/null +++ b/format-c/build.sh @@ -0,0 +1,35 @@ +#!/bin/sh -e + +ASM="uxncli $HOME/roms/drifblim.rom" +EMU="uxncli" +LIN="uxncli $HOME/roms/uxnlin.rom" +APP="$HOME/bin/butler push" + +SRC="format-c.tal" +DST="format-c.rom" + +CPY="$HOME/roms" +ARG="test.txt" + +echo ">> Cleaning" +rm -rf bin +mkdir bin + +if [[ "$*" == *"--lint"* ]] +then + echo ">> Linting $SRC" + $LIN $SRC +fi + +echo ">> Assembling $SRC" +$ASM $SRC $DST + +if [[ "$*" == *"--save"* ]] +then + echo ">> Saving $DST" + cp $DST $CPY +fi + +echo ">> Running $DST" +$EMU $DST $ARG + diff --git a/format-c/format-c.tal b/format-c/format-c.tal new file mode 100644 index 0000000..5d1ad12 --- /dev/null +++ b/format-c/format-c.tal @@ -0,0 +1,68 @@ +( usage: uxncli format-js.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 + +|0100 ( -> ) + + ;on-console .Console/vector DEO2 + +BRK + +@on-console ( -> ) + + [ LIT2r =src ] + ( read input ) + .Console/read DEI + DUP #20 LTH OVR #7f GTH ORA ?&end + STH2kr slen #003f GTH2 ?&end + STH2kr scap STA POP2r BRK + &end + POP + STH2r print-program + #010f DEO + +BRK + +@print-program ( src* -- ) + + .File/name DEO2 + #0001 .File/length DEO2 + ;dict/header pstr + LIT2r 0000 + &stream + #00 ,&buf STR + ;&buf .File/read DEO2 + .File/success DEI2 #0000 EQU2 ?&end + [ LIT2 "0 18 ] DEO [ LIT2 "x 18 ] DEO + [ LIT &buf $1 ] phex/b + [ LIT2 ", 18 ] DEO #2018 DEO + INC2r + ( linebreak ) + STH2kr #000f AND2 ORA ?&no-lb + #0a18 DEO #0918 DEO + &no-lb + .File/success DEI2 ORA ?&stream + &end + POP2r + #0a18 DEO + ;dict/footer + +!pstr + +( +@|stdlib ) + +@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* -- ) &while LDAk #18 DEO INC2 LDAk ?&while POP2 JMP2r + +@dict + &header "unsigned 20 "char 20 "rom[] 20 "= 20 "{ 0a 09 $1 + &footer "}; 0a 00 + diff --git a/format-c/test.txt b/format-c/test.txt new file mode 100644 index 0000000..651f559 --- /dev/null +++ b/format-c/test.txt @@ -0,0 +1 @@ +wigjewigjewigjewigjewigjewigjcncmnbegejgiwejgieg