This commit is contained in:
Brett Sanderson 2016-03-05 17:01:16 -05:00
parent 628ad531af
commit ab3f7de52c
4 changed files with 35 additions and 33 deletions

View File

@ -13,14 +13,14 @@ namespace CdgLib
{
private const int ColourTableSize = 16;
private const int CdgPacketSize = 24;
private const int PacketSize = 24;
private const int TileHeight = 12;
private const int TileWidth = 6;
public const int FullWidth = 300;
public const int FullHeight = 216;
private readonly int[] _mColourTable = new int[ColourTableSize];
private readonly byte[,] _mPixelColours = new byte[FullHeight, FullWidth];
private readonly int[] _colourTable = new int[ColourTableSize];
private readonly byte[,] _pixelColours = new byte[FullHeight, FullWidth];
private long _previousPosition;
@ -31,13 +31,13 @@ namespace CdgLib
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)
{
if (position < 0)
{
position = _previousPosition + CdgPacketSize;
position = _previousPosition + PacketSize;
}
if (position < _previousPosition)
@ -68,12 +68,12 @@ namespace CdgLib
private async Task<IEnumerable<Packet>> ReadSubCodeAsync(long numberOfPackets)
{
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);
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);
}
return subCodePackets;
@ -92,11 +92,11 @@ namespace CdgLib
if (ri < TileHeight || ri >= FullHeight - TileHeight || ci < TileWidth ||
ci >= FullWidth - TileWidth)
{
// _mPSurface.RgbData[ri, ci] = _mColourTable[_mBorderColourIndex];
// _mPSurface.RgbData[ri, ci] = _colourTable[_mBorderColourIndex];
}
else
{
_mPSurface.RgbData[ri, ci] = _mColourTable[_mPixelColours[ri + _mVOffset, ci + _mHOffset]];
_mPSurface.RgbData[ri, ci] = _colourTable[_pixelColours[ri + _mVOffset, ci + _mHOffset]];
}
}
}

View File

@ -1,7 +1,7 @@
namespace CdgLib.SubCode
{
internal enum Command : byte
public enum Command
{
Graphic = 0x9
Graphic = 9
}
}

View File

@ -3,7 +3,7 @@
/// <summary>
///
/// </summary>
internal enum Instruction
public enum Instruction
{
/// <summary>
/// Set the screen to a particular color.

View File

@ -4,18 +4,21 @@ namespace CdgLib.SubCode
{
public class Packet
{
public byte[] Command = new byte[1];
public byte[] Data = new byte[16];
public byte[] Instruction = new byte[1];
public byte[] ParityP = new byte[4];
public byte[] ParityQ = new byte[2];
public Command Command { get; }
public Instruction Instruction { get; }
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)
{
Array.Copy(data, 0, Command, 0, 1);
Array.Copy(data, 1, Instruction, 0, 1);
Command = (Command)(data[0] & 0x3F);
Instruction = (Instruction)(data[1] & 0x3F);
Array.Copy(data, 2, ParityQ, 0, 2);
Array.Copy(data, 4, Data, 0, 16);
Array.Copy(data, 20, ParityP, 0, 4);
@ -23,35 +26,34 @@ namespace CdgLib.SubCode
public void ApplyTransform(int[,] data)
{
if ((Command[0] & Mask) != (int) SubCode.Command.Graphic) return;
var instructionCode = (Instruction)(Instruction[0] & Mask);
switch (instructionCode)
if (Command != Command.Graphic) return;
switch (Instruction)
{
case SubCode.Instruction.MemoryPreset:
case Instruction.MemoryPreset:
MemoryPreset(data);
break;
case SubCode.Instruction.BorderPreset:
case Instruction.BorderPreset:
BorderPreset(data);
break;
case SubCode.Instruction.TileBlockNormal:
case Instruction.TileBlockNormal:
TileBlock(data,false);
break;
case SubCode.Instruction.ScrollPreset:
case Instruction.ScrollPreset:
Scroll(data,false);
break;
case SubCode.Instruction.ScrollCopy:
case Instruction.ScrollCopy:
Scroll(data,true);
break;
case SubCode.Instruction.DefineTransparentColor:
case Instruction.DefineTransparentColor:
DefineTransparentColour(data);
break;
case SubCode.Instruction.LoadColorTableLower:
case Instruction.LoadColorTableLower:
LoadColorTable(data,0);
break;
case SubCode.Instruction.LoadColorTableUpper:
case Instruction.LoadColorTableUpper:
LoadColorTable(data,1);
break;
case SubCode.Instruction.TileBlockXor:
case Instruction.TileBlockXor:
TileBlock(data,true);
break;
}