Beispiel #1
0
    def test_clock(self):
        memory = [0] * 0x10000
        new_memory = [0xEA, 0x00, 0x00]

        # Assign new memory
        for val, i in enumerate(new_memory):
            memory[val] = i

        cpu = LR35902(memory)

        cpu.clock()
        self.assertEqual(1, 1)
Beispiel #2
0
    def test_ld_nn_n(self):
        memory = [0] * 0x10000
        new_memory = [0x06, 0x53]

        # Assign new memory
        for val, i in enumerate(new_memory):
            memory[val] = i

        cpu = LR35902(memory)

        cpu.clock()

        self.assertEqual(cpu.B, 0x53)
Beispiel #3
0
    def test_cb_swap(self):
        memory = [0] * 0x10000
        new_memory = [0x06, 0x53, 0xCB, 0x30]

        # Assign new memory
        for val, i in enumerate(new_memory):
            memory[val] = i

        cpu = LR35902(memory)

        for _ in range(4):
            cpu.clock()

        self.assertEqual(cpu.B, 0x35)
Beispiel #4
0
    def __init__(self, pubsub, attach_debugger=False, bootloader_enabled=True):
        self.memory = Memory(pubsub)
        self.cpu = LR35902(self.memory.cpu_port, pubsub)
        self.timer = Timer(self.memory.timer_port)
        self.ppu = PPU(self.memory.ppu_port)
        self.rate = 0
        self.clocks = 0

        if attach_debugger:
            self.debugger = Debugger(self)

        if not bootloader_enabled:
            # Disable bootloader and skip it.
            self.memory.cpu_port[Memory.REGISTER_BOOTLOADER_DISABLED] = 0xFF
            self.cpu.PC = 0x100

        self.running = False
Beispiel #5
0
    def test_interrupt_toggle(self):
        memory = [0] * 0x10000
        new_memory = [
            0x06,  # 8
            0x53,
            0x06,  # 8
            0x53,
            0xFB,  # 4
            0x06,  # 8
            0x53,
            0xF3,  # 4
            0x06,  # 8
            0x53
        ]

        # Assign new memory
        for val, i in enumerate(new_memory):
            memory[val] = i

        cpu = LR35902(memory)

        for _ in range(4):
            cpu.clock()
        self.assertFalse(cpu.interrupts['enabled'])

        for _ in range(1):
            cpu.clock()
        self.assertFalse(cpu.interrupts['enabled'])

        for _ in range(2):
            cpu.clock()
        self.assertTrue(cpu.interrupts['enabled'])

        for _ in range(1):
            cpu.clock()
        self.assertTrue(cpu.interrupts['enabled'])

        for _ in range(2):
            cpu.clock()
        self.assertFalse(cpu.interrupts['enabled'])
Beispiel #6
0
 def test_initialize(self):
     LR35902([])
     self.assertEqual(1, 1)
Beispiel #7
0
import time
from gbc_emulator.mqtt import Mqtt
from gbc_emulator.lr35902 import LR35902

cpu = LR35902(None, None)


class bcolors:
    GREEN = '\u001b[38;5;2m'
    ENDC = '\033[0m'


def print_monitor(monitor):
    #print("\033[1;1H" + time.asctime())
    print("\033[1;1H\u001b[2J" + time.asctime())
    print("\nProgram:")
    pc = monitor["registers"]["PC"]
    for address, value in monitor["program"]:
        val_int = int(value, 16)
        mnemonic = "<Unknown>"
        if val_int == 0xCB:
            mnemonic = "<Bitwise Extension>"
        else:
            instruction = cpu.instructions[val_int]
            if instruction:
                mnemonic = instruction.mnemonic

        if pc == address:
            print(bcolors.GREEN +
                  "  0x{}: 0x{} {}".format(address, value, mnemonic) +
                  bcolors.ENDC)