# HG changeset patch # User Michael Pavone # Date 1483605383 28800 # Node ID c83ec07ddbacc4df5854a24383ccb24394ecc55d # Parent 2e3ad914bad31b5fb8f190bedc6fbc70b3a85083 Implemented Mode 4 H conter latching diff -r 2e3ad914bad3 -r c83ec07ddbac sms.c --- a/sms.c Thu Jan 05 00:08:28 2017 -0800 +++ b/sms.c Thu Jan 05 00:36:23 2017 -0800 @@ -12,8 +12,19 @@ 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 { diff -r 2e3ad914bad3 -r c83ec07ddbac vdp.c --- a/vdp.c Thu Jan 05 00:08:28 2017 -0800 +++ b/vdp.c Thu Jan 05 00:36:23 2017 -0800 @@ -2140,6 +2140,39 @@ } } +static uint16_t get_ext_vcounter(vdp_context *context) +{ + uint16_t line= context->vcounter & 0xFF; + if (context->double_res) { + line <<= 1; + if (line & 0x100) { + line |= 1; + } + } + return line << 8; +} + +void vdp_latch_hv(vdp_context *context) +{ + context->hv_latch = context->hslot | get_ext_vcounter(context); +} + +uint16_t vdp_hv_counter_read(vdp_context * context) +{ + if ((context->regs[REG_MODE_2] & BIT_MODE_5) && (context->regs[REG_MODE_1] & BIT_HVC_LATCH)) { + return context->hv_latch; + } + uint16_t hv; + if (context->regs[REG_MODE_2] & BIT_MODE_5) { + hv = context->hslot; + } else { + hv = context->hv_latch & 0xFF; + } + hv |= get_ext_vcounter(context); + + return hv; +} + int vdp_control_port_write(vdp_context * context, uint16_t value) { //printf("control port write: %X at %d\n", value, context->cycles); @@ -2184,7 +2217,7 @@ if (reg < (mode_5 ? VDP_REGS : 0xB)) { //printf("register %d set to %X\n", reg, value & 0xFF); if (reg == REG_MODE_1 && (value & BIT_HVC_LATCH) && !(context->regs[reg] & BIT_HVC_LATCH)) { - context->hv_latch = vdp_hv_counter_read(context); + vdp_latch_hv(context); } if (reg == REG_BG_COLOR) { value &= 0x3F; @@ -2388,23 +2421,6 @@ return context->prefetch; } -uint16_t vdp_hv_counter_read(vdp_context * context) -{ - if ((context->regs[REG_MODE_2] & BIT_MODE_5) && (context->regs[REG_MODE_1] & BIT_HVC_LATCH)) { - return context->hv_latch; - } - uint32_t line= context->vcounter & 0xFF; - uint32_t linecyc = context->hslot; - linecyc &= 0xFF; - if (context->double_res) { - line <<= 1; - if (line & 0x100) { - line |= 1; - } - } - return (line << 8) | linecyc; -} - uint16_t vdp_test_port_read(vdp_context * context) { //TODO: Find out what actually gets returned here diff -r 2e3ad914bad3 -r c83ec07ddbac vdp.h --- a/vdp.h Thu Jan 05 00:08:28 2017 -0800 +++ b/vdp.h Thu Jan 05 00:36:23 2017 -0800 @@ -213,6 +213,7 @@ uint16_t vdp_control_port_read(vdp_context * context); uint16_t vdp_data_port_read(vdp_context * context); uint8_t vdp_data_port_read_pbc(vdp_context * context); +void vdp_latch_hv(vdp_context *context); uint16_t vdp_hv_counter_read(vdp_context * context); uint16_t vdp_test_port_read(vdp_context * context); void vdp_adjust_cycles(vdp_context * context, uint32_t deduction);