From 830dfe3e1b2b8ea7ee144ae3c787fed82698b913 Mon Sep 17 00:00:00 2001 From: neauoire Date: Wed, 2 Aug 2023 08:35:28 -0700 Subject: [PATCH] (format-js) Working copy from uxn5 --- cli/format-js/format-js.tal | 94 +++++++++++++++++++++---------------- 1 file changed, 54 insertions(+), 40 deletions(-) diff --git a/cli/format-js/format-js.tal b/cli/format-js/format-js.tal index be68d84..d32794f 100644 --- a/cli/format-js/format-js.tal +++ b/cli/format-js/format-js.tal @@ -1,4 +1,4 @@ -( uxncli format-c.rom file.bin ) +( 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 @@ -7,7 +7,7 @@ @src $40 -|0100 @on-reset ( -> ) +|0100 ( -> ) ;on-console .Console/vector DEO2 @@ -15,54 +15,68 @@ BRK @on-console ( -> ) - [ LIT2r =src ] + ;src STH2 ( read input ) .Console/read DEI - DUP #20 LTH OVR #7f GTH ORA ?&>end - STH2kr slen #003f GTH2 ?&>end - STH2kr scap STA POP2r BRK - &>end + 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 + STH2r .File/name DEO2 + #0001 .File/length DEO2 + ;header-txt ;print-str JSR2 + LIT2r 0000 + &stream + #00 ,&buf STR + ;&buf + DUP2 .File/read DEO2 + LIT "0 #18 DEO LIT "x #18 DEO + LDA ,print/byte JSR LIT ", #18 DEO #2018 DEO + INC2r + ( linebreak ) + STH2kr #0007 AND2 ORA ,&no-lb JCN + #0a18 DEO #0918 DEO + &no-lb + .File/success DEI2 ORA ,&stream JCN + POP2r + ;footer-txt ;print-str JSR2 + #0a18 DEO #010f DEO BRK + &buf $1 -@ ( src* -- ) +@slen ( str* -- len* ) - .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 + DUP2 ,scap JSR SWP2 SUB2 -!pstr +JMP2r -( -@|stdlib ) +@scap ( str* -- end* ) -@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 + LDAk #00 NEQ JMP JMP2r + &while + INC2 LDAk ,&while JCN -@dict - &header "unsigned 20 "char 20 "rom[] 20 "= 20 "{ 0a 09 $1 - &footer "}; 0a 00 +JMP2r +@print ( 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 + +@print-str ( str* -- ) + + &while + LDAk #18 DEO + INC2 LDAk ,&while JCN + POP2 + +JMP2r + +@header-txt "const 20 "assembler 20 "= 20 "new 20 "Uint8Array([ 0a 09 00 +@footer-txt "0x00]) 00