From c18aeb9e63c6c022267fa1b997e7785fc539c87d Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Sat, 11 Nov 2017 11:12:09 +0000 Subject: [PATCH] More updates from the CPP core guidelines Signed-off-by: Adrian Conlon --- LR35902/inc/CharacterDefinition.h | 6 +++--- LR35902/inc/Display.h | 4 ++-- LR35902/inc/GameBoyBus.h | 30 ++++++++++++++--------------- LR35902/inc/IoRegisters.h | 28 +++++++++++++-------------- LR35902/inc/LR35902.h | 6 +++--- LR35902/inc/ObjectAttribute.h | 2 +- LR35902/src/CharacterDefinition.cpp | 5 ----- LR35902/src/Display.cpp | 4 +--- LR35902/src/GameBoyBus.cpp | 17 +--------------- LR35902/src/IoRegisters.cpp | 16 +-------------- LR35902/src/LR35902.cpp | 5 +---- LR35902/src/ObjectAttribute.cpp | 3 --- 12 files changed, 42 insertions(+), 84 deletions(-) diff --git a/LR35902/inc/CharacterDefinition.h b/LR35902/inc/CharacterDefinition.h index 8448771..1580c74 100644 --- a/LR35902/inc/CharacterDefinition.h +++ b/LR35902/inc/CharacterDefinition.h @@ -10,14 +10,14 @@ namespace EightBit { namespace GameBoy { class CharacterDefinition { public: - CharacterDefinition(); + CharacterDefinition() = default; CharacterDefinition(Ram* ram, uint16_t address); std::array get(int row) const; private: - Ram* m_ram; - uint16_t m_address; + Ram* m_ram = nullptr; + uint16_t m_address = ~0; }; } } \ No newline at end of file diff --git a/LR35902/inc/Display.h b/LR35902/inc/Display.h index b6565e8..03966bc 100644 --- a/LR35902/inc/Display.h +++ b/LR35902/inc/Display.h @@ -42,8 +42,8 @@ namespace EightBit { Ram& m_vram; const AbstractColourPalette* m_colours; std::array m_objectAttributes; - uint8_t m_control; - uint8_t m_scanLine; + uint8_t m_control = 0; + uint8_t m_scanLine = 0; std::array createPalette(int address); diff --git a/LR35902/inc/GameBoyBus.h b/LR35902/inc/GameBoyBus.h index 8c847ef..74d0d75 100644 --- a/LR35902/inc/GameBoyBus.h +++ b/LR35902/inc/GameBoyBus.h @@ -60,29 +60,29 @@ namespace EightBit { private: LR35902 m_cpu; - Rom m_bootRom; // 0x0000 - 0x00ff + Rom m_bootRom = 0x100; // 0x0000 - 0x00ff std::vector m_gameRomBanks; // 0x0000 - 0x3fff, 0x4000 - 0x7fff (switchable) - Ram m_videoRam; // 0x8000 - 0x9fff + Ram m_videoRam = 0x2000; // 0x8000 - 0x9fff std::vector m_ramBanks; // 0xa000 - 0xbfff (switchable) - Ram m_lowInternalRam; // 0xc000 - 0xdfff (mirrored at 0xe000) - Ram m_oamRam; // 0xfe00 - 0xfe9f + Ram m_lowInternalRam = 0x2000; // 0xc000 - 0xdfff (mirrored at 0xe000) + Ram m_oamRam = 0xa0; // 0xfe00 - 0xfe9f IoRegisters m_ioPorts; // 0xff00 - 0xff7f - Ram m_highInternalRam; // 0xff80 - 0xffff + Ram m_highInternalRam = 0x80; // 0xff80 - 0xffff - bool m_enabledLCD; + bool m_enabledLCD = false; - bool m_disableGameRom; + bool m_disableGameRom = false; - bool m_rom; - bool m_banked; - bool m_ram; - bool m_battery; + bool m_rom = false; + bool m_banked = false; + bool m_ram = false; + bool m_battery = false; - bool m_higherRomBank; - bool m_ramBankSwitching; + bool m_higherRomBank = true; + bool m_ramBankSwitching = false; - int m_romBank; - int m_ramBank; + int m_romBank = 1; + int m_ramBank = 0; void validateCartridgeType(); diff --git a/LR35902/inc/IoRegisters.h b/LR35902/inc/IoRegisters.h index ff66953..9123dab 100644 --- a/LR35902/inc/IoRegisters.h +++ b/LR35902/inc/IoRegisters.h @@ -166,24 +166,24 @@ namespace EightBit { private: Bus& m_bus; - bool m_disableBootRom; + bool m_disableBootRom = false; - register16_t m_divCounter; - int m_timerCounter; - int m_timerRate; + register16_t m_divCounter = { 0xab, 0xcc }; + int m_timerCounter = 0; + int m_timerRate = 0; - register16_t m_dmaAddress; - bool m_dmaTransferActive; + register16_t m_dmaAddress = { 0, 0 }; + bool m_dmaTransferActive = false; - bool m_scanP15; - bool m_scanP14; + bool m_scanP15 = false; + bool m_scanP14 = false; - bool m_p15; // misc keys - bool m_p14; // direction keys - bool m_p13; // down/start - bool m_p12; // up/select - bool m_p11; // left/b - bool m_p10; // right/a + bool m_p15 = true; // misc keys + bool m_p14 = true; // direction keys + bool m_p13 = true; // down/start + bool m_p12 = true; // up/select + bool m_p11 = true; // left/b + bool m_p10 = true; // right/a void checkTimer(int cycles); diff --git a/LR35902/inc/LR35902.h b/LR35902/inc/LR35902.h index 2742812..2c71c51 100644 --- a/LR35902/inc/LR35902.h +++ b/LR35902/inc/LR35902.h @@ -55,10 +55,10 @@ namespace EightBit { register16_t de; register16_t hl; - bool m_ime; - bool m_stopped; + bool m_ime = false; + bool m_stopped = false; - bool m_prefixCB; + bool m_prefixCB = false; bool& IME() { return m_ime; } diff --git a/LR35902/inc/ObjectAttribute.h b/LR35902/inc/ObjectAttribute.h index 99da0f9..e6d5529 100644 --- a/LR35902/inc/ObjectAttribute.h +++ b/LR35902/inc/ObjectAttribute.h @@ -11,7 +11,7 @@ namespace EightBit { namespace GameBoy { class ObjectAttribute { public: - ObjectAttribute(); + ObjectAttribute() = default; ObjectAttribute(Ram& ram, uint16_t address); uint8_t positionY() const { return m_positionY; } diff --git a/LR35902/src/CharacterDefinition.cpp b/LR35902/src/CharacterDefinition.cpp index 5e68fdc..cf885a5 100644 --- a/LR35902/src/CharacterDefinition.cpp +++ b/LR35902/src/CharacterDefinition.cpp @@ -3,11 +3,6 @@ #include -EightBit::GameBoy::CharacterDefinition::CharacterDefinition() -: m_ram(nullptr), - m_address(~0) { -} - EightBit::GameBoy::CharacterDefinition::CharacterDefinition(Ram* ram, uint16_t address) : m_ram(ram), m_address(address) { diff --git a/LR35902/src/Display.cpp b/LR35902/src/Display.cpp index 3c83b1d..7489a65 100644 --- a/LR35902/src/Display.cpp +++ b/LR35902/src/Display.cpp @@ -12,9 +12,7 @@ EightBit::GameBoy::Display::Display(const AbstractColourPalette* colours, Bus& b : m_bus(bus), m_oam(oam), m_vram(vram), - m_colours(colours), - m_control(0), - m_scanLine(0) { + m_colours(colours) { } const std::vector& EightBit::GameBoy::Display::pixels() const { diff --git a/LR35902/src/GameBoyBus.cpp b/LR35902/src/GameBoyBus.cpp index 6ab71bc..11b66c9 100644 --- a/LR35902/src/GameBoyBus.cpp +++ b/LR35902/src/GameBoyBus.cpp @@ -4,24 +4,9 @@ EightBit::GameBoy::Bus::Bus() : m_cpu(*this), - m_bootRom(0x100), m_gameRomBanks(1), - m_videoRam(0x2000), m_ramBanks(0), - m_lowInternalRam(0x2000), - m_oamRam(0xa0), - m_ioPorts(*this), - m_highInternalRam(0x80), - m_enabledLCD(false), - m_disableGameRom(false), - m_rom(false), - m_banked(false), - m_ram(false), - m_battery(false), - m_higherRomBank(true), - m_ramBankSwitching(false), - m_romBank(1), - m_ramBank(0) { + m_ioPorts(*this) { WrittenByte.connect(std::bind(&GameBoy::Bus::Bus_WrittenByte, this, std::placeholders::_1)); } diff --git a/LR35902/src/IoRegisters.cpp b/LR35902/src/IoRegisters.cpp index f49ce59..3a61f41 100644 --- a/LR35902/src/IoRegisters.cpp +++ b/LR35902/src/IoRegisters.cpp @@ -4,23 +4,9 @@ EightBit::GameBoy::IoRegisters::IoRegisters(Bus& bus) : Ram(0x80), - m_bus(bus), - m_disableBootRom(false), - m_timerCounter(0), - m_timerRate(0), - m_dmaTransferActive(false), - m_scanP15(false), - m_scanP14(false), - m_p15(true), - m_p14(true), - m_p13(true), - m_p12(true), - m_p11(true), - m_p10(true) { + m_bus(bus) { m_bus.ReadingByte.connect(std::bind(&IoRegisters::Bus_ReadingByte, this, std::placeholders::_1)); m_bus.WrittenByte.connect(std::bind(&IoRegisters::Bus_WrittenByte, this, std::placeholders::_1)); - m_divCounter.word = 0xabcc; - m_dmaAddress.word = 0; } void EightBit::GameBoy::IoRegisters::reset() { diff --git a/LR35902/src/LR35902.cpp b/LR35902/src/LR35902.cpp index 930f129..5387067 100644 --- a/LR35902/src/LR35902.cpp +++ b/LR35902/src/LR35902.cpp @@ -6,10 +6,7 @@ EightBit::GameBoy::LR35902::LR35902(Bus& memory) : IntelProcessor(memory), - m_bus(memory), - m_ime(false), - m_stopped(false), - m_prefixCB(false) { + m_bus(memory) { } void EightBit::GameBoy::LR35902::reset() { diff --git a/LR35902/src/ObjectAttribute.cpp b/LR35902/src/ObjectAttribute.cpp index bf37c71..18dc652 100644 --- a/LR35902/src/ObjectAttribute.cpp +++ b/LR35902/src/ObjectAttribute.cpp @@ -3,9 +3,6 @@ #include -EightBit::GameBoy::ObjectAttribute::ObjectAttribute() { -} - EightBit::GameBoy::ObjectAttribute::ObjectAttribute(Ram& ram, uint16_t address) { m_positionY = ram.peek(address); m_positionX = ram.peek(++address);