From acda0337217ae0232cb16b11712122fd75c2836e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=AA=20de=20Souza=20Pinto?= Date: Sun, 25 Oct 2026 18:04:04 +0100 Subject: [PATCH] cpu: Update cpu650x emulator code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updated from: Repo: https://github.com/rene/MOS650x HEAD: 36f2b67fd6de2a221e691c81d1d2c977756ca89a Signed-off-by: RenĂª de Souza Pinto --- src/cpu/cpu650x.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/cpu/cpu650x.c b/src/cpu/cpu650x.c index 908cc2e..69ba10c 100644 --- a/src/cpu/cpu650x.c +++ b/src/cpu/cpu650x.c @@ -571,7 +571,7 @@ static void PLA(void) static void PLP(void) { - CPU.P.reg = S_POP(); + CPU.P.reg = (S_POP() | EXP_FLAG_MASK) & (uint8_t)(~BRK_FLAG_MASK); } static void ROL(void) @@ -622,7 +622,7 @@ static void RTI(void) uint16_t addr; uint8_t pch, pcl; - CPU.P.reg = S_POP(); + CPU.P.reg = (S_POP() | EXP_FLAG_MASK) & (uint8_t)(~BRK_FLAG_MASK); pcl = S_POP(); pch = S_POP(); addr = (((uint16_t)pch << 8) & 0xff00) | ((uint16_t)pcl & 0x00ff); @@ -1007,7 +1007,8 @@ static int fetch_operand(enum _addr_modes mode) switch (mode) { case mIMP: - /* Nothing to do */ + /* Performs a dummy fetch */ + sbus_read(CPU.PC); break; case mIMM: @@ -1074,6 +1075,12 @@ static int fetch_operand(enum _addr_modes mode) if ((addr & 0xff00) != bah) cross = 1; + /* We need to perform a dummy read when page crossing for read + * instructions (differentiated by the add cycles == 0). + */ + if (cross || op_codes[opcode].add_cycles == 0) + sbus_read((uint16_t)((bah & 0xff00) | (addr & 0x00ff))); + /* Fetches the data */ fetched_addr = addr; break; @@ -1088,6 +1095,10 @@ static int fetch_operand(enum _addr_modes mode) if ((addr & 0xff00) != bah) cross = 1; + /* Dummy read as in abs,x */ + if (cross || op_codes[opcode].add_cycles == 0) + sbus_read((uint16_t)((bah & 0xff00) | (addr & 0x00ff))); + /* Fetches the data */ fetched_addr = addr; break; @@ -1111,6 +1122,10 @@ static int fetch_operand(enum _addr_modes mode) if ((addr & 0xff00) != bah) cross = 1; + /* Dummy read as in abs,x */ + if (cross || op_codes[opcode].add_cycles == 0) + sbus_read((uint16_t)((bah & 0xff00) | (addr & 0x00ff))); + fetched_addr = addr; break; } @@ -1254,7 +1269,7 @@ void cpu_reset(void) CPU.X = 0; CPU.Y = 0; CPU.S = 0xfd; - CPU.P.reg = 0x34; + CPU.P.reg = 0x24; /* Fetch initial vectors */ adl = sbus_read(0xfffc);