mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2025-08-15 10:27:26 +00:00
Simplify the usage of the register16_t union.
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
@@ -47,9 +47,9 @@ namespace EightBit {
|
|||||||
InputOutput& m_ports;
|
InputOutput& m_ports;
|
||||||
|
|
||||||
register16_t af;
|
register16_t af;
|
||||||
register16_t bc = { { 0xff, 0xff } };
|
register16_t bc = 0xffff;
|
||||||
register16_t de = { { 0xff, 0xff } };
|
register16_t de = 0xffff;
|
||||||
register16_t hl = { { 0xff, 0xff } };
|
register16_t hl = 0xffff;
|
||||||
|
|
||||||
uint8_t R(int r) {
|
uint8_t R(int r) {
|
||||||
switch (r) {
|
switch (r) {
|
||||||
|
@@ -12,10 +12,9 @@ EightBit::register16_t& EightBit::Intel8080::AF() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
EightBit::register16_t EightBit::Intel8080::AF() const {
|
EightBit::register16_t EightBit::Intel8080::AF() const {
|
||||||
register16_t returned;
|
const auto low = (af.low | Bit1) & ~(Bit5 | Bit3);
|
||||||
returned.low = (af.low | Bit1) & ~(Bit5 | Bit3);
|
const auto high = af.high;
|
||||||
returned.high = af.high;
|
return register16_t(low, high);
|
||||||
return returned;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EightBit::register16_t EightBit::Intel8080::BC() const {
|
EightBit::register16_t EightBit::Intel8080::BC() const {
|
||||||
@@ -142,8 +141,7 @@ void EightBit::Intel8080::add(register16_t value) {
|
|||||||
|
|
||||||
void EightBit::Intel8080::add(uint8_t value, int carry) {
|
void EightBit::Intel8080::add(uint8_t value, int carry) {
|
||||||
|
|
||||||
register16_t result;
|
const register16_t result = A() + value + carry;
|
||||||
result.word = A() + value + carry;
|
|
||||||
|
|
||||||
adjustAuxiliaryCarryAdd(F(), A(), value, result.word);
|
adjustAuxiliaryCarryAdd(F(), A(), value, result.word);
|
||||||
|
|
||||||
@@ -159,8 +157,7 @@ void EightBit::Intel8080::adc(uint8_t value) {
|
|||||||
|
|
||||||
void EightBit::Intel8080::subtract(uint8_t& operand, uint8_t value, int carry) {
|
void EightBit::Intel8080::subtract(uint8_t& operand, uint8_t value, int carry) {
|
||||||
|
|
||||||
register16_t result;
|
const register16_t result = operand - value - carry;
|
||||||
result.word = operand - value - carry;
|
|
||||||
|
|
||||||
adjustAuxiliaryCarrySub(F(), operand, value, result.word);
|
adjustAuxiliaryCarrySub(F(), operand, value, result.word);
|
||||||
|
|
||||||
|
@@ -29,9 +29,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
EightBit::register16_t getStartAddress() const {
|
EightBit::register16_t getStartAddress() const {
|
||||||
EightBit::register16_t returned;
|
//EightBit::register16_t returned;
|
||||||
returned.word = 0x100;
|
//returned.word = 0x100;
|
||||||
return returned;
|
return 0x100;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@@ -172,7 +172,7 @@ namespace EightBit {
|
|||||||
int m_timerCounter = 0;
|
int m_timerCounter = 0;
|
||||||
int m_timerRate = 0;
|
int m_timerRate = 0;
|
||||||
|
|
||||||
register16_t m_dmaAddress = { 0, 0 };
|
register16_t m_dmaAddress;
|
||||||
bool m_dmaTransferActive = false;
|
bool m_dmaTransferActive = false;
|
||||||
|
|
||||||
bool m_scanP15 = false;
|
bool m_scanP15 = false;
|
||||||
|
@@ -36,10 +36,9 @@ namespace EightBit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
register16_t AF() const final {
|
register16_t AF() const final {
|
||||||
register16_t returned;
|
const auto low = higherNibble(af.low);
|
||||||
returned.low = higherNibble(af.low);
|
const auto high = af.high;
|
||||||
returned.high = af.high;
|
return register16_t(low, high);
|
||||||
return returned;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual register16_t BC() const final { return bc; }
|
virtual register16_t BC() const final { return bc; }
|
||||||
@@ -59,10 +58,10 @@ namespace EightBit {
|
|||||||
private:
|
private:
|
||||||
Bus& m_bus;
|
Bus& m_bus;
|
||||||
|
|
||||||
register16_t af = { { 0xff, 0xff } };
|
register16_t af = 0xffff;
|
||||||
register16_t bc = { { 0xff, 0xff } };
|
register16_t bc = 0xffff;
|
||||||
register16_t de = { { 0xff, 0xff } };
|
register16_t de = 0xffff;
|
||||||
register16_t hl = { { 0xff, 0xff } };
|
register16_t hl = 0xffff;
|
||||||
|
|
||||||
bool m_ime = false;
|
bool m_ime = false;
|
||||||
bool m_stopped = false;
|
bool m_stopped = false;
|
||||||
|
@@ -120,8 +120,7 @@ void EightBit::GameBoy::LR35902::add(uint8_t& f, register16_t& operand, register
|
|||||||
|
|
||||||
void EightBit::GameBoy::LR35902::add(uint8_t& f, uint8_t& operand, uint8_t value, int carry) {
|
void EightBit::GameBoy::LR35902::add(uint8_t& f, uint8_t& operand, uint8_t value, int carry) {
|
||||||
|
|
||||||
register16_t result;
|
const register16_t result = operand + value + carry;
|
||||||
result.word = operand + value + carry;
|
|
||||||
|
|
||||||
adjustHalfCarryAdd(f, operand, value, result.low);
|
adjustHalfCarryAdd(f, operand, value, result.low);
|
||||||
|
|
||||||
@@ -138,8 +137,7 @@ void EightBit::GameBoy::LR35902::adc(uint8_t& f, uint8_t& operand, uint8_t value
|
|||||||
|
|
||||||
void EightBit::GameBoy::LR35902::subtract(uint8_t& f, uint8_t& operand, uint8_t value, int carry) {
|
void EightBit::GameBoy::LR35902::subtract(uint8_t& f, uint8_t& operand, uint8_t value, int carry) {
|
||||||
|
|
||||||
register16_t result;
|
const register16_t result = operand - value - carry;
|
||||||
result.word = operand - value - carry;
|
|
||||||
|
|
||||||
adjustHalfCarrySub(f, operand, value, result.low);
|
adjustHalfCarrySub(f, operand, value, result.low);
|
||||||
|
|
||||||
|
@@ -336,6 +336,6 @@ namespace EightBit {
|
|||||||
|
|
||||||
PinLevel m_soLine = Low;
|
PinLevel m_soLine = Low;
|
||||||
|
|
||||||
register16_t m_intermediate = { { 0, 0 } };
|
register16_t m_intermediate;
|
||||||
};
|
};
|
||||||
}
|
}
|
@@ -51,11 +51,10 @@ void EightBit::MOS6502::reset() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
EightBit::register16_t EightBit::MOS6502::getWordPaged(uint8_t page, uint8_t offset) {
|
EightBit::register16_t EightBit::MOS6502::getWordPaged(uint8_t page, uint8_t offset) {
|
||||||
EightBit::register16_t returned;
|
const auto low = getBytePaged(page, offset);
|
||||||
returned.low = getBytePaged(page, offset);
|
|
||||||
++BUS().ADDRESS().low;
|
++BUS().ADDRESS().low;
|
||||||
returned.high = BUS().read();
|
const auto high = BUS().read();
|
||||||
return returned;
|
return register16_t(low, high);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t EightBit::MOS6502::getBytePaged(uint8_t page, uint8_t offset) {
|
uint8_t EightBit::MOS6502::getBytePaged(uint8_t page, uint8_t offset) {
|
||||||
@@ -442,8 +441,7 @@ uint8_t EightBit::MOS6502::SUB_d(const uint8_t operand, const uint8_t data, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EightBit::MOS6502::CMP(uint8_t first, uint8_t second) {
|
void EightBit::MOS6502::CMP(uint8_t first, uint8_t second) {
|
||||||
register16_t result;
|
const register16_t result = first - second;
|
||||||
result.word = first - second;
|
|
||||||
adjustNZ(result.low);
|
adjustNZ(result.low);
|
||||||
clearFlag(P(), CF, result.high);
|
clearFlag(P(), CF, result.high);
|
||||||
}
|
}
|
||||||
|
@@ -114,8 +114,8 @@ namespace EightBit {
|
|||||||
std::array<register16_t, 2> m_accumulatorFlags;
|
std::array<register16_t, 2> m_accumulatorFlags;
|
||||||
int m_accumulatorFlagsSet = 0;
|
int m_accumulatorFlagsSet = 0;
|
||||||
|
|
||||||
register16_t m_ix = { { 0xff, 0xff } };
|
register16_t m_ix = 0xffff;
|
||||||
register16_t m_iy = { { 0xff, 0xff } };
|
register16_t m_iy = 0xffff;
|
||||||
|
|
||||||
refresh_t m_refresh = 0x7f;
|
refresh_t m_refresh = 0x7f;
|
||||||
|
|
||||||
@@ -421,7 +421,7 @@ namespace EightBit {
|
|||||||
void ccf();
|
void ccf();
|
||||||
void cpl();
|
void cpl();
|
||||||
|
|
||||||
void xhtl(register16_t& operand);
|
void xhtl();
|
||||||
|
|
||||||
void blockCompare();
|
void blockCompare();
|
||||||
|
|
||||||
|
@@ -255,8 +255,7 @@ void EightBit::Z80::add(const register16_t value) {
|
|||||||
|
|
||||||
void EightBit::Z80::add(const uint8_t value, const int carry) {
|
void EightBit::Z80::add(const uint8_t value, const int carry) {
|
||||||
|
|
||||||
register16_t result;
|
const register16_t result = A() + value + carry;
|
||||||
result.word = A() + value + carry;
|
|
||||||
|
|
||||||
adjustHalfCarryAdd(F(), A(), value, result.low);
|
adjustHalfCarryAdd(F(), A(), value, result.low);
|
||||||
adjustOverflowAdd(F(), A(), value, result.low);
|
adjustOverflowAdd(F(), A(), value, result.low);
|
||||||
@@ -274,8 +273,7 @@ void EightBit::Z80::adc(const uint8_t value) {
|
|||||||
|
|
||||||
void EightBit::Z80::subtract(uint8_t& operand, const uint8_t value, const int carry) {
|
void EightBit::Z80::subtract(uint8_t& operand, const uint8_t value, const int carry) {
|
||||||
|
|
||||||
register16_t result;
|
const register16_t result = operand - value - carry;
|
||||||
result.word = operand - value - carry;
|
|
||||||
|
|
||||||
adjustHalfCarrySub(F(), operand, value, result.low);
|
adjustHalfCarrySub(F(), operand, value, result.low);
|
||||||
adjustOverflowSub(F(), operand, value, result.low);
|
adjustOverflowSub(F(), operand, value, result.low);
|
||||||
@@ -463,14 +461,14 @@ void EightBit::Z80::ccf() {
|
|||||||
adjustXY<Z80>(F(), A());
|
adjustXY<Z80>(F(), A());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EightBit::Z80::xhtl(register16_t& operand) {
|
void EightBit::Z80::xhtl() {
|
||||||
MEMPTR().low = BUS().read(SP());
|
MEMPTR().low = BUS().read(SP());
|
||||||
BUS().write(operand.low);
|
BUS().write(HL2().low);
|
||||||
operand.low = MEMPTR().low;
|
HL2().low = MEMPTR().low;
|
||||||
++BUS().ADDRESS().word;
|
++BUS().ADDRESS().word;
|
||||||
MEMPTR().high = BUS().read();
|
MEMPTR().high = BUS().read();
|
||||||
BUS().write(operand.high);
|
BUS().write(HL2().high);
|
||||||
operand.high = MEMPTR().high;
|
HL2().high = MEMPTR().high;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EightBit::Z80::blockCompare() {
|
void EightBit::Z80::blockCompare() {
|
||||||
@@ -1420,7 +1418,7 @@ void EightBit::Z80::executeOther(const int x, const int y, const int z, const in
|
|||||||
addCycles(11);
|
addCycles(11);
|
||||||
break;
|
break;
|
||||||
case 4: // EX (SP),HL
|
case 4: // EX (SP),HL
|
||||||
xhtl(HL2());
|
xhtl();
|
||||||
addCycles(19);
|
addCycles(19);
|
||||||
break;
|
break;
|
||||||
case 5: // EX DE,HL
|
case 5: // EX DE,HL
|
||||||
|
@@ -29,9 +29,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
EightBit::register16_t getStartAddress() const {
|
EightBit::register16_t getStartAddress() const {
|
||||||
EightBit::register16_t returned;
|
//EightBit::register16_t returned;
|
||||||
returned.word = 0x100;
|
//returned.word = 0x100;
|
||||||
return returned;
|
return 0x100;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
14
inc/Bus.h
14
inc/Bus.h
@@ -30,13 +30,17 @@ namespace EightBit {
|
|||||||
uint16_t peekWord(uint16_t address) const;
|
uint16_t peekWord(uint16_t address) const;
|
||||||
|
|
||||||
uint8_t read();
|
uint8_t read();
|
||||||
uint8_t read(uint16_t offset);
|
template<class T> uint8_t read(const T address) {
|
||||||
uint8_t read(register16_t address);
|
ADDRESS() = address;
|
||||||
|
return read();
|
||||||
|
}
|
||||||
|
|
||||||
void write();
|
void write();
|
||||||
void write(uint8_t value);
|
void write(uint8_t value);
|
||||||
void write(uint16_t offset, uint8_t value);
|
template<class T> void write(const T offset, const uint8_t value) {
|
||||||
void write(register16_t address, uint8_t value);
|
ADDRESS() = offset;
|
||||||
|
write(value);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual uint8_t& reference(uint16_t address) = 0;
|
virtual uint8_t& reference(uint16_t address) = 0;
|
||||||
@@ -47,6 +51,6 @@ namespace EightBit {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t m_data = 0xff;
|
uint8_t m_data = 0xff;
|
||||||
register16_t m_address{ { 0xff, 0xff } };
|
register16_t m_address = 0xffff;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -183,7 +183,7 @@ namespace EightBit {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::array<opcode_decoded_t, 0x100> m_decodedOpcodes;
|
std::array<opcode_decoded_t, 0x100> m_decodedOpcodes;
|
||||||
register16_t m_sp = { { 0xff, 0xff } };
|
register16_t m_sp = 0xffff;
|
||||||
register16_t m_memptr = { { 0, 0 } };
|
register16_t m_memptr;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -124,10 +124,9 @@ namespace EightBit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
register16_t fetchWord() {
|
register16_t fetchWord() {
|
||||||
register16_t returned;
|
const auto low = fetchByte();
|
||||||
returned.low = fetchByte();
|
const auto high = fetchByte();
|
||||||
returned.high = fetchByte();
|
return register16_t(low, high);
|
||||||
return returned;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void push(uint8_t value) = 0;
|
virtual void push(uint8_t value) = 0;
|
||||||
@@ -139,10 +138,9 @@ namespace EightBit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
register16_t popWord() {
|
register16_t popWord() {
|
||||||
register16_t returned;
|
const auto low = pop();
|
||||||
returned.low = pop();
|
const auto high = pop();
|
||||||
returned.high = pop();
|
return register16_t(low, high);
|
||||||
return returned;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void jump(const register16_t destination) {
|
void jump(const register16_t destination) {
|
||||||
@@ -166,7 +164,7 @@ namespace EightBit {
|
|||||||
private:
|
private:
|
||||||
Bus& m_bus;
|
Bus& m_bus;
|
||||||
int m_cycles = 0;
|
int m_cycles = 0;
|
||||||
register16_t m_pc = { { 0, 0 } };
|
register16_t m_pc;
|
||||||
|
|
||||||
PinLevel m_intLine = Low;
|
PinLevel m_intLine = Low;
|
||||||
PinLevel m_nmiLine = Low;
|
PinLevel m_nmiLine = Low;
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace EightBit {
|
namespace EightBit {
|
||||||
typedef union {
|
union register16_t {
|
||||||
struct {
|
struct {
|
||||||
#ifdef HOST_LITTLE_ENDIAN
|
#ifdef HOST_LITTLE_ENDIAN
|
||||||
uint8_t low;
|
uint8_t low;
|
||||||
@@ -30,5 +30,8 @@ namespace EightBit {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
uint16_t word;
|
uint16_t word;
|
||||||
} register16_t;
|
register16_t() : word(0) {}
|
||||||
|
register16_t(uint16_t w) : word(w) {}
|
||||||
|
register16_t(uint8_t l, uint8_t h) : low(l), high(h) {}
|
||||||
|
} ;
|
||||||
}
|
}
|
||||||
|
27
src/Bus.cpp
27
src/Bus.cpp
@@ -18,10 +18,9 @@ void EightBit::Bus::poke(const uint16_t address, const uint8_t value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint16_t EightBit::Bus::peekWord(const uint16_t address) const {
|
uint16_t EightBit::Bus::peekWord(const uint16_t address) const {
|
||||||
register16_t returned;
|
const auto low = peek(address);
|
||||||
returned.low = peek(address);
|
const auto high = peek(address + 1);
|
||||||
returned.high = peek(address + 1);
|
return register16_t(low, high).word;
|
||||||
return returned.word;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t EightBit::Bus::read() {
|
uint8_t EightBit::Bus::read() {
|
||||||
@@ -31,16 +30,6 @@ uint8_t EightBit::Bus::read() {
|
|||||||
return DATA();
|
return DATA();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t EightBit::Bus::read(const uint16_t offset) {
|
|
||||||
ADDRESS().word = offset;
|
|
||||||
return read();
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t EightBit::Bus::read(const register16_t address) {
|
|
||||||
ADDRESS() = address;
|
|
||||||
return read();
|
|
||||||
}
|
|
||||||
|
|
||||||
void EightBit::Bus::write() {
|
void EightBit::Bus::write() {
|
||||||
WritingByte.fire(EventArgs::empty());
|
WritingByte.fire(EventArgs::empty());
|
||||||
reference() = DATA();
|
reference() = DATA();
|
||||||
@@ -52,16 +41,6 @@ void EightBit::Bus::write(const uint8_t value) {
|
|||||||
write();
|
write();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EightBit::Bus::write(const uint16_t offset, const uint8_t value) {
|
|
||||||
ADDRESS().word = offset;
|
|
||||||
write(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void EightBit::Bus::write(const register16_t address, const uint8_t value) {
|
|
||||||
ADDRESS() = address;
|
|
||||||
write(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t EightBit::Bus::reference() const {
|
uint8_t EightBit::Bus::reference() const {
|
||||||
return reference(ADDRESS().word);
|
return reference(ADDRESS().word);
|
||||||
}
|
}
|
||||||
|
@@ -21,10 +21,11 @@ uint8_t EightBit::IntelProcessor::pop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
EightBit::register16_t EightBit::IntelProcessor::getWord() {
|
EightBit::register16_t EightBit::IntelProcessor::getWord() {
|
||||||
register16_t returned;
|
BUS().ADDRESS().word = MEMPTR().word++;
|
||||||
returned.low = BUS().read(MEMPTR().word++);
|
const auto low = BUS().read();
|
||||||
returned.high = BUS().read(++BUS().ADDRESS().word);
|
++BUS().ADDRESS().word;
|
||||||
return returned;
|
const auto high = BUS().read();
|
||||||
|
return register16_t(low, high);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EightBit::IntelProcessor::setWord(const register16_t value) {
|
void EightBit::IntelProcessor::setWord(const register16_t value) {
|
||||||
|
Reference in New Issue
Block a user