2017-06-04 20:38:34 +00:00
|
|
|
#include "stdafx.h"
|
2021-05-29 09:31:32 +00:00
|
|
|
#include "../inc/Processor.h"
|
2017-06-04 20:38:34 +00:00
|
|
|
|
2021-07-18 13:28:40 +00:00
|
|
|
EightBit::Processor::Processor(Bus& bus) noexcept
|
2017-11-10 22:41:50 +00:00
|
|
|
: m_bus(bus) {
|
2017-06-04 20:38:34 +00:00
|
|
|
}
|
|
|
|
|
2021-12-27 22:07:30 +00:00
|
|
|
EightBit::Processor::Processor(const Processor& rhs)
|
|
|
|
: ClockedChip(rhs),
|
|
|
|
m_bus(rhs.m_bus) {
|
|
|
|
RESET() = rhs.RESET();
|
|
|
|
INT() = rhs.INT();
|
|
|
|
PC() = rhs.PC();
|
|
|
|
}
|
|
|
|
|
2024-01-07 14:04:41 +00:00
|
|
|
DEFINE_PIN_LEVEL_CHANGERS(RESET, Processor)
|
|
|
|
DEFINE_PIN_LEVEL_CHANGERS(INT, Processor)
|
2018-08-25 00:34:30 +00:00
|
|
|
|
2022-01-17 19:10:15 +00:00
|
|
|
void EightBit::Processor::handleRESET() noexcept {
|
2019-01-14 02:10:17 +00:00
|
|
|
raiseRESET();
|
|
|
|
}
|
|
|
|
|
2022-01-17 19:10:15 +00:00
|
|
|
void EightBit::Processor::handleINT() noexcept {
|
2019-01-14 02:10:17 +00:00
|
|
|
raiseINT();
|
2018-08-25 11:09:26 +00:00
|
|
|
}
|
|
|
|
|
2022-01-17 19:10:15 +00:00
|
|
|
void EightBit::Processor::memoryWrite(const register16_t address, const uint8_t data) noexcept {
|
2018-12-29 19:17:36 +00:00
|
|
|
BUS().ADDRESS() = address;
|
2020-02-09 11:51:58 +00:00
|
|
|
memoryWrite(data);
|
2018-12-29 19:17:36 +00:00
|
|
|
}
|
|
|
|
|
2022-01-17 19:10:15 +00:00
|
|
|
void EightBit::Processor::memoryWrite(const register16_t address) noexcept {
|
2021-01-09 08:41:48 +00:00
|
|
|
BUS().ADDRESS() = address;
|
|
|
|
memoryWrite();
|
|
|
|
}
|
|
|
|
|
2022-01-17 19:10:15 +00:00
|
|
|
void EightBit::Processor::memoryWrite(const uint8_t data) noexcept {
|
2018-12-29 19:17:36 +00:00
|
|
|
BUS().DATA() = data;
|
2020-02-09 11:51:58 +00:00
|
|
|
memoryWrite();
|
|
|
|
}
|
|
|
|
|
2022-01-17 19:10:15 +00:00
|
|
|
void EightBit::Processor::memoryWrite() noexcept {
|
2018-12-29 19:17:36 +00:00
|
|
|
busWrite();
|
|
|
|
}
|
|
|
|
|
2022-01-17 19:10:15 +00:00
|
|
|
void EightBit::Processor::busWrite() noexcept {
|
2018-12-29 19:17:36 +00:00
|
|
|
BUS().write();
|
|
|
|
}
|
|
|
|
|
2022-01-17 19:10:15 +00:00
|
|
|
uint8_t EightBit::Processor::memoryRead(const register16_t address) noexcept {
|
2018-12-29 19:17:36 +00:00
|
|
|
BUS().ADDRESS() = address;
|
2020-02-09 11:51:58 +00:00
|
|
|
return memoryRead();
|
|
|
|
}
|
|
|
|
|
2022-01-17 19:10:15 +00:00
|
|
|
uint8_t EightBit::Processor::memoryRead() noexcept {
|
2018-12-29 19:17:36 +00:00
|
|
|
return busRead();
|
|
|
|
}
|
|
|
|
|
2022-01-17 19:10:15 +00:00
|
|
|
uint8_t EightBit::Processor::busRead() noexcept {
|
2018-12-29 19:17:36 +00:00
|
|
|
return BUS().read();
|
|
|
|
}
|
|
|
|
|
2022-01-17 19:10:15 +00:00
|
|
|
uint8_t EightBit::Processor::getBytePaged(const uint8_t page, const uint8_t offset) noexcept {
|
2021-01-09 08:41:48 +00:00
|
|
|
return memoryRead(register16_t(offset, page));
|
|
|
|
}
|
|
|
|
|
2022-01-17 19:10:15 +00:00
|
|
|
void EightBit::Processor::setBytePaged(const uint8_t page, const uint8_t offset, const uint8_t value) noexcept {
|
2021-01-09 08:41:48 +00:00
|
|
|
memoryWrite(register16_t(offset, page), value);
|
|
|
|
}
|
|
|
|
|
2022-01-17 19:10:15 +00:00
|
|
|
uint8_t EightBit::Processor::fetchByte() noexcept {
|
2021-01-09 08:41:48 +00:00
|
|
|
return memoryRead(PC()++);
|
|
|
|
}
|
|
|
|
|
2022-01-17 19:10:15 +00:00
|
|
|
EightBit::register16_t EightBit::Processor::getWord(const register16_t address) noexcept {
|
2021-01-09 08:41:48 +00:00
|
|
|
BUS().ADDRESS() = address;
|
|
|
|
return getWord();
|
|
|
|
}
|
|
|
|
|
2022-01-17 19:10:15 +00:00
|
|
|
void EightBit::Processor::setWord(const register16_t address, const register16_t value) noexcept {
|
2021-01-09 08:41:48 +00:00
|
|
|
BUS().ADDRESS() = address;
|
|
|
|
setWord(value);
|
|
|
|
}
|
|
|
|
|
2022-01-17 19:10:15 +00:00
|
|
|
int EightBit::Processor::run(const int limit) noexcept {
|
2017-08-30 22:17:34 +00:00
|
|
|
int current = 0;
|
2018-09-20 23:16:00 +00:00
|
|
|
while (LIKELY(powered() && (current < limit)))
|
2018-08-25 00:34:30 +00:00
|
|
|
current += step();
|
2017-08-30 22:17:34 +00:00
|
|
|
return current;
|
|
|
|
}
|
2018-08-27 11:57:44 +00:00
|
|
|
|
2022-01-17 19:10:15 +00:00
|
|
|
int EightBit::Processor::execute(const uint8_t value) noexcept {
|
2018-12-29 19:17:36 +00:00
|
|
|
opcode() = value;
|
|
|
|
return execute();
|
|
|
|
}
|
|
|
|
|
2021-01-09 08:41:48 +00:00
|
|
|
void EightBit::Processor::jump(const register16_t destination) noexcept {
|
|
|
|
PC() = destination;
|
|
|
|
}
|
|
|
|
|
2022-01-17 19:10:15 +00:00
|
|
|
void EightBit::Processor::call(const register16_t destination) noexcept {
|
2021-01-02 11:49:34 +00:00
|
|
|
pushWord(PC());
|
|
|
|
jump(destination);
|
|
|
|
}
|
|
|
|
|
2022-01-17 19:10:15 +00:00
|
|
|
void EightBit::Processor::ret() noexcept {
|
2018-11-25 10:43:51 +00:00
|
|
|
jump(popWord());
|
|
|
|
}
|
2021-12-27 14:24:38 +00:00
|
|
|
|
|
|
|
bool EightBit::Processor::operator==(const EightBit::Processor& rhs) const {
|
|
|
|
return
|
|
|
|
ClockedChip::operator==(rhs)
|
|
|
|
&& RESET() == rhs.RESET()
|
|
|
|
&& INT() == rhs.INT()
|
|
|
|
&& PC() == rhs.PC();
|
|
|
|
}
|