nesemu/cpu/cpu.h

98 lines
2.1 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_OVERFLOW_MASK 0x40
#define CPU_STATUS_NEGATIVE_MASK 0x80
#define CPU_STACK_ADDR 0x0100
2024-01-06 14:27:09 -05:00
/**
* Gets a flag from the CPU registers.
*
* @param system The system
* @param mask The flag mask
* @return The value of the flag.
*/
bool cpu_get_flag(System *system, byte 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 cpu_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);
2023-12-23 17:10:31 -05:00
2024-01-06 14:27:09 -05:00
/**
* 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);
2023-11-26 12:11:49 -05:00
2024-01-06 14:27:09 -05:00
/**
* 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);
2023-11-26 12:11:49 -05:00
2024-01-06 14:27:09 -05:00
/**
* Pops a byte from the stack.
*
* @param system The system
* @return The value of the byte
*/
byte cpu_stack_pop(System *system);
2023-11-26 12:11:49 -05:00
2024-01-06 14:27:09 -05:00
/**
* 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);
2023-11-26 12:11:49 -05:00
2024-01-06 14:27:09 -05:00
/**
* 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);
2023-12-23 16:35:23 -05:00
2023-11-26 12:11:49 -05:00
#endif //CPU_CPU_H