diff --git a/Breaknes/BreaksCore/AbstractBoard.cpp b/Breaknes/BreaksCore/AbstractBoard.cpp
index b66c74c5..f38c52a5 100644
--- a/Breaknes/BreaksCore/AbstractBoard.cpp
+++ b/Breaknes/BreaksCore/AbstractBoard.cpp
@@ -146,21 +146,21 @@ namespace Breaknes
///
/// Check that the 6502 core is accessing the mapped APU/PPU registers and add an entry to regdump if necessary.
+ /// The register operation is committed only on the PHI2 phase of the processor (the signal value is obtained directly from the core)
+ /// If you don't do this, you may catch "bogus" register operations when the register address is set during PHI1.
///
- void Board::TreatCoreForRegdump(uint16_t addr_bus, uint8_t data_bus, BaseLogic::TriState m2, BaseLogic::TriState rnw)
+ void Board::TreatCoreForRegdump(uint16_t addr_bus, uint8_t data_bus, BaseLogic::TriState phi2, BaseLogic::TriState rnw)
{
// APU Regdump
if (apu_regdump && (addr_bus & ~MappedAPUMask) == MappedAPUBase) {
uint64_t phi_now = GetPHICounter();
- uint64_t delta = phi_now - prev_phi_counter_for_apuregdump;
- if (prev_phi_counter_for_apuregdump != phi_now) {
+ if (prev_phi_counter_for_apuregdump != phi_now && phi2 == BaseLogic::TriState::One) {
if (rnw == BaseLogic::TriState::One)
apu_regdump->LogRegRead(phi_now, addr_bus & MappedAPUMask);
else if (rnw == BaseLogic::TriState::Zero)
apu_regdump->LogRegWrite(phi_now, addr_bus & MappedAPUMask, data_bus);
-
prev_phi_counter_for_apuregdump = phi_now;
}
}
@@ -168,14 +168,12 @@ namespace Breaknes
if (ppu_regdump && (addr_bus & ~MappedPPUMask) == MappedPPUBase) {
uint64_t phi_now = GetPHICounter();
- uint64_t delta = phi_now - prev_phi_counter_for_ppuregdump;
- if (prev_phi_counter_for_ppuregdump != phi_now) {
+ if (prev_phi_counter_for_ppuregdump != phi_now && phi2 == BaseLogic::TriState::One) {
if (rnw == BaseLogic::TriState::One)
ppu_regdump->LogRegRead(phi_now, addr_bus & MappedPPUMask);
else if (rnw == BaseLogic::TriState::Zero)
ppu_regdump->LogRegWrite(phi_now, addr_bus & MappedPPUMask, data_bus);
-
prev_phi_counter_for_ppuregdump = phi_now;
}
}
diff --git a/Breaknes/BreaksCore/AbstractBoard.h b/Breaknes/BreaksCore/AbstractBoard.h
index d8d2603a..349ba8e8 100644
--- a/Breaknes/BreaksCore/AbstractBoard.h
+++ b/Breaknes/BreaksCore/AbstractBoard.h
@@ -55,7 +55,7 @@ namespace Breaknes
size_t prev_phi_counter_for_ppuregdump = 0;
size_t prev_phi_counter_for_apuregdump = 0;
- void TreatCoreForRegdump(uint16_t addr_bus, uint8_t data_bus, BaseLogic::TriState m2, BaseLogic::TriState rnw);
+ void TreatCoreForRegdump(uint16_t addr_bus, uint8_t data_bus, BaseLogic::TriState phi2, BaseLogic::TriState rnw);
public:
Board(APUSim::Revision apu_rev, PPUSim::Revision ppu_rev, Mappers::ConnectorType p1);
diff --git a/Breaknes/BreaksCore/FamicomBoard.cpp b/Breaknes/BreaksCore/FamicomBoard.cpp
index 451c1dd1..03824998 100644
--- a/Breaknes/BreaksCore/FamicomBoard.cpp
+++ b/Breaknes/BreaksCore/FamicomBoard.cpp
@@ -60,7 +60,7 @@ namespace Breaknes
M2 = outputs[(size_t)APUSim::APU_Output::M2];
// Accesses by the embedded core to APU registers are still broadcast to the address bus via the multiplexer.
- TreatCoreForRegdump(addr_bus, data_bus, M2, CPU_RnW);
+ TreatCoreForRegdump(addr_bus, data_bus, apu->GetPHI2(), CPU_RnW);
nOE1 = outputs[(size_t)APUSim::APU_Output::n_IN0]; // #RDP0 official
nOE2 = outputs[(size_t)APUSim::APU_Output::n_IN1]; // #RDP1 official
diff --git a/Breaknes/BreaksCore/NESBoard.cpp b/Breaknes/BreaksCore/NESBoard.cpp
index b2a217df..c16b9dbb 100644
--- a/Breaknes/BreaksCore/NESBoard.cpp
+++ b/Breaknes/BreaksCore/NESBoard.cpp
@@ -61,7 +61,7 @@ namespace Breaknes
M2 = outputs[(size_t)APUSim::APU_Output::M2];
// Accesses by the embedded core to APU registers are still broadcast to the address bus via the multiplexer.
- TreatCoreForRegdump(addr_bus, data_bus, M2, CPU_RnW);
+ TreatCoreForRegdump(addr_bus, data_bus, apu->GetPHI2(), CPU_RnW);
nOE1 = outputs[(size_t)APUSim::APU_Output::n_IN0]; // #RDP0 official
nOE2 = outputs[(size_t)APUSim::APU_Output::n_IN1]; // #RDP1 official
@@ -226,7 +226,7 @@ namespace Breaknes
{
if (PPU_nCE == TriState::Zero && CPU_RnW == TriState::Zero) {
int reg_sel = addr_bus & 7;
- printf("Write PPU %d=0x%02X\n", reg_sel, data_bus);
+ printf("Write PPU %d=0x%02X, phi2: %d, phi counter: 0x%llx\n", reg_sel, data_bus, apu->GetPHI2(), GetPHICounter());
}
}
}
diff --git a/BreaksAPU/APUSim/apu.cpp b/BreaksAPU/APUSim/apu.cpp
index 8ce0704c..3b91cbdf 100644
--- a/BreaksAPU/APUSim/apu.cpp
+++ b/BreaksAPU/APUSim/apu.cpp
@@ -161,4 +161,9 @@ namespace APUSim
// TBD: Add other APU
}
+
+ TriState APU::GetPHI2()
+ {
+ return wire.PHI2;
+ }
}
diff --git a/BreaksAPU/APUSim/apu.h b/BreaksAPU/APUSim/apu.h
index 57e86694..e345a260 100644
--- a/BreaksAPU/APUSim/apu.h
+++ b/BreaksAPU/APUSim/apu.h
@@ -365,5 +365,7 @@ namespace APUSim
///
///
void GetSignalFeatures(AudioSignalFeatures& features);
+
+ BaseLogic::TriState GetPHI2();
};
}