From 2b7d4dee3d105460e4a8d89f6eee2f93afea8a3f Mon Sep 17 00:00:00 2001 From: Riyyi Date: Wed, 31 Aug 2022 21:43:56 +0200 Subject: [PATCH] Emulator: Add LCDC register to PPU --- src/emu.cpp | 3 ++- src/ppu.cpp | 13 ++++++++++--- src/ppu.h | 17 ++++++++++++++++- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/emu.cpp b/src/emu.cpp index b4de96d..57f930e 100644 --- a/src/emu.cpp +++ b/src/emu.cpp @@ -69,7 +69,8 @@ void Emu::writeMemory(uint32_t address, uint32_t value) if (address == 0xff50) { Loader::the().disableBootrom(); } - else if (address >= memory.start_address && address <= memory.end_address) { + + if (address >= memory.start_address && address <= memory.end_address) { // Note: ECHO RAM hack if (address >= 0xc000 && address <= 0xddff) { writeMemory(address + (0xe000 - 0xc000), value); diff --git a/src/ppu.cpp b/src/ppu.cpp index c7c3569..ed584a9 100644 --- a/src/ppu.cpp +++ b/src/ppu.cpp @@ -5,11 +5,13 @@ * SPDX-License-Identifier: MIT */ +#include // uint32_t + +#include "emu.h" #include "ppu.h" #include "ruc/format/print.h" -#include -PPU ::PPU(unsigned int frequency) +PPU ::PPU(uint32_t frequency) : ProcessingUnit(frequency) { } @@ -20,5 +22,10 @@ PPU ::~PPU() void PPU::update() { - // print("ppu update\n"); + LCDC lcd_control = static_cast(Emu::the().readMemory(0xff40)); + if (!(lcd_control & LCDC::LCDandPPUEnable)) { + return; + } + + print("PPU update\n"); } diff --git a/src/ppu.h b/src/ppu.h index 8c243a9..ba17cef 100644 --- a/src/ppu.h +++ b/src/ppu.h @@ -7,11 +7,26 @@ #pragma once +#include // uint8_t, uint32_t + #include "processing-unit.h" +#include "ruc/meta/core.h" + +enum LCDC : uint8_t { + None = 0, + BGandWindowEnable = BIT(0), + OBJEnable = BIT(1), + OBJSize = BIT(2), // 0 = 8x8, 1 = 8x16 + BGTileMapArea = BIT(3), // 0 = 9800-9bff, 1 = 9c00-9fff + BGandWindowTileDataArea = BIT(4), // 0 = 8800-97ff, 1 = 8000-8fff + WindowEnable = BIT(5), // + WindowTileMapArea = BIT(6), // 0 = 9800-9bff, 1 = 9c00-9fff + LCDandPPUEnable = BIT(7), +}; class PPU final : public ProcessingUnit { public: - PPU(unsigned int frequency); + PPU(uint32_t frequency); virtual ~PPU(); virtual void update() override;