From 1a60d0c2a8eeef3b39ef276f0f3552552a1519b1 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 26 May 2009 14:49:37 +0200 Subject: adding ue4 (copy from ue3) --- ue4/mycpu/cinstruction.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 ue4/mycpu/cinstruction.cpp (limited to 'ue4/mycpu/cinstruction.cpp') diff --git a/ue4/mycpu/cinstruction.cpp b/ue4/mycpu/cinstruction.cpp new file mode 100644 index 0000000..a766015 --- /dev/null +++ b/ue4/mycpu/cinstruction.cpp @@ -0,0 +1,48 @@ +/** + * @module cinstruction + * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) + * @brief Abstract class for displays + * @date 13.05.2009 + */ + +#include +#include +#include +#include +#include "cinstruction.h" +#include "ccpu.h" + +using namespace std; + +const unsigned CInstruction::parseRegister(const std::string& str) +{ + unsigned reg; + if (str.length() < 2 || str[0] != 'r') + throw runtime_error("Invalid syntax of register"); + + try + { + reg = boost::lexical_cast(str.substr(1)); + } + catch(boost::bad_lexical_cast& ex) + { + throw runtime_error("Invalid syntax of register"); + } + + return reg; +} + +/*----------------------------------------------------------------------------*/ + +inline void CInstruction::checkRegister(CCPU *cpu, const unsigned regidx) +{ + assert(cpu != NULL); + if (regidx >= cpu->getRegisterCount()) + { + stringstream sstr; + sstr << "Register R" << regidx << " doesn't exist (out of bound)"; + throw runtime_error(sstr.str()); + } +} + +/* vim: set et sw=2 ts=2: */ -- cgit v1.2.3