beginning ppu

This commit is contained in:
2025-02-01 00:48:49 -07:00
parent 5206c3871e
commit f4cbfd09c8
25 changed files with 683 additions and 43 deletions

View File

@ -4,11 +4,36 @@
#include <emu.h>
#include <interrupts.h>
#include <dbg.h>
#include <timer.h>
cpu_context ctx = {0};
#define CPU_DEBUG 0
#define FILE_LOG 0
#if FILE_LOG == 1
FILE *log;
#endif
void cpu_init() {
ctx.regs.a = 0x01;
ctx.regs.f = 0xB0;
ctx.regs.b = 0x00;
ctx.regs.c = 0x13;
ctx.regs.d = 0x00;
ctx.regs.e = 0xD8;
ctx.regs.h = 0x01;
ctx.regs.l = 0x4D;
ctx.regs.sp = 0xFFFE;
ctx.regs.pc = 0x100;
ctx.ie_register = 0;
ctx.int_flags = 0;
ctx.int_master_enabled = false;
ctx.enabling_ime = false;
timer_get_context()->div = 0xABCC;
#if FILE_LOG == 1
log = fopen("log.txt", "w");
#endif
}
static void fetch_instruction() {
@ -32,7 +57,15 @@ bool cpu_step() {
if(!ctx.halted) {
u16 pc = ctx.regs.pc;
fetch_instruction();
emu_cycles(1);
#if FILE_LOG == 1
fprintf(log, "A:%02X F:%02X B:%02X C:%02X D:%02X E:%02X H:%02X L:%02X SP:%04X PC:%04X PCMEM:%02X,%02X,%02X,%02X\n",
ctx.regs.a, ctx.regs.f, ctx.regs.b, ctx.regs.c, ctx.regs.d, ctx.regs.e, ctx.regs.h, ctx.regs.l, ctx.regs.sp, pc,
bus_read(pc), bus_read(pc+1), bus_read(pc+2), bus_read(pc+3)
);
#endif
fetch_data();
#if CPU_DEBUG == 1
char flags[16];
sprintf(flags, "%c%c%c%c",
ctx.regs.f & (1 << 7) ? 'Z' : '-',
@ -52,6 +85,7 @@ bool cpu_step() {
dbg_update();
dbg_print();
#endif
execute();
} else {
@ -81,4 +115,8 @@ u8 cpu_get_ie_register(){
void cpu_set_ie_register(u8 ie){
ctx.ie_register = ie;
}
void cpu_request_interrupt(interrupt_type t) {
ctx.int_flags |= t;
}