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() public void DebugPrintScreen()
{ {
string screenDump = string.Empty; string screenDump = string.Empty;
for(int y = 0; y < 216; y++) for(int y = 0; y < 216; y++)
{ {
for(int x = 0; x < 300; x++) for(int x = 0; x < 300; x++)
{
screenDump += $"{this.DisplayData[x,y]:X}"; screenDump += $"{this.DisplayData[x,y]:X}";
}
screenDump += Environment.NewLine; screenDump += Environment.NewLine;
} }
@@ -94,34 +93,42 @@ namespace RedBookPlayer.Models.Hardware.Karaoke
var memoryPreset = new MemPreset(packet.Data); var memoryPreset = new MemPreset(packet.Data);
SetScreenColor(memoryPreset); SetScreenColor(memoryPreset);
break; break;
case SubchannelInstruction.BorderPreset: case SubchannelInstruction.BorderPreset:
var borderPreset = new BorderPreset(packet.Data); var borderPreset = new BorderPreset(packet.Data);
SetBorderColor(borderPreset); SetBorderColor(borderPreset);
break; break;
case SubchannelInstruction.TileBlockNormal: case SubchannelInstruction.TileBlockNormal:
var tileBlockNormal = new TileBlock(packet.Data); var tileBlockNormal = new TileBlock(packet.Data);
LoadTileBlock(tileBlockNormal, false); LoadTileBlock(tileBlockNormal, false);
break; break;
case SubchannelInstruction.ScrollPreset: case SubchannelInstruction.ScrollPreset:
var scrollPreset = new Scroll(packet.Data); var scrollPreset = new Scroll(packet.Data);
ScrollDisplay(scrollPreset, false); ScrollDisplay(scrollPreset, false);
break; break;
case SubchannelInstruction.ScrollCopy: case SubchannelInstruction.ScrollCopy:
var scrollCopy = new Scroll(packet.Data); var scrollCopy = new Scroll(packet.Data);
ScrollDisplay(scrollCopy, true); ScrollDisplay(scrollCopy, true);
break; break;
case SubchannelInstruction.DefineTransparentColor: case SubchannelInstruction.DefineTransparentColor:
var transparentColor = new BorderPreset(packet.Data); var transparentColor = new BorderPreset(packet.Data);
this.TransparentColor = transparentColor.Color; this.TransparentColor = transparentColor.Color;
break; break;
case SubchannelInstruction.LoadColorTableLower: case SubchannelInstruction.LoadColorTableLower:
var loadColorTableLower = new LoadCLUT(packet.Data); var loadColorTableLower = new LoadCLUT(packet.Data);
LoadColorTable(loadColorTableLower, false); LoadColorTable(loadColorTableLower, false);
break; break;
case SubchannelInstruction.LoadColorTableUpper: case SubchannelInstruction.LoadColorTableUpper:
var loadColorTableUpper = new LoadCLUT(packet.Data); var loadColorTableUpper = new LoadCLUT(packet.Data);
LoadColorTable(loadColorTableUpper, true); LoadColorTable(loadColorTableUpper, true);
break; break;
case SubchannelInstruction.TileBlockXOR: case SubchannelInstruction.TileBlockXOR:
var tileBlockXor = new TileBlock(packet.Data); var tileBlockXor = new TileBlock(packet.Data);
LoadTileBlock(tileBlockXor, true); LoadTileBlock(tileBlockXor, true);
@@ -154,10 +161,8 @@ namespace RedBookPlayer.Models.Hardware.Karaoke
return; return;
for(int x = 3; x < 297; x++) for(int x = 3; x < 297; x++)
for(int y = 6; y < 210; y++) for(int y = 6; y < 210; y++)
{ this.DisplayData[x,y] = memPreset.Color;
this.DisplayData[x,y] = memPreset.Color;
}
} }
/// <summary> /// <summary>
@@ -174,28 +179,20 @@ namespace RedBookPlayer.Models.Hardware.Karaoke
return; return;
for(int x = 0; x < 3; x++) for(int x = 0; x < 3; x++)
for(int y = 0; y < 216; y++) for(int y = 0; y < 216; y++)
{ this.DisplayData[x,y] = borderPreset.Color;
this.DisplayData[x,y] = borderPreset.Color;
}
for(int x = 297; x < 300; x++) for(int x = 297; x < 300; x++)
for(int y = 0; y < 216; y++) for(int y = 0; y < 216; y++)
{ this.DisplayData[x,y] = borderPreset.Color;
this.DisplayData[x,y] = borderPreset.Color;
}
for(int x = 0; x < 300; x++) for(int x = 0; x < 300; x++)
for(int y = 0; y < 6; y++) for(int y = 0; y < 6; y++)
{ this.DisplayData[x,y] = borderPreset.Color;
this.DisplayData[x,y] = borderPreset.Color;
}
for(int x = 0; x < 300; x++) for(int x = 0; x < 300; x++)
for(int y = 210; y < 216; y++) for(int y = 210; y < 216; y++)
{ this.DisplayData[x,y] = borderPreset.Color;
this.DisplayData[x,y] = borderPreset.Color;
}
} }
/// <summary> /// <summary>
@@ -226,17 +223,17 @@ namespace RedBookPlayer.Models.Hardware.Karaoke
// Now load the bitmap starting in the correct place // Now load the bitmap starting in the correct place
for(int x = 0; x < 12; x++) for(int x = 0; x < 12; x++)
for(int y = 0; y < 6; y++) for(int y = 0; y < 6; y++)
{ {
int adjustedX = x + tileBlock.Column; int adjustedX = x + tileBlock.Column;
int adjustedY = y + tileBlock.Row; int adjustedY = y + tileBlock.Row;
byte colorIndex = pattern[x,y] == 0 ? tileBlock.Color0 : tileBlock.Color1; byte colorIndex = pattern[x,y] == 0 ? tileBlock.Color0 : tileBlock.Color1;
if(xor) if(xor)
this.DisplayData[adjustedX, adjustedY] = (byte)(colorIndex ^ this.DisplayData[adjustedX, adjustedY]); this.DisplayData[adjustedX, adjustedY] = (byte)(colorIndex ^ this.DisplayData[adjustedX, adjustedY]);
else else
this.DisplayData[adjustedX, adjustedY] = colorIndex; this.DisplayData[adjustedX, adjustedY] = colorIndex;
} }
} }
/// <summary> /// <summary>
@@ -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> /// <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) private void ScrollDisplay(Scroll scroll, bool copy)
{ {
if(scroll == null) if(scroll == null || scroll.HScrollOffset < 0 || scroll.VScrollOffset < 0)
return; return;
// Derive the scroll values based on offsets // Derive the scroll values based on offsets
@@ -260,6 +257,7 @@ namespace RedBookPlayer.Models.Hardware.Karaoke
for(int y = 0; y < 216; y++) for(int y = 0; y < 216; y++)
{ {
byte[] overflow = new byte[hOffsetTotal]; byte[] overflow = new byte[hOffsetTotal];
for(int x = 299; x >= 0; x--) for(int x = 299; x >= 0; x--)
{ {
if(x + hOffsetTotal >= 300) if(x + hOffsetTotal >= 300)
@@ -270,9 +268,7 @@ namespace RedBookPlayer.Models.Hardware.Karaoke
// Fill in the now-empty pixels // Fill in the now-empty pixels
for(int i = 0; i < hOffsetTotal; i++) for(int i = 0; i < hOffsetTotal; i++)
{
this.DisplayData[i,y] = copy ? overflow[i] : scroll.Color; this.DisplayData[i,y] = copy ? overflow[i] : scroll.Color;
}
} }
} }
else if(scroll.HScrollCommand == ScrollCommand.Negative) else if(scroll.HScrollCommand == ScrollCommand.Negative)
@@ -280,6 +276,7 @@ namespace RedBookPlayer.Models.Hardware.Karaoke
for(int y = 0; y < 216; y++) for(int y = 0; y < 216; y++)
{ {
byte[] overflow = new byte[hOffsetTotal]; byte[] overflow = new byte[hOffsetTotal];
for(int x = 0; x < 300; x++) for(int x = 0; x < 300; x++)
{ {
if(x - hOffsetTotal < 0) if(x - hOffsetTotal < 0)
@@ -290,9 +287,7 @@ namespace RedBookPlayer.Models.Hardware.Karaoke
// Fill in the now-empty pixels // Fill in the now-empty pixels
for(int i = 299; i > 299 - hOffsetTotal; i++) for(int i = 299; i > 299 - hOffsetTotal; i++)
{
this.DisplayData[i,y] = copy ? overflow[i] : scroll.Color; this.DisplayData[i,y] = copy ? overflow[i] : scroll.Color;
}
} }
} }
@@ -303,6 +298,7 @@ namespace RedBookPlayer.Models.Hardware.Karaoke
for(int x = 0; x < 300; x++) for(int x = 0; x < 300; x++)
{ {
byte[] overflow = new byte[vOffsetTotal]; byte[] overflow = new byte[vOffsetTotal];
for(int y = 215; y >= 0; y--) for(int y = 215; y >= 0; y--)
{ {
if(y + vOffsetTotal >= 216) if(y + vOffsetTotal >= 216)
@@ -313,9 +309,7 @@ namespace RedBookPlayer.Models.Hardware.Karaoke
// Fill in the now-empty pixels // Fill in the now-empty pixels
for(int i = 0; i < vOffsetTotal; i++) for(int i = 0; i < vOffsetTotal; i++)
{
this.DisplayData[x,i] = copy ? overflow[i] : scroll.Color; this.DisplayData[x,i] = copy ? overflow[i] : scroll.Color;
}
} }
} }
else if(scroll.VScrollCommand == ScrollCommand.Negative) else if(scroll.VScrollCommand == ScrollCommand.Negative)
@@ -323,6 +317,7 @@ namespace RedBookPlayer.Models.Hardware.Karaoke
for(int x = 0; x < 300; x++) for(int x = 0; x < 300; x++)
{ {
byte[] overflow = new byte[vOffsetTotal]; byte[] overflow = new byte[vOffsetTotal];
for(int y = 0; y < 216; y++) for(int y = 0; y < 216; y++)
{ {
if(y - vOffsetTotal < 0) if(y - vOffsetTotal < 0)
@@ -333,9 +328,7 @@ namespace RedBookPlayer.Models.Hardware.Karaoke
// Fill in the now-empty pixels // Fill in the now-empty pixels
for(int i = 215; i > 215 - vOffsetTotal; i++) for(int i = 215; i > 215 - vOffsetTotal; i++)
{
this.DisplayData[x,i] = copy ? overflow[i] : scroll.Color; this.DisplayData[x,i] = copy ? overflow[i] : scroll.Color;
}
} }
} }
} }

View File

@@ -17,9 +17,7 @@ namespace RedBookPlayer.Models.Hardware.Karaoke
return; return;
for(int i = 0; i < 8; i++) for(int i = 0; i < 8; i++)
{
this.ColorSpec[i] = (short)(BitConverter.ToInt16(bytes, 2 * i) & 0x3F3F); 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); this.Column = (byte)(bytes[3] & 0x3F);
for(int i = 0; i < 12; i++) for(int i = 0; i < 12; i++)
{
this.TilePixels[i] = (byte)(bytes[4 + i] & 0x3F); this.TilePixels[i] = (byte)(bytes[4 + i] & 0x3F);
}
} }
} }
} }

View File

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