mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2026-04-21 01:16:50 +00:00
Tidy up register and static method access.
Signed-off-by: Adrian.Conlon <adrian.conlon@arup.com>
This commit is contained in:
@@ -39,8 +39,8 @@ void Fuse::TestRunner::initialiseRegisters() {
|
||||
m_cpu.IX() = inputRegisters[Fuse::RegisterState::IX];
|
||||
m_cpu.IY() = inputRegisters[Fuse::RegisterState::IY];
|
||||
|
||||
m_cpu.setStackPointer(inputRegisters[Fuse::RegisterState::SP]);
|
||||
m_cpu.setProgramCounter(inputRegisters[Fuse::RegisterState::PC]);
|
||||
m_cpu.SP() = inputRegisters[Fuse::RegisterState::SP];
|
||||
m_cpu.PC() = inputRegisters[Fuse::RegisterState::PC];
|
||||
|
||||
m_cpu.MEMPTR() = inputRegisters[Fuse::RegisterState::MEMPTR];
|
||||
|
||||
@@ -115,8 +115,8 @@ void Fuse::TestRunner::checkregisters() {
|
||||
auto ix = m_cpu.IX().word == expectedRegisters[Fuse::RegisterState::IX].word;
|
||||
auto iy = m_cpu.IY().word == expectedRegisters[Fuse::RegisterState::IY].word;
|
||||
|
||||
auto sp = m_cpu.getStackPointer().word == expectedRegisters[Fuse::RegisterState::SP].word;
|
||||
auto pc = m_cpu.getProgramCounter().word == expectedRegisters[Fuse::RegisterState::PC].word;
|
||||
auto sp = m_cpu.SP().word == expectedRegisters[Fuse::RegisterState::SP].word;
|
||||
auto pc = m_cpu.PC().word == expectedRegisters[Fuse::RegisterState::PC].word;
|
||||
|
||||
auto memptr = m_cpu.MEMPTR().word == expectedRegisters[Fuse::RegisterState::MEMPTR].word;
|
||||
|
||||
@@ -194,13 +194,13 @@ void Fuse::TestRunner::checkregisters() {
|
||||
|
||||
if (!sp) {
|
||||
auto expectedWord = expectedRegisters[Fuse::RegisterState::SP];
|
||||
auto actualWord = m_cpu.getStackPointer();
|
||||
auto actualWord = m_cpu.SP();
|
||||
dumpDifference("SPH", "SPL", actualWord, expectedWord);
|
||||
}
|
||||
|
||||
if (!pc) {
|
||||
auto expectedWord = expectedRegisters[Fuse::RegisterState::PC];
|
||||
auto actualWord = m_cpu.getProgramCounter();
|
||||
auto actualWord = m_cpu.PC();
|
||||
dumpDifference("PCH", "PCL", actualWord, expectedWord);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace EightBit {
|
||||
Disassembler();
|
||||
|
||||
static std::string state(Z80& cpu);
|
||||
std::string disassemble(const Z80& cpu);
|
||||
std::string disassemble(Z80& cpu);
|
||||
|
||||
static std::string flag(uint8_t value, int flag, const std::string& represents);
|
||||
static std::string flags(uint8_t value);
|
||||
|
||||
+10
-12
@@ -37,8 +37,6 @@ namespace EightBit {
|
||||
int execute(uint8_t opcode);
|
||||
int step();
|
||||
|
||||
bool getM1() const { return m1; }
|
||||
|
||||
// Mutable access to processor!!
|
||||
|
||||
virtual register16_t& AF() override {
|
||||
@@ -181,7 +179,7 @@ namespace EightBit {
|
||||
register16_t& RP(int rp) {
|
||||
switch (rp) {
|
||||
case 3:
|
||||
return sp;
|
||||
return SP();
|
||||
case HL_IDX:
|
||||
return HL2();
|
||||
default:
|
||||
@@ -225,28 +223,28 @@ namespace EightBit {
|
||||
adc(hl, operand);
|
||||
}
|
||||
|
||||
void adjustHalfCarryAdd(uint8_t& f, uint8_t before, uint8_t value, int calculation) {
|
||||
static void adjustHalfCarryAdd(uint8_t& f, uint8_t before, uint8_t value, int calculation) {
|
||||
setFlag(f, HC, calculateHalfCarryAdd(before, value, calculation));
|
||||
}
|
||||
|
||||
void adjustHalfCarrySub(uint8_t& f, uint8_t before, uint8_t value, int calculation) {
|
||||
static void adjustHalfCarrySub(uint8_t& f, uint8_t before, uint8_t value, int calculation) {
|
||||
setFlag(f, HC, calculateHalfCarrySub(before, value, calculation));
|
||||
}
|
||||
|
||||
void adjustOverflowAdd(uint8_t& f, uint8_t before, uint8_t value, uint8_t calculation) {
|
||||
static void adjustOverflowAdd(uint8_t& f, uint8_t before, uint8_t value, uint8_t calculation) {
|
||||
adjustOverflowAdd(f, before & SF, value & SF, calculation & SF);
|
||||
}
|
||||
|
||||
void adjustOverflowAdd(uint8_t& f, int beforeNegative, int valueNegative, int afterNegative) {
|
||||
static void adjustOverflowAdd(uint8_t& f, int beforeNegative, int valueNegative, int afterNegative) {
|
||||
auto overflow = (beforeNegative == valueNegative) && (beforeNegative != afterNegative);
|
||||
setFlag(f, VF, overflow);
|
||||
}
|
||||
|
||||
void adjustOverflowSub(uint8_t& f, uint8_t before, uint8_t value, uint8_t calculation) {
|
||||
static void adjustOverflowSub(uint8_t& f, uint8_t before, uint8_t value, uint8_t calculation) {
|
||||
adjustOverflowSub(f, before & SF, value & SF, calculation & SF);
|
||||
}
|
||||
|
||||
void adjustOverflowSub(uint8_t& f, int beforeNegative, int valueNegative, int afterNegative) {
|
||||
static void adjustOverflowSub(uint8_t& f, int beforeNegative, int valueNegative, int afterNegative) {
|
||||
auto overflow = (beforeNegative != valueNegative) && (beforeNegative != afterNegative);
|
||||
setFlag(f, VF, overflow);
|
||||
}
|
||||
@@ -298,9 +296,9 @@ namespace EightBit {
|
||||
uint8_t& sll(uint8_t& operand);
|
||||
uint8_t& srl(uint8_t& operand);
|
||||
|
||||
void bit(int n, uint8_t& operand);
|
||||
void res(int n, uint8_t& operand);
|
||||
void set(int nit, uint8_t& operand);
|
||||
uint8_t& bit(int n, uint8_t& operand);
|
||||
uint8_t& res(int n, uint8_t& operand);
|
||||
uint8_t& set(int nit, uint8_t& operand);
|
||||
|
||||
void daa();
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ EightBit::Disassembler::Disassembler() {
|
||||
|
||||
std::string EightBit::Disassembler::state(Z80& cpu) {
|
||||
|
||||
auto pc = cpu.getProgramCounter();
|
||||
auto sp = cpu.getStackPointer();
|
||||
auto pc = cpu.PC();
|
||||
auto sp = cpu.SP();
|
||||
|
||||
auto a = cpu.A();
|
||||
auto f = cpu.F();
|
||||
@@ -169,10 +169,10 @@ std::string EightBit::Disassembler::alu(int which) {
|
||||
throw std::logic_error("Unhandled alu operation");
|
||||
}
|
||||
|
||||
std::string EightBit::Disassembler::disassemble(const Z80& cpu) {
|
||||
std::string EightBit::Disassembler::disassemble(Z80& cpu) {
|
||||
m_prefixCB = m_prefixDD = m_prefixED = m_prefixFD = false;
|
||||
std::ostringstream output;
|
||||
disassemble(output, cpu, cpu.getProgramCounter().word);
|
||||
disassemble(output, cpu, cpu.PC().word);
|
||||
return output.str();
|
||||
}
|
||||
|
||||
|
||||
+50
-44
@@ -86,9 +86,9 @@ int EightBit::Z80::interrupt(bool maskable, uint8_t value) {
|
||||
cycles += 13;
|
||||
break;
|
||||
case 2:
|
||||
pushWord(pc);
|
||||
pc.low = value;
|
||||
pc.high = IV();
|
||||
pushWord(PC());
|
||||
PC().low = value;
|
||||
PC().high = IV();
|
||||
cycles += 19;
|
||||
break;
|
||||
}
|
||||
@@ -502,23 +502,26 @@ uint8_t& EightBit::Z80::srl(uint8_t& operand) {
|
||||
|
||||
#pragma region BIT/SET/RES
|
||||
|
||||
void EightBit::Z80::bit(int n, uint8_t& operand) {
|
||||
uint8_t& EightBit::Z80::bit(int n, uint8_t& operand) {
|
||||
auto& f = F();
|
||||
auto carry = f & CF;
|
||||
uint8_t discarded = operand;
|
||||
andr(discarded, 1 << n);
|
||||
clearFlag(f, PF, discarded);
|
||||
setFlag(f, CF, carry);
|
||||
return operand;
|
||||
}
|
||||
|
||||
void EightBit::Z80::res(int n, uint8_t& operand) {
|
||||
uint8_t& EightBit::Z80::res(int n, uint8_t& operand) {
|
||||
auto bit = 1 << n;
|
||||
operand &= ~bit;
|
||||
return operand;
|
||||
}
|
||||
|
||||
void EightBit::Z80::set(int n, uint8_t& operand) {
|
||||
uint8_t& EightBit::Z80::set(int n, uint8_t& operand) {
|
||||
auto bit = 1 << n;
|
||||
operand |= bit;
|
||||
return operand;
|
||||
}
|
||||
|
||||
#pragma endregion BIT/SET/RES
|
||||
@@ -526,22 +529,24 @@ void EightBit::Z80::set(int n, uint8_t& operand) {
|
||||
#pragma region Miscellaneous instructions
|
||||
|
||||
void EightBit::Z80::neg() {
|
||||
auto& a = A();
|
||||
auto& f = F();
|
||||
auto original = A();
|
||||
A() = 0;
|
||||
sub(A(), original);
|
||||
auto original = a;
|
||||
a = 0;
|
||||
sub(a, original);
|
||||
setFlag(f, PF, original == Bit7);
|
||||
setFlag(f, CF, original);
|
||||
}
|
||||
|
||||
void EightBit::Z80::daa() {
|
||||
|
||||
auto& acc = A();
|
||||
auto& f = F();
|
||||
|
||||
uint8_t a = A();
|
||||
auto a = acc;
|
||||
|
||||
auto lowAdjust = (f & HC) | (lowNibble(A()) > 9);
|
||||
auto highAdjust = (f & CF) | (A() > 0x99);
|
||||
auto lowAdjust = (f & HC) | (lowNibble(acc) > 9);
|
||||
auto highAdjust = (f & CF) | (acc > 0x99);
|
||||
|
||||
if (f & NF) {
|
||||
if (lowAdjust)
|
||||
@@ -555,16 +560,17 @@ void EightBit::Z80::daa() {
|
||||
a += 0x60;
|
||||
}
|
||||
|
||||
f = (f & (CF | NF)) | (A() > 0x99) | ((A() ^ a) & HC);
|
||||
f = (f & (CF | NF)) | (acc > 0x99) | ((acc ^ a) & HC);
|
||||
|
||||
adjustSZPXY(f, a);
|
||||
|
||||
A() = a;
|
||||
acc = a;
|
||||
}
|
||||
|
||||
void EightBit::Z80::cpl() {
|
||||
auto& a = A();
|
||||
auto& f = F();
|
||||
A() = ~A();
|
||||
a = ~a;
|
||||
adjustXY(f, A());
|
||||
setFlag(f, HC | NF);
|
||||
}
|
||||
@@ -586,7 +592,7 @@ void EightBit::Z80::ccf() {
|
||||
}
|
||||
|
||||
void EightBit::Z80::xhtl(register16_t& operand) {
|
||||
m_memory.ADDRESS() = sp;
|
||||
m_memory.ADDRESS() = SP();
|
||||
MEMPTR().low = m_memory.reference();
|
||||
m_memory.reference() = operand.low;
|
||||
operand.low = MEMPTR().low;
|
||||
@@ -608,17 +614,18 @@ void EightBit::Z80::xhtl() {
|
||||
|
||||
void EightBit::Z80::blockCompare() {
|
||||
|
||||
const auto& a = A();
|
||||
auto& f = F();
|
||||
|
||||
m_memory.ADDRESS() = HL();
|
||||
|
||||
auto value = m_memory.reference();
|
||||
uint8_t result = A() - value;
|
||||
uint8_t result = a - value;
|
||||
|
||||
setFlag(f, PF, --BC().word);
|
||||
|
||||
adjustSZ(f, result);
|
||||
adjustHalfCarrySub(f, A(), value, result);
|
||||
adjustHalfCarrySub(f, a, value, result);
|
||||
setFlag(f, NF);
|
||||
|
||||
if (f & HC)
|
||||
@@ -642,7 +649,7 @@ void EightBit::Z80::cpd() {
|
||||
|
||||
bool EightBit::Z80::cpir() {
|
||||
cpi();
|
||||
MEMPTR().word = pc.word;
|
||||
MEMPTR() = PC();
|
||||
auto again = (F() & PF) && !(F() & ZF); // See CPI
|
||||
if (again)
|
||||
MEMPTR().word--;
|
||||
@@ -651,7 +658,7 @@ bool EightBit::Z80::cpir() {
|
||||
|
||||
bool EightBit::Z80::cpdr() {
|
||||
cpd();
|
||||
MEMPTR().word = pc.word - 1;
|
||||
MEMPTR().word = PC().word - 1;
|
||||
auto again = (F() & PF) && !(F() & ZF); // See CPD
|
||||
if (!again)
|
||||
MEMPTR().word--;
|
||||
@@ -691,7 +698,7 @@ bool EightBit::Z80::ldir() {
|
||||
ldi();
|
||||
auto again = (F() & PF) != 0;
|
||||
if (again) // See LDI
|
||||
MEMPTR().word = pc.word - 1;
|
||||
MEMPTR().word = PC().word - 1;
|
||||
return again;
|
||||
}
|
||||
|
||||
@@ -699,7 +706,7 @@ bool EightBit::Z80::lddr() {
|
||||
ldd();
|
||||
auto again = (F() & PF) != 0;
|
||||
if (again) // See LDR
|
||||
MEMPTR().word = pc.word - 1;
|
||||
MEMPTR().word = PC().word - 1;
|
||||
return again;
|
||||
}
|
||||
|
||||
@@ -785,22 +792,24 @@ bool EightBit::Z80::otdr() {
|
||||
#pragma region Nibble rotation
|
||||
|
||||
void EightBit::Z80::rrd() {
|
||||
auto& a = A();
|
||||
auto& f = F();
|
||||
MEMPTR() = HL();
|
||||
auto memory = memptrReference();
|
||||
m_memory.reference() = promoteNibble(A()) | highNibble(memory);
|
||||
A() = (A() & 0xf0) | lowNibble(memory);
|
||||
m_memory.reference() = promoteNibble(a) | highNibble(memory);
|
||||
a = (a & 0xf0) | lowNibble(memory);
|
||||
adjustSZPXY(f, A());
|
||||
clearFlag(f, NF | HC);
|
||||
}
|
||||
|
||||
void EightBit::Z80::rld() {
|
||||
auto& a = A();
|
||||
auto& f = F();
|
||||
MEMPTR() = HL();
|
||||
auto memory = memptrReference();
|
||||
m_memory.reference() = promoteNibble(memory) | lowNibble(A());
|
||||
A() = (A() & 0xf0) | highNibble(memory);
|
||||
adjustSZPXY(f, A());
|
||||
m_memory.reference() = promoteNibble(memory) | lowNibble(a);
|
||||
a = (a & 0xf0) | highNibble(memory);
|
||||
adjustSZPXY(f, a);
|
||||
clearFlag(f, NF | HC);
|
||||
}
|
||||
|
||||
@@ -815,7 +824,7 @@ int EightBit::Z80::step() {
|
||||
|
||||
int EightBit::Z80::execute(uint8_t opcode) {
|
||||
|
||||
if (!getM1())
|
||||
if (!M1())
|
||||
throw std::logic_error("M1 cannot be high");
|
||||
|
||||
auto x = (opcode & 0b11000000) >> 6;
|
||||
@@ -887,8 +896,7 @@ void EightBit::Z80::executeCB(int x, int y, int z, int p, int q) {
|
||||
adjustXY(f, MEMPTR().high);
|
||||
cycles += 20;
|
||||
} else {
|
||||
auto operand = R(z);
|
||||
bit(y, operand);
|
||||
auto operand = bit(y, R(z));
|
||||
cycles += 8;
|
||||
if (z == 6) {
|
||||
adjustXY(f, MEMPTR().high);
|
||||
@@ -900,8 +908,7 @@ void EightBit::Z80::executeCB(int x, int y, int z, int p, int q) {
|
||||
break;
|
||||
case 2: // RES y, r[z]
|
||||
if (m_displaced) {
|
||||
res(y, DISPLACED());
|
||||
R2(z) = DISPLACED();
|
||||
R2(z) = res(y, DISPLACED());
|
||||
cycles += 23;
|
||||
} else {
|
||||
res(y, R(z));
|
||||
@@ -912,8 +919,7 @@ void EightBit::Z80::executeCB(int x, int y, int z, int p, int q) {
|
||||
break;
|
||||
case 3: // SET y, r[z]
|
||||
if (m_displaced) {
|
||||
set(y, DISPLACED());
|
||||
R2(z) = DISPLACED();
|
||||
R2(z) = set(y, DISPLACED());
|
||||
cycles += 23;
|
||||
} else {
|
||||
set(y, R(z));
|
||||
@@ -1065,13 +1071,13 @@ void EightBit::Z80::executeED(int x, int y, int z, int p, int q) {
|
||||
break;
|
||||
case 6: // LDIR
|
||||
if (ldir()) {
|
||||
pc.word -= 2;
|
||||
PC().word -= 2;
|
||||
cycles += 5;
|
||||
}
|
||||
break;
|
||||
case 7: // LDDR
|
||||
if (lddr()) {
|
||||
pc.word -= 2;
|
||||
PC().word -= 2;
|
||||
cycles += 5;
|
||||
}
|
||||
break;
|
||||
@@ -1087,13 +1093,13 @@ void EightBit::Z80::executeED(int x, int y, int z, int p, int q) {
|
||||
break;
|
||||
case 6: // CPIR
|
||||
if (cpir()) {
|
||||
pc.word -= 2;
|
||||
PC().word -= 2;
|
||||
cycles += 5;
|
||||
}
|
||||
break;
|
||||
case 7: // CPDR
|
||||
if (cpdr()) {
|
||||
pc.word -= 2;
|
||||
PC().word -= 2;
|
||||
cycles += 5;
|
||||
}
|
||||
break;
|
||||
@@ -1109,13 +1115,13 @@ void EightBit::Z80::executeED(int x, int y, int z, int p, int q) {
|
||||
break;
|
||||
case 6: // INIR
|
||||
if (inir()) {
|
||||
pc.word -= 2;
|
||||
PC().word -= 2;
|
||||
cycles += 5;
|
||||
}
|
||||
break;
|
||||
case 7: // INDR
|
||||
if (indr()) {
|
||||
pc.word -= 2;
|
||||
PC().word -= 2;
|
||||
cycles += 5;
|
||||
}
|
||||
break;
|
||||
@@ -1131,13 +1137,13 @@ void EightBit::Z80::executeED(int x, int y, int z, int p, int q) {
|
||||
break;
|
||||
case 6: // OTIR
|
||||
if (otir()) {
|
||||
pc.word -= 2;
|
||||
PC().word -= 2;
|
||||
cycles += 5;
|
||||
}
|
||||
break;
|
||||
case 7: // OTDR
|
||||
if (otdr()) {
|
||||
pc.word -= 2;
|
||||
PC().word -= 2;
|
||||
cycles += 5;
|
||||
}
|
||||
break;
|
||||
@@ -1394,11 +1400,11 @@ void EightBit::Z80::executeOther(int x, int y, int z, int p, int q) {
|
||||
cycles += 4;
|
||||
break;
|
||||
case 2: // JP HL
|
||||
pc = HL2();
|
||||
PC() = HL2();
|
||||
cycles += 4;
|
||||
break;
|
||||
case 3: // LD SP,HL
|
||||
sp = HL2();
|
||||
SP() = HL2();
|
||||
cycles += 4;
|
||||
break;
|
||||
}
|
||||
|
||||
+4
-4
@@ -32,11 +32,11 @@ void Board::initialise() {
|
||||
}
|
||||
|
||||
m_cpu.initialise();
|
||||
m_cpu.setProgramCounter(m_configuration.getStartAddress());
|
||||
m_cpu.PC() = m_configuration.getStartAddress();
|
||||
}
|
||||
|
||||
void Board::Cpu_ExecutingInstruction_Cpm(const EightBit::Z80&) {
|
||||
auto pc = m_cpu.getProgramCounter();
|
||||
auto pc = m_cpu.PC();
|
||||
switch (pc.word) {
|
||||
case 0x0: // CP/M warm start
|
||||
m_cpu.halt();
|
||||
@@ -68,7 +68,7 @@ void Board::bdos() {
|
||||
|
||||
void Board::Cpu_ExecutingInstruction_Profile(const EightBit::Z80& cpu) {
|
||||
|
||||
const auto pc = cpu.getProgramCounter();
|
||||
const auto pc = m_cpu.PC();
|
||||
|
||||
m_profiler.addAddress(pc.word);
|
||||
m_profiler.addInstruction(m_memory.peek(pc.word));
|
||||
@@ -79,6 +79,6 @@ void Board::Cpu_ExecutingInstruction_Debug(const EightBit::Z80& cpu) {
|
||||
std::cerr
|
||||
<< EightBit::Disassembler::state(m_cpu)
|
||||
<< "\t"
|
||||
<< m_disassembler.disassemble(cpu)
|
||||
<< m_disassembler.disassemble(m_cpu)
|
||||
<< '\n';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user