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) +! -1 (FREADCH-LEFT) +!
28 (FREADCH-OFS) @ LIMIT + C@
32 $FORTH_END_WORD FREADCH
37 (FREADCH-OFS) @ LIMIT + C!
38 -1 (FREADCH-OFS) +! -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 CHLF - 0BRANCH freadln_qt1
58 DUP CHCR = 0BRANCH freadln_3
60 DROP FREADCH DUP CHLF - 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)
116 $FORTH_CONST (TLOAD-NAME-BUF) tload_name_buf
117 ;; 9 bytes: name and ext
118 tload_name_buf: defb 0,0,0,0,0,0,0,0,0
120 $FORTH_WORD (TRD-PARSE-NAME)
122 ;; ( addr len defext -- newaddr len )
123 (TLOAD-NAME-BUF) LIT 9 BL FILL
125 LIT 8 MIN (TLOAD-NAME-BUF) SWAP CMOVE
126 R> -DUP 0BRANCH trd_parse_name_done
127 (TLOAD-NAME-BUF) LIT 8 + C!
129 (TLOAD-NAME-BUF) LIT 9
131 $FORTH_END_WORD (TRD-PARSE-NAME)
133 ;; interpret text file
137 LIT 70 (TRD-PARSE-NAME)
138 (.") "loading: " 2DUP XTYPE CR ;;"
141 $FORTH_END_WORD TLOAD
144 ;; (") ~TEST F~ TLOAD ;S ;;"
148 (") ~DECO~ TLOAD ;S ;;"
152 (") ~ZTEST~ TLOAD ;S ;;"