Title Physical Disk I/O Module for SWP CoPower_88 (18_May_84) ; ; Morrow Design, Inc. ; San Leandro, Ca. ; Copyright 1984 ; Modified for an MD-3 ; Russell Smith ; .z80 cseg banksw equ 0F6h ;micro decision bankswitch port# ;---------------------------------------------------------------------- ; Public Declarations (16_May_84) ;-------------------------------- ; entry diskdvr,init,restore,finit,fstore ext Hd_DBP ;---------------------------------------------------------------------- ; Local Equates (18_May_84) ;-------------------------- ; ; ROM Addresses ;--------------- ; Read_Sector equ 9 ;Read a Sector offset from start of ROM Write_Sector equ 0Ch ;Write a Sector offset from start of ROM ; Disk driver operation code definitions ;--------------------------------------- ; getsec equ 1 ;read sector putsec equ 2 ;write sector putfmt equ 4 ;format track ; Data structure for disk i/o control block ;------------------------------------------ ; dskop equ 0 ;disk operation code dskdrv equ 1 ;drive# (with side# in bit 7) dsktrk equ 2 ;track# dsksec equ 3 ;sector# dskptr equ 5 ;read/write pointer dskaux equ 7 ;auxilliary parameters (2 bytes) dsksts equ 9 ;operation completion status ; Lengths and Offsets ;-------------------- ; RXOff equ 61 ;Offset to the RamDatX pointer RYOff equ 64 ;Offset to the RamDatX pointer RXLeng equ 31 ;Length of the RamDatX area RYleng equ 71 ;Length of the RamDatY area MToff equ 26 ;Offset to 1st MTab from start of RamDatY Mtab_Length equ 9 ;Length of an Mtab ; Offsets for the RamDatX area ;----------------------------- ; HstDsk equ 0 ;Host Disk (Logical Drive Number) HstTrk equ 1 ;Host Track HstSec equ 2 ;Host Sector (Physical Sector) SecCnt equ 3 ;Sector Count Retry equ 4 ;Retry Count Hstbuf equ 5 ;Host Buffer Address ErFlag equ 7 ;Error Flag PhyTrk equ 8 ;Physical Track Number PhyHd equ 9 ;Physical Head Number IOadd equ 10 ;Execution Address SecSiz equ 12 ;Sector size code Stadd equ 14 ;Status area CmdCnt equ 21 ;Command Length CmdBuf equ 22 ;Command Buffer ; MTAB Offsets ;----------------------------- ; DskDef0 equ 0 DskDef1 equ 1 EotOff equ 5 ; MTAB Masks ;----------------------------- ; Ibmdef0 equ $FRGN ;(dsk0) value to be ored into dskdef0 Ibmdef1 equ $DRVDEN or $512 or $DBLMED ;(dsk1) value to be ored into dskdef1 Eot equ 9 Gpl equ 4 MorDef0 equ 0 ;(dsk0) value to be ored into dskdef0 MorDef1 equ $DRVDEN or $1024 ;(dsk1) value to be ored into dskdef1 ;MTAB's Dskdef0 Mask Bytes $DEF0 equ 11111111b xor ($FRGN or $SECZRO) $FRGN equ 10000000b ;Drive is Foreign (Not Morrow) $SECZRO equ 01000000b ;Sector Numbering Starts with Sector Zero (not 1) ;MTAB's Dskdef1 Mask Bytes $DEF1 equ 11111111b xor ($DRVDEN or $DBLMED or $128 or $256 or $512 or $1024) $DRVDEN equ 01000000b ;Double Density Media $DBLMED equ 00000100b ;Double Sided Media $128 equ 00000000b ;128 Bytes per Sector $256 equ 00001000b ;256 Bytes per Sector $512 equ 00010000b ;512 Bytes per Sector $1024 equ 00011000b ;1024 Bytes per Sector page ;---------------------------------------------------------------------- ; Main Line of the Disk Driver Routine (16_May_84) ;------------------------------------------------- ; diskdvr: ld a,(ix+dskop) cp 1 jp z,read ;jump if disk read operation cp 2 jp z,write ;jump if disk write operation cp 4 jp z,format ;jump if track format operation ld (ix+dsksts),255 ;else set all error bits and return ret page ;---------------------------------------------------------------------- ; Initialize drivers (17_Jul_84) ;------------------------------------------------- ; Init: ld hl,(1) ld bc,RXoff add hl,bc ;point to ramdatx ld e,(hl) inc hl ld d,(hl) inc hl push hl ex de,hl ;HL holds ramdatx pointer ld de,RamX ld bc,RXLeng ldir ;copy ramdatx to local storage pop hl ld e,(hl) inc hl ld d,(hl) ex de,hl ;HL holds ramdaty pointer ld de,RamY ld bc,RYLeng ldir ;copy ramdaty to local storage ld hl,RamY ld de,MToff ;get pointer to first MTAB add hl,de ld b,5 Mtab_Loop: push hl ld a,$def0 ;mask dskdef0 and (hl) or IbmDef0 ;or in IBM bits ld (hl),a inc hl ld a,$def1 ;mask dskdef1 and (hl) or IbmDef1 ;or in IBM bits ld (hl),a ld de,EotOff add hl,de ld (hl),Eot inc hl ld (hl),Gpl pop hl ld de,Mtab_Length add hl,de djnz Mtab_Loop ret Restore: Fstore: Finit: ret ;---------------------------------------------------------------------- ; Read sector (17_Jul_84) ;------------------------ ; Read: call setup ;store parameters for rom call ld hl,Read_Sector call disk ;read sector via RDHST entry point ret ;---------------------------------------------------------------------- ; Write sector (17_Jul_84) ;------------------------- ; Write: call setup ld hl,Write_Sector call disk ;write sector via WRTHST rom entry ret ;---------------------------------------------------------------------- ; Common Disk I/O (17_Jul_84) ;---------------------------- ; disk: ld (spsave),sp ;save caller's SP and IX registers ld sp,dskstk ;switch to local stack push ix ld ix,ramx ld iy,ramy out (banksw),a ;turn on the Morrow rom call pchl ;call physical disk r/w routine in a,(banksw) ;turn rom back off pop ix ld a,(ramx+ErFlag) ld (ix+dsksts),a ;set disk error status on return ld sp,(spsave) ret ;return with registers restored pchl: jp (hl) ;---------------------------------------------------------------------- ; Setup RamDatX for I/O (17_Jul_84) ;---------------------------------- ; Setup: ld a,(ix+dskdrv) and 00000011b ld (Ramx+HstDsk),a ;set HSTDSK in ramdatx xor a ld a,(ix+DskTrk) bit 7,(ix+DskDrv) jr z,SaSkp1 ;jump if selecting side zero scf SaSkp1: rla ;else create 2X odd track number ld (RamX+HstTrk),a ;set HSTTRK in ramdatx ld a,(ix+dsksec) ld (RamX+HstSec),a ;set HSTSEC in ramdatx ld a,1 ld (RamX+SecCnt),a ;set SECCNT=1 ld a,10 ld (RamX+Retry),a ;set RETRY=10 ld a,(ix+dskptr) ld (RamX+HstBuf),a ;set HSTBUF in ramdatx ld a,(ix+dskptr+1) ld (RamX+HstBuf+1),a ld a,0feh ld (RamX+ErFlag),a ;disable error message responses ret ;--------------------------------------------------------------------- ; Format/verify track function (18_Jul_84) ;----------------------------------------- ; FORMAT: LD DE,FMTBUF CALL BUILD ;go construct sector headers in buffer LD A,(IX+DSKTRK) LD (RAMX+PHYTRK),A ;set physical track# XOR A BIT 7,(IX+DSKDRV) JR Z,FORM1 LD A,00000100B FORM1: LD (RAMX+PHYHD),A ;set physical head# LD HL,0015H LD (RAMX+IOADD),HL ;set pointer to WRIO routine in rom LD HL,4D06H LD (RAMX+CMDCNT),HL ;set up CMDCNT and FDCCMD bytes in ramx LD HL,RAMX+HSTDSK OR (HL) ;merge side and drive select bits LD (RAMX+CMDBUF+1),A ;put after FDCCMD byte in command string LD L,(IX+DSKPTR) ;load HL with pointer to format info LD H,(IX+DSKPTR+1) PUSH HL ;save old contents of DSKPTR LD DE,RAMX+CMDBUF+2 LD BC,4 LDIR ;store data for N,SC,GPL and DAT params LD HL,FMTBUF LD (IX+DSKPTR),L LD (IX+DSKPTR+1),H CALL SETUP LD HL,0FH CALL DISK OR A JR NZ,FORMX POP HL PUSH HL INC HL LD B,(HL) ;get sectors-per-track from params INC HL INC HL INC HL ;point to start of sector numbers LD (IX+DSKAUX),0 FORM6: LD A,(HL) INC HL LD (IX+DSKSEC),A LD (RAMX+HSTSEC),A ;store sector# to read for verify PUSH HL PUSH BC LD HL,0009H CALL DISK ;now read sector back for verify POP BC POP HL OR A JR Z,FORM7 ;jump if good ready/rnf/crc/busy bits INC (IX+DSKAUX) FORM7: DJNZ FORM6 XOR A FORMX: LD (IX+DSKSTS),A POP HL LD (IX+DSKPTR),L ;restore caller's disk buffer pointer LD (IX+DSKPTR+1),H RET ; ; ; ; ; ... subroutine to build list of sector headers for 765 ... ; ; parameters are: ix ....... disk i/o control block pointer ; de ....... pointer to track data buffer ; BUILD: LD L,(IX+DSKPTR) LD H,(IX+DSKPTR+1) INC HL INC HL INC HL INC HL PUSH HL POP IY ;point IY to format descriptor stuff LD BC,0 ;set up BC for loop count and index BUILD3: LD A,(IX+DSKTRK) LD (DE),A ;store track# INC DE LD A,(IX+DSKDRV) RLCA AND 00000001B LD (DE),A ;store side# INC DE PUSH IY POP HL ADD HL,BC ;index into sector sequence list LD A,(HL) LD (DE),A ;store sector# from list INC DE LD A,(IY-4) LD (DE),A ;store sector length code INC DE INC BC LD A,C CP (IY-3) ;compare C to sectors-per-track JR C,BUILD3 XOR A RET ;---------------------------------------------------------------------- ; Local Data Area (18_Jul_84) ;---------------------------- ; SpSave: defw 0 RamX: defs 31 ;local copy of RAMDATX data structure RamY: defs 71 ;local copy of RAMDATY defs 64 DskStk equ $ FmtBuf: defs 1024 ;temp buffer for format/verify end