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
|
|
|
}
|
|
|
|
|
|
|
|
void EightBit::Processor::reset() {
|
2017-12-10 21:41:48 +00:00
|
|
|
if (lowered(POWER()))
|
|
|
|
throw std::logic_error("POWER cannot be low");
|
|
|
|
raise(INT());
|
|
|
|
raise(NMI());
|
|
|
|
raise(RESET());
|
2017-09-01 15:01:40 +00:00
|
|
|
PC().word = MEMPTR().word = 0;
|
2017-06-04 20:38:34 +00:00
|
|
|
}
|
|
|
|
|
2017-08-30 22:17:34 +00:00
|
|
|
int EightBit::Processor::run(int limit) {
|
|
|
|
int current = 0;
|
2017-11-20 19:17:49 +00:00
|
|
|
while (LIKELY(powered()) && current < limit) {
|
2017-08-30 22:17:34 +00:00
|
|
|
current += singleStep();
|
2017-08-31 16:19:32 +00:00
|
|
|
}
|
2017-08-30 22:17:34 +00:00
|
|
|
return current;
|
|
|
|
}
|
|
|
|
|
|
|
|
int EightBit::Processor::singleStep() {
|
2017-12-10 21:41:48 +00:00
|
|
|
if (UNLIKELY(lowered(RESET())))
|
|
|
|
reset();
|
2017-08-30 22:17:34 +00:00
|
|
|
return step();
|
|
|
|
}
|
2017-11-05 12:47:42 +00:00
|
|
|
|
|
|
|
uint8_t EightBit::Processor::fetchByte() {
|
|
|
|
return getByte(PC().word++);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EightBit::Processor::fetchWord(register16_t& output) {
|
|
|
|
output.low = fetchByte();
|
|
|
|
output.high = fetchByte();
|
|
|
|
}
|