mirror of
https://github.com/pevans/erc-c.git
synced 2024-11-23 08:31:55 +00:00
Remove modify_status() function
Also rewrite tests to use macros
This commit is contained in:
parent
8d0cf264d7
commit
f8bda4ebd3
@ -172,7 +172,6 @@ extern vm_8bit mos6502_pop_stack(mos6502 *);
|
||||
extern void mos6502_execute(mos6502 *);
|
||||
extern void mos6502_free(mos6502 *);
|
||||
extern void mos6502_last_executed(mos6502 *, vm_8bit *, vm_8bit *, vm_16bit *);
|
||||
extern void mos6502_modify_status(mos6502 *, vm_8bit, int, int);
|
||||
extern void mos6502_push_stack(mos6502 *, vm_8bit);
|
||||
extern void mos6502_set(mos6502 *, size_t, vm_8bit);
|
||||
extern void mos6502_set16(mos6502 *, size_t, vm_16bit);
|
||||
|
@ -237,58 +237,6 @@ mos6502_set_status(mos6502 *cpu, vm_8bit status)
|
||||
cpu->P = status;
|
||||
}
|
||||
|
||||
/*
|
||||
* In contrast, the modify_status function will conditionally set the
|
||||
* contents of certain bits, based upon the value of the operand. Those
|
||||
* bits are the negative, overflow, carry, and zero flags.
|
||||
*/
|
||||
void
|
||||
mos6502_modify_status(mos6502 *cpu, vm_8bit status, int orig, int result)
|
||||
{
|
||||
int bit7o, bit7r;
|
||||
|
||||
if (status & MOS_NEGATIVE) {
|
||||
cpu->P &= ~MOS_NEGATIVE;
|
||||
if (result & 0x80) {
|
||||
cpu->P |= MOS_NEGATIVE;
|
||||
}
|
||||
}
|
||||
|
||||
if (status & MOS_OVERFLOW) {
|
||||
cpu->P &= ~MOS_OVERFLOW;
|
||||
|
||||
bit7o = orig & 0x80;
|
||||
bit7r = result & 0x80;
|
||||
|
||||
// If the result of the operation is such that the sign bit,
|
||||
// that is to say bit 7, changes, then we have overflowed. E.g.:
|
||||
// 90 + 40 = 130, but that's actually -124 in two's complement.
|
||||
// So if you are paying attention to the sign, you have
|
||||
// overflowed from a positive into a negative result.
|
||||
if (bit7o ^ bit7r) {
|
||||
cpu->P |= MOS_OVERFLOW;
|
||||
}
|
||||
}
|
||||
|
||||
if (status & MOS_CARRY) {
|
||||
cpu->P &= ~MOS_CARRY;
|
||||
|
||||
// The result of the operation requires 9 bits to hold, but we
|
||||
// can only hold 8 bits; rather than lose that bit's value, it
|
||||
// is held in the carry bit of the P register.
|
||||
if (result > 0xFF) {
|
||||
cpu->P |= MOS_CARRY;
|
||||
}
|
||||
}
|
||||
|
||||
if (status & MOS_ZERO) {
|
||||
cpu->P &= ~MOS_ZERO;
|
||||
if ((result & 0xff) == 0) {
|
||||
cpu->P |= MOS_ZERO;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the instruction that is mapped to a given opcode.
|
||||
*/
|
||||
|
@ -37,24 +37,19 @@ Test(mos6502, pop_stack)
|
||||
|
||||
Test(mos6502, modify_status)
|
||||
{
|
||||
mos6502_modify_status(cpu, MOS_NEGATIVE, 130, 130);
|
||||
MOS_CHECK_N(130);
|
||||
cr_assert_eq(cpu->P & MOS_NEGATIVE, MOS_NEGATIVE);
|
||||
mos6502_modify_status(cpu, MOS_NEGATIVE, 123, 123);
|
||||
MOS_CHECK_N(123);
|
||||
cr_assert_neq(cpu->P & MOS_NEGATIVE, MOS_NEGATIVE);
|
||||
|
||||
mos6502_modify_status(cpu, MOS_OVERFLOW, 123, 133);
|
||||
MOS_CHECK_V(123, 133);
|
||||
cr_assert_eq(cpu->P & MOS_OVERFLOW, MOS_OVERFLOW);
|
||||
mos6502_modify_status(cpu, MOS_OVERFLOW, 44, 44);
|
||||
MOS_CHECK_V(44, 44);
|
||||
cr_assert_neq(cpu->P & MOS_OVERFLOW, MOS_OVERFLOW);
|
||||
|
||||
mos6502_modify_status(cpu, MOS_CARRY, 230, 260);
|
||||
cr_assert_eq(cpu->P & MOS_CARRY, MOS_CARRY);
|
||||
mos6502_modify_status(cpu, MOS_CARRY, 30, 190);
|
||||
cr_assert_neq(cpu->P & MOS_CARRY, MOS_CARRY);
|
||||
|
||||
mos6502_modify_status(cpu, MOS_ZERO, 0, 0);
|
||||
MOS_CHECK_Z(0);
|
||||
cr_assert_eq(cpu->P & MOS_ZERO, MOS_ZERO);
|
||||
mos6502_modify_status(cpu, MOS_ZERO, 1, 1);
|
||||
MOS_CHECK_Z(1);
|
||||
cr_assert_neq(cpu->P & MOS_ZERO, MOS_ZERO);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user