# HG changeset patch # User Mike Pavone # Date 1368597135 25200 # Node ID 87b65e5ce1ab8e61f3c0314a4d9d0483c2e1d2c7 # Parent 14a937097c2b8728033d86146d0438555e131fbf Fix a stupid bug in z80 busreq acknowledge delay code and make some small improvements there too diff -r 14a937097c2b -r 87b65e5ce1ab blastem.c --- a/blastem.c Tue May 14 21:59:56 2013 -0700 +++ b/blastem.c Tue May 14 22:52:15 2013 -0700 @@ -381,7 +381,7 @@ uint32_t zram_counter = 0; #define Z80_ACK_DELAY 3 -#define Z80_BUSY_DELAY 2//TODO: Find the actual value for this +#define Z80_BUSY_DELAY 1//TODO: Find the actual value for this #define Z80_REQ_BUSY 1 #define Z80_REQ_ACK 0 #define Z80_RES_BUSACK reset @@ -390,7 +390,7 @@ { genesis_context * gen = context->system; if (location < 0x10000) { - if (busack_cycle > context->current_cycle) { + if (busack_cycle <= context->current_cycle) { busack = new_busack; busack_cycle = CYCLE_NEVER; } @@ -433,16 +433,17 @@ } else { if (location == 0x1100) { sync_z80(gen->z80, context->current_cycle * MCLKS_PER_68K); - if (busack_cycle > context->current_cycle) { + if (busack_cycle <= context->current_cycle) { busack = new_busack; busack_cycle = CYCLE_NEVER; } if (value & 1) { dputs("bus requesting Z80"); - busreq = 1; - if(!reset) { + + if(!reset && !busreq) { busack_cycle = ((gen->z80->current_cycle + Z80_ACK_DELAY) * MCLKS_PER_Z80) / MCLKS_PER_68K;//context->current_cycle + Z80_ACK_DELAY; new_busack = Z80_REQ_ACK; + busreq = 1; } } else { if (busreq) { @@ -454,13 +455,13 @@ fwrite(z80_ram, 1, sizeof(z80_ram), f); fclose(f); #endif - //TODO: Add necessary delay between release of busreq and resumption of execution + busack_cycle = ((gen->z80->current_cycle + Z80_BUSY_DELAY) * MCLKS_PER_Z80) / MCLKS_PER_68K; + new_busack = Z80_REQ_BUSY; + busreq = 0; } - busreq = 0; //busack_cycle = CYCLE_NEVER; //busack = Z80_REQ_BUSY; - busack_cycle = ((gen->z80->current_cycle + Z80_BUSY_DELAY) * MCLKS_PER_Z80) / MCLKS_PER_68K; - new_busack = Z80_REQ_BUSY; + } } else if (location == 0x1200) { sync_z80(gen->z80, context->current_cycle * MCLKS_PER_68K); @@ -489,7 +490,7 @@ { genesis_context * gen = context->system; if (location < 0x10000) { - if (busack_cycle > context->current_cycle) { + if (busack_cycle <= context->current_cycle) { busack = new_busack; busack_cycle = CYCLE_NEVER; } @@ -533,16 +534,17 @@ //printf("IO Write of %X to %X @ %d\n", value, location, context->current_cycle); if (location == 0x1100) { sync_z80(gen->z80, context->current_cycle * MCLKS_PER_68K); - if (busack_cycle > context->current_cycle) { + if (busack_cycle <= context->current_cycle) { busack = new_busack; busack_cycle = CYCLE_NEVER; } if (value & 0x100) { dprintf("bus requesting Z80 @ %d\n", (context->current_cycle * MCLKS_PER_68K) / MCLKS_PER_Z80); - busreq = 1; - if(!reset) { + + if(!reset && !busreq) { busack_cycle = ((gen->z80->current_cycle + Z80_ACK_DELAY) * MCLKS_PER_Z80) / MCLKS_PER_68K;//context->current_cycle + Z80_ACK_DELAY; new_busack = Z80_REQ_ACK; + busreq = 1; } } else { if (busreq) { @@ -554,13 +556,12 @@ fwrite(z80_ram, 1, sizeof(z80_ram), f); fclose(f); #endif - //TODO: Add necessary delay between release of busreq and resumption of execution + busack_cycle = ((gen->z80->current_cycle + Z80_BUSY_DELAY) * MCLKS_PER_Z80) / MCLKS_PER_68K; + new_busack = Z80_REQ_BUSY; + busreq = 0; } - busreq = 0; //busack_cycle = CYCLE_NEVER; //busack = Z80_REQ_BUSY; - busack_cycle = ((gen->z80->current_cycle + Z80_BUSY_DELAY) * MCLKS_PER_Z80) / MCLKS_PER_68K; - new_busack = Z80_REQ_BUSY; } } else if (location == 0x1200) { sync_z80(gen->z80, context->current_cycle * MCLKS_PER_68K); @@ -573,6 +574,7 @@ if (reset) { need_reset = 1; //TODO: Add necessary delay between release of reset and start of execution + gen->z80->current_cycle = (context->current_cycle * MCLKS_PER_68K) / MCLKS_PER_Z80; } reset = 0; } else { @@ -594,7 +596,7 @@ { genesis_context *gen = context->system; if (location < 0x10000) { - if (busack_cycle > context->current_cycle) { + if (busack_cycle <= context->current_cycle) { busack = new_busack; busack_cycle = CYCLE_NEVER; } @@ -638,12 +640,12 @@ } } else { if (location == 0x1100) { - if (busack_cycle > context->current_cycle) { + if (busack_cycle <= context->current_cycle) { busack = new_busack; busack_cycle = CYCLE_NEVER; } context->value = Z80_RES_BUSACK || busack; - //printf("Byte read of BUSREQ returned %d @ %d (reset: %d, busack: %d)\n", context->value, context->current_cycle, reset, busack); + dprintf("Byte read of BUSREQ returned %d @ %d (reset: %d, busack: %d, busack_cycle %d)\n", context->value, context->current_cycle, reset, busack, busack_cycle); } else if (location == 0x1200) { context->value = !reset; } else { @@ -658,7 +660,7 @@ { genesis_context * gen = context->system; if (location < 0x10000) { - if (busack_cycle > context->current_cycle) { + if (busack_cycle <= context->current_cycle) { busack = new_busack; busack_cycle = CYCLE_NEVER; } @@ -710,7 +712,7 @@ //printf("Word read to %X returned %d\n", location, context->value); } else { if (location == 0x1100) { - if (busack_cycle > context->current_cycle) { + if (busack_cycle <= context->current_cycle) { busack = new_busack; busack_cycle = CYCLE_NEVER; }