57 lines
1.2 KiB
C
57 lines
1.2 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
|
|
|
|
#define FRAME_RATE 60
|
|
#define MASTER_CLOCK 21477272 // NTSC NES Master Clock (~21.47 MHz)
|
|
#define MASTER_CYCLE_PER_FRAME (MASTER_CLOCK / FRAME_RATE)
|
|
#define CPU_CLOCK_DIVISOR 12
|
|
#define CPU_CYCLE_PER_FRAME (MASTER_CYCLE_PER_FRAME / CPU_CLOCK_DIVISOR)
|
|
#define PPU_CLOCK_DIVISOR 4
|
|
#define PPU_CYCLE_PER_CPU_CYCLE (CPU_CLOCK_DIVISOR / PPU_CLOCK_DIVISOR)
|
|
|
|
#define PPU_REGISTERS_BASE_ADDR 0x2000
|
|
#define PPU_REGISTER_OAM_DMA_ADDR 0x4014
|
|
#define APU_REGISTERS_COUNT 24
|
|
|
|
typedef struct system {
|
|
void *rom_header;
|
|
Mapper mapper;
|
|
byte apu_registers[APU_REGISTERS_COUNT];
|
|
unsigned long cycle_count;
|
|
} System;
|
|
|
|
/**
|
|
* Initialize all components of a system.
|
|
*/
|
|
void system_init();
|
|
|
|
void system_start();
|
|
|
|
void system_next_frame();
|
|
|
|
/**
|
|
* Starts the main loop of a system.
|
|
*/
|
|
void system_loop();
|
|
|
|
/**
|
|
* De-initialize the components of a system.
|
|
*/
|
|
void system_uninit();
|
|
|
|
unsigned int system_get_cycles();
|
|
|
|
void system_add_cycles(unsigned int cycles);
|
|
|
|
Mapper *system_get_mapper();
|
|
|
|
#endif //NESEMULATOR_SYSTEM_H
|