Skip to content

Commit

Permalink
CPU clock counter reverted to negede to count full CPU cycle
Browse files Browse the repository at this point in the history
- Removed regdump flush counter (overengineering)
- Since CPU clk counter is now negedged delta=1 check is not required anymore
  • Loading branch information
ogamespec committed Jul 30, 2023
1 parent a2a9b24 commit f3c745a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 26 deletions.
29 changes: 8 additions & 21 deletions Breaknes/BreaksCore/AbstractBoard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ namespace Breaknes
}
ppu_regdump = new RegDumper("PPU", GetPHICounter(), filename);
prev_phi_counter_for_ppuregdump = GetPHICounter();
phi_flush_counter_ppuregdump = 0;

printf("PPU regdump enabled to file: %s\n", filename);
}
Expand All @@ -132,7 +131,6 @@ namespace Breaknes
}
apu_regdump = new RegDumper("APU", GetPHICounter(), filename);
prev_phi_counter_for_apuregdump = GetPHICounter();
phi_flush_counter_apuregdump = 0;

printf("APU regdump enabled to file: %s\n", filename);
}
Expand All @@ -151,47 +149,36 @@ namespace Breaknes
/// </summary>
void Board::TreatCoreForRegdump(uint16_t addr_bus, uint8_t data_bus, BaseLogic::TriState m2, BaseLogic::TriState rnw)
{
// The reason for checking for delta = 1 is that the first trigger is received during PHI1 of the core when it sets the register address;
// And since the PHI counter is posedge, we need to catch its next change (the next PHI2 after the address is set)

// 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 && delta == 1) {
if (prev_phi_counter_for_apuregdump != phi_now) {

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);

phi_flush_counter_apuregdump += delta;
if (phi_flush_counter_apuregdump >= JustAboutOneSecond) {
phi_flush_counter_apuregdump = 0;
apu_regdump->Flush();
}

prev_phi_counter_for_apuregdump = phi_now;
}
prev_phi_counter_for_apuregdump = phi_now;
}
// PPU Regump (isomorphic)
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 && delta == 1) {
if (prev_phi_counter_for_ppuregdump != phi_now) {

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);

phi_flush_counter_ppuregdump += delta;
if (phi_flush_counter_ppuregdump >= JustAboutOneSecond) {
phi_flush_counter_ppuregdump = 0;
ppu_regdump->Flush();
}
prev_phi_counter_for_ppuregdump = phi_now;
}
prev_phi_counter_for_ppuregdump = phi_now;
}
}
}

void Board::GetApuSignalFeatures(APUSim::AudioSignalFeatures* features)
Expand Down
2 changes: 0 additions & 2 deletions Breaknes/BreaksCore/AbstractBoard.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ namespace Breaknes
RegDumper* apu_regdump = nullptr;
size_t prev_phi_counter_for_ppuregdump = 0;
size_t prev_phi_counter_for_apuregdump = 0;
size_t phi_flush_counter_ppuregdump = 0;
size_t phi_flush_counter_apuregdump = 0;

void TreatCoreForRegdump(uint16_t addr_bus, uint8_t data_bus, BaseLogic::TriState m2, BaseLogic::TriState rnw);

Expand Down
5 changes: 3 additions & 2 deletions BreaksAPU/APUSim/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ namespace APUSim

// TBD: Other APU revisions

// The software PHI counter is triggered by the raising edge.
// The software PHI counter is triggered by the falling edge.
// This is purely a software design for convenience, and has nothing to do with APU hardware circuitry.
// CPU cycles count by falling edge means that it is a counter of FULL cycles (i.e. PHI1+PHI2 of the processor are executed)

if (IsPosedge(prev_phi, new_phi))
if (IsNegedge(prev_phi, new_phi))
{
apu->phi_counter++;
}
Expand Down
2 changes: 1 addition & 1 deletion Common/BaseBoardLib/RegDumpProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace BaseBoard
{
// Increase the cycle counter

if (IsPosedge(PrevCLK, CLK))
if (IsNegedge(PrevCLK, CLK))
{
clk_counter++;
hold = false;
Expand Down

0 comments on commit f3c745a

Please sign in to comment.