~sircmpwn/hdmg

bb71f7203384bfe41ffe5c957f9d838edeb54bac — Drew DeVault 1 year, 6 months ago 46ec035
sm83: fix ALU flag resets
2 files changed, 6 insertions(+), 6 deletions(-)

M sm83/flags.ha
M sm83/instr.ha
M sm83/flags.ha => sm83/flags.ha +3 -3
@@ 25,7 25,7 @@ fn flag_h_add16(a1: u16, a2: u16) u8 = {
};

fn andflags(cpu: *sm83) void = {
	cpu.regs.F &= FL_Z | FL_C | FL_N | FL_H;
	cpu.regs.F &= ~(FL_Z | FL_C | FL_N | FL_H);
	cpu.regs.F |= FL_H;
	if (cpu.regs.A == 0) {
		cpu.regs.F |= FL_Z;


@@ 33,14 33,14 @@ fn andflags(cpu: *sm83) void = {
};

fn orflags(cpu: *sm83) void = {
	cpu.regs.F &= FL_Z | FL_C | FL_N | FL_H;
	cpu.regs.F &= ~(FL_Z | FL_C | FL_N | FL_H);
	if (cpu.regs.A == 0) {
		cpu.regs.F |= FL_Z;
	};
};

fn xorflags(cpu: *sm83) void = {
	cpu.regs.F &= FL_Z | FL_C | FL_N | FL_H;
	cpu.regs.F &= ~(FL_Z | FL_C | FL_N | FL_H);
	if (cpu.regs.A == 0) {
		cpu.regs.F |= FL_Z;
	};

M sm83/instr.ha => sm83/instr.ha +3 -3
@@ 203,7 203,7 @@ fn exec_ld_sp_hl(cpu: *sm83) void = cpu.regs.SP = cpu.regs.HL;

fn exec_ld_hl_sp_r8(cpu: *sm83) void = {
	cpu.regs.HL = cpu.regs.SP + fetchd8(cpu);
	cpu.regs.F &= FL_Z | FL_N | FL_C | FL_H;
	cpu.regs.F &= ~(FL_Z | FL_N | FL_C | FL_H);
	// TODO: Figure out what to do with the C and H flags here
};



@@ 464,7 464,7 @@ fn exec_cpl(cpu: *sm83) void = {
fn dec8(cpu: *sm83, reg: *u8) void = {
	const old = *reg;
	*reg -= 1;
	cpu.regs.F &= FL_Z | FL_N | FL_H;
	cpu.regs.F &= ~(FL_Z | FL_N | FL_H);
	cpu.regs.F |= flag_z(cpu.regs.A) | FL_N | flag_h_sub8(old, 1, 0);
};



@@ 475,7 475,7 @@ fn dec16(cpu: *sm83, reg: *u16) void = {
fn inc8(cpu: *sm83, reg: *u8) void = {
	const old = *reg;
	*reg += 1;
	cpu.regs.F &= FL_Z | FL_N | FL_H;
	cpu.regs.F &= ~(FL_Z | FL_N | FL_H);
	cpu.regs.F |= flag_z(*reg) | flag_h_add8(old, 1, 0);
};