mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-12-22 09:30:32 +00:00
Simplify the usage of the register16_t union.
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
parent
89632774a7
commit
67487b5b6e
@ -47,9 +47,9 @@ namespace EightBit {
|
||||
InputOutput& m_ports;
|
||||
|
||||
register16_t af;
|
||||
register16_t bc = { { 0xff, 0xff } };
|
||||
register16_t de = { { 0xff, 0xff } };
|
||||
register16_t hl = { { 0xff, 0xff } };
|
||||
register16_t bc = 0xffff;
|
||||
register16_t de = 0xffff;
|
||||
register16_t hl = 0xffff;
|
||||
|
||||
uint8_t R(int r) {
|
||||
switch (r) {
|
||||
|
@ -12,10 +12,9 @@ EightBit::register16_t& EightBit::Intel8080::AF() {
|
||||
}
|
||||
|
||||
EightBit::register16_t EightBit::Intel8080::AF() const {
|
||||
register16_t returned;
|
||||
returned.low = (af.low | Bit1) & ~(Bit5 | Bit3);
|
||||
returned.high = af.high;
|
||||
return returned;
|
||||
const auto low = (af.low | Bit1) & ~(Bit5 | Bit3);
|
||||
const auto high = af.high;
|
||||
return register16_t(low, high);
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
register16_t result;
|
||||
result.word = A() + value + carry;
|
||||
const register16_t result = A() + value + carry;
|
||||
|
||||
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) {
|
||||
|
||||
register16_t result;
|
||||
result.word = operand - value - carry;
|
||||
const register16_t result = operand - value - carry;
|
||||
|
||||
adjustAuxiliaryCarrySub(F(), operand, value, result.word);
|
||||
|
||||
|
@ -29,9 +29,9 @@ public:
|
||||
}
|
||||
|
||||
EightBit::register16_t getStartAddress() const {
|
||||
EightBit::register16_t returned;
|
||||
returned.word = 0x100;
|
||||
return returned;
|
||||
//EightBit::register16_t returned;
|
||||
//returned.word = 0x100;
|
||||
return 0x100;
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -172,7 +172,7 @@ namespace EightBit {
|
||||
int m_timerCounter = 0;
|
||||
int m_timerRate = 0;
|
||||
|
||||
register16_t m_dmaAddress = { 0, 0 };
|
||||
register16_t m_dmaAddress;
|
||||
bool m_dmaTransferActive = false;
|
||||
|
||||
bool m_scanP15 = false;
|
||||
|
@ -36,10 +36,9 @@ namespace EightBit {
|
||||
}
|
||||
|
||||
register16_t AF() const final {
|
||||
register16_t returned;
|
||||
returned.low = higherNibble(af.low);
|
||||
returned.high = af.high;
|
||||
return returned;
|
||||
const auto low = higherNibble(af.low);
|
||||
const auto high = af.high;
|
||||
return register16_t(low, high);
|
||||
}
|
||||
|
||||
virtual register16_t BC() const final { return bc; }
|
||||
@ -59,10 +58,10 @@ namespace EightBit {
|
||||
private:
|
||||
Bus& m_bus;
|
||||
|
||||
register16_t af = { { 0xff, 0xff } };
|
||||
register16_t bc = { { 0xff, 0xff } };
|
||||
register16_t de = { { 0xff, 0xff } };
|
||||
register16_t hl = { { 0xff, 0xff } };
|
||||
register16_t af = 0xffff;
|
||||
register16_t bc = 0xffff;
|
||||
register16_t de = 0xffff;
|
||||
register16_t hl = 0xffff;
|
||||
|
||||
bool m_ime = 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) {
|
||||
|
||||
register16_t result;
|
||||
result.word = operand + value + carry;
|
||||
const register16_t result = operand + value + carry;
|
||||
|
||||
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) {
|
||||
|
||||
register16_t result;
|
||||
result.word = operand - value - carry;
|
||||
const register16_t result = operand - value - carry;
|
||||
|
||||
adjustHalfCarrySub(f, operand, value, result.low);
|
||||
|
||||
|
@ -336,6 +336,6 @@ namespace EightBit {
|
||||
|
||||
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 returned;
|
||||
returned.low = getBytePaged(page, offset);
|
||||
const auto low = getBytePaged(page, offset);
|
||||
++BUS().ADDRESS().low;
|
||||
returned.high = BUS().read();
|
||||
return returned;
|
||||
const auto high = BUS().read();
|
||||
return register16_t(low, high);
|
||||
}
|
||||
|
||||
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) {
|
||||
register16_t result;
|
||||
result.word = first - second;
|
||||
const register16_t result = first - second;
|
||||
adjustNZ(result.low);
|
||||
clearFlag(P(), CF, result.high);
|
||||
}
|
||||
|
@ -114,8 +114,8 @@ namespace EightBit {
|
||||
std::array<register16_t, 2> m_accumulatorFlags;
|
||||
int m_accumulatorFlagsSet = 0;
|
||||
|
||||
register16_t m_ix = { { 0xff, 0xff } };
|
||||
register16_t m_iy = { { 0xff, 0xff } };
|
||||
register16_t m_ix = 0xffff;
|
||||
register16_t m_iy = 0xffff;
|
||||
|
||||
refresh_t m_refresh = 0x7f;
|
||||
|
||||
@ -421,7 +421,7 @@ namespace EightBit {
|
||||
void ccf();
|
||||
void cpl();
|
||||
|
||||
void xhtl(register16_t& operand);
|
||||
void xhtl();
|
||||
|
||||
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) {
|
||||
|
||||
register16_t result;
|
||||
result.word = A() + value + carry;
|
||||
const register16_t result = A() + value + carry;
|
||||
|
||||
adjustHalfCarryAdd(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) {
|
||||
|
||||
register16_t result;
|
||||
result.word = operand - value - carry;
|
||||
const register16_t result = operand - value - carry;
|
||||
|
||||
adjustHalfCarrySub(F(), operand, value, result.low);
|
||||
adjustOverflowSub(F(), operand, value, result.low);
|
||||
@ -463,14 +461,14 @@ void EightBit::Z80::ccf() {
|
||||
adjustXY<Z80>(F(), A());
|
||||
}
|
||||
|
||||
void EightBit::Z80::xhtl(register16_t& operand) {
|
||||
void EightBit::Z80::xhtl() {
|
||||
MEMPTR().low = BUS().read(SP());
|
||||
BUS().write(operand.low);
|
||||
operand.low = MEMPTR().low;
|
||||
BUS().write(HL2().low);
|
||||
HL2().low = MEMPTR().low;
|
||||
++BUS().ADDRESS().word;
|
||||
MEMPTR().high = BUS().read();
|
||||
BUS().write(operand.high);
|
||||
operand.high = MEMPTR().high;
|
||||
BUS().write(HL2().high);
|
||||
HL2().high = MEMPTR().high;
|
||||
}
|
||||
|
||||
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);
|
||||
break;
|
||||
case 4: // EX (SP),HL
|
||||
xhtl(HL2());
|
||||
xhtl();
|
||||
addCycles(19);
|
||||
break;
|
||||
case 5: // EX DE,HL
|
||||
|
@ -29,9 +29,9 @@ public:
|
||||
}
|
||||
|
||||
EightBit::register16_t getStartAddress() const {
|
||||
EightBit::register16_t returned;
|
||||
returned.word = 0x100;
|
||||
return returned;
|
||||
//EightBit::register16_t returned;
|
||||
//returned.word = 0x100;
|
||||
return 0x100;
|
||||
}
|
||||
|
||||
private:
|
||||
|
14
inc/Bus.h
14
inc/Bus.h
@ -30,13 +30,17 @@ namespace EightBit {
|
||||
uint16_t peekWord(uint16_t address) const;
|
||||
|
||||
uint8_t read();
|
||||
uint8_t read(uint16_t offset);
|
||||
uint8_t read(register16_t address);
|
||||
template<class T> uint8_t read(const T address) {
|
||||
ADDRESS() = address;
|
||||
return read();
|
||||
}
|
||||
|
||||
void write();
|
||||
void write(uint8_t value);
|
||||
void write(uint16_t offset, uint8_t value);
|
||||
void write(register16_t address, uint8_t value);
|
||||
template<class T> void write(const T offset, const uint8_t value) {
|
||||
ADDRESS() = offset;
|
||||
write(value);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual uint8_t& reference(uint16_t address) = 0;
|
||||
@ -47,6 +51,6 @@ namespace EightBit {
|
||||
|
||||
private:
|
||||
uint8_t m_data = 0xff;
|
||||
register16_t m_address{ { 0xff, 0xff } };
|
||||
register16_t m_address = 0xffff;
|
||||
};
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ namespace EightBit {
|
||||
|
||||
private:
|
||||
std::array<opcode_decoded_t, 0x100> m_decodedOpcodes;
|
||||
register16_t m_sp = { { 0xff, 0xff } };
|
||||
register16_t m_memptr = { { 0, 0 } };
|
||||
register16_t m_sp = 0xffff;
|
||||
register16_t m_memptr;
|
||||
};
|
||||
}
|
||||
|
@ -124,10 +124,9 @@ namespace EightBit {
|
||||
}
|
||||
|
||||
register16_t fetchWord() {
|
||||
register16_t returned;
|
||||
returned.low = fetchByte();
|
||||
returned.high = fetchByte();
|
||||
return returned;
|
||||
const auto low = fetchByte();
|
||||
const auto high = fetchByte();
|
||||
return register16_t(low, high);
|
||||
}
|
||||
|
||||
virtual void push(uint8_t value) = 0;
|
||||
@ -139,10 +138,9 @@ namespace EightBit {
|
||||
}
|
||||
|
||||
register16_t popWord() {
|
||||
register16_t returned;
|
||||
returned.low = pop();
|
||||
returned.high = pop();
|
||||
return returned;
|
||||
const auto low = pop();
|
||||
const auto high = pop();
|
||||
return register16_t(low, high);
|
||||
}
|
||||
|
||||
void jump(const register16_t destination) {
|
||||
@ -166,7 +164,7 @@ namespace EightBit {
|
||||
private:
|
||||
Bus& m_bus;
|
||||
int m_cycles = 0;
|
||||
register16_t m_pc = { { 0, 0 } };
|
||||
register16_t m_pc;
|
||||
|
||||
PinLevel m_intLine = Low;
|
||||
PinLevel m_nmiLine = Low;
|
||||
|
@ -18,7 +18,7 @@
|
||||
#endif
|
||||
|
||||
namespace EightBit {
|
||||
typedef union {
|
||||
union register16_t {
|
||||
struct {
|
||||
#ifdef HOST_LITTLE_ENDIAN
|
||||
uint8_t low;
|
||||
@ -30,5 +30,8 @@ namespace EightBit {
|
||||
#endif
|
||||
};
|
||||
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 {
|
||||
register16_t returned;
|
||||
returned.low = peek(address);
|
||||
returned.high = peek(address + 1);
|
||||
return returned.word;
|
||||
const auto low = peek(address);
|
||||
const auto high = peek(address + 1);
|
||||
return register16_t(low, high).word;
|
||||
}
|
||||
|
||||
uint8_t EightBit::Bus::read() {
|
||||
@ -31,16 +30,6 @@ uint8_t EightBit::Bus::read() {
|
||||
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() {
|
||||
WritingByte.fire(EventArgs::empty());
|
||||
reference() = DATA();
|
||||
@ -52,16 +41,6 @@ void EightBit::Bus::write(const uint8_t value) {
|
||||
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 {
|
||||
return reference(ADDRESS().word);
|
||||
}
|
||||
|
@ -21,10 +21,11 @@ uint8_t EightBit::IntelProcessor::pop() {
|
||||
}
|
||||
|
||||
EightBit::register16_t EightBit::IntelProcessor::getWord() {
|
||||
register16_t returned;
|
||||
returned.low = BUS().read(MEMPTR().word++);
|
||||
returned.high = BUS().read(++BUS().ADDRESS().word);
|
||||
return returned;
|
||||
BUS().ADDRESS().word = MEMPTR().word++;
|
||||
const auto low = BUS().read();
|
||||
++BUS().ADDRESS().word;
|
||||
const auto high = BUS().read();
|
||||
return register16_t(low, high);
|
||||
}
|
||||
|
||||
void EightBit::IntelProcessor::setWord(const register16_t value) {
|
||||
|
Loading…
Reference in New Issue
Block a user