def test_push_pop1(): mem = nc.Memory(None, None) cpu = nc.NesCPU(mem) cpu.push(1) expected = 1 result = cpu.pop() assert expected == result, result
def test_push_pop2(): mem = nc.Memory(None, None) cpu = nc.NesCPU(mem) cpu.push(1) cpu.push(2) cpu.push(3) cpu.push(4) expected = [4, 3, 2, 1] result = [cpu.pop() for _ in range(4)] assert expected == result, result
def test_push(): """ addr = s + 0x0100 """ mem = nc.Memory(None, None) cpu = nc.NesCPU(mem) sp = cpu.sp cpu.push(1) expected = 1 addr = sp + 0x0100 result = cpu.memory[addr] assert expected == result, result
def test_load_nes(): nes = nft.prepared_nes() mem = nc.Memory(None, None) mem.load_nes(nes) if len(nes.prg_rom) == 32 * 1024: expected = nes.prg_rom else: expected = nes.prg_rom * 2 result = mem.prg_rom assert expected == result, result
def setup(self): width, height = 256, 240 canvas = pg.display.set_mode((width, height)) ppu = np.NesPPU(canvas) pad = ngp.GamePad() mem = nc.Memory(ppu, pad) cpu = nc.NesCPU(mem) self.cpu = cpu self.memory = mem self.ppu = ppu self.pad = pad self.key_mapper = { pg.K_j: 'a', pg.K_k: 'b', pg.K_u: 'select', pg.K_i: 'start', pg.K_w: 'up', pg.K_s: 'down', pg.K_a: 'left', pg.K_d: 'right', }
def test_by_log_differ(): differ = ld.LogDiffer.from_json('misc/nestest_log.json') nes = nft.prepared_nes() mem = nc.Memory(None, None) mem.load_nes(nes) cpu = nc.NesCPU(mem) # nestest.nes 所需的特殊初始化 cpu.pc = 0xc000 cpu.status = nc._Status(0x24) while True: info = cpu.dump_registers() op, addr, mode = cpu._prepare() info['op'] = op info['address'] = address_for_log_info(addr) try: differ.diff(info) except ld.AllTestsPassed: break cpu._execute(op, addr, mode)