(binstr.tal) Added a binary to string file converter in utils

This commit is contained in:
neauoire 2022-01-16 14:30:46 -08:00
parent 35953312ea
commit c1d42a97ce
1 changed files with 131 additions and 0 deletions

131
projects/utils/binstr.tal Normal file
View File

@ -0,0 +1,131 @@
(
converts a binary file to a series of shorts as strings
usage: uxncli binstr.rom file.bin )
%+ { ADD } %- { SUB } %* { MUL } %/ { DIV }
%< { LTH } %> { GTH } %= { EQU } %! { NEQ }
%++ { ADD2 } %-- { SUB2 } %** { MUL2 } %// { DIV2 }
%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 }
%HALT { #010f DEO }
( 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
,parse JSR
#00 ,&trap STR
BRK
@parse ( -- )
( load )
;src .File/name DEO2
#fff0 ;data -- .File/length DEO2
;data .File/read DEO2
( save length )
.File/success DEI2 .length STZ2
( export path )
;tal-ext ;src ;scat JSR2
( save )
;src .File/name DEO2
#0001 .File/length DEO2
( stream )
.length LDZ2 ;data ++ ;data
&loop
LDAk #04 SFT ,&parse JSR ,&write JSR
LDAk #0f AND ,&parse JSR ,&write JSR
( formatting )
DUP2 ;data --
DUP2 #000f AND2 #000f !! ,&no-linebreak JCN
#0a ,&write JSR ,&end JMP &no-linebreak
DUP2 #0001 AND2 #0001 !! ,&no-space JCN
#20 ,&write JSR &no-space
&end
POP2
INC2 GTH2k ,&loop JCN
POP2 POP2
HALT
JMP2r
&write ;&b STA ;&b .File/write DEO2 JMP2r
&parse DUP #09 GTH ,&above JCN #30 + JMP2r &above #57 + JMP2r
&b $1
@tal-ext ".tal $1
@scat ( src* dst* -- )
DUP2 ,slen JSR ++ ,scpy JSR
JMP2r
@slen ( str* -- len* )
DUP2 ,scap JSR SWP2 --
JMP2r
@scap ( str* -- end* )
LDAk #00 ! JMP JMP2r
&while
INC2 LDAk ,&while JCN
JMP2r
@scpy ( src* dst* -- )
STH2
&while
LDAk STH2kr STA INC2r
INC2 LDAk ,&while JCN
POP2
#00 STH2r STA
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