Mercurial > repos > blastem
comparison cdd_mcu.c @ 2073:c69e42444f96
Fix some cycle adjustment stuff and an off-by one on hte TOCT response
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 31 Jan 2022 00:01:15 -0800 |
parents | f22e04b69272 |
children | 983f57d08eff |
comparison
equal
deleted
inserted
replaced
2072:cc13c100b027 | 2073:c69e42444f96 |
---|---|
253 break; | 253 break; |
254 case SF_TOCT: | 254 case SF_TOCT: |
255 if (context->toc_valid) { | 255 if (context->toc_valid) { |
256 context->status_buffer.b.toct.first_track_high = 0; | 256 context->status_buffer.b.toct.first_track_high = 0; |
257 context->status_buffer.b.toct.first_track_low = 1; | 257 context->status_buffer.b.toct.first_track_low = 1; |
258 context->status_buffer.b.toct.last_track_high = (context->media->num_tracks + 1) / 10; | 258 context->status_buffer.b.toct.last_track_high = (context->media->num_tracks) / 10; |
259 context->status_buffer.b.toct.last_track_low = (context->media->num_tracks + 1) % 10; | 259 context->status_buffer.b.toct.last_track_low = (context->media->num_tracks) % 10; |
260 context->status_buffer.b.toct.version = 0; | 260 context->status_buffer.b.toct.version = 0; |
261 context->status_buffer.format = SF_TOCT; | 261 context->status_buffer.format = SF_TOCT; |
262 } else { | 262 } else { |
263 context->status_buffer.format = SF_NOTREADY; | 263 context->status_buffer.format = SF_NOTREADY; |
264 } | 264 } |
265 break; | 265 break; |
266 case SF_TOCN: | 266 case SF_TOCN: |
267 if (context->toc_valid) { | 267 if (context->toc_valid) { |
268 if (context->requested_track > context->media->num_tracks) { | |
269 printf("track number %d is bad\n", context->requested_track); | |
270 exit(0); | |
271 } | |
268 uint32_t lba = context->media->tracks[context->requested_track - 1].start_lba; | 272 uint32_t lba = context->media->tracks[context->requested_track - 1].start_lba; |
269 for (uint32_t i = 0; i < context->requested_track; i++) { | 273 for (uint32_t i = 0; i < context->requested_track; i++) { |
270 lba += context->media->tracks[i].fake_pregap; | 274 lba += context->media->tracks[i].fake_pregap; |
271 } | 275 } |
272 lba_to_status(context, lba); | 276 lba_to_status(context, lba); |
405 context->requested_track = context->cmd_buffer.b.format.track_high * 10; | 409 context->requested_track = context->cmd_buffer.b.format.track_high * 10; |
406 context->requested_track += context->cmd_buffer.b.format.track_low; | 410 context->requested_track += context->cmd_buffer.b.format.track_low; |
407 if (!context->media || context->requested_track > context->media->num_tracks) { | 411 if (!context->media || context->requested_track > context->media->num_tracks) { |
408 context->requested_format = SF_ABSOLUTE; | 412 context->requested_format = SF_ABSOLUTE; |
409 context->error_status = DS_CMD_ERROR; | 413 context->error_status = DS_CMD_ERROR; |
414 break; | |
410 } | 415 } |
411 context->status = DS_TOC_READ; | 416 context->status = DS_TOC_READ; |
412 context->seeking = 1; | 417 context->seeking = 1; |
413 context->seek_pba = 0; | 418 context->seek_pba = 0; |
414 context->requested_format = SF_TOCN; | 419 context->requested_format = SF_TOCN; |
579 } | 584 } |
580 | 585 |
581 void cdd_mcu_adjust_cycle(cdd_mcu *context, uint32_t deduction) | 586 void cdd_mcu_adjust_cycle(cdd_mcu *context, uint32_t deduction) |
582 { | 587 { |
583 uint32_t cd_deduction = mclks_to_cd_block(deduction); | 588 uint32_t cd_deduction = mclks_to_cd_block(deduction); |
589 if (context->cycle > cd_deduction) { | |
590 context->cycle -= cd_deduction; | |
591 } else { | |
592 context->cycle = 0; | |
593 } | |
584 if (context->next_int_cycle != CYCLE_NEVER) { | 594 if (context->next_int_cycle != CYCLE_NEVER) { |
585 context->next_int_cycle -= deduction; | 595 context->next_int_cycle -= deduction; |
586 } | 596 } |
587 if (context->last_subcode_cycle != CYCLE_NEVER) { | 597 if (context->last_subcode_cycle != CYCLE_NEVER) { |
588 context->last_subcode_cycle -= cd_deduction; | 598 if (context->last_subcode_cycle > cd_deduction) { |
599 context->last_subcode_cycle -= cd_deduction; | |
600 } else { | |
601 context->last_subcode_cycle = 0; | |
602 } | |
589 } | 603 } |
590 if (context->last_nibble_cycle != CYCLE_NEVER) { | 604 if (context->last_nibble_cycle != CYCLE_NEVER) { |
591 context->last_nibble_cycle -= cd_deduction; | 605 if (context->last_nibble_cycle > cd_deduction) { |
606 context->last_nibble_cycle -= cd_deduction; | |
607 } else { | |
608 context->last_nibble_cycle = 0; | |
609 } | |
592 } | 610 } |
593 if (context->last_byte_cycle != CYCLE_NEVER) { | 611 if (context->last_byte_cycle != CYCLE_NEVER) { |
594 context->last_byte_cycle -= cd_deduction; | 612 if (context->last_byte_cycle > cd_deduction) { |
595 } | 613 context->last_byte_cycle -= cd_deduction; |
596 } | 614 } else { |
615 context->last_byte_cycle = 0; | |
616 } | |
617 } | |
618 } |