// 6502.h // Main elements of the 6502 CPU #include"6502.h" byte acc, X, Y, P, S = 0x00; address PC = 0x0000; byte* Memory; byte getFlag(byte flag) { return ((P & flag) == flag) ? 1 : 0; } void SetFlag(byte flag, int x) { if (x == 1){ if ((P & flag) == 0x0) P += flag; }else if (x == 0){ if ((P & flag) == flag) P -= flag; } else{ fprintf(stderr, "SetFlag() passed arg neither 0 or 1"); } } void flagSet(byte flag){ P |= flag; } void flagClear(byte flag){ P &= ~flag; } // Functions which perform reusable routines for finding if a specific flag should be set. void SetFlagN(byte x){ /*if ((x & flag_N) == flag_N) SetFlag(flag_N, 1); else SetFlag(flag_N, 0);*/ P = (x & flag_N) | (P & ~flag_N); } //Perform prior to any changes TODO: FIX THIS! WTF WERE YOU THINKING? void SetFlagV(byte x, byte y){ address z = (address)x + (address)y; if (z > 0xFF) SetFlag(flag_V, 1); else SetFlag(flag_V, 0); } /*void SetFlagB(){ //WORK ON SetFlag(flag_B, 1); }*/ /*void SetFlagD(){ SetFlag(flag_D, 1); }*/ /*void SetFlagI(){ //WORK ON SetFlag(flag_Z, 1); }*/ void SetFlagZ(int x){ if (x == 0) SetFlag(flag_Z, 1); else SetFlag(flag_Z, 0); } /*void SetFlagC(){ SetFlag(flag_Z, 1); }*/ /*byte GetMemory(address x){ return Memory[x]; } void SetMemory(address x, byte y){ Memory[x] = y; }*/ byte GetStack() { S--; return GetMemory(0x01FF - S); } void SetStack(byte x) { SetMemory(0x01FF - S, x); S++; }