# HG changeset patch # User Michael Pavone # Date 1643616075 28800 # Node ID c69e42444f969615ea6a09ced804e196ffef1b26 # Parent cc13c100b02741376422b8fb318f655fcb8dcc19 Fix some cycle adjustment stuff and an off-by one on hte TOCT response diff -r cc13c100b027 -r c69e42444f96 cdd_mcu.c --- a/cdd_mcu.c Sun Jan 30 22:29:29 2022 -0800 +++ b/cdd_mcu.c Mon Jan 31 00:01:15 2022 -0800 @@ -255,8 +255,8 @@ if (context->toc_valid) { context->status_buffer.b.toct.first_track_high = 0; context->status_buffer.b.toct.first_track_low = 1; - context->status_buffer.b.toct.last_track_high = (context->media->num_tracks + 1) / 10; - context->status_buffer.b.toct.last_track_low = (context->media->num_tracks + 1) % 10; + context->status_buffer.b.toct.last_track_high = (context->media->num_tracks) / 10; + context->status_buffer.b.toct.last_track_low = (context->media->num_tracks) % 10; context->status_buffer.b.toct.version = 0; context->status_buffer.format = SF_TOCT; } else { @@ -265,6 +265,10 @@ break; case SF_TOCN: if (context->toc_valid) { + if (context->requested_track > context->media->num_tracks) { + printf("track number %d is bad\n", context->requested_track); + exit(0); + } uint32_t lba = context->media->tracks[context->requested_track - 1].start_lba; for (uint32_t i = 0; i < context->requested_track; i++) { lba += context->media->tracks[i].fake_pregap; @@ -407,6 +411,7 @@ if (!context->media || context->requested_track > context->media->num_tracks) { context->requested_format = SF_ABSOLUTE; context->error_status = DS_CMD_ERROR; + break; } context->status = DS_TOC_READ; context->seeking = 1; @@ -581,16 +586,33 @@ void cdd_mcu_adjust_cycle(cdd_mcu *context, uint32_t deduction) { uint32_t cd_deduction = mclks_to_cd_block(deduction); + if (context->cycle > cd_deduction) { + context->cycle -= cd_deduction; + } else { + context->cycle = 0; + } if (context->next_int_cycle != CYCLE_NEVER) { context->next_int_cycle -= deduction; } if (context->last_subcode_cycle != CYCLE_NEVER) { - context->last_subcode_cycle -= cd_deduction; + if (context->last_subcode_cycle > cd_deduction) { + context->last_subcode_cycle -= cd_deduction; + } else { + context->last_subcode_cycle = 0; + } } if (context->last_nibble_cycle != CYCLE_NEVER) { - context->last_nibble_cycle -= cd_deduction; + if (context->last_nibble_cycle > cd_deduction) { + context->last_nibble_cycle -= cd_deduction; + } else { + context->last_nibble_cycle = 0; + } } if (context->last_byte_cycle != CYCLE_NEVER) { - context->last_byte_cycle -= cd_deduction; + if (context->last_byte_cycle > cd_deduction) { + context->last_byte_cycle -= cd_deduction; + } else { + context->last_byte_cycle = 0; + } } } diff -r cc13c100b027 -r c69e42444f96 lc8951.c --- a/lc8951.c Sun Jan 30 22:29:29 2022 -0800 +++ b/lc8951.c Mon Jan 31 00:01:15 2022 -0800 @@ -317,10 +317,13 @@ void lc8951_adjust_cycles(lc8951 *context, uint32_t deduction) { + printf("CDC deduction of %u cycles @ %u, ", deduction, context->cycle); + context->cycle -= deduction; if (context->decode_end != CYCLE_NEVER) { context->decode_end -= deduction; } if (context->transfer_end != CYCLE_NEVER) { context->transfer_end -= deduction; } + printf("cycle is now %u, decode_end %u, transfer_end %u\n", context->cycle, context->decode_end, context->transfer_end); } diff -r cc13c100b027 -r c69e42444f96 segacd.c --- a/segacd.c Sun Jan 30 22:29:29 2022 -0800 +++ b/segacd.c Mon Jan 31 00:01:15 2022 -0800 @@ -597,9 +597,9 @@ case GA_CDD_CTRL: { cdd_run(cd, m68k->current_cycle); uint16_t changed = cd->gate_array[reg] ^ value; - cd->gate_array[reg] &= ~BIT_HOCK; - cd->gate_array[reg] |= value & BIT_HOCK; if (changed & BIT_HOCK) { + cd->gate_array[reg] &= ~BIT_HOCK; + cd->gate_array[reg] |= value & BIT_HOCK; if (value & BIT_HOCK) { cdd_hock_enabled(&cd->cdd); } else { @@ -928,11 +928,6 @@ return 0xFFFF; default: if (offset < GA_TIMER) { - if (offset == GA_CDC_CTRL) { - printf("CDC read(main): %X - %X @ %u (%u)\n", address, cd->gate_array[offset], m68k->current_cycle, scd_cycle); - } else if (offset >= GA_COMM_FLAG && offset <= GA_COMM_STATUS7) { - printf("COMM read(main): %X - %X @ %u (%u)\n", address, cd->gate_array[offset], m68k->current_cycle, scd_cycle); - } return cd->gate_array[offset]; } //TODO: open bus maybe? @@ -1049,7 +1044,6 @@ //Main CPU can only write the upper byte; cd->gate_array[reg] &= 0xFF; cd->gate_array[reg] |= value & 0xFF00; - printf("COMM write(main): %X - %X @ %u (%u)\n", address, value, m68k->current_cycle, scd_cycle); break; case GA_COMM_CMD0: case GA_COMM_CMD1: @@ -1060,7 +1054,6 @@ case GA_COMM_CMD6: case GA_COMM_CMD7: //no effects for these other than saving the value - printf("COMM write(main): %X - %X @ %u (%u)\n", address, value, m68k->current_cycle, scd_cycle); cd->gate_array[reg] = value; break; default: