summaryrefslogtreecommitdiff
path: root/sms.c
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2017-01-05 00:36:23 -0800
committerMichael Pavone <pavone@retrodev.com>2017-01-05 00:36:23 -0800
commit25908ea88742215abdc04c491736e0061e99498e (patch)
treee5f3a7781fb700c4924fc0d2b9e596c640a38a5e /sms.c
parentf04fcbb10860e4a8431e3ea70f46ade4280f7c9f (diff)
Implemented Mode 4 H conter latching
Diffstat (limited to 'sms.c')
-rw-r--r--sms.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/sms.c b/sms.c
index 170f2ce..b74b6dd 100644
--- a/sms.c
+++ b/sms.c
@@ -12,8 +12,19 @@ static void *memory_io_write(uint32_t location, void *vcontext, uint8_t value)
z80_context *z80 = vcontext;
sms_context *sms = z80->system;
if (location & 1) {
+ uint8_t fuzzy_ctrl_0 = sms->io.ports[0].control, fuzzy_ctrl_1 = sms->io.ports[1].control;
sms->io.ports[0].control = (~value) << 5 & 0x60;
+ fuzzy_ctrl_0 |= sms->io.ports[0].control;
sms->io.ports[1].control = (~value) << 3 & 0x60;
+ fuzzy_ctrl_1 |= sms->io.ports[1].control;
+ if (
+ (fuzzy_ctrl_0 & 0x40 & (sms->io.ports[0].output ^ (value << 1)) & (value << 1))
+ || (fuzzy_ctrl_0 & 0x40 & (sms->io.ports[1].output ^ (value >> 1)) & (value >> 1))
+ ) {
+ //TH is an output and it went from 0 -> 1
+ vdp_run_context(sms->vdp, z80->current_cycle);
+ vdp_latch_hv(sms->vdp);
+ }
io_data_write(sms->io.ports, value << 1, z80->current_cycle);
io_data_write(sms->io.ports + 1, value >> 1, z80->current_cycle);
} else {