diff options
| author | manuel <manuel@nc8430.lan> | 2009-05-26 23:10:13 +0200 |
|---|---|---|
| committer | manuel <manuel@nc8430.lan> | 2009-05-26 23:10:13 +0200 |
| commit | 26a97259f5a7b066cff2927e88c867fac2aaad87 (patch) | |
| tree | 40250b999ce0ca02d0ebcde55640c56be975e555 /ue4/mycpu/ccpu.cpp | |
| parent | 1a60d0c2a8eeef3b39ef276f0f3552552a1519b1 (diff) | |
| download | ooprog-26a97259f5a7b066cff2927e88c867fac2aaad87.tar.gz ooprog-26a97259f5a7b066cff2927e88c867fac2aaad87.tar.bz2 ooprog-26a97259f5a7b066cff2927e88c867fac2aaad87.zip | |
template FTW!!!!!11
Diffstat (limited to 'ue4/mycpu/ccpu.cpp')
| -rw-r--r-- | ue4/mycpu/ccpu.cpp | 89 |
1 files changed, 0 insertions, 89 deletions
diff --git a/ue4/mycpu/ccpu.cpp b/ue4/mycpu/ccpu.cpp deleted file mode 100644 index af86200..0000000 --- a/ue4/mycpu/ccpu.cpp +++ /dev/null | |||
| @@ -1,89 +0,0 @@ | |||
| 1 | /** | ||
| 2 | * @module ccpu | ||
| 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) | ||
| 4 | * @brief CPU implementation. Used as a container for memory and instructions. | ||
| 5 | * Implements an run method to execute the program (= the instructions). | ||
| 6 | * @date 10.05.2009 | ||
| 7 | */ | ||
| 8 | |||
| 9 | #ifdef DEBUG | ||
| 10 | # include <iostream> | ||
| 11 | # include <iomanip> | ||
| 12 | #endif | ||
| 13 | #include "ccpu.h" | ||
| 14 | #include "displays.h" | ||
| 15 | |||
| 16 | using namespace std; | ||
| 17 | |||
| 18 | CCPU::CCPU(const unsigned cnt) | ||
| 19 | : m_regcnt(cnt), m_memory(NULL), m_program(NULL), m_flagzero(false), m_flagsign(false) | ||
| 20 | { | ||
| 21 | /* create registers */ | ||
| 22 | m_registers = new CDat[cnt]; | ||
| 23 | for(unsigned i = 0; i < cnt; ++i) | ||
| 24 | m_registers[i] = 0; | ||
| 25 | |||
| 26 | /* create displays */ | ||
| 27 | m_displays.insert(new CDisplayWDEZ); | ||
| 28 | m_displays.insert(new CDisplayWHEX); | ||
| 29 | } | ||
| 30 | |||
| 31 | /*----------------------------------------------------------------------------*/ | ||
| 32 | |||
| 33 | CCPU::~CCPU() | ||
| 34 | { | ||
| 35 | /* delete registers */ | ||
| 36 | delete[] m_registers; | ||
| 37 | m_registers = NULL; | ||
| 38 | |||
| 39 | /* delete displays */ | ||
| 40 | std::set<CDisplay *>::iterator it; | ||
| 41 | for (it = m_displays.begin() ; it != m_displays.end(); ++it) | ||
| 42 | delete *it; | ||
| 43 | } | ||
| 44 | |||
| 45 | /*----------------------------------------------------------------------------*/ | ||
| 46 | |||
| 47 | void CCPU::run() | ||
| 48 | { | ||
| 49 | if (m_memory == NULL) | ||
| 50 | throw runtime_error("CPU has no memory"); | ||
| 51 | if (m_program == NULL) | ||
| 52 | throw runtime_error("CPU has no program to execute"); | ||
| 53 | if (m_regcnt == 0) | ||
| 54 | throw runtime_error("CPU has no registers"); | ||
| 55 | |||
| 56 | bool run = true; | ||
| 57 | while(run) | ||
| 58 | { | ||
| 59 | unsigned pc = static_cast<unsigned>(m_registers[0]); | ||
| 60 | |||
| 61 | /* end of the program reached */ | ||
| 62 | if (pc == m_program->size()) | ||
| 63 | break; | ||
| 64 | |||
| 65 | /* pc is out of bound */ | ||
| 66 | if (pc > m_program->size()) | ||
| 67 | throw runtime_error("Programcounter is out of bound"); | ||
| 68 | |||
| 69 | /* execute instruction */ | ||
| 70 | (*m_program->at(pc))(this); | ||
| 71 | ++m_registers[0]; | ||
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 75 | /*----------------------------------------------------------------------------*/ | ||
| 76 | |||
| 77 | #if DEBUG | ||
| 78 | void CCPU::dumpRegisters(std::ostream& out) | ||
| 79 | { | ||
| 80 | out << "[REGISTER DUMP]" << endl; | ||
| 81 | for(unsigned i = 0; i < getRegisterCount(); ++i) | ||
| 82 | { | ||
| 83 | out << "[" << std::setw(4) << std::setfill('0') << i << "] " | ||
| 84 | << m_registers[i] << endl; | ||
| 85 | } | ||
| 86 | } | ||
| 87 | #endif | ||
| 88 | |||
| 89 | /* vim: set et sw=2 ts=2: */ | ||
