nesemu/include/system.h

67 lines
1.3 KiB
C

//
// Created by william on 12/23/23.
//
#include "types.h"
#include "mapper.h"
#include "ppu.h"
#ifndef NESEMULATOR_SYSTEM_H
#define NESEMULATOR_SYSTEM_H
// NTSC NES Master Clock (~21.47 MHz)
#define MASTER_CLOCK 21477272
#define CPU_CLOCK_DIVISOR 12
#define PPU_CLOCK_DIVISOR 4
#define FRAME_RATE 60
#define PPU_REGISTERS_BASE_ADDR 0x2000
#define PPU_REGISTER_OAM_DMA_ADDR 0x4014
#define APU_REGISTERS_COUNT 24
// Reference: https://www.nesdev.org/obelisk-6502-guide/registers.html
typedef struct cpu {
address program_counter;
byte stack_pointer;
byte accumulator;
byte x;
byte y;
byte status;
bool oam_dma_triggered;
} CPU;
typedef struct system {
void *rom_header;
CPU cpu;
PPU ppu;
Mapper mapper;
ram ram;
byte apu_registers[APU_REGISTERS_COUNT];
unsigned long cycle_count;
} System;
/**
* Initialize all components of a system.
*
* @param system The system to initialize
*/
void system_init(System *system);
void system_start(System *system);
/**
* Starts the main loop of a system.
*
* @param system The system
*/
void system_loop(System *system);
/**
* De-initialize the components of a system.
*
* @param system The system to de-initialize
*/
void system_uninit(System *system);
#endif //NESEMULATOR_SYSTEM_H