mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-12-21 18:29:57 +00:00
More tidying of shareable code
This commit is contained in:
parent
8f3aef1c3e
commit
828e081a6e
@ -4,6 +4,7 @@
|
||||
|
||||
#include "IntelProcessor.h"
|
||||
#include "InputOutput.h"
|
||||
#include "Signal.h"
|
||||
|
||||
namespace EightBit {
|
||||
class Z80 : public IntelProcessor {
|
||||
@ -232,35 +233,6 @@ namespace EightBit {
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t getViaMemptr() {
|
||||
m_memory.ADDRESS() = MEMPTR();
|
||||
MEMPTR().word++;
|
||||
return m_memory.reference();
|
||||
}
|
||||
|
||||
void setViaMemptr(uint8_t value) {
|
||||
m_memory.ADDRESS() = MEMPTR();
|
||||
MEMPTR().word++;
|
||||
m_memory.reference() = value;
|
||||
MEMPTR().high = value;
|
||||
}
|
||||
|
||||
void getWordViaMemptr(register16_t& value) {
|
||||
m_memory.ADDRESS() = MEMPTR();
|
||||
MEMPTR().word++;
|
||||
value.low = m_memory.reference();
|
||||
m_memory.ADDRESS().word++;
|
||||
value.high = m_memory.reference();
|
||||
}
|
||||
|
||||
void setWordViaMemptr(register16_t value) {
|
||||
m_memory.ADDRESS() = MEMPTR();
|
||||
MEMPTR().word++;
|
||||
m_memory.reference() = value.low;
|
||||
m_memory.ADDRESS().word++;
|
||||
m_memory.reference() = value.high;
|
||||
}
|
||||
|
||||
void addViaMemptr(register16_t& hl, register16_t operand) {
|
||||
MEMPTR().word = hl.word + 1;
|
||||
add(hl, operand);
|
||||
@ -370,32 +342,32 @@ namespace EightBit {
|
||||
void blockCompare();
|
||||
|
||||
void cpi();
|
||||
void cpir();
|
||||
bool cpir();
|
||||
|
||||
void cpd();
|
||||
void cpdr();
|
||||
bool cpdr();
|
||||
|
||||
void blockLoad(register16_t source, register16_t destination);
|
||||
|
||||
void ldi();
|
||||
void ldir();
|
||||
bool ldir();
|
||||
|
||||
void ldd();
|
||||
void lddr();
|
||||
bool lddr();
|
||||
|
||||
void ini();
|
||||
void inir();
|
||||
bool inir();
|
||||
|
||||
void ind();
|
||||
void indr();
|
||||
bool indr();
|
||||
|
||||
void blockOut();
|
||||
|
||||
void outi();
|
||||
void otir();
|
||||
bool otir();
|
||||
|
||||
void outd();
|
||||
void otdr();
|
||||
bool otdr();
|
||||
|
||||
void neg();
|
||||
|
||||
|
112
Z80/src/Z80.cpp
112
Z80/src/Z80.cpp
@ -619,26 +619,28 @@ void EightBit::Z80::cpd() {
|
||||
MEMPTR().word--;
|
||||
}
|
||||
|
||||
void EightBit::Z80::cpir() {
|
||||
bool EightBit::Z80::cpir() {
|
||||
cpi();
|
||||
if ((F() & PF) && !(F() & ZF)) { // See CPI
|
||||
cycles += 5;
|
||||
MEMPTR().word = pc.word;
|
||||
auto again = (F() & PF) && !(F() & ZF); // See CPI
|
||||
if (again) {
|
||||
MEMPTR().word--;
|
||||
pc.word -= 2;
|
||||
MEMPTR().word = pc.word + 1;
|
||||
} else {
|
||||
MEMPTR().word = pc.word;
|
||||
}
|
||||
return again;
|
||||
}
|
||||
|
||||
void EightBit::Z80::cpdr() {
|
||||
bool EightBit::Z80::cpdr() {
|
||||
cpd();
|
||||
if ((F() & PF) && !(F() & ZF)) { // See CPD
|
||||
cycles += 5;
|
||||
MEMPTR().word = pc.word;
|
||||
auto again = (F() & PF) && !(F() & ZF); // See CPD
|
||||
if (again) {
|
||||
MEMPTR().word--;
|
||||
pc.word -= 2;
|
||||
MEMPTR().word = pc.word + 1;
|
||||
} else {
|
||||
MEMPTR().word = pc.word - 2;
|
||||
MEMPTR().word -= 2;
|
||||
}
|
||||
return again;
|
||||
}
|
||||
|
||||
#pragma endregion Block compare instructions
|
||||
@ -669,22 +671,24 @@ void EightBit::Z80::ldi() {
|
||||
DE().word++;
|
||||
}
|
||||
|
||||
void EightBit::Z80::ldir() {
|
||||
bool EightBit::Z80::ldir() {
|
||||
ldi();
|
||||
if (F() & PF) { // See LDI
|
||||
cycles += 5;
|
||||
auto again = (F() & PF) != 0;
|
||||
if (again) { // See LDI
|
||||
MEMPTR().word = pc.word - 1;
|
||||
pc.word -= 2;
|
||||
MEMPTR().word = pc.word + 1;
|
||||
}
|
||||
return again;
|
||||
}
|
||||
|
||||
void EightBit::Z80::lddr() {
|
||||
bool EightBit::Z80::lddr() {
|
||||
ldd();
|
||||
auto again = (F() & PF) != 0;
|
||||
if (F() & PF) { // See LDR
|
||||
cycles += 5;
|
||||
MEMPTR().word = pc.word - 1;
|
||||
pc.word -= 2;
|
||||
MEMPTR().word = pc.word + 1;
|
||||
}
|
||||
return again;
|
||||
}
|
||||
|
||||
#pragma endregion Block load instructions
|
||||
@ -713,20 +717,20 @@ void EightBit::Z80::ind() {
|
||||
setFlag(NF);
|
||||
}
|
||||
|
||||
void EightBit::Z80::inir() {
|
||||
bool EightBit::Z80::inir() {
|
||||
ini();
|
||||
if (!(F() & ZF)) { // See INI
|
||||
cycles += 5;
|
||||
auto again = !(F() & ZF); // See INI
|
||||
if (again)
|
||||
pc.word -= 2;
|
||||
}
|
||||
return again;
|
||||
}
|
||||
|
||||
void EightBit::Z80::indr() {
|
||||
bool EightBit::Z80::indr() {
|
||||
ind();
|
||||
if (!(F() & ZF)) { // See IND
|
||||
cycles += 5;
|
||||
auto again = !(F() & ZF); // See IND
|
||||
if (again)
|
||||
pc.word -= 2;
|
||||
}
|
||||
return again;
|
||||
}
|
||||
|
||||
#pragma endregion Block input instructions
|
||||
@ -755,20 +759,20 @@ void EightBit::Z80::outd() {
|
||||
MEMPTR().word = BC().word - 1;
|
||||
}
|
||||
|
||||
void EightBit::Z80::otir() {
|
||||
bool EightBit::Z80::otir() {
|
||||
outi();
|
||||
if (!(F() & ZF)) { // See OUTI
|
||||
cycles += 5;
|
||||
auto again = !(F() & ZF); // See OUTI
|
||||
if (again)
|
||||
pc.word -= 2;
|
||||
}
|
||||
return again;
|
||||
}
|
||||
|
||||
void EightBit::Z80::otdr() {
|
||||
bool EightBit::Z80::otdr() {
|
||||
outd();
|
||||
if (!(F() & ZF)) { // See OUTD
|
||||
cycles += 5;
|
||||
auto again = !(F() & ZF); // See OUTD
|
||||
if (again)
|
||||
pc.word -= 2;
|
||||
}
|
||||
return again;
|
||||
}
|
||||
|
||||
#pragma endregion Block output instructions
|
||||
@ -778,9 +782,8 @@ void EightBit::Z80::otdr() {
|
||||
#pragma region Nibble rotation
|
||||
|
||||
void EightBit::Z80::rrd() {
|
||||
MEMPTR() = m_memory.ADDRESS() = HL();
|
||||
MEMPTR().word++;
|
||||
auto memory = m_memory.reference();
|
||||
MEMPTR() = HL();
|
||||
auto memory = getViaMemptr();
|
||||
auto accumulator = A();
|
||||
A() = (accumulator & 0xf0) | lowNibble(memory);
|
||||
uint8_t updated = promoteNibble(lowNibble(accumulator)) | highNibble(memory);
|
||||
@ -790,9 +793,8 @@ void EightBit::Z80::rrd() {
|
||||
}
|
||||
|
||||
void EightBit::Z80::rld() {
|
||||
MEMPTR() = m_memory.ADDRESS() = HL();
|
||||
MEMPTR().word++;
|
||||
auto memory = m_memory.reference();
|
||||
MEMPTR() = HL();
|
||||
auto memory = getViaMemptr();
|
||||
auto accumulator = A();
|
||||
uint8_t updated = lowNibble(accumulator) | promoteNibble(memory);
|
||||
A() = (accumulator & 0xf0) | highNibble(memory);
|
||||
@ -909,13 +911,11 @@ void EightBit::Z80::executeCB(int x, int y, int z, int p, int q) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (m_prefixDD || m_prefixFD)
|
||||
adjustSZP(DISPLACED());
|
||||
else
|
||||
adjustSZP(R(z));
|
||||
if (m_prefixDD || m_prefixFD) {
|
||||
adjustSZP(DISPLACED());
|
||||
cycles += 23;
|
||||
} else {
|
||||
adjustSZP(R(z));
|
||||
cycles += 8;
|
||||
if (z == 6)
|
||||
cycles += 7;
|
||||
@ -1103,10 +1103,12 @@ void EightBit::Z80::executeED(int x, int y, int z, int p, int q) {
|
||||
ldd();
|
||||
break;
|
||||
case 6: // LDIR
|
||||
ldir();
|
||||
if (ldir())
|
||||
cycles += 5;
|
||||
break;
|
||||
case 7: // LDDR
|
||||
lddr();
|
||||
if (lddr())
|
||||
cycles += 5;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -1119,10 +1121,12 @@ void EightBit::Z80::executeED(int x, int y, int z, int p, int q) {
|
||||
cpd();
|
||||
break;
|
||||
case 6: // CPIR
|
||||
cpir();
|
||||
if (cpir())
|
||||
cycles += 5;
|
||||
break;
|
||||
case 7: // CPDR
|
||||
cpdr();
|
||||
if (cpdr())
|
||||
cycles += 5;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -1135,10 +1139,12 @@ void EightBit::Z80::executeED(int x, int y, int z, int p, int q) {
|
||||
ind();
|
||||
break;
|
||||
case 6: // INIR
|
||||
inir();
|
||||
if (inir())
|
||||
cycles += 5;
|
||||
break;
|
||||
case 7: // INDR
|
||||
indr();
|
||||
if (indr())
|
||||
cycles += 5;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -1151,10 +1157,12 @@ void EightBit::Z80::executeED(int x, int y, int z, int p, int q) {
|
||||
outd();
|
||||
break;
|
||||
case 6: // OTIR
|
||||
otir();
|
||||
if (otir())
|
||||
cycles += 5;
|
||||
break;
|
||||
case 7: // OTDR
|
||||
otdr();
|
||||
if (otdr())
|
||||
cycles += 5;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -42,6 +42,37 @@ namespace EightBit {
|
||||
|
||||
//
|
||||
|
||||
uint8_t getViaMemptr() {
|
||||
m_memory.ADDRESS() = MEMPTR();
|
||||
MEMPTR().word++;
|
||||
return m_memory.reference();
|
||||
}
|
||||
|
||||
void setViaMemptr(uint8_t value) {
|
||||
m_memory.ADDRESS() = MEMPTR();
|
||||
MEMPTR().word++;
|
||||
m_memory.reference() = value;
|
||||
MEMPTR().high = value;
|
||||
}
|
||||
|
||||
void getWordViaMemptr(register16_t& value) {
|
||||
m_memory.ADDRESS() = MEMPTR();
|
||||
MEMPTR().word++;
|
||||
value.low = m_memory.reference();
|
||||
m_memory.ADDRESS().word++;
|
||||
value.high = m_memory.reference();
|
||||
}
|
||||
|
||||
void setWordViaMemptr(register16_t value) {
|
||||
m_memory.ADDRESS() = MEMPTR();
|
||||
MEMPTR().word++;
|
||||
m_memory.reference() = value.low;
|
||||
m_memory.ADDRESS().word++;
|
||||
m_memory.reference() = value.high;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
void jump() {
|
||||
pc = MEMPTR();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user