Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regdump fixed #441

Merged
merged 4 commits into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Breaknes/BreaksCore/APUPlayerBoard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Breaknes
{
APUPlayerBoard::APUPlayerBoard(APUSim::Revision apu_rev, PPUSim::Revision ppu_rev, Mappers::ConnectorType p1) : Board(apu_rev, ppu_rev, p1)
{
core = new M6502Core::FakeM6502(0x4000, 0x1f);
core = new M6502Core::FakeM6502("APU", MappedAPUBase, MappedAPUMask);
apu = new APUSim::APU(core, apu_rev);
wram = new BaseBoard::SRAM("WRAM", wram_bits);

Expand Down
17 changes: 9 additions & 8 deletions Breaknes/BreaksCore/AbstractBoard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ namespace Breaknes
delete ppu_regdump;
ppu_regdump = nullptr;
}
ppu_regdump = new RegDumper(GetPHICounter(), filename);
ppu_regdump = new RegDumper("PPU", GetPHICounter(), filename);
prev_phi_counter_for_ppuregdump = GetPHICounter();
phi_flush_counter_ppuregdump = 0;

Expand All @@ -130,7 +130,7 @@ namespace Breaknes
delete apu_regdump;
apu_regdump = nullptr;
}
apu_regdump = new RegDumper(GetPHICounter(), filename);
apu_regdump = new RegDumper("APU", GetPHICounter(), filename);
prev_phi_counter_for_apuregdump = GetPHICounter();
phi_flush_counter_apuregdump = 0;

Expand All @@ -151,11 +151,14 @@ 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)

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 && delta == 1) {

if (rnw == BaseLogic::TriState::One)
apu_regdump->LogRegRead(phi_now, addr_bus & MappedAPUMask);
Expand All @@ -167,15 +170,14 @@ namespace Breaknes
phi_flush_counter_apuregdump = 0;
apu_regdump->Flush();
}

prev_phi_counter_for_apuregdump = phi_now;
}
prev_phi_counter_for_apuregdump = phi_now;
}
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 && delta == 1) {

if (rnw == BaseLogic::TriState::One)
ppu_regdump->LogRegRead(phi_now, addr_bus & MappedPPUMask);
Expand All @@ -187,9 +189,8 @@ namespace Breaknes
phi_flush_counter_ppuregdump = 0;
ppu_regdump->Flush();
}

prev_phi_counter_for_ppuregdump = phi_now;
}
prev_phi_counter_for_ppuregdump = phi_now;
}
}

Expand Down
6 changes: 3 additions & 3 deletions Breaknes/BreaksCore/PPUPlayerBoard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Breaknes
{
PPUPlayerBoard::PPUPlayerBoard(APUSim::Revision apu_rev, PPUSim::Revision ppu_rev, Mappers::ConnectorType p1) : Board(apu_rev, ppu_rev, p1)
{
core = new M6502Core::FakeM6502(0x2000, 0x7);
core = new M6502Core::FakeM6502("PPU", MappedPPUBase, MappedAPUMask);
ppu = new PPUSim::PPU(ppu_rev);
vram = new BaseBoard::SRAM("VRAM", vram_bits);

Expand Down Expand Up @@ -98,7 +98,7 @@ namespace Breaknes
TriState Core_SYNC = core_outputs[(size_t)M6502Core::OutputPad::SYNC];

bool pendingWrite = Core_RnW == TriState::Zero;
bool pendingCpuOperation = (addr_bus & ~7) == 0x2000;
bool pendingCpuOperation = (addr_bus & ~MappedPPUMask) == MappedPPUBase;
size_t ppuRegId = addr_bus & 7;

// CPU I/F operations counter (negedge)
Expand Down Expand Up @@ -201,7 +201,7 @@ namespace Breaknes
void PPUPlayerBoard::Reset()
{
pendingReset = true;
resetHalfClkCounter = 4;
resetHalfClkCounter = 64;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "pch.h"

RegDumper::RegDumper(uint64_t phi_counter_now, char* filename)
RegDumper::RegDumper(const char* target, uint64_t phi_counter_now, char* filename)
{
regLogFile = fopen(filename, "wb");
SavedPHICounter = phi_counter_now;
strcpy(regdump_target, target);
}

RegDumper::~RegDumper()
Expand All @@ -18,6 +19,11 @@ void RegDumper::LogRegRead(uint64_t phi_counter_now, uint8_t regnum)
{
RegDumpEntry entry{};

if (first_access) {
printf("First %s access, clk_counter: 0x%llx\n", regdump_target, phi_counter_now);
first_access = false;
}

uint64_t delta = phi_counter_now - SavedPHICounter;
if (delta > 0xffffffff)
{
Expand All @@ -43,6 +49,11 @@ void RegDumper::LogRegWrite(uint64_t phi_counter_now, uint8_t regnum, uint8_t va
{
RegDumpEntry entry{};

if (first_access) {
printf("First %s access, clk_counter: 0x%llx\n", regdump_target, phi_counter_now);
first_access = false;
}

uint64_t delta = phi_counter_now - SavedPHICounter;
if (delta > 0xffffffff)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ class RegDumper
{
uint64_t SavedPHICounter;
FILE* regLogFile;
char regdump_target[32];
bool first_access = true;

public:
RegDumper(uint64_t phi_counter_now, char* filename);
RegDumper(const char* target, uint64_t phi_counter_now, char* filename);
~RegDumper();

void LogRegRead(uint64_t phi_counter_now, uint8_t regnum);
Expand Down
4 changes: 2 additions & 2 deletions Breaknes/BreaksCore/Scripts/VS2022/BreaksCore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</ClCompile>
<ClCompile Include="..\..\PPUPlayerBoard.cpp" />
<ClCompile Include="..\..\PPUPlayerBoardDebug.cpp" />
<ClCompile Include="..\..\RegDump.cpp" />
<ClCompile Include="..\..\RegDumpEmitter.cpp" />
<ClCompile Include="..\..\SignalDefs.cpp" />
</ItemGroup>
<ItemGroup>
Expand All @@ -58,7 +58,7 @@
<ClInclude Include="..\..\NESBoard.h" />
<ClInclude Include="..\..\pch.h" />
<ClInclude Include="..\..\PPUPlayerBoard.h" />
<ClInclude Include="..\..\RegDump.h" />
<ClInclude Include="..\..\RegDumpEmitter.h" />
<ClInclude Include="..\..\SignalDefs.h" />
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Breaknes/BreaksCore/Scripts/VS2022/BreaksCore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<ClCompile Include="..\..\SignalDefs.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\RegDump.cpp">
<ClCompile Include="..\..\RegDumpEmitter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
Expand Down Expand Up @@ -116,7 +116,7 @@
<ClInclude Include="..\..\BreaksCore.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\RegDump.h">
<ClInclude Include="..\..\RegDumpEmitter.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Breaknes/BreaksCore/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

// Boards

#include "RegDump.h"
#include "RegDumpEmitter.h"
#include "SignalDefs.h"
#include "AbstractBoard.h"
#include "BogusBoard.h"
Expand Down
16 changes: 8 additions & 8 deletions BreaksAPU/APUPlayer/FormAbout.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

// TBD: Other APU revisions

// The software PHI counter is triggered by the falling edge.
// The software PHI counter is triggered by the raising edge.
// This is purely a software design for convenience, and has nothing to do with APU hardware circuitry.

if (IsNegedge(prev_phi, new_phi))
if (IsPosedge(prev_phi, new_phi))
{
apu->phi_counter++;
}
Expand Down
2 changes: 2 additions & 0 deletions BreaksAPU/FastAPU/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ A priori fast version of APUSim, so as not to confuse code with "fast" branches.
- No debugging yet

Otherwise, the code structure is the same as in APUSim, so don't get lost.

WIP.
4 changes: 2 additions & 2 deletions BreaksPPU/PPUPlayer/FormAbout.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion BreaksPPU/PPUPlayer/FormAbout.resx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
<data name="pictureBox1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAA4IAAAEYCAIAAACGCd86AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
wgAADsIBFShKgAAA7ttJREFUeF7s/Xe8FEXa/o8/f/++y3SamXNIioiKAZWcJUuOkrPkDCJBBCQJigKK
wQAADsEBuJFr7QAA7ttJREFUeF7s/Xe8FEXa/o8/f/++y3SamXNIioiKAZWcJUuOkrPkDCJBBCQJigKK
mHPOOee8q7u6urq7rq45EUwourvP80n87qq7p6f6rq6e6p6eOefAzOv9urio01XTM9NddZ379Mz81/8v
e6o+/19MWsak6hDhd7WIVgFUV2DUq1Dj1K9QRsiTX6HskCno8IUsSS5k8aoxyIJehyERKwIk1GlBAqSK
aDE0HuLeoI+iLdFzfL6wsifd76niC6PyuVcuxJcS8eiXfZGKqHw02CRCPFfZl0gRla9pxMUm3NchRYrx
Expand Down
4 changes: 2 additions & 2 deletions Common/BaseBoardLib/Fake6502.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ using namespace BaseLogic;

namespace M6502Core
{
FakeM6502::FakeM6502(uint16_t regs_base, uint8_t regs_mask) : M6502()
FakeM6502::FakeM6502(const char* target, uint16_t regs_base, uint16_t regs_mask) : M6502()
{
rp = new BaseBoard::RegDumpProcessor(regs_base, regs_mask);
rp = new BaseBoard::RegDumpProcessor(target, regs_base, regs_mask);
}

FakeM6502::~FakeM6502()
Expand Down
2 changes: 1 addition & 1 deletion Common/BaseBoardLib/Fake6502.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace M6502Core
BaseBoard::RegDumpProcessor* rp = nullptr;

public:
FakeM6502(uint16_t regs_base, uint8_t regs_mask);
FakeM6502(const char* target, uint16_t regs_base, uint16_t regs_mask);
~FakeM6502();

void sim(BaseLogic::TriState inputs[], BaseLogic::TriState outputs[], uint16_t* addr_bus, uint8_t* data_bus);
Expand Down
22 changes: 15 additions & 7 deletions Common/BaseBoardLib/RegDumpProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ using namespace BaseLogic;

namespace BaseBoard
{
RegDumpProcessor::RegDumpProcessor(uint16_t regs_base, uint8_t regs_mask)
RegDumpProcessor::RegDumpProcessor(const char* target, uint16_t regs_base, uint16_t regs_mask)
{
regbase = regs_base;
regmask = regs_mask;
strcpy(regdump_target, target);
}

RegDumpProcessor::~RegDumpProcessor()
Expand All @@ -20,19 +21,19 @@ namespace BaseBoard

void RegDumpProcessor::sim(TriState CLK, TriState n_RES, TriState& RnW, uint16_t* addr_bus, uint8_t* data_bus)
{
if (n_RES == TriState::Zero)
{
return;
}

// Increase the cycle counter

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

if (n_RES == TriState::Zero)
{
return;
}

// It is necessary to repeat the register operation during the whole current cycle, no matter how many times the simulation was called

if (hold)
Expand Down Expand Up @@ -60,6 +61,12 @@ namespace BaseBoard
}
*addr_bus = regbase | (current->reg & regmask);

if (first_access) {

printf("First %s access, clk_counter: 0x%llx\n", regdump_target, clk_counter);
first_access = false;
}

if (dump_regops) {

if (dump_4015_writes_only) {
Expand Down Expand Up @@ -132,6 +139,7 @@ namespace BaseBoard

clk_counter = 0;
PrevCLK = TriState::X;
first_access = true;
}

RegDumpEntry* RegDumpProcessor::GetCurrentEntry()
Expand Down
7 changes: 5 additions & 2 deletions Common/BaseBoardLib/RegDumpProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace BaseBoard
class RegDumpProcessor
{
uint16_t regbase = 0x1000; // e.g. 0x4000 - APU, 0x2000 - PPU
uint8_t regmask = 0x7f; // e.g. 0x1f - APU, 0x7 - PPU
uint16_t regmask = 0x7f; // e.g. 0x1f - APU, 0x7 - PPU
uint8_t* regdump = nullptr;
size_t regdump_size = 0;
size_t regdump_entry = 0;
Expand All @@ -34,8 +34,11 @@ namespace BaseBoard

const bool dump_4015_writes_only = false; // The most interesting

char regdump_target[32];
bool first_access = true;

public:
RegDumpProcessor(uint16_t regs_base, uint8_t regs_mask);
RegDumpProcessor(const char *target, uint16_t regs_base, uint16_t regs_mask);
~RegDumpProcessor();

void sim(BaseLogic::TriState CLK, BaseLogic::TriState n_RES, BaseLogic::TriState& RnW, uint16_t* addr_bus, uint8_t* data_bus);
Expand Down
2 changes: 1 addition & 1 deletion Common/SharpTools/IIR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public void Reconfigure (float SampleRate, float cutoff_freq)
delta = 1.0f / SampleRate;
float time_const = (float)(1.0 / (2.0 * Math.PI * cutoff_freq));
alpha = delta / (time_const + delta);
Console.WriteLine("IIR Reconfigured delta: {0}, alpha: {0}", delta, alpha);
Console.WriteLine("IIR Reconfigured delta: {0}, alpha: {1}", delta, alpha);
}

public void Input (float sample)
Expand Down
2 changes: 2 additions & 0 deletions Demos/DumpRegdump/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.regdump
*.txt
Loading
Loading