diff options
Diffstat (limited to 'ue3/mycpu/instructions.cpp')
| -rw-r--r-- | ue3/mycpu/instructions.cpp | 65 |
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 | ||
| 10 | using namespace std; | 11 | using namespace std; |
| @@ -210,27 +211,6 @@ void CInstructionTest::execute(CCPU *cpu) | |||
| 210 | 211 | ||
| 211 | /*============================================================================*/ | 212 | /*============================================================================*/ |
| 212 | 213 | ||
| 213 | void 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 | |||
| 226 | void CInstructionLabel::execute(CCPU *cpu) | ||
| 227 | { | ||
| 228 | if (m_label.empty()) | ||
| 229 | throw runtime_error("Empty label"); | ||
| 230 | } | ||
| 231 | |||
| 232 | /*============================================================================*/ | ||
| 233 | |||
| 234 | void CInstructionJumpA::compile(std::list<std::string>& params) | 214 | void 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 | /*============================================================================*/ |
