Mercurial > repos > blastem
comparison cdd_mcu.c @ 2089:0db3af42dd72
Fix some byte order stuff for audio tracks
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 06 Feb 2022 13:51:49 -0800 |
parents | c9d3b8e1ea56 |
children | c732dcc9c61b |
comparison
equal
deleted
inserted
replaced
2088:c716af3f8980 | 2089:0db3af42dd72 |
---|---|
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 = 0; | 42 context->next_byte_cycle = 0; |
43 context->requested_format = SF_NOTREADY; | 43 context->requested_format = SF_NOTREADY; |
44 context->media = media; | 44 context->media = media; |
45 context->current_status_nibble = -1; | 45 context->current_status_nibble = -1; |
46 context->current_cmd_nibble = -1; | 46 context->current_cmd_nibble = -1; |
47 context->current_sector_byte = -1; | 47 context->current_sector_byte = -1; |
508 } | 508 } |
509 | 509 |
510 void cdd_mcu_run(cdd_mcu *context, uint32_t cycle, uint16_t *gate_array, lc8951* cdc, cdd_fader* fader) | 510 void cdd_mcu_run(cdd_mcu *context, uint32_t cycle, uint16_t *gate_array, lc8951* cdc, cdd_fader* fader) |
511 { | 511 { |
512 uint32_t cd_cycle = mclks_to_cd_block(cycle); | 512 uint32_t cd_cycle = mclks_to_cd_block(cycle); |
513 uint32_t next_byte = context->last_byte_cycle + BYTE_CLOCKS; | |
514 if (!(gate_array[GAO_CDD_CTRL] & BIT_HOCK)) { | 513 if (!(gate_array[GAO_CDD_CTRL] & BIT_HOCK)) { |
515 //it's a little unclear if this gates the actual cd block clock or just handshaking | 514 //it's a little unclear if this gates the actual cd block clock or just handshaking |
516 //assum it's actually the clock for now | 515 //assum it's actually the clock for now |
517 for (; context->cycle < cd_cycle; context->cycle += CDD_MCU_DIVIDER) { | 516 for (; context->cycle < cd_cycle; context->cycle += CDD_MCU_DIVIDER) { |
518 if (context->cycle >= next_byte) { | 517 if (context->cycle >= context->next_byte_cycle) { |
519 cdd_fader_data(fader, 0); | 518 cdd_fader_data(fader, 0); |
520 next_byte = context->cycle + BYTE_CLOCKS; | 519 context->next_byte_cycle += BYTE_CLOCKS; |
521 context->last_byte_cycle = context->cycle; | |
522 } | 520 } |
523 } | 521 } |
524 gate_array[GAO_CDD_CTRL] |= BIT_MUTE; | 522 gate_array[GAO_CDD_CTRL] |= BIT_MUTE; |
525 return; | 523 return; |
526 } | 524 } |
583 context->current_cmd_nibble++; | 581 context->current_cmd_nibble++; |
584 context->last_nibble_cycle = context->cycle; | 582 context->last_nibble_cycle = context->cycle; |
585 next_cmd_nibble = context->cycle + NIBBLE_CLOCKS; | 583 next_cmd_nibble = context->cycle + NIBBLE_CLOCKS; |
586 } | 584 } |
587 } | 585 } |
588 if (context->cycle >= next_byte) { | 586 if (context->cycle >= context->next_byte_cycle) { |
589 if (context->current_sector_byte >= 0) { | 587 if (context->current_sector_byte >= 0) { |
590 uint8_t byte = context->media->read(context->media, context->current_sector_byte); | 588 uint8_t byte = context->media->read(context->media, context->current_sector_byte); |
591 lc8951_write_byte(cdc, cd_block_to_mclks(context->cycle), context->current_sector_byte++, byte); | 589 lc8951_write_byte(cdc, cd_block_to_mclks(context->cycle), context->current_sector_byte++, byte); |
592 cdd_fader_data(fader, gate_array[GAO_CDD_CTRL] & BIT_MUTE ? 0 : byte); | 590 cdd_fader_data(fader, gate_array[GAO_CDD_CTRL] & BIT_MUTE ? 0 : byte); |
593 } else { | 591 } else { |
594 cdd_fader_data(fader, 0); | 592 cdd_fader_data(fader, 0); |
595 } | 593 } |
596 context->last_byte_cycle = context->cycle; | |
597 if (context->current_sector_byte == 2352) { | 594 if (context->current_sector_byte == 2352) { |
598 context->current_sector_byte = -1; | 595 context->current_sector_byte = -1; |
599 } | 596 } |
600 next_byte = context->cycle + BYTE_CLOCKS; | 597 context->next_byte_cycle += BYTE_CLOCKS; |
601 } | 598 } |
602 } | 599 } |
603 } | 600 } |
604 | 601 |
605 void cdd_mcu_start_cmd_recv(cdd_mcu *context, uint16_t *gate_array) | 602 void cdd_mcu_start_cmd_recv(cdd_mcu *context, uint16_t *gate_array) |
652 context->last_nibble_cycle -= cd_deduction; | 649 context->last_nibble_cycle -= cd_deduction; |
653 } else { | 650 } else { |
654 context->last_nibble_cycle = 0; | 651 context->last_nibble_cycle = 0; |
655 } | 652 } |
656 } | 653 } |
657 if (context->last_byte_cycle != CYCLE_NEVER) { | 654 context->next_byte_cycle -= deduction; |
658 if (context->last_byte_cycle > cd_deduction) { | 655 } |
659 context->last_byte_cycle -= cd_deduction; | |
660 } else { | |
661 context->last_byte_cycle = 0; | |
662 } | |
663 } | |
664 } |