2025-01-30 14:30:19 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <common.h>
|
2025-01-30 16:27:27 -07:00
|
|
|
#include <instructions.h>
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
u8 a;
|
|
|
|
u8 f;
|
|
|
|
u8 b;
|
|
|
|
u8 c;
|
|
|
|
u8 d;
|
|
|
|
u8 e;
|
|
|
|
u8 h;
|
|
|
|
u8 l;
|
|
|
|
u16 pc;
|
|
|
|
u16 sp;
|
|
|
|
} cpu_registers;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
cpu_registers regs;
|
|
|
|
|
|
|
|
//current fetch...
|
|
|
|
u16 fetched_data;
|
|
|
|
u16 mem_dest;
|
|
|
|
bool dest_is_mem;
|
|
|
|
u8 cur_opcode;
|
|
|
|
instruction *cur_inst;
|
|
|
|
|
|
|
|
bool halted;
|
|
|
|
bool stepping;
|
2025-01-30 18:38:29 -07:00
|
|
|
|
|
|
|
bool int_master_enabled;
|
2025-01-31 14:39:38 -07:00
|
|
|
bool enabling_ime;
|
2025-01-30 21:59:05 -07:00
|
|
|
u8 ie_register;
|
2025-01-31 14:39:38 -07:00
|
|
|
u8 int_flags;
|
2025-01-30 16:27:27 -07:00
|
|
|
} cpu_context;
|
2025-01-30 14:30:19 -07:00
|
|
|
|
|
|
|
void cpu_init();
|
2025-01-30 17:03:56 -07:00
|
|
|
bool cpu_step();
|
|
|
|
|
|
|
|
typedef void (*IN_PROC)(cpu_context *);
|
|
|
|
|
|
|
|
IN_PROC inst_get_processor(in_type type);
|
|
|
|
|
|
|
|
#define CPU_FLAG_Z BIT(ctx->regs.f, 7)
|
2025-01-31 14:39:38 -07:00
|
|
|
#define CPU_FLAG_N BIT(ctx->regs.f, 6)
|
|
|
|
#define CPU_FLAG_H BIT(ctx->regs.f, 5)
|
2025-01-30 18:38:29 -07:00
|
|
|
#define CPU_FLAG_C BIT(ctx->regs.f, 4)
|
|
|
|
|
2025-02-19 21:35:26 -07:00
|
|
|
cpu_context *cpu_get_context();
|
|
|
|
|
2025-01-30 21:59:05 -07:00
|
|
|
u16 cpu_read_reg(reg_type rt);
|
|
|
|
|
|
|
|
void cpu_set_reg(reg_type rt, u16 val);
|
|
|
|
|
2025-01-31 12:24:55 -07:00
|
|
|
u8 cpu_read_reg8(reg_type rt);
|
|
|
|
|
|
|
|
void cpu_set_reg8(reg_type rt, u8 val);
|
|
|
|
|
2025-01-30 21:59:05 -07:00
|
|
|
void fetch_data();
|
|
|
|
|
|
|
|
u8 cpu_get_ie_register();
|
2025-01-30 22:54:33 -07:00
|
|
|
void cpu_set_ie_register(u8 ie);
|
|
|
|
|
2025-01-31 14:39:38 -07:00
|
|
|
cpu_registers *cpu_get_regs();
|
|
|
|
|
|
|
|
u8 cpu_get_int_flags();
|
2025-01-31 17:07:09 -07:00
|
|
|
void cpu_set_int_flags(u8 value);
|
|
|
|
|
|
|
|
void inst_to_str(cpu_context *ctx, char *str);
|