Turn the AbstractColourPalette into a templated class, so I can use Monogame "Color" type later on.
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
parent
5a7a3b5019
commit
fc84e05839
|
@ -3,14 +3,14 @@
|
|||
// </copyright>
|
||||
namespace EightBit.GameBoy
|
||||
{
|
||||
public class AbstractColourPalette
|
||||
public class AbstractColourPalette<T>
|
||||
{
|
||||
private readonly uint[] colours = new uint[4];
|
||||
|
||||
protected AbstractColourPalette()
|
||||
{
|
||||
}
|
||||
|
||||
public uint Colour(int index) => this.colours[index];
|
||||
protected T[] Colours { get; } = new T[4];
|
||||
|
||||
public T Colour(int index) => this.Colours[index];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,12 +102,12 @@ namespace EightBit.GameBoy
|
|||
{
|
||||
this.enabledLCD = (this.IO.Peek(IoRegisters.LCDC) & (byte)LcdcControl.LcdEnable) != 0;
|
||||
this.IO.ResetLY();
|
||||
return this.RunRasterLines(Display.RasterHeight);
|
||||
return this.RunRasterLines(DisplayCharacteristics.RasterHeight);
|
||||
}
|
||||
|
||||
public int RunVerticalBlankLines()
|
||||
{
|
||||
var lines = TotalLineCount - Display.RasterHeight;
|
||||
var lines = TotalLineCount - DisplayCharacteristics.RasterHeight;
|
||||
return this.RunVerticalBlankLines(lines);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,25 +3,17 @@
|
|||
// </copyright>
|
||||
namespace EightBit.GameBoy
|
||||
{
|
||||
public sealed class Display
|
||||
public sealed class Display<T>
|
||||
{
|
||||
public static readonly int BufferWidth = 256;
|
||||
public static readonly int BufferHeight = 256;
|
||||
public static readonly int BufferCharacterWidth = BufferWidth / 8;
|
||||
public static readonly int BufferCharacterHeight = BufferHeight / 8;
|
||||
public static readonly int RasterWidth = 160;
|
||||
public static readonly int RasterHeight = 144;
|
||||
public static readonly int PixelCount = RasterWidth * RasterHeight;
|
||||
|
||||
private readonly Bus bus;
|
||||
private readonly Ram oam;
|
||||
private readonly Ram vram;
|
||||
private readonly AbstractColourPalette colours;
|
||||
private readonly AbstractColourPalette<T> colours;
|
||||
private readonly ObjectAttribute[] objectAttributes = new ObjectAttribute[40];
|
||||
private byte control;
|
||||
private byte scanLine = 0;
|
||||
|
||||
public Display(AbstractColourPalette colours, Bus bus, Ram oam, Ram vram)
|
||||
public Display(AbstractColourPalette<T> colours, Bus bus, Ram oam, Ram vram)
|
||||
{
|
||||
this.colours = colours;
|
||||
this.bus = bus;
|
||||
|
@ -29,12 +21,12 @@ namespace EightBit.GameBoy
|
|||
this.vram = vram;
|
||||
}
|
||||
|
||||
public uint[] Pixels { get; } = new uint[PixelCount];
|
||||
public T[] Pixels { get; } = new T[DisplayCharacteristics.PixelCount];
|
||||
|
||||
public void Render()
|
||||
{
|
||||
this.scanLine = this.bus.IO.Peek(IoRegisters.LY);
|
||||
if (this.scanLine < RasterHeight)
|
||||
if (this.scanLine < DisplayCharacteristics.RasterHeight)
|
||||
{
|
||||
this.control = this.bus.IO.Peek(IoRegisters.LCDC);
|
||||
if ((this.control & (byte)LcdcControl.LcdEnable) != 0)
|
||||
|
@ -95,9 +87,9 @@ namespace EightBit.GameBoy
|
|||
private void RenderBackground(int bgArea, int bgCharacters, int offsetX, int offsetY, int[] palette)
|
||||
{
|
||||
var row = (this.scanLine - offsetY) / 8;
|
||||
var address = bgArea + (row * BufferCharacterWidth);
|
||||
var address = bgArea + (row * DisplayCharacteristics.BufferCharacterWidth);
|
||||
|
||||
for (var column = 0; column < BufferCharacterWidth; ++column)
|
||||
for (var column = 0; column < DisplayCharacteristics.BufferCharacterWidth; ++column)
|
||||
{
|
||||
var character = this.vram.Peek((ushort)address++);
|
||||
var definition = new CharacterDefinition(this.vram, (ushort)(bgCharacters + (16 * character)));
|
||||
|
@ -154,11 +146,11 @@ namespace EightBit.GameBoy
|
|||
|
||||
var rowDefinition = definition.Get(cy);
|
||||
|
||||
var lineAddress = y * RasterWidth;
|
||||
var lineAddress = y * DisplayCharacteristics.RasterWidth;
|
||||
for (var cx = 0; cx < width; ++cx)
|
||||
{
|
||||
var x = drawX + (flipX ? ~cx & flipMaskX : cx);
|
||||
if (x >= RasterWidth)
|
||||
if (x >= DisplayCharacteristics.RasterWidth)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
// <copyright file="DisplayCharacteristics.cs" company="Adrian Conlon">
|
||||
// Copyright (c) Adrian Conlon. All rights reserved.
|
||||
// </copyright>
|
||||
namespace EightBit.GameBoy
|
||||
{
|
||||
public static class DisplayCharacteristics
|
||||
{
|
||||
public const int BufferWidth = 256;
|
||||
public const int BufferHeight = 256;
|
||||
|
||||
public const int BufferCharacterWidth = BufferWidth / 8;
|
||||
public const int BufferCharacterHeight = BufferHeight / 8;
|
||||
|
||||
public const int RasterWidth = 160;
|
||||
public const int RasterHeight = 144;
|
||||
|
||||
public const int PixelCount = RasterWidth * RasterHeight;
|
||||
}
|
||||
}
|
|
@ -41,6 +41,7 @@
|
|||
<Compile Include="Disassembler.cs" />
|
||||
<Compile Include="Display.cs" />
|
||||
<Compile Include="Bus.cs" />
|
||||
<Compile Include="DisplayCharacteristics.cs" />
|
||||
<Compile Include="Interrupts.cs" />
|
||||
<Compile Include="IoRegisters.cs" />
|
||||
<Compile Include="LcdcControl.cs" />
|
||||
|
@ -62,8 +63,6 @@
|
|||
<AdditionalFiles Include="stylecop.json" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Analyzer Include="..\packages\StyleCop.Analyzers.1.1.118\analyzers\dotnet\cs\StyleCop.Analyzers.CodeFixes.dll" />
|
||||
<Analyzer Include="..\packages\StyleCop.Analyzers.1.1.118\analyzers\dotnet\cs\StyleCop.Analyzers.dll" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -7,8 +7,8 @@ namespace EightBit.GameBoy
|
|||
|
||||
public class LcdStatusModeEventArgs : EventArgs
|
||||
{
|
||||
public LcdStatusModeEventArgs(LcdStatusMode value) => this.LcdStatusMode = value;
|
||||
public LcdStatusModeEventArgs(LcdStatusMode value) => this.Mode = value;
|
||||
|
||||
public LcdStatusMode LcdStatusMode { get; }
|
||||
public LcdStatusMode Mode { get; }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue