diff options
Diffstat (limited to 'ue4/mycpu/instructions.h')
| -rw-r--r-- | ue4/mycpu/instructions.h | 157 |
1 files changed, 83 insertions, 74 deletions
diff --git a/ue4/mycpu/instructions.h b/ue4/mycpu/instructions.h index 3f2fd51..fd547aa 100644 --- a/ue4/mycpu/instructions.h +++ b/ue4/mycpu/instructions.h | |||
| @@ -19,9 +19,9 @@ | |||
| 19 | * Syntax: inc R1 | 19 | * Syntax: inc R1 |
| 20 | * (R1++) | 20 | * (R1++) |
| 21 | */ | 21 | */ |
| 22 | template<class T=CDat<int>, int width=0> | 22 | template <class T> |
| 23 | class CInstructionInc | 23 | class CInstructionInc |
| 24 | : public CInstruction<T> | 24 | : public CInstruction<T> |
| 25 | { | 25 | { |
| 26 | typedef CInstruction<T> super; | 26 | typedef CInstruction<T> super; |
| 27 | 27 | ||
| @@ -45,22 +45,21 @@ class CInstructionInc | |||
| 45 | 45 | ||
| 46 | /*----------------------------------------------------------------------------*/ | 46 | /*----------------------------------------------------------------------------*/ |
| 47 | 47 | ||
| 48 | template<class T=CDat<int>, int width=0> | 48 | template <class T> |
| 49 | void CInstructionInc<T>::compile(std::list<std::string>& params) | 49 | void CInstructionInc<T>::compile(std::list<std::string>& params) |
| 50 | { | 50 | { |
| 51 | if (params.size() != 1) | 51 | if (params.size() != 1) |
| 52 | throw std::runtime_error("Invalid paramater count - must be 1"); | 52 | throw CInstructionError("Invalid paramater count - must be 1"); |
| 53 | m_regidx1 = super::parseRegister(params.front()); | 53 | m_regidx1 = super::parseRegister(params.front()); |
| 54 | params.pop_front(); | 54 | params.pop_front(); |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | /*----------------------------------------------------------------------------*/ | 57 | /*----------------------------------------------------------------------------*/ |
| 58 | 58 | ||
| 59 | template<class T=CDat<int>, int width=0> | 59 | template <class T> |
| 60 | void CInstructionInc<T>::execute(CCPU<T> *cpu) | 60 | void CInstructionInc<T>::execute(CCPU<T> *cpu) |
| 61 | { | 61 | { |
| 62 | assert(cpu != NULL); | 62 | assert(cpu != NULL); |
| 63 | assert(cpu->getRegisters() != NULL); | ||
| 64 | super::checkRegister(cpu, m_regidx1); | 63 | super::checkRegister(cpu, m_regidx1); |
| 65 | cpu->getRegisters()[ m_regidx1 ]++; | 64 | cpu->getRegisters()[ m_regidx1 ]++; |
| 66 | } | 65 | } |
| @@ -74,7 +73,7 @@ void CInstructionInc<T>::execute(CCPU<T> *cpu) | |||
| 74 | * Syntax: dec R1 | 73 | * Syntax: dec R1 |
| 75 | * (R1--) | 74 | * (R1--) |
| 76 | */ | 75 | */ |
| 77 | template<class T=CDat<int>, int width=0> | 76 | template <class T> |
| 78 | class CInstructionDec | 77 | class CInstructionDec |
| 79 | : public CInstruction<T> | 78 | : public CInstruction<T> |
| 80 | { | 79 | { |
| @@ -100,22 +99,21 @@ class CInstructionDec | |||
| 100 | 99 | ||
| 101 | /*----------------------------------------------------------------------------*/ | 100 | /*----------------------------------------------------------------------------*/ |
| 102 | 101 | ||
| 103 | template<class T=CDat<int>, int width=0> | 102 | template <class T> |
| 104 | void CInstructionDec<T>::compile(std::list<std::string>& params) | 103 | void CInstructionDec<T>::compile(std::list<std::string>& params) |
| 105 | { | 104 | { |
| 106 | if (params.size() != 1) | 105 | if (params.size() != 1) |
| 107 | throw std::runtime_error("Invalid paramater count - must be 1"); | 106 | throw CInstructionError("Invalid paramater count - must be 1"); |
| 108 | m_regidx1 = super::parseRegister(params.front()); | 107 | m_regidx1 = super::parseRegister(params.front()); |
| 109 | params.pop_front(); | 108 | params.pop_front(); |
| 110 | } | 109 | } |
| 111 | 110 | ||
| 112 | /*----------------------------------------------------------------------------*/ | 111 | /*----------------------------------------------------------------------------*/ |
| 113 | 112 | ||
| 114 | template<class T=CDat<int>, int width=0> | 113 | template <class T> |
| 115 | void CInstructionDec<T>::execute(CCPU<T> *cpu) | 114 | void CInstructionDec<T>::execute(CCPU<T> *cpu) |
| 116 | { | 115 | { |
| 117 | assert(cpu != NULL); | 116 | assert(cpu != NULL); |
| 118 | assert(cpu->getRegisters() != NULL); | ||
| 119 | super::checkRegister(cpu, m_regidx1); | 117 | super::checkRegister(cpu, m_regidx1); |
| 120 | cpu->getRegisters()[ m_regidx1 ]--; | 118 | cpu->getRegisters()[ m_regidx1 ]--; |
| 121 | } | 119 | } |
| @@ -129,7 +127,7 @@ void CInstructionDec<T>::execute(CCPU<T> *cpu) | |||
| 129 | * Syntax: add R1, R2, R3 | 127 | * Syntax: add R1, R2, R3 |
| 130 | * (R1 = R2 + R3) | 128 | * (R1 = R2 + R3) |
| 131 | */ | 129 | */ |
| 132 | template<class T=CDat<int>, int width=0> | 130 | template <class T> |
| 133 | class CInstructionAdd | 131 | class CInstructionAdd |
| 134 | : public CInstruction<T> | 132 | : public CInstruction<T> |
| 135 | { | 133 | { |
| @@ -159,11 +157,11 @@ class CInstructionAdd | |||
| 159 | 157 | ||
| 160 | /*----------------------------------------------------------------------------*/ | 158 | /*----------------------------------------------------------------------------*/ |
| 161 | 159 | ||
| 162 | template<class T=CDat<int>, int width=0> | 160 | template <class T> |
| 163 | void CInstructionAdd<T>::compile(std::list<std::string>& params) | 161 | void CInstructionAdd<T>::compile(std::list<std::string>& params) |
| 164 | { | 162 | { |
| 165 | if (params.size() != 3) | 163 | if (params.size() != 3) |
| 166 | throw std::runtime_error("Invalid paramater count - must be 3"); | 164 | throw CInstructionError("Invalid paramater count - must be 3"); |
| 167 | m_regidx1 = super::parseRegister(params.front()); | 165 | m_regidx1 = super::parseRegister(params.front()); |
| 168 | params.pop_front(); | 166 | params.pop_front(); |
| 169 | m_regidx2 = super::parseRegister(params.front()); | 167 | m_regidx2 = super::parseRegister(params.front()); |
| @@ -174,11 +172,10 @@ void CInstructionAdd<T>::compile(std::list<std::string>& params) | |||
| 174 | 172 | ||
| 175 | /*----------------------------------------------------------------------------*/ | 173 | /*----------------------------------------------------------------------------*/ |
| 176 | 174 | ||
| 177 | template<class T=CDat<int>, int width=0> | 175 | template <class T> |
| 178 | void CInstructionAdd<T>::execute(CCPU<T> *cpu) | 176 | void CInstructionAdd<T>::execute(CCPU<T> *cpu) |
| 179 | { | 177 | { |
| 180 | assert(cpu != NULL); | 178 | assert(cpu != NULL); |
| 181 | assert(cpu->getRegisters() != NULL); | ||
| 182 | super::checkRegister(cpu, m_regidx1); | 179 | super::checkRegister(cpu, m_regidx1); |
| 183 | super::checkRegister(cpu, m_regidx2); | 180 | super::checkRegister(cpu, m_regidx2); |
| 184 | super::checkRegister(cpu, m_regidx3); | 181 | super::checkRegister(cpu, m_regidx3); |
| @@ -195,7 +192,7 @@ void CInstructionAdd<T>::execute(CCPU<T> *cpu) | |||
| 195 | * Syntax: sub R1, R2, R3 | 192 | * Syntax: sub R1, R2, R3 |
| 196 | * (R1 = R2 - R3) | 193 | * (R1 = R2 - R3) |
| 197 | */ | 194 | */ |
| 198 | template<class T=CDat<int>, int width=0> | 195 | template <class T> |
| 199 | class CInstructionSub | 196 | class CInstructionSub |
| 200 | : public CInstruction<T> | 197 | : public CInstruction<T> |
| 201 | { | 198 | { |
| @@ -225,11 +222,11 @@ class CInstructionSub | |||
| 225 | 222 | ||
| 226 | /*----------------------------------------------------------------------------*/ | 223 | /*----------------------------------------------------------------------------*/ |
| 227 | 224 | ||
| 228 | template<class T=CDat<int>, int width=0> | 225 | template <class T> |
| 229 | void CInstructionSub<T>::compile(std::list<std::string>& params) | 226 | void CInstructionSub<T>::compile(std::list<std::string>& params) |
| 230 | { | 227 | { |
| 231 | if (params.size() != 3) | 228 | if (params.size() != 3) |
| 232 | throw std::runtime_error("Invalid paramater count - must be 3"); | 229 | throw CInstructionError("Invalid paramater count - must be 3"); |
| 233 | m_regidx1 = super::parseRegister(params.front()); | 230 | m_regidx1 = super::parseRegister(params.front()); |
| 234 | params.pop_front(); | 231 | params.pop_front(); |
| 235 | m_regidx2 = super::parseRegister(params.front()); | 232 | m_regidx2 = super::parseRegister(params.front()); |
| @@ -240,11 +237,10 @@ void CInstructionSub<T>::compile(std::list<std::string>& params) | |||
| 240 | 237 | ||
| 241 | /*----------------------------------------------------------------------------*/ | 238 | /*----------------------------------------------------------------------------*/ |
| 242 | 239 | ||
| 243 | template<class T=CDat<int>, int width=0> | 240 | template <class T> |
| 244 | void CInstructionSub<T>::execute(CCPU<T> *cpu) | 241 | void CInstructionSub<T>::execute(CCPU<T> *cpu) |
| 245 | { | 242 | { |
| 246 | assert(cpu != NULL); | 243 | assert(cpu != NULL); |
| 247 | assert(cpu->getRegisters() != NULL); | ||
| 248 | super::checkRegister(cpu, m_regidx1); | 244 | super::checkRegister(cpu, m_regidx1); |
| 249 | super::checkRegister(cpu, m_regidx2); | 245 | super::checkRegister(cpu, m_regidx2); |
| 250 | super::checkRegister(cpu, m_regidx3); | 246 | super::checkRegister(cpu, m_regidx3); |
| @@ -261,7 +257,7 @@ void CInstructionSub<T>::execute(CCPU<T> *cpu) | |||
| 261 | * Syntax: mul R1, R2, R3 | 257 | * Syntax: mul R1, R2, R3 |
| 262 | * (R1 = R2 * R3) | 258 | * (R1 = R2 * R3) |
| 263 | */ | 259 | */ |
| 264 | template<class T=CDat<int>, int width=0> | 260 | template <class T> |
| 265 | class CInstructionMul | 261 | class CInstructionMul |
| 266 | : public CInstruction<T> | 262 | : public CInstruction<T> |
| 267 | { | 263 | { |
| @@ -291,11 +287,11 @@ class CInstructionMul | |||
| 291 | 287 | ||
| 292 | /*----------------------------------------------------------------------------*/ | 288 | /*----------------------------------------------------------------------------*/ |
| 293 | 289 | ||
| 294 | template<class T=CDat<int>, int width=0> | 290 | template <class T> |
| 295 | void CInstructionMul<T>::compile(std::list<std::string>& params) | 291 | void CInstructionMul<T>::compile(std::list<std::string>& params) |
| 296 | { | 292 | { |
| 297 | if (params.size() != 3) | 293 | if (params.size() != 3) |
| 298 | throw std::runtime_error("Invalid paramater count - must be 3"); | 294 | throw CInstructionError("Invalid paramater count - must be 3"); |
| 299 | m_regidx1 = super::parseRegister(params.front()); | 295 | m_regidx1 = super::parseRegister(params.front()); |
| 300 | params.pop_front(); | 296 | params.pop_front(); |
| 301 | m_regidx2 = super::parseRegister(params.front()); | 297 | m_regidx2 = super::parseRegister(params.front()); |
| @@ -306,7 +302,7 @@ void CInstructionMul<T>::compile(std::list<std::string>& params) | |||
| 306 | 302 | ||
| 307 | /*----------------------------------------------------------------------------*/ | 303 | /*----------------------------------------------------------------------------*/ |
| 308 | 304 | ||
| 309 | template<class T=CDat<int>, int width=0> | 305 | template <class T> |
| 310 | void CInstructionMul<T>::execute(CCPU<T> *cpu) | 306 | void CInstructionMul<T>::execute(CCPU<T> *cpu) |
| 311 | { | 307 | { |
| 312 | super::checkRegister(cpu, m_regidx1); | 308 | super::checkRegister(cpu, m_regidx1); |
| @@ -325,7 +321,7 @@ void CInstructionMul<T>::execute(CCPU<T> *cpu) | |||
| 325 | * Syntax: div R1, R2, R3 | 321 | * Syntax: div R1, R2, R3 |
| 326 | * (R1 = R2 / R3) | 322 | * (R1 = R2 / R3) |
| 327 | */ | 323 | */ |
| 328 | template<class T=CDat<int>, int width=0> | 324 | template <class T> |
| 329 | class CInstructionDiv | 325 | class CInstructionDiv |
| 330 | : public CInstruction<T> | 326 | : public CInstruction<T> |
| 331 | { | 327 | { |
| @@ -355,11 +351,11 @@ class CInstructionDiv | |||
| 355 | 351 | ||
| 356 | /*----------------------------------------------------------------------------*/ | 352 | /*----------------------------------------------------------------------------*/ |
| 357 | 353 | ||
| 358 | template<class T=CDat<int>, int width=0> | 354 | template <class T> |
| 359 | void CInstructionDiv<T>::compile(std::list<std::string>& params) | 355 | void CInstructionDiv<T>::compile(std::list<std::string>& params) |
| 360 | { | 356 | { |
| 361 | if (params.size() != 3) | 357 | if (params.size() != 3) |
| 362 | throw std::runtime_error("Invalid paramater count - must be 3"); | 358 | throw CInstructionError("Invalid paramater count - must be 3"); |
| 363 | m_regidx1 = super::parseRegister(params.front()); | 359 | m_regidx1 = super::parseRegister(params.front()); |
| 364 | params.pop_front(); | 360 | params.pop_front(); |
| 365 | m_regidx2 = super::parseRegister(params.front()); | 361 | m_regidx2 = super::parseRegister(params.front()); |
| @@ -370,11 +366,10 @@ void CInstructionDiv<T>::compile(std::list<std::string>& params) | |||
| 370 | 366 | ||
| 371 | /*----------------------------------------------------------------------------*/ | 367 | /*----------------------------------------------------------------------------*/ |
| 372 | 368 | ||
| 373 | template<class T=CDat<int>, int width=0> | 369 | template <class T> |
| 374 | void CInstructionDiv<T>::execute(CCPU<T> *cpu) | 370 | void CInstructionDiv<T>::execute(CCPU<T> *cpu) |
| 375 | { | 371 | { |
| 376 | assert(cpu != NULL); | 372 | assert(cpu != NULL); |
| 377 | assert(cpu->getRegisters() != NULL); | ||
| 378 | super::checkRegister(cpu, m_regidx1); | 373 | super::checkRegister(cpu, m_regidx1); |
| 379 | super::checkRegister(cpu, m_regidx2); | 374 | super::checkRegister(cpu, m_regidx2); |
| 380 | super::checkRegister(cpu, m_regidx3); | 375 | super::checkRegister(cpu, m_regidx3); |
| @@ -391,7 +386,7 @@ void CInstructionDiv<T>::execute(CCPU<T> *cpu) | |||
| 391 | * Syntax: load R1, R2 | 386 | * Syntax: load R1, R2 |
| 392 | * (R1 = memory[R2]) | 387 | * (R1 = memory[R2]) |
| 393 | */ | 388 | */ |
| 394 | template<class T=CDat<int>, int width=0> | 389 | template <class T> |
| 395 | class CInstructionLoad | 390 | class CInstructionLoad |
| 396 | : public CInstruction<T> | 391 | : public CInstruction<T> |
| 397 | { | 392 | { |
| @@ -419,11 +414,11 @@ class CInstructionLoad | |||
| 419 | 414 | ||
| 420 | /*----------------------------------------------------------------------------*/ | 415 | /*----------------------------------------------------------------------------*/ |
| 421 | 416 | ||
| 422 | template<class T=CDat<int>, int width=0> | 417 | template <class T> |
| 423 | void CInstructionLoad<T>::compile(std::list<std::string>& params) | 418 | void CInstructionLoad<T>::compile(std::list<std::string>& params) |
| 424 | { | 419 | { |
| 425 | if (params.size() != 2) | 420 | if (params.size() != 2) |
| 426 | throw std::runtime_error("Invalid paramater count - must be 2"); | 421 | throw CInstructionError("Invalid paramater count - must be 2"); |
| 427 | m_regidx1 = super::parseRegister(params.front()); | 422 | m_regidx1 = super::parseRegister(params.front()); |
| 428 | params.pop_front(); | 423 | params.pop_front(); |
| 429 | m_regidx2 = super::parseRegister(params.front()); | 424 | m_regidx2 = super::parseRegister(params.front()); |
| @@ -432,11 +427,10 @@ void CInstructionLoad<T>::compile(std::list<std::string>& params) | |||
| 432 | 427 | ||
| 433 | /*----------------------------------------------------------------------------*/ | 428 | /*----------------------------------------------------------------------------*/ |
| 434 | 429 | ||
| 435 | template<class T=CDat<int>, int width=0> | 430 | template <class T> |
| 436 | void CInstructionLoad<T>::execute(CCPU<T> *cpu) | 431 | void CInstructionLoad<T>::execute(CCPU<T> *cpu) |
| 437 | { | 432 | { |
| 438 | assert(cpu != NULL); | 433 | assert(cpu != NULL); |
| 439 | assert(cpu->getRegisters() != NULL); | ||
| 440 | assert(cpu->getMemory() != NULL); | 434 | assert(cpu->getMemory() != NULL); |
| 441 | super::checkRegister(cpu, m_regidx1); | 435 | super::checkRegister(cpu, m_regidx1); |
| 442 | super::checkRegister(cpu, m_regidx2); | 436 | super::checkRegister(cpu, m_regidx2); |
| @@ -453,7 +447,7 @@ void CInstructionLoad<T>::execute(CCPU<T> *cpu) | |||
| 453 | * Syntax: store R1, R2 | 447 | * Syntax: store R1, R2 |
| 454 | * (memory[R2] = R1) | 448 | * (memory[R2] = R1) |
| 455 | */ | 449 | */ |
| 456 | template<class T=CDat<int>, int width=0> | 450 | template <class T> |
| 457 | class CInstructionStore | 451 | class CInstructionStore |
| 458 | : public CInstruction<T> | 452 | : public CInstruction<T> |
| 459 | { | 453 | { |
| @@ -481,11 +475,11 @@ class CInstructionStore | |||
| 481 | 475 | ||
| 482 | /*----------------------------------------------------------------------------*/ | 476 | /*----------------------------------------------------------------------------*/ |
| 483 | 477 | ||
| 484 | template<class T=CDat<int>, int width=0> | 478 | template <class T> |
| 485 | void CInstructionStore<T>::compile(std::list<std::string>& params) | 479 | void CInstructionStore<T>::compile(std::list<std::string>& params) |
| 486 | { | 480 | { |
| 487 | if (params.size() != 2) | 481 | if (params.size() != 2) |
| 488 | throw std::runtime_error("Invalid paramater count - must be 2"); | 482 | throw CInstructionError("Invalid paramater count - must be 2"); |
| 489 | m_regidx1 = super::parseRegister(params.front()); | 483 | m_regidx1 = super::parseRegister(params.front()); |
| 490 | params.pop_front(); | 484 | params.pop_front(); |
| 491 | m_regidx2 = super::parseRegister(params.front()); | 485 | m_regidx2 = super::parseRegister(params.front()); |
| @@ -494,11 +488,10 @@ void CInstructionStore<T>::compile(std::list<std::string>& params) | |||
| 494 | 488 | ||
| 495 | /*----------------------------------------------------------------------------*/ | 489 | /*----------------------------------------------------------------------------*/ |
| 496 | 490 | ||
| 497 | template<class T=CDat<int>, int width=0> | 491 | template <class T> |
| 498 | void CInstructionStore<T>::execute(CCPU<T> *cpu) | 492 | void CInstructionStore<T>::execute(CCPU<T> *cpu) |
| 499 | { | 493 | { |
| 500 | assert(cpu != NULL); | 494 | assert(cpu != NULL); |
| 501 | assert(cpu->getRegisters() != NULL); | ||
| 502 | assert(cpu->getMemory() != NULL); | 495 | assert(cpu->getMemory() != NULL); |
| 503 | super::checkRegister(cpu, m_regidx1); | 496 | super::checkRegister(cpu, m_regidx1); |
| 504 | super::checkRegister(cpu, m_regidx2); | 497 | super::checkRegister(cpu, m_regidx2); |
| @@ -515,7 +508,7 @@ void CInstructionStore<T>::execute(CCPU<T> *cpu) | |||
| 515 | * Syntax: test R1 | 508 | * Syntax: test R1 |
| 516 | * (R1 == 0: zeroflag: true, R1 < 0: signflag: true) | 509 | * (R1 == 0: zeroflag: true, R1 < 0: signflag: true) |
| 517 | */ | 510 | */ |
| 518 | template<class T=CDat<int>, int width=0> | 511 | template <class T> |
| 519 | class CInstructionTest | 512 | class CInstructionTest |
| 520 | : public CInstruction<T> | 513 | : public CInstruction<T> |
| 521 | { | 514 | { |
| @@ -541,22 +534,21 @@ class CInstructionTest | |||
| 541 | 534 | ||
| 542 | /*----------------------------------------------------------------------------*/ | 535 | /*----------------------------------------------------------------------------*/ |
| 543 | 536 | ||
| 544 | template<class T=CDat<int>, int width=0> | 537 | template <class T> |
| 545 | void CInstructionTest<T>::compile(std::list<std::string>& params) | 538 | void CInstructionTest<T>::compile(std::list<std::string>& params) |
| 546 | { | 539 | { |
| 547 | if (params.size() != 1) | 540 | if (params.size() != 1) |
| 548 | throw std::runtime_error("Invalid paramater count - must be 1"); | 541 | throw CInstructionError("Invalid paramater count - must be 1"); |
| 549 | m_regidx1 = super::parseRegister(params.front()); | 542 | m_regidx1 = super::parseRegister(params.front()); |
| 550 | params.pop_front(); | 543 | params.pop_front(); |
| 551 | } | 544 | } |
| 552 | 545 | ||
| 553 | /*----------------------------------------------------------------------------*/ | 546 | /*----------------------------------------------------------------------------*/ |
| 554 | 547 | ||
| 555 | template<class T=CDat<int>, int width=0> | 548 | template <class T> |
| 556 | void CInstructionTest<T>::execute(CCPU<T> *cpu) | 549 | void CInstructionTest<T>::execute(CCPU<T> *cpu) |
| 557 | { | 550 | { |
| 558 | assert(cpu != NULL); | 551 | assert(cpu != NULL); |
| 559 | assert(cpu->getRegisters() != NULL); | ||
| 560 | super::checkRegister(cpu, m_regidx1); | 552 | super::checkRegister(cpu, m_regidx1); |
| 561 | if (cpu->getRegisters()[ m_regidx1 ] == T(0)) | 553 | if (cpu->getRegisters()[ m_regidx1 ] == T(0)) |
| 562 | cpu->setFlagZero(true); | 554 | cpu->setFlagZero(true); |
| @@ -572,7 +564,7 @@ void CInstructionTest<T>::execute(CCPU<T> *cpu) | |||
| 572 | * Implementation of assembler command "label" | 564 | * Implementation of assembler command "label" |
| 573 | * Syntax: label name: | 565 | * Syntax: label name: |
| 574 | */ | 566 | */ |
| 575 | template<class T=CDat<int>, int width=0> | 567 | template <class T> |
| 576 | class CInstructionLabel | 568 | class CInstructionLabel |
| 577 | : public CInstruction<T> | 569 | : public CInstruction<T> |
| 578 | { | 570 | { |
| @@ -604,7 +596,7 @@ class CInstructionLabel | |||
| 604 | * Syntax: jumpa labelname | 596 | * Syntax: jumpa labelname |
| 605 | * (jump to labelname) | 597 | * (jump to labelname) |
| 606 | */ | 598 | */ |
| 607 | template<class T=CDat<int>, int width=0> | 599 | template <class T> |
| 608 | class CInstructionJumpA | 600 | class CInstructionJumpA |
| 609 | : public CInstruction<T> | 601 | : public CInstruction<T> |
| 610 | { | 602 | { |
| @@ -630,26 +622,32 @@ class CInstructionJumpA | |||
| 630 | 622 | ||
| 631 | /*----------------------------------------------------------------------------*/ | 623 | /*----------------------------------------------------------------------------*/ |
| 632 | 624 | ||
| 633 | template<class T=CDat<int>, int width=0> | 625 | template <class T> |
| 634 | void CInstructionJumpA<T>::compile(std::list<std::string>& params) | 626 | void CInstructionJumpA<T>::compile(std::list<std::string>& params) |
| 635 | { | 627 | { |
| 636 | if (params.size() != 1) | 628 | if (params.size() != 1) |
| 637 | throw std::runtime_error("Invalid paramater count - must be 1"); | 629 | throw CInstructionError("Invalid paramater count - must be 1"); |
| 638 | m_addr = params.front(); | 630 | m_addr = params.front(); |
| 639 | params.pop_front(); | 631 | params.pop_front(); |
| 640 | } | 632 | } |
| 641 | 633 | ||
| 642 | /*----------------------------------------------------------------------------*/ | 634 | /*----------------------------------------------------------------------------*/ |
| 643 | 635 | ||
| 644 | template<class T=CDat<int>, int width=0> | 636 | template <class T> |
| 645 | void CInstructionJumpA<T>::execute(CCPU<T> *cpu) | 637 | void CInstructionJumpA<T>::execute(CCPU<T> *cpu) |
| 646 | { | 638 | { |
| 647 | assert(cpu != NULL); | 639 | assert(cpu != NULL); |
| 648 | assert(cpu->getRegisters() != NULL); | ||
| 649 | assert(cpu->getProgram() != NULL); | 640 | assert(cpu->getProgram() != NULL); |
| 650 | if (m_addr.empty()) | 641 | if (m_addr.empty()) |
| 651 | throw std::runtime_error("Empty address"); | 642 | throw CInstructionError("Empty address"); |
| 652 | cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr); | 643 | try |
| 644 | { | ||
| 645 | cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr); | ||
| 646 | } | ||
| 647 | catch(CProgramError& ex) | ||
| 648 | { | ||
| 649 | throw CInstructionError(ex.what()); | ||
| 650 | } | ||
| 653 | } | 651 | } |
| 654 | 652 | ||
| 655 | /*============================================================================*/ | 653 | /*============================================================================*/ |
| @@ -661,7 +659,7 @@ void CInstructionJumpA<T>::execute(CCPU<T> *cpu) | |||
| 661 | * Syntax: jumpz labelname | 659 | * Syntax: jumpz labelname |
| 662 | * (jump to labelname if zeroflag) | 660 | * (jump to labelname if zeroflag) |
| 663 | */ | 661 | */ |
| 664 | template<class T=CDat<int>, int width=0> | 662 | template <class T> |
| 665 | class CInstructionJumpZ | 663 | class CInstructionJumpZ |
| 666 | : public CInstruction<T> | 664 | : public CInstruction<T> |
| 667 | { | 665 | { |
| @@ -687,28 +685,34 @@ class CInstructionJumpZ | |||
| 687 | 685 | ||
| 688 | /*----------------------------------------------------------------------------*/ | 686 | /*----------------------------------------------------------------------------*/ |
| 689 | 687 | ||
| 690 | template<class T=CDat<int>, int width=0> | 688 | template <class T> |
| 691 | void CInstructionJumpZ<T>::compile(std::list<std::string>& params) | 689 | void CInstructionJumpZ<T>::compile(std::list<std::string>& params) |
| 692 | { | 690 | { |
| 693 | if (params.size() != 1) | 691 | if (params.size() != 1) |
| 694 | throw std::runtime_error("Invalid paramater count - must be 1"); | 692 | throw CInstructionError("Invalid paramater count - must be 1"); |
| 695 | m_addr = params.front(); | 693 | m_addr = params.front(); |
| 696 | params.pop_front(); | 694 | params.pop_front(); |
| 697 | } | 695 | } |
| 698 | 696 | ||
| 699 | /*----------------------------------------------------------------------------*/ | 697 | /*----------------------------------------------------------------------------*/ |
| 700 | 698 | ||
| 701 | template<class T=CDat<int>, int width=0> | 699 | template <class T> |
| 702 | void CInstructionJumpZ<T>::execute(CCPU<T> *cpu) | 700 | void CInstructionJumpZ<T>::execute(CCPU<T> *cpu) |
| 703 | { | 701 | { |
| 704 | assert(cpu != NULL); | 702 | assert(cpu != NULL); |
| 705 | assert(cpu->getRegisters() != NULL); | ||
| 706 | assert(cpu->getProgram() != NULL); | 703 | assert(cpu->getProgram() != NULL); |
| 707 | if (!cpu->getFlagZero()) | 704 | if (!cpu->getFlagZero()) |
| 708 | return; | 705 | return; |
| 709 | if (m_addr.empty()) | 706 | if (m_addr.empty()) |
| 710 | throw std::runtime_error("Empty address"); | 707 | throw CInstructionError("Empty address"); |
| 711 | cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr); | 708 | try |
| 709 | { | ||
| 710 | cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr); | ||
| 711 | } | ||
| 712 | catch(CProgramError& ex) | ||
| 713 | { | ||
| 714 | throw CInstructionError(ex.what()); | ||
| 715 | } | ||
| 712 | } | 716 | } |
| 713 | 717 | ||
| 714 | /*============================================================================*/ | 718 | /*============================================================================*/ |
| @@ -720,7 +724,7 @@ void CInstructionJumpZ<T>::execute(CCPU<T> *cpu) | |||
| 720 | * Syntax: jumps labelname | 724 | * Syntax: jumps labelname |
| 721 | * (jump to labelname if signflag) | 725 | * (jump to labelname if signflag) |
| 722 | */ | 726 | */ |
| 723 | template<class T=CDat<int>, int width=0> | 727 | template <class T> |
| 724 | class CInstructionJumpS | 728 | class CInstructionJumpS |
| 725 | : public CInstruction<T> | 729 | : public CInstruction<T> |
| 726 | { | 730 | { |
| @@ -746,28 +750,34 @@ class CInstructionJumpS | |||
| 746 | 750 | ||
| 747 | /*----------------------------------------------------------------------------*/ | 751 | /*----------------------------------------------------------------------------*/ |
| 748 | 752 | ||
| 749 | template<class T=CDat<int>, int width=0> | 753 | template <class T> |
| 750 | void CInstructionJumpS<T>::compile(std::list<std::string>& params) | 754 | void CInstructionJumpS<T>::compile(std::list<std::string>& params) |
| 751 | { | 755 | { |
| 752 | if (params.size() != 1) | 756 | if (params.size() != 1) |
| 753 | throw std::runtime_error("Invalid paramater count - must be 1"); | 757 | throw CInstructionError("Invalid paramater count - must be 1"); |
| 754 | m_addr = params.front(); | 758 | m_addr = params.front(); |
| 755 | params.pop_front(); | 759 | params.pop_front(); |
| 756 | } | 760 | } |
| 757 | 761 | ||
| 758 | /*----------------------------------------------------------------------------*/ | 762 | /*----------------------------------------------------------------------------*/ |
| 759 | 763 | ||
| 760 | template<class T=CDat<int>, int width=0> | 764 | template <class T> |
| 761 | void CInstructionJumpS<T>::execute(CCPU<T> *cpu) | 765 | void CInstructionJumpS<T>::execute(CCPU<T> *cpu) |
| 762 | { | 766 | { |
| 763 | assert(cpu != NULL); | 767 | assert(cpu != NULL); |
| 764 | assert(cpu->getRegisters() != NULL); | ||
| 765 | assert(cpu->getProgram() != NULL); | 768 | assert(cpu->getProgram() != NULL); |
| 766 | if (!cpu->getFlagSign()) | 769 | if (!cpu->getFlagSign()) |
| 767 | return; | 770 | return; |
| 768 | if (m_addr.empty()) | 771 | if (m_addr.empty()) |
| 769 | throw std::runtime_error("Empty address"); | 772 | throw CInstructionError("Empty address"); |
| 770 | cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr); | 773 | try |
| 774 | { | ||
| 775 | cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr); | ||
| 776 | } | ||
| 777 | catch(CProgramError& ex) | ||
| 778 | { | ||
| 779 | throw CInstructionError(ex.what()); | ||
| 780 | } | ||
| 771 | } | 781 | } |
| 772 | 782 | ||
| 773 | /*============================================================================*/ | 783 | /*============================================================================*/ |
| @@ -779,7 +789,7 @@ void CInstructionJumpS<T>::execute(CCPU<T> *cpu) | |||
| 779 | * Syntax: write DEV, R1 | 789 | * Syntax: write DEV, R1 |
| 780 | * (write R1 to DEV, which is a name of a display) | 790 | * (write R1 to DEV, which is a name of a display) |
| 781 | */ | 791 | */ |
| 782 | template<class T=CDat<int>, int width=0> | 792 | template <class T> |
| 783 | class CInstructionWrite | 793 | class CInstructionWrite |
| 784 | : public CInstruction<T> | 794 | : public CInstruction<T> |
| 785 | { | 795 | { |
| @@ -808,11 +818,11 @@ class CInstructionWrite | |||
| 808 | 818 | ||
| 809 | /*----------------------------------------------------------------------------*/ | 819 | /*----------------------------------------------------------------------------*/ |
| 810 | 820 | ||
| 811 | template<class T=CDat<int>, int width=0> | 821 | template <class T> |
| 812 | void CInstructionWrite<T>::compile(std::list<std::string>& params) | 822 | void CInstructionWrite<T>::compile(std::list<std::string>& params) |
| 813 | { | 823 | { |
| 814 | if (params.size() != 2) | 824 | if (params.size() != 2) |
| 815 | throw std::runtime_error("Invalid paramater count - must be 2"); | 825 | throw CInstructionError("Invalid paramater count - must be 2"); |
| 816 | m_dev = params.front(); | 826 | m_dev = params.front(); |
| 817 | params.pop_front(); | 827 | params.pop_front(); |
| 818 | m_regidx1 = super::parseRegister(params.front()); | 828 | m_regidx1 = super::parseRegister(params.front()); |
| @@ -821,14 +831,13 @@ void CInstructionWrite<T>::compile(std::list<std::string>& params) | |||
| 821 | 831 | ||
| 822 | /*----------------------------------------------------------------------------*/ | 832 | /*----------------------------------------------------------------------------*/ |
| 823 | 833 | ||
| 824 | template<class T=CDat<int>, int width=0> | 834 | template <class T> |
| 825 | void CInstructionWrite<T>::execute(CCPU<T> *cpu) | 835 | void CInstructionWrite<T>::execute(CCPU<T> *cpu) |
| 826 | { | 836 | { |
| 827 | assert(cpu != NULL); | 837 | assert(cpu != NULL); |
| 828 | assert(cpu->getRegisters() != NULL); | ||
| 829 | super::checkRegister(cpu, m_regidx1); | 838 | super::checkRegister(cpu, m_regidx1); |
| 830 | if (m_dev.empty()) | 839 | if (m_dev.empty()) |
| 831 | throw std::runtime_error("Empty device"); | 840 | throw CInstructionError("Empty device"); |
| 832 | 841 | ||
| 833 | CDisplay<T> *display = NULL; | 842 | CDisplay<T> *display = NULL; |
| 834 | std::set<CDisplay<T> *> displays = cpu->getDisplays(); | 843 | std::set<CDisplay<T> *> displays = cpu->getDisplays(); |
| @@ -841,7 +850,7 @@ void CInstructionWrite<T>::execute(CCPU<T> *cpu) | |||
| 841 | } | 850 | } |
| 842 | } | 851 | } |
| 843 | if (display == NULL) | 852 | if (display == NULL) |
| 844 | throw std::runtime_error("Unknown display"); | 853 | throw CInstructionError("Unknown display"); |
| 845 | 854 | ||
| 846 | display->display(cpu->getRegisters()[ m_regidx1 ]); | 855 | display->display(cpu->getRegisters()[ m_regidx1 ]); |
| 847 | } | 856 | } |
