(hexdump.tal) Rewrote

This commit is contained in:
neauoire 2022-03-15 11:42:17 -07:00
parent 24474b6b32
commit 084a0f5ab4
2 changed files with 66 additions and 131 deletions

View File

@ -1,131 +0,0 @@
(
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

View File

@ -0,0 +1,66 @@
( usage: uxncli hexdump.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 ( -> )
;src STH2
( read input )
.Console/read DEI
DUP #20 LTH OVR #7f GTH ORA ,&end JCN
STH2kr ,slen JSR #003f GTH2 ,&end JCN
STH2kr ,scap JSR STA POP2r BRK
&end
POP
STH2r .File/name DEO2
#0002 .File/length DEO2
LIT2r 0000
&stream
#0000 ,&buf STR2
;&buf
DUP2 .File/read DEO2
LDA2 ,print JSR #2018 DEO
INC2r
( linebreak )
STH2kr #0007 AND2 ORA ,&no-lb JCN
#0a18 DEO
&no-lb
.File/success DEI2 ORA ,&stream JCN
POP2r
#010f DEO
BRK
&buf $2
@slen ( str* -- len* )
DUP2 ,scap JSR SWP2 SUB2
JMP2r
@scap ( str* -- end* )
LDAk #00 NEQ JMP JMP2r
&while
INC2 LDAk ,&while JCN
JMP2r
@print ( short* -- )
&short ( short* -- ) SWP ,&byte JSR
&byte ( byte -- ) DUP #04 SFT ,&char JSR
&char ( char -- ) #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO
JMP2r