blob: 488c3be91cfa941c975c353fafbd3595c9e63852 [file] [log] [blame] [edit]
From 414e0d993548fa6e1aea8b944da531e7db07bb94 Mon Sep 17 00:00:00 2001
From: Leandro Nini <drfiemost@users.noreply.github.com>
Date: Wed, 24 Mar 2021 18:06:14 +0100
Subject: [PATCH] Register A and F are inverted in position so swap them when
pushing/pulling from the stack. Fixes issue #20
---
gme/Gb_Cpu.cpp | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/gme/Gb_Cpu.cpp b/gme/Gb_Cpu.cpp
index 21f334e..b8787b2 100644
--- a/gme/Gb_Cpu.cpp
+++ b/gme/Gb_Cpu.cpp
@@ -881,7 +881,7 @@ loop:
// Stack
- case 0xF1: // POP FA
+ case 0xF1: // POP AF
case 0xC1: // POP BC
case 0xD1: // POP DE
case 0xE1: // POP HL (common)
@@ -890,7 +890,8 @@ loop:
sp = (sp + 2) & 0xFFFF;
if ( op != 0xF1 )
goto loop;
- flags = rg.flags & 0xF0;
+ flags = rg.a & 0xF0;
+ rg.a = rg.flags;
goto loop;
case 0xC5: // PUSH BC
@@ -905,8 +906,8 @@ loop:
data = rp.hl;
goto push;
- case 0xF5: // PUSH FA
- data = (flags << 8) | rg.a;
+ case 0xF5: // PUSH AF
+ data = (rg.a << 8) | flags;
goto push;
// Flow control
--
2.10.5