game-music-emu: Register A and F are inverted in position so swap them when pushing/pulling from the stack. Fixes issue #20

From fd481255bc43015c8700c8196afde7b4189d659e Mon Sep 17 00:00:00 2001
From: Leandro Nini <[EMAIL REDACTED]>
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 c9e4373..7f8e2aa 100644
--- a/gme/Gb_Cpu.cpp
+++ b/gme/Gb_Cpu.cpp
@@ -881,7 +881,7 @@ bool Gb_Cpu::run( blargg_long cycle_count )
 
 // 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 @@ bool Gb_Cpu::run( blargg_long cycle_count )
 		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 @@ bool Gb_Cpu::run( blargg_long cycle_count )
 		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