From 064eaaed391835d0e0d057466f6f552e43e79bd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Neuwirth?= Date: Wed, 27 May 2009 16:43:43 +0200 Subject: add cdatset --- ue4/mycpu/mycpu.cpp | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'ue4/mycpu/mycpu.cpp') diff --git a/ue4/mycpu/mycpu.cpp b/ue4/mycpu/mycpu.cpp index 6c9f71a..2d73177 100644 --- a/ue4/mycpu/mycpu.cpp +++ b/ue4/mycpu/mycpu.cpp @@ -17,6 +17,8 @@ #include #include #include "cdat.h" +#include "cdatn.h" +#include "cdatset.h" #include "cmem.h" #include "cprogram.h" #include "ccpu.h" @@ -73,7 +75,32 @@ int main(int argc, char* argv[]) } /* create memory and optionally initialize memory from file */ - CMem > memory; + + CMem *memory = NULL; + if (vm.count("format")) + { + string format(vm["format"].as()); + if(format == "s") + memory = new CMem >(); + else + { + try + { + int bc = boost::lexical_cast(format); + if (bc > 1 && bc < 33) + memory = new CMem >(); + } + catch(boost::bad_lexical_cast& ex) + { + std::stringstream sstr; + sstr << "Illegal format: (" << format << "): " << ex.what(); + throw std::runtime_error(sstr.str()); + } + } + } + else + + if (vm.count("memory")) { string memoryfile(vm["memory"].as()); @@ -86,7 +113,7 @@ int main(int argc, char* argv[]) try { - memory.initialize(file); + memory->initialize(file); file.close(); } catch(runtime_error& ex) @@ -98,7 +125,7 @@ int main(int argc, char* argv[]) } #if DEBUG - memory.dump(cerr); + memory->dump(cerr); #endif } @@ -134,7 +161,7 @@ int main(int argc, char* argv[]) try { CCPU > cpu(256); - cpu.setMemory(&memory); + cpu.setMemory(memory); cpu.setProgram(&program); cpu.run(); #if DEBUG @@ -146,7 +173,7 @@ int main(int argc, char* argv[]) cerr << me << ": Error while executing program:" << endl << " " << ex.what() << endl; #if DEBUG - memory.dump(cerr); + memory->dump(cerr); #endif return 1; } -- cgit v1.2.3