nesemu/cpu/cpu.h

102 lines
2.2 KiB
C

//
// Created by william on 10/15/23.
//
#ifndef CPU_CPU_H
#define CPU_CPU_H
#include <stdbool.h>
#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_OVERFLOW_MASK 0x40
#define CPU_STATUS_NEGATIVE_MASK 0x80
#define CPU_STACK_ADDR 0x0100
/**
* Gets a flag from the CPU registers.
*
* @param system The system
* @param mask The flag mask
* @return The value of the flag.
*/
bool system_get_flag(System *system, byte mask);
static inline bool cpu_get_flag(CPU *cpu, byte mask) {
return cpu->status & mask;
}
/**
* Sets a flag in the CPU registers.
*
* @param system The system
* @param mask The flag mask
* @param set If the flag is set or not
*/
void system_set_flag(System *system, byte mask, bool set);
/**
* Gets the next byte in the program.
* Increases the system program counter.
*
* @param system The system
* @return The value of the next byte.
*/
byte cpu_get_next_byte(System *system);
/**
* Gets the next word in the program.
* Increases the system program counter by 2.
*
* @param system The system
* @return The value of the next word.
*/
word cpu_get_next_word(System *system);
/**
* Pushes a byte in to the stack.
*
* @param system The system
* @param value The value to push to the stack
*/
void cpu_stack_push(System *system, byte value);
/**
* Pushes the execution context to the stack.
* This includes the program counter and the CPU status.
*
* @param system The system
*/
void cpu_stack_push_context(System *system);
/**
* Pops a byte from the stack.
*
* @param system The system
* @return The value of the byte
*/
byte cpu_stack_pop(System *system);
/**
* Pops an execution context from the stack and overwrite the current context.
* This includes the program counter and the CPU status.
*
* @param system The system
*/
void cpu_stack_pop_context(System *system);
/**
* Adds wait cycles to the CPU.
*
* @param cycle_count The number of cycle to wait
*/
void cpu_add_cycles(System *system, unsigned int cycle_count);
#endif //CPU_CPU_H