summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile3
-rw-r--r--test_int_timing.c87
-rw-r--r--vdp.c13
3 files changed, 97 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index 69923ff..14498c7 100644
--- a/Makefile
+++ b/Makefile
@@ -209,6 +209,9 @@ test_x86 : test_x86.o gen_x86.o gen.o
test_arm : test_arm.o gen_arm.o mem.o gen.o
$(CC) -o test_arm test_arm.o gen_arm.o mem.o gen.o
+
+test_int_timing : test_int_timing.o vdp.o
+ $(CC) -o $@ $^
gen_fib : gen_fib.o gen_x86.o mem.o
$(CC) -o gen_fib gen_fib.o gen_x86.o mem.o
diff --git a/test_int_timing.c b/test_int_timing.c
new file mode 100644
index 0000000..74eed05
--- /dev/null
+++ b/test_int_timing.c
@@ -0,0 +1,87 @@
+/*
+ Copyright 2017 Michael Pavone
+ This file is part of BlastEm.
+ BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text.
+*/
+#include <stdio.h>
+#include "vdp.h"
+
+int headless = 1;
+
+uint32_t render_map_color(uint8_t r, uint8_t g, uint8_t b)
+{
+ return 0;
+}
+
+uint16_t read_dma_value(uint32_t address)
+{
+ return 0;
+}
+
+
+int main(int argc, char **argv)
+{
+ vdp_context context;
+ int ret = 0;
+ init_vdp_context(&context, 0);
+ vdp_control_port_write(&context, 0x8000 | BIT_PAL_SEL);
+ vdp_control_port_write(&context, 0x8100 | BIT_DISP_EN | BIT_VINT_EN | BIT_MODE_5);
+ puts("Testing H32 Mode");
+ while (!(context.flags2 & FLAG2_VINT_PENDING))
+ {
+ vdp_run_context(&context, context.cycles + 1);
+ }
+ vdp_int_ack(&context);
+ uint32_t vint_cycle = vdp_next_vint(&context);
+ while (!(context.flags2 & FLAG2_VINT_PENDING))
+ {
+ vdp_run_context(&context, context.cycles + 1);
+ uint32_t vint_cycle2 = vdp_next_vint(&context);
+ if (vint_cycle2 != vint_cycle) {
+ printf("VINT Cycle changed from %d to %d @ line %d, slot %d\n", vint_cycle, vint_cycle2, context.vcounter, context.hslot);;
+ ret = 1;
+ vint_cycle = vint_cycle2;
+ }
+ }
+ vdp_int_ack(&context);
+ puts("Testing H40 Mode");
+ vdp_control_port_write(&context, 0x8C81);
+ while (!(context.flags2 & FLAG2_VINT_PENDING))
+ {
+ vdp_run_context(&context, context.cycles + 1);
+ }
+ vdp_int_ack(&context);
+ vint_cycle = vdp_next_vint(&context);
+ while (!(context.flags2 & FLAG2_VINT_PENDING))
+ {
+ vdp_run_context(&context, context.cycles + 1);
+ uint32_t vint_cycle2 = vdp_next_vint(&context);
+ if (vint_cycle2 != vint_cycle) {
+ printf("VINT Cycle changed from %d to %d @ line %d, slot %d\n", vint_cycle, vint_cycle2, context.vcounter, context.hslot);;
+ ret = 1;
+ vint_cycle = vint_cycle2;
+ }
+ }
+ vdp_int_ack(&context);
+ puts("Testing Mode 4");
+ vdp_control_port_write(&context, 0x8C00);
+ vdp_control_port_write(&context, 0x8100 | BIT_DISP_EN | BIT_VINT_EN);
+ while (!(context.flags2 & FLAG2_VINT_PENDING))
+ {
+ vdp_run_context(&context, context.cycles + 1);
+ }
+ context.flags2 &= ~FLAG2_VINT_PENDING;
+ vint_cycle = vdp_next_vint(&context);
+ while (!(context.flags2 & FLAG2_VINT_PENDING))
+ {
+ vdp_run_context(&context, context.cycles + 1);
+ uint32_t vint_cycle2 = vdp_next_vint(&context);
+ if (vint_cycle2 != vint_cycle) {
+ printf("VINT Cycle changed from %d to %d @ line %d, slot %d\n", vint_cycle, vint_cycle2, context.vcounter, context.hslot);;
+ ret = 1;
+ vint_cycle = vint_cycle2;
+ }
+ }
+ printf("Result: %s\n", ret ? "failure" : "success");
+ return ret;
+} \ No newline at end of file
diff --git a/vdp.c b/vdp.c
index 787027f..20a4f4d 100644
--- a/vdp.c
+++ b/vdp.c
@@ -54,6 +54,7 @@
#define BORDER_BOT_V30_PAL 24
#define INVALID_LINE 0x200
+#define TIMING_DEBUG
static int32_t color_map[1 << 12];
static uint16_t mode4_address_map[0x4000];
@@ -2760,18 +2761,18 @@ uint32_t vdp_next_vint_z80(vdp_context * context)
if (context->regs[REG_MODE_4] & BIT_H40) {
if (context->hslot >= LINE_CHANGE_H40 && context->hslot <= VINT_SLOT_H40) {
uint32_t cycles = context->cycles;
- if (context->hslot < 182) {
- cycles += (182 - context->hslot) * MCLKS_SLOT_H40;
+ if (context->hslot < 183) {
+ cycles += (183 - context->hslot) * MCLKS_SLOT_H40;
}
- if (context->hslot < 229) {
- cycles += h40_hsync_cycles[0];
+ if (context->hslot < HSYNC_SLOT_H40) {
+ cycles += (HSYNC_SLOT_H40 - (context->hslot >= 229 ? context->hslot : 229)) * MCLKS_SLOT_H40;
}
- for (int slot = context->hslot <= 229 ? 229 : context->hslot; slot < HSYNC_END_H40; slot++ )
+ for (int slot = context->hslot <= HSYNC_SLOT_H40 ? HSYNC_SLOT_H40 : context->hslot; slot < HSYNC_END_H40; slot++ )
{
cycles += h40_hsync_cycles[slot - HSYNC_SLOT_H40];
}
- cycles += (VINT_SLOT_H40 - (context->hslot > HSYNC_SLOT_H40 ? context->hslot : HSYNC_SLOT_H40)) * MCLKS_SLOT_H40;
+ cycles += (VINT_SLOT_H40 - (context->hslot > HSYNC_END_H40 ? context->hslot : HSYNC_END_H40)) * MCLKS_SLOT_H40;
return cycles;
}
} else {