mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-12-21 18:29:57 +00:00
More memptr adjustments
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
parent
1abe3ae456
commit
ed76038bfa
@ -236,8 +236,7 @@ void EightBit::Intel8080::xhtl() {
|
||||
}
|
||||
|
||||
void EightBit::Intel8080::writePort(uint8_t port) {
|
||||
BUS().ADDRESS().low = port;
|
||||
BUS().ADDRESS().high = A();
|
||||
BUS().ADDRESS() = register16_t(port, A());
|
||||
BUS().DATA() = A();
|
||||
writePort();
|
||||
}
|
||||
@ -247,8 +246,7 @@ void EightBit::Intel8080::writePort() {
|
||||
}
|
||||
|
||||
uint8_t EightBit::Intel8080::readPort(uint8_t port) {
|
||||
BUS().ADDRESS().low = port;
|
||||
BUS().ADDRESS().high = A();
|
||||
BUS().ADDRESS() = register16_t(port, A());
|
||||
return readPort();
|
||||
}
|
||||
|
||||
@ -330,7 +328,7 @@ void EightBit::Intel8080::execute(int x, int y, int z, int p, int q) {
|
||||
addCycles(7);
|
||||
break;
|
||||
case 2: // LD (nn),HL
|
||||
MEMPTR() = fetchWord();
|
||||
BUS().ADDRESS() = fetchWord();
|
||||
setWord(HL());
|
||||
addCycles(16);
|
||||
break;
|
||||
@ -354,7 +352,7 @@ void EightBit::Intel8080::execute(int x, int y, int z, int p, int q) {
|
||||
addCycles(7);
|
||||
break;
|
||||
case 2: // LD HL,(nn)
|
||||
MEMPTR() = fetchWord();
|
||||
BUS().ADDRESS() = fetchWord();
|
||||
HL() = getWord();
|
||||
addCycles(16);
|
||||
break;
|
||||
|
@ -21,10 +21,10 @@ namespace EightBit {
|
||||
|
||||
uint8_t priority() const { return flags() & Processor::Bit7; }
|
||||
|
||||
bool highPriority() const { return priority() != 0; }
|
||||
bool lowPriority() const { return priority() == 0; }
|
||||
bool flipY() const { return (flags() & Processor::Bit6) != 0; }
|
||||
bool flipX() const { return (flags() & Processor::Bit5) != 0; }
|
||||
bool highPriority() const { return !!priority(); }
|
||||
bool lowPriority() const { return !priority(); }
|
||||
bool flipY() const { return !!(flags() & Processor::Bit6); }
|
||||
bool flipX() const { return !!(flags() & Processor::Bit5); }
|
||||
int palette() const { return (flags() & Processor::Bit4) >> 3; }
|
||||
|
||||
private:
|
||||
|
@ -90,7 +90,7 @@ void EightBit::GameBoy::Display::renderBackground() {
|
||||
|
||||
const auto palette = createPalette(IoRegisters::BGP);
|
||||
|
||||
const auto window = (m_control & IoRegisters::WindowEnable) != 0;
|
||||
const auto window = !!(m_control & IoRegisters::WindowEnable);
|
||||
const auto bgArea = (m_control & IoRegisters::BackgroundCodeAreaSelection) ? 0x1c00 : 0x1800;
|
||||
const auto bgCharacters = (m_control & IoRegisters::BackgroundCharacterDataSelection) ? 0 : 0x800;
|
||||
|
||||
|
@ -130,8 +130,7 @@ void EightBit::GameBoy::IoRegisters::Bus_WrittenByte(EightBit::EventArgs) {
|
||||
case SCX:
|
||||
break;
|
||||
case DMA:
|
||||
m_dmaAddress.high = value;
|
||||
m_dmaAddress.low = 0;
|
||||
m_dmaAddress = register16_t(0, value);
|
||||
m_dmaTransferActive = true;
|
||||
break;
|
||||
case LY: // R/O
|
||||
@ -145,7 +144,7 @@ void EightBit::GameBoy::IoRegisters::Bus_WrittenByte(EightBit::EventArgs) {
|
||||
break;
|
||||
|
||||
case BOOT_DISABLE:
|
||||
m_disableBootRom = value != 0;
|
||||
m_disableBootRom = !!value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -418,7 +418,7 @@ void EightBit::GameBoy::LR35902::executeOther(int x, int y, int z, int p, int q)
|
||||
addCycle();
|
||||
break;
|
||||
case 1: // GB: LD (nn),SP
|
||||
MEMPTR() = fetchWord();
|
||||
BUS().ADDRESS() = fetchWord();
|
||||
setWord(SP());
|
||||
addCycles(5);
|
||||
break;
|
||||
@ -731,8 +731,7 @@ void EightBit::GameBoy::LR35902::executeOther(int x, int y, int z, int p, int q)
|
||||
case 3: // Assorted operations
|
||||
switch (y) {
|
||||
case 0: // JP nn
|
||||
MEMPTR() = fetchWord();
|
||||
jump(MEMPTR());
|
||||
jump(MEMPTR() = fetchWord());
|
||||
addCycles(4);
|
||||
break;
|
||||
case 1: // CB prefix
|
||||
@ -763,8 +762,7 @@ void EightBit::GameBoy::LR35902::executeOther(int x, int y, int z, int p, int q)
|
||||
case 1:
|
||||
switch (p) {
|
||||
case 0: // CALL nn
|
||||
MEMPTR() = fetchWord();
|
||||
call(MEMPTR());
|
||||
call(MEMPTR() = fetchWord());
|
||||
addCycles(6);
|
||||
break;
|
||||
}
|
||||
|
@ -58,15 +58,11 @@ EightBit::register16_t EightBit::MOS6502::getWordPaged(uint8_t page, uint8_t off
|
||||
}
|
||||
|
||||
uint8_t EightBit::MOS6502::getBytePaged(uint8_t page, uint8_t offset) {
|
||||
BUS().ADDRESS().low = offset;
|
||||
BUS().ADDRESS().high = page;
|
||||
return BUS().read();
|
||||
return BUS().read(register16_t(offset, page));
|
||||
}
|
||||
|
||||
void EightBit::MOS6502::setBytePaged(uint8_t page, uint8_t offset, uint8_t value) {
|
||||
BUS().ADDRESS().low = offset;
|
||||
BUS().ADDRESS().high = page;
|
||||
BUS().write(value);
|
||||
BUS().write(register16_t(offset, page), value);
|
||||
}
|
||||
|
||||
void EightBit::MOS6502::interrupt(uint8_t vector) {
|
||||
|
@ -102,7 +102,7 @@ void Board::Cpu_ExecutingInstruction_Debug(EightBit::MOS6502& cpu) {
|
||||
|
||||
void Board::Memory_ReadingByte_Input(EightBit::EventArgs) {
|
||||
if (ADDRESS().word == m_configuration.getInputAddress()) {
|
||||
if (DATA() != 0)
|
||||
if (!!DATA())
|
||||
write(0);
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ namespace EightBit {
|
||||
uint8_t variable : 7;
|
||||
|
||||
refresh_t(const uint8_t value)
|
||||
: high((value & Bit7) != 0),
|
||||
: high(!!(value & Bit7)),
|
||||
variable(value & Mask7)
|
||||
{ }
|
||||
|
||||
|
@ -117,7 +117,6 @@ bool EightBit::Z80::jumpConditionalFlag(const int flag) {
|
||||
|
||||
void EightBit::Z80::retn() {
|
||||
ret();
|
||||
MEMPTR() = PC();
|
||||
IFF1() = IFF2();
|
||||
}
|
||||
|
||||
@ -589,9 +588,7 @@ void EightBit::Z80::rld() {
|
||||
}
|
||||
|
||||
void EightBit::Z80::writePort(const uint8_t port) {
|
||||
BUS().ADDRESS().low = port;
|
||||
BUS().ADDRESS().high = A();
|
||||
MEMPTR() = BUS().ADDRESS();
|
||||
MEMPTR() = BUS().ADDRESS() = register16_t(port, A());
|
||||
BUS().DATA() = A();
|
||||
writePort();
|
||||
++MEMPTR().low;
|
||||
@ -602,9 +599,7 @@ void EightBit::Z80::writePort() {
|
||||
}
|
||||
|
||||
uint8_t EightBit::Z80::readPort(const uint8_t port) {
|
||||
BUS().ADDRESS().low = port;
|
||||
BUS().ADDRESS().high = A();
|
||||
MEMPTR() = BUS().ADDRESS();
|
||||
MEMPTR() = BUS().ADDRESS() = register16_t(port, A());
|
||||
++MEMPTR().low;
|
||||
return readPort();
|
||||
}
|
||||
@ -640,9 +635,7 @@ int EightBit::Z80::step() {
|
||||
addCycles(13);
|
||||
return cycles();
|
||||
case 2:
|
||||
MEMPTR().low = BUS().DATA();
|
||||
MEMPTR().high = IV();
|
||||
call(MEMPTR());
|
||||
call(MEMPTR() = register16_t(BUS().DATA(), IV()));
|
||||
addCycles(19);
|
||||
return cycles();
|
||||
default:
|
||||
@ -843,7 +836,7 @@ void EightBit::Z80::executeED(const int x, const int y, const int z, const int p
|
||||
addCycles(15);
|
||||
break;
|
||||
case 3: // Retrieve/store register pair from/to immediate address
|
||||
MEMPTR() = fetchWord();
|
||||
BUS().ADDRESS() = fetchWord();
|
||||
switch (q) {
|
||||
case 0: // LD (nn), rp[p]
|
||||
setWord(RP(p));
|
||||
@ -955,7 +948,7 @@ void EightBit::Z80::executeED(const int x, const int y, const int z, const int p
|
||||
break;
|
||||
case 7: // LDDR
|
||||
if (LIKELY(lddr())) {
|
||||
MEMPTR()= --PC();
|
||||
MEMPTR() = --PC();
|
||||
--PC();
|
||||
addCycles(5);
|
||||
}
|
||||
@ -972,14 +965,14 @@ void EightBit::Z80::executeED(const int x, const int y, const int z, const int p
|
||||
break;
|
||||
case 6: // CPIR
|
||||
if (LIKELY(cpir())) {
|
||||
MEMPTR()= --PC();
|
||||
MEMPTR() = --PC();
|
||||
--PC();
|
||||
addCycles(5);
|
||||
}
|
||||
break;
|
||||
case 7: // CPDR
|
||||
if (LIKELY(cpdr())) {
|
||||
MEMPTR()= --PC();
|
||||
MEMPTR() = --PC();
|
||||
--PC();
|
||||
addCycles(5);
|
||||
} else {
|
||||
@ -1115,7 +1108,7 @@ void EightBit::Z80::executeOther(const int x, const int y, const int z, const in
|
||||
addCycles(7);
|
||||
break;
|
||||
case 2: // LD (nn),HL
|
||||
MEMPTR() = fetchWord();
|
||||
BUS().ADDRESS() = fetchWord();
|
||||
setWord(HL2());
|
||||
addCycles(16);
|
||||
break;
|
||||
@ -1145,7 +1138,7 @@ void EightBit::Z80::executeOther(const int x, const int y, const int z, const in
|
||||
addCycles(7);
|
||||
break;
|
||||
case 2: // LD HL,(nn)
|
||||
MEMPTR() = fetchWord();
|
||||
BUS().ADDRESS() = fetchWord();
|
||||
HL2() = getWord();
|
||||
addCycles(16);
|
||||
break;
|
||||
@ -1334,7 +1327,6 @@ void EightBit::Z80::executeOther(const int x, const int y, const int z, const in
|
||||
switch (p) {
|
||||
case 0: // RET
|
||||
ret();
|
||||
MEMPTR() = PC();
|
||||
addCycles(10);
|
||||
break;
|
||||
case 1: // EXX
|
||||
|
@ -128,43 +128,43 @@ namespace EightBit {
|
||||
//
|
||||
|
||||
void restart(const uint8_t address) {
|
||||
MEMPTR().low = address;
|
||||
MEMPTR().high = 0;
|
||||
call(MEMPTR());
|
||||
call(MEMPTR() = register16_t(address, 0));
|
||||
}
|
||||
|
||||
bool callConditional(const int condition) {
|
||||
MEMPTR() = fetchWord();
|
||||
if (condition)
|
||||
call(MEMPTR());
|
||||
return condition != 0;
|
||||
return !!condition;
|
||||
}
|
||||
|
||||
bool jumpConditional(const int conditional) {
|
||||
bool jumpConditional(const int condition) {
|
||||
MEMPTR() = fetchWord();
|
||||
if (conditional)
|
||||
if (condition)
|
||||
jump(MEMPTR());
|
||||
return conditional != 0;
|
||||
return !!condition;
|
||||
}
|
||||
|
||||
bool returnConditional(const int condition) {
|
||||
if (condition) {
|
||||
if (condition)
|
||||
ret();
|
||||
MEMPTR() = PC();
|
||||
}
|
||||
return condition != 0;
|
||||
return !!condition;
|
||||
}
|
||||
|
||||
void jr(const int8_t offset) {
|
||||
MEMPTR() = PC() + offset;
|
||||
jump(MEMPTR());
|
||||
jump(MEMPTR() = PC() + offset);
|
||||
}
|
||||
|
||||
bool jrConditional(const int conditional) {
|
||||
bool jrConditional(const int condition) {
|
||||
const auto offset = fetchByte();
|
||||
if (conditional)
|
||||
if (condition)
|
||||
jr(offset);
|
||||
return conditional != 0;
|
||||
return !!condition;
|
||||
}
|
||||
|
||||
virtual void ret() final {
|
||||
Processor::ret();
|
||||
MEMPTR() = PC();
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -91,12 +91,12 @@ namespace EightBit {
|
||||
static void clearFlag(uint8_t& f, const int flag) { f &= ~flag; }
|
||||
static void setFlag(uint8_t& f, const int flag) { f |= flag; }
|
||||
|
||||
static void setFlag(uint8_t& f, const int flag, const int condition) { setFlag(f, flag, condition != 0); }
|
||||
static void setFlag(uint8_t& f, const int flag, const uint32_t condition) { setFlag(f, flag, condition != 0); }
|
||||
static void setFlag(uint8_t& f, const int flag, const int condition) { setFlag(f, flag, !!condition); }
|
||||
static void setFlag(uint8_t& f, const int flag, const uint32_t condition) { setFlag(f, flag, !!condition); }
|
||||
static void setFlag(uint8_t& f, const int flag, const bool condition) { condition ? setFlag(f, flag) : clearFlag(f, flag); }
|
||||
|
||||
static void clearFlag(uint8_t& f, const int flag, const int condition) { clearFlag(f, flag, condition != 0); }
|
||||
static void clearFlag(uint8_t& f, const int flag, const uint32_t condition) { clearFlag(f, flag, condition != 0); }
|
||||
static void clearFlag(uint8_t& f, const int flag, const int condition) { clearFlag(f, flag, !!condition); }
|
||||
static void clearFlag(uint8_t& f, const int flag, const uint32_t condition) { clearFlag(f, flag, !!condition); }
|
||||
static void clearFlag(uint8_t& f, const int flag, const bool condition) { condition ? clearFlag(f, flag) : setFlag(f, flag); }
|
||||
|
||||
Processor(Bus& memory);
|
||||
@ -141,7 +141,7 @@ namespace EightBit {
|
||||
jump(destination);
|
||||
}
|
||||
|
||||
void ret() {
|
||||
virtual void ret() {
|
||||
jump(popWord());
|
||||
}
|
||||
|
||||
|
@ -21,14 +21,14 @@ uint8_t EightBit::IntelProcessor::pop() {
|
||||
}
|
||||
|
||||
EightBit::register16_t EightBit::IntelProcessor::getWord() {
|
||||
BUS().ADDRESS() = MEMPTR()++;
|
||||
const auto low = BUS().read();
|
||||
++BUS().ADDRESS();
|
||||
MEMPTR() = ++BUS().ADDRESS();
|
||||
const auto high = BUS().read();
|
||||
return register16_t(low, high);
|
||||
}
|
||||
|
||||
void EightBit::IntelProcessor::setWord(const register16_t value) {
|
||||
BUS().write(MEMPTR()++, value.low);
|
||||
BUS().write(++BUS().ADDRESS(), value.high);
|
||||
BUS().write(value.low);
|
||||
MEMPTR() = ++BUS().ADDRESS();
|
||||
BUS().write(value.high);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user