// array/map of pointers which all point // to the functions which the index corresponds to. // use that like a sort of map AddData idata; //Instruction Data // Load and Store Instructions // the load and store instructions are currently // used to express how data structures will work eventually. void fLDA(Addressing addr, address val){ idata = fAddress(addr, val); acc = idata.val; } void fLDX(Addressing addr, address val){ idata = fAddress(addr, val); X = idata.value; } void fLDY(Addressing addr, address val){ idata = fAddress(addr, val); Y = idata.value; } void fSTA(Addressing addr, address val){ idata = fAddress(addr, val); Memory[idata.value] = acc; } void fSTX(Addressing addr, address val){ idata = fAddress(addr, val); Memory[idata.value] = X; } void fSTY(Addressing addr, address val){ idata = fAddress(addr, val); Memory[idata.value] = Y; } // Arithmetic Instructions void fADC(Addressing addr, address val){ idata = fAddress(addr, val); int buffer = acc + fAddress(addr, val); setFlagV(buffer, acc); if (buffer > 255){ flagSet(flag_C); }else{ flagClear(flag_C); } acc += fAddress(addr, val); setFlagN(acc); setFlagZ(acc); } void fSBC(Addressing addr, address val){ idata = fAddress(addr, val); int buffer = acc - fAddress(addr, val); setFlagV(buffer, acc); if (buffer < 0){ flagSet(flag_C); }else{ flagClear(flag_C); } acc -= fAddress(addr, val); setFlagN(acc); setFlagZ(acc); } //Increment and Decrement Instructions void fINC(Addressing addr, address val){ idata = fAddress(addr, val); Memory[x]++; setFlagD(Memory[x]); setFlagZ(Memory[x]); } void fINX(Addressing addr, address val){ idata = fAddress(addr, val); X++; setFlagD(X); setFlagZ(X); } void fINY(Addressing addr, address val){ idata = fAddress(addr, val); Y++; setFlagD(Y); setFlagZ(Y); } void fDEC(Addressing addr, address val){ idata = fAddress(addr, val); Memory[x]--; setFlagD(Memory[x]); setFlagZ(Memory[x]); } void fDEX(Addressing addr, address val){ idata = fAddress(addr, val); X--; setFlagD(X); setFlagZ(X); } void fDEY(Addressing addr, address val){ idata = fAddress(addr, val); Y--; setFlagD(Y); setFlagZ(Y); } // Logical Instructions void fAND(Addressing addr, address val){ idata = fAddress(addr, val); acc = acc & fAddress(addr, val); setFlagN(); setFlagZ(acc); } void fORA(Addressing addr, address val){ idata = fAddress(addr, val); acc = acc | fAddress(addr, val); setFlagN(); setFlagZ(acc); } void fEOR(Addressing addr, address val){ idata = fAddress(addr, val); acc = acc ^ fAddress(addr, val); setFlagN(acc); setFlagZ(acc); } // Jump, Branch, Compare, and Test Bits void fJMP(Addressing addr, address val){ idata = fAddress(addr, val); PC = val; } void fBCC(Addressing addr, address val){ idata = fAddress(addr, val); //signed char val down to BVC if (getFlag(flag_C) == 0) PC += val; } void fBCS(Addressing addr, address val){ idata = fAddress(addr, val); if (getFlag(flag_C) == 1) PC += val; } void fBEQ(Addressing addr, address val){ idata = fAddress(addr, val); if (getFlag(flag_Z) == 1) PC += val; } void fBNE(Addressing addr, address val){ idata = fAddress(addr, val); if (getFlag(flag_Z) == 0) PC += val; } void fBMI(Addressing addr, address val){ idata = fAddress(addr, val); if (getFlag(flag_N) == 1) PC += val; } void fBPL(Addressing addr, address val){ idata = fAddress(addr, val); if (getFlag(flag_N) == 0) PC += val; } void fBVS(Addressing addr, address val){ idata = fAddress(addr, val); if (getFlag(flag_V) == 1) PC += val; } void fBVC(Addressing addr, address val){ idata = fAddress(addr, val); if (getFlag(flag_V) == 0) PC += val; } void fCMP(Addressing addr, address val){ idata = fAddress(addr, val); if (acc < Memory[val]){ flagSet(flag_N); flagClear(flag_Z); flagClear(flag_C); }if (acc == Memory[val]){ flagClear(flag_N); flagSet(flag_Z); flagClear(flag_C); }if (acc > Memory[val]){ flagClear(flag_N); flagClear(flag_Z); flagSet(flag_C); } } void fCPX(Addressing addr, address val){ idata = fAddress(addr, val); if (X < Memory[val]){ flagSet(flag_N); flagClear(flag_Z); flagClear(flag_C); }if (X == Memory[val]){ flagClear(flag_N); flagSet(flag_Z); flagClear(flag_C); }if (X > Memory[val]){ flagClear(flag_N); flagClear(flag_Z); flagSet(flag_C); } } void fCPY(Addressing addr, address val){ idata = fAddress(addr, val); if (Y < Memory[val]){ flagSet(flag_N); flagClear(flag_Z); flagClear(flag_C); }if (Y == Memory[val]){ flagClear(flag_N); flagSet(flag_Z); flagClear(flag_C); }if (Y > Memory[val]){ flagClear(flag_N); flagClear(flag_Z); flagSet(flag_C); } } void fBIT(Addressing addr, address val){ idata = fAddress(addr, val); setFlag(flag_N, (Memory[val] & flag_N)); setFlag(flag_V, (Memory[val] & flag_V)); if (((Memory[val] & flag_N) & (Memory[val] & flag_V)) == 0) { flagSet(flag_Z); } else { flagSet(flag_Z); } } // Shift and Rotate Instructions void fASL(Addressing addr, address val){ idata = fAddress(addr, val); setFlag(flag_C, (val & 0x80)); acc = (val << 1); setFlagN(acc); setFlagZ(acc); } void fASL(Addressing addr, address val){ idata = fAddress(addr, val); setFlag(flag_C, (val & 0x01)); acc = (val >> 1); setFlagN(acc); setFlagZ(acc); } void fROL(Addressing addr, address val){ idata = fAddress(addr, val); setFlag(flag_C, (val & 0x80)); acc = (val << 1); acc |= (getFlag(flag_C) * 0x01); setFlagN(acc); setFlagZ(acc); } void fROR(Addressing addr, address val){ idata = fAddress(addr, val); setFlag(flag_C, (val & 0x01)); acc = (val >> 1); acc |= (getFlag(flag_C) * 0x80); setFlagN(acc); setFlagZ(acc); } // Transfer Instructions void fTAX(Addressing addr, address val){ idata = fAddress(addr, val); X = acc; setFlagN(X); setFlagZ(X); } void fTAY(Addressing addr, address val){ idata = fAddress(addr, val); Y = acc; setFlagN(Y); setFlagZ(Y); } void fTXA(Addressing addr, address val){ idata = fAddress(addr, val); acc = X; setFlagN(acc); setFlagZ(acc); } void fTYA(Addressing addr, address val){ idata = fAddress(addr, val); acc = Y; setFlagN(acc); setFlagZ(acc); } // Stack Instructions void fTSX(Addressing addr, address val){ idata = fAddress(addr, val); X = S; } void fTXS(Addressing addr, address val){ idata = fAddress(addr, val); S = X; } void fPHA(Addressing addr, address val){ idata = fAddress(addr, val); } void fPHP(Addressing addr, address val){ idata = fAddress(addr, val); } void fPLA(Addressing addr, address val){ idata = fAddress(addr, val); } void fPLP(Addressing addr, address val){ idata = fAddress(addr, val); } // Subroutine Instructions // Set/Reset Insutrctions void fCLC(Addressing addr, address val){ idata = fAddress(addr, val); flagClear(flag_C); return {1, 2}; } void fCLD(Addressing addr, address val){ idata = fAddress(addr, val); flagClear(flag_D); return {1, 2}; } void fCLI(Addressing addr, address val){ idata = fAddress(addr, val); flagClear(flag_I); return {1, 2}; } void fCLV(Addressing addr, address val){ idata = fAddress(addr, val); flagClear(flag_V); return {1, 2}; } void fSEC(Addressing addr, address val){ idata = fAddress(addr, val); flagSet(flag_C); return {1, 2}; } void fSED(Addressing addr, address val){ idata = fAddress(addr, val); flagSet(flag_D); return {1, 2}; } void fSEI(Addressing addr, address val){ idata = fAddress(addr, val); flagSet(flag_I); return {1, 2}; } // NOP/BRK Instructions void fNOP(Addressing addr, address val){ idata = fAddress(addr, val); return {1, 2}; } void fBRK(Addressing addr, address val){ idata = fAddress(addr, val); flagSet(flag_B); return {1, 7}; }