/ main_6502.cpp
main_6502.cpp
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 // http://www.obelisk.me.uk/6502/ 5 6 using Byte = unsigned char; 7 using Word = unsigned short; 8 9 using u32 = unsigned int; 10 11 struct Mem { 12 static constexpr u32 MAX_MEM = 1024 * 64; 13 Byte Data[MAX_MEM]; 14 15 void Initialise() { 16 for (u32 i = 0; i < MAX_MEM; i++) { 17 Data[i] = 0; 18 } 19 } 20 }; 21 22 struct CPU { 23 Word PC; // program counter 24 Word SP; // stack pointer 25 26 Byte A, X, Y; // registers 27 28 Byte C : 1; // status flag 29 Byte Z : 1; // status flag 30 Byte I : 1; // status flag 31 Byte D : 1; // status flag 32 Byte B : 1; // status flag 33 Byte V : 1; // status flag 34 Byte N : 1; // status flag 35 36 void Reset(Mem &memory) { 37 PC = 0xFFFC; 38 SP = 0x0100; 39 C = Z = I = D = B = V = N = 0; 40 A = X = Y = 0; 41 memory.Initialise(); 42 } 43 }; 44 45 int main() { 46 Mem mem; 47 CPU cpu; 48 cpu.Reset(mem); 49 return 0; 50 }