Skip to content

Commit

Permalink
Merge pull request #277 from ogamespec/main
Browse files Browse the repository at this point in the history
NSFBoard completed
  • Loading branch information
ogamespec authored Feb 10, 2023
2 parents 7646579 + 4bab5c3 commit 139fdf9
Show file tree
Hide file tree
Showing 23 changed files with 626 additions and 100 deletions.
57 changes: 56 additions & 1 deletion Breaknes/Breaknes/BreaksCoreInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ public class DebugInfoEntry
[DllImport("BreaksCore.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void GetDebugInfo(DebugInfoType type, IntPtr entries);

[DllImport("NSFPlayerInterop.dll", CallingConvention = CallingConvention.Cdecl)]
static extern int GetDebugInfoByName(DebugInfoType type, ref DebugInfoEntryRaw entry);

[DllImport("NSFPlayerInterop.dll", CallingConvention = CallingConvention.Cdecl)]
static extern int SetDebugInfoByName(DebugInfoType type, ref DebugInfoEntryRaw entry);

[DllImport("BreaksCore.dll", CallingConvention = CallingConvention.Cdecl)]
static extern int GetMemLayout();

Expand Down Expand Up @@ -214,6 +220,55 @@ public static List<DebugInfoEntry> GetTestDebugInfo()

return list;
}
}

public static UInt32 GetDebugInfoByName(DebugInfoType type, string category, string name)
{
DebugInfoEntryRaw entry = new();

unsafe
{
for (int i = 0; i < 32; i++)
{
if (i < category.Length)
entry.category[i] = (byte)category[i];
else
entry.category[i] = 0;

if (i < name.Length)
entry.name[i] = (byte)name[i];
else
entry.name[i] = 0;
}
}

GetDebugInfoByName(type, ref entry);

return entry.value;
}

public static void SetDebugInfoByName(DebugInfoType type, string category, string name, UInt32 value)
{
DebugInfoEntryRaw entry = new();

unsafe
{
for (int i = 0; i < 32; i++)
{
if (i < category.Length)
entry.category[i] = (byte)category[i];
else
entry.category[i] = 0;

if (i < name.Length)
entry.name[i] = (byte)name[i];
else
entry.name[i] = 0;
}
}

entry.value = value;

SetDebugInfoByName(type, ref entry);
}
}
}
7 changes: 5 additions & 2 deletions Breaks6502/M6502Core/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,12 @@ namespace M6502Core
info->ACR = ToByte(alu->getACR());
info->AVR = ToByte(alu->getAVR());

for (size_t n = 0; n < Decoder::outputs_count; n++)
if (decoder_out != nullptr)
{
info->decoder_out[n] = ToByte(decoder_out[n]);
for (size_t n = 0; n < Decoder::outputs_count; n++)
{
info->decoder_out[n] = ToByte(decoder_out[n]);
}
}

info->Y_SB = cmd.Y_SB;
Expand Down
41 changes: 29 additions & 12 deletions BreaksAPU/APUSim/dpcm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,23 @@ namespace APUSim
{
n_ACLK2 = NOT(apu->wire.ACLK);

// TBD: Rearrange propagation delays while debugging APUSim in combat conditions.

sim_SampleCounterReg();
sim_ControlReg();
sim_Decoder1();
sim_Decoder2();

sim_FreqLFSR();

sim_IntControl();
sim_EnableControl();
sim_DMAControl();
sim_SampleCounterControl();
sim_SampleBufferControl();

sim_Decoder1();
sim_Decoder2();
sim_FreqLFSR();
sim_SampleCounterReg();
sim_SampleCounterControl();
sim_SampleCounter();
sim_SampleBitCounter();

sim_SampleBufferControl();
sim_SampleBuffer();

sim_AddressReg();
Expand Down Expand Up @@ -79,7 +81,7 @@ namespace APUSim
TriState W4015 = apu->wire.W4015;
TriState n_R4015 = apu->wire.n_R4015;
TriState RES = apu->wire.RES;
TriState PCMDone = DMC1;
TriState PCMDone = get_DMC1();

sout_latch.set(SOUT, n_ACLK);
DMC2 = sout_latch.get();
Expand All @@ -95,8 +97,8 @@ namespace APUSim
TriState PHI1 = apu->wire.PHI1;
TriState RnW = apu->wire.RnW;
TriState RES = apu->wire.RES;
TriState nDMCEnableDelay = CTRL2;
TriState nDMAStop = CTRL1;
TriState nDMCEnableDelay = get_CTRL2();
TriState nDMAStop = get_CTRL1();

run_latch1.set(start_ff.get(), n_ACLK2);
run_latch2.set(run_latch1.nget(), n_ACLK);
Expand All @@ -113,7 +115,7 @@ namespace APUSim
{
TriState ACLK = apu->wire.ACLK;
TriState n_ACLK = apu->wire.n_ACLK;
TriState PCMDone = DMC1;
TriState PCMDone = get_DMC1();
TriState DMCFinish = DMC2;
TriState DMCEnable = ED2;

Expand Down Expand Up @@ -155,6 +157,21 @@ namespace APUSim
BSTEP = NOR(n_DFLOAD, NOT(n_NOUT));
}

TriState DpcmChan::get_CTRL1()
{
return stop_ff.nget();
}

TriState DpcmChan::get_CTRL2()
{
return en_latch3.nget();
}

TriState DpcmChan::get_DMC1()
{
return NOR(pcm_latch.get(), NOT(n_ACLK2));
}

#pragma endregion "DPCM Control"

#pragma region "DPCM Sampling"
Expand Down
4 changes: 4 additions & 0 deletions BreaksAPU/APUSim/dpcm.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ namespace APUSim
void sim_AddressCounter();
void sim_Output();

BaseLogic::TriState get_CTRL1();
BaseLogic::TriState get_CTRL2();
BaseLogic::TriState get_DMC1();

public:
DpcmChan(APU* parent);
~DpcmChan();
Expand Down
25 changes: 19 additions & 6 deletions BreaksAPU/NSFPlayer/FormMain.Designer.cs

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

44 changes: 43 additions & 1 deletion BreaksAPU/NSFPlayer/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ private void FormMain_Load(object sender, EventArgs e)
SetPaused(true);

backgroundWorker1.RunWorkerAsync();

signalPlot1.ForceMinMax(true, -0.5f, +2.0f);
}

private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -123,10 +125,34 @@ private void InitBoard(string nsf_filename)

var settings = FormSettings.LoadSettings();
NSFPlayerInterop.CreateBoard("NSFPlayer", settings.APU_Revision, "None", "None");

// Setup NSF

bool bank_switching = false;
for (int i=0; i<8; i++)
{
if (nsf.GetHead().Bankswitch[i] != 0)
{
bank_switching = true;
break;
}
}

NSFPlayerInterop.LoadNSFData(nsf.GetData(), nsf.GetData().Length, nsf.GetHead().LoadAddress);
NSFPlayerInterop.EnableNSFBanking(bank_switching);

var head = nsf.GetHead();
for (int i = 0; i < 8; i++)
{
BreaksCore.SetDebugInfoByName(
BreaksCore.DebugInfoType.DebugInfoType_Board,
"NSFPlayer Board", "Bank" + i.ToString(), head.Bankswitch[i]);
}

UpdateMemLayout();

// Autoplay
SetPaused(false);
SetPaused(!settings.AutoPlay);
}

private void DisposeBoard()
Expand Down Expand Up @@ -440,6 +466,21 @@ void UpdateMemLayout()
UpdateMemLayoutInProgress = false;
}

/// <summary>
/// A tool for short-range debugging.
/// Step-by-step execution of the simulation. Available only if the worker is stopped.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button3_Click(object sender, EventArgs e)
{
if (Paused && nsf_loaded)
{
NSFPlayerInterop.Step();
Button2Click();
}
}

#endregion "APU Debug"


Expand Down Expand Up @@ -508,5 +549,6 @@ private void toolStripButton1_Click(object sender, EventArgs e)

#endregion "What's that for?"


}
}
6 changes: 6 additions & 0 deletions BreaksAPU/NSFPlayer/FormSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ static APUPlayerSettings SetDefaultSettings()

settings.APU_Revision = "RP2A03G";
settings.OutputSampleRate = 48000;
settings.AutoPlay = true;

SaveSettings(settings);

Expand Down Expand Up @@ -99,6 +100,11 @@ public class APUPlayerSettings
[Category("Host Features")]
[Description("The AUX output is sampled at a high frequency, which cannot be played by a ordinary sound card. Therefore, some of the samples are skipped to match the DSound playback frequency (this setting).")]
public int OutputSampleRate { get; set; }

[XmlElement]
[Category("Host Features")]
[Description("Automatically start the simulation after loading the NSF")]
public bool AutoPlay { get; set; }
}

// https://stackoverflow.com/questions/24503462/how-to-show-drop-down-control-in-property-grid
Expand Down
Loading

0 comments on commit 139fdf9

Please sign in to comment.