2017-06-04 20:38:34 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "Processor.h"
|
|
|
|
|
2017-09-06 12:22:23 +00:00
|
|
|
EightBit::Processor::Processor(Bus& bus)
|
2017-11-10 22:41:50 +00:00
|
|
|
: m_bus(bus) {
|
2017-06-04 20:38:34 +00:00
|
|
|
}
|
|
|
|
|
2019-01-14 23:17:54 +00:00
|
|
|
DEFINE_PIN_LEVEL_CHANGERS(RESET, Processor);
|
|
|
|
DEFINE_PIN_LEVEL_CHANGERS(INT, Processor);
|
2018-08-25 00:34:30 +00:00
|
|
|
|
2019-01-14 02:10:17 +00:00
|
|
|
void EightBit::Processor::handleRESET() {
|
|
|
|
raiseRESET();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EightBit::Processor::handleINT() {
|
|
|
|
raiseINT();
|
2018-08-25 11:09:26 +00:00
|
|
|
}
|
|
|
|
|
2018-12-29 19:17:36 +00:00
|
|
|
void EightBit::Processor::busWrite(const register16_t address, const uint8_t data) {
|
|
|
|
BUS().ADDRESS() = address;
|
|
|
|
busWrite(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EightBit::Processor::busWrite(const uint8_t data) {
|
|
|
|
BUS().DATA() = data;
|
|
|
|
busWrite();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EightBit::Processor::busWrite() {
|
|
|
|
BUS().write();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t EightBit::Processor::busRead(const register16_t address) {
|
|
|
|
BUS().ADDRESS() = address;
|
|
|
|
return busRead();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t EightBit::Processor::busRead() {
|
|
|
|
return BUS().read();
|
|
|
|
}
|
|
|
|
|
2018-04-14 08:39:06 +00:00
|
|
|
int EightBit::Processor::run(const int limit) {
|
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
|
|
|
|
2018-12-29 19:17:36 +00:00
|
|
|
int EightBit::Processor::execute(const uint8_t value) {
|
|
|
|
opcode() = value;
|
|
|
|
return execute();
|
|
|
|
}
|
|
|
|
|
2018-08-27 11:57:44 +00:00
|
|
|
// http://graphics.stanford.edu/~seander/bithacks.html#FixedSignExtend
|
2018-09-20 23:16:00 +00:00
|
|
|
int8_t EightBit::Processor::signExtend(const int b, uint8_t x) {
|
2019-11-03 09:23:28 +00:00
|
|
|
const uint8_t m = bit(b - 1); // mask can be pre-computed if b is fixed
|
|
|
|
x = x & (bit(b) - 1); // (Skip this if bits in x above position b are already zero.)
|
2018-08-27 11:57:44 +00:00
|
|
|
const auto result = (x ^ m) - m;
|
|
|
|
return result;
|
|
|
|
}
|
2018-11-25 10:43:51 +00:00
|
|
|
|
|
|
|
void EightBit::Processor::ret() {
|
|
|
|
jump(popWord());
|
|
|
|
}
|