2024-01-06 14:27:09 -05:00
|
|
|
//
|
|
|
|
// Created by william on 12/23/23.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "include/cpu.h"
|
|
|
|
#include "include/system.h"
|
|
|
|
#include "memory.h"
|
2024-05-06 20:23:44 -04:00
|
|
|
#include "cpu.h"
|
2024-01-06 14:27:09 -05:00
|
|
|
|
2024-05-06 20:23:44 -04:00
|
|
|
System current_sys;
|
2024-01-06 14:27:09 -05:00
|
|
|
|
2024-05-06 20:23:44 -04:00
|
|
|
void system_init() {
|
|
|
|
cpu_init();
|
2024-05-23 23:52:04 -04:00
|
|
|
ppu_init();
|
2024-05-06 20:23:44 -04:00
|
|
|
|
|
|
|
current_sys.mapper = get_mapper(MAPPER_TYPE_SIMPLE);
|
|
|
|
current_sys.cycle_count = 7;
|
2024-01-06 14:27:09 -05:00
|
|
|
}
|
|
|
|
|
2024-05-06 20:23:44 -04:00
|
|
|
void system_start() {
|
|
|
|
address pc = mem_get_word(0xfffc);
|
|
|
|
cpu_get_state()->program_counter = pc;
|
2024-01-06 14:27:09 -05:00
|
|
|
}
|
|
|
|
|
2024-05-17 00:33:37 -04:00
|
|
|
void system_next_frame() {
|
|
|
|
for (int cpu_c = 0; cpu_c < CPU_CYCLE_PER_FRAME; cpu_c++) {
|
2024-08-20 20:43:42 -04:00
|
|
|
if (!current_sys.paused) {
|
|
|
|
cpu_cycle();
|
|
|
|
}
|
2024-01-06 14:27:09 -05:00
|
|
|
|
2024-08-20 20:43:42 -04:00
|
|
|
if (!current_sys.ppu_paused) {
|
|
|
|
for (int ppu_c = 0; ppu_c < PPU_CYCLE_PER_CPU_CYCLE; ppu_c++) {
|
|
|
|
ppu_cycle();
|
|
|
|
}
|
2024-01-06 14:27:09 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-20 20:43:42 -04:00
|
|
|
void system_toggle_pause(bool pause_ppu) {
|
2024-08-03 21:51:31 -04:00
|
|
|
current_sys.paused = !current_sys.paused;
|
2024-08-20 20:43:42 -04:00
|
|
|
|
|
|
|
if (!current_sys.paused) {
|
|
|
|
current_sys.ppu_paused = false;
|
|
|
|
} else if (pause_ppu) {
|
|
|
|
current_sys.ppu_paused = true;
|
|
|
|
}
|
2024-08-03 21:51:31 -04:00
|
|
|
}
|
|
|
|
|
2024-05-06 20:23:44 -04:00
|
|
|
void system_uninit() {
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int system_get_cycles() {
|
|
|
|
return current_sys.cycle_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void system_add_cycles(unsigned int cycles) {
|
|
|
|
current_sys.cycle_count += cycles;
|
|
|
|
}
|
|
|
|
|
|
|
|
Mapper *system_get_mapper() {
|
|
|
|
return ¤t_sys.mapper;
|
2024-01-06 14:27:09 -05:00
|
|
|
}
|