1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8 $FORTH_VAR (FREADCH-BLOCK) 0
9 ;; offset in the current block
10 $FORTH_VAR (FREADCH-OFS) 0
12 $FORTH_VAR (FREADCH-LEFT) 0
14 ;; read char from file
15 ;; all variables must be set!
16 ;; block must be loaded!
20 (FREADCH-LEFT) @ 0BRANCH freadch_eof
22 (FREADCH-OFS) @ LIT 256 < 0= 0BRANCH freadch_0
24 (FREADCH-OFS) 0! (FREADCH-BLOCK) @ 1+ DUP (FREADCH-BLOCK) !
27 1 (FREADCH-OFS) +! LIT -1 (FREADCH-LEFT) +!
28 (FREADCH-OFS) @ LIMIT + C@
32 $FORTH_END_WORD FREADCH
37 (FREADCH-OFS) @ LIMIT + C!
38 LIT -1 (FREADCH-OFS) +! LIT -1 (FREADCH-LEFT) +! ;S
39 $FORTH_END_WORD FUNREADCH
42 ;; read text file line by line
43 ;; all variables must be set!
46 ;; ( -- addr len TRUE | FALSE )
49 FREADCH DUP 0< 0BRANCH freadln_0
51 DROP -DUP 0= 0BRANCH freadln_qt
52 ;; nothing except EOF was read
53 DROP 0 BRANCH freadln_q
56 DUP LIT 10 - 0BRANCH freadln_qt1
58 DUP LIT 13 = 0BRANCH freadln_3
60 DROP FREADCH DUP LIT 10 - 0BRANCH freadln_qt1
63 FUNREADCH BRANCH freadln_qt
66 ;; just add char (if there is enough room for it %-)
67 OVER LIT 256 < 0BRANCH freadln_unget
68 >R 2DUP + R> SWAP C! ;; store char
74 ;; write terminating 0x00 & success flag
78 $FORTH_END_WORD FREADLN
80 ;; "close" current file -- clear vars
84 (FREADCH-OFS) 0! (FREADCH-LEFT) 0! ;S
85 $FORTH_END_WORD FCLOSE
87 ;; prepare variables for reading file
90 ;; ( addr len -- success_flag)
91 (TR-FFIND) DUP 0< 0BRANCH fopen0
95 (TR-FILEBUF) 1- (FREADCH-BLOCK) ! LIT #5CE8 @ (FREADCH-LEFT) !
96 LIT 256 (FREADCH-OFS) ! 1
101 ;; interpret text file
105 FOPEN 0BRANCH tload_err
107 FREADLN 0BRANCH tload_q
108 TLOAD-Y 1! DROP TIB ! IN 0! INTERPRET
111 (.") ~TLOAD: can't open input file %-(\n~ ;;"
114 $FORTH_END_WORD TLOAD
117 ;; (") ~TEST F~ TLOAD ;S ;;"
121 (") ~DECO F~ TLOAD ;S ;;"