|00 @System [ &vec $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1 ] |10 @Console [ &vec $2 &read $1 &pad $4 &type $1 &write $1 &error $1 ] |a0 @File [ &vec $2 &ok $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] |0100 ;on-console .Console/vec DEO2 BRK ( emit an unsigned short as a decimal ) @decimal ( n* -> ) LIT2r ff00 ( n* [ff^ 0^] ) &r ( ... x* ) #000a DIV2k STH2k ( x* 10* x/10* [ff^ i^ x/10*] ) MUL2 SUB2 NIP #30 ADD ( digit^ x/10* [ff^ i^] ) STH2r INCr ORAk ?&r ( digit^ x/10* [ff^ i+1^] ) POP2 ( d0* ... dn* [ff^ i+1^] ) &w ( d0^ ... dn^ [ff^ j^] ) .Console/write DEO ( d0^ ... dn-1^ [ff^ j^] ) OVRr ADDr STHkr ?&w ( d^ ... dn-1^ [ff^ j-1^] ) POP2r JMP2r ( ) @print ( s* -> ) LDAk ?{ POP2 JMP2r } LDAk .Console/write DEO INC2 !print @on-console ( -> BRK ) .Console/type DEI #02 NEQ ?run .Console/read DEI append BRK @append ( c^ -> ) ;ptr LDA2 STA ;ptr LDA2k INC2 SWP2 STA2 JMP2r @not-readable ( -> bool^ ) #0100 .File/length DEO2 ;buf .File/read DEO2 .File/ok DEI2 #0000 EQU2 JMP2r @writable ( -> bool^ ) #0015 .File/length DEO2 ;dat .File/write DEO2 .File/ok DEI2 #0000 NEQ2 JMP2r @run ( -> BRK ) #00 append ;path .File/name DEO2 ;msg1 print ;path print LIT "' .Console/write DEO #0a .Console/write DEO not-readable ?{ ;msg2 print !exit } ;msg3 print writable ?{ ;msg6 print !exit } ;msg4 print .File/ok DEI2 decimal ;msg5 print ( >> ) @exit ( -> BRK ) #80 .System/halt DEO BRK @msg1 "Read 20 "path: 20 "' 00 @msg2 "File 20 "was 20 "readable 0a 00 @msg3 "File 20 "was 20 "not 20 "readable 0a 00 @msg4 "File 20 "was 20 "writable, 20 "wrote 20 00 @msg5 20 "bytes. 0a 00 @msg6 "File 20 "was 20 "not 20 "writable 0a 00 @dat "This 20 "is 20 "sample 20 "data. 0a 00 @ptr =path @buf $100 @path $1000