uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

file.tal (2011B)


      1 ( File:
      2 	Creates a temporary file called file-output.txt, 
      3 	then read it back in console, print length and delete it. )
      4 
      5 |a0 @File0 &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
      6 |b0 @File1 &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
      7 
      8 |0100 ( -> )
      9 
     10 	( write a file with file0 )
     11 	;filepath-txt .File0/name DEO2
     12 	;part1 ,append JSR
     13 	;part2 ,append JSR
     14 	( close file before changing device )
     15 	.File0/name DEI2k ROT DEO2
     16 	( read a file with file1 )
     17 	;filepath-txt .File1/name DEO2
     18 	,stream JSR
     19 	( delete file with file0 )
     20 	;filepath-txt .File0/delete DEO2
     21 
     22 BRK
     23 
     24 @append ( part* -- )
     25 
     26 	DUP2 ;print-str JSR2
     27 	DUP2 ;slen JSR2 STH2k .File0/length DEO2
     28 	.File0/write DEO2
     29 	( print result )
     30 	;saved-txt ;print-str JSR2 
     31 	STH2r ;print JSR2 #2018 DEO
     32 	;bytes-txt ;print-str JSR2 #0a18 DEO
     33 
     34 JMP2r
     35 
     36 @stream ( -- )
     37 
     38 	#0001 .File1/length DEO2
     39 	LIT2r 0000
     40 	&stream
     41 		;&buf DUP2 .File1/read DEO2 LDA #18 DEO INC2r
     42 		.File1/success DEI2 #0000 NEQ2 ,&stream JCN
     43 	( print result )
     44 	;loaded-txt ;print-str JSR2 
     45 	STH2r ;print JSR2 #2018 DEO
     46 	;bytes-txt ;print-str JSR2 #0a18 DEO
     47 
     48 JMP2r
     49 	&buf $1
     50 
     51 @slen ( str* -- len* )
     52 
     53 	DUP2 ,scap JSR SWP2 SUB2
     54 
     55 JMP2r
     56 
     57 @scap ( str* -- end* )
     58 
     59 	LDAk #00 NEQ JMP JMP2r
     60 	&while INC2 LDAk ,&while JCN
     61 
     62 JMP2r
     63 
     64 @print ( short* -- )
     65 
     66 	&short ( short* -- ) SWP ,&byte JSR
     67 	&byte ( byte -- ) DUP #04 SFT ,&char JSR
     68 	&char ( char -- ) #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO
     69 
     70 JMP2r
     71 
     72 @print-str ( str* -- )
     73 
     74 	&while
     75 		LDAk #18 DEO
     76 		INC2 LDAk ,&while JCN
     77 	POP2
     78 
     79 JMP2r
     80 
     81 @saved-txt "Saved 20 $1
     82 @loaded-txt "Loaded 20 $1
     83 @bytes-txt "bytes. $1
     84 @filepath-txt "file-output.txt $1
     85 
     86 @part1
     87 	596f 7572 2073 6163 7265 6420 706c 616e
     88 	7473 2c20 6966 2068 6572 6520 6265 6c6f
     89 	772c 0a4f 6e6c 7920 616d 6f6e 6720 7468
     90 	6520 706c 616e 7473 2077 696c 6c20 6772
     91 	6f77 2e0a 00
     92 
     93 @part2
     94 	536f 6369 6574 7920 6973 2061 6c6c 2062
     95 	7574 2072 7564 652c 0a54 6f20 7468 6973
     96 	2064 656c 6963 696f 7573 2073 6f6c 6974
     97 	7564 652e 0a