v6502cpp/Trace.cpp

104 lines
2.4 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"
2013-12-17 02:51:12 +00:00
#include "TransCache.h"
2013-12-12 22:05:33 +00:00
#include "SegmentCache.h"
#include "Common.h"
#include "trans.h"
2013-12-12 22:05:33 +00:00
#include <iostream>
#include <iomanip>
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->segs) {
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(this->common.rA());
2013-12-12 22:05:33 +00:00
std::cout << " X";
pHexb(this->common.rX());
2013-12-12 22:05:33 +00:00
std::cout << " Y";
pHexb(this->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(this->common.rS());
2013-12-12 22:05:33 +00:00
std::cout << " PC";
pHexw(this->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- ";
}
2013-12-12 22:05:33 +00:00
std::cout << " DB";
pHexb(this->common.rData());
2013-12-12 22:05:33 +00:00
std::cout << " AB";
pHexw(this->common.rAddr());
2013-12-12 22:05:33 +00:00
std::cout << std::endl;
}
2013-12-17 02:51:12 +00:00
void Trace::dumpTransistors() const {
/* count depletion-mode MOSFETs */
int cd(0);
for (auto sp : this->segs) {
Segment* seg = sp.second.get();
if (seg->dmos) {
++cd;
}
}
std::cout << "eMOSFETs: " << this->transes.size() << ", dMOSFETs: " << cd << std::endl;
}