mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2026-03-16 07:16:28 +00:00
150 lines
3.2 KiB
C++
150 lines
3.2 KiB
C++
#include "stdafx.h"
|
|
#include "../inc/IntelProcessor.h"
|
|
|
|
std::array<int, 8> EightBit::IntelProcessor::m_halfCarryTableAdd = { { 0, 0, 1, 0, 1, 0, 1, 1 } };
|
|
std::array<int, 8> EightBit::IntelProcessor::m_halfCarryTableSub = { { 0, 1, 1, 1, 0, 0, 0, 1 } };
|
|
|
|
EightBit::IntelProcessor::IntelProcessor(Bus& bus)
|
|
: LittleEndianProcessor(bus) {
|
|
for (int i = 0; i < 0x100; ++i)
|
|
m_decodedOpcodes.at(i) = i;
|
|
|
|
RaisedPOWER.connect([this](EventArgs) {
|
|
PC() = SP() = Mask16;
|
|
resetWorkingRegisters();
|
|
raiseHALT();
|
|
});
|
|
}
|
|
|
|
EightBit::IntelProcessor::IntelProcessor(const IntelProcessor& rhs) noexcept
|
|
: LittleEndianProcessor(rhs) {
|
|
|
|
m_sp = rhs.m_sp;
|
|
m_memptr = rhs.m_memptr;
|
|
|
|
HALT() = rhs.HALT();
|
|
}
|
|
|
|
void EightBit::IntelProcessor::resetWorkingRegisters() noexcept {
|
|
AF() = BC() = DE() = HL() = Mask16;
|
|
}
|
|
|
|
DEFINE_PIN_LEVEL_CHANGERS(HALT, IntelProcessor);
|
|
|
|
void EightBit::IntelProcessor::handleRESET() {
|
|
Processor::handleRESET();
|
|
disableInterrupts();
|
|
Processor::jump(0);
|
|
}
|
|
|
|
void EightBit::IntelProcessor::handleINT() {
|
|
Processor::handleINT();
|
|
disableInterrupts();
|
|
raiseHALT();
|
|
}
|
|
|
|
void EightBit::IntelProcessor::push(const uint8_t value) {
|
|
memoryWrite(--SP(), value);
|
|
}
|
|
|
|
uint8_t EightBit::IntelProcessor::pop() {
|
|
return memoryRead(SP()++);
|
|
}
|
|
|
|
|
|
EightBit::register16_t& EightBit::IntelProcessor::incrementPC() {
|
|
if (raised(HALT()))
|
|
Processor::incrementPC();
|
|
return PC();
|
|
}
|
|
|
|
uint8_t EightBit::IntelProcessor::fetchInstruction() {
|
|
fetchByte();
|
|
return lowered(HALT()) ? (uint8_t)0 : BUS().DATA();
|
|
}
|
|
|
|
EightBit::register16_t EightBit::IntelProcessor::getWord() {
|
|
const auto returned = LittleEndianProcessor::getWord();
|
|
MEMPTR() = BUS().ADDRESS();
|
|
return returned;
|
|
}
|
|
|
|
void EightBit::IntelProcessor::setWord(const register16_t value) {
|
|
LittleEndianProcessor::setWord(value);
|
|
MEMPTR() = BUS().ADDRESS();
|
|
}
|
|
|
|
void EightBit::IntelProcessor::restart(const uint8_t address) {
|
|
MEMPTR() = { address, 0 };
|
|
call();
|
|
}
|
|
|
|
void EightBit::IntelProcessor::callConditional(bool condition) {
|
|
fetchWordMEMPTR();
|
|
if (condition)
|
|
call();
|
|
}
|
|
|
|
void EightBit::IntelProcessor::jumpConditional(bool condition) {
|
|
fetchWordMEMPTR();
|
|
if (condition)
|
|
jump();
|
|
}
|
|
|
|
void EightBit::IntelProcessor::jumpRelativeConditional(bool condition) {
|
|
const auto offset = fetchByte();
|
|
if (condition)
|
|
jumpRelative(offset);
|
|
}
|
|
|
|
void EightBit::IntelProcessor::returnConditional(bool condition) {
|
|
if (condition)
|
|
ret();
|
|
}
|
|
|
|
void EightBit::IntelProcessor::jumpRelative(const int8_t offset) noexcept {
|
|
MEMPTR() = PC() + offset;
|
|
jump();
|
|
}
|
|
|
|
|
|
void EightBit::IntelProcessor::ret() {
|
|
LittleEndianProcessor::ret();
|
|
MEMPTR() = PC();
|
|
}
|
|
|
|
void EightBit::IntelProcessor::fetchWordMEMPTR() {
|
|
const auto _ = fetchWord();
|
|
MEMPTR() = intermediate();
|
|
}
|
|
|
|
void EightBit::IntelProcessor::jumpIndirect() {
|
|
fetchWordMEMPTR();
|
|
jump();
|
|
}
|
|
|
|
void EightBit::IntelProcessor::jump() {
|
|
Processor::jump(MEMPTR());
|
|
}
|
|
|
|
void EightBit::IntelProcessor::callIndirect() {
|
|
fetchWordMEMPTR();
|
|
call();
|
|
}
|
|
|
|
void EightBit::IntelProcessor::call() {
|
|
Processor::call(MEMPTR());
|
|
}
|
|
|
|
bool EightBit::IntelProcessor::operator==(const EightBit::IntelProcessor& rhs) const noexcept {
|
|
return
|
|
LittleEndianProcessor::operator==(rhs)
|
|
&& HALT() == rhs.HALT()
|
|
&& MEMPTR() == rhs.MEMPTR()
|
|
&& SP() == rhs.SP()
|
|
&& AF() == rhs.AF()
|
|
&& BC() == rhs.BC()
|
|
&& DE() == rhs.DE()
|
|
&& HL() == rhs.HL();
|
|
}
|