summaryrefslogtreecommitdiffstats
path: root/ue3/mycpu/cmem.cpp
diff options
context:
space:
mode:
authorGünther Neuwirth <e0626638@student.tuwien.ac.at>2009-05-12 23:00:03 +0200
committerGünther Neuwirth <e0626638@student.tuwien.ac.at>2009-05-12 23:00:03 +0200
commitddf63e2765a6b225d18c59321595e69e1a126e0c (patch)
tree36336d5b3a1f0af0f9c2782351e30efe31bcf159 /ue3/mycpu/cmem.cpp
parente41c92320aef4a54b7f3b323f7302b180019b6d7 (diff)
downloadooprog-ddf63e2765a6b225d18c59321595e69e1a126e0c.tar.gz
ooprog-ddf63e2765a6b225d18c59321595e69e1a126e0c.tar.bz2
ooprog-ddf63e2765a6b225d18c59321595e69e1a126e0c.zip
adding tha rest
Diffstat (limited to 'ue3/mycpu/cmem.cpp')
-rw-r--r--ue3/mycpu/cmem.cpp70
1 files changed, 64 insertions, 6 deletions
diff --git a/ue3/mycpu/cmem.cpp b/ue3/mycpu/cmem.cpp
index ec60b56..165747b 100644
--- a/ue3/mycpu/cmem.cpp
+++ b/ue3/mycpu/cmem.cpp
@@ -37,13 +37,9 @@ CMem::~CMem()
37 37
38CDat& CMem::getRegister(const string reg) 38CDat& CMem::getRegister(const string reg)
39{ 39{
40 istringstream stmp (
41 reg.substr(reg.find_first_of("R") + 1, reg.size())
42 );
43 40
44 unsigned int regnr; 41 unsigned int regnr = getRegNr(reg);
45 stmp >> regnr; 42
46
47 // if (regnr >= MAX_REGISTER ) 43 // if (regnr >= MAX_REGISTER )
48 44
49 if (regnr >= m_registers.size()) 45 if (regnr >= m_registers.size())
@@ -55,6 +51,68 @@ CDat& CMem::getRegister(const string reg)
55 51
56 return m_registers[regnr]; 52 return m_registers[regnr];
57} 53}
54
55/*----------------------------------------------------------------------------*/
56
57string CMem::getMemAt(const std::string addr)
58{
59 int pos = getRegister(addr).getTypeValue();
60 /* open and read mem */
61 ifstream file(m_memfile.c_str(), ios::in);
62 string cur_line;
63 for (int i = 0; i <= pos; i++)
64 getline(file, cur_line);
65
66 file.close();
67 if (cur_line.empty())
68 return "";
69 trim(cur_line);
70 return cur_line;
71}
72void CMem::setMemAt(const std::string addr, const CDat& value)
73{
74 unsigned int pos = getRegister(addr).getTypeValue();
75 /* open and read mem */
76 ifstream ifile(m_memfile.c_str() );
77 vector<string> tmp;
78 unsigned int i = 0;
79 while (ifile.good())
80 {
81 string cur_line;
82 getline(ifile, cur_line);
83 if(!cur_line.empty())
84 tmp.push_back(cur_line);
85 i++;
86 }
87 ifile.close();
88 cout << tmp.size()<<"sasa"<<pos<<" "<<endl;
89
90 ofstream ofile(m_memfile.c_str(), fstream::trunc);
91 i = 0;
92 while (ofile.good() && i < tmp.size())
93 {
94 if (i != pos)
95 ofile << tmp[i] << endl;
96 else
97 ofile << value << endl;
98 cout << tmp[i]<< endl;
99 i++;
100 }
101 ofile.close();
102}
103/*----------------------------------------------------------------------------*/
104
105unsigned int CMem::getRegNr(const std::string reg)
106{
107 istringstream stmp (
108 reg.substr(reg.find_first_of("R") + 1, reg.size())
109 );
110
111 unsigned int regnr;
112 stmp >> regnr;
113 return regnr;
114}
115
58/*----------------------------------------------------------------------------*/ 116/*----------------------------------------------------------------------------*/
59 117
60#ifdef DEBUG 118#ifdef DEBUG