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