1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; low-level +3DOS words
3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5 ; Pages 1, 3, 4, 6 are considered as an array
6 ; of 128 sector buffers (numbered 0...127),
8 ; The cache and RAMdisk occupy two separate
9 ; (contiguous) areas of this array.
12 IF !defined(USE_P3DOS_ERROR_MESSAGES)
13 USE_P3DOS_ERROR_MESSAGES equ 0
16 IF USE_P3DOS_ERROR_MESSAGES
17 p3dos_error_msg_table:
19 defc "Drive not ready"
21 defc "Disk is write protected"
29 defc "Missing address mark"
31 defc "Unrecognised disk format"
33 defc "Unknown disk error"
37 defc "Unsuitable media"
38 ;;Non-recoverable errors:
44 defc "Drive not found"
48 defc "File already exists"
58 defc "File number not open"
62 defc "Cannot rename between drives"
70 defc "Disk not bootable"
75 defc "Too many open files"
80 ;; show warning message
81 $FORTH_WORD (+3DOS-ERR-TEXT)
83 ;; ( num -- addr count )
84 $IF USE_P3DOS_ERROR_MESSAGES
86 LIT p3dos_error_msg_table
90 COUNT ;; ( tbl+1 msgid | num )
91 ?DUP 0BRANCH .loop_done
92 ;; ( tbl+1 msgid | num )
93 R@ = 0BRANCH .loop_skip
94 COUNT ;; ( addr count | num )
97 COUNT + ;; skip string
105 0 <# #S [CHAR] # HOLD [CHAR] R DUP HOLD HOLD [CHAR] E HOLD #>
108 $FORTH_END_WORD (+3DOS-ERR-TEXT)
111 $FORTH_VAR (+3DOS-R/O) 0
112 ;; registers for +3DOS calls
113 ;; loaded before calling a function, and the result will be stored here
114 $FORTH_VAR (+3DOS-BC) 0
115 fvar_p3dos_bc equ $-2
118 $FORTH_CONST (+3DOS-B) fvar_p3dos_bc+1
119 $FORTH_CONST (+3DOS-C) fvar_p3dos_bc
121 $FORTH_VAR (+3DOS-DE) 0
122 fvar_p3dos_de equ $-2
125 $FORTH_CONST (+3DOS-D) fvar_p3dos_de+1
126 $FORTH_CONST (+3DOS-E) fvar_p3dos_de
128 $FORTH_VAR (+3DOS-HL) 0
129 fvar_p3dos_hl equ $-2
132 $FORTH_CONST (+3DOS-H) fvar_p3dos_hl+1
133 $FORTH_CONST (+3DOS-L) fvar_p3dos_hl
135 $FORTH_VAR (+3DOS-AF) 0
136 fvar_p3dos_af equ $-2
139 $FORTH_CONST (+3DOS-A) fvar_p3dos_af+1
140 $FORTH_CONST (+3DOS-F) fvar_p3dos_af
143 $FORTH_CODE_WORD (+3DOS-CF?)
149 $FORTH_END_CODE_WORD (+3DOS-CF?)
151 $FORTH_CODE_WORD (+3DOS-ZF?)
160 $FORTH_END_CODE_WORD (+3DOS-ZF?)
163 ;; check error, show error message, return error flag
164 $FORTH_WORD (+3DOS-ERR?)
167 (+3DOS-CF?) TBRANCH .noerror
168 (.") ~\x02+3DOS ERROR: ~ ;;"
170 (+3DOS-ERR-TEXT) XTYPE CR
174 $FORTH_END_WORD (+3DOS-ERR?)
178 ;; WARNING! SP should not be at TSTACK!
179 $FORTH_CODE_WORD (+3DOS-CMD)
185 push ix ; some +3DOS functions destroys it
194 ld (p3dos_call_addr),hl
196 ; prepare stack and RAM/ROM
197 ld a,(BANKM) ; RAM/ROM switching system variable
198 res 5,a ; reset locking (just in case)
199 ld (p3dos_saved_bankm),a ; save it to be restored later
200 or 7 ; want RAM page 7
201 res 4,a ; and DOS ROM
202 ld bc,#7FFD ; port used for horiz ROM switch and RAM paging
205 ld (BANKM),a ; keep system variables up to date
206 out (c),a ; RAM page 7 to top and DOS ROM
208 ; set +2A/+3 port #1FFD
210 ld (p3dos_saved_bank678),a
211 set 2,a ; switch on +3DOS ROM
216 ld (p3dos_saved_sp),sp
222 ; switch stack to TSTACK
236 ; load all registers (except AF)
237 ld hl,(fvar_p3dos_hl)
238 ld de,(fvar_p3dos_de)
239 ld bc,(fvar_p3dos_bc)
242 p3dos_call_addr equ $-2
247 ld sp,fvar_p3dos_af+2
249 ; save all registers (except AF)
250 ld (fvar_p3dos_hl),hl
251 ld (fvar_p3dos_de),de
252 ld (fvar_p3dos_bc),bc
256 ;and #F8 ; reset bits for page 0
257 ;set 4,a ; switch to ROM 3 (48 BASIC)
258 ;res 5,a ; reset locking (just in case)
259 ld a,(p3dos_saved_bankm)
262 out (c),a ; switch back to RAM page 0 and 48 BASIC
264 ; restore +2A/+3 port #1FFD
265 ld a,(p3dos_saved_bank678)
271 ld sp,(p3dos_saved_sp)
288 p3dos_saved_bankm: defb 0
289 p3dos_saved_bank678: defb 0
290 p3dos_saved_sp: defw 0
291 $FORTH_END_CODE_WORD (+3DOS-CMD)
294 fword_p3dos_cat_mask: defm "*.*",0xff
296 fword_p3dos_cat_buffer equ #5D40
297 fword_p3dos_cat_buffer_len equ 8
302 ;; maximum is actually 64x13+13 = 845
304 LIT fword_p3dos_cat_buffer LIT fword_p3dos_cat_buffer_len*13 ERASE
306 LIT fword_p3dos_cat_buffer_len (+3DOS-B) C! ;; the number of entries in the buffer
307 1 (+3DOS-C) C! ;; include system files in the catalog
308 LIT fword_p3dos_cat_buffer (+3DOS-DE) ! ;; buffer address
309 LIT fword_p3dos_cat_mask (+3DOS-HL) !
310 LIT 10 (+3DOS-CMD) (+3DOS-ERR?) TBRANCH .exit
311 (+3DOS-B) C@ DUP 1 > 0BRANCH .exit
312 LIT fword_p3dos_cat_buffer+13
316 DUP LIT 8 XTYPE [CHAR] . XEMIT DUP LIT 8 + 3 XTYPE
317 SPACE DUP LIT 11 + @ 0 U.R (.") ~kb~ ;;"
324 (+3DOS-B) C@ LIT fword_p3dos_cat_buffer_len = 0BRANCH .exit_nodrop
325 LIT fword_p3dos_cat_buffer+13*(fword_p3dos_cat_buffer_len-1) LIT fword_p3dos_cat_buffer LIT 13 CMOVE
331 $FORTH_END_WORD +3-CAT
334 $FORTH_WORD (+3DOS-NO-RAMDISK)
336 LIT 0x0008 (+3DOS-DE) ! ;; cache
337 LIT 0x0000 (+3DOS-HL) ! ;; ramdist
341 $FORTH_END_WORD (+3DOS-NO-RAMDISK)