From af922a264ae9bee829cea9695289e41355e51170 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Sat, 7 Jun 2025 19:40:09 +0300 Subject: [PATCH] JIT/fast CPU CIA hack --- cia.cpp | 26 ++++++++++++++++++++++++++ od-win32/win32.cpp | 5 +++++ 2 files changed, 31 insertions(+) diff --git a/cia.cpp b/cia.cpp index ce98703c..355f3af5 100644 --- a/cia.cpp +++ b/cia.cpp @@ -183,6 +183,8 @@ static struct rtc_ricoh_data rtc_ricoh; static int internaleclockphase; static bool cia_cycle_accurate; +int cia_timer_hack_adjust = 1; + static bool acc_mode(void) { return cia_cycle_accurate; @@ -1484,6 +1486,16 @@ static uae_u8 ReadCIAReg(int num, int reg) case 7: { uae_u16 tval = t->timer - t->passed; + // fast CPU timer hack + if ((t->cr & CR_START) && !(t->cr & CR_INMODE1) && !(t->cr & CR_INMODE) && t->latch == t->timer) { + if (currprefs.cachesize || currprefs.m68k_speed < 0) { + uae_u16 adj = cia_timer_hack_adjust; + if (adj >= tval && tval > 1) { + adj = tval - 1; + } + tval -= adj; + } + } if (reg == 4 || reg == 6) { return tval & 0xff; } @@ -1629,10 +1641,24 @@ static void CIA_cr_write(int num, int tnum, uae_u8 val) if (!acc_mode()) { // if inaccurate mode: do everything immediately + // Fast CPU timer hack. If timer is stopped, add few extra ticks to timer before stopping it. + if ((t->cr & CR_START) && !(val & CR_START) && !(t->cr & CR_INMODE1) && !(t->cr & CR_INMODE) && t->timer == t->latch) { + if (currprefs.cachesize || currprefs.m68k_speed < 0) { + uae_u16 adj = cia_timer_hack_adjust; + if (adj >= t->timer && t->timer > 1) { + adj = t->timer - 1; + } + if (t->timer > adj) { + t->timer -= adj; + } + } + } + if (val & CR_LOAD) { val &= ~CR_LOAD; t->timer = t->latch; } + if (val & CR_START) { if (!CIA_timer_inmode(tnum, val)) { t->inputpipe = CIA_PIPE_ALL_MASK; diff --git a/od-win32/win32.cpp b/od-win32/win32.cpp index 9d11f4ae..b2fdd005 100644 --- a/od-win32/win32.cpp +++ b/od-win32/win32.cpp @@ -6572,6 +6572,7 @@ extern int kb_mcu_log; extern int logitech_lcd; extern uae_s64 max_avi_size; extern int floppy_writemode; +extern int cia_timer_hack_adjust; extern DWORD_PTR cpu_affinity, cpu_paffinity; static DWORD_PTR original_affinity = -1; @@ -7217,6 +7218,10 @@ static int parseargs(const TCHAR *argx, const TCHAR *np, const TCHAR *np2) on_screen_keyboard = getval(np); return 2; } + if (!_tcscmp(arg, _T("cia_timer_hack"))) { + cia_timer_hack_adjust = getval(np); + return 2; + } #endif return 0; -- 2.47.3