src/mess/devices/ti99_hd.c
| r9487 | r9488 | |
| 31 | 31 | #if 0 |
| 32 | 32 | static void dump_contents(UINT8 *buffer, int length) |
| 33 | 33 | { |
| 34 | | for (int i=0; i < length; i+=16) |
| 35 | | { |
| 36 | | for (int j=0; j < 16; j+=2) |
| 37 | | { |
| 38 | | printf("%02x%02x ", buffer[i+j], buffer[i+j+1]); |
| 39 | | } |
| 40 | | printf("\n"); |
| 41 | | } |
| 34 | for (int i=0; i < length; i+=16) |
| 35 | { |
| 36 | for (int j=0; j < 16; j+=2) |
| 37 | { |
| 38 | printf("%02x%02x ", buffer[i+j], buffer[i+j+1]); |
| 39 | } |
| 40 | printf("\n"); |
| 41 | } |
| 42 | 42 | } |
| 43 | 43 | #endif |
| 44 | 44 | |
| r9487 | r9488 | |
| 54 | 54 | info = hard_disk_get_info(hdfile); |
| 55 | 55 | |
| 56 | 56 | if ( (cylinder >= info->cylinders) || |
| 57 | | (head >= info->heads) || |
| 58 | | (sector >= info->sectors)) |
| 59 | | return FALSE; |
| 57 | (head >= info->heads) || |
| 58 | (sector >= info->sectors)) |
| 59 | return FALSE; |
| 60 | 60 | |
| 61 | 61 | *lba = (cylinder * info->heads + head) |
| 62 | | * info->sectors |
| 63 | | + sector; |
| 62 | * info->sectors |
| 63 | + sector; |
| 64 | 64 | return TRUE; |
| 65 | 65 | } |
| 66 | 66 | return FALSE; |
| r9487 | r9488 | |
| 69 | 69 | /* Accessor functions */ |
| 70 | 70 | void ti99_mfm_harddisk_read_sector(running_device *harddisk, int cylinder, int head, int sector, UINT8 **buf, int *sector_length) |
| 71 | 71 | { |
| 72 | | UINT32 lba; |
| 72 | UINT32 lba; |
| 73 | 73 | mfmhd_state *hd = (mfmhd_state *)downcast<legacy_device_base *>(harddisk)->token(); |
| 74 | 74 | running_device *drive = harddisk->subdevice("drive"); |
| 75 | | hard_disk_file *file = mess_hd_get_hard_disk_file(drive); |
| 75 | hard_disk_file *file = mess_hd_get_hard_disk_file(drive); |
| 76 | 76 | |
| 77 | | *sector_length = 256; |
| 78 | | *buf = (UINT8 *)malloc(*sector_length); |
| 77 | *sector_length = 256; |
| 78 | *buf = (UINT8 *)malloc(*sector_length); |
| 79 | 79 | |
| 80 | 80 | if (cylinder != hd->current_cylinder) |
| 81 | 81 | { |
| 82 | 82 | return; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | | if (file==NULL) |
| 86 | | { |
| 87 | | hd->status &= ~MFMHD_READY; |
| 88 | | return; |
| 89 | | } |
| 85 | if (file==NULL) |
| 86 | { |
| 87 | hd->status &= ~MFMHD_READY; |
| 88 | return; |
| 89 | } |
| 90 | 90 | |
| 91 | | if (!harddisk_chs_to_lba(file, cylinder, head, sector, &lba)) |
| 92 | | { |
| 93 | | hd->status &= ~MFMHD_READY; |
| 94 | | return; |
| 95 | | } |
| 91 | if (!harddisk_chs_to_lba(file, cylinder, head, sector, &lba)) |
| 92 | { |
| 93 | hd->status &= ~MFMHD_READY; |
| 94 | return; |
| 95 | } |
| 96 | 96 | |
| 97 | | if (!hard_disk_read(file, lba, *buf)) |
| 98 | | { |
| 99 | | hd->status &= ~MFMHD_READY; |
| 100 | | return; |
| 101 | | } |
| 102 | | /* printf("ti99_hd read sector c=%04d h=%02d s=%02d\n", cylinder, head, sector); */ |
| 103 | | hd->status |= MFMHD_READY; |
| 97 | if (!hard_disk_read(file, lba, *buf)) |
| 98 | { |
| 99 | hd->status &= ~MFMHD_READY; |
| 100 | return; |
| 101 | } |
| 102 | /* printf("ti99_hd read sector c=%04d h=%02d s=%02d\n", cylinder, head, sector); */ |
| 103 | hd->status |= MFMHD_READY; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | void ti99_mfm_harddisk_write_sector(running_device *harddisk, int cylinder, int head, int sector, UINT8 *buf, int sector_length) |
| 107 | 107 | { |
| 108 | | UINT32 lba; |
| 108 | UINT32 lba; |
| 109 | 109 | mfmhd_state *hd = (mfmhd_state *)downcast<legacy_device_base *>(harddisk)->token(); |
| 110 | 110 | running_device *drive = harddisk->subdevice("drive"); |
| 111 | | hard_disk_file *file = mess_hd_get_hard_disk_file(drive); |
| 111 | hard_disk_file *file = mess_hd_get_hard_disk_file(drive); |
| 112 | 112 | |
| 113 | | if (file==NULL) |
| 114 | | { |
| 115 | | hd->status &= ~MFMHD_READY; |
| 116 | | return; |
| 117 | | } |
| 113 | if (file==NULL) |
| 114 | { |
| 115 | hd->status &= ~MFMHD_READY; |
| 116 | return; |
| 117 | } |
| 118 | 118 | |
| 119 | | if (!harddisk_chs_to_lba(file, cylinder, head, sector, &lba)) |
| 120 | | { |
| 121 | | hd->status &= ~MFMHD_READY; |
| 122 | | hd->status |= MFMHD_WRFAULT; |
| 123 | | return; |
| 124 | | } |
| 119 | if (!harddisk_chs_to_lba(file, cylinder, head, sector, &lba)) |
| 120 | { |
| 121 | hd->status &= ~MFMHD_READY; |
| 122 | hd->status |= MFMHD_WRFAULT; |
| 123 | return; |
| 124 | } |
| 125 | 125 | |
| 126 | | if (!hard_disk_write(file, lba, buf)) |
| 126 | if (!hard_disk_write(file, lba, buf)) |
| 127 | 127 | { |
| 128 | | hd->status &= ~MFMHD_READY; |
| 129 | | hd->status |= MFMHD_WRFAULT; |
| 128 | hd->status &= ~MFMHD_READY; |
| 129 | hd->status |= MFMHD_WRFAULT; |
| 130 | 130 | return; |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | | hd->status |= MFMHD_READY; |
| 133 | hd->status |= MFMHD_READY; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | #define TI99HD_BLOCKNOTFOUND -1 |
| r9487 | r9488 | |
| 176 | 176 | |
| 177 | 177 | /* We assume an interleave of 3 for 32 sectors. */ |
| 178 | 178 | int step = 3; |
| 179 | | UINT32 lba; |
| 180 | | int i; |
| 179 | UINT32 lba; |
| 180 | int i; |
| 181 | 181 | |
| 182 | | int gap1 = 16; |
| 183 | | int gap2 = 8; |
| 184 | | int gap3 = 15; |
| 185 | | int gap4 = 340; |
| 186 | | int sync = 13; |
| 187 | | int count; |
| 188 | | int size; |
| 189 | | int position = 0; |
| 190 | | int sector; |
| 191 | | int crc; |
| 182 | int gap1 = 16; |
| 183 | int gap2 = 8; |
| 184 | int gap3 = 15; |
| 185 | int gap4 = 340; |
| 186 | int sync = 13; |
| 187 | int count; |
| 188 | int size; |
| 189 | int position = 0; |
| 190 | int sector; |
| 191 | int crc; |
| 192 | 192 | |
| 193 | 193 | const hard_disk_info *info; |
| 194 | | hard_disk_file *file = mess_hd_get_hard_disk_file(drive); |
| 194 | hard_disk_file *file = mess_hd_get_hard_disk_file(drive); |
| 195 | 195 | |
| 196 | 196 | if (file==NULL) |
| 197 | 197 | { |
| r9487 | r9488 | |
| 201 | 201 | |
| 202 | 202 | info = hard_disk_get_info(file); |
| 203 | 203 | |
| 204 | | count = info->sectors; |
| 205 | | size = info->sectorbytes/128; |
| 204 | count = info->sectors; |
| 205 | size = info->sectorbytes/128; |
| 206 | 206 | |
| 207 | 207 | *data_count = gap1 + count*(sync+12+gap2+sync+size*128+gap3)+gap4; |
| 208 | 208 | |
| r9487 | r9488 | |
| 284 | 284 | |
| 285 | 285 | *pbuffer = trackdata; |
| 286 | 286 | |
| 287 | | /* Remember to free the buffer! Except when an error has occured, |
| 288 | | the function returns a newly allocated buffer. |
| 289 | | Errors are indicated by READY=FALSE. */ |
| 287 | // Remember to free the buffer! Except when an error has occured, |
| 288 | // the function returns a newly allocated buffer. |
| 289 | // Errors are indicated by READY=FALSE. |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | /* |
| r9487 | r9488 | |
| 320 | 320 | |
| 321 | 321 | current_pos = find_block(track_image, 0, 100, 0x4e, gap1); |
| 322 | 322 | |
| 323 | | /* In case of defect formats, we continue as far as possible. This |
| 324 | | may lead to sectors not being written. */ |
| 323 | // In case of defect formats, we continue as far as possible. This |
| 324 | // may lead to sectors not being written. */ |
| 325 | 325 | if (current_pos==TI99HD_BLOCKNOTFOUND) |
| 326 | 326 | { |
| 327 | 327 | logerror("ti99_hd error: write track: Cannot find gap1 for cylinder %d, head %d.\n", hd->current_cylinder, head); |
| r9487 | r9488 | |
| 411 | 411 | running_device *drive; |
| 412 | 412 | mfmhd_state *hd = (mfmhd_state *)downcast<legacy_device_base *>(harddisk)->token(); |
| 413 | 413 | drive = harddisk->subdevice("drive"); |
| 414 | | hard_disk_file *file = mess_hd_get_hard_disk_file(drive); |
| 414 | hard_disk_file *file = mess_hd_get_hard_disk_file(drive); |
| 415 | 415 | |
| 416 | 416 | if (file!=NULL) |
| 417 | 417 | status |= MFMHD_READY; |
| r9487 | r9488 | |
| 434 | 434 | running_device *drive = harddisk->subdevice("drive"); |
| 435 | 435 | mfmhd_state *hd = (mfmhd_state *)downcast<legacy_device_base *>(harddisk)->token(); |
| 436 | 436 | const hard_disk_info *info; |
| 437 | | hard_disk_file *file = mess_hd_get_hard_disk_file(drive); |
| 437 | hard_disk_file *file = mess_hd_get_hard_disk_file(drive); |
| 438 | 438 | |
| 439 | 439 | if (file==NULL) return; |
| 440 | 440 | |
| r9487 | r9488 | |
| 461 | 461 | running_device *drive = harddisk->subdevice("drive"); |
| 462 | 462 | mfmhd_state *hd = (mfmhd_state *)downcast<legacy_device_base *>(harddisk)->token(); |
| 463 | 463 | const hard_disk_info *info; |
| 464 | | hard_disk_file *file; |
| 464 | hard_disk_file *file; |
| 465 | 465 | int interleave = 3; |
| 466 | 466 | |
| 467 | 467 | file = mess_hd_get_hard_disk_file(drive); |
| 468 | 468 | if (file==NULL) |
| 469 | 469 | { |
| 470 | | hd->status &= ~MFMHD_READY; |
| 470 | hd->status &= ~MFMHD_READY; |
| 471 | 471 | return; |
| 472 | 472 | } |
| 473 | 473 | |
| r9487 | r9488 | |
| 497 | 497 | |
| 498 | 498 | |
| 499 | 499 | MACHINE_CONFIG_FRAGMENT( mfmhd ) |
| 500 | | MDRV_DEVICE_ADD( "drive", HARDDISK, 0 ) |
| 500 | MDRV_DEVICE_ADD( "drive", HARDDISK, 0 ) |
| 501 | 501 | MACHINE_CONFIG_END |
| 502 | 502 | |
| 503 | 503 | MACHINE_CONFIG_FRAGMENT( idehd ) |
| 504 | | MDRV_DEVICE_ADD( "drive", IDE_HARDDISK, 0 ) |
| 504 | MDRV_DEVICE_ADD( "drive", IDE_HARDDISK, 0 ) |
| 505 | 505 | MACHINE_CONFIG_END |
| 506 | 506 | |
| 507 | 507 | static const char DEVTEMPLATE_SOURCE[] = __FILE__; |