]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
JIT/fast CPU CIA hack
authorToni Wilen <twilen@winuae.net>
Sat, 7 Jun 2025 16:40:09 +0000 (19:40 +0300)
committerToni Wilen <twilen@winuae.net>
Sat, 7 Jun 2025 16:40:09 +0000 (19:40 +0300)
cia.cpp
od-win32/win32.cpp

diff --git a/cia.cpp b/cia.cpp
index ce98703c876a447a8139062a0d40e04fea937b39..355f3af5d0714ccac2468de430434ad5bbf73775 100644 (file)
--- 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;
index 9d11f4aefe289508b83f70f67f8f3f96bf0a9a06..b2fdd0050a6a543eebeb54c936b98e05dfcf5ccf 100644 (file)
@@ -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;