From c7903c0a50e2d02e35984e79e8245ab1b860f193 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Wed, 31 Aug 2022 20:27:04 +0200 Subject: [PATCH] Emulator: Fix address pushed onto stack in CALL opcode --- src/cpu.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cpu.cpp b/src/cpu.cpp index 239ea86..963c157 100644 --- a/src/cpu.cpp +++ b/src/cpu.cpp @@ -1411,13 +1411,13 @@ void CPU::call() } m_wait_cycles += 24; - // Push address of next 2 bytes in memory onto stack + // Push address of the instruction after the CALL on the stack, such that RET can pop it later m_sp = (m_sp - 1) & 0xffff; - write(m_sp, data >> 8); + write(m_sp, m_pc >> 8); m_sp = (m_sp - 1) & 0xffff; - write(m_sp, data & 0xff); + write(m_sp, m_pc & 0xff); - // Jump to this address + // Jump to operand address m_pc = data; };