changeset 535:aaa77e351c24

Better emulation of the YM-2612 busy flag
author Mike Pavone <pavone@retrodev.com>
date Thu, 13 Feb 2014 00:55:01 -0800
parents c641006da28e
children 69cfdc81a87c
files ym2612.c ym2612.h
diffstat 2 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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;
 }
 
--- 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;