uxn-utils/cli/format-js/format-js.tal

72 lines
1.3 KiB
Tal
Raw Normal View History

2023-08-02 11:35:28 -04:00
( usage: uxncli format-js.rom file.bin )
2023-08-02 11:29:11 -04:00
|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
2024-02-14 23:23:44 -05:00
|0100
2023-08-02 11:29:11 -04:00
2024-02-14 23:23:44 -05:00
@on-reset ( -> )
2023-08-02 11:29:11 -04:00
;on-console .Console/vector DEO2
2024-02-14 23:23:44 -05:00
BRK
2023-08-02 11:29:11 -04:00
@on-console ( -> )
2023-08-02 11:35:28 -04:00
;src STH2
2024-02-14 23:23:44 -05:00
( | read input )
.Console/read DEI DUP #20 LTH OVR #7f GTH ORA ?&end
STH2kr slen #003f GTH2 ?&end
STH2kr scap/ STA
POP2r BRK
&end ( c -- )
POP STH2r .File/name DEO2
#0001 .File/length DEO2
;header-txt <pstr>
LIT2r 0000
&stream ( -- )
2023-08-02 11:29:11 -04:00
#00 ,&buf STR
2024-02-14 23:23:44 -05:00
;&buf DUP2 .File/read DEO2
LIT "0 #18 DEO
LIT "x #18 DEO
LDA <phex>/byte
LIT ", #18 DEO
#2018 DEO
2023-08-02 11:29:11 -04:00
INC2r
2024-02-14 23:23:44 -05:00
( linebreak ) STH2kr #0007 AND2 ORA ?{
#0a18 DEO
#0918 DEO }
.File/success DEI2 ORA ?&stream
POP2r ;footer-txt <pstr>
2023-08-02 11:29:11 -04:00
#0a18 DEO
2023-08-02 11:35:28 -04:00
#010f DEO
2024-02-14 23:23:44 -05:00
BRK &buf $1
2023-08-02 11:35:28 -04:00
@slen ( str* -- len* )
2024-02-14 23:23:44 -05:00
DUP2 scap/ SWP2 SUB2 JMP2r
2023-08-02 11:35:28 -04:00
@scap ( str* -- end* )
2024-02-14 23:23:44 -05:00
INC2 & LDAk ?scap
JMP2r
2023-08-02 11:35:28 -04:00
2024-02-14 23:23:44 -05:00
@<phex> ( short* -- )
SWP <phex>/byte
&byte ( byte -- )
DUP #04 SFT <phex>/char
&char ( char -- )
#0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO
JMP2r
2023-08-02 11:29:11 -04:00
2024-02-14 23:23:44 -05:00
@<pstr> ( str* -- )
LDAk DUP ?{ POP2 JMP2r }
#18 DEO
INC2 !<pstr>
2023-08-02 11:29:11 -04:00
2024-02-14 23:23:44 -05:00
@header-txt
"const 20 "assembler 20 "= 20 "new 20 "Uint8Array([ 0a 09 00
2023-08-02 11:29:11 -04:00
2024-02-14 23:23:44 -05:00
@footer-txt
"0x00]) 00
2023-08-02 11:29:11 -04:00