From 3536ae228f002befbbcec0176ed6d4ac9fdef8c6 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Sat, 16 Sep 2017 20:41:34 +0300 Subject: [PATCH] AR3 CIA triggers need small delay. --- ar.cpp | 21 +++++++++++++------ cia.cpp | 65 +++++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 57 insertions(+), 29 deletions(-) diff --git a/ar.cpp b/ar.cpp index aa05641d..a0d0e26a 100644 --- a/ar.cpp +++ b/ar.cpp @@ -1119,6 +1119,19 @@ void action_replay_reset (bool hardreset, bool keyboardreset) } } +static void action_replay_cia_access_delay(uae_u32 v) +{ + if (v) { + armode_read = ARMODE_WRITE_BFD100; + action_replay_flag = ACTION_REPLAY_ACTIVATE; + set_special(SPCFLAG_ACTION_REPLAY); + } else { + armode_read = ARMODE_READ_BFE001; + action_replay_flag = ACTION_REPLAY_ACTIVATE; + set_special(SPCFLAG_ACTION_REPLAY); + } +} + void action_replay_cia_access(bool write) { if (armodel < 2) @@ -1128,13 +1141,9 @@ void action_replay_cia_access(bool write) if (action_replay_flag == ACTION_REPLAY_INACTIVE) return; if ((armode_write & ARMODE_ACTIVATE_BFE001) && !write) { - armode_read = ARMODE_READ_BFE001; - action_replay_flag = ACTION_REPLAY_ACTIVATE; - set_special (SPCFLAG_ACTION_REPLAY); + event2_newevent_xx(-1, 1, write, action_replay_cia_access_delay); } else if ((armode_write & ARMODE_ACTIVATE_BFD100) && write) { - armode_read = ARMODE_WRITE_BFD100; - action_replay_flag = ACTION_REPLAY_ACTIVATE; - set_special (SPCFLAG_ACTION_REPLAY); + event2_newevent_xx(-1, 1, write, action_replay_cia_access_delay); } } diff --git a/cia.cpp b/cia.cpp index 738b582e..4b1eb465 100644 --- a/cia.cpp +++ b/cia.cpp @@ -1026,7 +1026,7 @@ static void setciatod(unsigned long *tod, uae_u32 v) *tod = bintod; } -static uae_u8 ReadCIAA (unsigned int addr) +static uae_u8 ReadCIAA (unsigned int addr, uae_u32 *flags) { unsigned int tmp; int reg = addr & 15; @@ -1041,9 +1041,7 @@ static uae_u8 ReadCIAA (unsigned int addr) switch (reg) { case 0: { -#ifdef ACTION_REPLAY - action_replay_cia_access(false); -#endif + *flags |= 1; uae_u8 v = DISK_status_ciaa() & 0x3c; v |= handle_joystick_buttons (ciaapra, ciaadra); v |= (ciaapra | (ciaadra ^ 3)) & 0x03; @@ -1185,7 +1183,7 @@ static uae_u8 ReadCIAA (unsigned int addr) return 0; } -static uae_u8 ReadCIAB (unsigned int addr) +static uae_u8 ReadCIAB (unsigned int addr, uae_u32 *flags) { unsigned int tmp; int reg = addr & 15; @@ -1328,7 +1326,7 @@ static uae_u8 ReadCIAB (unsigned int addr) return 0; } -static void WriteCIAA (uae_u16 addr, uae_u8 val) +static void WriteCIAA (uae_u16 addr, uae_u8 val, uae_u32 *flags) { int reg = addr & 15; @@ -1522,7 +1520,7 @@ static void WriteCIAA (uae_u16 addr, uae_u8 val) } } -static void WriteCIAB (uae_u16 addr, uae_u8 val) +static void WriteCIAB (uae_u16 addr, uae_u8 val, uae_u32 *flags) { int reg = addr & 15; @@ -1554,9 +1552,7 @@ static void WriteCIAB (uae_u16 addr, uae_u8 val) #endif break; case 1: -#ifdef ACTION_REPLAY - action_replay_cia_access(true); -#endif + *flags |= 2; #if DONGLE_DEBUG > 0 if (notinrom ()) write_log (_T("BFD100 W %02X %s\n"), val, debuginfo(0)); @@ -1908,6 +1904,7 @@ static uae_u32 REGPARAM2 cia_bget (uaecptr addr) { int r = (addr & 0xf00) >> 8; uae_u8 v = 0; + uae_u32 flags = 0; if (isgarynocia(addr)) return dummy_get(addr, 1, false, 0); @@ -1920,25 +1917,25 @@ static uae_u32 REGPARAM2 cia_bget (uaecptr addr) case 0: if (!issinglecia ()) { cia_wait_pre (1 | 2); - v = (addr & 1) ? ReadCIAA (r) : ReadCIAB (r); + v = (addr & 1) ? ReadCIAA (r, &flags) : ReadCIAB (r, &flags); cia_wait_post (1 | 2, v); } break; case 1: cia_wait_pre (2); if (currprefs.cpu_model == 68000 && currprefs.cpu_compatible) { - v = (addr & 1) ? regs.irc : ReadCIAB (r); + v = (addr & 1) ? regs.irc : ReadCIAB (r, &flags); } else { - v = (addr & 1) ? dummy_get_safe(addr, 1, false, 0) : ReadCIAB (r); + v = (addr & 1) ? dummy_get_safe(addr, 1, false, 0) : ReadCIAB (r, &flags); } cia_wait_post (2, v); break; case 2: cia_wait_pre (1); if (currprefs.cpu_model == 68000 && currprefs.cpu_compatible) - v = (addr & 1) ? ReadCIAA (r) : regs.irc >> 8; + v = (addr & 1) ? ReadCIAA (r, &flags) : regs.irc >> 8; else - v = (addr & 1) ? ReadCIAA (r) : dummy_get_safe(addr, 1, false, 0); + v = (addr & 1) ? ReadCIAA (r, &flags) : dummy_get_safe(addr, 1, false, 0); cia_wait_post (1, v); break; case 3: @@ -1953,7 +1950,11 @@ static uae_u32 REGPARAM2 cia_bget (uaecptr addr) } break; } - +#ifdef ACTION_REPLAY + if (flags) { + action_replay_cia_access((flags & 2) != 0); + } +#endif return v; } @@ -1961,6 +1962,7 @@ static uae_u32 REGPARAM2 cia_wget (uaecptr addr) { int r = (addr & 0xf00) >> 8; uae_u16 v = 0; + uae_u32 flags = 0; if (isgarynocia(addr)) return dummy_get(addr, 2, false, 0); @@ -1974,18 +1976,18 @@ static uae_u32 REGPARAM2 cia_wget (uaecptr addr) if (!issinglecia ()) { cia_wait_pre (1 | 2); - v = (ReadCIAB (r) << 8) | ReadCIAA (r); + v = (ReadCIAB (r, &flags) << 8) | ReadCIAA (r, &flags); cia_wait_post (1 | 2, v); } break; case 1: cia_wait_pre (2); - v = (ReadCIAB (r) << 8) | dummy_get_safe(addr, 1, false, 0); + v = (ReadCIAB (r, &flags) << 8) | dummy_get_safe(addr, 1, false, 0); cia_wait_post (2, v); break; case 2: cia_wait_pre (1); - v = (dummy_get_safe(addr, 1, false, 0) << 8) | ReadCIAA (r); + v = (dummy_get_safe(addr, 1, false, 0) << 8) | ReadCIAA (r, &flags); cia_wait_post (1, v); break; case 3: @@ -2000,6 +2002,11 @@ static uae_u32 REGPARAM2 cia_wget (uaecptr addr) } break; } +#ifdef ACTION_REPLAY + if (flags) { + action_replay_cia_access((flags & 2) != 0); + } +#endif return v; } @@ -2039,16 +2046,22 @@ static void REGPARAM2 cia_bput (uaecptr addr, uae_u32 value) int cs = cia_chipselect(addr); if (!issinglecia () || (cs & 3) != 0) { + uae_u32 flags = 0; cia_wait_pre (((cs & 2) == 0 ? 1 : 0) | ((cs & 1) == 0 ? 2 : 0)); if ((cs & 2) == 0) - WriteCIAB (r, value); + WriteCIAB (r, value, &flags); if ((cs & 1) == 0) - WriteCIAA (r, value); + WriteCIAA (r, value, &flags); cia_wait_post (((cs & 2) == 0 ? 1 : 0) | ((cs & 1) == 0 ? 2 : 0), value); if (((cs & 3) == 3) && (warned > 0 || currprefs.illegal_mem)) { write_log (_T("cia_bput: unknown CIA address %08X=%02X PC=%08X\n"), addr, value & 0xff, M68K_GETPC); warned--; } +#ifdef ACTION_REPLAY + if (flags) { + action_replay_cia_access((flags & 2) != 0); + } +#endif } } @@ -2067,16 +2080,22 @@ static void REGPARAM2 cia_wput (uaecptr addr, uae_u32 value) int cs = cia_chipselect(addr); if (!issinglecia () || (cs & 3) != 0) { + uae_u32 flags = 0; cia_wait_pre (((cs & 2) == 0 ? 1 : 0) | ((cs & 1) == 0 ? 2 : 0)); if ((cs & 2) == 0) - WriteCIAB (r, value >> 8); + WriteCIAB (r, value >> 8, &flags); if ((cs & 1) == 0) - WriteCIAA (r, value & 0xff); + WriteCIAA (r, value & 0xff, &flags); cia_wait_post (((cs & 2) == 0 ? 1 : 0) | ((cs & 1) == 0 ? 2 : 0), value); if (((cs & 3) == 3) && (warned > 0 || currprefs.illegal_mem)) { write_log (_T("cia_wput: unknown CIA address %08X=%04X %08X\n"), addr, value & 0xffff, M68K_GETPC); warned--; } +#ifdef ACTION_REPLAY + if (flags) { + action_replay_cia_access((flags & 2) != 0); + } +#endif } } -- 2.47.3