Esempio n. 1
0
TEST(Cpu, SBC_NoUnderflow) {
    Cpu cpu;
    ASSERT_EQ(0, cpu.P.read());
    cpu.i_sec();  // set carry instruction
    cpu.A.write(0x01);
    cpu.i_sbc(0x01);
    ASSERT_EQ(0, cpu.A.read());
    ASSERT_TRUE(cpu.P.has_carry());
    ASSERT_TRUE(cpu.P.has_zero());
    ASSERT_FALSE(cpu.P.has_negative());
    ASSERT_FALSE(cpu.P.has_overflow());
}
Esempio n. 2
0
TEST(Cpu, ADC_Overflow) {
    Cpu cpu;
    ASSERT_EQ(0, cpu.P.read());
    cpu.i_sec();  // set carry instruction
    cpu.A.write(0xff);
    cpu.i_adc(0x01);
    // 0xff + 0x01 + 1 (carry) overflows to one
    ASSERT_EQ(1, cpu.A.read());
    ASSERT_TRUE(cpu.P.has_carry());
    ASSERT_FALSE(cpu.P.has_zero());
    ASSERT_FALSE(cpu.P.has_negative());
    ASSERT_FALSE(cpu.P.has_overflow());
}
Esempio n. 3
0
TEST(Cpu, SBC_OverflowFlag_Negative) {
    Cpu cpu;
    ASSERT_EQ(0, cpu.P.read());
    cpu.i_sec();
    cpu.A.write(0x01);
    cpu.i_sbc(0x02);
    // 1 - 2 = -1 is allowed to be negative, so
    // the overflow flag should be cleared
    ASSERT_EQ(0xff, cpu.A.read());
    ASSERT_FALSE(cpu.P.has_overflow());
    ASSERT_TRUE(cpu.P.has_negative());
    ASSERT_FALSE(cpu.P.has_zero());
    ASSERT_FALSE(cpu.P.has_carry());
}
Esempio n. 4
0
TEST(Cpu, SBC_OverflowFlag_Positive) {
    Cpu cpu;
    ASSERT_EQ(0, cpu.P.read());
    cpu.i_sec();
    cpu.A.write(0x01);  // 1
    cpu.i_sbc(0x80);      // -128
    // 1 - (-128) = 1 + 128 = 129
    // But this overflows in two's complement math:
    // 0x01 - 0x80 = 0x81 = -127
    ASSERT_EQ(0x81, cpu.A.read());
    ASSERT_TRUE(cpu.P.has_overflow());
    ASSERT_TRUE(cpu.P.has_negative());
    ASSERT_FALSE(cpu.P.has_zero());
    ASSERT_FALSE(cpu.P.has_carry());
}
Esempio n. 5
0
TEST(Cpu, ADC_NoOverflow) {
    Cpu cpu;
    ASSERT_EQ(0, cpu.P.read());
    cpu.i_sec();  // set carry instruction
    cpu.A.write(0x7f);
    cpu.i_adc(0x01);
    // 0x7f + 0x01 + 1 = 0x81
    ASSERT_EQ(0x81, cpu.A.read());
    ASSERT_FALSE(cpu.P.has_carry());
    ASSERT_FALSE(cpu.P.has_zero());
    ASSERT_TRUE(cpu.P.has_negative());

    // interpreting inputs as signed two's complement values, we added
    // a positive to a positive (0x7f + 0x01) and got a negative (0x81)
    // so we should see the overflow flag get set
    ASSERT_TRUE(cpu.P.has_overflow());
}