Exemplo n.º 1
0
def test_bnnn():
    vm = Chip8VirtualMachine()
    vm.v[0x0] = 0xFF
    vm.memory[0x200] = 0xb3
    vm.memory[0x201] = 0x45

    # act
    vm.step()

    # assert
    vm.pc = 0x345 + 0xff
Exemplo n.º 2
0
def test_annn():
    # arrange
    vm = Chip8VirtualMachine()
    vm.memory[0x200] = 0xa1
    vm.memory[0x201] = 0x23

    # act
    vm.step()

    # assert
    assert vm.i == 0x123
    assert vm.pc == 0x202
Exemplo n.º 3
0
def test_fx29():
    # arrange
    vm = Chip8VirtualMachine()
    vm.loadl(0x200, 0xf429)
    vm.v[0x4] = 0x3

    # act
    vm.step()

    # assert
    assert vm.i == 0x000f
    assert vm.pc == 0x202
Exemplo n.º 4
0
def test_6xnn():
    # arrange
    vm = Chip8VirtualMachine()
    vm.memory[0x200] = 0x6a
    vm.memory[0x201] = 0xbc

    # act
    vm.step()

    # assert
    assert vm.v[0xa] == 0xbc
    assert vm.pc == 0x202
Exemplo n.º 5
0
def test_2nnn():
    # arrange
    vm = Chip8VirtualMachine()
    vm.memory[0x200] = 0x23
    vm.memory[0x201] = 0x45

    # act
    vm.step()

    # assert
    assert vm.pc == 0x345
    assert vm.stack == [0x200]
Exemplo n.º 6
0
def test_7xnn():
    # arrange
    vm = Chip8VirtualMachine()
    vm.memory[0x200] = 0x7e
    vm.memory[0x201] = 0xff
    vm.v[0xe] = 0xff

    # act
    vm.step()

    # assert
    assert vm.v[0xe] == 0xfe
    assert vm.pc == 0x202
Exemplo n.º 7
0
def test_cxnn(mocker):
    # arrange
    vm = Chip8VirtualMachine()
    vm.loadl(0x200, 0xc864)

    mocker.patch("random.randint").return_value = 0x25

    # act
    vm.step()

    # assert
    assert vm.v[0x8] == 0x24  # 0x25 & 0x64
    assert vm.pc == 0x202  # TODO: separate pc into (all that alter pc in expected way, and unexpected)
Exemplo n.º 8
0
def test_fx1e():
    # arrange
    vm = Chip8VirtualMachine()
    vm.loadl(0x200, 0xf31e)
    vm.v[0x3] = 0x44

    # act
    vm.step()

    # assert
    assert vm.v[0x3] == 0x44
    assert vm.i == 0x0044
    assert vm.pc == 0x202
Exemplo n.º 9
0
def test_9xy0__vx_equals_vy():
    # arrange
    vm = Chip8VirtualMachine()  # TODO: put in "provider" function
    vm.memory[0x200] = 0x96
    vm.memory[0x201] = 0x30
    vm.v[0x6] = 0x14
    vm.v[0x3] = 0x14

    # act
    vm.step()

    # assert
    assert vm.pc == 0x202
Exemplo n.º 10
0
def test_fx15():
    # arrange
    vm = Chip8VirtualMachine()
    vm.loadl(0x200, 0xfa15)
    vm.v[0xa] = 0xff
    # TODO: add v out of bounds check

    # act
    vm.step()

    # assert
    assert vm.delay_timer_register == 0xff
    assert vm.v[0xa] == 0xff
    assert vm.pc == 0x202
Exemplo n.º 11
0
def test_fx18():
    # arrange
    vm = Chip8VirtualMachine()
    vm.loadl(0x200, 0xf918)
    vm.v[0x9] = 0x25
    # TODO: add v out of bounds check

    # act
    vm.step()

    # assert
    assert vm.sound_timer_register == 0x25  # TODO: sound timer only goes down on next, right? and the sound?
    assert vm.v[0x9] == 0x25
    assert vm.pc == 0x202
Exemplo n.º 12
0
def test_fx07():
    # arrange
    vm = Chip8VirtualMachine()
    vm.loadl(0x200, 0xf507)
    vm.delay_timer_register = 0x33
    # TODO: add v out of bounds check

    # act
    vm.step()

    # assert
    assert vm.delay_timer_register == 0x33
    assert vm.v[0x5] == 0x33
    assert vm.pc == 0x202
Exemplo n.º 13
0
def test_00e0(mocker):
    # arrange
    vm = Chip8VirtualMachine()
    vm.memory[0x200] = 0x00
    vm.memory[0x201] = 0xe0

    mocker.spy(vm.screen, "cls")

    # act
    vm.step()
    # will work by xor

    # assert
    assert vm.screen.cls.call_count == 1
    assert vm.pc == 0x202
Exemplo n.º 14
0
def test_00ee():
    # arrange
    vm = Chip8VirtualMachine()
    vm.pc = 0x300
    vm.stack = [0xaaa, 0x200]

    vm.memory[0x300] = 0x00
    vm.memory[0x301] = 0xee

    # act
    vm.step()

    # assert
    assert vm.pc == 0x200
    assert vm.stack == [0xaaa]
Exemplo n.º 15
0
def test_8xy7_with_borrow():
    # arrange
    vm = Chip8VirtualMachine()
    vm.memory[0x200] = 0x82
    vm.memory[0x201] = 0x87
    vm.v[0x2] = 0x22
    vm.v[0x8] = 0x20

    # step
    vm.step()

    # assert
    assert vm.v[0x2] == 0xfd  # guess TODO: verify
    assert vm.v[0x8] == 0x20
    assert vm.v[0xf] == 0x00  # borrow
    assert vm.pc == 0x202
Exemplo n.º 16
0
def test_8xy5_without_borrow():
    # arrange
    vm = Chip8VirtualMachine()
    vm.memory[0x200] = 0x82
    vm.memory[0x201] = 0x85
    vm.v[0x2] = 0x0b
    vm.v[0x8] = 0x05

    # step
    vm.step()

    # assert
    assert vm.v[0x2] == 0x06
    assert vm.v[0x8] == 0x05
    assert vm.v[0xf] == 0x01  # no borrow
    assert vm.pc == 0x202
Exemplo n.º 17
0
def test_1nnn():
    # command -- test modification
    # TODO: add "docstring"

    # arrange
    vm = Chip8VirtualMachine()

    # TODO: a "load" or "set" would be better: vm.memory.set(0x1a, 0xbc) or ('0x1abc')
    vm.memory[0x200] = 0x1a
    vm.memory[0x201] = 0xbc

    # act
    vm.step()

    # assert
    assert vm.pc == 0xabc
Exemplo n.º 18
0
def test_8xy4_with_carry():
    # arrange
    vm = Chip8VirtualMachine()
    vm.memory[0x200] = 0x82
    vm.memory[0x201] = 0x84
    vm.v[0x2] = 0xff
    vm.v[0x8] = 0x20

    # act
    vm.step()

    # assert
    assert vm.v[0x2] == 0x1f
    assert vm.v[0x8] == 0x20
    assert vm.v[0xf] == 0x01
    assert vm.pc == 0x202
Exemplo n.º 19
0
def test_8xy7_without_borrow():
    # arrange
    vm = Chip8VirtualMachine()
    vm.memory[0x200] = 0x82
    vm.memory[0x201] = 0x87
    vm.v[0x2] = 0x11
    vm.v[0x8] = 0x20

    # step
    vm.step()

    # assert
    assert vm.v[0x2] == 0x0f
    assert vm.v[0x8] == 0x20
    assert vm.v[0xf] == 0x01  # no borrow
    assert vm.pc == 0x202
Exemplo n.º 20
0
    def __init__(self, master):
        self._master = master
        super().__init__(self._master)

        self._configure_gui()
        self._create_widgets()

        # TODO: experimental
        self.vm = Chip8VirtualMachine(
            screen_set=self._set,
            screen_unset=self._unset)  # TODO: needs better

        # self.vm.loadf("Chip8 Picture.ch8")
        # self.vm.loadf("IBM Logo.ch8")

        # TODO: check error on this one
        # self.vm.loadf("Chip8 emulator Logo [Garstyciuks].ch8")

        # TODO: need to implement wait for key
        # self.vm.loadf("Chip-8 Pack/Chip-8 Programs/Random Number Test [Matthew Mikolay, 2010].ch8")

        # TODO: check error no screen instructions
        # self.vm.loadf("Chip-8 Pack/Chip-8 Programs/Division Test [Sergey Naydenov, 2010].ch8")

        # TODO: check error no screen instructions
        # self.vm.loadf("Chip-8 Pack/Chip-8 Programs/SQRT Test [Sergey Naydenov, 2010].ch8")

        self.vm.loadf("Chip-8 Pack/Chip-8 Demos/Maze [David Winter, 199x].ch8")
        # TODO: add this to tests (store rnd instructs)...

        #self.vm.loadf("Chip-8 Pack/Chip-8 Demos/Maze (alt) [David Winter, 199x].ch8")

        # TOdO: add this to tests -- needs a screen model with gui -- takes a bit to create
        #self.vm.loadf("Chip-8 Pack/Chip-8 Demos/Sirpinski [Sergey Naydenov, 2010].ch8")

        # TODO: yup, nowhere near able to run this one
        #self.vm.loadf("Chip-8 Pack/Chip-8 Demos/Trip8 Demo (2008) [Revival Studios].ch8")

        #self.vm.loadf("Chip-8 Pack/Chip-8 Demos/Zero Demo [zeroZshadow, 2007].ch8")

        #self.vm.loadf("Chip-8 Pack/Chip-8 Games/15 Puzzle [Roger Ivie] (alt).ch8")  # TODO: check error -- run all by david winter's emul first

        # self.vm.loadf("Chip-8 Pack/Chip-8 Games/Airplane.ch8") -- TODO: check erorr

        self.after(0, self._step)
Exemplo n.º 21
0
def test_fx65():
    # arrange
    vm = Chip8VirtualMachine()
    vm.loadl(0x200, 0xf365)

    vm.i = 0x250
    vm.loadl(0x250, 0x1234, 0x5678)

    # act
    vm.step()

    # assert
    assert vm.pc == 0x202
    assert vm.i == 0x250
    assert vm.v[0x0] == vm.memory[0x250] == 0x12
    assert vm.v[0x1] == vm.memory[0x251] == 0x34
    assert vm.v[0x2] == vm.memory[0x252] == 0x56
    assert vm.v[0x3] == vm.memory[0x253] == 0x78
Exemplo n.º 22
0
def test_fx55():
    # arrange
    vm = Chip8VirtualMachine()
    vm.loadl(0x200, 0xf455)
    for offset, i in enumerate(range(0x05), start=0xA):
        vm.v[i] = offset
    vm.i = 0x250

    # act
    vm.step()

    # assert
    assert vm.i == 0x250
    assert vm.memory[0x250] == vm.v[0x0] == 0xa
    assert vm.memory[0x251] == vm.v[0x1] == 0xb
    assert vm.memory[0x252] == vm.v[0x2] == 0xc
    assert vm.memory[0x253] == vm.v[0x3] == 0xd
    assert vm.memory[0x254] == vm.v[0x4] == 0xe
    assert vm.pc == 0x202
Exemplo n.º 23
0
def vm():
    return Chip8VirtualMachine()