;::::::::::::::::::::::::::::::::::::::::::::****************************** ; Floppy Disk Routines ***** Hardware Dependent ***** ; - Retro-Brew Hardware with HBIOS - ****************************** ; ; 1.4 - 27 Mar 14 - Initial N8VEM test release WW+LN ; 1.3 - 26 Aug 01 - Cleaned up for GPL Release. HFB ; 1.2c- 12 May 97 - Cleaned up source, modified STSIZE Code (again). HFB ; 1.2b- 22 Apr 97 - Changed 5.25" Hi/Lo Speed controls. HFB ; 1.0a- 23 Mar 97 - (test) fixes. HFB ; 1.0 - 13 Aug 96 - Initial Release for P112 from YASMIO. HFB ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; Floppy Units are accessed on Retro-Brew systems using HBIOS function ; calls. These functions include read, write, status and media type. ; For 3.5" drive there are two media types. For 5.25" drive two media ; types are supported, while for 8" drives one type is supported. ; Only high density is supported on 3.5" drives either single or double ; sided. For 5.25" drive either double or high density is supported on ; double sided disks. Only double density double sided 8" disks are ; supported. Many BPBIOS floppy routines are stubbed such as DMA support ; and motor control since all these details are handled behind the scene by ; HBIOS. Currently HBIOS handles the head given the track and sector so ; the interface treats all floppies as single sided. IF BANKED COMMON /BANK2/ ELSE CSEG ENDIF ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; STMODE (Function 0) - Set the FDC mode for Read/Write operations. ; ; Enter : A = Single-Density Flag (0 = Double Dens, 0FFH = Single Dens) ; Return: Nothing ; Uses : AF All other Registers Preserved/Not Affected ; ; Assumes STSIZE and STSECT called first ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: STMODE: CALL PANIC ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; STSIZE (Function 1) - Set Drive Size (3.5", 5.25", 8"), Drive Speed ; (High/Low) Capability, and a Boolean flag for whether Motor Control is ; needed by the Drive. ; ; Enter : A = Hi Speed Flag ( 0 = Normal, 0FFH = High Speed Capable) ; D = Motor Flag (0 = No Motor Control, 0FFH = Motor needed) ; E = Drive Size (0 = Hard, 001 = 8", 010 = 5.25", 011 = 3.5") ; Return: Nothing ; Uses : AF All other Registers Preserved/Not Affected ; ; Assumes STHDRV Called Previously. Call before calling STMODE. ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: STSIZE: CALL PANIC ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; STHDRV (Function 2) - Set Head and Drive for Disk Operations. ; ; Enter : A = Unit # in D0-D1, Head in D2 ; Return: Nothing ; Uses : AF All other Registers Preserved/Not Affected ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: STHDRV: CALL PANIC ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; STSECT (Function 3) - Set Sector Number, Sector Size and Last Sector # ; ; Enter : A = Physical Sector Number ; D = Sector Size (0=128, 1=256, 2=512, 3=1024) ; E = Last Physical Sector # on Side ; Return: Nothing ; Uses : AF All other Registers Preserved/Not Affected ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: STSECT: CALL PANIC ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; SPEC (Function 4) - Do a Specify Command, setting Step Rate and Head ; Load/Unload Time. Values are rounded up if not even increments. ; ; Enter : A = Step Rate (in mS; Bit 7 = 1 for 8" drive ; D = Head Unload Time (in mS) ; E = Head Load Time (in mS) ; Return: Nothing ; Uses : AF All other Registers Preserved/Not Affected ; ; Assumes STSIZE called previously to set DRVSPD variable. ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: SPEC: CALL PANIC ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; RECAL (Function 5) - Recalibrate Drive (moves heads to track 0). ; ; Enter : Nothing ; Return: A = 0 if Ok, NZ if Error. Flags reflect A ; Uses : AF All other Registers Preserved/Not Affected ; ; NOTE: BC Must be preserved by this routine. ; Assumes STHDRV, SPEC, STSIZE and STMODE called first. ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: RECAL: CALL PANIC ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; SEEK (Function 6) - Set the Track for disk operations and seek to it. ; ; Enter : A = Desired Track Number ; D = Verify flag (0=No, FF=Yes) ; E = Double-step Flag (E <> 0 for Double-step) ; Return: A = 0, Zero Flag Set (Z) if Ok, A <> 0 Zero Clear (NZ) if Error ; Uses : AF All other Registers Preserved/Not Affected ; ; Assumes STHDRV, SPEC, STSIZE and STMODE are called first. ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: SEEK: CALL PANIC XOR A RET ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; SREAD (Function 7) - Read a Sector from the Floppy Disk. The Mode, ; Head/Drive, Track, and Sector must have already been set. ; ; Enter : HL --> Read Buffer ; Return: A = 0, Zero Set (Z) if Ok, A <> 0, Zero Clear (NZ) if Error. ; Uses : AF,HL. All other Registers Preserved/Not Affected ; ; Assumes STMODE, STHDRV, STSECT, SPEC and SEEK Called First. ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: SREAD: CALL PANIC XOR A RET ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; SWRITE (Function 8) - Write a Sector to the Floppy Disk. The Mode, ; Head/Drive, Track, and Sector must have already been set. ; ; Enter : HL --> Write Buffer ; Return: A = 0, Zero Flag Set (Z) if Ok, A <> 0 Zero Clear (NZ) if Errors ; Uses : AF,HL. All other registers Preserved/Not Affected. ; Assumes STMODE, STHDRV, STSECT, SPEC and SEEK Called First. ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: SWRITE: CALL PANIC XOR A RET ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; READID (Function 9) - Read the first Valid Address Mark on a track. ; ; Enter : Nothing ; Return: A = 0 if Ok, NZ if Error. Flags reflect A ; Uses : AF All other Registers Preserved/Not Affected ; ; Assumes STHDRV, SPEC, STSIZE and STMODE called first. ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: READID: CALL PANIC XOR A RET ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; RETDST (Function 10) - Return the status of a drive. ; This routine reports a "765" Controller type instead of actual number. ; ; Enter : Nothing ; Return: A = Status byte ; BC = 765 (FDC Controller Type) ; HL = Address of Status Byte ; Uses : AF,BC,HL All other Registers Preserved/Not Affected ; ; Assumes STHDRV called first ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: RETDST: CALL PANIC ;LD HL,ST0 ; Point to Status Byte (Reg 3 contents) ;LD A,(HL) ; fetch it ;LD BC,765 ; load Controller ID RET ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; FMTTRK (Function 11) - Format a complete track on one side of a Floppy ; Disk. The Mode, Head/Drive, Track, and Sector must have been set. ; ; NOTE: The contents of the Format Data Block varies between controllers, ; so RETDST should be called to determine the controller type before ; setting up data structures. ; ; Enter : D = Formatting Sctrs/Track value ; E = Formatting Gap 3 Byte Count ; HL = Pointer to Controller-dependent Format Data block ; Return: A = 0, Zero Flag Set (Z) if Ok, A <> 0 Zero Clear (NZ) if Errors ; Uses : All Primary Registers ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: FMTTRK: CALL PANIC ;XOR A RET ;============================================================================= ; FDCMD - Send Command to FDC ; Enter: B = # of Bytes in Command, C = Command Byte ; HL -> Buffer for Read/Write Data (If Needed) ; Exit : AF = Status byte ; Uses : AF,BC FDCMD: CALL PANIC ;LD A,(ST0) ; Else get first byte of Status ;AND 0C0H ; check for Normal termination RET ; ..return w/Error Flags set ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; MOTOR CONTROL. This routine performs final selection of the drive control ; latch and determines if the Motors are already spinning. If they are off ; and Motor control is needed, then the Motors are activated and the spinup ; delay time in tenths-of-seconds is performed before returning. ; ; Enter : Command byte in A ; Return: Head Delay bit set in Command in A if needed ; Uses : None. All Registers Preserved/Not Affected MOTOR: CALL PANIC XOR A RET ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; Hardware-Dependent Host Read/Write Routine linked to from FLOPPY module. ; This routine Reads/Writes data from HSTBUF trying up to MXRTRY times ; before giving up. If an error occurs after the next-to-last try, the ; heads are homed to force a re-seek. ; ; Enter: (RDOP Set for desired operation) ; Exit : A = 0, Zero Set if Ok, A <> 0, Zero Reset if Errors ; Uses : AF,HL ; ; RDOP is set to 1 for Read, 0 for Write, TTRK set with desired Track ; number, STHDRV, STSECT, STMODE, SPEC all called previously. ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: FHDRW: CALL PANIC ;XOR A RET ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CSEG ;*** Remainder of Code MUST be in Main Memory *** ;======================================================================== ; Reset the Floppy Disk Controller. Called from CBOOT in case of Hard ; Disk Boot which leaves the controller in a "hung" state, and locally ; if the Controller times out (often due to changing diskettes). FDRst: CALL PANIC RET ;======================================================================== ; Motor Off routine. Called from SELFLP2 which forces ; Motors/Timer to be Off state so spinup delay is forced on next selection. MOTOFF: CALL PANIC ChgSpd: RET ;======================== RAM Storage Area ============================== IF BANKED COMMON /B2RAM/ ; If banked, Local stack in Bank ELSE DSEG ; ..otherwise in Data Segment ENDIF ; DSEG ; Place in Common memory ; NOTE: Variables listed as (** Global **) are accessed by other modules and ; MUST exist as defined. HDR: DEFS 1 ; Head (B2), Drive (B0,1) (** Global **) ; FDC Operation Result Storage Area ;ST0: DEFS 1 ; Status Byte 0 ;ST1: DEFS 1 ; Status Byte 1 (can also be PCN) ;ST2: DEFS 1 ; Status Byte 2 RC: DEFS 1 ; Track # (** Global **) ;RH: DEFS 1 ; Head # (0/1) RR: DEFS 1 ; Sector # (** Global **) RN: DEFS 1 ; Sector Size (** Global **) ;-->>> Do NOT re-order the following two bytes !! <<<-- ;MTM: DEFS 1 ; Floppy Time down-counter ;MOTIM: DEFS 1 ; Motor On Time Counter ; DISK Subsystem Variable Storage ;FDMOT: DEFS 1 ; Motor on required flag RDOP: DEFS 1 ; Read/write flag ;RETRYS: DEFS 1 ; Number of times to try Opns ;RWRTRY: DEFS 1 ; Number of read/write tries ;DRVSPD: DEFS 1 ; Drive Speed ;DRVSIZ: DEFS 1 ; Drive Size STEP2: DEFS 1 ; <> 0 for Double Step (** Global **) ;MODE: DEFS 1 ; Bit 6 = 1 if MFM, 0 = FM ;ACTIVE: DEFS 1 ; Current bits written to Dev Contr Reg (DCR) ;DLYCNT: DEFS 1 ; Delay value reading Main Status Reg ;FSPT: DEFS 1 ; Format Sectors/Track value TSBSCF: DEFS 1 ; 0=Hd always 0 (TSBSC) (** Global **) TTRK: DEFS 1 ; Storage for Track (** Global **) ;TRKARY: DEFS 4 ; Track storage locations for four drives ;=========================== End of FDC-WW ==============================