v6502cpp/Trace.cpp

81 lines
2.0 KiB
C++
Raw Normal View History

2013-12-12 22:05:33 +00:00
/*
* File: Trace.cpp
* Author: cmosher
*
* Created on December 12, 2013, 3:39 PM
*/
#include "Trace.h"
#include "SegmentCache.h"
#include "Common.h"
2013-12-12 22:05:33 +00:00
#include <iostream>
#include <iomanip>
#include <cassert>
2013-12-12 22:05:33 +00:00
static void pHex(const unsigned long x, const int width) {
std::cout << std::setw(width) << std::setfill('0') << std::hex << x << std::dec;
}
static void pHexb(const unsigned char x) {
pHex(x,2);
2013-12-12 22:05:33 +00:00
}
static void pHexw(const unsigned short x) {
pHex(x,4);
2013-12-12 22:05:33 +00:00
}
void Trace::dumpSegments() const {
for (auto sp : this->s) {
Segment* seg = sp.second.get();
if (seg->pull == Pull::UP) {
std::cout << (seg->on ? "U" : "u");
} else if (seg->pull == Pull::DOWN) {
std::cout << (seg->on ? "D" : "d");
} else {
std::cout << (seg->on ? "F" : "f");
}
}
std::cout << std::endl;
2013-12-12 22:05:33 +00:00
}
void Trace::dumpRegisters() const {
2013-12-12 22:05:33 +00:00
std::cout << "A";
pHexb(common.rA());
2013-12-12 22:05:33 +00:00
std::cout << " X";
pHexb(common.rX());
2013-12-12 22:05:33 +00:00
std::cout << " Y";
pHexb(common.rY());
2013-12-12 22:05:33 +00:00
std::cout << " ";
std::cout << (this->common.P7->on ? "N" : "n");
std::cout << (this->common.P6->on ? "V" : "v");
2013-12-12 22:05:33 +00:00
std::cout << ".";
std::cout << (this->common.P4->on ? "B" : "b");
std::cout << (this->common.P3->on ? "D" : "d");
std::cout << (this->common.P2->on ? "I" : "i");
std::cout << (this->common.P1->on ? "Z" : "z");
std::cout << (this->common.P0->on ? "C" : "c");
2013-12-12 22:05:33 +00:00
std::cout << " S";
pHexb(common.rS());
2013-12-12 22:05:33 +00:00
std::cout << " PC";
pHexw(common.rPC());
if (this->common.CLK1OUT->on) {
2013-12-12 22:05:33 +00:00
std::cout << " PH1 ";
}
if (this->common.CLK2OUT->on) {
2013-12-12 22:05:33 +00:00
std::cout << " PH2";
if (this->common.RW->on) {
2013-12-12 22:05:33 +00:00
std::cout << " R";
} else {
std::cout << " W";
}
}
if (!(this->common.CLK1OUT->on || this->common.CLK2OUT->on)) {
2013-12-12 22:05:33 +00:00
std::cout << " PH- ";
}
std::cout << " DB";
pHexb(common.rData());
2013-12-12 22:05:33 +00:00
std::cout << " AB";
pHexw(common.rAddr());
2013-12-12 22:05:33 +00:00
std::cout << std::endl;
}