Beispiel #1
0
class ROMTests(unittest.TestCase):
    def setUp(self):
        gba = console_lookup("GBA")
        self.roms_console = gba
        self.rom = ROM("/Users/scottrice/ROMs/GBA/Pokemon Emerald.gba", gba)
        self.noext_rom = ROM("/Users/scottrice/ROMs/GBA/Pokemon Emerald", gba)

    def test_name(self):
        """
        Name should be the name of the ROM file minus the extension.
        If the ROM has no extension, then the name should just be the name of
        the ROM file
        """
        self.assertEqual(self.rom.name(), "Pokemon Emerald")
        self.assertEqual(self.noext_rom.name(), "Pokemon Emerald")

    def test_executable(self):
        """
        The executable should be a file in the executables directory with the
        same name as the ROM. On Windows, this file should end with a .cmd file
        extension. On Mac/Linux systems, it should end with a .sh
        """
        rom_exe_location = self.rom.executable_path()
        # Assert that the exe is in the exe directory for it's console
        self.assertEqual(os.path.dirname(rom_exe_location),
                         self.roms_console.executables_directory())
        # Assert that the exe name is the same as the ROM name with the correct
        # extension for the current platform
        if sys.platform.startswith('win'):
            self.assertEqual(os.path.basename(rom_exe_location),
                             self.rom.name() + ".cmd")
        else:
            self.assertEqual(os.path.basename(rom_exe_location),
                             self.rom.name() + ".sh")
Beispiel #2
0
    def __init__(self, params):
        super(ModelCell, self).__init__()

        self.device = torch.device("cpu")
        if torch.cuda.is_available():
            self.device = torch.device("cuda")

        # set params
        self.params = params

        # create memory
        self.memory = ROM(params.memory_n, params.memory_m)

        # create controller
        self.controller = LSTMController(
            params.sequence_width + 1 + self.memory.M, params.controller_size,
            params.controller_layers)

        # create state
        self.state = State(self.memory, self.controller)

        # create FC layer for addressing using controller output
        self.addressing_params_sizes = [self.memory.M, 1, 1, 3, 1]
        self.fc1 = nn.Sequential(
            nn.Linear(params.controller_size, sum(
                self.addressing_params_sizes)))  # no sigmoid needed here.

        # create FC layer to make output from controller output and read value
        self.fc2 = nn.Sequential(
            nn.Linear(params.controller_size + self.memory.M,
                      params.sequence_width + 1), nn.Sigmoid())

        self.to(self.device)
Beispiel #3
0
class ROMTests(unittest.TestCase):
    def setUp(self):
        gba = Console("GBA", "Gameboy Advance")
        self.roms_console = gba
        self.rom = ROM("/Users/scottrice/ROMs/GBA/Pokemon Emerald.gba",gba)
        self.noext_rom = ROM("/Users/scottrice/ROMs/GBA/Pokemon Emerald",gba)
    
    def test_name(self):
        """
        Name should be the name of the ROM file minus the extension.
        If the ROM has no extension, then the name should just be the name of
        the ROM file
        """
        self.assertEqual(self.rom.name(),"Pokemon Emerald")
        self.assertEqual(self.noext_rom.name(),"Pokemon Emerald")
        
    def test_executable(self):
        """
        The executable should be a file in the executables directory with the
        same name as the ROM. On Windows, this file should end with a .cmd file
        extension. On Mac/Linux systems, it should end with a .sh
        """
        rom_exe_location = self.rom.executable_path()
        # Assert that the exe is in the exe directory for it's console
        self.assertEqual(os.path.dirname(rom_exe_location),self.roms_console.executables_directory())
        # Assert that the exe name is the same as the ROM name with the correct
        # extension for the current platform
        if sys.platform.startswith('win'):
            self.assertEqual(os.path.basename(rom_exe_location),self.rom.name() + ".cmd")
        else:
            self.assertEqual(os.path.basename(rom_exe_location),self.rom.name() + ".sh")
    
	    
Beispiel #4
0
    def __init__(self, params):
        super(ModelCell, self).__init__()

        self.device = torch.device("cpu")
        if torch.cuda.is_available():
            self.device = torch.device("cuda")

        # set params
        self.params = params

        # create memory
        self.memory = ROM(params.memory_n, params.memory_m)

        # create controller
        self.controller = LSTMController(self.memory.M, params.controller_size,
                                         params.controller_layers)

        # create state
        self.state = State(self.memory, self.controller)

        # create variational model
        self.vmodel = params.variationalmodel(params.sequence_width,
                                              params.variational_hidden_size,
                                              params.memory_m, params.memory_m)

        # create FC layer for addressing using controller output
        self.addressing_params_sizes = [self.memory.M, 1, 1, 3, 1]
        self.fc1 = nn.Linear(params.controller_size,
                             sum(self.addressing_params_sizes))

        self.to(self.device)
Beispiel #5
0
 def test_zexdoc(self):
     print(">>> RUNNING ZEXDOC")
     debugger = Debugger()
     debugger.stopOnError = False
     debugger.setHook(0x5, self.systemFunction)
     debugger.setHook(0x0, self.stop)
     rom = ROM(mapAt=0x100)
     rom.loadFrom('./zexdoc.com', False)
     cpu = CPU(rom=rom, debugger=debugger)
     cpu.SP = 0xF000
     cpu.run(0x100)
     self.assertTrue(True)
Beispiel #6
0
class NES(object):
    def __init__(self):
        self.cpu = CPU()
        self.rom = ROM()

    def load_rom(self, rom_path):
        with open(rom_path, 'rb') as f:
            self.rom.load_rom(f.read())

    def start(self):
        for instruction in self.rom.PRG_ROM:
            self.cpu.process_instruction(instruction)
Beispiel #7
0
class ModelCell(nn.Module):
    def __init__(self, params):
        super(ModelCell, self).__init__()

        self.device = torch.device("cpu")
        if torch.cuda.is_available():
            self.device = torch.device("cuda")

        # set params
        self.params = params

        # create memory
        self.memory = ROM(params.memory_n, params.memory_m)

        # create controller
        self.controller = LSTMController(
            params.sequence_width + 1 + self.memory.M, params.controller_size,
            params.controller_layers)

        # create state
        self.state = State(self.memory, self.controller)

        # create FC layer for addressing using controller output
        self.addressing_params_sizes = [self.memory.M, 1, 1, 3, 1]
        self.fc1 = nn.Sequential(
            nn.Linear(params.controller_size, sum(
                self.addressing_params_sizes)))  # no sigmoid needed here.

        # create FC layer to make output from controller output and read value
        self.fc2 = nn.Sequential(
            nn.Linear(params.controller_size + self.memory.M,
                      params.sequence_width + 1), nn.Sigmoid())

        self.to(self.device)

    def reset_parameters(self, stdv=1e-1):
        for weight in self.parameters():
            weight.data.normal_(0, stdv)

    def forward(self, X):
        cout, self.state.controllerstate.state = self.controller(
            torch.cat([X, self.state.readstate.r], dim=1),
            self.state.controllerstate.state)
        address_params = self.fc1(cout)
        k, beta, g, s, gamma = _split_cols(address_params,
                                           self.addressing_params_sizes)
        self.state.readstate.w = self.memory.address(k, beta, g, s, gamma,
                                                     self.state.readstate.w)
        self.state.readstate.r = self.memory.read(self.state.readstate.w)
        self.memory.write(X)
        outp = self.fc2(torch.cat([cout, self.state.readstate.r], dim=1))

        return outp
Beispiel #8
0
    def __open_rom_dialog(self, evt):
        path = self.view.show_file_dialog()
        if path:
            try:
                with open(path, 'rb') as file:
                    if path.endswith(".nes") or path.endswith(".NES"):
                        self.emu.set_rom(ROM(file, True))
                    elif path.endswith(".dat") or path.endswith(".DAT"):
                        self.emu.set_rom(ROM(file, False))
                    self.__refresh_rom()
            except IOError:
                wx.LogError("Cannot open file: '%s'." % path)

        self.__set_code_button(self.emu.has_rom())
Beispiel #9
0
class ROMTests(unittest.TestCase):
    def setUp(self):
        gba = Console("GBA", "Gameboy Advance")
        self.roms_console = gba
        self.rom = ROM("/Users/scottrice/ROMs/GBA/Pokemon Emerald.gba",gba)
        self.noext_rom = ROM("/Users/scottrice/ROMs/GBA/Pokemon Emerald",gba)
    
    def test_name(self):
        """
        Name should be the name of the ROM file minus the extension.
        If the ROM has no extension, then the name should just be the name of
        the ROM file
        """
        self.assertEqual(self.rom.name(),"Pokemon Emerald")
        self.assertEqual(self.noext_rom.name(),"Pokemon Emerald")
Beispiel #10
0
 def test_lra_does_modify_value_correctly(self):
     cpu = CPU(ROM(b'\x17'))
     cpu.A = 0b01110110
     cpu.CFlag = True
     cpu.readOp()
     self.assertEqual(0b11101101, cpu.A)
     self.assertFalse(cpu.CFlag)
Beispiel #11
0
 def test_sbc_a_b_correctly_calculates_result(self):
     cpu = CPU(ROM(b'\x98'))
     cpu.A = 0x40
     cpu.B = 0x3f
     cpu.CFlag = Bits.set()
     cpu.readOp()
     self.assertEqual(0, cpu.A)
Beispiel #12
0
 def test_sbc_hl_de_that_overflows_sets_pv_flag(self):
     cpu = CPU(ROM(b'\xed\x52'))
     cpu.HL = 0x8000
     cpu.DE = 0x1111
     cpu.PVFlag = False
     cpu.readOp()
     self.assertTrue(cpu.PVFlag)
Beispiel #13
0
 def test_sbc_hl_de_that_does_not_overflows_resets_pv_flag(self):
     cpu = CPU(ROM(b'\xed\x52'))
     cpu.HL = 0xaaaa
     cpu.DE = 0xbbbb
     cpu.PVFlag = True
     cpu.readOp()
     self.assertFalse(cpu.PVFlag)
Beispiel #14
0
 def test_sbc_hl_de_that_results_in_value_greater_than_zero_resets_s_flag(self):
     cpu = CPU(ROM(b'\xed\x52'))
     cpu.HL = 0x1000
     cpu.DE = 0x0999
     cpu.SFLag = True
     cpu.readOp()
     self.assertFalse(cpu.SFlag)
Beispiel #15
0
 def test_call_not_s_jumps_if_SFlag_is_not_set(self):
     cpu = CPU(ROM(b'\x00' * 0x1A47 + b'\xf4\x20\x15'))
     cpu.PC = 0x1A47
     cpu.SP = 0x3002
     cpu.SFlag = False
     cpu.readOp()
     self.assertEqual(0x1520, cpu.PC)
Beispiel #16
0
 def test_ld_hl_E_correctly_stores_value_from_given_address_to_hl(self):
     ram = RAM()
     cpu = CPU(ROM(b'\x73'), ram)
     cpu.HL = 0x2000
     cpu.E = 0x20
     cpu.readOp()
     self.assertEqual(0x20, ram[0x2000])
Beispiel #17
0
 def test_sbc_a_c_without_c_calculates_results(self):
     cpu = CPU(ROM(b'\x99'))
     cpu.A = 0x40
     cpu.C = 0x3f
     cpu.CFlag = Bits.reset()
     cpu.readOp()
     self.assertEqual(1, cpu.A)
Beispiel #18
0
 def test_sbc_hl_de_sets_n_flag(self):
     cpu = CPU(ROM(b'\xed\x52'))
     cpu.HL = 0x9999
     cpu.DE = 0x1223
     cpu.NFlag = False
     cpu.readOp()
     self.assertTrue(cpu.NFlag)
Beispiel #19
0
 def test_sbc_a_d_sets_SFlag_when_result_is_below_zero(self):
     cpu = CPU(ROM(b'\x9a'))
     cpu.A = 0x40
     cpu.D = 0x44
     cpu.CFlag = Bits.reset()
     cpu.readOp()
     self.assertTrue(cpu.SFlag)
Beispiel #20
0
 def test_sbc_hl_de_that_results_in_value_less_than_zero_set_s_flag(self):
     cpu = CPU(ROM(b'\xed\x52'))
     cpu.HL = 0x1000
     cpu.DE = 0x1002
     cpu.SFlag = False
     cpu.readOp()
     self.assertTrue(cpu.SFlag)
Beispiel #21
0
 def test_and_a_resets_n_and_c_flag(self):
     cpu = CPU(ROM(b'\xa7'))
     cpu.CFlag = True
     cpu.NFlag = True
     cpu.readOp()
     self.assertFalse(cpu.CFlag)
     self.assertFalse(cpu.NFlag)
Beispiel #22
0
 def test_sbc_hl_de_that_does_generate_borrow_sets_c_flag(self):
     cpu = CPU(ROM(b'\xed\x52'))
     cpu.HL = 0x1000
     cpu.DE = 0x2000
     cpu.CFlag = False
     cpu.readOp()
     self.assertTrue(cpu.CFlag)
Beispiel #23
0
 def test_sbc_a_e_sets_ZFlag_when_result_is_zero(self):
     cpu = CPU(ROM(b'\x9b'))
     cpu.A = 0x44
     cpu.E = 0x44
     cpu.CFlag = Bits.reset()
     cpu.readOp()
     self.assertTrue(cpu.ZFlag)
Beispiel #24
0
 def test_sbc_hl_de_that_does_not_generate_carry_on_12bit_resets_h_flag(self):
     cpu = CPU(ROM(b'\xed\x52'))
     cpu.HL = 0x0910
     cpu.DE = 0x0100
     cpu.HFlag = True
     cpu.readOp()
     self.assertFalse(cpu.HFlag)
Beispiel #25
0
 def test_sbc_hl_de_that_does_generate_carry_on_12th_bit_set_h_flag(self):
     cpu = CPU(ROM(b'\xed\x52'))
     cpu.HL = 0x1000
     cpu.DE = 0x0001
     cpu.HFlag = False
     cpu.readOp()
     self.assertTrue(cpu.HFlag)
Beispiel #26
0
def main():
    # Set up command line arguments parser
    parser = argparse.ArgumentParser(description='NES Emulator')
    parser.add_argument('rom_path',
                        metavar='R',
                        type=str,
                        help='The location to the rom file')
    args = parser.parse_args()

    # load rom
    with open(args.rom_path, 'rb') as file:
        rom_bytes = file.read()

    rom = ROM(rom_bytes)

    # create ram
    ram = RAM()

    # create ppu
    ppu = PPU()

    # create cpu
    cpu = CPU(ram, ppu)
    cpu.start_up()
    cpu.run_rom(rom)
Beispiel #27
0
 def test_sbc_hl_de_that_results_zero_sets_z_flag(self):
     cpu = CPU(ROM(b'\xed\x52'))
     cpu.HL = 0x9999
     cpu.DE = 0x9999
     cpu.ZFlag = False
     cpu.readOp()
     self.assertTrue(cpu.ZFlag)
Beispiel #28
0
 def test_sbc_hl_bc_result_is_crrect_if_c_flag_is_reset(self):
     cpu = CPU(ROM(b'\xed\x42'))
     cpu.HL = 0x9999
     cpu.BC = 0x1111
     cpu.CFlag = False
     cpu.readOp()
     self.assertEqual(0x8888, cpu.HL)
Beispiel #29
0
 def test_sbc_hl_de_result_is_correct_if_c_flag_is_set(self):
     cpu = CPU(ROM(b'\xed\x52'))
     cpu.HL = 0x9999
     cpu.DE = 0x1111
     cpu.CFlag = True
     cpu.readOp()
     self.assertEqual(0x8887, cpu.HL)
Beispiel #30
0
 def test_sbc_a_mem_hl_correctly_calculates_value(self):
     cpu = CPU(ROM(b'\x9e\x00\x00\x22'))
     cpu.A = 0x23
     cpu.HL = 0x3
     cpu.CFlag = Bits.set()
     cpu.readOp()
     self.assertEqual(0, cpu.A)
Beispiel #31
0
 def test_ld_bc_a_loads_corect_value(self):
     ram = RAM()
     cpu = CPU(ROM(b'\x02'), ram)
     cpu.A = 0x7a
     cpu.BC = 0x1212
     cpu.readOp()
     self.assertEqual(0x7a, cpu.ram[cpu.BC])
Beispiel #32
0
 def test_sbc_hl_de_that_does_not_generate_borrow_resets_c_flag(self):
     cpu = CPU(ROM(b'\xed\x52'))
     cpu.HL = 0x1000
     cpu.DE = 0x0999
     cpu.CFlag = True
     cpu.readOp()
     self.assertFalse(cpu.CFlag)
Beispiel #33
0
    def test_name(self):
        prefix = "Any Text"
        gba = Console("Gameboy Advance")
        prefix_gba = Console("Gameboy Advance", { "prefix": prefix })
        empty_prefix_gba = Console("Gameboy Advance", {"prefix": "" })
        rom_path = "/Users/scottrice/ROMs/GBA/Pokemon Emerald.gba"

        rom = ROM(rom_path, gba)
        prefix_rom = ROM(rom_path, prefix_gba)
        empty_prefix_rom = ROM(rom_path, empty_prefix_gba)

        # With no prefix, the name should be the same as the basename
        self.assertEqual(rom.name(), "Pokemon Emerald")
        # When the prefix is the empty string, it should be treated as if no
        # prefix was given
        self.assertEqual(empty_prefix_rom.name(), "Pokemon Emerald")
        # When the console has a prefix, the ROM should begin with that string
        self.assertTrue(prefix_rom.name().startswith(prefix))
Beispiel #34
0
    def test_basename(self):
        """
        Basename should be the name of the ROM file minus the extension.
        If the ROM has no extension, then the name should just be the name of
        the ROM file
        """
        gba = Console("Gameboy Advance")
        prefix_gba = Console("Gameboy Advance", { "prefix":"Any Text" })
        rom_path = "/Users/scottrice/ROMs/GBA/Pokemon Emerald.gba"
        noext_rom_path = "/Users/scottrice/ROMs/GBA/Pokemon Emerald"
        rom = ROM(rom_path,gba)
        noext_rom = ROM(noext_rom_path,gba)
        prefix_rom = ROM(rom_path, prefix_gba)

        # Standard situation
        self.assertEqual(rom.basename(),"Pokemon Emerald")
        # Should correctly figure out the basename when the ROM has no extension
        self.assertEqual(noext_rom.basename(),"Pokemon Emerald")
        # The basename shouldn't include the prefix
        self.assertEqual(prefix_rom.basename(), "Pokemon Emerald")
Beispiel #35
0
		return b1,b2
		print "Split: %s:%s -> %s:%s,%s:%s"%(self.addr,self.endaddr,b1.addr,b1.endaddr,b2.addr,b2.endaddr)
	def contains(self,addr):
		if addr<self.addr:
			return False
		if addr>=self.endaddr:
			return False
		return True
def UtoS(n):
	if n<0x80:
		return n
	return -(0x100-n)

disasmd={}
if __name__=="__main__":
	rom=ROM()
	with open('pacman.nes','rb') as f:
		rom.load(f)
	#rom.prgbanks[0][0x30C3:0x30C8]=[0xA2,0x00,0xA0,0x00,0xA1,0xAA,0xB1,0x55,0x60]
	labels={rom.read16(0xFFFA):['nmi',CODE,False],rom.read16(0xFFFC):['rst',CODE,False],rom.read16(0xFFFE):['irq',CODE,False]}
	#labels={rom.read16(0xFFFC):['rst',CODE,False]}
	#labels={0xF0C3:['rst',CODE,False]}
	toprocess=[i for i in labels.keys()]
	blocks={}
	jumptables=[[0xC267,4],[0xC52E,12],[0xC7A1,3],[0xCAD7,9],[0xD40E,4],[0xD596,5],[0xD601,4],[0xD6DE,4]]
	while len(toprocess)>0:
		k=toprocess.pop()
		if k in blocks:
			continue
		b1=None
		for i in blocks.values():
Beispiel #36
0
 def setUp(self):
     gba = console_lookup("GBA")
     self.roms_console = gba
     self.rom = ROM("/Users/scottrice/ROMs/GBA/Pokemon Emerald.gba",gba)
     self.noext_rom = ROM("/Users/scottrice/ROMs/GBA/Pokemon Emerald",gba)
Beispiel #37
0
CODE=1
DATA=2
JTT=4
JT=8
CC=16
PC=32

def UtoS(n):
	if n<0x80:
		return n
	return -(0x100-n)

disasmd={}
if __name__=="__main__":
	rom=ROM()
	with open('C:\\users\\Andrew.Sentman\\workspace\\AIIEmu\\tests\\pacman.nes','rb') as f:
		rom.load(f)
	labels={rom.read16(0xFFFA):['nmi',CODE,False],rom.read16(0xFFFD):['rst',CODE,False],rom.read16(0xFFFE):['irq',CODE,False]}
	jumptables=[[0xC267,4],[0xC52E,12],[0xC7A1,3],[0xCAD7,9],[0xD40E,4],[0xD596,5],[0xD601,4],[0xD6DE,4]]
	byteflags=[0]*0x10000
	for i in jumptables:
		for j in xrange(i[0],i[0]+i[1]*2):
			byteflags[j]|=JT
		for j in xrange(i[1]):
			taddr=rom.read16(i[0]+j*2)
			if taddr not in labels:
				labels[taddr]=['__'+hex(taddr),CODE|JTT,False]
			else:
				labels[taddr][1]|=CODE|JTT
	#print labels
Beispiel #38
0
				inloc=NodeLocImmediate(self.bytes[1])
			if self.op[0]=='AND':
				ast.append(NodeAssign(NodeLocReg('A'),NodeAND(NodeLocReg('A'),inloc)))
				ast.append(NodeAssign(NodeLocReg('fS'),NodeBit(NodeLocReg('A'),7)))
				ast.append(NodeAssign(NodeLocReg('fZ'),NodeEqual(NodeLocReg('A'),NodeLocImmediate(0))))
				return ast
			if self.op[0] in ['LDA','LDX','LDY']:
				ast.append(NodeAssign(NodeLocReg(self.op[0][2]),inloc))
				return ast
		if self.op[5]==STO:
			if self.op[1]==ZP:
				return [NodeWrite(NodeLocAbsolute(self.bytes[1]),NodeLocReg(self.op[0][2]))]
		if self.op[5]==JSR:
			return [NodeBranch(NodeLocAbsolute(self.bytes[1]+(self.bytes[2]<<8)))]
		if self.op[5]==JMP:
			if self.op[1]==ABS:
				return [NodeBranch(NodeLocAbsolute(self.bytes[1]+(self.bytes[2]<<8)))]
		if self.op[5]==RTS:
			return [NodeRTS()]
		print self.op[0]
		print 5/0
if __name__=="__main__":
	rom=ROM()
	with open('C:\\users\\Andrew.Sentman\\workspace\\AIIEmu\\tests\\pacman.nes','rb') as f:
		rom.load(f)
	addr=0xc033
	while True:
		op=Opcode()
		addr=op.load(rom,addr)
		print op.genAST()
Beispiel #39
0
 def setUp(self):
     gba = Console("GBA", "Gameboy Advance")
     self.roms_console = gba
     self.rom = ROM("/Users/scottrice/ROMs/GBA/Pokemon Emerald.gba",gba)
     self.noext_rom = ROM("/Users/scottrice/ROMs/GBA/Pokemon Emerald",gba)