# HG changeset patch # User Mike Pavone # Date 1392281701 28800 # Node ID aaa77e351c24d2162ccedaab92aed492ad7ddbda # Parent c641006da28e2bfc608824598186c36fe00e3b43 Better emulation of the YM-2612 busy flag diff -r c641006da28e -r aaa77e351c24 ym2612.c --- a/ym2612.c Thu Feb 13 00:10:36 2014 -0800 +++ b/ym2612.c Thu Feb 13 00:55:01 2014 -0800 @@ -21,7 +21,9 @@ #define dfopen(var, fname, mode) #endif -#define BUSY_CYCLES 17 +#define BUSY_CYCLES_ADDRESS 17 +#define BUSY_CYCLES_DATA_LOW 83 +#define BUSY_CYCLES_DATA_HIGH 47 #define OP_UPDATE_PERIOD 144 enum { @@ -505,7 +507,7 @@ } } } - if (context->current_cycle >= context->write_cycle + (BUSY_CYCLES * context->clock_inc / 6)) { + if (context->current_cycle >= context->write_cycle + (context->busy_cycles * context->clock_inc / 6)) { context->status &= 0x7F; context->write_cycle = CYCLE_NEVER; } @@ -517,6 +519,8 @@ //printf("address_write_part1: %X\n", address); context->selected_reg = address; context->selected_part = 0; + context->write_cycle = context->current_cycle; + context->busy_cycles = BUSY_CYCLES_ADDRESS; } void ym_address_write_part2(ym2612_context * context, uint8_t address) @@ -524,6 +528,8 @@ //printf("address_write_part2: %X\n", address); context->selected_reg = address; context->selected_part = 1; + context->write_cycle = context->current_cycle; + context->busy_cycles = BUSY_CYCLES_ADDRESS; } uint8_t fnum_to_keycode[] = { @@ -802,6 +808,7 @@ } context->write_cycle = context->current_cycle; + context->busy_cycles = context->selected_reg < 0xA0 ? BUSY_CYCLES_DATA_LOW : BUSY_CYCLES_DATA_HIGH; context->status |= 0x80; } diff -r c641006da28e -r aaa77e351c24 ym2612.h --- a/ym2612.h Thu Feb 13 00:10:36 2014 -0800 +++ b/ym2612.h Thu Feb 13 00:55:01 2014 -0800 @@ -67,7 +67,9 @@ uint32_t sample_rate; uint32_t sample_limit; uint32_t current_cycle; + //TODO: Condense the next two fields into one uint32_t write_cycle; + uint32_t busy_cycles; ym_operator operators[NUM_OPERATORS]; ym_channel channels[NUM_CHANNELS]; uint16_t timer_a;