/* * Compare Less Immediate * If AC < XXXX, X{0..9}, then PSW[0] = T else PSW[0] = F. * * 29 XXXX * * Compare contents of accumulator to integer */ void o29(Vm* vm){ int value = charArrayToInt(2,6,vm->IR); if(vm->ACC < value){ vm->PSW[0] = 'T'; }else{ vm->PSW[0] = 'F'; } }
int readInteger(std::ifstream &in) { char store[4]; in.read(store, 4); return charArrayToInt(store); }
/* * Compare Greater Register Addressing * If AC > M(Pn) then PSW[0] = T else PSW[0] = F. * * 26 Pn -- * * If contents of Accumulator are greater than the contents of memory location pointed to by Pn, n{0..3}, * then byte 0 of the PSW set to T, else set to F. */ void o26(Vm* vm){ int value = charArrayToInt(0, 6, vm->memory[getPointer(vm, charToInt(vm->IR[3]))]); if(vm->ACC > value){ vm->PSW[0] = 'T'; }else{ vm->PSW[0] = 'F'; } }
/* * START THE VM */ void startVM(Vm* vm) { vm->PC = 0; while (charArrayToInt(0,2,vm->IR) != 99) { nextInstruction(vm); switch (charArrayToInt(0,2,vm->IR)) { case 0: o0(vm); break; case 1: o1(vm); break; case 2: o2(vm); break; case 3: o3(vm); break; case 4: o4(vm); break; case 5: o5(vm); break; case 6: o6(vm); break; case 7: o7(vm); break; case 8: o8(vm); break; case 9: o9(vm); break; case 10: o10(vm); break; case 11: o11(vm); break; case 12: o12(vm); break; case 13: o13(vm); break; case 14: o14(vm); break; case 15: o15(vm); break; case 16: o16(vm); break; case 17: o17(vm); break; case 18: o18(vm); break; case 19: o19(vm); break; case 20: o20(vm); break; case 21: o21(vm); break; case 22: o22(vm); break; case 23: o23(vm); break; case 24: o24(vm); break; case 25: o25(vm); break; case 26: o26(vm); break; case 27: o27(vm); break; case 28: o28(vm); break; case 29: o29(vm); break; case 30: o30(vm); break; case 31: o31(vm); break; case 32: o32(vm); break; case 33: o33(vm); break; case 34: o34(vm); break; case 35: o35(vm); break; case 99: o99(vm); break; default: // Code break; } displayVmFinal(vm); } }
/* * Branch Unconditional * PC == XX, X{0..9} * * 35 XX -- */ void o35(Vm* vm){ vm->PC = charArrayToInt(2,4,vm->IR); }
/* * Branch Conditional * If PSW[0] = F then PC = XX, X{0..9} * * 34 XX -- */ void o34(Vm* vm){ if(vm->PSW[0] == 'F'){ vm->PC = charArrayToInt(2,4,vm->IR); } }
/* * Subtract from Accumulator Direct Addressing * AC <- AC - M(XX), X{0..9}. * * 23 XX -- * * Subtract from accumulator contents of memory location XX */ void o23(Vm* vm){ vm->ACC -= charArrayToInt(0, 6, vm->memory[charArrayToInt(2,4,vm->IR)]); }
/* * Store Accumulator Direct Addressing * M(XX) <- AC. * * 07 XX -- * * Store contents of AC into memory location XX, X{0..9} */ void o7(Vm* vm){ intToCharArray(vm->ACC, vm->memory[charArrayToInt(2,4,vm->IR)]); }
/* * Subtract Accumulator Immediate * AC <- AC - XXXX, X{0..9}. * * 17 XX XX */ void o17(Vm* vm){ vm->ACC -= charArrayToInt(2,6,vm->IR); }
/* * Add Accumulator Immediate * AC <- AC + XXXX, X{0..9}. * * 16 XX XX */ void o16(Vm* vm){ vm->ACC += charArrayToInt(2,6,vm->IR); }
/* * Load Register R0 Immediate * R0 <- XXXX. * * 12 XX XX * * Load Register R0 with integer value XXXX, X{0..9} */ void o12(Vm* vm){ setRegister(vm, 0, charArrayToInt(2,6,vm->IR)); }
/* * Load Register from memory: Direct Addressing * Rn <- M(XX). * * 11 Rn XX * * Load Register Rn, n{0..3}, with the contents of memory location XX, X{0..9} */ void o11(Vm* vm){ setRegister(vm, charToInt(vm->IR[3]), charArrayToInt(0,6,vm->memory[charArrayToInt(4,6,vm->IR)])); }
/* * Load Register from memory: Register Addressing * Rn <- M(Pn). * * 10 Rn Pn * * Load Register Rn with the contents of memory location pointed to by Pn, n{0..3} */ void o10(Vm* vm){ setRegister(vm, charToInt(vm->IR[3]), charArrayToInt(0,6,vm->memory[getPointer(vm, charToInt(vm->IR[5]))])); }
/* * Store Register to memory: Direct Addressing * M(XX) <- Rn. * * 09 Rn XX * * Store contents of Register n, n{0..3} to memory location XX, X{0..9} */ void o9(Vm* vm){ intToCharArray(getRegister(vm, charToInt(vm->IR[3])), vm->memory[charArrayToInt(4,6,vm->IR)]); }
void Object::loadFromXml(tinyxml2::XMLElement* objectElement) { std::vector<std::string> attributesObject, attributesSymmetry, attributesPoint, valuesObject, valuesSymmetry; std::vector<float> valuesPoint; attributesObject.push_back("ID"); attributesObject.push_back("name"); attributesSymmetry.push_back("type"); attributesPoint.push_back("x"); attributesPoint.push_back("y"); attributesPoint.push_back("z"); //getting attributes for object getAttributeList(valuesObject, attributesObject, objectElement); objectName_=valuesObject.at(1); objectID_=charArrayToInt(valuesObject.at(0).c_str()); //getting attributes for object -only one symmetry per object tinyxml2::XMLElement* symmetryPtr = objectElement->FirstChildElement("symmetry"); if(symmetryPtr != NULL) { getAttributeList(valuesSymmetry, attributesSymmetry, symmetryPtr); } else { std::cout << "[Error] Wrong XML Element Name: symmetry" << std::endl; exit(EXIT_FAILURE); } //Mapping strings to enum type, see util getSymmetryTypeFromString(objectSymmetry_.symmetryType,valuesSymmetry.at(0)); //getting attributes for the layers and stuff, several cases and element, looping tinyxml2::XMLElement* layerOrAxisPtr = symmetryPtr->FirstChildElement(); tinyxml2::XMLElement* pointPtr = NULL; switch (objectSymmetry_.symmetryType) { case SINGLEPLANE: { SinglePlane singlePlane; //actual single plane in the loop; int n =0; int m = 0; //Outer Loop for (; layerOrAxisPtr; layerOrAxisPtr=layerOrAxisPtr->NextSiblingElement() ) { pointPtr = layerOrAxisPtr->FirstChildElement("point"); //std::cout << "[Debug 50]:Outer Loop " << "\n" << std::flush; //std::cout << "[Debug 50]:Pointer Value " << layerOrAxisPtr->Name() << "\n" << std::flush; m=0; //Inner Loop - getting the full layer or axis for(; pointPtr; pointPtr=pointPtr->NextSiblingElement() ){ getAttributeList(valuesPoint, attributesPoint, pointPtr); //std::cout << "[Debug 60]:Inner Loop " << "\n" << std::flush; //std::cout << "[Debug 60]:Pointer Value " << pointPtr->Name() << "\n" << std::flush; //std::cout << "[Debug 60]: m " << m << "\n" << std::flush; //std::cout << "[Debug 60]: n " << n << "\n" << std::flush; //std::cout << "[Debug 60]: ValuePoint(1) " << valuesPoint.at(1) << "\n" << std::flush; if (m==0) singlePlane.plane1.point1 << valuesPoint.at(0), valuesPoint.at(1), valuesPoint.at(2); else if(m==1) singlePlane.plane1.point2 << valuesPoint.at(0), valuesPoint.at(1), valuesPoint.at(2); else if(m==2) singlePlane.plane1.point3 << valuesPoint.at(0), valuesPoint.at(1), valuesPoint.at(2); m++; valuesPoint.resize(0); //erasing content } //In Outer Loop n++; } singlePlane.scale(0.001); objectSymmetry_.symmetryData = singlePlane; } break; case DOUBLEPLANE: { DoublePlane doublePlane; //actual single plane in the loop; int n =0; int m = 0; //Outer Loop for (; layerOrAxisPtr; layerOrAxisPtr =layerOrAxisPtr->NextSiblingElement("layer") ) { pointPtr = layerOrAxisPtr->FirstChildElement("point"); m=0; //Inner Loop - getting the full layer or axis for(; pointPtr; pointPtr=pointPtr->NextSiblingElement("point") ){ getAttributeList(valuesPoint, attributesPoint, pointPtr); if (n==0) { if (m==0) doublePlane.plane1.point1 << valuesPoint.at(0), valuesPoint.at(1), valuesPoint.at(2); else if(m==1) doublePlane.plane1.point2 << valuesPoint.at(0), valuesPoint.at(1), valuesPoint.at(2); else if(m==2) doublePlane.plane1.point3 << valuesPoint.at(0), valuesPoint.at(1), valuesPoint.at(2); } else if (n==1){ if (m==0) doublePlane.plane2.point1 << valuesPoint.at(0), valuesPoint.at(1), valuesPoint.at(2); else if(m==1) doublePlane.plane2.point2 << valuesPoint.at(0), valuesPoint.at(1), valuesPoint.at(2); else if(m==2) doublePlane.plane2.point3 << valuesPoint.at(0), valuesPoint.at(1), valuesPoint.at(2); } m++; valuesPoint.resize(0); //erasing content } //In Outer Loop n++; } doublePlane.scale(0.001); objectSymmetry_.symmetryData = doublePlane; } break; case TRIPLEPLANE: { TriplePlane triplePlane; //actual single plane in the loop; int n =0; int m = 0; //Outer Loop for (; layerOrAxisPtr; layerOrAxisPtr=layerOrAxisPtr->NextSiblingElement("layer") ) { pointPtr = layerOrAxisPtr->FirstChildElement("point"); m=0; //Inner Loop - getting the full layer or axis for(; pointPtr; pointPtr=pointPtr->NextSiblingElement("point") ){ getAttributeList(valuesPoint, attributesPoint, pointPtr); if (n==0) { if (m==0) triplePlane.plane1.point1 << valuesPoint.at(0), valuesPoint.at(1), valuesPoint.at(2); else if(m==1) triplePlane.plane1.point2 << valuesPoint.at(0), valuesPoint.at(1), valuesPoint.at(2); else if(m==2) triplePlane.plane1.point3 << valuesPoint.at(0), valuesPoint.at(1), valuesPoint.at(2); } else if (n==1){ if (m==0) triplePlane.plane2.point1 << valuesPoint.at(0), valuesPoint.at(1), valuesPoint.at(2); else if(m==1) triplePlane.plane2.point2 << valuesPoint.at(0), valuesPoint.at(1), valuesPoint.at(2); else if(m==2) triplePlane.plane2.point3 << valuesPoint.at(0), valuesPoint.at(1), valuesPoint.at(2); } else if (n==2) { if (m==0) triplePlane.plane3.point1 << valuesPoint.at(0), valuesPoint.at(1), valuesPoint.at(2); else if(m==1) triplePlane.plane3.point2 << valuesPoint.at(0), valuesPoint.at(1), valuesPoint.at(2); else if(m==2) triplePlane.plane3.point3 << valuesPoint.at(0), valuesPoint.at(1), valuesPoint.at(2); } m++; valuesPoint.resize(0); //erasing content } //In Outer Loop n++; } triplePlane.scale(0.001); objectSymmetry_.symmetryData = triplePlane; } break; case AXIAL: { Axial axial; //actual single plane in the loop; int n =0; int m = 0; //Outer Loop for (; layerOrAxisPtr; layerOrAxisPtr=layerOrAxisPtr->NextSiblingElement("axis") ) { pointPtr = layerOrAxisPtr->FirstChildElement("point"); m=0; //Inner Loop - getting the full layer or axis for(; pointPtr; pointPtr = pointPtr->NextSiblingElement("point") ){ getAttributeList(valuesPoint, attributesPoint, pointPtr); std::cout << "[Debug 60]: ValuePoint(1) " << valuesPoint.at(1) << "\n" << std::flush; if (m==0) axial.axis1.point1 << valuesPoint.at(0), valuesPoint.at(1), valuesPoint.at(2); else if(m==1) axial.axis1.point2 << valuesPoint.at(0), valuesPoint.at(1), valuesPoint.at(2); m++; valuesPoint.resize(0); //erasing content } //In Outer Loop n++; } axial.scale(0.001); objectSymmetry_.symmetryData = axial; } break; case AXIALSINGLEPLANE: { AxialSinglePlane axialSinglePlane; //actual single plane in the loop; Layer3D layer; Axis3D axis; int n =0; int m = 0; //Outer Loop for axis layerOrAxisPtr = symmetryPtr->FirstChildElement("axis"); for (; layerOrAxisPtr; layerOrAxisPtr=layerOrAxisPtr->NextSiblingElement("axis") ) { pointPtr = layerOrAxisPtr->FirstChildElement("point"); m=0; //Inner Loop - getting the full layer or axis for(; pointPtr; pointPtr=pointPtr->NextSiblingElement("point") ){ getAttributeList(valuesPoint, attributesPoint, pointPtr); if (m==0) axis.point1 << valuesPoint.at(0), valuesPoint.at(1), valuesPoint.at(2); else if(m==1) axis.point2 << valuesPoint.at(0), valuesPoint.at(1), valuesPoint.at(2); m++; valuesPoint.resize(0); //erasing content } //In Outer Loop n++; } //Outer Loop for layer n=0; m=0; layerOrAxisPtr = symmetryPtr->FirstChildElement("layer"); for (; layerOrAxisPtr; layerOrAxisPtr=layerOrAxisPtr->NextSiblingElement("layer") ) { pointPtr = layerOrAxisPtr->FirstChildElement("point"); m=0; //Inner Loop - getting the full layer or axis for(; pointPtr; pointPtr=pointPtr->NextSiblingElement("point") ){ getAttributeList(valuesPoint, attributesPoint, pointPtr); if (m==0) layer.point1 << valuesPoint.at(0), valuesPoint.at(1), valuesPoint.at(2); else if(m==1) layer.point2 << valuesPoint.at(0), valuesPoint.at(1), valuesPoint.at(2); else if(m==2) layer.point3 << valuesPoint.at(0), valuesPoint.at(1), valuesPoint.at(2); m++; valuesPoint.resize(0); //erasing content } //In Outer Loop n++; } axialSinglePlane.axis1 = axis; axialSinglePlane.plane1 = layer; axialSinglePlane.scale(0.001); objectSymmetry_.symmetryData = axialSinglePlane; } break; default: std::cout << "[Error] Objectsymmetry not correctly defined on XML, exiting!\n"; exit(EXIT_FAILURE); break; } }
/* * Subtract from Accumulator Register Addressing * AC <- AC - M(Pn). * * 22 Pn -- * * Subtract from accumulator contents of memory location XX */ void o22(Vm* vm){ vm->ACC -= charArrayToInt(0, 6, vm->memory[getPointer(vm, charToInt(vm->IR[3]))]); }
/* * Load Accumulator Immediate * AC <- XXXX, X: {0 .. 9}. * * 03 XX XX * * Load interger value XXXX into accumulator */ void o3(Vm* vm){ vm->ACC = charArrayToInt(2, 6,vm->IR); }