--- hatari/src/includes/fdc.h 2019/04/01 07:15:29 1.1.1.9 +++ hatari/src/includes/fdc.h 2019/04/09 08:59:25 1.1.1.16 @@ -1,131 +1,114 @@ /* Hatari - fdc.h - This file is distributed under the GNU Public License, version 2 or at - your option any later version. Read the file gpl.txt for details. + This file is distributed under the GNU General Public License, version 2 + or at your option any later version. Read the file gpl.txt for details. */ #ifndef HATARI_FDC_H #define HATARI_FDC_H -/*-----------------------------------------------------------------------*/ -/* FDC Emulation commands */ -enum -{ - FDCEMU_CMD_NULL = 0, - /* Type I */ - FDCEMU_CMD_RESTORE, - FDCEMU_CMD_SEEK, - FDCEMU_CMD_STEP, - FDCEMU_CMD_STEPIN, - FDCEMU_CMD_STEPOUT, - /* Type II */ - FDCEMU_CMD_READSECTORS, - FDCEMU_CMD_READMULTIPLESECTORS, - FDCEMU_CMD_WRITESECTORS, - FDCEMU_CMD_WRITEMULTIPLESECTORS, - /* Type III */ - FDCEMU_CMD_READADDRESS, -}; - -/* FDC Emulation commands */ -#define FDCEMU_RUN_NULL 0 - -/* FDC Running Restore commands */ -enum -{ - FDCEMU_RUN_RESTORE_SEEKTOTRACKZERO, - FDCEMU_RUN_RESTORE_COMPLETE -}; - -/* FDC Running Seek commands */ -enum -{ - FDCEMU_RUN_SEEK_TOTRACK, - FDCEMU_RUN_SEEK_COMPLETE -}; - -/* FDC Running Step commands */ -enum -{ - FDCEMU_RUN_STEP_ONCE, - FDCEMU_RUN_STEP_COMPLETE -}; - -/* FDC Running Step In commands */ -enum -{ - FDCEMU_RUN_STEPIN_ONCE, - FDCEMU_RUN_STEPIN_COMPLETE -}; - -/* FDC Running Step Out commands */ -enum -{ - FDCEMU_RUN_STEPOUT_ONCE, - FDCEMU_RUN_STEPOUT_COMPLETE -}; - -/* FDC Running Read Sector/s commands */ -enum -{ - FDCEMU_RUN_READSECTORS_READDATA, - FDCEMU_RUN_READSECTORS_COMPLETE -}; - -/* FDC Running write Sector/s commands */ -enum -{ - FDCEMU_RUN_WRITESECTORS_WRITEDATA, - FDCEMU_RUN_WRITESECTORS_COMPLETE -}; - -/* FDC Running Read Address commands */ -enum -{ - FDCEMU_RUN_READADDRESS, - FDCEMU_RUN_READADDRESS_COMPLETE -}; - - -/* Commands are taking the equivalent of FDC_DELAY_CYCLES cpu cycles to execute */ -/* to try to simulate the speed of a real ST floppy drive */ -#define FDC_DELAY_CYCLES 92160 -//#define FDC_DELAY_CYCLES 1536 // 'Just Bugging Demo' by ACF requires a very fast delay (bug in the loader) - - -extern Sint16 FDCSectorCountRegister; -extern Uint16 DiskControllerWord_ff8604wr; -extern Uint16 DMAModeControl_ff8606wr; - - -extern void FDC_Reset(void); -extern void FDC_MemorySnapShot_Capture(bool bSave); -extern void FDC_ResetDMAStatus(void); -extern void FDC_SetDMAStatus(bool bError); -extern void FDC_DmaStatus_ReadWord(void); -extern int FDC_FindFloppyDrive(void); -extern void FDC_AcknowledgeInterrupt(void); -extern void FDC_GpipRead(void); -extern void FDC_InterruptHandler_Update(void); -extern void FDC_UpdateRestoreCmd(void); -extern void FDC_UpdateSeekCmd(void); -extern void FDC_UpdateStepCmd(void); -extern void FDC_UpdateStepInCmd(void); -extern void FDC_UpdateStepOutCmd(void); -extern void FDC_UpdateReadSectorsCmd(void); -extern void FDC_UpdateWriteSectorsCmd(void); -extern void FDC_UpdateReadAddressCmd(void); -extern Uint32 FDC_ReadDMAAddress(void); -extern void FDC_WriteDMAAddress(Uint32 Address); -extern bool FDC_ReadSectorFromFloppy(void); -extern bool FDC_WriteSectorFromFloppy(void); -extern void FDC_DMADataFromFloppy(void); -extern void FDC_DiskController_WriteWord(void); -extern void FDC_DiskControllerStatus_ReadWord(void); -extern void FDC_DmaModeControl_WriteWord(void); -extern void FDC_FloppyMode_WriteByte(void); -extern void FDC_FloppyMode_ReadByte(void); +/* Values for the Size byte in the Address Field of a sector */ +#define FDC_SECTOR_SIZE_MASK 0x03 /* Only bits 0-1 of the Sector size in the ID field are used by the WD1772 */ + +#define FDC_SECTOR_SIZE_128 0 /* Sector size used in the ID fields */ +#define FDC_SECTOR_SIZE_256 1 +#define FDC_SECTOR_SIZE_512 2 +#define FDC_SECTOR_SIZE_1024 3 + + +/* These are some standard GAP values to format a track with 9 or 10 sectors */ +/* When handling ST/MSA disk images, those values are required to get accurate */ +/* timings when emulating disk's spin and index's position. */ +/* Those values are also use to build standard sector in STX disk images when */ +/* track contains only the sector data and no sector info. */ +#define FDC_TRACK_LAYOUT_STANDARD_GAP1 60 /* Track Pre GAP : 0x4e */ +#define FDC_TRACK_LAYOUT_STANDARD_GAP2 12 /* Sector ID Pre GAP : 0x00 */ +#define FDC_TRACK_LAYOUT_STANDARD_GAP3a 22 /* Sector ID Post GAP : 0x4e */ +#define FDC_TRACK_LAYOUT_STANDARD_GAP3b 12 /* Sector DATA Pre GAP : 0x00 */ +#define FDC_TRACK_LAYOUT_STANDARD_GAP4 40 /* Sector DATA Pre GAP : 0x4e */ +#define FDC_TRACK_LAYOUT_STANDARD_GAP5 0 /* Track Post GAP : 0x4e (to fill the rest of the track, value is variable) */ + /* GAP5 is 664 bytes for 9 sectors or 50 bytes for 10 sectors */ + +/* Size of a raw standard 512 byte sector in a track, including ID field and all GAPs : 614 bytes */ +/* (this must be the same as the data returned in FDC_UpdateReadTrackCmd() ) */ +#define FDC_TRACK_LAYOUT_STANDARD_RAW_SECTOR_512 ( FDC_TRACK_LAYOUT_STANDARD_GAP2 \ + + 3 + 1 + 6 + FDC_TRACK_LAYOUT_STANDARD_GAP3a + FDC_TRACK_LAYOUT_STANDARD_GAP3b \ + + 3 + 1 + 512 + 2 + FDC_TRACK_LAYOUT_STANDARD_GAP4 ) + + +#define FDC_IRQ_SOURCE_COMPLETE (1<<0) /* IRQ set after completing a command */ +#define FDC_IRQ_SOURCE_INDEX (1<<1) /* IRQ set when COND_IP is set and index is reached */ +#define FDC_IRQ_SOURCE_FORCED (1<<2) /* IRQ was forced by a previous Dx command with COND_IMMEDIATE */ +#define FDC_IRQ_SOURCE_HDC (1<<3) /* IRQ set by HDC */ +#define FDC_IRQ_SOURCE_OTHER (1<<4) /* IRQ set by other parts (IPF) */ + + +/* Option bits in the command register */ +#define FDC_COMMAND_BIT_VERIFY (1<<2) /* 0=no verify after type I, 1=verify after type I */ +#define FDC_COMMAND_BIT_HEAD_LOAD (1<<2) /* for type II/III 0=no extra delay, 1=add 30 ms delay to set the head */ +#define FDC_COMMAND_BIT_SPIN_UP (1<<3) /* 0=enable motor's spin up, 1=disable motor's spin up */ +#define FDC_COMMAND_BIT_UPDATE_TRACK (1<<4) /* 0=don't update TR after type I, 1=update TR after type I */ +#define FDC_COMMAND_BIT_MULTIPLE_SECTOR (1<<4) /* 0=read/write only 1 sector, 1=read/write many sectors */ + + +#define FDC_INTERRUPT_COND_IP (1<<2) /* Force interrupt on Index Pulse */ +#define FDC_INTERRUPT_COND_IMMEDIATE (1<<3) /* Force interrupt immediate */ + +extern int FDC_StepRate_ms[]; + + +extern void FDC_MemorySnapShot_Capture ( bool bSave ); +extern void FDC_Init ( void ); +extern void FDC_Reset ( bool bCold ); +extern void FDC_SetDMAStatus ( bool bError ); + +extern void FDC_SetIRQ ( Uint8 IRQ_Source ); +extern void FDC_ClearIRQ ( void ); +extern void FDC_ClearHdcIRQ(void); +extern void FDC_InterruptHandler_Update ( void ); + +extern void FDC_Drive_Set_BusyLed ( Uint8 SR ); +extern int FDC_Get_Statusbar_Text ( char *text, size_t maxlen ); +extern void FDC_Drive_Set_Enable ( int Drive , bool value ); +extern void FDC_Drive_Set_NumberOfHeads ( int Drive , int NbrHeads ); +extern void FDC_InsertFloppy ( int Drive ); +extern void FDC_EjectFloppy ( int Drive ); +extern void FDC_SetDriveSide ( Uint8 io_porta_old , Uint8 io_porta_new ); +extern int FDC_GetBytesPerTrack ( int Drive ); + +extern int FDC_IndexPulse_GetCurrentPos_FdcCycles ( Uint32 *pFdcCyclesPerRev ); +extern int FDC_IndexPulse_GetCurrentPos_NbBytes ( void ); +extern int FDC_IndexPulse_GetState ( void ); +extern int FDC_NextIndexPulse_FdcCycles ( void ); + +extern Uint8 FDC_GetCmdType ( Uint8 CR ); + +extern void FDC_DiskController_WriteWord ( void ); +extern void FDC_DiskControllerStatus_ReadWord ( void ); +extern void FDC_DmaModeControl_WriteWord ( void ); +extern void FDC_DmaStatus_ReadWord ( void ); +extern int FDC_DMA_GetModeControl_R_WR ( void ); +extern int FDC_DMA_GetMode(void); +extern void FDC_DMA_FIFO_Push ( Uint8 Byte ); +extern Uint8 FDC_DMA_FIFO_Pull ( void ); +extern int FDC_DMA_GetSectorCount ( void ); + +extern void FDC_Buffer_Reset ( void ); +extern void FDC_Buffer_Add_Timing ( Uint8 Byte , Uint16 Timing ); +extern void FDC_Buffer_Add ( Uint8 Byte ); +extern Uint16 FDC_Buffer_Read_Timing ( void ); +extern Uint8 FDC_Buffer_Read_Byte ( void ); +extern Uint8 FDC_Buffer_Read_Byte_pos ( int pos ); +extern int FDC_Buffer_Get_Size ( void ); + +extern void FDC_DmaAddress_ReadByte ( void ); +extern void FDC_DmaAddress_WriteByte ( void ); +extern Uint32 FDC_GetDMAAddress ( void ); +extern void FDC_WriteDMAAddress ( Uint32 Address ); + +extern void FDC_FloppyMode_ReadByte ( void ); +extern void FDC_FloppyMode_WriteByte ( void ); #endif /* ifndef HATARI_FDC_H */