3 #include <boost/tokenizer.hpp>
4 #include <boost/program_options.hpp>
5 #include <boost/lexical_cast.hpp>
11 #include "CInstrFactory.hpp"
12 #include "uint32_from_hex.hpp"
16 using boost::lexical_cast;
17 using boost::bad_lexical_cast;
21 using namespace boost::program_options;
22 namespace po = boost::program_options;
26 int main(int argc, char* argv[])
31 po::options_description desc("Allowed options");
33 ("help,h","produce help message")
34 ("file,f",value<string>(), "input file")
37 po::positional_options_description p;
41 po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
44 if(vm.count("help")) {
49 if(vm.count("file")) {
51 cout << "going to open file " << vm["file"].as<string>() << endl;
53 inFile.open(vm["file"].as<string>(), ios::in);
55 cerr << "Error opening file " << vm["file"].as<string>() << endl;
60 cout << "not input file given!" << endl << endl;
65 catch(std::exception& ex) {
66 cout << ex.what() << endl;
70 string dir = "./instr/";
72 map<short, Iinstr*> instr;
74 CInstrFactory instrFab;
76 instrFab.loadLibsIntoMap(instr, dir);
78 catch(std::bad_alloc& e) {
79 cerr << progName << ": bad_alloc caught " << e.what() << endl;
82 catch(std::string& s) {
83 cerr << progName << ": " << s << endl;
88 CCpu cpu(16,1000,1000);
95 boost::char_separator<char> sep(";", "", boost::keep_empty_tokens);
96 boost::tokenizer<boost::char_separator<char> > tokens(str, sep);
98 while(getline(inFile, str)) {
103 for(auto tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter) {
104 if(tok_iter == tokens.begin()) {
106 type = lexical_cast<int>(*tok_iter);
110 catch(bad_lexical_cast &) {
119 addr = lexical_cast<uint32_from_hex>(*tok_iter);
121 catch(bad_lexical_cast& e) {
122 cerr << e.what() << endl;
126 else if(count == 2) {
128 CDat data = lexical_cast<uint32_from_hex>(*tok_iter);
129 cpu.setRAM(addr, data);
131 catch(bad_lexical_cast& e) {
132 cerr << e.what() << endl;
140 addr = lexical_cast<uint32_from_hex>(*tok_iter);
142 catch(bad_lexical_cast& e) {
143 cerr << e.what() << endl;
147 else if(count == 2) {
148 Iinstr *pi = disasm.decode(*tok_iter);
149 cpu.setProg(addr, pi);
154 cerr << "ignoring labels and comments for now" << endl;
156 cerr << "i was to lazy to implement the other format types for now" << endl;
166 for(int i = 0; i <= 32; i += 4) {
167 Iinstr *pinstr = cpu.getProg(i);
169 cout << i << " : " << std::hex << i << std::dec << " " << pinstr->toString() << endl;
172 cout << "Null at " << i << " : " << std::hex << i << endl;
176 for(int i = 0; i <= 32; i += 4) {
177 CDat data = cpu.getRAM(i);
178 cout << i << " : " << std::hex << i << std::dec << " " << data << endl;
181 cpu.setRegister(1, 4);
182 cpu.setRegister(2, 0);
188 // following: job of the bootloader
191 //set return to nowhere for ret
194 for(int i = 0; ; i++) {
197 cout << " reg0: " << cpu.getRegister(0) << " reg1: " << cpu.getRegister(1);
198 cout << " reg2: " << cpu.getRegister(2) << " reg3: " << cpu.getRegister(3);
199 cout << " reg4: " << cpu.getRegister(4) << " reg5: " << cpu.getRegister(5);
200 cout << endl << endl;