summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2015-05-20 22:27:51 -0700
committerMichael Pavone <pavone@retrodev.com>2015-05-20 22:27:51 -0700
commit73ffeecaebbc313eb5713d779622b6e91cc72675 (patch)
tree022d8f867fdc8773073665d0d908b56d9a019ce3
parent863ea0b3f8b8879ac3092f391a68dc95d0d04de2 (diff)
Add some tests for hint timing and fix it properly this time.
-rw-r--r--Makefile3
-rw-r--r--test.c76
-rw-r--r--vdp.c26
3 files changed, 92 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index 6ddcd52..ae61100 100644
--- a/Makefile
+++ b/Makefile
@@ -106,6 +106,9 @@ stateview : stateview.o vdp.o render_sdl.o $(CONFIGOBJS) gst.o
vgmplay : vgmplay.o render_sdl.o $(CONFIGOBJS) $(AUDIOOBJS)
$(CC) -o vgmplay vgmplay.o render_sdl.o $(CONFIGOBJS) $(AUDIOOBJS) $(LDFLAGS)
+
+test : test.o vdp.o
+ $(CC) -o test test.o vdp.o
testgst : testgst.o gst.o
$(CC) -o testgst testgst.o gst.o
diff --git a/test.c b/test.c
new file mode 100644
index 0000000..d06a26b
--- /dev/null
+++ b/test.c
@@ -0,0 +1,76 @@
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include "vdp.h"
+
+int headless = 1;
+uint16_t read_dma_value(uint32_t address)
+{
+ return 0;
+}
+
+uint32_t render_map_color(uint8_t r, uint8_t g, uint8_t b)
+{
+ return 0;
+}
+
+void render_alloc_surfaces(vdp_context * context)
+{
+ context->oddbuf = context->framebuf = malloc(512 * 256 * 4 * 2);
+ memset(context->oddbuf, 0, 512 * 256 * 4 * 2);
+ context->evenbuf = ((char *)context->oddbuf) + 512 * 256 * 4;
+}
+
+int check_hint_time(vdp_context * v_context)
+{
+ uint32_t orig_hint_cycle = vdp_next_hint(v_context);
+ uint32_t cur_hint_cycle;
+ printf("hint cycle is %d at vcounter: %d, hslot: %d\n", orig_hint_cycle, v_context->vcounter, v_context->hslot);
+ int res = 1;
+ while ((cur_hint_cycle = vdp_next_hint(v_context)) > v_context->cycles)
+ {
+ if (cur_hint_cycle != orig_hint_cycle) {
+ fprintf(stderr, "ERROR: hint cycle changed to %d at vcounter: %d, hslot: %d\n", cur_hint_cycle, v_context->vcounter, v_context->hslot);
+ orig_hint_cycle = cur_hint_cycle;
+ res = 0;
+ }
+ vdp_run_context(v_context, v_context->cycles + 1);
+ }
+ printf("hint fired at cycle: %d, vcounter: %d, hslot: %d\n", cur_hint_cycle, v_context->vcounter, v_context->hslot);
+ vdp_int_ack(v_context, 4);
+ return res;
+}
+
+
+int main(int argc, char ** argv)
+{
+ vdp_context v_context;
+ init_vdp_context(&v_context, 0);
+ vdp_control_port_write(&v_context, 0x8144);
+ vdp_control_port_write(&v_context, 0x8C81);
+ vdp_control_port_write(&v_context, 0x8A7F);
+ vdp_control_port_write(&v_context, 0x8014);
+ v_context.hint_counter = 0x7F;
+ v_context.vcounter = 128;
+ v_context.hslot = 165;
+ //check single shot behavior
+ int res = check_hint_time(&v_context);
+ //check every line behavior
+ while (v_context.vcounter < 225)
+ {
+ vdp_run_context(&v_context, v_context.cycles + 1);
+ }
+ vdp_control_port_write(&v_context, 0x8A00);
+ int hint_count = 0;
+ while (res && v_context.vcounter != 224)
+ {
+ res = res && check_hint_time(&v_context);
+ hint_count++;
+ }
+ if (res && hint_count != 225) {
+ fprintf(stderr, "ERROR: hint count should be 225 but was %d instead\n", hint_count);
+ res = 0;
+ }
+ return 0;
+}
diff --git a/vdp.c b/vdp.c
index c7240d4..afd5087 100644
--- a/vdp.c
+++ b/vdp.c
@@ -1443,6 +1443,19 @@ uint32_t const h40_hsync_cycles[] = {19, 20, 20, 20, 18, 20, 20, 20, 18, 20, 20,
void vdp_advance_line(vdp_context *context)
{
context->vcounter++;
+ context->vcounter &= 0x1FF;
+ if (context->flags2 & FLAG2_REGION_PAL) {
+ if (context->latched_mode & BIT_PAL) {
+ if (context->vcounter == 0x10B) {
+ context->vcounter = 0x1D2;
+ }
+ } else if (context->vcounter == 0x103){
+ context->vcounter = 0x1CA;
+ }
+ } else if (!(context->latched_mode & BIT_PAL) && context->vcounter == 0xEB) {
+ context->vcounter = 0x1E5;
+ }
+
if (context->vcounter > (context->latched_mode & BIT_PAL ? PAL_INACTIVE_START : NTSC_INACTIVE_START)) {
context->hint_counter = context->regs[REG_HINT];
} else if (context->hint_counter) {
@@ -1565,19 +1578,6 @@ void vdp_run_context(vdp_context * context, uint32_t target_cycles)
} else {
vdp_advance_line(context);
}
- context->vcounter &= 0x1FF;
- if (context->flags2 & FLAG2_REGION_PAL) {
- if (context->latched_mode & BIT_PAL) {
- if (context->vcounter == 0x10B) {
- context->vcounter = 0x1D2;
- }
- } else if (context->vcounter == 0x103){
- context->vcounter = 0x1CA;
- }
- } else if (!(context->latched_mode & BIT_PAL) && context->vcounter == 0xEB) {
- context->vcounter = 0x1E5;
- }
-
}
}