From f67834dd18859ed333c88360f4141a99dc7db5dd Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 28 May 2009 19:22:52 +0200 Subject: push for me --- ue4/mycpu/instructions.h | 157 +++++++++++++++++++++++++---------------------- 1 file changed, 83 insertions(+), 74 deletions(-) (limited to 'ue4/mycpu/instructions.h') 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 @@ * Syntax: inc R1 * (R1++) */ -template, int width=0> +template class CInstructionInc - : public CInstruction + : public CInstruction { typedef CInstruction super; @@ -45,22 +45,21 @@ class CInstructionInc /*----------------------------------------------------------------------------*/ -template, int width=0> +template void CInstructionInc::compile(std::list& params) { if (params.size() != 1) - throw std::runtime_error("Invalid paramater count - must be 1"); + throw CInstructionError("Invalid paramater count - must be 1"); m_regidx1 = super::parseRegister(params.front()); params.pop_front(); } /*----------------------------------------------------------------------------*/ -template, int width=0> +template void CInstructionInc::execute(CCPU *cpu) { assert(cpu != NULL); - assert(cpu->getRegisters() != NULL); super::checkRegister(cpu, m_regidx1); cpu->getRegisters()[ m_regidx1 ]++; } @@ -74,7 +73,7 @@ void CInstructionInc::execute(CCPU *cpu) * Syntax: dec R1 * (R1--) */ -template, int width=0> +template class CInstructionDec : public CInstruction { @@ -100,22 +99,21 @@ class CInstructionDec /*----------------------------------------------------------------------------*/ -template, int width=0> +template void CInstructionDec::compile(std::list& params) { if (params.size() != 1) - throw std::runtime_error("Invalid paramater count - must be 1"); + throw CInstructionError("Invalid paramater count - must be 1"); m_regidx1 = super::parseRegister(params.front()); params.pop_front(); } /*----------------------------------------------------------------------------*/ -template, int width=0> +template void CInstructionDec::execute(CCPU *cpu) { assert(cpu != NULL); - assert(cpu->getRegisters() != NULL); super::checkRegister(cpu, m_regidx1); cpu->getRegisters()[ m_regidx1 ]--; } @@ -129,7 +127,7 @@ void CInstructionDec::execute(CCPU *cpu) * Syntax: add R1, R2, R3 * (R1 = R2 + R3) */ -template, int width=0> +template class CInstructionAdd : public CInstruction { @@ -159,11 +157,11 @@ class CInstructionAdd /*----------------------------------------------------------------------------*/ -template, int width=0> +template void CInstructionAdd::compile(std::list& params) { if (params.size() != 3) - throw std::runtime_error("Invalid paramater count - must be 3"); + throw CInstructionError("Invalid paramater count - must be 3"); m_regidx1 = super::parseRegister(params.front()); params.pop_front(); m_regidx2 = super::parseRegister(params.front()); @@ -174,11 +172,10 @@ void CInstructionAdd::compile(std::list& params) /*----------------------------------------------------------------------------*/ -template, int width=0> +template void CInstructionAdd::execute(CCPU *cpu) { assert(cpu != NULL); - assert(cpu->getRegisters() != NULL); super::checkRegister(cpu, m_regidx1); super::checkRegister(cpu, m_regidx2); super::checkRegister(cpu, m_regidx3); @@ -195,7 +192,7 @@ void CInstructionAdd::execute(CCPU *cpu) * Syntax: sub R1, R2, R3 * (R1 = R2 - R3) */ -template, int width=0> +template class CInstructionSub : public CInstruction { @@ -225,11 +222,11 @@ class CInstructionSub /*----------------------------------------------------------------------------*/ -template, int width=0> +template void CInstructionSub::compile(std::list& params) { if (params.size() != 3) - throw std::runtime_error("Invalid paramater count - must be 3"); + throw CInstructionError("Invalid paramater count - must be 3"); m_regidx1 = super::parseRegister(params.front()); params.pop_front(); m_regidx2 = super::parseRegister(params.front()); @@ -240,11 +237,10 @@ void CInstructionSub::compile(std::list& params) /*----------------------------------------------------------------------------*/ -template, int width=0> +template void CInstructionSub::execute(CCPU *cpu) { assert(cpu != NULL); - assert(cpu->getRegisters() != NULL); super::checkRegister(cpu, m_regidx1); super::checkRegister(cpu, m_regidx2); super::checkRegister(cpu, m_regidx3); @@ -261,7 +257,7 @@ void CInstructionSub::execute(CCPU *cpu) * Syntax: mul R1, R2, R3 * (R1 = R2 * R3) */ -template, int width=0> +template class CInstructionMul : public CInstruction { @@ -291,11 +287,11 @@ class CInstructionMul /*----------------------------------------------------------------------------*/ -template, int width=0> +template void CInstructionMul::compile(std::list& params) { if (params.size() != 3) - throw std::runtime_error("Invalid paramater count - must be 3"); + throw CInstructionError("Invalid paramater count - must be 3"); m_regidx1 = super::parseRegister(params.front()); params.pop_front(); m_regidx2 = super::parseRegister(params.front()); @@ -306,7 +302,7 @@ void CInstructionMul::compile(std::list& params) /*----------------------------------------------------------------------------*/ -template, int width=0> +template void CInstructionMul::execute(CCPU *cpu) { super::checkRegister(cpu, m_regidx1); @@ -325,7 +321,7 @@ void CInstructionMul::execute(CCPU *cpu) * Syntax: div R1, R2, R3 * (R1 = R2 / R3) */ -template, int width=0> +template class CInstructionDiv : public CInstruction { @@ -355,11 +351,11 @@ class CInstructionDiv /*----------------------------------------------------------------------------*/ -template, int width=0> +template void CInstructionDiv::compile(std::list& params) { if (params.size() != 3) - throw std::runtime_error("Invalid paramater count - must be 3"); + throw CInstructionError("Invalid paramater count - must be 3"); m_regidx1 = super::parseRegister(params.front()); params.pop_front(); m_regidx2 = super::parseRegister(params.front()); @@ -370,11 +366,10 @@ void CInstructionDiv::compile(std::list& params) /*----------------------------------------------------------------------------*/ -template, int width=0> +template void CInstructionDiv::execute(CCPU *cpu) { assert(cpu != NULL); - assert(cpu->getRegisters() != NULL); super::checkRegister(cpu, m_regidx1); super::checkRegister(cpu, m_regidx2); super::checkRegister(cpu, m_regidx3); @@ -391,7 +386,7 @@ void CInstructionDiv::execute(CCPU *cpu) * Syntax: load R1, R2 * (R1 = memory[R2]) */ -template, int width=0> +template class CInstructionLoad : public CInstruction { @@ -419,11 +414,11 @@ class CInstructionLoad /*----------------------------------------------------------------------------*/ -template, int width=0> +template void CInstructionLoad::compile(std::list& params) { if (params.size() != 2) - throw std::runtime_error("Invalid paramater count - must be 2"); + throw CInstructionError("Invalid paramater count - must be 2"); m_regidx1 = super::parseRegister(params.front()); params.pop_front(); m_regidx2 = super::parseRegister(params.front()); @@ -432,11 +427,10 @@ void CInstructionLoad::compile(std::list& params) /*----------------------------------------------------------------------------*/ -template, int width=0> +template void CInstructionLoad::execute(CCPU *cpu) { assert(cpu != NULL); - assert(cpu->getRegisters() != NULL); assert(cpu->getMemory() != NULL); super::checkRegister(cpu, m_regidx1); super::checkRegister(cpu, m_regidx2); @@ -453,7 +447,7 @@ void CInstructionLoad::execute(CCPU *cpu) * Syntax: store R1, R2 * (memory[R2] = R1) */ -template, int width=0> +template class CInstructionStore : public CInstruction { @@ -481,11 +475,11 @@ class CInstructionStore /*----------------------------------------------------------------------------*/ -template, int width=0> +template void CInstructionStore::compile(std::list& params) { if (params.size() != 2) - throw std::runtime_error("Invalid paramater count - must be 2"); + throw CInstructionError("Invalid paramater count - must be 2"); m_regidx1 = super::parseRegister(params.front()); params.pop_front(); m_regidx2 = super::parseRegister(params.front()); @@ -494,11 +488,10 @@ void CInstructionStore::compile(std::list& params) /*----------------------------------------------------------------------------*/ -template, int width=0> +template void CInstructionStore::execute(CCPU *cpu) { assert(cpu != NULL); - assert(cpu->getRegisters() != NULL); assert(cpu->getMemory() != NULL); super::checkRegister(cpu, m_regidx1); super::checkRegister(cpu, m_regidx2); @@ -515,7 +508,7 @@ void CInstructionStore::execute(CCPU *cpu) * Syntax: test R1 * (R1 == 0: zeroflag: true, R1 < 0: signflag: true) */ -template, int width=0> +template class CInstructionTest : public CInstruction { @@ -541,22 +534,21 @@ class CInstructionTest /*----------------------------------------------------------------------------*/ -template, int width=0> +template void CInstructionTest::compile(std::list& params) { if (params.size() != 1) - throw std::runtime_error("Invalid paramater count - must be 1"); + throw CInstructionError("Invalid paramater count - must be 1"); m_regidx1 = super::parseRegister(params.front()); params.pop_front(); } /*----------------------------------------------------------------------------*/ -template, int width=0> +template void CInstructionTest::execute(CCPU *cpu) { assert(cpu != NULL); - assert(cpu->getRegisters() != NULL); super::checkRegister(cpu, m_regidx1); if (cpu->getRegisters()[ m_regidx1 ] == T(0)) cpu->setFlagZero(true); @@ -572,7 +564,7 @@ void CInstructionTest::execute(CCPU *cpu) * Implementation of assembler command "label" * Syntax: label name: */ -template, int width=0> +template class CInstructionLabel : public CInstruction { @@ -604,7 +596,7 @@ class CInstructionLabel * Syntax: jumpa labelname * (jump to labelname) */ -template, int width=0> +template class CInstructionJumpA : public CInstruction { @@ -630,26 +622,32 @@ class CInstructionJumpA /*----------------------------------------------------------------------------*/ -template, int width=0> +template void CInstructionJumpA::compile(std::list& params) { if (params.size() != 1) - throw std::runtime_error("Invalid paramater count - must be 1"); + throw CInstructionError("Invalid paramater count - must be 1"); m_addr = params.front(); params.pop_front(); } /*----------------------------------------------------------------------------*/ -template, int width=0> +template void CInstructionJumpA::execute(CCPU *cpu) { assert(cpu != NULL); - assert(cpu->getRegisters() != NULL); assert(cpu->getProgram() != NULL); if (m_addr.empty()) - throw std::runtime_error("Empty address"); - cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr); + throw CInstructionError("Empty address"); + try + { + cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr); + } + catch(CProgramError& ex) + { + throw CInstructionError(ex.what()); + } } /*============================================================================*/ @@ -661,7 +659,7 @@ void CInstructionJumpA::execute(CCPU *cpu) * Syntax: jumpz labelname * (jump to labelname if zeroflag) */ -template, int width=0> +template class CInstructionJumpZ : public CInstruction { @@ -687,28 +685,34 @@ class CInstructionJumpZ /*----------------------------------------------------------------------------*/ -template, int width=0> +template void CInstructionJumpZ::compile(std::list& params) { if (params.size() != 1) - throw std::runtime_error("Invalid paramater count - must be 1"); + throw CInstructionError("Invalid paramater count - must be 1"); m_addr = params.front(); params.pop_front(); } /*----------------------------------------------------------------------------*/ -template, int width=0> +template void CInstructionJumpZ::execute(CCPU *cpu) { assert(cpu != NULL); - assert(cpu->getRegisters() != NULL); assert(cpu->getProgram() != NULL); if (!cpu->getFlagZero()) return; if (m_addr.empty()) - throw std::runtime_error("Empty address"); - cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr); + throw CInstructionError("Empty address"); + try + { + cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr); + } + catch(CProgramError& ex) + { + throw CInstructionError(ex.what()); + } } /*============================================================================*/ @@ -720,7 +724,7 @@ void CInstructionJumpZ::execute(CCPU *cpu) * Syntax: jumps labelname * (jump to labelname if signflag) */ -template, int width=0> +template class CInstructionJumpS : public CInstruction { @@ -746,28 +750,34 @@ class CInstructionJumpS /*----------------------------------------------------------------------------*/ -template, int width=0> +template void CInstructionJumpS::compile(std::list& params) { if (params.size() != 1) - throw std::runtime_error("Invalid paramater count - must be 1"); + throw CInstructionError("Invalid paramater count - must be 1"); m_addr = params.front(); params.pop_front(); } /*----------------------------------------------------------------------------*/ -template, int width=0> +template void CInstructionJumpS::execute(CCPU *cpu) { assert(cpu != NULL); - assert(cpu->getRegisters() != NULL); assert(cpu->getProgram() != NULL); if (!cpu->getFlagSign()) return; if (m_addr.empty()) - throw std::runtime_error("Empty address"); - cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr); + throw CInstructionError("Empty address"); + try + { + cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr); + } + catch(CProgramError& ex) + { + throw CInstructionError(ex.what()); + } } /*============================================================================*/ @@ -779,7 +789,7 @@ void CInstructionJumpS::execute(CCPU *cpu) * Syntax: write DEV, R1 * (write R1 to DEV, which is a name of a display) */ -template, int width=0> +template class CInstructionWrite : public CInstruction { @@ -808,11 +818,11 @@ class CInstructionWrite /*----------------------------------------------------------------------------*/ -template, int width=0> +template void CInstructionWrite::compile(std::list& params) { if (params.size() != 2) - throw std::runtime_error("Invalid paramater count - must be 2"); + throw CInstructionError("Invalid paramater count - must be 2"); m_dev = params.front(); params.pop_front(); m_regidx1 = super::parseRegister(params.front()); @@ -821,14 +831,13 @@ void CInstructionWrite::compile(std::list& params) /*----------------------------------------------------------------------------*/ -template, int width=0> +template void CInstructionWrite::execute(CCPU *cpu) { assert(cpu != NULL); - assert(cpu->getRegisters() != NULL); super::checkRegister(cpu, m_regidx1); if (m_dev.empty()) - throw std::runtime_error("Empty device"); + throw CInstructionError("Empty device"); CDisplay *display = NULL; std::set *> displays = cpu->getDisplays(); @@ -841,7 +850,7 @@ void CInstructionWrite::execute(CCPU *cpu) } } if (display == NULL) - throw std::runtime_error("Unknown display"); + throw CInstructionError("Unknown display"); display->display(cpu->getRegisters()[ m_regidx1 ]); } -- cgit v1.2.3