From 1dd2501e9859ea03c0edad2221a587e1e7d3be2a Mon Sep 17 00:00:00 2001 From: Brandon Wright Date: Fri, 1 Jun 2018 14:05:00 -0500 Subject: [PATCH] The flag pushed on to the stack before IRQ is the updated one. --- cpuexec.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/cpuexec.cpp b/cpuexec.cpp index cc7880a0..ca0ee4c5 100644 --- a/cpuexec.cpp +++ b/cpuexec.cpp @@ -207,6 +207,16 @@ static inline void S9xReschedule (void); void S9xMainLoop (void) { + #define CHECK_FOR_IRQ_CHANGE() \ + if (Timings.IRQFlagChanging) \ + { \ + if (Timings.IRQFlagChanging == IRQ_CLEAR_FLAG) \ + ClearIRQ(); \ + else if (Timings.IRQFlagChanging == IRQ_SET_FLAG) \ + SetIRQ(); \ + Timings.IRQFlagChanging = IRQ_NONE; \ + } + for (;;) { if (CPU.NMIPending) @@ -258,17 +268,14 @@ void S9xMainLoop (void) } if ((CPU.IRQLine || CPU.IRQExternal) && !CheckFlag(IRQ)) + { + /* The flag pushed onto the stack is the new value */ + CHECK_FOR_IRQ_CHANGE(); S9xOpcode_IRQ(); + } /* Change IRQ flag for instructions that set it only on last cycle */ - if (Timings.IRQFlagChanging) - { - if (Timings.IRQFlagChanging == IRQ_CLEAR_FLAG) - ClearIRQ(); - else if (Timings.IRQFlagChanging == IRQ_SET_FLAG) - SetIRQ(); - Timings.IRQFlagChanging = IRQ_NONE; - } + CHECK_FOR_IRQ_CHANGE(); #ifdef DEBUGGER