Refactor
This commit is contained in:
parent
628ad531af
commit
ab3f7de52c
@ -13,14 +13,14 @@ namespace CdgLib
|
|||||||
{
|
{
|
||||||
private const int ColourTableSize = 16;
|
private const int ColourTableSize = 16;
|
||||||
|
|
||||||
private const int CdgPacketSize = 24;
|
private const int PacketSize = 24;
|
||||||
private const int TileHeight = 12;
|
private const int TileHeight = 12;
|
||||||
private const int TileWidth = 6;
|
private const int TileWidth = 6;
|
||||||
public const int FullWidth = 300;
|
public const int FullWidth = 300;
|
||||||
public const int FullHeight = 216;
|
public const int FullHeight = 216;
|
||||||
|
|
||||||
private readonly int[] _mColourTable = new int[ColourTableSize];
|
private readonly int[] _colourTable = new int[ColourTableSize];
|
||||||
private readonly byte[,] _mPixelColours = new byte[FullHeight, FullWidth];
|
private readonly byte[,] _pixelColours = new byte[FullHeight, FullWidth];
|
||||||
|
|
||||||
|
|
||||||
private long _previousPosition;
|
private long _previousPosition;
|
||||||
@ -31,13 +31,13 @@ namespace CdgLib
|
|||||||
|
|
||||||
public bool Transparent => true;
|
public bool Transparent => true;
|
||||||
|
|
||||||
public long Duration => Length/CdgPacketSize*1000/300;
|
public long Duration => Length/PacketSize*1000/300;
|
||||||
|
|
||||||
public async Task<Bitmap> RenderAtTime(long position = -1)
|
public async Task<Bitmap> RenderAtTime(long position = -1)
|
||||||
{
|
{
|
||||||
if (position < 0)
|
if (position < 0)
|
||||||
{
|
{
|
||||||
position = _previousPosition + CdgPacketSize;
|
position = _previousPosition + PacketSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (position < _previousPosition)
|
if (position < _previousPosition)
|
||||||
@ -68,12 +68,12 @@ namespace CdgLib
|
|||||||
private async Task<IEnumerable<Packet>> ReadSubCodeAsync(long numberOfPackets)
|
private async Task<IEnumerable<Packet>> ReadSubCodeAsync(long numberOfPackets)
|
||||||
{
|
{
|
||||||
var subCodePackets = new List<Packet>();
|
var subCodePackets = new List<Packet>();
|
||||||
var buffer = new byte[CdgPacketSize*numberOfPackets];
|
var buffer = new byte[PacketSize*numberOfPackets];
|
||||||
var bytesRead = await ReadAsync(buffer, 0, buffer.Length);
|
var bytesRead = await ReadAsync(buffer, 0, buffer.Length);
|
||||||
|
|
||||||
for (var i = 0; i < bytesRead/CdgPacketSize; i++)
|
for (var i = 0; i < bytesRead/PacketSize; i++)
|
||||||
{
|
{
|
||||||
var subCodePacket = new Packet(buffer.Skip(i* CdgPacketSize).Take(CdgPacketSize).ToArray());
|
var subCodePacket = new Packet(buffer.Skip(i* PacketSize).Take(PacketSize).ToArray());
|
||||||
subCodePackets.Add(subCodePacket);
|
subCodePackets.Add(subCodePacket);
|
||||||
}
|
}
|
||||||
return subCodePackets;
|
return subCodePackets;
|
||||||
@ -92,11 +92,11 @@ namespace CdgLib
|
|||||||
if (ri < TileHeight || ri >= FullHeight - TileHeight || ci < TileWidth ||
|
if (ri < TileHeight || ri >= FullHeight - TileHeight || ci < TileWidth ||
|
||||||
ci >= FullWidth - TileWidth)
|
ci >= FullWidth - TileWidth)
|
||||||
{
|
{
|
||||||
// _mPSurface.RgbData[ri, ci] = _mColourTable[_mBorderColourIndex];
|
// _mPSurface.RgbData[ri, ci] = _colourTable[_mBorderColourIndex];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_mPSurface.RgbData[ri, ci] = _mColourTable[_mPixelColours[ri + _mVOffset, ci + _mHOffset]];
|
_mPSurface.RgbData[ri, ci] = _colourTable[_pixelColours[ri + _mVOffset, ci + _mHOffset]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
namespace CdgLib.SubCode
|
namespace CdgLib.SubCode
|
||||||
{
|
{
|
||||||
internal enum Command : byte
|
public enum Command
|
||||||
{
|
{
|
||||||
Graphic = 0x9
|
Graphic = 9
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal enum Instruction
|
public enum Instruction
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set the screen to a particular color.
|
/// Set the screen to a particular color.
|
||||||
|
|||||||
@ -4,18 +4,21 @@ namespace CdgLib.SubCode
|
|||||||
{
|
{
|
||||||
public class Packet
|
public class Packet
|
||||||
{
|
{
|
||||||
public byte[] Command = new byte[1];
|
public Command Command { get; }
|
||||||
public byte[] Data = new byte[16];
|
|
||||||
public byte[] Instruction = new byte[1];
|
public Instruction Instruction { get; }
|
||||||
public byte[] ParityP = new byte[4];
|
|
||||||
public byte[] ParityQ = new byte[2];
|
public byte[] ParityQ { get; } = new byte[2];
|
||||||
|
|
||||||
|
public byte[] Data { get; } = new byte[16];
|
||||||
|
|
||||||
|
public byte[] ParityP { get; } = new byte[4];
|
||||||
|
|
||||||
private const byte Mask = 0x3f;
|
|
||||||
|
|
||||||
public Packet(byte[] data)
|
public Packet(byte[] data)
|
||||||
{
|
{
|
||||||
Array.Copy(data, 0, Command, 0, 1);
|
Command = (Command)(data[0] & 0x3F);
|
||||||
Array.Copy(data, 1, Instruction, 0, 1);
|
Instruction = (Instruction)(data[1] & 0x3F);
|
||||||
Array.Copy(data, 2, ParityQ, 0, 2);
|
Array.Copy(data, 2, ParityQ, 0, 2);
|
||||||
Array.Copy(data, 4, Data, 0, 16);
|
Array.Copy(data, 4, Data, 0, 16);
|
||||||
Array.Copy(data, 20, ParityP, 0, 4);
|
Array.Copy(data, 20, ParityP, 0, 4);
|
||||||
@ -23,35 +26,34 @@ namespace CdgLib.SubCode
|
|||||||
|
|
||||||
public void ApplyTransform(int[,] data)
|
public void ApplyTransform(int[,] data)
|
||||||
{
|
{
|
||||||
if ((Command[0] & Mask) != (int) SubCode.Command.Graphic) return;
|
if (Command != Command.Graphic) return;
|
||||||
var instructionCode = (Instruction)(Instruction[0] & Mask);
|
switch (Instruction)
|
||||||
switch (instructionCode)
|
|
||||||
{
|
{
|
||||||
case SubCode.Instruction.MemoryPreset:
|
case Instruction.MemoryPreset:
|
||||||
MemoryPreset(data);
|
MemoryPreset(data);
|
||||||
break;
|
break;
|
||||||
case SubCode.Instruction.BorderPreset:
|
case Instruction.BorderPreset:
|
||||||
BorderPreset(data);
|
BorderPreset(data);
|
||||||
break;
|
break;
|
||||||
case SubCode.Instruction.TileBlockNormal:
|
case Instruction.TileBlockNormal:
|
||||||
TileBlock(data,false);
|
TileBlock(data,false);
|
||||||
break;
|
break;
|
||||||
case SubCode.Instruction.ScrollPreset:
|
case Instruction.ScrollPreset:
|
||||||
Scroll(data,false);
|
Scroll(data,false);
|
||||||
break;
|
break;
|
||||||
case SubCode.Instruction.ScrollCopy:
|
case Instruction.ScrollCopy:
|
||||||
Scroll(data,true);
|
Scroll(data,true);
|
||||||
break;
|
break;
|
||||||
case SubCode.Instruction.DefineTransparentColor:
|
case Instruction.DefineTransparentColor:
|
||||||
DefineTransparentColour(data);
|
DefineTransparentColour(data);
|
||||||
break;
|
break;
|
||||||
case SubCode.Instruction.LoadColorTableLower:
|
case Instruction.LoadColorTableLower:
|
||||||
LoadColorTable(data,0);
|
LoadColorTable(data,0);
|
||||||
break;
|
break;
|
||||||
case SubCode.Instruction.LoadColorTableUpper:
|
case Instruction.LoadColorTableUpper:
|
||||||
LoadColorTable(data,1);
|
LoadColorTable(data,1);
|
||||||
break;
|
break;
|
||||||
case SubCode.Instruction.TileBlockXor:
|
case Instruction.TileBlockXor:
|
||||||
TileBlock(data,true);
|
TileBlock(data,true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user