def test_ld_byte(): asm = """ LD V0, #12 EXIT """ emulator_debug = run_asm(asm) assert emulator_debug.get("V0") == int("12", 16)
def test_shr(): asm = """ LD V0, #2 SHR V0 EXIT """ emulator_debug = run_asm(asm) assert emulator_debug.get("V0") == 1
def test_shl(): asm = """ LD V0, #1 SHL V0 EXIT """ emulator_debug = run_asm(asm) assert emulator_debug.get("V0") == 2
def test_add_byte(): asm = """ LD V0, #1 ADD V0, #1 EXIT """ emulator_debug = run_asm(asm) assert emulator_debug.get("V0") == 2
def test_rnd_v0_is_zero(): asm = """ LD V0, #0 RND V0, #0 EXIT """ emulator_debug = run_asm(asm) assert emulator_debug.get("V0") == 0
def test_rnd(): asm = """ LD V0, #0 RND V0, #f EXIT """ emulator_debug = run_asm(asm) assert emulator_debug.get("V0") != 0
def test_se_byte(): asm = """ LD V0, #1 SE V0, #1 LD V0, #2 EXIT """ emulator_debug = run_asm(asm) assert emulator_debug.get("V0") == 1
def test_shl_with_first_bit_one(): asm = """ LD V0, #80 SHL V0 EXIT """ emulator_debug = run_asm(asm) assert emulator_debug.get("V0") == 0 assert emulator_debug.get("VF") == 1
def test_or(): asm = """ LD V0, #1 LD V1, #3 OR V0, V1 EXIT """ emulator_debug = run_asm(asm) assert emulator_debug.get("V0") == 3
def test_call(): asm = """ CALL test EXIT test: EXIT """ emulator_debug = run_asm(asm) assert emulator_debug.get("PC") == 0x200 + 6
def test_ld_register(): asm = """ LD V0, #1 LD V1, #2 LD V0, V1 EXIT """ emulator_debug = run_asm(asm) assert emulator_debug.get("V0") == int("2", 16)
def test_shr_with_last_bit_one(): asm = """ LD V0, #3 SHR V0 EXIT """ emulator_debug = run_asm(asm) assert emulator_debug.get("V0") == 1 assert emulator_debug.get("VF") == 1
def test_sub_register(): asm = """ LD V0, #1 LD V1, #1 SUB V0, V1 EXIT """ emulator_debug = run_asm(asm) assert emulator_debug.get("V0") == 0
def test_subn_not_borrow(): asm = """ LD V0, #1 LD V1, #2 SUBN V0, V1 EXIT """ emulator_debug = run_asm(asm) assert emulator_debug.get("V0") == 1 assert emulator_debug.get("VF") == 1
def test_add_register_with_carry(): asm = """ LD V0, #1 LD V1, #FF ADD V0, V1 EXIT """ emulator_debug = run_asm(asm) assert emulator_debug.get("V0") == 0 assert emulator_debug.get("VF") == 1
def test_sub_register_with_carry(): asm = """ LD V0, #f LD V1, #1 SUB V0, V1 EXIT """ emulator_debug = run_asm(asm) assert emulator_debug.get("V0") == 14 assert emulator_debug.get("VF") == 1
def test_se_register(): asm = """ LD V0, #1 LD V1, #1 LD V3, #1 SE V0, V1 LD V3, #2 EXIT """ emulator_debug = run_asm(asm) assert emulator_debug.get("V3") == 1
def test_jp(): asm = """ LD V0, #1 JP test EXIT test: LD V0, #2 EXIT """ emulator_debug = run_asm(asm) assert emulator_debug.get("V0") == 2 assert emulator_debug.get("PC") == 0x200 + 8
def test_jp_with_v0(): # hex #204 + #2 is the EXIT row asm = """ LD V0, #2 JP V0, #204 LD V0, #1 EXIT """ emulator_debug = run_asm(asm) assert emulator_debug.get("V0") == 2 assert emulator_debug.get("PC") == 0x200 + 6