Address review comments

This commit is contained in:
Matt Nadareski
2022-02-11 13:23:33 -08:00
parent 2ab1be864d
commit 2efd0fa40c
4 changed files with 36 additions and 46 deletions

View File

@@ -68,12 +68,11 @@ namespace RedBookPlayer.Models.Hardware.Karaoke
public void DebugPrintScreen()
{
string screenDump = string.Empty;
for(int y = 0; y < 216; y++)
{
for(int x = 0; x < 300; x++)
{
screenDump += $"{this.DisplayData[x,y]:X}";
}
screenDump += Environment.NewLine;
}
@@ -94,34 +93,42 @@ namespace RedBookPlayer.Models.Hardware.Karaoke
var memoryPreset = new MemPreset(packet.Data);
SetScreenColor(memoryPreset);
break;
case SubchannelInstruction.BorderPreset:
var borderPreset = new BorderPreset(packet.Data);
SetBorderColor(borderPreset);
break;
case SubchannelInstruction.TileBlockNormal:
var tileBlockNormal = new TileBlock(packet.Data);
LoadTileBlock(tileBlockNormal, false);
break;
case SubchannelInstruction.ScrollPreset:
var scrollPreset = new Scroll(packet.Data);
ScrollDisplay(scrollPreset, false);
break;
case SubchannelInstruction.ScrollCopy:
var scrollCopy = new Scroll(packet.Data);
ScrollDisplay(scrollCopy, true);
break;
case SubchannelInstruction.DefineTransparentColor:
var transparentColor = new BorderPreset(packet.Data);
this.TransparentColor = transparentColor.Color;
break;
case SubchannelInstruction.LoadColorTableLower:
var loadColorTableLower = new LoadCLUT(packet.Data);
LoadColorTable(loadColorTableLower, false);
break;
case SubchannelInstruction.LoadColorTableUpper:
var loadColorTableUpper = new LoadCLUT(packet.Data);
LoadColorTable(loadColorTableUpper, true);
break;
case SubchannelInstruction.TileBlockXOR:
var tileBlockXor = new TileBlock(packet.Data);
LoadTileBlock(tileBlockXor, true);
@@ -155,10 +162,8 @@ namespace RedBookPlayer.Models.Hardware.Karaoke
for(int x = 3; x < 297; x++)
for(int y = 6; y < 210; y++)
{
this.DisplayData[x,y] = memPreset.Color;
}
}
/// <summary>
/// Set the border to a particular color
@@ -175,28 +180,20 @@ namespace RedBookPlayer.Models.Hardware.Karaoke
for(int x = 0; x < 3; x++)
for(int y = 0; y < 216; y++)
{
this.DisplayData[x,y] = borderPreset.Color;
}
for(int x = 297; x < 300; x++)
for(int y = 0; y < 216; y++)
{
this.DisplayData[x,y] = borderPreset.Color;
}
for(int x = 0; x < 300; x++)
for(int y = 0; y < 6; y++)
{
this.DisplayData[x,y] = borderPreset.Color;
}
for(int x = 0; x < 300; x++)
for(int y = 210; y < 216; y++)
{
this.DisplayData[x,y] = borderPreset.Color;
}
}
/// <summary>
/// Load a block of pixels with a certain pattern
@@ -246,7 +243,7 @@ namespace RedBookPlayer.Models.Hardware.Karaoke
/// <param name="copy">True if data wraps around on scroll, false if filled by a solid color</param>
private void ScrollDisplay(Scroll scroll, bool copy)
{
if(scroll == null)
if(scroll == null || scroll.HScrollOffset < 0 || scroll.VScrollOffset < 0)
return;
// Derive the scroll values based on offsets
@@ -260,6 +257,7 @@ namespace RedBookPlayer.Models.Hardware.Karaoke
for(int y = 0; y < 216; y++)
{
byte[] overflow = new byte[hOffsetTotal];
for(int x = 299; x >= 0; x--)
{
if(x + hOffsetTotal >= 300)
@@ -270,16 +268,15 @@ namespace RedBookPlayer.Models.Hardware.Karaoke
// Fill in the now-empty pixels
for(int i = 0; i < hOffsetTotal; i++)
{
this.DisplayData[i,y] = copy ? overflow[i] : scroll.Color;
}
}
}
else if(scroll.HScrollCommand == ScrollCommand.Negative)
{
for(int y = 0; y < 216; y++)
{
byte[] overflow = new byte[hOffsetTotal];
for(int x = 0; x < 300; x++)
{
if(x - hOffsetTotal < 0)
@@ -290,11 +287,9 @@ namespace RedBookPlayer.Models.Hardware.Karaoke
// Fill in the now-empty pixels
for(int i = 299; i > 299 - hOffsetTotal; i++)
{
this.DisplayData[i,y] = copy ? overflow[i] : scroll.Color;
}
}
}
// If we're scrolling vertically
if(scroll.VScrollCommand == ScrollCommand.Positive
@@ -303,6 +298,7 @@ namespace RedBookPlayer.Models.Hardware.Karaoke
for(int x = 0; x < 300; x++)
{
byte[] overflow = new byte[vOffsetTotal];
for(int y = 215; y >= 0; y--)
{
if(y + vOffsetTotal >= 216)
@@ -313,16 +309,15 @@ namespace RedBookPlayer.Models.Hardware.Karaoke
// Fill in the now-empty pixels
for(int i = 0; i < vOffsetTotal; i++)
{
this.DisplayData[x,i] = copy ? overflow[i] : scroll.Color;
}
}
}
else if(scroll.VScrollCommand == ScrollCommand.Negative)
{
for(int x = 0; x < 300; x++)
{
byte[] overflow = new byte[vOffsetTotal];
for(int y = 0; y < 216; y++)
{
if(y - vOffsetTotal < 0)
@@ -333,12 +328,10 @@ namespace RedBookPlayer.Models.Hardware.Karaoke
// Fill in the now-empty pixels
for(int i = 215; i > 215 - vOffsetTotal; i++)
{
this.DisplayData[x,i] = copy ? overflow[i] : scroll.Color;
}
}
}
}
/// <summary>
/// Load either the upper or lower half of the color table

View File

@@ -17,9 +17,7 @@ namespace RedBookPlayer.Models.Hardware.Karaoke
return;
for(int i = 0; i < 8; i++)
{
this.ColorSpec[i] = (short)(BitConverter.ToInt16(bytes, 2 * i) & 0x3F3F);
}
}
}
}

View File

@@ -32,9 +32,7 @@ namespace RedBookPlayer.Models.Hardware.Karaoke
this.Column = (byte)(bytes[3] & 0x3F);
for(int i = 0; i < 12; i++)
{
this.TilePixels[i] = (byte)(bytes[4 + i] & 0x3F);
}
}
}
}

View File

@@ -1369,13 +1369,14 @@ namespace RedBookPlayer.Models.Hardware
/// </summary>
/// <param name="subchannelData">Raw subchannel data to format</param>
/// <returns>Dictionary mapping subchannel to formatted data</returns>
private Dictionary<char, byte[]> ConvertSubchannels(byte[] subchannelData)
Dictionary<char, byte[]> ConvertSubchannels(byte[] subchannelData)
{
if(subchannelData == null || subchannelData.Length % 96 != 0)
return null;
// Parse the subchannel data, if possible
var parsedSubchannelData = ParseSubchannels(subchannelData);
return ConvertSubchannels(parsedSubchannelData);
}