summaryrefslogtreecommitdiffstats
path: root/ue3/mycpu/instructions.cpp
diff options
context:
space:
mode:
authormanuel <manuel@clan-server.at>2009-05-13 15:29:51 +0200
committermanuel <manuel@clan-server.at>2009-05-13 15:29:51 +0200
commit431bbac5a99abbccf33500e22aa353ec792eff94 (patch)
tree0649a2833c7ee5f6cbce145b719c104c7efe19df /ue3/mycpu/instructions.cpp
parent89e202f49b9857dcd3627fbc4e0262125d729bbc (diff)
downloadooprog-431bbac5a99abbccf33500e22aa353ec792eff94.tar.gz
ooprog-431bbac5a99abbccf33500e22aa353ec792eff94.tar.bz2
ooprog-431bbac5a99abbccf33500e22aa353ec792eff94.zip
* adding -Wno-long-long to all Makefiles
* adding execute operator to cinstruction * added labels map for better performance
Diffstat (limited to 'ue3/mycpu/instructions.cpp')
-rw-r--r--ue3/mycpu/instructions.cpp65
1 files changed, 4 insertions, 61 deletions
diff --git a/ue3/mycpu/instructions.cpp b/ue3/mycpu/instructions.cpp
index 609cd1c..a6ac611 100644
--- a/ue3/mycpu/instructions.cpp
+++ b/ue3/mycpu/instructions.cpp
@@ -5,6 +5,7 @@
5 * @date 10.05.2009 5 * @date 10.05.2009
6 */ 6 */
7 7
8#include <map>
8#include "instructions.h" 9#include "instructions.h"
9 10
10using namespace std; 11using namespace std;
@@ -210,27 +211,6 @@ void CInstructionTest::execute(CCPU *cpu)
210 211
211/*============================================================================*/ 212/*============================================================================*/
212 213
213void CInstructionLabel::compile(std::list<std::string>& params)
214{
215 if (params.size() != 1)
216 throw runtime_error("Invalid paramater count - must be 1");
217 string label = params.front();
218 params.pop_front();
219 if (label.length() < 2 || label[ label.length() - 1] != ':')
220 throw runtime_error("Label has invalid syntax");
221 m_label = label.substr(0, label.length() - 1);
222}
223
224/*----------------------------------------------------------------------------*/
225
226void CInstructionLabel::execute(CCPU *cpu)
227{
228 if (m_label.empty())
229 throw runtime_error("Empty label");
230}
231
232/*============================================================================*/
233
234void CInstructionJumpA::compile(std::list<std::string>& params) 214void CInstructionJumpA::compile(std::list<std::string>& params)
235{ 215{
236 if (params.size() != 1) 216 if (params.size() != 1)
@@ -245,18 +225,7 @@ void CInstructionJumpA::execute(CCPU *cpu)
245{ 225{
246 if (m_addr.empty()) 226 if (m_addr.empty())
247 throw runtime_error("Empty address"); 227 throw runtime_error("Empty address");
248 228 cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr);
249 const CProgram *progam = cpu->getProgram();
250 for(unsigned i = 0; i < progam->size(); i++)
251 {
252 if (progam->at(i)->isLabel() && progam->at(i)->getLabelName() == m_addr)
253 {
254 cpu->getRegisters()[ 0 ] = i;
255 return;
256 }
257 }
258
259 throw runtime_error("Unknown label '" + m_addr + "'");
260} 229}
261 230
262/*============================================================================*/ 231/*============================================================================*/
@@ -275,20 +244,7 @@ void CInstructionJumpZ::execute(CCPU *cpu)
275{ 244{
276 if (!cpu->getFlagZero()) 245 if (!cpu->getFlagZero())
277 return; 246 return;
278 if (m_addr.empty()) 247 cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr);
279 throw runtime_error("Empty address");
280
281 const CProgram *progam = cpu->getProgram();
282 for(unsigned i = 0; i < progam->size(); i++)
283 {
284 if (progam->at(i)->isLabel() && progam->at(i)->getLabelName() == m_addr)
285 {
286 cpu->getRegisters()[ 0 ] = i;
287 return;
288 }
289 }
290
291 throw runtime_error("Unknown label '" + m_addr + "'");
292} 248}
293 249
294/*============================================================================*/ 250/*============================================================================*/
@@ -307,20 +263,7 @@ void CInstructionJumpS::execute(CCPU *cpu)
307{ 263{
308 if (!cpu->getFlagSign()) 264 if (!cpu->getFlagSign())
309 return; 265 return;
310 if (m_addr.empty()) 266 cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr);
311 throw runtime_error("Empty address");
312
313 const CProgram *progam = cpu->getProgram();
314 for(unsigned i = 0; i < progam->size(); i++)
315 {
316 if (progam->at(i)->isLabel() && progam->at(i)->getLabelName() == m_addr)
317 {
318 cpu->getRegisters()[ 0 ] = i;
319 return;
320 }
321 }
322
323 throw runtime_error("Unknown label '" + m_addr + "'");
324} 267}
325 268
326/*============================================================================*/ 269/*============================================================================*/