2013-12-13 04:31:47 +00:00
|
|
|
/*
|
|
|
|
* File: Cpu6502Helper.cpp
|
|
|
|
* Author: Christopher
|
|
|
|
*
|
|
|
|
* Created on December 12, 2013, 10:22 PM
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Cpu6502Helper.h"
|
2013-12-15 02:04:57 +00:00
|
|
|
#include "Cpu6502.h"
|
|
|
|
#include "Common.h"
|
2013-12-15 17:49:18 +00:00
|
|
|
#include "SegmentTypes.h"
|
2013-12-13 04:31:47 +00:00
|
|
|
|
2013-12-15 02:04:57 +00:00
|
|
|
void Cpu6502Helper::powerOn() {
|
2013-12-15 17:49:18 +00:00
|
|
|
PinSettings ps;
|
2013-12-15 02:04:57 +00:00
|
|
|
|
|
|
|
// set voltage supply and ground.
|
2013-12-15 17:49:18 +00:00
|
|
|
ps.insert(std::make_pair(this->common.VCC, true));
|
|
|
|
ps.insert(std::make_pair(this->common.VSS, false));
|
2013-12-15 02:04:57 +00:00
|
|
|
|
|
|
|
// don't do the set-overflow overriding functionality
|
2013-12-15 17:49:18 +00:00
|
|
|
ps.insert(std::make_pair(this->common.SO, false));
|
2013-12-15 02:04:57 +00:00
|
|
|
|
|
|
|
// ready to run (i.e., do not do single-stepping of instructions)
|
2013-12-15 17:49:18 +00:00
|
|
|
ps.insert(std::make_pair(this->common.RDY, true));
|
2013-12-15 02:04:57 +00:00
|
|
|
|
|
|
|
// pull up to indicate that we are not interrupting now
|
2013-12-15 17:49:18 +00:00
|
|
|
ps.insert(std::make_pair(this->common.IRQ, true));
|
|
|
|
ps.insert(std::make_pair(this->common.NMI, true));
|
2013-12-15 02:04:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* RES_BAR pin means "not resetting". Since it is a negated pin, pulling it low means "resetting"
|
|
|
|
* and pulling it high means "not resetting" or equivalently "running".
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* RES_BAR false: resetting now (i.e., in power-up now; pull high to begin normal operation)
|
|
|
|
* We want to hold RES_BAR low for a while, indicating power-up phase during which the
|
|
|
|
* CPU does not start up normal operations yet. The caller can set RES_BAR high (by calling
|
|
|
|
* reset) whenever he is ready to start the CPU running.
|
|
|
|
*/
|
2013-12-15 17:49:18 +00:00
|
|
|
ps.insert(std::make_pair(this->common.RES, false));
|
2013-12-15 02:04:57 +00:00
|
|
|
|
2013-12-15 17:49:18 +00:00
|
|
|
this->cpu.setPins(ps);
|
2013-12-15 02:04:57 +00:00
|
|
|
|
2013-12-15 17:49:18 +00:00
|
|
|
this->nextPhase = true;
|
2013-12-15 02:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Cpu6502Helper::tick() {
|
|
|
|
step();
|
|
|
|
step();
|
2013-12-13 04:31:47 +00:00
|
|
|
}
|
|
|
|
|
2013-12-15 02:04:57 +00:00
|
|
|
void Cpu6502Helper::step() {
|
|
|
|
/*
|
|
|
|
* We cheat a little bit here: instead of requiring the
|
|
|
|
* caller to toggle clock-zero pin, we let him just call
|
|
|
|
* "step" and *we* keep track of which phase we are in.
|
|
|
|
* To do this, we just use the CLK0 segment value (as
|
|
|
|
* a kind of temporary variable), and just toggle it in
|
|
|
|
* order to know which phase we are going into.
|
|
|
|
*
|
|
|
|
* The real 6502, of course, does not do this.
|
|
|
|
*/
|
2013-12-15 17:49:18 +00:00
|
|
|
this->nextPhase = !this->nextPhase;
|
2013-12-15 02:04:57 +00:00
|
|
|
|
2013-12-15 17:49:18 +00:00
|
|
|
this->cpu.clock(this->nextPhase);
|
2013-12-15 02:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Cpu6502Helper::reset() {
|
2013-12-15 17:49:18 +00:00
|
|
|
this->cpu.setPins(PinSettings{std::make_pair(this->common.RES, true)});
|
2013-12-15 02:04:57 +00:00
|
|
|
}
|