diff options
Diffstat (limited to 'ue4/mycpu/mycpu.cpp')
| -rw-r--r-- | ue4/mycpu/mycpu.cpp | 37 |
1 files changed, 32 insertions, 5 deletions
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 @@ | |||
| 17 | #include <stdexcept> | 17 | #include <stdexcept> |
| 18 | #include <stdlib.h> | 18 | #include <stdlib.h> |
| 19 | #include "cdat.h" | 19 | #include "cdat.h" |
| 20 | #include "cdatn.h" | ||
| 21 | #include "cdatset.h" | ||
| 20 | #include "cmem.h" | 22 | #include "cmem.h" |
| 21 | #include "cprogram.h" | 23 | #include "cprogram.h" |
| 22 | #include "ccpu.h" | 24 | #include "ccpu.h" |
| @@ -73,7 +75,32 @@ int main(int argc, char* argv[]) | |||
| 73 | } | 75 | } |
| 74 | 76 | ||
| 75 | /* create memory and optionally initialize memory from file */ | 77 | /* create memory and optionally initialize memory from file */ |
| 76 | CMem<CDat<int> > memory; | 78 | |
| 79 | CMem *memory = NULL; | ||
| 80 | if (vm.count("format")) | ||
| 81 | { | ||
| 82 | string format(vm["format"].as<string>()); | ||
| 83 | if(format == "s") | ||
| 84 | memory = new CMem<CDatSet<int> >(); | ||
| 85 | else | ||
| 86 | { | ||
| 87 | try | ||
| 88 | { | ||
| 89 | int bc = boost::lexical_cast<int>(format); | ||
| 90 | if (bc > 1 && bc < 33) | ||
| 91 | memory = new CMem<CDatN<int> >(); | ||
| 92 | } | ||
| 93 | catch(boost::bad_lexical_cast& ex) | ||
| 94 | { | ||
| 95 | std::stringstream sstr; | ||
| 96 | sstr << "Illegal format: (" << format << "): " << ex.what(); | ||
| 97 | throw std::runtime_error(sstr.str()); | ||
| 98 | } | ||
| 99 | } | ||
| 100 | } | ||
| 101 | else | ||
| 102 | |||
| 103 | |||
| 77 | if (vm.count("memory")) | 104 | if (vm.count("memory")) |
| 78 | { | 105 | { |
| 79 | string memoryfile(vm["memory"].as<string>()); | 106 | string memoryfile(vm["memory"].as<string>()); |
| @@ -86,7 +113,7 @@ int main(int argc, char* argv[]) | |||
| 86 | 113 | ||
| 87 | try | 114 | try |
| 88 | { | 115 | { |
| 89 | memory.initialize(file); | 116 | memory->initialize(file); |
| 90 | file.close(); | 117 | file.close(); |
| 91 | } | 118 | } |
| 92 | catch(runtime_error& ex) | 119 | catch(runtime_error& ex) |
| @@ -98,7 +125,7 @@ int main(int argc, char* argv[]) | |||
| 98 | } | 125 | } |
| 99 | 126 | ||
| 100 | #if DEBUG | 127 | #if DEBUG |
| 101 | memory.dump(cerr); | 128 | memory->dump(cerr); |
| 102 | #endif | 129 | #endif |
| 103 | } | 130 | } |
| 104 | 131 | ||
| @@ -134,7 +161,7 @@ int main(int argc, char* argv[]) | |||
| 134 | try | 161 | try |
| 135 | { | 162 | { |
| 136 | CCPU<CDat<int> > cpu(256); | 163 | CCPU<CDat<int> > cpu(256); |
| 137 | cpu.setMemory(&memory); | 164 | cpu.setMemory(memory); |
| 138 | cpu.setProgram(&program); | 165 | cpu.setProgram(&program); |
| 139 | cpu.run(); | 166 | cpu.run(); |
| 140 | #if DEBUG | 167 | #if DEBUG |
| @@ -146,7 +173,7 @@ int main(int argc, char* argv[]) | |||
| 146 | cerr << me << ": Error while executing program:" << endl | 173 | cerr << me << ": Error while executing program:" << endl |
| 147 | << " " << ex.what() << endl; | 174 | << " " << ex.what() << endl; |
| 148 | #if DEBUG | 175 | #if DEBUG |
| 149 | memory.dump(cerr); | 176 | memory->dump(cerr); |
| 150 | #endif | 177 | #endif |
| 151 | return 1; | 178 | return 1; |
| 152 | } | 179 | } |
