def test_graphics():
    memory = Memory()
    screen = FakeScreen(memory)
    cpu = Cpu(GRAPHICS, screen=screen, memory=memory)
    cpu.run_until_exit_or_halt()
    assert cpu.output == []
    assert memory[210] == 254
Exemplo n.º 2
0
def test_subtract():
    cpu = Cpu([])
    cpu.registers[0] = 30
    cpu.registers[1] = 20

    Sub(0, 1, 2).execute(cpu)

    assert cpu.registers[2] == 10
Exemplo n.º 3
0
def test_add_register_and_number_carry():
    cpu = Cpu([])
    cpu.registers[0] = 250

    AddRegisterAndNumber(50, 0, 1).execute(cpu)

    assert cpu.registers[1] == 44
    assert cpu.carry_flag
Exemplo n.º 4
0
def test_add():
    cpu = Cpu([])
    cpu.registers[0] = 10
    cpu.registers[1] = 20

    Add(0, 1, 2).execute(cpu)

    assert cpu.registers[2] == 30
def test_breakpoint():
    cpu = Cpu(BREAKPOINT)
    cpu.run_until_exit_or_halt()
    assert cpu.output == ["1"]
    assert cpu.halted
    cpu.halted = False
    cpu.run_until_exit_or_halt()
    assert cpu.output == ["1", "2"]
Exemplo n.º 6
0
def test_subtract_carry():
    cpu = Cpu([])
    cpu.registers[0] = 20
    cpu.registers[1] = 30

    Sub(0, 1, 2).execute(cpu)

    assert cpu.registers[2] == 246
    assert cpu.carry_flag
Exemplo n.º 7
0
def test_add_carry():
    cpu = Cpu([])
    cpu.registers[0] = 250
    cpu.registers[1] = 6

    Add(0, 1, 2).execute(cpu)

    assert cpu.registers[2] == 0
    assert cpu.carry_flag
Exemplo n.º 8
0
def run_program_from_file(filename: str, program_args: List[int]):
    if filename.endswith(".txt"):
        sprites, program = assembly.load_from_file(filename)
    else:
        program, sprites = binary.load_program_from_file(filename)
    memory = Memory(sprites=sprites)
    screen = PygameScreen(memory, filename)
    cpu = Cpu(program, args=program_args, allow_sleeps=True, screen=screen, memory=memory)
    run_program(cpu)
Exemplo n.º 9
0
def test_stack_push_and_pop():
    cpu = Cpu([])

    Push(42).execute(cpu)
    Push(43).execute(cpu)
    Pop(0).execute(cpu)
    Pop(1).execute(cpu)

    assert cpu.registers[0] == 43
    assert cpu.registers[1] == 42
Exemplo n.º 10
0
def run_example(name: str, program_args: List[int]):
    sprites, program = EXAMPLE_PROGRAMS[name]
    memory = Memory(sprites)
    screen = PygameScreen(memory, name)
    cpu = Cpu(program,
              args=program_args,
              allow_sleeps=True,
              screen=screen,
              memory=memory)
    run_program(cpu)
Exemplo n.º 11
0
def test_memory():
    cpu = Cpu([])

    cpu.registers[1] = 42
    Store(1, 123).execute(cpu)

    assert cpu.memory[123] == 42

    Load(1, 123).execute(cpu)

    assert cpu.registers[1] == 42
Exemplo n.º 12
0
def test_subroutine_call_and_return():
    cpu = Cpu([])
    cpu.instruction_pointer = 10

    CallSubroutine(42).execute(cpu)

    assert cpu.instruction_pointer == 42

    Return().execute(cpu)

    assert cpu.instruction_pointer == 10
def test_fibonacci():
    cpu = Cpu(FIBONACCI)
    cpu.run_until_exit_or_halt()
    # Fibonacci sequence loops around at 255
    assert cpu.output == ["0", "1", "1", "2", "3", "5", "8", "13", "21", "34", "55", "89", "144", "233", "121", "98"]
def test_subroutine():
    cpu = Cpu(SUBROUTINE)
    cpu.run_until_exit_or_halt()
    assert cpu.output == ["1", "2", "3"]
def test_add_two_args():
    cpu = Cpu(ADD_TWO_ARGS, args=[38, 4])
    cpu.run_until_exit_or_halt()
    assert cpu.output == ["42"]
def test_1337():
    cpu = Cpu(PRINT_1337)
    cpu.run_until_exit_or_halt()
    assert cpu.output == ["1", "3", "3", "7"]