1 TITLE 'sd disk handler'
3 ; CP/M-80 Version 3 -- Modular BIOS
8 ; Disk drive dispatching tables for linked BIOS
10 public sd0,sd1,sd2,sd3
12 ; 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 ; print message @<HL> up to 00, saves <BC> & <DE>
26 extrn ?pdec ; print binary number in <A> from 0 to 99.
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
57 ; Extended Disk Parameter Headers (XPDHs)
63 db 0,0 ; relative drive zero
64 sd0: dph 0,dpbsimhd512
70 db 1,0 ; relative drive one
71 sd1: dph 0,dpbsimhd512
77 db 2,0 ; relative drive zero
78 sd2: dph 0,dpbsimhd512
84 db 3,0 ; relative drive one
85 sd3: dph 0,dpbsimhd512
88 cseg ; DPB must be resident
91 dpb 512,8,2048,4096,1024,6
96 ; Disk I/O routines for standardized BIOS interface
98 ; Initialization entry point.
99 ; called for first time initialization.
107 ret ; all initialization done by drive 0
112 ; This entry is called when a logical drive is about to
113 ; be logged into for the purpose of density determination.
114 ; It may adjust the parameters contained in the disk
115 ; parameter header pointed at by <DE>
121 ld (hl),0 ;login function
131 call bnk2phy ;phys. linear address
140 ld b,send_msg_login_len
144 ld b,recv_msg_len ; max receive message len
153 ; disk READ and WRITE entry points.
154 ; these entries are called with the following arguments:
156 ; absolute drive number in @adrv (8 bits) +0
157 ; relative drive number in @rdrv (8 bits) +1
158 ; disk track address in @trk (16 bits) +2
159 ; disk sector address in @sect(16 bits) +4
160 ; multi sector count in @cnt (8 bits) +6
161 ; disk transfer address in @dma (16 bits) +7
162 ; disk transfer bank in @dbnk (8 bits) +9
163 ; pointer to XDPH in <DE>
165 ; they transfer the appropriate data, perform retries
166 ; if necessary, then return an error code in <A>
169 ld de,read$msg ; point at " Read "
173 ld de,write$msg ; point at " Write "
176 ld hl,residual ; remainng sectors from last multi io?
186 ld b,1 ; assume 1 sector to transfer
191 ld b,a ; number of sectors to transfer
192 dec a ; save remaining
194 xor a ; reset multi sector count
197 ; compute pysical transfer address
199 ; and send it to AVR.
207 ld (operation$name),hl ; save message for errors
208 ld hl,@adrv ;address of arguments
214 ld e,(hl) ;dma address
220 call bnk2phy ;phys. linear address
236 ld b,recv_msg_len ; max receive message len
240 ret z ; check status and return to BDOS if no error
242 ; suppress error message if BDOS is returning errors to application...
248 ; Had permanent error, print message like:
249 ; BIOS Err on d: T-nn, S-mm, <operation> <type>, Retry ?
251 call ?pderr ; print message header
253 ld hl,(operation$name)
254 call ?pmsg ; last function (read or write)
260 ld hl,drvmsg0 ; point at first driver error message
267 jr z,prompt ; no fatfs error
272 ld hl,fr$msg0 ; point at first FatFs message
279 call ?pmsg ; print "<BEL>, Retry (Y/N) ? "
280 call u$conin$echo ; get operator response
282 jr z,retry ; Yes, then retry 10 more times
289 ld a,1 ; return hard error to BDOS
292 cancel: ; here to abort job
293 jp ?wboot ; leap directly to warmstart vector
297 ; Print message to error code in A
303 push hl ; put pointer to first message on stack
309 ld e,a ; save message number
319 ; not found (should not happen)
328 ; get console input, echo it, and shift to upper case
334 jr z,u$c1 ; see if any char already struck
336 jr u$conin$echo ; yes, eat it and try again
346 sub 'a'-'A' ; make upper case
355 ds 1 ; subcommand (login/read/write)
358 ; -read/write- -login-
359 ds 2 ; @trk xdph address
360 ds 2 ; @sect (3 byte)
363 send_msg_rw_len equ $ - send_msg
364 send_msg_login_len equ 7
373 ds 4 ; room for additional parameter
374 recv_msg_len equ $ - recv_msg
377 ; error message components
386 drvmsg0: db 'Unknown Error, ',0
387 drvmsg1: db 'Invalid Parameter(s), ',0
388 drvmsg2: db 'Invalid Drive, ',0
389 drvmsg3: db 'Bus Timeout, ',0
390 drvmsg_size equ $ - drvmsg0
393 fsmsg: db 'FatFs: ',0
395 ; table of pointers to error message strings
397 fr$msg0: db 'Unknown Error,',0
398 fr$msg1: db 'DISK_ERR,',0
399 fr$msg2: db 'INT_ERR,',0
400 fr$msg3: db 'NOT_READY,',0
401 fr$msg4: db 'NO_FILE,',0
402 fr$msg5: db 'NO_PATH,',0
403 fr$msg6: db 'INVALID_NAME,',0
404 fr$msg7: db 'DENIED,',0
405 fr$msg8: db 'EXIST,',0
406 fr$msg9: db 'INVALID_OBJECT,',0
407 fr$msg10: db 'WRITE_PROTECTED,',0
408 fr$msg11: db 'INVALID_DRIVE,',0
409 fr$msg12: db 'NOT_ENABLED,',0
410 fr$msg13: db 'NO_FILE_SYSTEM,',0
411 fr$msg14: db 'MKFS_ABORTED,',0
412 fr$msg15: db 'TIMEOUT,',0
413 fr$msg16: db 'LOCKED,',0
414 fr$msg17: db 'NOT_ENOUGH_CORE,',0
415 fr$msg18: db 'TOO_MANY_OPEN_FILES,',0
416 fr$msg19: db 'FR_INVALID_PARAMETER,',0
417 fr$msg20: db 'short read/write,',0
418 fr$msg$size equ $ - fr$msg0
422 db ' Retry (Y/N) ? ',0