diff options
Diffstat (limited to 'ue3/mycpu/ccpu.cpp')
| -rw-r--r-- | ue3/mycpu/ccpu.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/ue3/mycpu/ccpu.cpp b/ue3/mycpu/ccpu.cpp new file mode 100644 index 0000000..6f364f8 --- /dev/null +++ b/ue3/mycpu/ccpu.cpp | |||
| @@ -0,0 +1,78 @@ | |||
| 1 | /** | ||
| 2 | * @module ccpu | ||
| 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) | ||
| 4 | * @brief TODO | ||
| 5 | * @date 10.05.2009 | ||
| 6 | */ | ||
| 7 | |||
| 8 | #ifdef DEBUG | ||
| 9 | # include <iostream> | ||
| 10 | # include <iomanip> | ||
| 11 | #endif | ||
| 12 | #include "ccpu.h" | ||
| 13 | |||
| 14 | using namespace std; | ||
| 15 | |||
| 16 | CCPU::CCPU(const unsigned cnt) | ||
| 17 | : m_regcnt(cnt), m_memory(NULL), m_program(NULL), m_flagzero(0), m_flagsign(0) | ||
| 18 | { | ||
| 19 | m_registers = new CDat[cnt]; | ||
| 20 | for(unsigned i = 0; i < cnt; ++i) | ||
| 21 | m_registers[i] = 0; | ||
| 22 | } | ||
| 23 | |||
| 24 | /*----------------------------------------------------------------------------*/ | ||
| 25 | |||
| 26 | CCPU::~CCPU() | ||
| 27 | { | ||
| 28 | delete[] m_registers; | ||
| 29 | m_registers = NULL; | ||
| 30 | } | ||
| 31 | |||
| 32 | /*----------------------------------------------------------------------------*/ | ||
| 33 | |||
| 34 | void CCPU::run() | ||
| 35 | { | ||
| 36 | if (m_memory == NULL) | ||
| 37 | throw runtime_error("CPU has no memory"); | ||
| 38 | if (m_program == NULL) | ||
| 39 | throw runtime_error("CPU has no program to execute"); | ||
| 40 | if (m_regcnt == 0) | ||
| 41 | throw runtime_error("CPU has no registers"); | ||
| 42 | |||
| 43 | bool run = true; | ||
| 44 | while(run) | ||
| 45 | { | ||
| 46 | unsigned pc = static_cast<unsigned>(m_registers[0]); | ||
| 47 | |||
| 48 | /* end of the program reached */ | ||
| 49 | if (pc == m_program->size()) | ||
| 50 | return; | ||
| 51 | |||
| 52 | /* pc is out of bound */ | ||
| 53 | if (pc > m_program->size()) | ||
| 54 | throw runtime_error("Programcounter is out of bound"); | ||
| 55 | |||
| 56 | /* execute instruction */ | ||
| 57 | m_program->at(pc)->execute(this); | ||
| 58 | ++m_registers[0]; | ||
| 59 | } | ||
| 60 | |||
| 61 | cout << "LALA" << endl; | ||
| 62 | } | ||
| 63 | |||
| 64 | /*----------------------------------------------------------------------------*/ | ||
| 65 | |||
| 66 | #if DEBUG | ||
| 67 | void CCPU::dumpRegisters(std::ostream& out) | ||
| 68 | { | ||
| 69 | out << "[REGISTER DUMP]" << endl; | ||
| 70 | for(unsigned i = 0; i < getRegisterCount(); ++i) | ||
| 71 | { | ||
| 72 | out << "[" << std::setw(4) << std::setfill('0') << i << "] " | ||
| 73 | << m_registers[i] << endl; | ||
| 74 | } | ||
| 75 | } | ||
| 76 | #endif | ||
| 77 | |||
| 78 | /* vim: set et sw=2 ts=2: */ | ||
