Split project into multiple files

This commit is contained in:
2025-07-21 20:43:53 -04:00
parent 817827b4ad
commit ffef7101fa
11 changed files with 430 additions and 343 deletions

54
src/cpu.cpp Normal file
View File

@@ -0,0 +1,54 @@
//
// Created by Palindromic Bread Loaf on 7/21/25.
//
#include "cpu.h"
#include <iostream>
// CPU Implementation
void CPU::Reset() {
A = X = Y = 0;
SP = 0x01FF;
PC = 0x8000; // Will be loaded from reset vector
P = 0x34; // Start in emulation mode
DB = PB = 0;
D = 0;
cycles = 0;
}
void CPU::Step() {
ExecuteInstruction();
}
void CPU::ExecuteInstruction() {
uint8_t opcode = bus->Read(PC++);
// TODO: Actual Opcode decoding
switch (opcode) {
case 0xEA: NOP(); break;
case 0xA9: LDA(); break;
default:
std::cout << "Unknown opcode: 0x" << std::hex << (int)opcode << std::endl;
break;
}
cycles++;
}
void CPU::NOP() {
// No operation
}
void CPU::LDA() {
// Load accumulator - immediate mode
if (P & FLAG_M) {
// 8-bit mode
A = (A & 0xFF00) | bus->Read(PC++);
} else {
// 16-bit mode
A = bus->Read16(PC);
PC += 2;
}
}