~sircmpwn/hdmg

0d3a85629c17df219379a68ce15c92837239824b — Drew DeVault 1 year, 6 months ago 76de834
dmg: add dmg struct
2 files changed, 29 insertions(+), 0 deletions(-)

M cmd/hdmg/main.ha
A dmg/dmg.ha
M cmd/hdmg/main.ha => cmd/hdmg/main.ha +3 -0
@@ 9,4 9,7 @@ export fn main() void = {
	const cart = cart::load(file)!;
	defer cart::cart_free(cart);
	fmt::println(cart.title)!;

	const dmg = dmg::init(cart);
	defer dmg::finish(&dmg);
};

A dmg/dmg.ha => dmg/dmg.ha +26 -0
@@ 0,0 1,26 @@
use dmg::cart;
use sm83;

export type dmg = struct {
	cart: *cart::cart,
	cpu: sm83::sm83,
	mmu: *mmu,
};

// Initializes a new DMG emulator.
export fn init(cart: *cart::cart) dmg = {
	let mmu = new_mmu(cart);
	let cpu = sm83::init(mmu);
	// XXX: Other power-on registers? From which BIOS model?
	cpu.regs.PC = 0x100;
	cpu.regs.SP = 0xFFFE;
	return dmg {
		cart = cart,
		cpu = cpu,
		mmu = mmu,
	};
};

export fn finish(dmg: *dmg) void = {
	mmu_free(dmg.mmu);
};