|
|
1.1 root 1: /*
2: Hatari - floppy_stx.h
3:
4: This file is distributed under the GNU General Public License, version 2 or at
5: your option any later version. Read the file gpl.txt for details.
6: */
7:
8:
9:
10:
11: typedef struct {
12: /* Content of the STX sector block (16 bytes) */
13: Uint32 DataOffset; /* Offset of sector data in the track data */
14: Uint16 BitPosition; /* Position in bits from the start of the track */
15: /* (this seems to be the position of the start of the ID field, */
16: /* just after the IDAM, but it's not always precise) */
17: Uint16 ReadTime; /* in ms */
18:
19: Uint8 ID_Track; /* Content of the Address Field */
20: Uint8 ID_Head;
21: Uint8 ID_Sector;
22: Uint8 ID_Size;
23: Uint16 ID_CRC;
24:
25: Uint8 FDC_Status; /* FDC status and flags for this sector */
26: Uint8 Reserved; /* Unused, always 0 */
27:
28: /* Other internal variables */
29: Uint16 SectorSize; /* In bytes, depends on ID_Size */
30: Uint8 *pData; /* Bytes for this sector or null if RNF */
31: Uint8 *pFuzzyData; /* Fuzzy mask for this sector or null if no fuzzy bits */
32: Uint8 *pTimingData; /* Data for variable bit width or null */
33:
34: Sint32 SaveSectorIndex; /* Index in STX_SaveStruct[].pSaveSectorsStruct or -1 if not used */
35: } STX_SECTOR_STRUCT;
36:
37: #define STX_SECTOR_BLOCK_SIZE ( 4+2+2+1+1+1+1+2+1+1 ) /* Size of the sector block in an STX file = 16 bytes */
38:
39: /* NOTE : bits 3,4,5 have the same meaning as in the FDC's Status register */
40: #define STX_SECTOR_FLAG_VARIABLE_TIME (1<<0) /* bit 0, if set, this sector has variable bit width */
41: #define STX_SECTOR_FLAG_LOST_DATA (1<<3) /* bit 3, if set, data were lost while reading/writing */
42: #define STX_SECTOR_FLAG_CRC (1<<3) /* bit 3, if set, there's a CRC error */
43: #define STX_SECTOR_FLAG_RNF (1<<4) /* bit 4, if set, there's no sector data */
44: #define STX_SECTOR_FLAG_RECORD_TYPE (1<<5) /* bit 5, if set, deleted data */
45: #define STX_SECTOR_FLAG_FUZZY (1<<7) /* bit 7, if set, this sector has fuzzy bits */
46:
47: #define STX_SECTOR_READ_TIME_DEFAULT 16384 /* Default value if ReadTime==0 */
48:
49:
50: typedef struct {
51: /* Content of the STX track block (16 bytes) */
52: Uint32 BlockSize; /* Number of bytes in this track block */
53: Uint32 FuzzySize; /* Number of bytes in fuzzy mask */
54: Uint16 SectorsCount; /* Number of sector blocks in this track */
55: Uint16 Flags; /* Flags for this track */
56: Uint16 MFMSize; /* Number of MFM bytes in this track */
57: Uint8 TrackNumber; /* bits 0-6 = track number bit 7 = side */
58: Uint8 RecordType; /* Unused */
59:
60: /* Other internal variables */
61: STX_SECTOR_STRUCT *pSectorsStruct; /* All the sectors struct for this track or null */
62:
63: Uint8 *pFuzzyData; /* Fuzzy mask data for all the fuzzy sectors of the track */
64:
65: Uint8 *pTrackData; /* Track data (after sectors data and fuzzy data) */
66: Uint16 TrackImageSyncPosition;
67: Uint16 TrackImageSize; /* Number of bytes in pTrackImageData */
68: Uint8 *pTrackImageData; /* Optional data as returned by the read track command */
69:
70: Uint8 *pSectorsImageData; /* Optional data for the sectors of this track */
71:
72: Uint8 *pTiming;
73: Uint16 TimingFlags; /* always '5' ? */
74: Uint16 TimingSize;
75: Uint8 *pTimingData; /* Timing data for all the sectors of the track ; each timing */
76: /* consists of 2 bytes per 16 FDC bytes */
77:
78: Sint32 SaveTrackIndex; /* Index in STX_SaveStruct[].pSaveTracksStruct or -1 if not used */
79: } STX_TRACK_STRUCT;
80:
81: #define STX_TRACK_BLOCK_SIZE ( 4+4+2+2+2+1+1 ) /* Size of the track block in an STX file = 16 bytes */
82:
83: #define STX_TRACK_FLAG_SECTOR_BLOCK (1<<0) /* bit 0, if set, this track contains sector blocks */
84: #define STX_TRACK_FLAG_TRACK_IMAGE (1<<6) /* bit 6, if set, this track contains a track image */
85: #define STX_TRACK_FLAG_TRACK_IMAGE_SYNC (1<<7) /* bit 7, if set, the track image has a sync position */
86:
87:
88:
89:
90: typedef struct {
91: /* Content of the STX header block (16 bytes) */
92: char FileID[ 4 ]; /* Should be "RSY\0" */
93: Uint16 Version; /* Only version 3 is supported */
94: Uint16 ImagingTool; /* 0x01 (Atari Tool) or 0xCC (Discovery Cartridge) */
95: Uint16 Reserved_1; /* Unused */
96: Uint8 TracksCount; /* Number of track blocks in this file */
97: Uint8 Revision; /* 0x00 (old Pasti file) 0x02 (new Pasti file) */
98: Uint32 Reserved_2; /* Unused */
99:
100: /* Other internal variables */
101: STX_TRACK_STRUCT *pTracksStruct;
102:
103: /* These variable are used to warn the user only one time if a write command is made */
104: bool WarnedWriteSector; /* True if a 'write sector' command was made and user was warned */
105: bool WarnedWriteTrack; /* True if a 'write track' command was made and user was warned */
106: } STX_MAIN_STRUCT;
107:
108: #define STX_MAIN_BLOCK_SIZE ( 4+2+2+2+1+1+4 ) /* Size of the header block in an STX file = 16 bytes */
109:
110:
111: /* Additionnal structures used to save the data for the 'write sector' and 'write track' commands */
112: /* TODO : data are only saved in memory / snapshot and will be lost when exiting. */
113: /* We should have a file format to store them with the .STX file */
114: typedef struct {
115: /* Copy track/side + ID field + BitPosition to uniquely identify each sector */
116: Uint8 Track;
117: Uint8 Side;
118: Uint16 BitPosition;
119: Uint8 ID_Track; /* Content of the Address Field */
120: Uint8 ID_Head;
121: Uint8 ID_Sector;
122: Uint8 ID_Size;
123: Uint16 ID_CRC;
124:
125: Uint16 SectorSize; /* Number of bytes in this sector */
126: Uint8 *pData; /* Data written for this sector */
127:
128: Uint8 StructIsUsed; /* >0 : this structure contains info (and must be saved) */
129: /* =0 : this structure is free and can be reused for another sector */
130: } STX_SAVE_SECTOR_STRUCT;
131:
132:
133: typedef struct {
134: Uint8 Track;
135: Uint8 Side;
136:
137: Uint16 TrackSizeWrite; /* Number of bytes in this track (when writing) */
138: /* (can be rounded to 16 because of DMA buffering */
139: Uint8 *pDataWrite; /* Data written for this track */
140:
141: Uint16 TrackSizeRead; /* Number of bytes in this track (when reading) */
142: /* Due to interpreting bytes $F5-$FF, TrackSizeRead will often be > TrackSizeWrite */
143: Uint8 *pDataRead; /* Data saved for this track as they will be read */
144: /* (after interpreting bytes $F5-$FF) */
145: } STX_SAVE_TRACK_STRUCT;
146:
147:
148: typedef struct {
149: Uint32 SaveSectorsCount;
150: STX_SAVE_SECTOR_STRUCT *pSaveSectorsStruct;
151:
152: Uint32 SaveTracksCount;
153: STX_SAVE_TRACK_STRUCT *pSaveTracksStruct;
154: } STX_SAVE_STRUCT;
155:
156:
157:
158: extern void STX_MemorySnapShot_Capture(bool bSave);
159: extern bool STX_FileNameIsSTX(const char *pszFileName, bool bAllowGZ);
160: extern bool STX_FileNameToSave ( const char *FilenameSTX , char *FilenameSave );
161: extern Uint8 *STX_ReadDisk(int Drive, const char *pszFileName, long *pImageSize, int *pImageType);
162: extern bool STX_WriteDisk(int Drive, const char *pszFileName, Uint8 *pBuffer, int ImageSize);
163:
164: extern bool STX_Init ( void );
165: extern bool STX_Insert ( int Drive , const char *FilenameSTX , Uint8 *pImageBuffer , long ImageSize );
166: extern bool STX_Eject ( int Drive );
167:
168: extern STX_MAIN_STRUCT *STX_BuildStruct ( Uint8 *pFileBuffer , int Debug );
169:
170:
171: extern Uint32 FDC_GetCyclesPerRev_FdcCycles_STX ( Uint8 Drive , Uint8 Track , Uint8 Side );
172: extern int FDC_NextSectorID_FdcCycles_STX ( Uint8 Drive , Uint8 NumberOfHeads , Uint8 Track , Uint8 Side );
173: extern Uint8 FDC_NextSectorID_TR_STX ( void );
174: extern Uint8 FDC_NextSectorID_SR_STX ( void );
175: extern Uint8 FDC_NextSectorID_LEN_STX ( void );
176: extern Uint8 FDC_NextSectorID_CRC_OK_STX ( void );
177: extern Uint8 FDC_ReadSector_STX ( Uint8 Drive , Uint8 Track , Uint8 Sector , Uint8 Side , int *pSectorSize );
178: extern Uint8 FDC_WriteSector_STX ( Uint8 Drive , Uint8 Track , Uint8 Sector , Uint8 Side , int SectorSize );
179: extern Uint8 FDC_ReadAddress_STX ( Uint8 Drive , Uint8 Track , Uint8 Sector , Uint8 Side );
180: extern Uint8 FDC_ReadTrack_STX ( Uint8 Drive , Uint8 Track , Uint8 Side );
181: extern Uint8 FDC_WriteTrack_STX ( Uint8 Drive , Uint8 Track , Uint8 Side , int TrackSize );
182:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.