2 Skelton for retropc emulator
4 Author : Takeda.Toshiya
11 #include "../fileio.h"
12 #if defined(_USE_AGAR) || defined(_USE_SDL) || defined(_USE_QT)
13 #include "agar_logger.h"
17 static const uint16 crc_table[256] = {
18 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
19 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
20 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
21 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
22 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
23 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
24 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
25 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
26 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
27 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
28 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
29 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
30 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
31 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
32 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
33 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
36 // teledisk decoder table
37 static const uint8 d_code[256] = {
38 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
39 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
40 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
41 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
42 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
43 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
44 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
45 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,
46 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
47 0x0c, 0x0c, 0x0c, 0x0c, 0x0d, 0x0d, 0x0d, 0x0d, 0x0e, 0x0e, 0x0e, 0x0e, 0x0f, 0x0f, 0x0f, 0x0f,
48 0x10, 0x10, 0x10, 0x10, 0x11, 0x11, 0x11, 0x11, 0x12, 0x12, 0x12, 0x12, 0x13, 0x13, 0x13, 0x13,
49 0x14, 0x14, 0x14, 0x14, 0x15, 0x15, 0x15, 0x15, 0x16, 0x16, 0x16, 0x16, 0x17, 0x17, 0x17, 0x17,
50 0x18, 0x18, 0x19, 0x19, 0x1a, 0x1a, 0x1b, 0x1b, 0x1c, 0x1c, 0x1d, 0x1d, 0x1e, 0x1e, 0x1f, 0x1f,
51 0x20, 0x20, 0x21, 0x21, 0x22, 0x22, 0x23, 0x23, 0x24, 0x24, 0x25, 0x25, 0x26, 0x26, 0x27, 0x27,
52 0x28, 0x28, 0x29, 0x29, 0x2a, 0x2a, 0x2b, 0x2b, 0x2c, 0x2c, 0x2d, 0x2d, 0x2e, 0x2e, 0x2f, 0x2f,
53 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f
55 static const uint8 d_len[256] = {
56 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
57 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
58 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
59 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
60 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
61 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
62 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
63 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
64 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
65 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
66 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
67 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
68 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
69 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
70 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
71 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08
73 static const int secsize[8] = {
74 128, 256, 512, 1024, 2048, 4096, 8192, 16384
77 static uint8 tmp_buffer[DISK_BUFFER_SIZE];
81 int ncyl, nside, nsec, size;
84 static const fd_format_t fd_formats[] = {
85 { MEDIA_TYPE_2D, 40, 1, 16, 256 }, // 1D 160KB
86 { MEDIA_TYPE_2D , 40, 2, 16, 256 }, // 2D 320KB
87 #if defined(_MZ80B) || defined(_MZ2000) || defined(_MZ2200) || defined(_MZ2500)
88 { MEDIA_TYPE_2DD, 80, 2, 16, 256 }, // 2DD 640KB (MZ-2500)
90 { MEDIA_TYPE_2DD, 80, 2, 8, 512 }, // 2DD 640KB
92 { MEDIA_TYPE_2DD, 80, 2, 9, 512 }, // 2DD 720KB
93 { MEDIA_TYPE_2HD, 80, 2, 15, 512 }, // 2HC 1.20MB
94 { MEDIA_TYPE_2HD, 77, 2, 8, 1024 }, // 2HD 1.25MB
95 { MEDIA_TYPE_144, 80, 2, 18, 512 }, // 2HD 1.44MB
96 { MEDIA_TYPE_144, 80, 2, 36, 512 }, // 2ED 2.88MB
100 #define IS_VALID_TRACK(offset) ((offset) >= 0x2b0 && (offset) < sizeof(buffer))
102 void DISK::open(_TCHAR path[], int bank)
104 // check current disk image
106 if(_tcsicmp(orig_path, path) == 0 && file_bank == bank) {
111 memset(buffer, 0, sizeof(buffer));
112 media_type = MEDIA_TYPE_UNK;
113 is_standard_image = is_fdi_image = false;
114 trim_required = false;
118 if(fi->Fopen(path, FILEIO_READ_BINARY)) {
119 bool converted = false;
121 _tcscpy_s(orig_path, _MAX_PATH, path);
122 _tcscpy_s(dest_path, _MAX_PATH, path);
123 _stprintf_s(temp_path, _MAX_PATH, _T("%s.$$$"), path);
126 // check if file protected
127 write_protected = fi->IsProtected(path);
129 // is this d88 format ?
130 if(check_file_extension(path, _T(".d88")) || check_file_extension(path, _T(".d77"))) {
132 for(int i = 0; i < bank; i++) {
133 fi->Fseek(offset + 0x1c, SEEK_SET);
134 offset += fi->FgetUint32_LE();
136 fi->Fseek(offset + 0x1c, FILEIO_SEEK_SET);
137 file_size.d = fi->FgetUint32_LE();
138 fi->Fseek(offset, FILEIO_SEEK_SET);
139 fi->Fread(buffer, file_size.d, 1);
141 inserted = changed = true;
142 // trim_required = true;
143 trim_required = false;
147 fi->Fseek(0, FILEIO_SEEK_END);
148 file_size.d = fi->Ftell();
149 fi->Fseek(0, FILEIO_SEEK_SET);
152 #if defined(_X1) || defined(_X1TWIN) || defined(_X1TURBO) || defined(_X1TURBOZ)
153 // is this 2d format ?
154 if(check_file_extension(path, _T(".2d"))) {
155 if(standard_to_d88(MEDIA_TYPE_2D, 40, 2, 16, 256)) {
156 inserted = changed = is_standard_image = true;
159 fi->Fseek(0, FILEIO_SEEK_SET);
163 // check image file format
164 for(int i = 0;; i++) {
165 const fd_format_t *p = &fd_formats[i];
169 int len = p->ncyl * p->nside * p->nsec * p->size;
170 // 4096 bytes: FDI header ???
171 if(file_size.d == len || (file_size.d == (len + 4096) && (len == 655360 || len == 1261568))) {
172 if(file_size.d == len + 4096) {
174 fi->Fread(fdi_header, 4096, 1);
176 if(standard_to_d88(p->type, p->ncyl, p->nside, p->nsec, p->size)) {
177 inserted = changed = is_standard_image = true;
182 if(0 < file_size.d && file_size.d <= DISK_BUFFER_SIZE) {
183 memset(buffer, 0, sizeof(buffer));
184 fi->Fread(buffer, file_size.d, 1);
186 // check d88 format (temporary)
187 if(file_size.b.l == buffer[0x1c] && file_size.b.h == buffer[0x1d] && file_size.b.h2 == buffer[0x1e] && file_size.b.h3 == buffer[0x1f]) {
188 inserted = changed = true;
191 _stprintf_s(dest_path, _MAX_PATH, _T("%s.D88"), path);
195 if(memcmp(buffer, "TD", 2) == 0 || memcmp(buffer, "td", 2) == 0) {
196 // teledisk image file
197 inserted = changed = converted = teledisk_to_d88();
198 } else if(memcmp(buffer, "IMD", 3) == 0) {
199 // imagedisk image file
200 inserted = changed = converted = imagedisk_to_d88();
201 } else if(memcmp(buffer, "MV - CPC", 8) == 0) {
202 // standard cpdread image file
203 inserted = changed = converted = cpdread_to_d88(0);
204 } else if(memcmp(buffer, "EXTENDED", 8) == 0) {
205 // extended cpdread image file
206 inserted = changed = converted = cpdread_to_d88(1);
209 // failed to convert the disk image
217 fi->Remove(temp_path);
223 FILEIO* fio = new FILEIO();
224 if(fio->Fopen(dest_path, FILEIO_WRITE_BINARY)) {
225 fio->Fwrite(buffer, file_size.d, 1);
231 crc32 = getcrc32(buffer, file_size.d);
233 if(buffer[0x1a] != 0) {
234 write_protected = true;
236 if(media_type == MEDIA_TYPE_UNK) {
237 if((media_type = buffer[0x1b]) == MEDIA_TYPE_2HD) {
238 for(int trkside = 0; trkside < 164; trkside++) {
240 offset.read_4bytes_le_from(buffer + 0x20 + trkside * 4);
242 if(!IS_VALID_TRACK(offset.d)) {
246 uint8 *t = buffer + offset.d;
247 pair sector_num, data_size;
248 sector_num.read_2bytes_le_from(t + 4);
249 data_size.read_2bytes_le_from(t + 14);
251 if(sector_num.sd >= 18 && data_size.sd == 512) {
252 media_type = MEDIA_TYPE_144;
258 // FIXME: ugly patch for X1turbo ALPHA and Batten Tanuki
260 #if defined(_X1) || defined(_X1TWIN) || defined(_X1TURBO) || defined(_X1TURBOZ)
261 if(media_type == MEDIA_TYPE_2D) {
262 // check first sector
264 offset.read_4bytes_le_from(buffer + 0x20);
265 if(IS_VALID_TRACK(offset.d)) {
266 static const uint8 batten[] = {0xca, 0xde, 0xaf, 0xc3, 0xdd, 0x20, 0xc0, 0xc7, 0xb7};
267 uint8 *t = buffer + offset.d;
268 if(strncmp((char *)(t + 0x11), "turbo ALPHA", 11) == 0) {
269 is_special_disk = SPECIAL_DISK_X1_ALPHA;
270 } else if(memcmp((void *)(t + 0x11), batten, sizeof(batten)) == 0) {
271 is_special_disk = SPECIAL_DISK_X1_BATTEN;
286 trim_required = false;
288 if(!write_protected && file_size.d && getcrc32(buffer, file_size.d) != crc32) {
290 FILEIO* fio = new FILEIO();
291 int pre_size = 0, post_size = 0;
292 uint8 *pre_buffer = NULL, *post_buffer = NULL;
294 // is this d88 format ?
295 if(check_file_extension(dest_path, _T(".d88")) || check_file_extension(dest_path, _T(".d77"))) {
296 if(fio->Fopen(dest_path, FILEIO_READ_BINARY)) {
297 fio->Fseek(0, FILEIO_SEEK_END);
298 uint32 total_size = fio->Ftell(), offset = 0;
299 for(int i = 0; i < file_bank; i++) {
300 fio->Fseek(offset + 0x1c, SEEK_SET);
301 offset += fio->FgetUint32_LE();
303 if((pre_size = offset) > 0) {
304 pre_buffer = (uint8 *)malloc(pre_size);
305 fio->Fseek(0, FILEIO_SEEK_SET);
306 fio->Fread(pre_buffer, pre_size, 1);
308 fio->Fseek(offset + 0x1c, SEEK_SET);
309 offset += fio->FgetUint32_LE();
310 if((post_size = total_size - offset) > 0) {
311 post_buffer = (uint8 *)malloc(post_size);
312 fio->Fseek(offset, FILEIO_SEEK_SET);
313 fio->Fread(post_buffer, post_size, 1);
318 if(!fio->Fopen(dest_path, FILEIO_WRITE_BINARY)) {
319 _TCHAR tmp_path[_MAX_PATH];
320 _stprintf_s(tmp_path, _MAX_PATH, _T("temporary_saved_floppy_disk_#%d.d88"), drive_num);
321 fio->Fopen(emu->bios_path(tmp_path), FILEIO_WRITE_BINARY);
323 if(fio->IsOpened()) {
325 fio->Fwrite(pre_buffer, pre_size, 1);
327 if(is_standard_image) {
329 fio->Fwrite(fdi_header, 4096, 1);
331 for(int trkside = 0; trkside < 164; trkside++) {
333 offset.read_4bytes_le_from(buffer + 0x20 + trkside * 4);
335 if(!IS_VALID_TRACK(offset.d)) {
338 uint8* t = buffer + offset.d;
339 pair sector_num, data_size;
340 sector_num.read_2bytes_le_from(t + 4);
342 for(int i = 0; i < sector_num.sd; i++) {
343 data_size.read_2bytes_le_from(t + 14);
344 fio->Fwrite(t + 0x10, data_size.sd, 1);
345 t += data_size.sd + 0x10;
349 fio->Fwrite(buffer, file_size.d, 1);
352 fio->Fwrite(post_buffer, post_size, 1);
366 inserted = write_protected = false;
368 sector_size.sd = sector_num.sd = 0;
372 bool DISK::get_track(int trk, int side)
374 sector_size.sd = sector_num.sd = 0;
377 // disk not inserted or invalid media type
378 if(!(inserted && check_media_type())) {
383 int trkside = trk * 2 + (side & 1);
384 if(!(0 <= trkside && trkside < 164)) {
388 offset.read_4bytes_le_from(buffer + 0x20 + trkside * 4);
390 if(!IS_VALID_TRACK(offset.d)) {
395 sector = buffer + offset.d;
396 sector_num.read_2bytes_le_from(sector + 4);
398 // create each sector position in track
399 int sync_size = drive_mfm ? 12 : 6;
400 int am_size = drive_mfm ? 3 : 0;
401 int gap2_size = drive_mfm ? 22 : 11;
404 too_many_sectors = false;
407 int total = 0, gap3_size;
409 for(int i = 0; i < sector_num.sd; i++) {
411 data_size.read_2bytes_le_from(t + 14);
412 if((data_size.sd >> data_size_shift) < 0x80) {
413 too_many_sectors = true;
416 total += sync_size + (am_size + 1) + (4 + 2) + gap2_size + sync_size + (am_size + 1);
417 total += (data_size.sd >> data_size_shift) + 2;
418 t += data_size.sd + 0x10;
420 if(too_many_sectors) {
421 // Too many sectors in this track
424 } else if((gap3_size = (get_track_size() - total) / (sector_num.sd + 2)) < 12) {
430 total = gap3_size * 2;
432 for(int i = 0; i < sector_num.sd; i++) {
434 data_size.read_2bytes_le_from(t + 14);
435 if(too_many_sectors) {
436 total = gap3_size * 2 + (get_track_size() - gap3_size * 2) * i / sector_num.sd;
438 sync_position[i] = total;
439 total += sync_size + (am_size + 1);
440 id_position[i] = total;
441 total += (4 + 2) + gap2_size + sync_size + (am_size + 1);
442 data_position[i] = total;
443 total += (data_size.sd >> data_size_shift) + 2 + gap3_size;
447 t += data_size.sd + 0x10;
452 bool DISK::make_track(int trk, int side)
454 int track_size = get_track_size();
456 if(!get_track(trk, side)) {
457 // create a dummy track
458 for(int i = 0; i < track_size; i++) {
465 int sync_size = drive_mfm ? 12 : 6;
466 int am_size = drive_mfm ? 3 : 0;
467 int gap2_size = drive_mfm ? 22 : 11;
468 uint8 gap_data = drive_mfm ? 0x4e : 0xff;
471 memset(track, gap_data, track_size);
473 if(sync_position[0] >= (sync_size + am_size + 1) + (8 + 5)) {
474 int p = (sync_position[0] - (sync_size + am_size + 1)) * 8 / (8 + 5);
477 for(int i = 0; i < sync_size; i++) {
481 for(int i = 0; i < am_size; i++) {
490 for(int i = 0; i < sector_num.sd; i++) {
492 data_size.read_2bytes_le_from(t + 14);
493 int p = sync_position[i];
496 for(int j = 0; j < sync_size; j++) {
497 if(p < track_size) track[p++] = 0x00;
500 for(int j = 0; j < am_size; j++) {
501 if(p < track_size) track[p++] = 0xa1;
503 if(p < track_size) track[p++] = 0xfe;
505 if(p < track_size) track[p++] = t[0];
506 if(p < track_size) track[p++] = t[1];
507 if(p < track_size) track[p++] = t[2];
508 if(p < track_size) track[p++] = t[3];
510 crc = (uint16)((crc << 8) ^ crc_table[(uint8)(crc >> 8) ^ t[0]]);
511 crc = (uint16)((crc << 8) ^ crc_table[(uint8)(crc >> 8) ^ t[1]]);
512 crc = (uint16)((crc << 8) ^ crc_table[(uint8)(crc >> 8) ^ t[2]]);
513 crc = (uint16)((crc << 8) ^ crc_table[(uint8)(crc >> 8) ^ t[3]]);
514 if(p < track_size) track[p++] = (crc >> 8) & 0xff;
515 if(p < track_size) track[p++] = (crc >> 0) & 0xff;
517 for(int j = 0; j < gap2_size; j++) {
518 if(p < track_size) track[p++] = gap_data;
521 for(int j = 0; j < sync_size; j++) {
522 if(p < track_size) track[p++] = 0x00;
525 for(int j = 0; j < am_size; j++) {
526 if(p < track_size) track[p++] = 0xa1;
528 if(p < track_size) track[p++] = (t[7] != 0) ? 0xf8 : 0xfb;
531 for(int j = 0; j < (data_size.sd >> data_size_shift); j++) {
532 if(p < track_size) track[p++] = t[0x10 + j];
533 crc = (uint16)((crc << 8) ^ crc_table[(uint8)(crc >> 8) ^ t[0x10 + j]]);
535 if(p < track_size) track[p++] = (crc >> 8) & 0xff;
536 if(p < track_size) track[p++] = (crc >> 0) & 0xff;
538 t += data_size.sd + 0x10;
543 bool DISK::get_sector(int trk, int side, int index)
545 sector_size.sd = sector_num.sd = 0;
548 // disk not inserted or invalid media type
549 if(!(inserted && check_media_type())) {
554 int trkside = trk * 2 + (side & 1);
555 if(!(0 <= trkside && trkside < 164)) {
559 offset.read_4bytes_le_from(buffer + 0x20 + trkside * 4);
561 if(!IS_VALID_TRACK(offset.d)) {
566 uint8* t = buffer + offset.d;
567 sector_num.read_2bytes_le_from(t + 4);
569 if(index >= sector_num.sd) {
574 for(int i = 0; i < index; i++) {
576 data_size.read_2bytes_le_from(t + 14);
577 t += data_size.sd + 0x10;
583 void DISK::set_sector_info(uint8 *t)
591 crc = (uint16)((crc << 8) ^ crc_table[(uint8)(crc >> 8) ^ t[0]]);
592 crc = (uint16)((crc << 8) ^ crc_table[(uint8)(crc >> 8) ^ t[1]]);
593 crc = (uint16)((crc << 8) ^ crc_table[(uint8)(crc >> 8) ^ t[2]]);
594 crc = (uint16)((crc << 8) ^ crc_table[(uint8)(crc >> 8) ^ t[3]]);
595 id[4] = (crc >> 8) & 0xff;
596 id[5] = (crc >> 0) & 0xff;
598 deleted = (t[7] != 0);
599 crc_error = (t[8] != 0x00 && t[8] != 0x10);
601 sector_size.read_2bytes_le_from(t + 14);
604 void DISK::set_deleted(bool value)
607 uint8 *t = sector - 0x10;
608 t[7] = value ? 0x10 : 0;
609 if(t[8] == 0x00 || t[8] == 0x10) {
616 void DISK::set_crc_error(bool value)
619 uint8 *t = sector - 0x10;
620 t[8] = value ? 0xb0 : t[7];
625 bool DISK::format_track(int trk, int side)
627 // disk not inserted or invalid media type
628 if(!(inserted && check_media_type())) {
633 int trkside = trk * 2 + (side & 1);
634 if(!(0 <= trkside && trkside < 164)) {
638 // create new empty track
641 trim_required = false;
643 memset(buffer + DISK_BUFFER_SIZE, 0, sizeof(buffer) - DISK_BUFFER_SIZE);
645 offset.d = DISK_BUFFER_SIZE;
646 offset.write_4bytes_le_to(buffer + 0x20 + trkside * 4);
648 trim_required = true;
653 void DISK::insert_sector(uint8 c, uint8 h, uint8 r, uint8 n, bool deleted, bool crc_error, uint8 fill_data, int length)
655 uint8* t = buffer + DISK_BUFFER_SIZE;
658 for(int i = 0; i < (sector_num.sd - 1); i++) {
659 t[4] = sector_num.b.l;
660 t[5] = sector_num.b.h;
662 data_size.read_2bytes_le_from(t + 14);
663 t += data_size.sd + 0x10;
669 t[4] = sector_num.b.l;
670 t[5] = sector_num.b.h;
671 t[6] = drive_mfm ? 0 : 0x40;
672 t[7] = deleted ? 0x10 : 0;
673 t[8] = crc_error ? 0xb0 : t[7];
674 t[14] = (length >> 0) & 0xff;
675 t[15] = (length >> 8) & 0xff;
676 memset(t + 16, fill_data, length);
681 void DISK::trim_buffer()
683 uint32 dest_offset = 0x2b0;
686 memcpy(tmp_buffer, buffer, 0x2b0);
689 for(int trkside = 0; trkside < 164; trkside++) {
691 src_trk_offset.read_4bytes_le_from(buffer + 0x20 + trkside * 4);
693 pair dest_trk_offset;
694 dest_trk_offset.d = 0;
696 if(IS_VALID_TRACK(src_trk_offset.d)) {
697 uint8* t = buffer + src_trk_offset.d;
698 pair sector_num, data_size;
699 sector_num.read_2bytes_le_from(t + 4);
700 if(sector_num.sd != 0) {
701 dest_trk_offset.d = dest_offset;
702 for(int i = 0; i < sector_num.sd; i++) {
703 data_size.read_2bytes_le_from(t + 14);
704 memcpy(tmp_buffer + dest_offset, t, data_size.sd + 0x10);
705 dest_offset += data_size.sd + 0x10;
706 t += data_size.sd + 0x10;
710 dest_trk_offset.write_4bytes_le_to(tmp_buffer + 0x20 + trkside * 4);
714 file_size.d = dest_offset;
715 file_size.write_4bytes_le_to(tmp_buffer + 0x1c);
717 memset(buffer, 0, sizeof(buffer));
718 memcpy(buffer, tmp_buffer, file_size.d);
725 } else if(inserted) {
726 return (media_type == MEDIA_TYPE_2HD) ? 360 : 300;
728 return (drive_type == DRIVE_TYPE_2HD) ? 360 : 300;
732 int DISK::get_track_size()
735 return media_type == MEDIA_TYPE_144 ? 12500 : media_type == MEDIA_TYPE_2HD ? 10410 : drive_mfm ? 6250 : 3100;
737 return drive_type == DRIVE_TYPE_144 ? 12500 : drive_type == DRIVE_TYPE_2HD ? 10410 : drive_mfm ? 6250 : 3100;
741 double DISK::get_usec_per_bytes(int bytes)
743 return 1000000.0 / (get_track_size() * (get_rpm() / 60.0)) * bytes;
746 bool DISK::check_media_type()
750 return (media_type == MEDIA_TYPE_2D);
752 return (media_type == MEDIA_TYPE_2D || media_type == MEDIA_TYPE_2DD);
754 return (media_type == MEDIA_TYPE_2HD);
756 return (media_type == MEDIA_TYPE_144);
758 return true; // always okay
763 // teledisk image decoder
766 this teledisk image decoder is based on:
768 LZHUF.C English version 1.0 based on Japanese version 29-NOV-1988
769 LZSS coded by Haruhiko OKUMURA
770 Adaptive Huffman Coding coded by Haruyasu YOSHIZAKI
771 Edited and translated to English by Kenji RIKITAKE
775 #define COPYBUFFER(src, size) { \
776 if(file_size.d + (size) > DISK_BUFFER_SIZE) { \
779 memcpy(buffer + file_size.d, (src), (size)); \
780 file_size.d += (size); \
783 bool DISK::teledisk_to_d88()
793 // check teledisk header
794 fi->Fseek(0, FILEIO_SEEK_SET);
795 fi->Fread(&hdr, sizeof(td_hdr_t), 1);
796 if(hdr.sig[0] == 't' && hdr.sig[1] == 'd') {
797 // decompress to the temporary file
798 FILEIO* fo = new FILEIO();
799 if(!fo->Fopen(temp_path, FILEIO_WRITE_BINARY)) {
806 if((rd = decode(obuf, 512)) > 0) {
807 fo->Fwrite(obuf, rd, 1);
815 // reopen the temporary file
817 if(!fi->Fopen(temp_path, FILEIO_READ_BINARY)) {
821 if(hdr.flag & 0x80) {
823 fi->Fread(&cmt, sizeof(td_cmt_t), 1);
824 fi->Fseek(cmt.len, FILEIO_SEEK_CUR);
831 memset(&d88_hdr, 0, sizeof(d88_hdr_t));
832 _strcpy_s(d88_hdr.title, sizeof(d88_hdr.title), "TELEDISK");
833 d88_hdr.protect = 0; // non-protected
834 COPYBUFFER(&d88_hdr, sizeof(d88_hdr_t));
837 int trkcnt = 0, trkptr = sizeof(d88_hdr_t);
838 fi->Fread(&trk, sizeof(td_trk_t), 1);
839 while(trk.nsec != 0xff) {
840 d88_hdr.trkptr[trkcnt++] = trkptr;
842 d88_hdr.trkptr[trkcnt++] = trkptr;
845 // read sectors in this track
846 for(int i = 0; i < trk.nsec; i++) {
847 uint8 buf[2048], dst[2048];
848 memset(buf, 0, sizeof(buf));
849 memset(dst, 0, sizeof(dst));
851 // read sector header
852 fi->Fread(&sct, sizeof(td_sct_t), 1);
854 // create d88 sector header
855 memset(&d88_sct, 0, sizeof(d88_sct_t));
860 d88_sct.nsec = trk.nsec;
861 d88_sct.dens = (hdr.dens & 0x80) ? 0x40 : 0;
862 d88_sct.del = (sct.ctrl & 4) ? 0x10 : 0;
863 d88_sct.stat = (sct.ctrl & 2) ? 0xb0 : d88_sct.del;
864 d88_sct.size = secsize[sct.n & 3];
866 // create sector image
867 if(sct.ctrl != 0x10) {
868 // read sector source
869 int len = fi->Fgetc();
870 len += fi->Fgetc() * 256 - 1;
871 int flag = fi->Fgetc(), d = 0;
872 fi->Fread(buf, len, 1);
876 memcpy(dst, buf, len);
877 } else if(flag == 1) {
879 len2.read_2bytes_le_from(buf);
884 } else if(flag == 2) {
885 for(int s = 0; s < len;) {
892 } else if(type < 5) {
898 for(int j = 0; j < n; j++) {
902 for(int j = 0; j < n; j++) {
907 break; // unknown type
911 break; // unknown flag
918 COPYBUFFER(&d88_sct, sizeof(d88_sct_t));
919 COPYBUFFER(dst, d88_sct.size);
920 trkptr += sizeof(d88_sct_t) + d88_sct.size;
923 fi->Fread(&trk, sizeof(td_trk_t), 1);
925 d88_hdr.type = ((hdr.dens & 3) == 2) ? MEDIA_TYPE_2HD : ((trkcnt >> 1) > 60) ? MEDIA_TYPE_2DD : MEDIA_TYPE_2D;
926 d88_hdr.size = trkptr;
927 memcpy(buffer, &d88_hdr, sizeof(d88_hdr_t));
931 int DISK::next_word()
933 if(ibufndx >= ibufcnt) {
934 ibufndx = ibufcnt = 0;
935 memset(inbuf, 0, 512);
936 for(int i = 0; i < 512; i++) {
949 getbuf |= inbuf[ibufndx++] << (8 - getlen);
957 if(next_word() < 0) {
963 return (i < 0) ? 1 : 0;
968 if(next_word() != 0) {
978 void DISK::start_huff()
981 for(i = 0; i < N_CHAR; i++) {
983 son[i] = i + TABLE_SIZE;
984 prnt[i + TABLE_SIZE] = i;
987 while(j <= ROOT_POSITION) {
988 freq[j] = freq[i] + freq[i + 1];
990 prnt[i] = prnt[i + 1] = j;
993 freq[TABLE_SIZE] = 0xffff;
994 prnt[ROOT_POSITION] = 0;
1001 for(i = 0; i < TABLE_SIZE; i++) {
1002 if(son[i] >= TABLE_SIZE) {
1003 freq[j] = (freq[i] + 1) / 2;
1008 for(i = 0, j = N_CHAR; j < TABLE_SIZE; i += 2, j++) {
1010 f = freq[j] = freq[i] + freq[k];
1011 for(k = j - 1; f < freq[k]; k--);
1014 memmove(&freq[k + 1], &freq[k], l);
1016 memmove(&son[k + 1], &son[k], l);
1019 for(i = 0; i < TABLE_SIZE; i++) {
1020 if((k = son[i]) >= TABLE_SIZE) {
1023 prnt[k] = prnt[k + 1] = i;
1028 void DISK::update(int c)
1031 if(freq[ROOT_POSITION] == MAX_FREQ) {
1034 c = prnt[c + TABLE_SIZE];
1037 if(k > freq[l = c + 1]) {
1038 while(k > freq[++l]);
1044 if(i < TABLE_SIZE) {
1050 if(j < TABLE_SIZE) {
1057 while((c = prnt[c]) != 0);
1060 short DISK::decode_char()
1063 uint16 c = son[ROOT_POSITION];
1064 while(c < TABLE_SIZE) {
1065 if((ret = get_bit()) < 0) {
1076 short DISK::decode_position()
1080 if((bit = get_byte()) < 0) {
1084 c = (uint16)d_code[i] << 6;
1087 if((bit = get_bit()) < 0) {
1092 return (c | i & 0x3f);
1095 void DISK::init_decode()
1097 ibufcnt= ibufndx = bufcnt = getbuf = 0;
1100 for(int i = 0; i < STRING_BUFFER_SIZE - LOOKAHEAD_BUFFER_SIZE; i++) {
1103 ptr = STRING_BUFFER_SIZE - LOOKAHEAD_BUFFER_SIZE;
1106 int DISK::decode(uint8 *buf, int len)
1110 for(count = 0; count < len;) {
1112 if((c = decode_char()) < 0) {
1116 *(buf++) = (uint8)c;
1117 text_buf[ptr++] = (uint8)c;
1118 ptr &= (STRING_BUFFER_SIZE - 1);
1121 if((pos = decode_position()) < 0) {
1124 bufpos = (ptr - pos - 1) & (STRING_BUFFER_SIZE - 1);
1125 bufcnt = c - 255 + THRESHOLD;
1129 while(bufndx < bufcnt && count < len) {
1130 c = text_buf[(bufpos + bufndx) & (STRING_BUFFER_SIZE - 1)];
1131 *(buf++) = (uint8)c;
1133 text_buf[ptr++] = (uint8)c;
1134 ptr &= (STRING_BUFFER_SIZE - 1);
1137 if(bufndx >= bufcnt) {
1138 bufndx = bufcnt = 0;
1145 // imagedisk image decoder
1147 bool DISK::imagedisk_to_d88()
1154 fi->Fseek(0, FILEIO_SEEK_SET);
1156 while((tmp = fi->Fgetc()) != 0x1a) {
1165 // create d88 header
1166 memset(&d88_hdr, 0, sizeof(d88_hdr_t));
1167 _strcpy_s(d88_hdr.title, sizeof(d88_hdr.title), "IMAGEDISK");
1168 d88_hdr.protect = 0; // non-protected
1169 COPYBUFFER(&d88_hdr, sizeof(d88_hdr_t));
1172 int trkptr = sizeof(d88_hdr_t);
1173 int trkcnt = 0, mode;
1175 for(int t = 0; t < 164; t++) {
1176 // check end of file
1177 if(fi->Fread(&trk, sizeof(imd_trk_t), 1) != 1) {
1182 // check track header
1184 mode = trk.mode % 3; // 0=500kbps, 1=300kbps, 2=250kbps
1189 d88_hdr.trkptr[t] = trkptr;
1192 uint8 c[64], h[64], r[64];
1193 fi->Fread(r, trk.nsec, 1);
1194 if(trk.head & 0x80) {
1195 fi->Fread(c, trk.nsec, 1);
1197 memset(c, trk.cyl, sizeof(c));
1199 if(trk.head & 0x40) {
1200 fi->Fread(h, trk.nsec, 1);
1202 memset(h, trk.head & 1, sizeof(h));
1205 // read sectors in this track
1206 for(int i = 0; i < trk.nsec; i++) {
1207 // create d88 sector header
1208 int sectype = fi->Fgetc();
1212 memset(&d88_sct, 0, sizeof(d88_sct_t));
1216 d88_sct.n = trk.size;
1217 d88_sct.nsec = trk.nsec;
1218 d88_sct.dens = (trk.mode < 3) ? 0x40 : 0;
1219 d88_sct.del = (sectype == 3 || sectype == 4 || sectype == 7 || sectype == 8) ? 0x10 : 0;
1220 d88_sct.stat = (sectype == 5 || sectype == 6 || sectype == 7 || sectype == 8) ? 0xb0 : d88_sct.del;
1221 d88_sct.size = secsize[trk.size & 7];
1223 // create sector image
1225 if(sectype == 1 || sectype == 3 || sectype == 5 || sectype == 7) {
1227 fi->Fread(dst, d88_sct.size, 1);
1228 } else if(sectype == 2 || sectype == 4 || sectype == 6 || sectype == 8) {
1230 int tmp = fi->Fgetc();
1231 memset(dst, tmp, d88_sct.size);
1237 COPYBUFFER(&d88_sct, sizeof(d88_sct_t));
1238 COPYBUFFER(dst, d88_sct.size);
1239 trkptr += sizeof(d88_sct_t) + d88_sct.size;
1242 d88_hdr.type = (mode == 0) ? MEDIA_TYPE_2HD : ((trkcnt >> 1) > 60) ? MEDIA_TYPE_2DD : MEDIA_TYPE_2D;
1243 d88_hdr.size = trkptr;
1244 memcpy(buffer, &d88_hdr, sizeof(d88_hdr_t));
1248 // cpdread image decoder (from MESS formats/dsk_dsk.c)
1250 bool DISK::cpdread_to_d88(int extended)
1256 // get cylinder number and side number
1257 memcpy(tmp_buffer, buffer, file_size.d);
1258 int ncyl = tmp_buffer[0x30];
1259 int nside = tmp_buffer[0x31];
1264 // create d88 header
1265 memset(&d88_hdr, 0, sizeof(d88_hdr_t));
1266 _strcpy_s(d88_hdr.title, sizeof(d88_hdr.title), "CPDRead");
1267 d88_hdr.protect = 0; // non-protected
1268 COPYBUFFER(&d88_hdr, sizeof(d88_hdr_t));
1271 int trkofs = 0x100, trkofs_ptr = 0x34;
1272 int trkptr = sizeof(d88_hdr_t);
1274 for(int c = 0; c < ncyl; c++) {
1275 for(int h = 0; h < nside; h++) {
1276 // read sectors in this track
1277 uint8 *track_info = tmp_buffer + trkofs;
1278 int cyl = track_info[0x10];
1279 int side = track_info[0x11];
1280 int nsec = track_info[0x15];
1281 int size = 1 << (track_info[0x14] + 7); // standard
1282 int sctofs = trkofs + 0x100;
1286 d88_hdr.trkptr[2 * cyl] = d88_hdr.trkptr[2 * cyl + 1] = trkptr;
1288 d88_hdr.trkptr[2 * cyl + side] = trkptr;
1290 for(int s = 0; s < nsec; s++) {
1292 uint8 *sector_info = tmp_buffer + trkofs + 0x18 + s * 8;
1294 size = sector_info[6] + sector_info[7] * 256;
1297 // create d88 sector header
1298 memset(&d88_sct, 0, sizeof(d88_sct_t));
1299 d88_sct.c = sector_info[0];
1300 d88_sct.h = sector_info[1];
1301 d88_sct.r = sector_info[2];
1302 d88_sct.n = sector_info[3];
1303 d88_sct.nsec = nsec;
1305 d88_sct.del = (sector_info[5] == 0xb2) ? 0x10 : 0;
1306 d88_sct.stat = (sector_info[5] == 0xb5) ? 0xb0 : d88_sct.del;
1307 d88_sct.size = size;
1310 COPYBUFFER(&d88_sct, sizeof(d88_sct_t));
1311 COPYBUFFER(tmp_buffer + sctofs, size);
1312 trkptr += sizeof(d88_sct_t) + size;
1318 trkofs += tmp_buffer[trkofs_ptr++] * 256;
1320 trkofs += tmp_buffer[0x32] + tmp_buffer[0x33] * 256;
1324 d88_hdr.type = (total < (368640 + 655360) / 2) ? MEDIA_TYPE_2D : (total < (737280 + 1228800) / 2) ? MEDIA_TYPE_2DD : MEDIA_TYPE_2HD;
1325 d88_hdr.size = trkptr;
1326 memcpy(buffer, &d88_hdr, sizeof(d88_hdr_t));
1330 // standard image decoder
1332 bool DISK::standard_to_d88(int type, int ncyl, int nside, int nsec, int size)
1340 // create d88 header
1341 memset(&d88_hdr, 0, sizeof(d88_hdr_t));
1342 _strcpy_s(d88_hdr.title, sizeof(d88_hdr.title), "STANDARD");
1343 d88_hdr.protect = 0; // non-protected
1344 d88_hdr.type = (type == MEDIA_TYPE_144) ? MEDIA_TYPE_2HD : type;
1346 COPYBUFFER(&d88_hdr, sizeof(d88_hdr_t));
1349 for(int i = 0; i < 8; i++) {
1350 if(size == (128 << i)) {
1357 int trkptr = sizeof(d88_hdr_t);
1358 for(int c = 0; c < ncyl; c++) {
1359 for(int h = 0; h < nside; h++) {
1360 d88_hdr.trkptr[t++] = trkptr;
1363 d88_hdr.trkptr[t++] = trkptr;
1366 // read sectors in this track
1367 for(int s = 0; s < nsec; s++) {
1368 // create d88 sector header
1369 memset(&d88_sct, 0, sizeof(d88_sct_t));
1374 d88_sct.nsec = nsec;
1378 d88_sct.size = size;
1380 // create sector image
1382 memset(dst, 0xe5, sizeof(dst));
1383 fi->Fread(dst, size, 1);
1386 COPYBUFFER(&d88_sct, sizeof(d88_sct_t));
1387 COPYBUFFER(dst, size);
1388 trkptr += sizeof(d88_sct_t) + size;
1392 d88_hdr.size = trkptr;
1393 memcpy(buffer, &d88_hdr, sizeof(d88_hdr_t));
1397 #define STATE_VERSION 3
1399 void DISK::save_state(FILEIO* state_fio)
1401 state_fio->FputUint32(STATE_VERSION);
1403 state_fio->Fwrite(buffer, sizeof(buffer), 1);
1404 state_fio->Fwrite(orig_path, sizeof(orig_path), 1);
1405 state_fio->Fwrite(dest_path, sizeof(dest_path), 1);
1406 state_fio->FputUint32(file_size.d);
1407 state_fio->FputInt32(file_bank);
1408 state_fio->FputUint32(crc32);
1409 state_fio->Fwrite(fdi_header, sizeof(fdi_header), 1);
1410 state_fio->FputBool(inserted);
1411 state_fio->FputBool(ejected);
1412 state_fio->FputBool(write_protected);
1413 state_fio->FputBool(changed);
1414 state_fio->FputUint8(media_type);
1415 state_fio->FputBool(is_standard_image);
1416 state_fio->FputBool(is_fdi_image);
1417 state_fio->FputInt32(is_special_disk);
1418 state_fio->Fwrite(track, sizeof(track), 1);
1419 state_fio->FputInt32(sector_num.sd);
1420 state_fio->FputInt32(data_size_shift);
1421 state_fio->FputBool(too_many_sectors);
1422 state_fio->FputBool(no_skew);
1423 state_fio->Fwrite(sync_position, sizeof(sync_position), 1);
1424 state_fio->Fwrite(id_position, sizeof(id_position), 1);
1425 state_fio->Fwrite(data_position, sizeof(data_position), 1);
1426 state_fio->FputInt32(sector ? (int)(sector - buffer) : -1);
1427 state_fio->FputInt32(sector_size.sd);
1428 state_fio->Fwrite(id, sizeof(id), 1);
1429 state_fio->FputUint8(density);
1430 state_fio->FputBool(deleted);
1431 state_fio->FputBool(crc_error);
1432 state_fio->FputUint8(drive_type);
1433 state_fio->FputInt32(drive_rpm);
1434 state_fio->FputBool(drive_mfm);
1437 bool DISK::load_state(FILEIO* state_fio)
1439 if(state_fio->FgetUint32() != STATE_VERSION) {
1442 state_fio->Fread(buffer, sizeof(buffer), 1);
1443 state_fio->Fread(orig_path, sizeof(orig_path), 1);
1444 state_fio->Fread(dest_path, sizeof(dest_path), 1);
1445 file_size.d = state_fio->FgetUint32();
1446 file_bank = state_fio->FgetInt32();
1447 crc32 = state_fio->FgetUint32();
1448 state_fio->Fread(fdi_header, sizeof(fdi_header), 1);
1449 inserted = state_fio->FgetBool();
1450 ejected = state_fio->FgetBool();
1451 write_protected = state_fio->FgetBool();
1452 changed = state_fio->FgetBool();
1453 media_type = state_fio->FgetUint8();
1454 is_standard_image = state_fio->FgetBool();
1455 is_fdi_image = state_fio->FgetBool();
1456 is_special_disk = state_fio->FgetInt32();
1457 state_fio->Fread(track, sizeof(track), 1);
1458 sector_num.sd = state_fio->FgetInt32();
1459 data_size_shift = state_fio->FgetInt32();
1460 too_many_sectors = state_fio->FgetBool();
1461 no_skew = state_fio->FgetBool();
1462 state_fio->Fread(sync_position, sizeof(sync_position), 1);
1463 state_fio->Fread(id_position, sizeof(id_position), 1);
1464 state_fio->Fread(data_position, sizeof(data_position), 1);
1465 int offset = state_fio->FgetInt32();
1466 sector = (offset != -1) ? buffer + offset : NULL;
1467 sector_size.sd = state_fio->FgetInt32();
1468 state_fio->Fread(id, sizeof(id), 1);
1469 density = state_fio->FgetUint8();
1470 deleted = state_fio->FgetBool();
1471 crc_error = state_fio->FgetBool();
1472 drive_type = state_fio->FgetUint8();
1473 drive_rpm = state_fio->FgetInt32();
1474 drive_mfm = state_fio->FgetBool();