mirror of
https://git.sr.ht/~rabbits/uxn
synced 2024-11-05 13:55:06 +00:00
92 lines
1.8 KiB
Tal
92 lines
1.8 KiB
Tal
( File:
|
|
Creates a temporary file called file-output.txt,
|
|
then read it back in console, print length and delete it. )
|
|
|
|
|a0 @File0 &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
|
|
|b0 @File1 &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
|
|
|
|
|0100 ( -> )
|
|
|
|
( write a file with file0 )
|
|
;filepath-txt .File0/name DEO2
|
|
;part1 ,append JSR
|
|
;part2 ,append JSR
|
|
( read a file with file1 )
|
|
;filepath-txt .File1/name DEO2
|
|
,stream JSR
|
|
( delete file with file0 )
|
|
;filepath-txt .File0/delete DEO2
|
|
|
|
BRK
|
|
|
|
@append ( part* -- )
|
|
|
|
DUP2 ;print-str JSR2
|
|
DUP2 ;slen JSR2 STH2k .File0/length DEO2
|
|
.File0/write DEO2
|
|
( print result )
|
|
;saved-txt ;print-str JSR2
|
|
STH2r ;print JSR2 #2018 DEO
|
|
;bytes-txt ;print-str JSR2 #0a18 DEO
|
|
|
|
JMP2r
|
|
|
|
@stream ( -- )
|
|
|
|
#0001 .File1/length DEO2
|
|
LIT2r 0000
|
|
&stream
|
|
;&buf DUP2 .File1/read DEO2 LDA #18 DEO INC2r
|
|
.File1/success DEI2 #0000 NEQ2 ,&stream JCN
|
|
( print result )
|
|
;loaded-txt ;print-str JSR2
|
|
STH2r ;print JSR2 #2018 DEO
|
|
;bytes-txt ;print-str JSR2 #0a18 DEO
|
|
|
|
JMP2r
|
|
&buf $1
|
|
|
|
@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
|
|
|
|
@print-str ( str* -- )
|
|
|
|
&while
|
|
LDAk #18 DEO
|
|
INC2 LDAk ,&while JCN
|
|
POP2
|
|
|
|
JMP2r
|
|
|
|
@saved-txt "Saved 20 $1
|
|
@loaded-txt "Loaded 20 $1
|
|
@bytes-txt "bytes. $1
|
|
@filepath-txt "file-output.txt $1
|
|
|
|
@part1
|
|
476f 6420 6865 6c70 2074 6865 2064 7265
|
|
616d 6572 2077 686f 7365 206d 6164 2076
|
|
6973 696f 6e73 2073 6865 770a 00
|
|
|
|
@part2
|
|
5468 6f73 6520 6465 6164 2065 7965 7320
|
|
7365 7420 696e 2063 7279 7374 616c 2067
|
|
756c 6673 2062 656c 6f77 210a 00
|