From 70c70af96911151a94f2a6b58a3e78d191f3c0b4 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Sat, 11 Aug 2018 21:19:19 +0100 Subject: [PATCH] Sort out some exception and member initialisation rules. Signed-off-by: Adrian Conlon --- Intel8080/inc/Disassembler.h | 2 +- Intel8080/inc/Profiler.h | 2 +- Intel8080/src/Disassembler.cpp | 2 +- Intel8080/src/Intel8080.cpp | 8 +-- Intel8080/src/Profiler.cpp | 2 +- LR35902/inc/AbstractColourPalette.h | 2 +- LR35902/inc/Disassembler.h | 4 +- LR35902/inc/Display.h | 4 +- LR35902/inc/GameBoyBus.h | 2 +- LR35902/src/Disassembler.cpp | 2 +- LR35902/src/GameBoyBus.cpp | 2 +- LR35902/src/IoRegisters.cpp | 4 +- LR35902/src/LR35902.cpp | 18 ++--- M6502/inc/Disassembly.h | 2 +- M6502/inc/Symbols.h | 2 +- M6502/inc/mos6502.h | 6 +- M6502/src/Symbols.cpp | 2 +- M6502/src/mos6502.cpp | 9 ++- Z80/inc/Disassembler.h | 10 +-- Z80/inc/Z80.h | 4 +- Z80/src/Disassembler.cpp | 2 +- Z80/src/Z80.cpp | 108 +++++++++++++--------------- Z80/test/Configuration.cpp | 2 +- Z80/test/Configuration.h | 2 +- inc/InputOutput.h | 4 +- inc/IntelProcessor.h | 2 +- inc/Processor.h | 6 +- inc/Register.h | 46 +++++++++++- src/IntelProcessor.cpp | 14 ++-- src/Processor.cpp | 5 +- 30 files changed, 157 insertions(+), 123 deletions(-) diff --git a/Intel8080/inc/Disassembler.h b/Intel8080/inc/Disassembler.h index 993fbe0..510c0dc 100644 --- a/Intel8080/inc/Disassembler.h +++ b/Intel8080/inc/Disassembler.h @@ -10,7 +10,7 @@ namespace EightBit { class Disassembler { public: - Disassembler(); + Disassembler() noexcept; static std::string state(Intel8080& cpu); std::string disassemble(Intel8080& cpu); diff --git a/Intel8080/inc/Profiler.h b/Intel8080/inc/Profiler.h index 90a4986..09e1688 100644 --- a/Intel8080/inc/Profiler.h +++ b/Intel8080/inc/Profiler.h @@ -6,7 +6,7 @@ namespace EightBit { class Profiler { public: - Profiler(); + Profiler() noexcept; ~Profiler(); void addInstruction(uint8_t instruction); diff --git a/Intel8080/src/Disassembler.cpp b/Intel8080/src/Disassembler.cpp index 9b5537f..c1484a7 100644 --- a/Intel8080/src/Disassembler.cpp +++ b/Intel8080/src/Disassembler.cpp @@ -8,7 +8,7 @@ #include #include -EightBit::Disassembler::Disassembler() { +EightBit::Disassembler::Disassembler() noexcept { // Disable exceptions where too many format arguments are available m_formatter.exceptions(boost::io::all_error_bits ^ boost::io::too_many_args_bit); } diff --git a/Intel8080/src/Intel8080.cpp b/Intel8080/src/Intel8080.cpp index 8f1b6d9..28f5d05 100644 --- a/Intel8080/src/Intel8080.cpp +++ b/Intel8080/src/Intel8080.cpp @@ -117,7 +117,7 @@ bool EightBit::Intel8080::callConditionalFlag(int flag) { void EightBit::Intel8080::add(register16_t value) { const auto result = HL().word + value.word; - HL().word = result; + HL() = result; setFlag(F(), CF, result & Bit16); } @@ -229,7 +229,7 @@ void EightBit::Intel8080::xhtl() { MEMPTR().low = BUS().read(SP()); BUS().write(L()); L() = MEMPTR().low; - ++BUS().ADDRESS().word; + ++BUS().ADDRESS(); MEMPTR().high = BUS().read(); BUS().write(H()); H() = MEMPTR().high; @@ -374,10 +374,10 @@ void EightBit::Intel8080::execute(int x, int y, int z, int p, int q) { case 3: // 16-bit INC/DEC switch (q) { case 0: // INC rp - ++RP(p).word; + ++RP(p); break; case 1: // DEC rp - --RP(p).word; + --RP(p); break; default: UNREACHABLE; diff --git a/Intel8080/src/Profiler.cpp b/Intel8080/src/Profiler.cpp index f2c0d9d..601b87b 100644 --- a/Intel8080/src/Profiler.cpp +++ b/Intel8080/src/Profiler.cpp @@ -4,7 +4,7 @@ #include -EightBit::Profiler::Profiler() { +EightBit::Profiler::Profiler() noexcept { m_instructions.fill(0); m_addresses.fill(0); } diff --git a/LR35902/inc/AbstractColourPalette.h b/LR35902/inc/AbstractColourPalette.h index 14fd5a0..57ccb71 100644 --- a/LR35902/inc/AbstractColourPalette.h +++ b/LR35902/inc/AbstractColourPalette.h @@ -14,7 +14,7 @@ namespace EightBit { Dark }; - AbstractColourPalette() + AbstractColourPalette() noexcept : m_colours(4) { } diff --git a/LR35902/inc/Disassembler.h b/LR35902/inc/Disassembler.h index 1825be5..6b9b934 100644 --- a/LR35902/inc/Disassembler.h +++ b/LR35902/inc/Disassembler.h @@ -13,7 +13,7 @@ namespace EightBit { class Disassembler { public: - Disassembler(); + Disassembler() noexcept; static std::string state(LR35902& cpu); std::string disassemble(LR35902& cpu); @@ -37,7 +37,7 @@ namespace EightBit { }; mutable boost::format m_formatter; - bool m_prefixCB; + bool m_prefixCB = false; void disassemble(std::ostringstream& output, LR35902& cpu, uint16_t pc); diff --git a/LR35902/inc/Display.h b/LR35902/inc/Display.h index e2eb1ed..525dee7 100644 --- a/LR35902/inc/Display.h +++ b/LR35902/inc/Display.h @@ -35,12 +35,12 @@ namespace EightBit { void loadObjectAttributes(); private: - std::array m_pixels; + std::array m_pixels = { 0 }; Bus& m_bus; Ram& m_oam; Ram& m_vram; const AbstractColourPalette* m_colours; - std::array m_objectAttributes; + std::array m_objectAttributes = { ObjectAttribute() }; uint8_t m_control = 0; uint8_t m_scanLine = 0; diff --git a/LR35902/inc/GameBoyBus.h b/LR35902/inc/GameBoyBus.h index 7833ceb..e812b3b 100644 --- a/LR35902/inc/GameBoyBus.h +++ b/LR35902/inc/GameBoyBus.h @@ -33,7 +33,7 @@ namespace EightBit { RomPageSize = 0x4000 }; - Bus(); + Bus() noexcept; LR35902& CPU() { return m_cpu; } Ram& VRAM() { return m_videoRam; } diff --git a/LR35902/src/Disassembler.cpp b/LR35902/src/Disassembler.cpp index 46c2c98..d861286 100644 --- a/LR35902/src/Disassembler.cpp +++ b/LR35902/src/Disassembler.cpp @@ -9,7 +9,7 @@ #include "LR35902.h" #include "IoRegisters.h" -EightBit::GameBoy::Disassembler::Disassembler() { +EightBit::GameBoy::Disassembler::Disassembler() noexcept { // Disable exceptions where too many format arguments are available m_formatter.exceptions(boost::io::all_error_bits ^ boost::io::too_many_args_bit); } diff --git a/LR35902/src/GameBoyBus.cpp b/LR35902/src/GameBoyBus.cpp index 9f91736..3797935 100644 --- a/LR35902/src/GameBoyBus.cpp +++ b/LR35902/src/GameBoyBus.cpp @@ -2,7 +2,7 @@ #include "GameBoyBus.h" #include "Display.h" -EightBit::GameBoy::Bus::Bus() +EightBit::GameBoy::Bus::Bus() noexcept : m_cpu(*this), 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 787ecd1..b0054aa 100644 --- a/LR35902/src/IoRegisters.cpp +++ b/LR35902/src/IoRegisters.cpp @@ -12,7 +12,7 @@ EightBit::GameBoy::IoRegisters::IoRegisters(Bus& bus) void EightBit::GameBoy::IoRegisters::reset() { poke(NR52, 0xf1); poke(LCDC, DisplayBackground | BackgroundCharacterDataSelection | LcdEnable); - m_divCounter.word = 0xabcc; + m_divCounter = 0xabcc; m_timerCounter = 0; } @@ -194,7 +194,7 @@ bool EightBit::GameBoy::IoRegisters::timerDisabled() { } void EightBit::GameBoy::IoRegisters::incrementDIV(int cycles) { - m_divCounter.word += cycles; + m_divCounter += cycles; poke(DIV, m_divCounter.high); } diff --git a/LR35902/src/LR35902.cpp b/LR35902/src/LR35902.cpp index 65c8bc0..a6d9ef3 100644 --- a/LR35902/src/LR35902.cpp +++ b/LR35902/src/LR35902.cpp @@ -12,7 +12,7 @@ EightBit::GameBoy::LR35902::LR35902(Bus& memory) void EightBit::GameBoy::LR35902::reset() { IntelProcessor::reset(); di(); - SP().word = Mask16 - 1; + SP() = Mask16 - 1; m_prefixCB = false; } @@ -469,11 +469,11 @@ void EightBit::GameBoy::LR35902::executeOther(int x, int y, int z, int p, int q) addCycles(2); break; case 2: // GB: LDI (HL),A - BUS().write(HL().word++, A()); + BUS().write(HL()++, A()); addCycles(2); break; case 3: // GB: LDD (HL),A - BUS().write(HL().word--, A()); + BUS().write(HL()--, A()); addCycles(2); break; default: @@ -491,11 +491,11 @@ void EightBit::GameBoy::LR35902::executeOther(int x, int y, int z, int p, int q) addCycles(2); break; case 2: // GB: LDI A,(HL) - A() = BUS().read(HL().word++); + A() = BUS().read(HL()++); addCycles(2); break; case 3: // GB: LDD A,(HL) - A() = BUS().read(HL().word--); + A() = BUS().read(HL()--); addCycles(2); break; default: @@ -509,10 +509,10 @@ void EightBit::GameBoy::LR35902::executeOther(int x, int y, int z, int p, int q) case 3: // 16-bit INC/DEC switch (q) { case 0: // INC rp - ++RP(p).word; + ++RP(p); break; case 1: // DEC rp - --RP(p).word; + --RP(p); break; default: UNREACHABLE; @@ -637,7 +637,7 @@ void EightBit::GameBoy::LR35902::executeOther(int x, int y, int z, int p, int q) const auto before = SP().word; const int8_t value = fetchByte(); const auto result = before + value; - SP().word = result; + SP() = result; const auto carried = before ^ value ^ (result & Mask16); clearFlag(F(), ZF | NF); setFlag(F(), CF, carried & Bit8); @@ -653,7 +653,7 @@ void EightBit::GameBoy::LR35902::executeOther(int x, int y, int z, int p, int q) const auto before = SP().word; const int8_t value = fetchByte(); const auto result = before + value; - HL().word = result; + HL() = result; const auto carried = before ^ value ^ (result & Mask16); clearFlag(F(), ZF | NF); setFlag(F(), CF, carried & Bit8); diff --git a/M6502/inc/Disassembly.h b/M6502/inc/Disassembly.h index 4de6f3f..989ad6e 100644 --- a/M6502/inc/Disassembly.h +++ b/M6502/inc/Disassembly.h @@ -21,7 +21,7 @@ namespace EightBit { MOS6502& processor; const Symbols& symbols; - mutable uint16_t m_address; + mutable uint16_t m_address = 0xffff; std::string disassemble_Implied(const std::string& instruction) const { return "\t" + instruction; diff --git a/M6502/inc/Symbols.h b/M6502/inc/Symbols.h index b26cc4a..8ad255b 100644 --- a/M6502/inc/Symbols.h +++ b/M6502/inc/Symbols.h @@ -8,7 +8,7 @@ namespace EightBit { class Symbols { public: - Symbols(std::string path = ""); + Symbols(std::string path = "") noexcept; const std::map& getLabels() const { return labels; } const std::map& getConstants() const { return constants; } diff --git a/M6502/inc/mos6502.h b/M6502/inc/mos6502.h index 01c8f08..3824688 100644 --- a/M6502/inc/mos6502.h +++ b/M6502/inc/mos6502.h @@ -102,14 +102,14 @@ namespace EightBit { std::tuple Address_AbsoluteX() { auto address = Address_Absolute(); const auto page = address.high; - address.word += X(); + address += X(); return std::tuple(address, address.high != page); } std::tuple Address_AbsoluteY() { auto address = Address_Absolute(); const auto page = address.high; - address.word += Y(); + address += Y(); return std::tuple(address, address.high != page); } @@ -120,7 +120,7 @@ namespace EightBit { std::tuple Address_IndirectIndexedY() { auto address = Address_ZeroPageIndirect(); const auto page = address.high; - address.word += Y(); + address += Y(); return std::tuple(address, address.high != page); } diff --git a/M6502/src/Symbols.cpp b/M6502/src/Symbols.cpp index 93cc4a4..cdcb913 100644 --- a/M6502/src/Symbols.cpp +++ b/M6502/src/Symbols.cpp @@ -10,7 +10,7 @@ #include #include -EightBit::Symbols::Symbols(std::string path) { +EightBit::Symbols::Symbols(std::string path) noexcept { if (!path.empty()) { Parse(path); AssignSymbols(); diff --git a/M6502/src/mos6502.cpp b/M6502/src/mos6502.cpp index 546659e..0d0495d 100644 --- a/M6502/src/mos6502.cpp +++ b/M6502/src/mos6502.cpp @@ -488,7 +488,7 @@ uint8_t EightBit::MOS6502::ADD_d(uint8_t operand, uint8_t data, int carry) { void EightBit::MOS6502::Branch(int8_t displacement) { const auto page = PC().high; - PC().word += displacement; + PC() += displacement; if (UNLIKELY(PC().high != page)) addCycle(); addCycle(); @@ -514,7 +514,7 @@ void EightBit::MOS6502::PLP() { void EightBit::MOS6502::JSR_abs() { const auto address = Address_Absolute(); - --PC().word; + --PC(); call(address); } @@ -525,7 +525,7 @@ void EightBit::MOS6502::RTI() { void EightBit::MOS6502::RTS() { ret(); - ++PC().word; + ++PC(); } void EightBit::MOS6502::JMP_abs() { @@ -537,8 +537,7 @@ void EightBit::MOS6502::JMP_ind() { } void EightBit::MOS6502::BRK() { - ++PC().word; - pushWord(PC()); + pushWord(++PC()); PHP(); setFlag(P(), IF); jump(getWordPaged(0xff, IRQvector)); diff --git a/Z80/inc/Disassembler.h b/Z80/inc/Disassembler.h index 6dbf893..43bfd11 100644 --- a/Z80/inc/Disassembler.h +++ b/Z80/inc/Disassembler.h @@ -9,7 +9,7 @@ namespace EightBit { class Disassembler { public: - Disassembler(); + Disassembler() noexcept; static std::string state(Z80& cpu); std::string disassemble(Z80& cpu); @@ -25,10 +25,10 @@ namespace EightBit { private: mutable boost::format m_formatter; - bool m_prefixCB; - bool m_prefixDD; - bool m_prefixED; - bool m_prefixFD; + bool m_prefixCB = false; + bool m_prefixDD = false; + bool m_prefixED = false; + bool m_prefixFD = false; void disassemble(std::ostringstream& output, Z80& cpu, uint16_t pc); diff --git a/Z80/inc/Z80.h b/Z80/inc/Z80.h index 32f1c3f..3b69e8a 100644 --- a/Z80/inc/Z80.h +++ b/Z80/inc/Z80.h @@ -364,7 +364,7 @@ namespace EightBit { void xhtl(); - void blockCompare(); + void blockCompare(register16_t source, register16_t& counter); void cpi(); bool cpir(); @@ -372,7 +372,7 @@ namespace EightBit { void cpd(); bool cpdr(); - void blockLoad(register16_t source, register16_t destination); + void blockLoad(register16_t source, register16_t destination, register16_t& counter); void ldi(); bool ldir(); diff --git a/Z80/src/Disassembler.cpp b/Z80/src/Disassembler.cpp index 84481f3..8909525 100644 --- a/Z80/src/Disassembler.cpp +++ b/Z80/src/Disassembler.cpp @@ -10,7 +10,7 @@ #include "Z80.h" -EightBit::Disassembler::Disassembler() { +EightBit::Disassembler::Disassembler() noexcept { // Disable exceptions where too many format arguments are available m_formatter.exceptions(boost::io::all_error_bits ^ boost::io::too_many_args_bit); } diff --git a/Z80/src/Z80.cpp b/Z80/src/Z80.cpp index 9182b8e..c6c1072 100644 --- a/Z80/src/Z80.cpp +++ b/Z80/src/Z80.cpp @@ -183,7 +183,7 @@ void EightBit::Z80::sbc(const register16_t value) { const auto valueNegative = value.high & SF; const auto result = MEMPTR().word - value.word - (F() & CF); - HL2().word = result; + HL2() = result; const auto afterNegative = HL2().high & SF; @@ -195,7 +195,7 @@ void EightBit::Z80::sbc(const register16_t value) { setFlag(F(), CF, result & Bit16); adjustXY(F(), HL2().high); - ++MEMPTR().word; + ++MEMPTR(); } void EightBit::Z80::adc(const register16_t value) { @@ -206,7 +206,7 @@ void EightBit::Z80::adc(const register16_t value) { const auto valueNegative = value.high & SF; const auto result = MEMPTR().word + value.word + (F() & CF); - HL2().word = result; + HL2() = result; const auto afterNegative = HL2().high & SF; @@ -218,7 +218,7 @@ void EightBit::Z80::adc(const register16_t value) { setFlag(F(), CF, result & Bit16); adjustXY(F(), HL2().high); - ++MEMPTR().word; + ++MEMPTR(); } void EightBit::Z80::add(const register16_t value) { @@ -227,14 +227,14 @@ void EightBit::Z80::add(const register16_t value) { const auto result = MEMPTR().word + value.word; - HL2().word = result; + HL2() = result; clearFlag(F(), NF); setFlag(F(), CF, result & Bit16); adjustHalfCarryAdd(F(), MEMPTR().high, value.high, HL2().high); adjustXY(F(), HL2().high); - ++MEMPTR().word; + ++MEMPTR(); } void EightBit::Z80::add(const uint8_t value, const int carry) { @@ -438,18 +438,18 @@ void EightBit::Z80::xhtl() { MEMPTR().low = BUS().read(SP()); BUS().write(HL2().low); HL2().low = MEMPTR().low; - ++BUS().ADDRESS().word; + ++BUS().ADDRESS(); MEMPTR().high = BUS().read(); BUS().write(HL2().high); HL2().high = MEMPTR().high; } -void EightBit::Z80::blockCompare() { +void EightBit::Z80::blockCompare(register16_t source, register16_t& counter) { - const auto value = BUS().read(HL()); + const auto value = BUS().read(source); uint8_t result = A() - value; - setFlag(F(), PF, --BC().word); + setFlag(F(), PF, --counter.word); adjustSZ(F(), result); adjustHalfCarrySub(F(), A(), value, result); @@ -462,15 +462,13 @@ void EightBit::Z80::blockCompare() { } void EightBit::Z80::cpi() { - blockCompare(); - ++HL().word; - ++MEMPTR().word; + blockCompare(HL()++, BC()); + ++MEMPTR(); } void EightBit::Z80::cpd() { - blockCompare(); - --HL().word; - --MEMPTR().word; + blockCompare(HL()--, BC()); + --MEMPTR(); } bool EightBit::Z80::cpir() { @@ -483,26 +481,22 @@ bool EightBit::Z80::cpdr() { return (F() & PF) && !(F() & ZF); // See CPD } -void EightBit::Z80::blockLoad(const register16_t source, const register16_t destination) { +void EightBit::Z80::blockLoad(const register16_t source, const register16_t destination, register16_t& counter) { const auto value = BUS().read(source); BUS().write(destination, value); const auto xy = A() + value; setFlag(F(), XF, xy & 8); setFlag(F(), YF, xy & 2); clearFlag(F(), NF | HC); - setFlag(F(), PF, --BC().word); + setFlag(F(), PF, --counter.word); } void EightBit::Z80::ldd() { - blockLoad(HL(), DE()); - --HL().word; - --DE().word; + blockLoad(HL()--, DE()--, BC()); } void EightBit::Z80::ldi() { - blockLoad(HL(), DE()); - ++HL().word; - ++DE().word; + blockLoad(HL()++, DE()++, BC()); } bool EightBit::Z80::ldir() { @@ -517,18 +511,18 @@ bool EightBit::Z80::lddr() { void EightBit::Z80::ini() { MEMPTR() = BUS().ADDRESS() = BC(); - ++MEMPTR().word; + ++MEMPTR(); const auto value = readPort(); - BUS().write(HL().word++, value); + BUS().write(HL()++, value); decrement(B()); setFlag(F(), NF); } void EightBit::Z80::ind() { MEMPTR() = BUS().ADDRESS() = BC(); - --MEMPTR().word; + --MEMPTR(); const auto value = readPort(); - BUS().write(HL().word--, value); + BUS().write(HL()--, value); decrement(B()); setFlag(F(), NF); } @@ -554,15 +548,15 @@ void EightBit::Z80::blockOut() { } void EightBit::Z80::outi() { - BUS().ADDRESS().word = HL().word++; + BUS().ADDRESS() = HL()++; blockOut(); - MEMPTR().word = BC().word + 1; + MEMPTR() = BC().word + 1; } void EightBit::Z80::outd() { - BUS().ADDRESS().word = HL().word--; + BUS().ADDRESS() = HL()--; blockOut(); - MEMPTR().word = BC().word - 1; + MEMPTR() = BC().word - 1; } bool EightBit::Z80::otir() { @@ -577,7 +571,7 @@ bool EightBit::Z80::otdr() { void EightBit::Z80::rrd() { MEMPTR() = BUS().ADDRESS() = HL(); - ++MEMPTR().word; + ++MEMPTR(); const auto memory = BUS().read(); BUS().write(promoteNibble(A()) | highNibble(memory)); A() = higherNibble(A()) | lowerNibble(memory); @@ -587,7 +581,7 @@ void EightBit::Z80::rrd() { void EightBit::Z80::rld() { MEMPTR() = BUS().ADDRESS() = HL(); - ++MEMPTR().word; + ++MEMPTR(); const auto memory = BUS().read(); BUS().write(promoteNibble(memory) | lowNibble(A())); A() = higherNibble(A()) | highNibble(memory); @@ -818,7 +812,7 @@ void EightBit::Z80::executeED(const int x, const int y, const int z, const int p switch (z) { case 0: // Input from port with 16-bit address MEMPTR() = BUS().ADDRESS() = BC(); - ++MEMPTR().word; + ++MEMPTR(); readPort(); if (LIKELY(y != 6)) // IN r[y],(C) R(y, BUS().DATA()); @@ -828,7 +822,7 @@ void EightBit::Z80::executeED(const int x, const int y, const int z, const int p break; case 1: // Output to port with 16-bit address MEMPTR() = BUS().ADDRESS() = BC(); - ++MEMPTR().word; + ++MEMPTR(); if (UNLIKELY(y == 6)) // OUT (C),0 BUS().DATA() = 0; else // OUT (C),r[y] @@ -955,15 +949,15 @@ void EightBit::Z80::executeED(const int x, const int y, const int z, const int p break; case 6: // LDIR if (LIKELY(ldir())) { - MEMPTR().word = --PC().word; - --PC().word; + MEMPTR() = --PC(); + --PC(); addCycles(5); } break; case 7: // LDDR if (LIKELY(lddr())) { - MEMPTR().word = --PC().word; - --PC().word; + MEMPTR()= --PC(); + --PC(); addCycles(5); } break; @@ -979,18 +973,18 @@ void EightBit::Z80::executeED(const int x, const int y, const int z, const int p break; case 6: // CPIR if (LIKELY(cpir())) { - MEMPTR().word = --PC().word; - --PC().word; + MEMPTR()= --PC(); + --PC(); addCycles(5); } break; case 7: // CPDR if (LIKELY(cpdr())) { - MEMPTR().word = --PC().word; - --PC().word; + MEMPTR()= --PC(); + --PC(); addCycles(5); } else { - MEMPTR().word = PC().word - 2; + MEMPTR() = PC() - 2; } break; } @@ -1005,13 +999,13 @@ void EightBit::Z80::executeED(const int x, const int y, const int z, const int p break; case 6: // INIR if (LIKELY(inir())) { - PC().word -= 2; + PC() -= 2; addCycles(5); } break; case 7: // INDR if (LIKELY(indr())) { - PC().word -= 2; + PC() -= 2; addCycles(5); } break; @@ -1027,13 +1021,13 @@ void EightBit::Z80::executeED(const int x, const int y, const int z, const int p break; case 6: // OTIR if (LIKELY(otir())) { - PC().word -= 2; + PC() -= 2; addCycles(5); } break; case 7: // OTDR if (LIKELY(otdr())) { - PC().word -= 2; + PC() -= 2; addCycles(5); } break; @@ -1109,14 +1103,14 @@ void EightBit::Z80::executeOther(const int x, const int y, const int z, const in switch (p) { case 0: // LD (BC),A MEMPTR() = BUS().ADDRESS() = BC(); - ++MEMPTR().word; + ++MEMPTR(); MEMPTR().high = BUS().DATA() = A(); BUS().write(); addCycles(7); break; case 1: // LD (DE),A MEMPTR() = BUS().ADDRESS() = DE(); - ++MEMPTR().word; + ++MEMPTR(); MEMPTR().high = BUS().DATA() = A(); BUS().write(); addCycles(7); @@ -1128,7 +1122,7 @@ void EightBit::Z80::executeOther(const int x, const int y, const int z, const in break; case 3: // LD (nn),A MEMPTR() = BUS().ADDRESS() = fetchWord(); - ++MEMPTR().word; + ++MEMPTR(); MEMPTR().high = BUS().DATA() = A(); BUS().write(); addCycles(13); @@ -1141,13 +1135,13 @@ void EightBit::Z80::executeOther(const int x, const int y, const int z, const in switch (p) { case 0: // LD A,(BC) MEMPTR() = BUS().ADDRESS() = BC(); - ++MEMPTR().word; + ++MEMPTR(); A() = BUS().read(); addCycles(7); break; case 1: // LD A,(DE) MEMPTR() = BUS().ADDRESS() = DE(); - ++MEMPTR().word; + ++MEMPTR(); A() = BUS().read(); addCycles(7); break; @@ -1158,7 +1152,7 @@ void EightBit::Z80::executeOther(const int x, const int y, const int z, const in break; case 3: // LD A,(nn) MEMPTR() = BUS().ADDRESS() = fetchWord(); - ++MEMPTR().word; + ++MEMPTR(); A() = BUS().read(); addCycles(13); break; @@ -1173,10 +1167,10 @@ void EightBit::Z80::executeOther(const int x, const int y, const int z, const in case 3: // 16-bit INC/DEC switch (q) { case 0: // INC rp - ++RP(p).word; + ++RP(p); break; case 1: // DEC rp - --RP(p).word; + --RP(p); break; default: UNREACHABLE; diff --git a/Z80/test/Configuration.cpp b/Z80/test/Configuration.cpp index 77ae143..aacba64 100644 --- a/Z80/test/Configuration.cpp +++ b/Z80/test/Configuration.cpp @@ -1,7 +1,7 @@ #include "stdafx.h" #include "Configuration.h" -Configuration::Configuration() +Configuration::Configuration() noexcept : m_debugMode(false), m_profileMode(false), m_romDirectory("roms") { diff --git a/Z80/test/Configuration.h b/Z80/test/Configuration.h index 64a76ae..b5ac774 100644 --- a/Z80/test/Configuration.h +++ b/Z80/test/Configuration.h @@ -6,7 +6,7 @@ class Configuration { public: - Configuration(); + Configuration() noexcept; bool isDebugMode() const { return m_debugMode; diff --git a/inc/InputOutput.h b/inc/InputOutput.h index 8e8ddc3..51cfec2 100644 --- a/inc/InputOutput.h +++ b/inc/InputOutput.h @@ -33,7 +33,7 @@ namespace EightBit { void OnWrittenPort(uint8_t port); private: - std::array m_input; - std::array m_output; + std::array m_input = { 0 }; + std::array m_output = { 0 }; }; } diff --git a/inc/IntelProcessor.h b/inc/IntelProcessor.h index 01dd294..ebe91d2 100644 --- a/inc/IntelProcessor.h +++ b/inc/IntelProcessor.h @@ -156,7 +156,7 @@ namespace EightBit { } void jr(const int8_t offset) { - MEMPTR().word = PC().word + offset; + MEMPTR() = PC() + offset; jump(MEMPTR()); } diff --git a/inc/Processor.h b/inc/Processor.h index bc330a0..d9b8910 100644 --- a/inc/Processor.h +++ b/inc/Processor.h @@ -105,11 +105,11 @@ namespace EightBit { virtual void reset(); bool halted() { return lowered(HALT()); } - void halt() { --PC().word; lower(HALT()); } - void proceed() { ++PC().word; raise(HALT()); } + void halt() { --PC(); lower(HALT()); } + void proceed() { ++PC(); raise(HALT()); } uint8_t fetchByte() { - return BUS().read(PC().word++); + return BUS().read(PC()++); } register16_t fetchWord() { diff --git a/inc/Register.h b/inc/Register.h index 0f2f5d5..a0aeefc 100644 --- a/inc/Register.h +++ b/inc/Register.h @@ -32,6 +32,48 @@ namespace EightBit { uint16_t word; register16_t() noexcept : word(0) {} register16_t(uint16_t w) noexcept : word(w) {} - register16_t(uint8_t l, uint8_t h) noexcept : low(l), high(h) {} - } ; + register16_t(uint8_t l, uint8_t h) noexcept : low(l), high(h) {} + + register16_t& operator++() noexcept { + ++word; + return *this; + } + + register16_t& operator--() noexcept { + --word; + return *this; + } + + register16_t operator++(int) noexcept { + register16_t temporary(*this); + operator++(); + return temporary; + } + + register16_t operator--(int) noexcept { + register16_t temporary(*this); + operator--(); + return temporary; + } + + register16_t& operator+=(const register16_t rhs) noexcept { + this->word += rhs.word; + return *this; + } + + register16_t& operator-=(const register16_t rhs) noexcept { + this->word -= rhs.word; + return *this; + } + }; + + inline register16_t operator+(register16_t lhs, const register16_t rhs) noexcept { + lhs += rhs; + return lhs; + } + + inline register16_t operator-(register16_t lhs, const register16_t rhs) noexcept { + lhs -= rhs; + return lhs; + } } diff --git a/src/IntelProcessor.cpp b/src/IntelProcessor.cpp index caba993..d5cfb5f 100644 --- a/src/IntelProcessor.cpp +++ b/src/IntelProcessor.cpp @@ -9,26 +9,26 @@ EightBit::IntelProcessor::IntelProcessor(Bus& bus) void EightBit::IntelProcessor::reset() { Processor::reset(); - SP().word = AF().word = BC().word = DE().word = HL().word = Mask16; + SP() = AF() = BC() = DE() = HL() = Mask16; } void EightBit::IntelProcessor::push(const uint8_t value) { - BUS().write(--SP().word, value); + BUS().write(--SP(), value); } uint8_t EightBit::IntelProcessor::pop() { - return BUS().read(SP().word++); + return BUS().read(SP()++); } EightBit::register16_t EightBit::IntelProcessor::getWord() { - BUS().ADDRESS().word = MEMPTR().word++; + BUS().ADDRESS() = MEMPTR()++; const auto low = BUS().read(); - ++BUS().ADDRESS().word; + ++BUS().ADDRESS(); const auto high = BUS().read(); return register16_t(low, high); } void EightBit::IntelProcessor::setWord(const register16_t value) { - BUS().write(MEMPTR().word++, value.low); - BUS().write(++BUS().ADDRESS().word, value.high); + BUS().write(MEMPTR()++, value.low); + BUS().write(++BUS().ADDRESS(), value.high); } diff --git a/src/Processor.cpp b/src/Processor.cpp index 3eb1c6a..6916027 100644 --- a/src/Processor.cpp +++ b/src/Processor.cpp @@ -11,14 +11,13 @@ void EightBit::Processor::reset() { raise(INT()); raise(NMI()); raise(RESET()); - PC().word = 0; + PC() = 0; } int EightBit::Processor::run(const int limit) { int current = 0; - while (LIKELY(powered()) && current < limit) { + while (LIKELY(powered()) && current < limit) current += singleStep(); - } return current; }