GB: Fix read/write of A, PC and CycleCounter when executing

This commit is contained in:
Ilari Liusvaara 2014-03-24 14:03:01 +02:00
parent 3ab62196fd
commit 2592a724bc
6 changed files with 119 additions and 10 deletions

View file

@ -1,7 +1,7 @@
From 148f2f6e1142f9d2caa9612dd9a68069426537f8 Mon Sep 17 00:00:00 2001
From: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
Date: Fri, 9 Aug 2013 20:13:11 +0300
Subject: [PATCH 1/5] Changes to make libgambatte rerecording friendly
Subject: [PATCH 1/6] Changes to make libgambatte rerecording friendly
---
Makefile | 10 +
@ -5889,5 +5889,5 @@ index 7d8dbe1..341bce6 100644
}
--
1.9.rc1
1.9.1

View file

@ -1,7 +1,7 @@
From 1bcbfe173abb9650c8ae13677d4dca4f0222ab7e Mon Sep 17 00:00:00 2001
From: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
Date: Mon, 18 Nov 2013 01:53:58 +0200
Subject: [PATCH 2/5] Expose CPU registers
Subject: [PATCH 2/6] Expose CPU registers
---
libgambatte/include/gambatte.h | 22 +++++++++++++++++++
@ -120,5 +120,5 @@ index 0204557..a61e177 100644
+}
}
--
1.9.rc1
1.9.1

View file

@ -1,7 +1,7 @@
From 6725b4545adc3e94e0344e5f904267349ce167ba Mon Sep 17 00:00:00 2001
From: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
Date: Thu, 28 Nov 2013 22:05:32 +0200
Subject: [PATCH 3/5] Breakpoints & debugging
Subject: [PATCH 3/6] Breakpoints & debugging
---
libgambatte/include/gambatte.h | 23 +++++++++
@ -486,5 +486,5 @@ index a531930..4a252b7 100644
void nontrivial_write(unsigned p, unsigned data, unsigned cycleCounter);
void updateSerial(unsigned cc);
--
1.9.rc1
1.9.1

View file

@ -1,7 +1,7 @@
From 607d3e252c43d67cea54ec222ef1767a86b3660b Mon Sep 17 00:00:00 2001
From: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
Date: Thu, 5 Dec 2013 08:48:21 +0200
Subject: [PATCH 4/5] Fix sound DC levels
Subject: [PATCH 4/6] Fix sound DC levels
This was causing popping in Mega Man (I)
---
@ -105,5 +105,5 @@ index bc0a312..0abd4fb 100644
unsigned out = lfsr_.isHighState() ? outHigh : outLow;
--
1.9.rc1
1.9.1

View file

@ -1,7 +1,7 @@
From 84fe61ebd27df485ff894d1d05b8950916c6508c Mon Sep 17 00:00:00 2001
From: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
Date: Sat, 1 Feb 2014 12:56:47 +0200
Subject: [PATCH 5/5] Crash on illegal instruction, fix MBC3 bank0
Subject: [PATCH 5/6] Crash on illegal instruction, fix MBC3 bank0
---
libgambatte/include/gambatte.h | 2 ++
@ -188,5 +188,5 @@ index 1775139..bfec71c 100644
void loadOrSave(loadsave& state) {
rtc_->loadOrSave(state);
--
1.9.rc1
1.9.1

View file

@ -0,0 +1,109 @@
From 24df3ca0d17d37bb3192b0ddf28cc16d9b4f8fa5 Mon Sep 17 00:00:00 2001
From: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
Date: Mon, 24 Mar 2014 14:01:29 +0200
Subject: [PATCH 6/6] Fix read/write of A, PC and CycleCounter when executing
---
libgambatte/src/cpu.cpp | 9 +++++++++
libgambatte/src/cpu.h | 3 +++
libgambatte/src/gambatte.cpp | 10 +++++-----
3 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/libgambatte/src/cpu.cpp b/libgambatte/src/cpu.cpp
index 037fff2..7f10986 100644
--- a/libgambatte/src/cpu.cpp
+++ b/libgambatte/src/cpu.cpp
@@ -44,6 +44,9 @@ CPU::CPU(time_t (**_getCurrentTime)())
, l(0x4D)
, skip_(false)
, emuflags(0)
+, pcptr(&pc_)
+, aptr(&a_)
+, cyclecountptr(&cycleCounter_)
{
}
@@ -514,10 +517,13 @@ void CPU::process(unsigned const cycles) {
mem_.setEndtime(cycleCounter_, cycles);
unsigned char a = a_;
+ aptr = &a;
unsigned cycleCounter = cycleCounter_;
+ cyclecountptr = &cycleCounter;
while (mem_.isActive()) {
unsigned short pc = pc_;
+ pcptr = &pc;
if (mem_.halted()) {
if (cycleCounter < mem_.nextEventTime()) {
@@ -2020,11 +2026,14 @@ void CPU::process(unsigned const cycles) {
}
pc_ = pc;
+ pcptr = &pc_;
cycleCounter = mem_.event(cycleCounter);
}
a_ = a;
+ aptr = &a_;
cycleCounter_ = cycleCounter;
+ cyclecountptr = &cycleCounter_;
}
}
diff --git a/libgambatte/src/cpu.h b/libgambatte/src/cpu.h
index c2a340b..4df0958 100644
--- a/libgambatte/src/cpu.h
+++ b/libgambatte/src/cpu.h
@@ -101,6 +101,9 @@ public:
unsigned short sp;
unsigned hf1, hf2, zf, cf;
unsigned char a_, b, c, d, e, /*f,*/ h, l;
+ unsigned char* aptr;
+ unsigned short* pcptr;
+ unsigned* cyclecountptr;
private:
Memory mem_;
bool skip_;
diff --git a/libgambatte/src/gambatte.cpp b/libgambatte/src/gambatte.cpp
index f2310ed..d54f5df 100644
--- a/libgambatte/src/gambatte.cpp
+++ b/libgambatte/src/gambatte.cpp
@@ -301,14 +301,14 @@ std::string GB::version()
uint32_t GB::get_cpureg(enum cpu_register _reg)
{
switch(_reg) {
- case REG_CYCLECOUNTER: return p_->cpu.cycleCounter_;
- case REG_PC: return p_->cpu.pc_;
+ case REG_CYCLECOUNTER: return *p_->cpu.cyclecountptr;
+ case REG_PC: return *p_->cpu.pcptr;
case REG_SP: return p_->cpu.sp;
case REG_HF1: return p_->cpu.hf1;
case REG_HF2: return p_->cpu.hf2;
case REG_ZF: return p_->cpu.zf;
case REG_CF: return p_->cpu.cf;
- case REG_A: return p_->cpu.a_;
+ case REG_A: return *p_->cpu.aptr;
case REG_B: return p_->cpu.b;
case REG_C: return p_->cpu.c;
case REG_D: return p_->cpu.d;
@@ -325,13 +325,13 @@ uint32_t GB::get_cpureg(enum cpu_register _reg)
void GB::set_cpureg(enum cpu_register _reg, uint32_t val)
{
switch(_reg) {
- case REG_PC: p_->cpu.pc_ = val; break;
+ case REG_PC: *p_->cpu.pcptr = val; break;
case REG_SP: p_->cpu.sp = val; break;
case REG_HF1: p_->cpu.hf1 = val; break;
case REG_HF2: p_->cpu.hf2 = val; break;
case REG_ZF: p_->cpu.zf = val; break;
case REG_CF: p_->cpu.cf = val; break;
- case REG_A: p_->cpu.a_ = val; break;
+ case REG_A: *p_->cpu.aptr = val; break;
case REG_B: p_->cpu.b = val; break;
case REG_C: p_->cpu.c = val; break;
case REG_D: p_->cpu.d = val; break;
--
1.9.1