From cac871cf2b79a75bf252d9b8e0b83c29f8883600 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Sun, 24 Jun 2018 20:58:20 +0100 Subject: [PATCH] Remove duplicated code (from const definitions) the performance benefit isn't worth the amount of duplicated code. Signed-off-by: Adrian Conlon --- Intel8080/inc/Disassembler.h | 6 +-- Intel8080/inc/Intel8080.h | 34 ------------- Intel8080/src/Disassembler.cpp | 6 +-- Intel8080/test/Board.cpp | 2 +- Intel8080/test/Board.h | 6 +-- LR35902/fusetest_LR35902/FuseTestRunner.h | 4 -- LR35902/inc/CharacterDefinition.h | 6 +-- LR35902/inc/Display.h | 2 +- LR35902/inc/GameBoyBus.h | 7 +-- LR35902/inc/LR35902.h | 9 ---- LR35902/src/CharacterDefinition.cpp | 4 +- LR35902/src/Display.cpp | 6 +-- LR35902/src/GameBoyBus.cpp | 42 +++------------- M6502/inc/mos6502.h | 6 --- M6502/test/Board.h | 4 -- Z80/fusetest_Z80/FuseTestRunner.h | 4 -- Z80/inc/Disassembler.h | 8 +-- Z80/inc/Z80.h | 59 ----------------------- Z80/src/Disassembler.cpp | 8 +-- Z80/src/Z80.cpp | 16 ------ Z80/test/Board.cpp | 4 +- Z80/test/Board.h | 10 ++-- inc/Bus.h | 9 ++-- inc/IntelProcessor.h | 14 ------ inc/Memory.h | 3 +- inc/Ram.h | 4 -- inc/Rom.h | 4 -- inc/Signal.h | 4 +- src/Bus.cpp | 10 ++-- src/InputOutput.cpp | 8 +-- 30 files changed, 50 insertions(+), 259 deletions(-) diff --git a/Intel8080/inc/Disassembler.h b/Intel8080/inc/Disassembler.h index e0985a7..993fbe0 100644 --- a/Intel8080/inc/Disassembler.h +++ b/Intel8080/inc/Disassembler.h @@ -12,8 +12,8 @@ namespace EightBit { public: Disassembler(); - static std::string state(const Intel8080& cpu); - std::string disassemble(const Intel8080& cpu); + static std::string state(Intel8080& cpu); + std::string disassemble(Intel8080& cpu); static std::string flag(uint8_t value, int flag, std::string represents, std::string off = "-"); static std::string flags(uint8_t value); @@ -26,7 +26,7 @@ namespace EightBit { private: mutable boost::format m_formatter; - void disassemble(std::ostringstream& output, const Intel8080& cpu, uint16_t pc); + void disassemble(std::ostringstream& output, Intel8080& cpu, uint16_t pc); void disassemble( std::ostringstream& output, diff --git a/Intel8080/inc/Intel8080.h b/Intel8080/inc/Intel8080.h index d37be25..cca4ed3 100644 --- a/Intel8080/inc/Intel8080.h +++ b/Intel8080/inc/Intel8080.h @@ -29,13 +29,9 @@ namespace EightBit { virtual int execute(uint8_t opcode) final; virtual int step() final; - virtual register16_t AF() const final; virtual register16_t& AF() final; - virtual register16_t BC() const final; virtual register16_t& BC() final; - virtual register16_t DE() const final; virtual register16_t& DE() final; - virtual register16_t HL() const final; virtual register16_t& HL() final; protected: @@ -105,21 +101,6 @@ namespace EightBit { } } - register16_t RP(int rp) const { - switch (rp) { - case 0b00: - return BC(); - case 0b01: - return DE(); - case 0b10: - return HL(); - case 0b11: - return SP(); - default: - UNREACHABLE; - } - } - register16_t& RP(int rp) { switch (rp) { case 0b00: @@ -135,21 +116,6 @@ namespace EightBit { } } - register16_t RP2(int rp) const { - switch (rp) { - case 0b00: - return BC(); - case 0b01: - return DE(); - case 0b10: - return HL(); - case 0b11: - return AF(); - default: - UNREACHABLE; - } - } - register16_t& RP2(int rp) { switch (rp) { case 0b00: diff --git a/Intel8080/src/Disassembler.cpp b/Intel8080/src/Disassembler.cpp index bf05a98..9b5537f 100644 --- a/Intel8080/src/Disassembler.cpp +++ b/Intel8080/src/Disassembler.cpp @@ -13,7 +13,7 @@ EightBit::Disassembler::Disassembler() { m_formatter.exceptions(boost::io::all_error_bits ^ boost::io::too_many_args_bit); } -std::string EightBit::Disassembler::state(const Intel8080& cpu) { +std::string EightBit::Disassembler::state(Intel8080& cpu) { auto pc = cpu.PC(); auto sp = cpu.SP(); @@ -160,13 +160,13 @@ std::string EightBit::Disassembler::alu2(int which) { throw std::logic_error("Unhandled alu operation"); } -std::string EightBit::Disassembler::disassemble(const Intel8080& cpu) { +std::string EightBit::Disassembler::disassemble(Intel8080& cpu) { std::ostringstream output; disassemble(output, cpu, cpu.PC().word); return output.str(); } -void EightBit::Disassembler::disassemble(std::ostringstream& output, const Intel8080& cpu, uint16_t pc) { +void EightBit::Disassembler::disassemble(std::ostringstream& output, Intel8080& cpu, uint16_t pc) { auto& bus = cpu.BUS(); auto opcode = bus.peek(pc); diff --git a/Intel8080/test/Board.cpp b/Intel8080/test/Board.cpp index 4a595e8..8a343c4 100644 --- a/Intel8080/test/Board.cpp +++ b/Intel8080/test/Board.cpp @@ -49,7 +49,7 @@ void Board::Cpu_ExecutingInstruction_Cpm(const EightBit::Intel8080& cpu) { } } -void Board::bdos() const { +void Board::bdos() { switch (CPU().C()) { case 0x2: { const auto character = CPU().E(); diff --git a/Intel8080/test/Board.h b/Intel8080/test/Board.h index 15e8d55..7419151 100644 --- a/Intel8080/test/Board.h +++ b/Intel8080/test/Board.h @@ -24,10 +24,6 @@ protected: return m_ram.reference(address); } - virtual uint8_t reference(uint16_t address) const { - return m_ram.reference(address); - } - private: const Configuration& m_configuration; EightBit::Ram m_ram = 0x10000; @@ -41,5 +37,5 @@ private: void Cpu_ExecutingInstruction_Debug(const EightBit::Intel8080& cpu); void Cpu_ExecutingInstruction_Profile(const EightBit::Intel8080& cpu); - void bdos() const; + void bdos(); }; diff --git a/LR35902/fusetest_LR35902/FuseTestRunner.h b/LR35902/fusetest_LR35902/FuseTestRunner.h index 6047186..f275f97 100644 --- a/LR35902/fusetest_LR35902/FuseTestRunner.h +++ b/LR35902/fusetest_LR35902/FuseTestRunner.h @@ -41,10 +41,6 @@ namespace Fuse { return m_ram.reference(address); } - virtual uint8_t reference(uint16_t address) const { - return m_ram.reference(address); - } - public: TestRunner(const Test& test, const ExpectedTestResult& expected); diff --git a/LR35902/inc/CharacterDefinition.h b/LR35902/inc/CharacterDefinition.h index 81751fe..6d4bd8c 100644 --- a/LR35902/inc/CharacterDefinition.h +++ b/LR35902/inc/CharacterDefinition.h @@ -10,12 +10,12 @@ namespace EightBit { namespace GameBoy { class CharacterDefinition final { public: - CharacterDefinition(const Ram& vram, uint16_t address); + CharacterDefinition(Ram& vram, uint16_t address); - std::array get(int row) const; + std::array get(int row); private: - const Ram& m_vram; + Ram& m_vram; uint16_t m_address = ~0; }; } diff --git a/LR35902/inc/Display.h b/LR35902/inc/Display.h index 27254a2..e2eb1ed 100644 --- a/LR35902/inc/Display.h +++ b/LR35902/inc/Display.h @@ -59,7 +59,7 @@ namespace EightBit { int drawX, int drawY, bool flipX, bool flipY, bool allowTransparencies, const std::array& palette, - const CharacterDefinition& definition); + CharacterDefinition& definition); }; } } \ No newline at end of file diff --git a/LR35902/inc/GameBoyBus.h b/LR35902/inc/GameBoyBus.h index 958c6fa..7833ceb 100644 --- a/LR35902/inc/GameBoyBus.h +++ b/LR35902/inc/GameBoyBus.h @@ -36,13 +36,9 @@ namespace EightBit { Bus(); LR35902& CPU() { return m_cpu; } - const LR35902& CPU() const { return m_cpu; } Ram& VRAM() { return m_videoRam; } - const Ram& VRAM() const { return m_videoRam; } Ram& OAMRAM() { return m_oamRam; } - const Ram& OAMRAM() const { return m_oamRam; } IoRegisters& IO() { return m_ioPorts; } - const IoRegisters& IO() const { return m_ioPorts; } void reset(); @@ -59,8 +55,7 @@ namespace EightBit { int runVerticalBlankLines(); protected: - virtual uint8_t& reference(uint16_t address, bool& rom); - virtual uint8_t reference(uint16_t address, bool& rom) const; + virtual uint8_t& reference(uint16_t address); private: LR35902 m_cpu; diff --git a/LR35902/inc/LR35902.h b/LR35902/inc/LR35902.h index 9919988..08c8a57 100644 --- a/LR35902/inc/LR35902.h +++ b/LR35902/inc/LR35902.h @@ -35,17 +35,8 @@ namespace EightBit { return af; } - register16_t AF() const final { - const auto low = higherNibble(af.low); - const auto high = af.high; - return register16_t(low, high); - } - - virtual register16_t BC() const final { return bc; } virtual register16_t& BC() final { return bc; } - virtual register16_t DE() const final { return de; } virtual register16_t& DE() final { return de; } - virtual register16_t HL() const final { return hl; } virtual register16_t& HL() final { return hl; } int singleStep(); diff --git a/LR35902/src/CharacterDefinition.cpp b/LR35902/src/CharacterDefinition.cpp index 7204335..4be04c4 100644 --- a/LR35902/src/CharacterDefinition.cpp +++ b/LR35902/src/CharacterDefinition.cpp @@ -3,12 +3,12 @@ #include -EightBit::GameBoy::CharacterDefinition::CharacterDefinition(const Ram& vram, const uint16_t address) +EightBit::GameBoy::CharacterDefinition::CharacterDefinition(Ram& vram, const uint16_t address) : m_vram(vram), m_address(address) { } -std::array EightBit::GameBoy::CharacterDefinition::get(int row) const { +std::array EightBit::GameBoy::CharacterDefinition::get(int row) { std::array returned; diff --git a/LR35902/src/Display.cpp b/LR35902/src/Display.cpp index 33cfcc2..6dd0971 100644 --- a/LR35902/src/Display.cpp +++ b/LR35902/src/Display.cpp @@ -71,7 +71,7 @@ void EightBit::GameBoy::Display::renderObjects() { const auto drawX = spriteX - 8; const auto sprite = current.pattern(); - const auto definition = CharacterDefinition(m_vram, characterAddressMultiplier * sprite); + auto definition = CharacterDefinition(m_vram, characterAddressMultiplier * sprite); const auto& palette = palettes[current.palette()]; const auto flipX = current.flipX(); const auto flipY = current.flipY(); @@ -118,7 +118,7 @@ void EightBit::GameBoy::Display::renderBackground( const auto character = m_vram.peek(address++); - const auto definition = CharacterDefinition(m_vram, bgCharacters + 16 * character); + auto definition = CharacterDefinition(m_vram, bgCharacters + 16 * character); renderTile( 8, column * 8 + offsetX, row * 8 + offsetY, @@ -133,7 +133,7 @@ void EightBit::GameBoy::Display::renderTile( const int drawX, const int drawY, const bool flipX, const bool flipY, const bool allowTransparencies, const std::array& palette, - const CharacterDefinition& definition) { + CharacterDefinition& definition) { const auto width = 8; diff --git a/LR35902/src/GameBoyBus.cpp b/LR35902/src/GameBoyBus.cpp index 0ba3a05..9f91736 100644 --- a/LR35902/src/GameBoyBus.cpp +++ b/LR35902/src/GameBoyBus.cpp @@ -149,21 +149,19 @@ void EightBit::GameBoy::Bus::validateCartridgeType() { } } -uint8_t EightBit::GameBoy::Bus::reference(uint16_t address, bool& rom) const { +uint8_t& EightBit::GameBoy::Bus::reference(uint16_t address) { - rom = true; if ((address < 0x100) && IO().bootRomEnabled()) - return m_bootRom.reference(address); + return DATA() = m_bootRom.peek(address); if ((address < 0x4000) && gameRomEnabled()) - return m_gameRomBanks[0].reference(address); + return DATA() = m_gameRomBanks[0].peek(address); if ((address < 0x8000) && gameRomEnabled()) - return m_gameRomBanks[m_romBank].reference(address - 0x4000); + return DATA() = m_gameRomBanks[m_romBank].peek(address - 0x4000); - rom = false; if (address < 0xa000) return VRAM().reference(address - 0x8000); if (address < 0xc000) - return m_ramBanks.size() == 0 ? rom = true, 0xff : m_ramBanks[m_ramBank].reference(address - 0xa000); + return m_ramBanks.size() == 0 ? DATA() = 0xff : m_ramBanks[m_ramBank].reference(address - 0xa000); if (address < 0xe000) return m_lowInternalRam.reference(address - 0xc000); if (address < 0xfe00) @@ -171,35 +169,7 @@ uint8_t EightBit::GameBoy::Bus::reference(uint16_t address, bool& rom) const { if (address < 0xfea0) return OAMRAM().reference(address - 0xfe00); if (address < IoRegisters::BASE) - return rom = true, 0xff; - if (address < 0xff80) - return IO().reference(address - IoRegisters::BASE); - return m_highInternalRam.reference(address - 0xff80); -} - -uint8_t& EightBit::GameBoy::Bus::reference(uint16_t address, bool& rom) { - - rom = true; - if ((address < 0x100) && IO().bootRomEnabled()) - return DATA() = m_bootRom.reference(address); - if ((address < 0x4000) && gameRomEnabled()) - return DATA() = m_gameRomBanks[0].reference(address); - if ((address < 0x8000) && gameRomEnabled()) - return DATA() = m_gameRomBanks[m_romBank].reference(address - 0x4000); - - rom = false; - if (address < 0xa000) - return VRAM().reference(address - 0x8000); - if (address < 0xc000) - return m_ramBanks.size() == 0 ? rom = true, DATA() = 0xff : m_ramBanks[m_ramBank].reference(address - 0xa000); - if (address < 0xe000) - return m_lowInternalRam.reference(address - 0xc000); - if (address < 0xfe00) - return m_lowInternalRam.reference(address - 0xe000); // Low internal RAM mirror - if (address < 0xfea0) - return OAMRAM().reference(address - 0xfe00); - if (address < IoRegisters::BASE) - return rom = true, DATA() = 0xff; + return DATA() = 0xff; if (address < 0xff80) return IO().reference(address - IoRegisters::BASE); return m_highInternalRam.reference(address - 0xff80); diff --git a/M6502/inc/mos6502.h b/M6502/inc/mos6502.h index 5589cab..01c8f08 100644 --- a/M6502/inc/mos6502.h +++ b/M6502/inc/mos6502.h @@ -33,18 +33,12 @@ namespace EightBit { virtual int step() final; virtual void powerOn() override; - uint8_t X() const { return x; } uint8_t& X() { return x; } - uint8_t Y() const { return y; } uint8_t& Y() { return y; } - uint8_t A() const { return a; } uint8_t& A() { return a; } - uint8_t S() const { return s; } uint8_t& S() { return s; } - uint8_t P() const { return p; } uint8_t& P() { return p; } - PinLevel SO() const { return m_soLine; } // In PinLevel& SO() { return m_soLine; } // In protected: diff --git a/M6502/test/Board.h b/M6502/test/Board.h index 724ec54..75e875f 100644 --- a/M6502/test/Board.h +++ b/M6502/test/Board.h @@ -24,10 +24,6 @@ protected: return m_ram.reference(address); } - virtual uint8_t reference(uint16_t address) const { - return m_ram.reference(address); - } - private: const Configuration& m_configuration; EightBit::Ram m_ram = 0x10000; diff --git a/Z80/fusetest_Z80/FuseTestRunner.h b/Z80/fusetest_Z80/FuseTestRunner.h index 1e7060e..245a46c 100644 --- a/Z80/fusetest_Z80/FuseTestRunner.h +++ b/Z80/fusetest_Z80/FuseTestRunner.h @@ -40,10 +40,6 @@ namespace Fuse { return m_ram.reference(address); } - virtual uint8_t reference(uint16_t address) const { - return m_ram.reference(address); - } - public: TestRunner(const Test& test, const ExpectedTestResult& expected); diff --git a/Z80/inc/Disassembler.h b/Z80/inc/Disassembler.h index 399b604..6dbf893 100644 --- a/Z80/inc/Disassembler.h +++ b/Z80/inc/Disassembler.h @@ -11,8 +11,8 @@ namespace EightBit { public: Disassembler(); - static std::string state(const Z80& cpu); - std::string disassemble(const Z80& cpu); + static std::string state(Z80& cpu); + std::string disassemble(Z80& cpu); static std::string flag(uint8_t value, int flag, const std::string& represents); static std::string flags(uint8_t value); @@ -30,7 +30,7 @@ namespace EightBit { bool m_prefixED; bool m_prefixFD; - void disassemble(std::ostringstream& output, const Z80& cpu, uint16_t pc); + void disassemble(std::ostringstream& output, Z80& cpu, uint16_t pc); void disassembleCB( std::ostringstream& output, @@ -52,7 +52,7 @@ namespace EightBit { void disassembleOther( std::ostringstream& output, - const Z80& cpu, + Z80& cpu, uint16_t pc, std::string& specification, int& dumpCount, diff --git a/Z80/inc/Z80.h b/Z80/inc/Z80.h index 628f928..32f1c3f 100644 --- a/Z80/inc/Z80.h +++ b/Z80/inc/Z80.h @@ -51,44 +51,28 @@ namespace EightBit { Signal ExecutingInstruction; PinLevel& M1() { return m_m1Line; } // Out - PinLevel M1() const { return m_m1Line; } virtual int execute(uint8_t opcode) final; virtual int step() final; virtual register16_t& AF() final; - virtual register16_t AF() const final; virtual register16_t& BC() final; - virtual register16_t BC() const final; virtual register16_t& DE() final; - virtual register16_t DE() const final; virtual register16_t& HL() final; - virtual register16_t HL() const final; register16_t& IX() { return m_ix; } - register16_t IX() const { return m_ix; } uint8_t& IXH() { return IX().high; } - uint8_t IXH() const { return IX().high; } uint8_t& IXL() { return IX().low; } - uint8_t IXL() const { return IX().low; } register16_t& IY() { return m_iy; } - register16_t IY() const { return m_iy; } uint8_t& IYH() { return IY().high; } - uint8_t IYH() const { return IY().high; } uint8_t& IYL() { return IY().low; } - uint8_t IYL() const { return IY().low; } refresh_t& REFRESH() { return m_refresh; } - refresh_t REFRESH() const { return m_refresh; } uint8_t& IV() { return iv; } - uint8_t IV() const { return iv; } int& IM() { return m_interruptMode; } - int IM() const { return m_interruptMode; } bool& IFF1() { return m_iff1; } - bool IFF1() const { return m_iff1; } bool& IFF2() { return m_iff2; } - bool IFF2() const { return m_iff2; } void exx() { m_registerSet ^= 1; @@ -274,23 +258,6 @@ namespace EightBit { } } - register16_t RP(const int rp) const { - ASSUME(rp >= 0); - ASSUME(rp <= 3); - switch (rp) { - case 0: - return BC(); - case 1: - return DE(); - case 2: - return HL2(); - case 3: - return SP(); - default: - UNREACHABLE; - } - } - register16_t& HL2() { if (LIKELY(!m_displaced)) return HL(); @@ -300,15 +267,6 @@ namespace EightBit { return IY(); } - register16_t HL2() const { - if (LIKELY(!m_displaced)) - return HL(); - if (m_prefixDD) - return IX(); - // Must be FD prefix - return IY(); - } - register16_t& RP2(const int rp) { ASSUME(rp >= 0); ASSUME(rp <= 3); @@ -326,23 +284,6 @@ namespace EightBit { } } - register16_t RP2(const int rp) const { - ASSUME(rp >= 0); - ASSUME(rp <= 3); - switch (rp) { - case 0: - return BC(); - case 1: - return DE(); - case 2: - return HL2(); - case 3: - return AF(); - default: - UNREACHABLE; - } - } - static void adjustHalfCarryAdd(uint8_t& f, const uint8_t before, const uint8_t value, const int calculation) { setFlag(f, HC, calculateHalfCarryAdd(before, value, calculation)); } diff --git a/Z80/src/Disassembler.cpp b/Z80/src/Disassembler.cpp index 6722380..84481f3 100644 --- a/Z80/src/Disassembler.cpp +++ b/Z80/src/Disassembler.cpp @@ -15,7 +15,7 @@ EightBit::Disassembler::Disassembler() { m_formatter.exceptions(boost::io::all_error_bits ^ boost::io::too_many_args_bit); } -std::string EightBit::Disassembler::state(const Z80& cpu) { +std::string EightBit::Disassembler::state(Z80& cpu) { auto pc = cpu.PC(); auto sp = cpu.SP(); @@ -171,14 +171,14 @@ std::string EightBit::Disassembler::alu(int which) { throw std::logic_error("Unhandled alu operation"); } -std::string EightBit::Disassembler::disassemble(const Z80& cpu) { +std::string EightBit::Disassembler::disassemble(Z80& cpu) { m_prefixCB = m_prefixDD = m_prefixED = m_prefixFD = false; std::ostringstream output; disassemble(output, cpu, cpu.PC().word); return output.str(); } -void EightBit::Disassembler::disassemble(std::ostringstream& output, const Z80& cpu, uint16_t pc) { +void EightBit::Disassembler::disassemble(std::ostringstream& output, Z80& cpu, uint16_t pc) { auto& bus = cpu.BUS(); auto opcode = bus.peek(pc); @@ -423,7 +423,7 @@ void EightBit::Disassembler::disassembleED( void EightBit::Disassembler::disassembleOther( std::ostringstream& output, - const Z80& cpu, + Z80& cpu, uint16_t pc, std::string& specification, int& dumpCount, diff --git a/Z80/src/Z80.cpp b/Z80/src/Z80.cpp index 343929b..9182b8e 100644 --- a/Z80/src/Z80.cpp +++ b/Z80/src/Z80.cpp @@ -8,34 +8,18 @@ EightBit::Z80::Z80(Bus& bus, InputOutput& ports) m_ports(ports) { } -EightBit::register16_t EightBit::Z80::AF() const { - return m_accumulatorFlags[m_accumulatorFlagsSet]; -} - EightBit::register16_t& EightBit::Z80::AF() { return m_accumulatorFlags[m_accumulatorFlagsSet]; } -EightBit::register16_t EightBit::Z80::BC() const { - return m_registers[m_registerSet][BC_IDX]; -} - EightBit::register16_t& EightBit::Z80::BC() { return m_registers[m_registerSet][BC_IDX]; } -EightBit::register16_t EightBit::Z80::DE() const { - return m_registers[m_registerSet][DE_IDX]; -} - EightBit::register16_t& EightBit::Z80::DE() { return m_registers[m_registerSet][DE_IDX]; } -EightBit::register16_t EightBit::Z80::HL() const { - return m_registers[m_registerSet][HL_IDX]; -} - EightBit::register16_t& EightBit::Z80::HL() { return m_registers[m_registerSet][HL_IDX]; } diff --git a/Z80/test/Board.cpp b/Z80/test/Board.cpp index ac48f5f..1b680e1 100644 --- a/Z80/test/Board.cpp +++ b/Z80/test/Board.cpp @@ -52,7 +52,7 @@ void Board::Cpu_ExecutingInstruction_Cpm(const EightBit::Z80& cpu) { } } -void Board::bdos() const { +void Board::bdos() { switch (CPU().C()) { case 0x2: std::cout << CPU().E(); @@ -73,7 +73,7 @@ void Board::Cpu_ExecutingInstruction_Profile(const EightBit::Z80& cpu) { m_profiler.addInstruction(peek(pc.word)); } -void Board::Cpu_ExecutingInstruction_Debug(const EightBit::Z80& cpu) { +void Board::Cpu_ExecutingInstruction_Debug(EightBit::Z80& cpu) { std::cerr << EightBit::Disassembler::state(cpu) diff --git a/Z80/test/Board.h b/Z80/test/Board.h index 712deef..e9d9059 100644 --- a/Z80/test/Board.h +++ b/Z80/test/Board.h @@ -22,11 +22,7 @@ public: void initialise(); protected: - virtual uint8_t& reference(uint16_t address) { - return m_ram.reference(address); - } - - virtual uint8_t reference(uint16_t address) const { + virtual uint8_t& reference(uint16_t address) final { return m_ram.reference(address); } @@ -40,8 +36,8 @@ private: void Cpu_ExecutingInstruction_Cpm(const EightBit::Z80& cpu); - void Cpu_ExecutingInstruction_Debug(const EightBit::Z80& cpu); + void Cpu_ExecutingInstruction_Debug(EightBit::Z80& cpu); void Cpu_ExecutingInstruction_Profile(const EightBit::Z80& cpu); - void bdos() const; + void bdos(); }; diff --git a/inc/Bus.h b/inc/Bus.h index c611bb3..c97a8f7 100644 --- a/inc/Bus.h +++ b/inc/Bus.h @@ -22,12 +22,12 @@ namespace EightBit { uint8_t& DATA() { return m_data; } uint8_t DATA() const { return m_data; } - uint8_t peek() const; - uint8_t peek(uint16_t address) const; + uint8_t peek(); + uint8_t peek(uint16_t address); void poke(uint8_t value); void poke(uint16_t address, uint8_t value); - uint16_t peekWord(uint16_t address) const; + uint16_t peekWord(uint16_t address); uint8_t read(); template uint8_t read(const T address) { @@ -44,10 +44,7 @@ namespace EightBit { protected: virtual uint8_t& reference(uint16_t address) = 0; - virtual uint8_t reference(uint16_t address) const = 0; - uint8_t& reference(); - uint8_t reference() const; private: uint8_t m_data = 0xff; diff --git a/inc/IntelProcessor.h b/inc/IntelProcessor.h index 7b10a65..2a77b29 100644 --- a/inc/IntelProcessor.h +++ b/inc/IntelProcessor.h @@ -37,38 +37,24 @@ namespace EightBit { } register16_t& MEMPTR() { return m_memptr; } - register16_t MEMPTR() const { return m_memptr; } register16_t& SP() { return m_sp; } - register16_t SP() const { return m_sp; } virtual register16_t& AF() = 0; - virtual register16_t AF() const = 0; uint8_t& A() { return AF().high; } - uint8_t A() const { return AF().high; } uint8_t& F() { return AF().low; } - uint8_t F() const { return AF().low; } virtual register16_t& BC() = 0; - virtual register16_t BC() const = 0; uint8_t& B() { return BC().high; } - uint8_t B() const { return BC().high; } uint8_t& C() { return BC().low; } - uint8_t C() const { return BC().low; } virtual register16_t& DE() = 0; - virtual register16_t DE() const = 0; uint8_t& D() { return DE().high; } - uint8_t D() const { return DE().high; } uint8_t& E() { return DE().low; } - uint8_t E() const { return DE().low; } virtual register16_t& HL() = 0; - virtual register16_t HL() const = 0; uint8_t& H() { return HL().high; } - uint8_t H() const { return HL().high; } uint8_t& L() { return HL().low; } - uint8_t L() const { return HL().low; } protected: IntelProcessor(Bus& bus); diff --git a/inc/Memory.h b/inc/Memory.h index 87ac0b4..a0bd246 100644 --- a/inc/Memory.h +++ b/inc/Memory.h @@ -34,13 +34,12 @@ namespace EightBit { return limit; } - uint8_t peek(const uint16_t address) const { + uint8_t peek(const uint16_t address) { return BYTES()[address]; } protected: std::vector& BYTES() { return m_bytes; } - const std::vector& BYTES() const { return m_bytes; } void poke(const uint16_t address, const uint8_t value) { BYTES()[address] = value; diff --git a/inc/Ram.h b/inc/Ram.h index 5d0190c..2600634 100644 --- a/inc/Ram.h +++ b/inc/Ram.h @@ -14,10 +14,6 @@ namespace EightBit { return BYTES()[address]; } - uint8_t reference(uint16_t address) const { - return peek(address); - } - void poke(uint16_t address, uint8_t value) { Memory::poke(address, value); } diff --git a/inc/Rom.h b/inc/Rom.h index e5fc81b..d312d44 100644 --- a/inc/Rom.h +++ b/inc/Rom.h @@ -9,9 +9,5 @@ namespace EightBit { Rom(const size_t size = 0) : Memory(size) { } - - uint8_t reference(uint16_t address) const { - return peek(address); - } }; } diff --git a/inc/Signal.h b/inc/Signal.h index ebc7a09..4a74aec 100644 --- a/inc/Signal.h +++ b/inc/Signal.h @@ -6,7 +6,7 @@ namespace EightBit { template class Signal final { private: - typedef std::function delegate_t; + typedef std::function delegate_t; typedef std::vector delegates_t; delegates_t m_delegates; @@ -16,7 +16,7 @@ namespace EightBit { m_delegates.push_back(functor); } - void fire(const T& e) const { + void fire(T& e) const { for (auto& delegate : m_delegates) delegate(e); } diff --git a/src/Bus.cpp b/src/Bus.cpp index c6e8f9e..6ad725b 100644 --- a/src/Bus.cpp +++ b/src/Bus.cpp @@ -1,11 +1,11 @@ #include "stdafx.h" #include "Bus.h" -uint8_t EightBit::Bus::peek() const { +uint8_t EightBit::Bus::peek() { return reference(); } -uint8_t EightBit::Bus::peek(const uint16_t address) const { +uint8_t EightBit::Bus::peek(const uint16_t address) { return reference(address); } @@ -17,7 +17,7 @@ void EightBit::Bus::poke(const uint16_t address, const uint8_t value) { reference(address) = value; } -uint16_t EightBit::Bus::peekWord(const uint16_t address) const { +uint16_t EightBit::Bus::peekWord(const uint16_t address) { const auto low = peek(address); const auto high = peek(address + 1); return register16_t(low, high).word; @@ -41,10 +41,6 @@ void EightBit::Bus::write(const uint8_t value) { write(); } -uint8_t EightBit::Bus::reference() const { - return reference(ADDRESS().word); -} - uint8_t& EightBit::Bus::reference() { return reference(ADDRESS().word); } diff --git a/src/InputOutput.cpp b/src/InputOutput.cpp index b406d18..fe866ea 100644 --- a/src/InputOutput.cpp +++ b/src/InputOutput.cpp @@ -14,18 +14,18 @@ void EightBit::InputOutput::writeOutputPort(const uint8_t port, const uint8_t va OnWrittenPort(port); } -void EightBit::InputOutput::OnReadingPort(const uint8_t port) { +void EightBit::InputOutput::OnReadingPort(uint8_t port) { ReadingPort.fire(port); } -void EightBit::InputOutput::OnReadPort(const uint8_t port) { +void EightBit::InputOutput::OnReadPort(uint8_t port) { ReadPort.fire(port); } -void EightBit::InputOutput::OnWritingPort(const uint8_t port) { +void EightBit::InputOutput::OnWritingPort(uint8_t port) { WritingPort.fire(port); } -void EightBit::InputOutput::OnWrittenPort(const uint8_t port) { +void EightBit::InputOutput::OnWrittenPort(uint8_t port) { WrittenPort.fire(port); }