~sircmpwn/hdmg

c3847edaf077f121d61a257e4d8f725a5ae387dd — Drew DeVault 1 year, 3 months ago e0405e1
hdmg: print CPU state on SIGUSR1
2 files changed, 23 insertions(+), 0 deletions(-)

M cmd/hdmg/main.ha
M dmg/mmu.ha
M cmd/hdmg/main.ha => cmd/hdmg/main.ha +22 -0
@@ 10,6 10,7 @@ use sdl2::{
	SDL_RendererFlags,
	SDL_WindowFlags
};
use unix::signal;

def CLOCK_NANOHZ: i64 = dmg::CLOCK_HZ * 1000000;



@@ 21,6 22,8 @@ export type state = struct {
	render: *sdl2::SDL_Renderer,
};

let gstate: *state = null: *state;

export fn main() void = {
	const file = os::open(os::args[1])!;
	const cart = cart::load(file)!;


@@ 53,6 56,8 @@ export fn main() void = {
		window = win,
		render = render,
	};
	gstate = &state;
	signal::handle(signal::SIGUSR1, &handle_usr1);

	for (!state.quit) {
		update(&state)!;


@@ 82,3 87,20 @@ fn draw(state: *state) (void | sdl2::error) = {
	sdl2::SDL_RenderClear(state.render)?;
	sdl2::SDL_RenderPresent(state.render);
};

fn handle_usr1(sig: int, info: *signal::siginfo, uctx: *void) void = {
	fmt::errorfln("AF   {:04x}\tBC   {:04x}\tDE   {:04x}\tHL  {:04x}",
		gstate.dmg.cpu.regs.AF,
		gstate.dmg.cpu.regs.BC,
		gstate.dmg.cpu.regs.DE,
		gstate.dmg.cpu.regs.HL)!;
	fmt::errorfln("PC   {:04x}\tSP   {:04x}",
		gstate.dmg.cpu.regs.PC,
		gstate.dmg.cpu.regs.SP)!;
	fmt::errorfln("IME  {: 4x}\tIE   {: 4x}\tIF   {: 4x}",
		gstate.dmg.cpu.int_ime,
		gstate.dmg.cpu.int_ie,
		gstate.dmg.cpu.int_if)!;
	fmt::errorfln("HALT {: 4x}\tSTOP {: 4x}",
		gstate.dmg.cpu.halt, gstate.dmg.cpu.stop)!;
};

M dmg/mmu.ha => dmg/mmu.ha +1 -0
@@ 2,6 2,7 @@
// or something. Dunno.
use dmg::cart;
use sm83;
use fmt; // XXX TEMP

export type mmu = struct {
	sm83::mmu,