From fc84e05839624875c93948fb0589890f883dc7b8 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Sun, 28 Jul 2019 23:43:22 +0100 Subject: [PATCH] Turn the AbstractColourPalette into a templated class, so I can use Monogame "Color" type later on. Signed-off-by: Adrian Conlon --- LR35902/AbstractColourPalette.cs | 8 ++++---- LR35902/Bus.cs | 4 ++-- LR35902/Display.cs | 26 +++++++++----------------- LR35902/DisplayCharacteristics.cs | 19 +++++++++++++++++++ LR35902/LR35902.csproj | 3 +-- LR35902/LcdStatusModeEventArgs.cs | 4 ++-- 6 files changed, 37 insertions(+), 27 deletions(-) create mode 100644 LR35902/DisplayCharacteristics.cs diff --git a/LR35902/AbstractColourPalette.cs b/LR35902/AbstractColourPalette.cs index 5afbb90..efd42ba 100644 --- a/LR35902/AbstractColourPalette.cs +++ b/LR35902/AbstractColourPalette.cs @@ -3,14 +3,14 @@ // namespace EightBit.GameBoy { - public class AbstractColourPalette + public class AbstractColourPalette { - 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]; } } diff --git a/LR35902/Bus.cs b/LR35902/Bus.cs index b4086d2..7a57717 100644 --- a/LR35902/Bus.cs +++ b/LR35902/Bus.cs @@ -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); } diff --git a/LR35902/Display.cs b/LR35902/Display.cs index 20132a6..70e03dc 100644 --- a/LR35902/Display.cs +++ b/LR35902/Display.cs @@ -3,25 +3,17 @@ // namespace EightBit.GameBoy { - public sealed class Display + public sealed class Display { - 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 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 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; } diff --git a/LR35902/DisplayCharacteristics.cs b/LR35902/DisplayCharacteristics.cs new file mode 100644 index 0000000..1513669 --- /dev/null +++ b/LR35902/DisplayCharacteristics.cs @@ -0,0 +1,19 @@ +// +// Copyright (c) Adrian Conlon. All rights reserved. +// +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; + } +} diff --git a/LR35902/LR35902.csproj b/LR35902/LR35902.csproj index 5b16bc1..da9b741 100644 --- a/LR35902/LR35902.csproj +++ b/LR35902/LR35902.csproj @@ -41,6 +41,7 @@ + @@ -62,8 +63,6 @@ - - \ No newline at end of file diff --git a/LR35902/LcdStatusModeEventArgs.cs b/LR35902/LcdStatusModeEventArgs.cs index 5c987e5..a09c61b 100644 --- a/LR35902/LcdStatusModeEventArgs.cs +++ b/LR35902/LcdStatusModeEventArgs.cs @@ -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; } } }