1 ;; Native x86 GNU/Linux Forth System, Direct Threaded Code
3 ;; Copyright (C) 2020 Ketmar Dark // Invisible Vector
5 ;; This program is free software: you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation, version 3 of the License ONLY.
9 ;; This program is distributed in the hope that it will be useful,
10 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ;; GNU General Public License for more details.
14 ;; You should have received a copy of the GNU General Public License
15 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
18 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19 urword_value
"(DEFAULT-#TIB)",par_default_tib_size
,1024
22 ;; this will be patched by the startup code
23 urword_value
"(DEFAULT-TIB)",par_default_tib
,0
27 urword_var
"TIB", tib
, 0 ;fdata_tib
28 urword_var
"#TIB", tibsize
, 0 ;fdata_tib_end-fdata_tib
29 urword_var
">IN", inptr
, 0
30 urword_var
"TIB-LINE#",tiblineno
,0
32 ;; "TIB-GETCH" will set this if last read char is not EOL
33 ;; parsing words will set this too, as if they're using "TIB-GETCH"
34 urword_var
"(TIB-LAST-READ-CHAR)",par_last_read_char
,0
36 urword_value
"(LAST-TLOAD-PATH-ADDR)",par_last_tload_path
,0
38 ;; size of TIB save buffer
39 urword_const
"#TIB-SAVE-BUFFER",tib_save_buffer_size
,4+4+4+4+4
41 ;; current file we are interpreting
42 urword_const
"(#TIB-CURR-FNAME)",par_tib_curr_fname_size
,4096
45 urword_value
"(TIB-CURR-FNAME)",par_tib_curr_fname
,0
49 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
50 urword_code
"TIBSTATE>R",par_tibstate_rpush
51 rpushmem
[fvar_tib_data
]
52 rpushmem
[fvar_tibsize_data
]
53 rpushmem
[fvar_inptr_data
]
54 rpushmem
[fvar_tiblineno_data
]
55 rpushmem
[fvar_par_last_read_char_data
]
59 urword_code
"R>TIBSTATE",par_tibstate_rpop
60 rpopmem
[fvar_par_last_read_char_data
]
61 rpopmem
[fvar_tiblineno_data
]
62 rpopmem
[fvar_inptr_data
]
63 rpopmem
[fvar_tibsize_data
]
64 rpopmem
[fvar_tib_data
]
68 urword_code
"RDROP-TIBSTATE",par_tibstate_rdrop
74 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
75 urword_forth
"TIB-DEFAULT?",tib_is_default
76 UF tib @ par_default_tib equal
79 urword_forth
"TIB-RESET",tib_reset
81 UF par_default_tib tib
!
82 UF par_default_tib_size tibsize
!
86 urto par_last_tload_path
91 urword_forth
"TIB-PEEKCH",tib_peekch
93 UF inptr @ tibsize @ uless
95 UF tib @ inptr @
+ cpeek
105 urword_forth
"TIB-GETCH",tib_getch
114 UF
1 tiblineno addpoke
117 UF dup par_last_read_char
!
123 urword_code
"TIB-PEEKCH",tib_peekch
125 ;; will never be negative
128 ld
eax,[fvar_inptr_data
]
129 cp
eax,dword [fvar_tibsize_data
]
131 add eax,[fvar_tib_data
]
141 urword_code
"TIB-GETCH",tib_getch
143 ;; will never be negative
146 ld
eax,[fvar_inptr_data
]
147 cp
eax,dword [fvar_tibsize_data
]
149 add eax,[fvar_tib_data
]
155 ; update last read char
156 ld
[fvar_par_last_read_char_data
],TOS
158 inc dword [fvar_inptr_data
]
159 ; update current line
162 cp
dword [fvar_tiblineno_data
],0
164 inc dword [fvar_tiblineno_data
]
172 urword_forth
"TIB-CALC-CURRLINE",tib_calc_currline
174 ;; returns line number for the current TIB position
178 UF inptr @ tib @
+ tib @
187 urword_code
"TIB-CALC-CURRLINE",tib_calc_currline
189 ;; returns line number for the current TIB position
191 ld
edi,[fvar_tib_data
]
192 ld
ecx,[fvar_inptr_data
]
194 xor edx,edx ; line counter
209 urword_forth
"ACCEPT",accept
210 ;; ( addr maxlen -- readlen // -1 )
211 UF dup
0 lessequ errid_input_too_long qerror
213 ;; ( addr maxlen currcount )
217 UF dup
0xffffffff equal
222 ;; ( addr maxlen currcount char )
228 ;; ( addr maxlen currcount | char )
229 UF rot rpop over cpoke
1inc nrot
1inc
232 UF rdrop
;; drop char, we have no room for it
241 ;; ( addr maxlen currcount char )
244 UF par_reset_emitcol
;; because OS did cr (i hope)
246 ;; check for overflow
250 UF
2drop drop
0xffffffff
257 urword_forth
"REFILL",refill
259 ;; either refills TIB and sets flag to true, or does nothing and sets flag to false
263 UF tib @ tibsize @
1dec accept
267 UF endcr pardottype
"ERROR: ACCEPT buffer overflow" cr
269 ;UF tib @ over type 124 emit dup . cr