0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-01 03:52:39 +00:00
uxn/projects/utils/proquints.tal
2022-01-17 12:06:50 -08:00

113 lines
2 KiB
Tal

(
converts a binary file to a proquints, identifiers that are readable, and pronounceable.
usage: uxncli proquints.rom file.bin )
%+ { ADD } %- { SUB } %* { MUL } %/ { DIV }
%< { LTH } %> { GTH } %= { EQU } %! { NEQ }
%++ { ADD2 } %-- { SUB2 } %** { MUL2 } %// { DIV2 }
%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 }
%HALT { #010f DEO }
%EMIT { #18 DEO }
%PRINT { ;print-str JSR2 #0a EMIT }
%DEBUG { ;print-hex/byte JSR2 #0a EMIT }
%DEBUG2 { ;print-hex JSR2 #0a EMIT }
( devices )
|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
( variables )
|0000
@length $2
@src $30
|0100 ( -> )
;on-console .Console/vector DEO2
BRK
@on-console ( -> )
( starting )
[ LIT &trap $1 ] ,&started JCN
;src #0020 ;mclr JSR2
#01 ,&trap STR
&started
( append )
.Console/read DEI #20 < ,&validate JCN
;src ;slen JSR2 #0030 == ,&validate JCN
;src .Console/read DEI ;sput JSR2 BRK
&validate
( load )
;src .File/name DEO2
#fff0 ;data -- .File/length DEO2
;data .File/read DEO2
( save length )
.File/success DEI2 .length STZ2
,parse JSR
#00 ,&trap STR
BRK
@parse ( -- )
.length LDZ2 ;data ++ ;data
&loop
LDA2k ,proquint JSR
INC2 INC2 GTH2k ,&loop JCN
POP2 POP2
HALT
JMP2r
@proquint ( short* -- )
( c1 ) DUP2 #0c ,&emit-con JSR
( v1 ) DUP2 #0a ,&emit-vow JSR
( c2 ) DUP2 #06 ,&emit-con JSR
( v2 ) DUP2 #03 ,&emit-vow JSR
( c3 ) #00 ,&emit-con JSR
#20 EMIT
JMP2r
&emit-con SFT2 #000f AND2 ;&con ADD2 LDA EMIT JMP2r
&con "bdfghjklmnprstvz
&emit-vow SFT2 #0003 AND2 ;&vow ADD2 LDA EMIT JMP2r
&vow "aiou
@slen ( str* -- len* )
DUP2 ,scap JSR SWP2 --
JMP2r
@scap ( str* -- end* )
LDAk #00 ! JMP JMP2r
&while
INC2 LDAk ,&while JCN
JMP2r
@sput ( str* char -- )
ROT ROT ,scap JSR STA
JMP2r
@mclr ( addr* len* -- )
OVR2 ++ SWP2
&loop
STH2k #00 STH2r STA
INC2 GTH2k ,&loop JCN
POP2 POP2
JMP2r
@data