From 557a468dcccfc1d1e4ccc067b31f812478236077 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Wed, 27 Apr 2016 23:57:00 -0700 Subject: Properly emulate machine freeze when reading from VDP while configured for writes --- vdp.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'vdp.c') diff --git a/vdp.c b/vdp.c index c52106c..0be1bf4 100644 --- a/vdp.c +++ b/vdp.c @@ -8,6 +8,7 @@ #include #include #include "render.h" +#include "util.h" #define NTSC_INACTIVE_START 224 #define PAL_INACTIVE_START 240 @@ -1737,10 +1738,18 @@ uint16_t vdp_data_port_read(vdp_context * context) context->flags2 &= ~FLAG2_READ_PENDING; } if (context->cd & 1) { - return 0; + warning("Read from VDP data port while writes are configured, CPU is now frozen. VDP Address: %X, CD: %X\n", context->address, context->cd); } + uint32_t old_frame = context->frame; while (!(context->flags & FLAG_READ_FETCHED)) { vdp_run_context(context, context->cycles + ((context->regs[REG_MODE_4] & BIT_H40) ? 16 : 20)); + if (context->frame != old_frame) { + if (!headless) { + //TODO: make pushing frames to renderer automatic so this doesn't need to be here + wait_render_frame(context, 0); + } + old_frame = context->frame; + } } context->flags &= ~FLAG_READ_FETCHED; //Should this happen after the prefetch or after the read? -- cgit v1.2.3