// // Created by william on 10/15/23. // #ifndef CPU_CPU_H #define CPU_CPU_H #include #include "memory.h" // Reference: https://www.nesdev.org/wiki/Status_flags #define CPU_STATUS_CARRY_MASK 0x01 #define CPU_STATUS_ZERO_MASK 0x02 #define CPU_STATUS_INTERRUPT_DISABLE_MASK 0x04 #define CPU_STATUS_DECIMAL_MASK 0x08 #define CPU_STATUS_B_MASK 0x10 #define CPU_STATUS_I_MASK 0x20 #define CPU_STATUS_OVERFLOW_MASK 0x40 #define CPU_STATUS_NEGATIVE_MASK 0x80 #define CPU_STACK_ADDR 0x0100 // Reference: https://www.nesdev.org/obelisk-6502-guide/registers.html typedef struct { address program_counter; byte stack_pointer; byte accumulator; byte x; byte y; byte status; } CpuRegisters; enum OperandType { OPERAND_TYPE_ACCUMULATOR, OPERAND_TYPE_IMMEDIATE, OPERAND_TYPE_ADDRESS }; typedef struct { word value; enum OperandType type; bool is_page_crossing; } Operand; char* operand_name(Operand *operand); CpuRegisters* cpu_get_registers(); byte cpu_get_flag(byte mask); void cpu_set_flag(bool set, byte mask); byte cpu_get_next_byte(); word cpu_get_next_word(); byte cpu_peek_byte(address addr); word cpu_peek_word(address addr); void cpu_push_byte(byte value, address addr); void cpu_stack_push(byte value); void cpu_stack_push_context(); byte cpu_stack_pop(); void cpu_stack_pop_context(); void cpu_add_cycles(unsigned int cycle_count); #endif //CPU_CPU_H