From 8f5ad4611ce8bdc9e3288e24252633557f4e950b Mon Sep 17 00:00:00 2001 From: Martin Perner Date: Sun, 9 Jan 2011 16:03:40 +0100 Subject: [PATCH] [sim] color up your simulator --- 3b_sim/ccolor.h | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 3b_sim/ccpu.cpp | 4 +-- 3b_sim/ccpu.hpp | 2 ++ 3b_sim/sim.cpp | 4 +-- 3c_disasm/ccolor.h | 1 + 5 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 3b_sim/ccolor.h create mode 120000 3c_disasm/ccolor.h diff --git a/3b_sim/ccolor.h b/3b_sim/ccolor.h new file mode 100644 index 0000000..aabf4a3 --- /dev/null +++ b/3b_sim/ccolor.h @@ -0,0 +1,65 @@ +#ifndef COLOR_H +#define COLOR_H + +// +//taken from +//http://www.velocityreviews.com/forums/t279115-design-question-a-little-c-header-for-colorizing-text-in-linux-comments-ideas.html + +#include +using namespace std; + +enum ColorName +{ + black, + red, + green, + brown, + blue, + magenta, + cyan, + gray, + + darkgray, + lightred, + lightgreen, + yellow, + lightblue, + lightmagenta, + lightcyan, + white +}; + + +struct color +{ + color(ColorName f = white, ColorName b = black) : fore(f), back(b) {} + + ColorName fore; + ColorName back; +}; + + +inline ostream& operator<<(ostream& o, const color& c) +{ + o << "\033["; + + if(c.back != black) { + o << "4" << c.back << ";"; + } + else { + o << "0;"; + } + + if(c.fore > gray) { + // bold color + o << "1;3" << c.fore - gray - 1; + } + else { + o << "0;3" << c.fore ; + } + + return o << "m"; + +} + +#endif diff --git a/3b_sim/ccpu.cpp b/3b_sim/ccpu.cpp index 6bfb654..873f1b7 100644 --- a/3b_sim/ccpu.cpp +++ b/3b_sim/ccpu.cpp @@ -18,12 +18,12 @@ void CCpu::tick() throw string("Out of Instructions!"); } if(this->conditionMet(instr->getCondition())) { - cout << "Executing: " << instr->toString() << endl; + cout << color(green,black) << "Executing: " << color(white,black) << instr->toString() << endl; instr->execInstr(); this->incPerfBy(instr->getClockCount()); } else { - cout << "Didn't Execute " << instr->toString() << "; condition wasn't met" << endl; + cout << color(red,black) << "Didn't Execute " << color(white,black) << instr->toString() << "; condition wasn't met" << endl; this->incPerf(); } diff --git a/3b_sim/ccpu.hpp b/3b_sim/ccpu.hpp index 4c250b5..11f6152 100644 --- a/3b_sim/ccpu.hpp +++ b/3b_sim/ccpu.hpp @@ -5,6 +5,8 @@ #include "cmem.hpp" #include "cpmem.hpp" +#include "ccolor.h" + class Iinstr; #include "Iinstr.hpp" diff --git a/3b_sim/sim.cpp b/3b_sim/sim.cpp index d628d10..8589084 100644 --- a/3b_sim/sim.cpp +++ b/3b_sim/sim.cpp @@ -114,7 +114,7 @@ void execStep(const vector& in) } else { ignoreBreak = true; - cout << "Breakpoint 0x" << std::hex << setw(8) << setfill('0') << *breakp << std::hex << " hit" << endl; + cout << color(white,red) << "Breakpoint" << color(white,black) << " 0x" << std::hex << setw(8) << setfill('0') << *breakp << std::hex << " hit" << endl; break; } } @@ -136,7 +136,7 @@ void execRun(const vector&) } else { ignoreBreak = true; - cout << "Breakpoint 0x" << std::hex << setw(8) << setfill('0') << *breakp << std::hex << " hit" << endl; + cout << color(white,red) << "Breakpoint" << color(white,black) << " 0x" << std::hex << setw(8) << setfill('0') << *breakp << std::hex << " hit" << endl; return; } } diff --git a/3c_disasm/ccolor.h b/3c_disasm/ccolor.h new file mode 120000 index 0000000..755cdff --- /dev/null +++ b/3c_disasm/ccolor.h @@ -0,0 +1 @@ +../3b_sim/ccolor.h \ No newline at end of file -- 2.25.1