Mercurial > repos > blastem
comparison cdd_mcu.c @ 2076:3f29e2726522
Added basic support for ISO images for games that only have a data track
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 31 Jan 2022 22:07:18 -0800 |
parents | 983f57d08eff |
children | c534a3199020 |
comparison
equal
deleted
inserted
replaced
2075:983f57d08eff | 2076:3f29e2726522 |
---|---|
37 void cdd_mcu_init(cdd_mcu *context, system_media *media) | 37 void cdd_mcu_init(cdd_mcu *context, system_media *media) |
38 { | 38 { |
39 context->next_int_cycle = CYCLE_NEVER; | 39 context->next_int_cycle = CYCLE_NEVER; |
40 context->last_subcode_cycle = CYCLE_NEVER; | 40 context->last_subcode_cycle = CYCLE_NEVER; |
41 context->last_nibble_cycle = CYCLE_NEVER; | 41 context->last_nibble_cycle = CYCLE_NEVER; |
42 context->last_byte_cycle = CYCLE_NEVER; | |
42 context->requested_format = SF_NOTREADY; | 43 context->requested_format = SF_NOTREADY; |
43 context->media = media; | 44 context->media = media; |
44 context->current_status_nibble = -1; | 45 context->current_status_nibble = -1; |
45 context->current_cmd_nibble = -1; | 46 context->current_cmd_nibble = -1; |
47 context->current_sector_byte = -1; | |
46 } | 48 } |
47 | 49 |
48 enum { | 50 enum { |
49 GAO_CDD_CTRL, | 51 GAO_CDD_CTRL, |
50 GAO_CDD_STATUS, | 52 GAO_CDD_STATUS, |
109 { | 111 { |
110 case DS_PLAY: | 112 case DS_PLAY: |
111 handle_seek(context); | 113 handle_seek(context); |
112 if (!context->seeking) { | 114 if (!context->seeking) { |
113 context->head_pba++; | 115 context->head_pba++; |
114 uint32_t lba = context->head_pba - LEADIN_SECTORS; | 116 context->media->seek(context->media, context->head_pba - LEADIN_SECTORS); |
115 for (uint32_t i = 0; i < context->media->num_tracks; i++) | |
116 { | |
117 if (lba < context->media->tracks[i].fake_pregap) { | |
118 context->in_fake_pregap = 1; | |
119 break; | |
120 } | |
121 lba -= context->media->tracks[i].fake_pregap; | |
122 if (lba < context->media->tracks[i].start_lba) { | |
123 context->in_fake_pregap = 1; | |
124 break; | |
125 } | |
126 if (lba < context->media->tracks[i].end_lba) { | |
127 fseek(context->media->f, lba * 2352, SEEK_SET); | |
128 context->in_fake_pregap = 0; | |
129 break; | |
130 } | |
131 } | |
132 } | 117 } |
133 break; | 118 break; |
134 case DS_PAUSE: | 119 case DS_PAUSE: |
135 handle_seek(context); | 120 handle_seek(context); |
136 break; | 121 break; |
521 context->last_nibble_cycle = context->cycle; | 506 context->last_nibble_cycle = context->cycle; |
522 next_cmd_nibble = context->cycle + NIBBLE_CLOCKS; | 507 next_cmd_nibble = context->cycle + NIBBLE_CLOCKS; |
523 } | 508 } |
524 } | 509 } |
525 if (context->cycle >= next_byte) { | 510 if (context->cycle >= next_byte) { |
526 uint8_t byte; | 511 uint8_t byte = context->media->read(context->media, context->current_sector_byte); |
527 if (context->in_fake_pregap) { | |
528 if (!context->current_sector_byte || (context->current_sector_byte >= 16)) { | |
529 byte = 0; | |
530 //TODO: error detection and correction bytes | |
531 } else if (context->current_sector_byte < 12) { | |
532 byte = 0xFF; | |
533 } else if (context->current_sector_byte == 12) { | |
534 uint32_t minute = ((context->head_pba - LEADIN_SECTORS) / 75) / 60; | |
535 byte = (minute % 10) | ((minute / 10 ) << 4); | |
536 } else if (context->current_sector_byte == 13) { | |
537 uint32_t seconds = ((context->head_pba - LEADIN_SECTORS) / 75) % 60; | |
538 byte = (seconds % 10) | ((seconds / 10 ) << 4); | |
539 } else if (context->current_sector_byte == 14) { | |
540 uint32_t frames = (context->head_pba - LEADIN_SECTORS) % 75; | |
541 byte = (frames % 10) | ((frames / 10 ) << 4); | |
542 } else { | |
543 byte = 1; | |
544 } | |
545 } else { | |
546 byte = fgetc(context->media->f); | |
547 } | |
548 lc8951_write_byte(cdc, cd_block_to_mclks(context->cycle), context->current_sector_byte++, byte); | 512 lc8951_write_byte(cdc, cd_block_to_mclks(context->cycle), context->current_sector_byte++, byte); |
549 context->last_byte_cycle = context->cycle; | 513 context->last_byte_cycle = context->cycle; |
550 if (context->current_sector_byte == 2352) { | 514 if (context->current_sector_byte == 2352) { |
551 context->current_sector_byte = -1; | 515 context->current_sector_byte = -1; |
552 next_byte = CYCLE_NEVER; | 516 next_byte = CYCLE_NEVER; |