[sim] color up your simulator
authorMartin Perner <martin@perner.cc>
Sun, 9 Jan 2011 15:03:40 +0000 (16:03 +0100)
committerMartin Perner <martin@perner.cc>
Sun, 9 Jan 2011 17:11:31 +0000 (18:11 +0100)
3b_sim/ccolor.h [new file with mode: 0644]
3b_sim/ccpu.cpp
3b_sim/ccpu.hpp
3b_sim/sim.cpp
3c_disasm/ccolor.h [new symlink]

diff --git a/3b_sim/ccolor.h b/3b_sim/ccolor.h
new file mode 100644 (file)
index 0000000..aabf4a3
--- /dev/null
@@ -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 <iostream>
+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
index 6bfb65481fd61162ddcb9afd2ec3a9f14f102de1..873f1b7af8160baf9907fe600981e3226f24c0cd 100644 (file)
@@ -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();
        }
 
index 4c250b57570b97363655da1bbf9c8374e3013843..11f615212b9c32ea4e5798cc3da5f11e64a313ec 100644 (file)
@@ -5,6 +5,8 @@
 #include "cmem.hpp"
 #include "cpmem.hpp"
 
+#include "ccolor.h"
+
 class Iinstr;
 
 #include "Iinstr.hpp"
index d628d10a1cff46ec1cd740a4a1bb0081eb037839..8589084687a79e362a59335844980287fa11d41d 100644 (file)
@@ -114,7 +114,7 @@ void execStep(const vector<string>& 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<string>&)
                        }
                        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 (symlink)
index 0000000..755cdff
--- /dev/null
@@ -0,0 +1 @@
+../3b_sim/ccolor.h
\ No newline at end of file