Sort out some exception and member initialisation rules.

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2018-08-11 21:19:19 +01:00
parent b640da1910
commit 70c70af969
30 changed files with 157 additions and 123 deletions

View File

@ -10,7 +10,7 @@
namespace EightBit { namespace EightBit {
class Disassembler { class Disassembler {
public: public:
Disassembler(); Disassembler() noexcept;
static std::string state(Intel8080& cpu); static std::string state(Intel8080& cpu);
std::string disassemble(Intel8080& cpu); std::string disassemble(Intel8080& cpu);

View File

@ -6,7 +6,7 @@
namespace EightBit { namespace EightBit {
class Profiler { class Profiler {
public: public:
Profiler(); Profiler() noexcept;
~Profiler(); ~Profiler();
void addInstruction(uint8_t instruction); void addInstruction(uint8_t instruction);

View File

@ -8,7 +8,7 @@
#include <iomanip> #include <iomanip>
#include <bitset> #include <bitset>
EightBit::Disassembler::Disassembler() { EightBit::Disassembler::Disassembler() noexcept {
// Disable exceptions where too many format arguments are available // Disable exceptions where too many format arguments are available
m_formatter.exceptions(boost::io::all_error_bits ^ boost::io::too_many_args_bit); m_formatter.exceptions(boost::io::all_error_bits ^ boost::io::too_many_args_bit);
} }

View File

@ -117,7 +117,7 @@ bool EightBit::Intel8080::callConditionalFlag(int flag) {
void EightBit::Intel8080::add(register16_t value) { void EightBit::Intel8080::add(register16_t value) {
const auto result = HL().word + value.word; const auto result = HL().word + value.word;
HL().word = result; HL() = result;
setFlag(F(), CF, result & Bit16); setFlag(F(), CF, result & Bit16);
} }
@ -229,7 +229,7 @@ void EightBit::Intel8080::xhtl() {
MEMPTR().low = BUS().read(SP()); MEMPTR().low = BUS().read(SP());
BUS().write(L()); BUS().write(L());
L() = MEMPTR().low; L() = MEMPTR().low;
++BUS().ADDRESS().word; ++BUS().ADDRESS();
MEMPTR().high = BUS().read(); MEMPTR().high = BUS().read();
BUS().write(H()); BUS().write(H());
H() = MEMPTR().high; 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 case 3: // 16-bit INC/DEC
switch (q) { switch (q) {
case 0: // INC rp case 0: // INC rp
++RP(p).word; ++RP(p);
break; break;
case 1: // DEC rp case 1: // DEC rp
--RP(p).word; --RP(p);
break; break;
default: default:
UNREACHABLE; UNREACHABLE;

View File

@ -4,7 +4,7 @@
#include <iostream> #include <iostream>
EightBit::Profiler::Profiler() { EightBit::Profiler::Profiler() noexcept {
m_instructions.fill(0); m_instructions.fill(0);
m_addresses.fill(0); m_addresses.fill(0);
} }

View File

@ -14,7 +14,7 @@ namespace EightBit {
Dark Dark
}; };
AbstractColourPalette() AbstractColourPalette() noexcept
: m_colours(4) { : m_colours(4) {
} }

View File

@ -13,7 +13,7 @@ namespace EightBit {
class Disassembler { class Disassembler {
public: public:
Disassembler(); Disassembler() noexcept;
static std::string state(LR35902& cpu); static std::string state(LR35902& cpu);
std::string disassemble(LR35902& cpu); std::string disassemble(LR35902& cpu);
@ -37,7 +37,7 @@ namespace EightBit {
}; };
mutable boost::format m_formatter; mutable boost::format m_formatter;
bool m_prefixCB; bool m_prefixCB = false;
void disassemble(std::ostringstream& output, LR35902& cpu, uint16_t pc); void disassemble(std::ostringstream& output, LR35902& cpu, uint16_t pc);

View File

@ -35,12 +35,12 @@ namespace EightBit {
void loadObjectAttributes(); void loadObjectAttributes();
private: private:
std::array<uint32_t, PixelCount> m_pixels; std::array<uint32_t, PixelCount> m_pixels = { 0 };
Bus& m_bus; Bus& m_bus;
Ram& m_oam; Ram& m_oam;
Ram& m_vram; Ram& m_vram;
const AbstractColourPalette* m_colours; const AbstractColourPalette* m_colours;
std::array<ObjectAttribute, 40> m_objectAttributes; std::array<ObjectAttribute, 40> m_objectAttributes = { ObjectAttribute() };
uint8_t m_control = 0; uint8_t m_control = 0;
uint8_t m_scanLine = 0; uint8_t m_scanLine = 0;

View File

@ -33,7 +33,7 @@ namespace EightBit {
RomPageSize = 0x4000 RomPageSize = 0x4000
}; };
Bus(); Bus() noexcept;
LR35902& CPU() { return m_cpu; } LR35902& CPU() { return m_cpu; }
Ram& VRAM() { return m_videoRam; } Ram& VRAM() { return m_videoRam; }

View File

@ -9,7 +9,7 @@
#include "LR35902.h" #include "LR35902.h"
#include "IoRegisters.h" #include "IoRegisters.h"
EightBit::GameBoy::Disassembler::Disassembler() { EightBit::GameBoy::Disassembler::Disassembler() noexcept {
// Disable exceptions where too many format arguments are available // Disable exceptions where too many format arguments are available
m_formatter.exceptions(boost::io::all_error_bits ^ boost::io::too_many_args_bit); m_formatter.exceptions(boost::io::all_error_bits ^ boost::io::too_many_args_bit);
} }

View File

@ -2,7 +2,7 @@
#include "GameBoyBus.h" #include "GameBoyBus.h"
#include "Display.h" #include "Display.h"
EightBit::GameBoy::Bus::Bus() EightBit::GameBoy::Bus::Bus() noexcept
: m_cpu(*this), : m_cpu(*this),
m_ioPorts(*this) { m_ioPorts(*this) {
WrittenByte.connect(std::bind(&GameBoy::Bus::Bus_WrittenByte, this, std::placeholders::_1)); WrittenByte.connect(std::bind(&GameBoy::Bus::Bus_WrittenByte, this, std::placeholders::_1));

View File

@ -12,7 +12,7 @@ EightBit::GameBoy::IoRegisters::IoRegisters(Bus& bus)
void EightBit::GameBoy::IoRegisters::reset() { void EightBit::GameBoy::IoRegisters::reset() {
poke(NR52, 0xf1); poke(NR52, 0xf1);
poke(LCDC, DisplayBackground | BackgroundCharacterDataSelection | LcdEnable); poke(LCDC, DisplayBackground | BackgroundCharacterDataSelection | LcdEnable);
m_divCounter.word = 0xabcc; m_divCounter = 0xabcc;
m_timerCounter = 0; m_timerCounter = 0;
} }
@ -194,7 +194,7 @@ bool EightBit::GameBoy::IoRegisters::timerDisabled() {
} }
void EightBit::GameBoy::IoRegisters::incrementDIV(int cycles) { void EightBit::GameBoy::IoRegisters::incrementDIV(int cycles) {
m_divCounter.word += cycles; m_divCounter += cycles;
poke(DIV, m_divCounter.high); poke(DIV, m_divCounter.high);
} }

View File

@ -12,7 +12,7 @@ EightBit::GameBoy::LR35902::LR35902(Bus& memory)
void EightBit::GameBoy::LR35902::reset() { void EightBit::GameBoy::LR35902::reset() {
IntelProcessor::reset(); IntelProcessor::reset();
di(); di();
SP().word = Mask16 - 1; SP() = Mask16 - 1;
m_prefixCB = false; m_prefixCB = false;
} }
@ -469,11 +469,11 @@ void EightBit::GameBoy::LR35902::executeOther(int x, int y, int z, int p, int q)
addCycles(2); addCycles(2);
break; break;
case 2: // GB: LDI (HL),A case 2: // GB: LDI (HL),A
BUS().write(HL().word++, A()); BUS().write(HL()++, A());
addCycles(2); addCycles(2);
break; break;
case 3: // GB: LDD (HL),A case 3: // GB: LDD (HL),A
BUS().write(HL().word--, A()); BUS().write(HL()--, A());
addCycles(2); addCycles(2);
break; break;
default: default:
@ -491,11 +491,11 @@ void EightBit::GameBoy::LR35902::executeOther(int x, int y, int z, int p, int q)
addCycles(2); addCycles(2);
break; break;
case 2: // GB: LDI A,(HL) case 2: // GB: LDI A,(HL)
A() = BUS().read(HL().word++); A() = BUS().read(HL()++);
addCycles(2); addCycles(2);
break; break;
case 3: // GB: LDD A,(HL) case 3: // GB: LDD A,(HL)
A() = BUS().read(HL().word--); A() = BUS().read(HL()--);
addCycles(2); addCycles(2);
break; break;
default: 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 case 3: // 16-bit INC/DEC
switch (q) { switch (q) {
case 0: // INC rp case 0: // INC rp
++RP(p).word; ++RP(p);
break; break;
case 1: // DEC rp case 1: // DEC rp
--RP(p).word; --RP(p);
break; break;
default: default:
UNREACHABLE; 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 auto before = SP().word;
const int8_t value = fetchByte(); const int8_t value = fetchByte();
const auto result = before + value; const auto result = before + value;
SP().word = result; SP() = result;
const auto carried = before ^ value ^ (result & Mask16); const auto carried = before ^ value ^ (result & Mask16);
clearFlag(F(), ZF | NF); clearFlag(F(), ZF | NF);
setFlag(F(), CF, carried & Bit8); 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 auto before = SP().word;
const int8_t value = fetchByte(); const int8_t value = fetchByte();
const auto result = before + value; const auto result = before + value;
HL().word = result; HL() = result;
const auto carried = before ^ value ^ (result & Mask16); const auto carried = before ^ value ^ (result & Mask16);
clearFlag(F(), ZF | NF); clearFlag(F(), ZF | NF);
setFlag(F(), CF, carried & Bit8); setFlag(F(), CF, carried & Bit8);

View File

@ -21,7 +21,7 @@ namespace EightBit {
MOS6502& processor; MOS6502& processor;
const Symbols& symbols; const Symbols& symbols;
mutable uint16_t m_address; mutable uint16_t m_address = 0xffff;
std::string disassemble_Implied(const std::string& instruction) const { std::string disassemble_Implied(const std::string& instruction) const {
return "\t" + instruction; return "\t" + instruction;

View File

@ -8,7 +8,7 @@
namespace EightBit { namespace EightBit {
class Symbols { class Symbols {
public: public:
Symbols(std::string path = ""); Symbols(std::string path = "") noexcept;
const std::map<uint16_t, std::string>& getLabels() const { return labels; } const std::map<uint16_t, std::string>& getLabels() const { return labels; }
const std::map<uint16_t, std::string>& getConstants() const { return constants; } const std::map<uint16_t, std::string>& getConstants() const { return constants; }

View File

@ -102,14 +102,14 @@ namespace EightBit {
std::tuple<register16_t, bool> Address_AbsoluteX() { std::tuple<register16_t, bool> Address_AbsoluteX() {
auto address = Address_Absolute(); auto address = Address_Absolute();
const auto page = address.high; const auto page = address.high;
address.word += X(); address += X();
return std::tuple<register16_t, bool>(address, address.high != page); return std::tuple<register16_t, bool>(address, address.high != page);
} }
std::tuple<register16_t, bool> Address_AbsoluteY() { std::tuple<register16_t, bool> Address_AbsoluteY() {
auto address = Address_Absolute(); auto address = Address_Absolute();
const auto page = address.high; const auto page = address.high;
address.word += Y(); address += Y();
return std::tuple<register16_t, bool>(address, address.high != page); return std::tuple<register16_t, bool>(address, address.high != page);
} }
@ -120,7 +120,7 @@ namespace EightBit {
std::tuple<register16_t, bool> Address_IndirectIndexedY() { std::tuple<register16_t, bool> Address_IndirectIndexedY() {
auto address = Address_ZeroPageIndirect(); auto address = Address_ZeroPageIndirect();
const auto page = address.high; const auto page = address.high;
address.word += Y(); address += Y();
return std::tuple<register16_t, bool>(address, address.high != page); return std::tuple<register16_t, bool>(address, address.high != page);
} }

View File

@ -10,7 +10,7 @@
#include <boost/algorithm/string/regex.hpp> #include <boost/algorithm/string/regex.hpp>
#include <boost/regex.hpp> #include <boost/regex.hpp>
EightBit::Symbols::Symbols(std::string path) { EightBit::Symbols::Symbols(std::string path) noexcept {
if (!path.empty()) { if (!path.empty()) {
Parse(path); Parse(path);
AssignSymbols(); AssignSymbols();

View File

@ -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) { void EightBit::MOS6502::Branch(int8_t displacement) {
const auto page = PC().high; const auto page = PC().high;
PC().word += displacement; PC() += displacement;
if (UNLIKELY(PC().high != page)) if (UNLIKELY(PC().high != page))
addCycle(); addCycle();
addCycle(); addCycle();
@ -514,7 +514,7 @@ void EightBit::MOS6502::PLP() {
void EightBit::MOS6502::JSR_abs() { void EightBit::MOS6502::JSR_abs() {
const auto address = Address_Absolute(); const auto address = Address_Absolute();
--PC().word; --PC();
call(address); call(address);
} }
@ -525,7 +525,7 @@ void EightBit::MOS6502::RTI() {
void EightBit::MOS6502::RTS() { void EightBit::MOS6502::RTS() {
ret(); ret();
++PC().word; ++PC();
} }
void EightBit::MOS6502::JMP_abs() { void EightBit::MOS6502::JMP_abs() {
@ -537,8 +537,7 @@ void EightBit::MOS6502::JMP_ind() {
} }
void EightBit::MOS6502::BRK() { void EightBit::MOS6502::BRK() {
++PC().word; pushWord(++PC());
pushWord(PC());
PHP(); PHP();
setFlag(P(), IF); setFlag(P(), IF);
jump(getWordPaged(0xff, IRQvector)); jump(getWordPaged(0xff, IRQvector));

View File

@ -9,7 +9,7 @@ namespace EightBit {
class Disassembler { class Disassembler {
public: public:
Disassembler(); Disassembler() noexcept;
static std::string state(Z80& cpu); static std::string state(Z80& cpu);
std::string disassemble(Z80& cpu); std::string disassemble(Z80& cpu);
@ -25,10 +25,10 @@ namespace EightBit {
private: private:
mutable boost::format m_formatter; mutable boost::format m_formatter;
bool m_prefixCB; bool m_prefixCB = false;
bool m_prefixDD; bool m_prefixDD = false;
bool m_prefixED; bool m_prefixED = false;
bool m_prefixFD; bool m_prefixFD = false;
void disassemble(std::ostringstream& output, Z80& cpu, uint16_t pc); void disassemble(std::ostringstream& output, Z80& cpu, uint16_t pc);

View File

@ -364,7 +364,7 @@ namespace EightBit {
void xhtl(); void xhtl();
void blockCompare(); void blockCompare(register16_t source, register16_t& counter);
void cpi(); void cpi();
bool cpir(); bool cpir();
@ -372,7 +372,7 @@ namespace EightBit {
void cpd(); void cpd();
bool cpdr(); bool cpdr();
void blockLoad(register16_t source, register16_t destination); void blockLoad(register16_t source, register16_t destination, register16_t& counter);
void ldi(); void ldi();
bool ldir(); bool ldir();

View File

@ -10,7 +10,7 @@
#include "Z80.h" #include "Z80.h"
EightBit::Disassembler::Disassembler() { EightBit::Disassembler::Disassembler() noexcept {
// Disable exceptions where too many format arguments are available // Disable exceptions where too many format arguments are available
m_formatter.exceptions(boost::io::all_error_bits ^ boost::io::too_many_args_bit); m_formatter.exceptions(boost::io::all_error_bits ^ boost::io::too_many_args_bit);
} }

View File

@ -183,7 +183,7 @@ void EightBit::Z80::sbc(const register16_t value) {
const auto valueNegative = value.high & SF; const auto valueNegative = value.high & SF;
const auto result = MEMPTR().word - value.word - (F() & CF); const auto result = MEMPTR().word - value.word - (F() & CF);
HL2().word = result; HL2() = result;
const auto afterNegative = HL2().high & SF; const auto afterNegative = HL2().high & SF;
@ -195,7 +195,7 @@ void EightBit::Z80::sbc(const register16_t value) {
setFlag(F(), CF, result & Bit16); setFlag(F(), CF, result & Bit16);
adjustXY<Z80>(F(), HL2().high); adjustXY<Z80>(F(), HL2().high);
++MEMPTR().word; ++MEMPTR();
} }
void EightBit::Z80::adc(const register16_t value) { 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 valueNegative = value.high & SF;
const auto result = MEMPTR().word + value.word + (F() & CF); const auto result = MEMPTR().word + value.word + (F() & CF);
HL2().word = result; HL2() = result;
const auto afterNegative = HL2().high & SF; const auto afterNegative = HL2().high & SF;
@ -218,7 +218,7 @@ void EightBit::Z80::adc(const register16_t value) {
setFlag(F(), CF, result & Bit16); setFlag(F(), CF, result & Bit16);
adjustXY<Z80>(F(), HL2().high); adjustXY<Z80>(F(), HL2().high);
++MEMPTR().word; ++MEMPTR();
} }
void EightBit::Z80::add(const register16_t value) { 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; const auto result = MEMPTR().word + value.word;
HL2().word = result; HL2() = result;
clearFlag(F(), NF); clearFlag(F(), NF);
setFlag(F(), CF, result & Bit16); setFlag(F(), CF, result & Bit16);
adjustHalfCarryAdd(F(), MEMPTR().high, value.high, HL2().high); adjustHalfCarryAdd(F(), MEMPTR().high, value.high, HL2().high);
adjustXY<Z80>(F(), HL2().high); adjustXY<Z80>(F(), HL2().high);
++MEMPTR().word; ++MEMPTR();
} }
void EightBit::Z80::add(const uint8_t value, const int carry) { void EightBit::Z80::add(const uint8_t value, const int carry) {
@ -438,18 +438,18 @@ void EightBit::Z80::xhtl() {
MEMPTR().low = BUS().read(SP()); MEMPTR().low = BUS().read(SP());
BUS().write(HL2().low); BUS().write(HL2().low);
HL2().low = MEMPTR().low; HL2().low = MEMPTR().low;
++BUS().ADDRESS().word; ++BUS().ADDRESS();
MEMPTR().high = BUS().read(); MEMPTR().high = BUS().read();
BUS().write(HL2().high); BUS().write(HL2().high);
HL2().high = MEMPTR().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; uint8_t result = A() - value;
setFlag(F(), PF, --BC().word); setFlag(F(), PF, --counter.word);
adjustSZ<Z80>(F(), result); adjustSZ<Z80>(F(), result);
adjustHalfCarrySub(F(), A(), value, result); adjustHalfCarrySub(F(), A(), value, result);
@ -462,15 +462,13 @@ void EightBit::Z80::blockCompare() {
} }
void EightBit::Z80::cpi() { void EightBit::Z80::cpi() {
blockCompare(); blockCompare(HL()++, BC());
++HL().word; ++MEMPTR();
++MEMPTR().word;
} }
void EightBit::Z80::cpd() { void EightBit::Z80::cpd() {
blockCompare(); blockCompare(HL()--, BC());
--HL().word; --MEMPTR();
--MEMPTR().word;
} }
bool EightBit::Z80::cpir() { bool EightBit::Z80::cpir() {
@ -483,26 +481,22 @@ bool EightBit::Z80::cpdr() {
return (F() & PF) && !(F() & ZF); // See CPD 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); const auto value = BUS().read(source);
BUS().write(destination, value); BUS().write(destination, value);
const auto xy = A() + value; const auto xy = A() + value;
setFlag(F(), XF, xy & 8); setFlag(F(), XF, xy & 8);
setFlag(F(), YF, xy & 2); setFlag(F(), YF, xy & 2);
clearFlag(F(), NF | HC); clearFlag(F(), NF | HC);
setFlag(F(), PF, --BC().word); setFlag(F(), PF, --counter.word);
} }
void EightBit::Z80::ldd() { void EightBit::Z80::ldd() {
blockLoad(HL(), DE()); blockLoad(HL()--, DE()--, BC());
--HL().word;
--DE().word;
} }
void EightBit::Z80::ldi() { void EightBit::Z80::ldi() {
blockLoad(HL(), DE()); blockLoad(HL()++, DE()++, BC());
++HL().word;
++DE().word;
} }
bool EightBit::Z80::ldir() { bool EightBit::Z80::ldir() {
@ -517,18 +511,18 @@ bool EightBit::Z80::lddr() {
void EightBit::Z80::ini() { void EightBit::Z80::ini() {
MEMPTR() = BUS().ADDRESS() = BC(); MEMPTR() = BUS().ADDRESS() = BC();
++MEMPTR().word; ++MEMPTR();
const auto value = readPort(); const auto value = readPort();
BUS().write(HL().word++, value); BUS().write(HL()++, value);
decrement(B()); decrement(B());
setFlag(F(), NF); setFlag(F(), NF);
} }
void EightBit::Z80::ind() { void EightBit::Z80::ind() {
MEMPTR() = BUS().ADDRESS() = BC(); MEMPTR() = BUS().ADDRESS() = BC();
--MEMPTR().word; --MEMPTR();
const auto value = readPort(); const auto value = readPort();
BUS().write(HL().word--, value); BUS().write(HL()--, value);
decrement(B()); decrement(B());
setFlag(F(), NF); setFlag(F(), NF);
} }
@ -554,15 +548,15 @@ void EightBit::Z80::blockOut() {
} }
void EightBit::Z80::outi() { void EightBit::Z80::outi() {
BUS().ADDRESS().word = HL().word++; BUS().ADDRESS() = HL()++;
blockOut(); blockOut();
MEMPTR().word = BC().word + 1; MEMPTR() = BC().word + 1;
} }
void EightBit::Z80::outd() { void EightBit::Z80::outd() {
BUS().ADDRESS().word = HL().word--; BUS().ADDRESS() = HL()--;
blockOut(); blockOut();
MEMPTR().word = BC().word - 1; MEMPTR() = BC().word - 1;
} }
bool EightBit::Z80::otir() { bool EightBit::Z80::otir() {
@ -577,7 +571,7 @@ bool EightBit::Z80::otdr() {
void EightBit::Z80::rrd() { void EightBit::Z80::rrd() {
MEMPTR() = BUS().ADDRESS() = HL(); MEMPTR() = BUS().ADDRESS() = HL();
++MEMPTR().word; ++MEMPTR();
const auto memory = BUS().read(); const auto memory = BUS().read();
BUS().write(promoteNibble(A()) | highNibble(memory)); BUS().write(promoteNibble(A()) | highNibble(memory));
A() = higherNibble(A()) | lowerNibble(memory); A() = higherNibble(A()) | lowerNibble(memory);
@ -587,7 +581,7 @@ void EightBit::Z80::rrd() {
void EightBit::Z80::rld() { void EightBit::Z80::rld() {
MEMPTR() = BUS().ADDRESS() = HL(); MEMPTR() = BUS().ADDRESS() = HL();
++MEMPTR().word; ++MEMPTR();
const auto memory = BUS().read(); const auto memory = BUS().read();
BUS().write(promoteNibble(memory) | lowNibble(A())); BUS().write(promoteNibble(memory) | lowNibble(A()));
A() = higherNibble(A()) | highNibble(memory); 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) { switch (z) {
case 0: // Input from port with 16-bit address case 0: // Input from port with 16-bit address
MEMPTR() = BUS().ADDRESS() = BC(); MEMPTR() = BUS().ADDRESS() = BC();
++MEMPTR().word; ++MEMPTR();
readPort(); readPort();
if (LIKELY(y != 6)) // IN r[y],(C) if (LIKELY(y != 6)) // IN r[y],(C)
R(y, BUS().DATA()); 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; break;
case 1: // Output to port with 16-bit address case 1: // Output to port with 16-bit address
MEMPTR() = BUS().ADDRESS() = BC(); MEMPTR() = BUS().ADDRESS() = BC();
++MEMPTR().word; ++MEMPTR();
if (UNLIKELY(y == 6)) // OUT (C),0 if (UNLIKELY(y == 6)) // OUT (C),0
BUS().DATA() = 0; BUS().DATA() = 0;
else // OUT (C),r[y] 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; break;
case 6: // LDIR case 6: // LDIR
if (LIKELY(ldir())) { if (LIKELY(ldir())) {
MEMPTR().word = --PC().word; MEMPTR() = --PC();
--PC().word; --PC();
addCycles(5); addCycles(5);
} }
break; break;
case 7: // LDDR case 7: // LDDR
if (LIKELY(lddr())) { if (LIKELY(lddr())) {
MEMPTR().word = --PC().word; MEMPTR()= --PC();
--PC().word; --PC();
addCycles(5); addCycles(5);
} }
break; break;
@ -979,18 +973,18 @@ void EightBit::Z80::executeED(const int x, const int y, const int z, const int p
break; break;
case 6: // CPIR case 6: // CPIR
if (LIKELY(cpir())) { if (LIKELY(cpir())) {
MEMPTR().word = --PC().word; MEMPTR()= --PC();
--PC().word; --PC();
addCycles(5); addCycles(5);
} }
break; break;
case 7: // CPDR case 7: // CPDR
if (LIKELY(cpdr())) { if (LIKELY(cpdr())) {
MEMPTR().word = --PC().word; MEMPTR()= --PC();
--PC().word; --PC();
addCycles(5); addCycles(5);
} else { } else {
MEMPTR().word = PC().word - 2; MEMPTR() = PC() - 2;
} }
break; break;
} }
@ -1005,13 +999,13 @@ void EightBit::Z80::executeED(const int x, const int y, const int z, const int p
break; break;
case 6: // INIR case 6: // INIR
if (LIKELY(inir())) { if (LIKELY(inir())) {
PC().word -= 2; PC() -= 2;
addCycles(5); addCycles(5);
} }
break; break;
case 7: // INDR case 7: // INDR
if (LIKELY(indr())) { if (LIKELY(indr())) {
PC().word -= 2; PC() -= 2;
addCycles(5); addCycles(5);
} }
break; break;
@ -1027,13 +1021,13 @@ void EightBit::Z80::executeED(const int x, const int y, const int z, const int p
break; break;
case 6: // OTIR case 6: // OTIR
if (LIKELY(otir())) { if (LIKELY(otir())) {
PC().word -= 2; PC() -= 2;
addCycles(5); addCycles(5);
} }
break; break;
case 7: // OTDR case 7: // OTDR
if (LIKELY(otdr())) { if (LIKELY(otdr())) {
PC().word -= 2; PC() -= 2;
addCycles(5); addCycles(5);
} }
break; break;
@ -1109,14 +1103,14 @@ void EightBit::Z80::executeOther(const int x, const int y, const int z, const in
switch (p) { switch (p) {
case 0: // LD (BC),A case 0: // LD (BC),A
MEMPTR() = BUS().ADDRESS() = BC(); MEMPTR() = BUS().ADDRESS() = BC();
++MEMPTR().word; ++MEMPTR();
MEMPTR().high = BUS().DATA() = A(); MEMPTR().high = BUS().DATA() = A();
BUS().write(); BUS().write();
addCycles(7); addCycles(7);
break; break;
case 1: // LD (DE),A case 1: // LD (DE),A
MEMPTR() = BUS().ADDRESS() = DE(); MEMPTR() = BUS().ADDRESS() = DE();
++MEMPTR().word; ++MEMPTR();
MEMPTR().high = BUS().DATA() = A(); MEMPTR().high = BUS().DATA() = A();
BUS().write(); BUS().write();
addCycles(7); addCycles(7);
@ -1128,7 +1122,7 @@ void EightBit::Z80::executeOther(const int x, const int y, const int z, const in
break; break;
case 3: // LD (nn),A case 3: // LD (nn),A
MEMPTR() = BUS().ADDRESS() = fetchWord(); MEMPTR() = BUS().ADDRESS() = fetchWord();
++MEMPTR().word; ++MEMPTR();
MEMPTR().high = BUS().DATA() = A(); MEMPTR().high = BUS().DATA() = A();
BUS().write(); BUS().write();
addCycles(13); addCycles(13);
@ -1141,13 +1135,13 @@ void EightBit::Z80::executeOther(const int x, const int y, const int z, const in
switch (p) { switch (p) {
case 0: // LD A,(BC) case 0: // LD A,(BC)
MEMPTR() = BUS().ADDRESS() = BC(); MEMPTR() = BUS().ADDRESS() = BC();
++MEMPTR().word; ++MEMPTR();
A() = BUS().read(); A() = BUS().read();
addCycles(7); addCycles(7);
break; break;
case 1: // LD A,(DE) case 1: // LD A,(DE)
MEMPTR() = BUS().ADDRESS() = DE(); MEMPTR() = BUS().ADDRESS() = DE();
++MEMPTR().word; ++MEMPTR();
A() = BUS().read(); A() = BUS().read();
addCycles(7); addCycles(7);
break; break;
@ -1158,7 +1152,7 @@ void EightBit::Z80::executeOther(const int x, const int y, const int z, const in
break; break;
case 3: // LD A,(nn) case 3: // LD A,(nn)
MEMPTR() = BUS().ADDRESS() = fetchWord(); MEMPTR() = BUS().ADDRESS() = fetchWord();
++MEMPTR().word; ++MEMPTR();
A() = BUS().read(); A() = BUS().read();
addCycles(13); addCycles(13);
break; 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 case 3: // 16-bit INC/DEC
switch (q) { switch (q) {
case 0: // INC rp case 0: // INC rp
++RP(p).word; ++RP(p);
break; break;
case 1: // DEC rp case 1: // DEC rp
--RP(p).word; --RP(p);
break; break;
default: default:
UNREACHABLE; UNREACHABLE;

View File

@ -1,7 +1,7 @@
#include "stdafx.h" #include "stdafx.h"
#include "Configuration.h" #include "Configuration.h"
Configuration::Configuration() Configuration::Configuration() noexcept
: m_debugMode(false), : m_debugMode(false),
m_profileMode(false), m_profileMode(false),
m_romDirectory("roms") { m_romDirectory("roms") {

View File

@ -6,7 +6,7 @@
class Configuration { class Configuration {
public: public:
Configuration(); Configuration() noexcept;
bool isDebugMode() const { bool isDebugMode() const {
return m_debugMode; return m_debugMode;

View File

@ -33,7 +33,7 @@ namespace EightBit {
void OnWrittenPort(uint8_t port); void OnWrittenPort(uint8_t port);
private: private:
std::array<uint8_t, 0x100> m_input; std::array<uint8_t, 0x100> m_input = { 0 };
std::array<uint8_t, 0x100> m_output; std::array<uint8_t, 0x100> m_output = { 0 };
}; };
} }

View File

@ -156,7 +156,7 @@ namespace EightBit {
} }
void jr(const int8_t offset) { void jr(const int8_t offset) {
MEMPTR().word = PC().word + offset; MEMPTR() = PC() + offset;
jump(MEMPTR()); jump(MEMPTR());
} }

View File

@ -105,11 +105,11 @@ namespace EightBit {
virtual void reset(); virtual void reset();
bool halted() { return lowered(HALT()); } bool halted() { return lowered(HALT()); }
void halt() { --PC().word; lower(HALT()); } void halt() { --PC(); lower(HALT()); }
void proceed() { ++PC().word; raise(HALT()); } void proceed() { ++PC(); raise(HALT()); }
uint8_t fetchByte() { uint8_t fetchByte() {
return BUS().read(PC().word++); return BUS().read(PC()++);
} }
register16_t fetchWord() { register16_t fetchWord() {

View File

@ -32,6 +32,48 @@ namespace EightBit {
uint16_t word; uint16_t word;
register16_t() noexcept : word(0) {} register16_t() noexcept : word(0) {}
register16_t(uint16_t w) noexcept : word(w) {} 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;
}
} }

View File

@ -9,26 +9,26 @@ EightBit::IntelProcessor::IntelProcessor(Bus& bus)
void EightBit::IntelProcessor::reset() { void EightBit::IntelProcessor::reset() {
Processor::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) { void EightBit::IntelProcessor::push(const uint8_t value) {
BUS().write(--SP().word, value); BUS().write(--SP(), value);
} }
uint8_t EightBit::IntelProcessor::pop() { uint8_t EightBit::IntelProcessor::pop() {
return BUS().read(SP().word++); return BUS().read(SP()++);
} }
EightBit::register16_t EightBit::IntelProcessor::getWord() { EightBit::register16_t EightBit::IntelProcessor::getWord() {
BUS().ADDRESS().word = MEMPTR().word++; BUS().ADDRESS() = MEMPTR()++;
const auto low = BUS().read(); const auto low = BUS().read();
++BUS().ADDRESS().word; ++BUS().ADDRESS();
const auto high = BUS().read(); const auto high = BUS().read();
return register16_t(low, high); return register16_t(low, high);
} }
void EightBit::IntelProcessor::setWord(const register16_t value) { void EightBit::IntelProcessor::setWord(const register16_t value) {
BUS().write(MEMPTR().word++, value.low); BUS().write(MEMPTR()++, value.low);
BUS().write(++BUS().ADDRESS().word, value.high); BUS().write(++BUS().ADDRESS(), value.high);
} }

View File

@ -11,14 +11,13 @@ void EightBit::Processor::reset() {
raise(INT()); raise(INT());
raise(NMI()); raise(NMI());
raise(RESET()); raise(RESET());
PC().word = 0; PC() = 0;
} }
int EightBit::Processor::run(const int limit) { int EightBit::Processor::run(const int limit) {
int current = 0; int current = 0;
while (LIKELY(powered()) && current < limit) { while (LIKELY(powered()) && current < limit)
current += singleStep(); current += singleStep();
}
return current; return current;
} }