2013-12-13 04:31:47 +00:00
|
|
|
/*
|
|
|
|
* File: Cpu6502.cpp
|
|
|
|
* Author: Christopher
|
|
|
|
*
|
|
|
|
* Created on December 12, 2013, 10:14 PM
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Cpu6502.h"
|
2013-12-13 14:55:19 +00:00
|
|
|
#include "addressbus.h"
|
|
|
|
#include "StateCalculator.h"
|
2013-12-15 17:49:18 +00:00
|
|
|
#include "Trace.h"
|
2013-12-15 02:04:57 +00:00
|
|
|
#include "Common.h"
|
2013-12-15 17:49:18 +00:00
|
|
|
#include "trans.h"
|
2013-12-13 04:31:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define TRACEREG 1
|
2013-12-15 05:23:25 +00:00
|
|
|
//#define TRACESEG 1
|
2013-12-13 04:31:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-15 02:04:57 +00:00
|
|
|
void Cpu6502::setPins(const PinSettings& ps) {
|
2013-12-15 17:49:18 +00:00
|
|
|
SegmentSet rec;
|
2013-12-15 02:04:57 +00:00
|
|
|
for (auto p : ps) {
|
|
|
|
p.first->set(p.second);
|
|
|
|
rec.insert(p.first);
|
|
|
|
}
|
|
|
|
StateCalculator::recalc(rec);
|
2013-12-13 04:31:47 +00:00
|
|
|
}
|
|
|
|
|
2013-12-15 02:04:57 +00:00
|
|
|
void Cpu6502::clock(bool phase) {
|
2013-12-15 03:48:06 +00:00
|
|
|
setPins(PinSettings{std::make_pair(common.CLK0,phase)});
|
2013-12-13 04:31:47 +00:00
|
|
|
rw();
|
|
|
|
|
2013-12-15 02:04:57 +00:00
|
|
|
#ifdef TRACEREG
|
|
|
|
this->trace.dumpRegisters();
|
|
|
|
#endif
|
2013-12-13 04:31:47 +00:00
|
|
|
|
2013-12-15 02:04:57 +00:00
|
|
|
#ifdef TRACESEG
|
|
|
|
this->trace.dumpSegments();
|
|
|
|
#endif
|
2013-12-13 04:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Cpu6502::rw() {
|
2013-12-15 03:48:06 +00:00
|
|
|
/* database read/write happens (only) during Clock Phase 2 */
|
|
|
|
if (common.CLK2OUT->on) {
|
2013-12-15 02:04:57 +00:00
|
|
|
readData();
|
|
|
|
writeData();
|
2013-12-13 04:31:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-15 02:04:57 +00:00
|
|
|
void Cpu6502::readData() {
|
2013-12-15 03:48:06 +00:00
|
|
|
if (this->common.RW->on) {
|
2013-12-15 17:49:18 +00:00
|
|
|
setPins(this->common.getDataPinSettings(this->addressBus.read(this->common.rAddr())));
|
2013-12-13 04:31:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-15 02:04:57 +00:00
|
|
|
void Cpu6502::writeData() {
|
2013-12-15 03:48:06 +00:00
|
|
|
if (!this->common.RW->on) {
|
|
|
|
this->addressBus.write(this->common.rAddr(), this->common.rData());
|
2013-12-13 04:31:47 +00:00
|
|
|
}
|
|
|
|
}
|