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

8 Samples per PCLK in RAW/Composite View #194

Merged
merged 3 commits into from
Jun 15, 2022
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: 2 additions & 0 deletions BreaksPPU/PPUPlayer/FormCompositeViewer.Designer.cs

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

33 changes: 13 additions & 20 deletions BreaksPPU/PPUPlayer/FormCompositeViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,11 @@ public FormCompositeViewer(string filename)
}
}

private void FormCompositeViewer_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
Close();
}
}

void ResetVisualize()
{
PPUPlayerInterop.GetSignalFeatures(out ppu_features);

// In Logisim the samples are sampled every CLK, not every half-cycle as in combat. Therefore, you must divide by 2.
SamplesPerScan = ppu_features.PixelsPerScan * ppu_features.SamplesPerPCLK / 2;
SamplesPerScan = ppu_features.PixelsPerScan * ppu_features.SamplesPerPCLK;
ScanBuffer = new PPUPlayerInterop.VideoOutSample[2 * SamplesPerScan];
WritePtr = 0;

Expand Down Expand Up @@ -136,9 +127,6 @@ void ProcessScanComposite()
float normalize_factor = 1.0f / ppu_features.WhiteLevel;
PPUPlayerInterop.VideoOutSample[] batch = new PPUPlayerInterop.VideoOutSample[num_phases];

// In Logisim the samples are sampled every CLK, not every half-cycle as in combat. Therefore, you must divide by 2.
int SamplesPerPixelInLogisimDump = ppu_features.SamplesPerPCLK / 2;

// Skip HSync

while (ScanBuffer[ReadPtr].composite <= ppu_features.SyncLevel)
Expand All @@ -150,7 +138,7 @@ void ProcessScanComposite()

int cb_phase = PLL();

ReadPtr += ppu_features.BackPorchSize * SamplesPerPixelInLogisimDump;
ReadPtr += ppu_features.BackPorchSize * ppu_features.SamplesPerPCLK;

// Output the visible part of the signal

Expand All @@ -160,7 +148,7 @@ void ProcessScanComposite()
{
// Extract the median sample batch

int MidPtr = ReadPtr + i * SamplesPerPixelInLogisimDump - num_phases / 2;
int MidPtr = ReadPtr + i * ppu_features.SamplesPerPCLK - num_phases / 2;

for (int n = 0; n < num_phases; n++)
{
Expand All @@ -171,7 +159,7 @@ void ProcessScanComposite()

float Y = 0, I = 0, Q = 0;

float ofs = i * SamplesPerPixelInLogisimDump;
float ofs = i * ppu_features.SamplesPerPCLK;

// TBD: For now, a hack to tweak Hue. Interestingly, PPUSim does not require this tweaking.
float hue_adj = 0.35f;
Expand Down Expand Up @@ -209,12 +197,9 @@ void ProcessScanComposite()

int PLL()
{
// In Logisim the samples are sampled every CLK, not every half-cycle as in combat. Therefore, you must divide by 2.
int SamplesPerPixelInLogisimDump = ppu_features.SamplesPerPCLK / 2;

int ReadPtr = SyncPos;
int num_phases = 12;
int samples = ppu_features.BackPorchSize * SamplesPerPixelInLogisimDump;
int samples = ppu_features.BackPorchSize * ppu_features.SamplesPerPCLK;

// Skip HSync

Expand Down Expand Up @@ -301,5 +286,13 @@ private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
int n = comboBox1.SelectedIndex;
ShowField(n);
}

private void FormCompositeViewer_KeyDown_1(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
Close();
}
}
}
}
10 changes: 3 additions & 7 deletions BreaksPPU/PPUPlayer/FormRawViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ void ResetVisualize()
{
PPUPlayerInterop.GetSignalFeatures(out ppu_features);

// In Logisim the samples are sampled every CLK, not every half-cycle as in combat. Therefore, you must divide by 2.
SamplesPerScan = ppu_features.PixelsPerScan * ppu_features.SamplesPerPCLK / 2;
SamplesPerScan = ppu_features.PixelsPerScan * ppu_features.SamplesPerPCLK;
ScanBuffer = new PPUPlayerInterop.VideoOutSample[2 * SamplesPerScan];
WritePtr = 0;

Expand Down Expand Up @@ -118,17 +117,14 @@ void ProcessScanRAW()
{
int ReadPtr = SyncPos;

// In Logisim the samples are sampled every CLK, not every half-cycle as in combat. Therefore, you must divide by 2.
int SamplesPerPixelInLogisimDump = ppu_features.SamplesPerPCLK / 2;

// Skip HSync and Back Porch

while ((ScanBuffer[ReadPtr].raw & 0b1000000000) != 0)
{
ReadPtr++;
}

ReadPtr += ppu_features.BackPorchSize * SamplesPerPixelInLogisimDump;
ReadPtr += ppu_features.BackPorchSize * ppu_features.SamplesPerPCLK;

// Output the visible part of the signal

Expand All @@ -142,7 +138,7 @@ void ProcessScanRAW()
field[CurrentScan * 256 + i] = Color.FromArgb(r, g, b);
}

ReadPtr += SamplesPerPixelInLogisimDump;
ReadPtr += ppu_features.SamplesPerPCLK;
}

CurrentScan++;
Expand Down