Ensure GB register accesses pass through bus notification code.

Signed-off-by: Adrian.Conlon <adrian.conlon@gmail.com>
This commit is contained in:
Adrian.Conlon 2017-07-18 21:41:10 +01:00
parent 99e3454527
commit 758574007d
2 changed files with 18 additions and 11 deletions

View File

@ -79,9 +79,15 @@ namespace EightBit {
void reset();
uint8_t& REG(int offset) {
ADDRESS().word = BASE + offset;
return Memory::reference();
void writeRegister(int offset, uint8_t content) {
REG(offset) = content;
fireWriteBusEvent();
}
uint8_t readRegister(int offset) {
auto returned = REG(offset);
fireReadBusEvent();
return returned;
}
void incrementLY() {
@ -104,5 +110,10 @@ namespace EightBit {
private:
std::array<uint8_t, 0x100> m_boot;
uint8_t& REG(int offset) {
ADDRESS().word = BASE + offset;
return Memory::reference();
}
};
}

View File

@ -712,8 +712,7 @@ void EightBit::LR35902::executeOther(int x, int y, int z, int p, int q) {
} else {
switch (y) {
case 4: // GB: LD (FF00 + n),A
m_bus.REG(fetchByte()) = A();
m_bus.fireWriteBusEvent();
m_bus.writeRegister(fetchByte(), A());
cycles += 3;
break;
case 5: { // GB: ADD SP,dd
@ -729,8 +728,7 @@ void EightBit::LR35902::executeOther(int x, int y, int z, int p, int q) {
cycles += 4;
break;
case 6: // GB: LD A,(FF00 + n)
A() = m_bus.REG(fetchByte());
m_bus.fireReadBusEvent();
A() = m_bus.readRegister(fetchByte());
cycles += 3;
break;
case 7: { // GB: LD HL,SP + dd
@ -782,8 +780,7 @@ void EightBit::LR35902::executeOther(int x, int y, int z, int p, int q) {
} else {
switch (y) {
case 4: // GB: LD (FF00 + C),A
m_bus.REG(C()) = A();
m_bus.fireWriteBusEvent();
m_bus.writeRegister(C(), A());
cycles += 2;
break;
case 5: // GB: LD (nn),A
@ -792,8 +789,7 @@ void EightBit::LR35902::executeOther(int x, int y, int z, int p, int q) {
cycles += 4;
break;
case 6: // GB: LD A,(FF00 + C)
A() = m_bus.REG(C());
m_bus.fireReadBusEvent();
A() = m_bus.readRegister(C());
cycles += 2;
break;
case 7: // GB: LD A,(nn)