From 45581d3d376e8deed84952cb838ae330549e5241 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 12 May 2009 23:18:17 +0200 Subject: my cpu design --- ue3/mycpu/ccpu.cpp | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 ue3/mycpu/ccpu.cpp (limited to 'ue3/mycpu/ccpu.cpp') 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 @@ +/** + * @module ccpu + * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) + * @brief TODO + * @date 10.05.2009 + */ + +#ifdef DEBUG +# include +# include +#endif +#include "ccpu.h" + +using namespace std; + +CCPU::CCPU(const unsigned cnt) + : m_regcnt(cnt), m_memory(NULL), m_program(NULL), m_flagzero(0), m_flagsign(0) +{ + m_registers = new CDat[cnt]; + for(unsigned i = 0; i < cnt; ++i) + m_registers[i] = 0; +} + +/*----------------------------------------------------------------------------*/ + +CCPU::~CCPU() +{ + delete[] m_registers; + m_registers = NULL; +} + +/*----------------------------------------------------------------------------*/ + +void CCPU::run() +{ + if (m_memory == NULL) + throw runtime_error("CPU has no memory"); + if (m_program == NULL) + throw runtime_error("CPU has no program to execute"); + if (m_regcnt == 0) + throw runtime_error("CPU has no registers"); + + bool run = true; + while(run) + { + unsigned pc = static_cast(m_registers[0]); + + /* end of the program reached */ + if (pc == m_program->size()) + return; + + /* pc is out of bound */ + if (pc > m_program->size()) + throw runtime_error("Programcounter is out of bound"); + + /* execute instruction */ + m_program->at(pc)->execute(this); + ++m_registers[0]; + } + + cout << "LALA" << endl; +} + +/*----------------------------------------------------------------------------*/ + +#if DEBUG +void CCPU::dumpRegisters(std::ostream& out) +{ + out << "[REGISTER DUMP]" << endl; + for(unsigned i = 0; i < getRegisterCount(); ++i) + { + out << "[" << std::setw(4) << std::setfill('0') << i << "] " + << m_registers[i] << endl; + } +} +#endif + +/* vim: set et sw=2 ts=2: */ -- cgit v1.2.3