1 TITLE 'sd disk handler'
3 ; CP/M-80 Version 3 -- Modular BIOS
6 ; Disk drive dispatching tables for linked BIOS
11 ; Variables containing parameters passed by BDOS
18 ; System Control Block variables
20 extrn @ermde ; BDOS error mode
22 ; Utility routines in standard BIOS
24 extrn ?wboot ; warm boot vector
25 extrn ?pmsg,pr.inln ; print message @<HL>, print inline message
26 extrn pr.crlf ; print <cr><lf>
27 extrn ?pderr ; print BIOS disk error header
28 extrn ?conin,?cono ; con in and out
29 extrn ?const ; get console status
37 ; Port Address Equates
42 ; CP/M 3 Disk definition macros
46 ; Z180 macro library instruction definitions (ignored by slr180)
50 ; common control characters
59 ; Extended Disk Parameter Headers (XPDHs)
65 db 0,0 ; relative drive zero
66 sd0: dph 0,dpbsimhd512
72 db 1,0 ; relative drive one
73 sd1: dph 0,dpbsimhd512
79 db 2,0 ; relative drive zero
80 sd2: dph 0,dpbsimhd512
86 db 3,0 ; relative drive one
87 sd3: dph 0,dpbsimhd512
94 db 4,0 ; relative drive zero
95 sd4: dph 0,dpbsimhd512
101 db 5,0 ; relative drive one
102 sd5: dph 0,dpbsimhd512
108 db 6,0 ; relative drive zero
109 sd6: dph 0,dpbsimhd512
115 db 7,0 ; relative drive one
116 sd7: dph 0,dpbsimhd512
119 cseg ; DPB must be resident
122 dpb 512,8,2048,4096,1024,6
125 dseg ; rest is banked
127 ; Disk I/O routines for standardized BIOS interface
129 ; Initialization entry point.
130 ; called for first time initialization.
142 ret ; all initialization done by drive 0
145 ; This entry is called when a logical drive is about to
146 ; be logged into for the purpose of density determination.
147 ; It may adjust the parameters contained in the disk
148 ; parameter header pointed at by <DE>
150 ; absolute drive number in @adrv (8 bits) +0
151 ; relative drive number in @rdrv (8 bits) +1
157 ld (hl),0 ;login function
167 call bnk2phy ;phys. linear address
176 ld b,send_msg_login_len
180 ld b,recv_msg_len ; max receive message len
192 ; disk READ and WRITE entry points.
193 ; these entries are called with the following arguments:
195 ; absolute drive number in @adrv (8 bits) +0
196 ; relative drive number in @rdrv (8 bits) +1
197 ; disk track address in @trk (16 bits) +2
198 ; disk sector address in @sect(16 bits) +4
199 ; multi sector count in @cnt (8 bits) +6
200 ; disk transfer address in @dma (16 bits) +7
201 ; disk transfer bank in @dbnk (8 bits) +9
202 ; pointer to XDPH in <DE>
204 ; they transfer the appropriate data, perform retries
205 ; if necessary, then return an error code in <A>
208 ld de,read$msg ; point at " Read "
212 ld de,write$msg ; point at " Write "
216 ld hl,residual ; remainng sectors from last multi io?
226 ld b,1 ; assume 1 sector to transfer
231 ld b,a ; number of sectors to transfer
232 dec a ; save remaining
234 xor a ; reset multi sector count
237 ; compute pysical transfer address
239 ; and send it to AVR.
247 ld (operation$name),hl ; save message for errors
248 ld hl,@adrv ;address of arguments
251 ld (de),a ;number of sectors
254 ld e,(hl) ;dma address
260 call bnk2phy ;phys. linear address
276 ld b,recv_msg_len ; max receive message len
280 ret z ; check status and return to BDOS if no error
282 ; suppress error message if BDOS is returning errors to application...
288 ; Had permanent error, print message like:
289 ; BIOS Err on d: T-nn, S-mm, <operation> <type>, Retry ?
291 call ?pderr ; print message header
293 ld hl,(operation$name)
294 call ?pmsg ; last function (read or write)
300 ld hl,drvmsg0 ; point at first driver error message
307 jr z,prompt ; no fatfs error
312 ld hl,fr$msg0 ; point at first FatFs message
319 db ' Retry (Y/N) ? ',0
321 call u$conin$echo ; get operator response
323 jr z,retry ; Yes, then retry 10 more times
330 ld a,1 ; return hard error to BDOS
333 cancel: ; here to abort job
334 jp ?wboot ; leap directly to warmstart vector
338 ; Print message to error code in A
344 push hl ; put pointer to first message on stack
350 ld e,a ; save message number
360 ; not found (should not happen)
369 ; get console input, echo it, and shift to upper case
375 jr z,u$c1 ; see if any char already struck
377 jr u$conin$echo ; yes, eat it and try again
387 sub 'a'-'A' ; make upper case
396 ds 1 ; subcommand (login/read/write)
399 ; -read/write- -login-
400 ds 2 ; @trk xdph address
401 ds 2 ; @sect (3 byte)
404 send_msg_rw_len equ $ - send_msg
405 send_msg_login_len equ 7
414 ds 4 ; room for additional parameter
415 recv_msg_len equ $ - recv_msg
418 ; error message components
427 drvmsg0: db 'Unknown Error, ',0
428 drvmsg1: db 'Invalid Parameter(s), ',0
429 drvmsg2: db 'Invalid Drive, ',0
430 drvmsg3: db 'Bus Timeout, ',0
431 drvmsg_size equ $ - drvmsg0
435 ; table of pointers to error message strings
437 fr$msg0: db 'Unknown Error,',0
438 fr$msg1: db 'DISK_ERR,',0
439 fr$msg2: db 'INT_ERR,',0
440 fr$msg3: db 'NOT_READY,',0
441 fr$msg4: db 'NO_FILE,',0
442 fr$msg5: db 'NO_PATH,',0
443 fr$msg6: db 'INVALID_NAME,',0
444 fr$msg7: db 'DENIED,',0
445 fr$msg8: db 'EXIST,',0
446 fr$msg9: db 'INVALID_OBJECT,',0
447 fr$msg10: db 'WRITE_PROTECTED,',0
448 fr$msg11: db 'INVALID_DRIVE,',0
449 fr$msg12: db 'NOT_ENABLED,',0
450 fr$msg13: db 'NO_FILE_SYSTEM,',0
451 fr$msg14: db 'MKFS_ABORTED,',0
452 fr$msg15: db 'TIMEOUT,',0
453 fr$msg16: db 'LOCKED,',0
454 fr$msg17: db 'NOT_ENOUGH_CORE,',0
455 fr$msg18: db 'TOO_MANY_OPEN_FILES,',0
456 fr$msg19: db 'FR_INVALID_PARAMETER,',0
457 fr$msg20: db 'short read/write,',0
458 fr$msg$size equ $ - fr$msg0