summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2015-01-04 23:05:37 -0800
committerMichael Pavone <pavone@retrodev.com>2015-01-04 23:05:37 -0800
commitd8bb1db03b5f3c3beb86dce633f89872d05318a5 (patch)
treea67dea583909060b8cd0f1597432a524703b33f1
parent52fb42428540e149d7ae6b53bdb52603b8e1947f (diff)
Some small synchronization improvements that do not seem to fix anything
-rw-r--r--blastem.c76
-rw-r--r--vdp.c17
-rw-r--r--vdp.h1
3 files changed, 55 insertions, 39 deletions
diff --git a/blastem.c b/blastem.c
index 21e59ab..bbb9c51 100644
--- a/blastem.c
+++ b/blastem.c
@@ -210,41 +210,45 @@ m68k_context * sync_components(m68k_context * context, uint32_t address)
z80_context * z_context = gen->z80;
uint32_t mclks = context->current_cycle;
sync_z80(z_context, mclks);
+ sync_sound(gen, mclks);
if (mclks >= mclk_target) {
- sync_sound(gen, mclks);
- gen->ym->current_cycle -= mclk_target;
- gen->psg->cycles -= mclk_target;
- if (gen->ym->write_cycle != CYCLE_NEVER) {
- gen->ym->write_cycle = gen->ym->write_cycle >= mclk_target ? gen->ym->write_cycle - mclk_target : 0;
- }
vdp_run_context(v_context, mclk_target);
- //printf("reached frame end | MCLK Cycles: %d, Target: %d, VDP cycles: %d\n", mclks, mclk_target, v_context->cycles);
-
- if (!headless) {
- break_on_sync |= wait_render_frame(v_context, frame_limit);
- } else if(exit_after){
- --exit_after;
- if (!exit_after) {
- exit(0);
+ if (vdp_is_frame_over(v_context)) {
+ //printf("reached frame end | MCLK Cycles: %d, Target: %d, VDP cycles: %d\n", mclks, mclk_target, v_context->cycles);
+
+ if (!headless) {
+ break_on_sync |= wait_render_frame(v_context, frame_limit);
+ } else if(exit_after){
+ --exit_after;
+ if (!exit_after) {
+ exit(0);
+ }
}
- }
- frame++;
- mclks -= mclk_target;
- vdp_adjust_cycles(v_context, mclk_target);
- io_adjust_cycles(gen->ports, context->current_cycle, mclk_target);
- io_adjust_cycles(gen->ports+1, context->current_cycle, mclk_target);
- io_adjust_cycles(gen->ports+2, context->current_cycle, mclk_target);
- context->current_cycle -= mclk_target;
- z80_adjust_cycles(z_context, mclk_target);
- if (mclks) {
+ frame++;
+ mclks -= mclk_target;
+ vdp_adjust_cycles(v_context, mclk_target);
+ io_adjust_cycles(gen->ports, context->current_cycle, mclk_target);
+ io_adjust_cycles(gen->ports+1, context->current_cycle, mclk_target);
+ io_adjust_cycles(gen->ports+2, context->current_cycle, mclk_target);
+ context->current_cycle -= mclk_target;
+ z80_adjust_cycles(z_context, mclk_target);
+ gen->ym->current_cycle -= mclk_target;
+ gen->psg->cycles -= mclk_target;
+ if (gen->ym->write_cycle != CYCLE_NEVER) {
+ gen->ym->write_cycle = gen->ym->write_cycle >= mclk_target ? gen->ym->write_cycle - mclk_target : 0;
+ }
+ if (mclks) {
+ vdp_run_context(v_context, mclks);
+ }
+ mclk_target = vdp_cycles_to_frame_end(v_context);
+ context->sync_cycle = mclk_target;
+ } else {
vdp_run_context(v_context, mclks);
+ mclk_target = vdp_cycles_to_frame_end(v_context);
}
- mclk_target = vdp_cycles_to_frame_end(v_context);
- context->sync_cycle = mclk_target;
} else {
//printf("running VDP for %d cycles\n", mclks - v_context->cycles);
vdp_run_context(v_context, mclks);
- sync_sound(gen, mclks);
}
if (context->int_ack) {
vdp_int_ack(v_context, context->int_ack);
@@ -284,7 +288,6 @@ m68k_context * vdp_port_write(uint32_t vdp_port, m68k_context * context, uint16_
int blocked;
uint32_t before_cycle = v_context->cycles;
if (vdp_port < 4) {
- gen->bus_busy = 1;
while (vdp_data_port_write(v_context, value) < 0) {
while(v_context->flags & FLAG_DMA_RUN) {
vdp_run_dma_done(v_context, mclk_target);
@@ -296,7 +299,6 @@ m68k_context * vdp_port_write(uint32_t vdp_port, m68k_context * context, uint16_
//context->current_cycle = v_context->cycles;
}
} else if(vdp_port < 8) {
- gen->bus_busy = 1;
blocked = vdp_control_port_write(v_context, value);
if (blocked) {
while (blocked) {
@@ -323,19 +325,16 @@ m68k_context * vdp_port_write(uint32_t vdp_port, m68k_context * context, uint16_
if (v_context->cycles != before_cycle) {
//printf("68K paused for %d (%d) cycles at cycle %d (%d) for write\n", v_context->cycles - context->current_cycle, v_context->cycles - before_cycle, context->current_cycle, before_cycle);
context->current_cycle = v_context->cycles;
+ //Lock the Z80 out of the bus until the VDP access is complete
+ gen->bus_busy = 1;
+ sync_z80(gen->z80, v_context->cycles);
+ gen->bus_busy = 0;
}
} else if (vdp_port < 0x18) {
- sync_sound(gen, context->current_cycle);
psg_write(gen->psg, value);
} else {
//TODO: Implement undocumented test register(s)
}
- if (gen->bus_busy)
- {
- //Lock the Z80 out of the bus until the VDP access is complete
- sync_z80(gen->z80, v_context->cycles);
- gen->bus_busy = 0;
- }
return context;
}
@@ -402,6 +401,11 @@ uint16_t vdp_port_read(uint32_t vdp_port, m68k_context * context)
if (v_context->cycles != before_cycle) {
//printf("68K paused for %d (%d) cycles at cycle %d (%d) for read\n", v_context->cycles - context->current_cycle, v_context->cycles - before_cycle, context->current_cycle, before_cycle);
context->current_cycle = v_context->cycles;
+ //Lock the Z80 out of the bus until the VDP access is complete
+ genesis_context *gen = context->system;
+ gen->bus_busy = 1;
+ sync_z80(gen->z80, v_context->cycles);
+ gen->bus_busy = 0;
}
return value;
}
diff --git a/vdp.c b/vdp.c
index d6dc899..710d2ab 100644
--- a/vdp.c
+++ b/vdp.c
@@ -1627,7 +1627,7 @@ int vdp_control_port_write(vdp_context * context, uint16_t value)
if (!context->double_res) {
context->framebuf = context->oddbuf;
}
- }
+ }
context->cd &= 0x3C;
}
} else {
@@ -1892,7 +1892,7 @@ uint32_t vdp_cycles_to_line(vdp_context * context, uint32_t target)
return MCLKS_LINE * (lines - 1) + vdp_cycles_next_line(context);
}
-uint32_t vdp_cycles_to_frame_end(vdp_context * context)
+uint32_t vdp_frame_end_line(vdp_context * context)
{
uint32_t frame_end;
if (context->flags2 & FLAG2_REGION_PAL) {
@@ -1908,7 +1908,18 @@ uint32_t vdp_cycles_to_frame_end(vdp_context * context)
frame_end = NTSC_INACTIVE_START + 8;
}
}
- return context->cycles + vdp_cycles_to_line(context, frame_end);
+ return frame_end;
+}
+
+uint32_t vdp_cycles_to_frame_end(vdp_context * context)
+{
+ return context->cycles + vdp_cycles_to_line(context, vdp_frame_end_line(context));
+}
+
+uint8_t vdp_is_frame_over(vdp_context * context)
+{
+ uint32_t frame_end = vdp_frame_end_line(context);
+ return context->vcounter >= frame_end && context->vcounter < (frame_end + 8);
}
uint32_t vdp_next_hint(vdp_context * context)
diff --git a/vdp.h b/vdp.h
index 184521a..70c0953 100644
--- a/vdp.h
+++ b/vdp.h
@@ -194,6 +194,7 @@ void vdp_print_sprite_table(vdp_context * context);
void vdp_print_reg_explain(vdp_context * context);
void latch_mode(vdp_context * context);
uint32_t vdp_cycles_to_frame_end(vdp_context * context);
+uint8_t vdp_is_frame_over(vdp_context * context);
extern int32_t color_map[1 << 12];