nesemu/cpu/cpu.h

66 lines
1.4 KiB
C
Raw Normal View History

2023-11-26 12:11:49 -05:00
//
// Created by william on 10/15/23.
//
#ifndef CPU_CPU_H
#define CPU_CPU_H
#include <stdbool.h>
2023-12-03 00:27:07 -05:00
#include "memory.h"
2023-11-26 12:11:49 -05:00
// 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;
2023-12-23 17:10:31 -05:00
char* operand_name(Operand *operand);
2023-11-26 12:11:49 -05:00
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();
2023-12-23 16:35:23 -05:00
void cpu_add_cycles(unsigned int cycle_count);
2023-11-26 12:11:49 -05:00
#endif //CPU_CPU_H