class Emu(object): def __init__(self, debug, graphicsScale): self.rom = Rom() self.gpu = Gpu(graphicsScale) self.cpu = Cpu(self.gpu) self.gpu.setCpu(self.cpu) self.debugger = None self.debugger = Debugger(self.cpu) if True == debug: self.debugger.activate() def run(self, binPath): self.rom.load(binPath) self.cpu.execProg(self.rom.romData, self.debugger) self.pyGameMainLoop() def pyGameMainLoop(self): while 1: event = pygame.event.wait() if event.type == pygame.KEYDOWN: keysPressed = pygame.key.get_pressed() self.cpu.keyboard.keyPressedIndication(keysPressed) if keysPressed[pygame.K_q]: self.cpu.stop() if event.type == pygame.QUIT: self.cpu.stop() if False == self.cpu.running: raise SystemExit
def __init__(self, debug, graphicsScale): self.rom = Rom() self.gpu = Gpu(graphicsScale) self.cpu = Cpu(self.gpu) self.gpu.setCpu(self.cpu) self.debugger = None self.debugger = Debugger(self.cpu) if True == debug: self.debugger.activate()
def Run(self) -> None: (input_path, input_full_filename) = os.path.split(self.input_filename) (input_filename, input_extension) = os.path.splitext(input_full_filename) output_filename = os.path.join( self.output_location or input_path, "%s-randomized-%d%s" % (input_filename, self.seed, input_extension or ".nes")) output_rom = Rom(output_filename, src=self.input_filename) output_rom.OpenFile(write_mode=True) patch = self._GetPatch() for address in patch.GetAddresses(): data: List[int] data = patch.GetData(address) output_rom.WriteBytes(address, data)
def loadRom(self, file): if self.isRunning: self.stop() print "Loading rom {0}...".format(file) # Load ROM file self.rom = Rom(self) self.rom.load(file) if self.rom.valid: print "Rom loaded." self.reset() print "Creating rom mapper..." self.mmap = self.rom.createMapper() if not self.mmap: return self.mmap.loadROM() # TODO: self.ppu.setMirroring(self.rom.getMirroringType()) self.romFile = file print "Initialized NES, ready to start." else: print "Invalid ROM: {0}".format(file) return self.rom.valid
def init_iso_data(self): print ("parsing iso") self.input_iso_file = IsoFS(self.input_iso_path) self.input_iso_file.read_iso() print("getting rom") rom_file = self.input_iso_file.get_file_from_path('SLUS_209.11;1') self.rom = Rom(rom_file) if not os.path.exists('out'): os.mkdir('out') if not os.path.exists('out/old_DDS3.DDT'): print("getting ddt") ddt_file = self.input_iso_file.get_file_from_path('DDS3.DDT;1') with open('out/old_DDS3.DDT', 'wb') as file: file.write(ddt_file.read()) if not os.path.exists('out/old_DDS3.IMG'): print("getting file system img") with open('out/old_DDS3.IMG', 'wb') as file: for chunk in self.input_iso_file.read_file_in_chunks('DDS3.IMG;1'): file.write(chunk) print("parsing dds3 fs") self.dds3 = DDS3FS('out/old_DDS3.DDT', 'out/old_DDS3.IMG') self.dds3.read_dds3()
class Nes(object): __metaclass__ = Singleton def __init__(self): self.cpu = Cpu() self.ppu = Ppu() self.rom = None self.memory = None self.is_running = False def reset(self): if self.memory: self.memory.reset() self.cpu.reset() self.ppu.reset() def start(self): pass def stop(self): pass def load(self, filename): if self.is_running: self.stop() self.rom = Rom() self.rom.load(filename) if self.rom.is_valid: self.memory = Mapper(self.rom.mapper_type) if self.memory == None: raise Exception('Unknown mapper: %d' % self.rom.mapper_type) self.memory.load() self.ppu.set_mirroring(self.rom.get_mirrowing()) return self.rom.is_valid def reload(self): if self.rom and self.rom.filename: self.load(self.rom.filename)
def patch_routine(self, rom: Rom): with open(f'tmp_{self.name}.asm', 'w') as f: f.write(str(self)) (success, rom_data) = asar.patch(f'tmp_{self.name}.asm', rom.data) if success: rom.data = rom_data ptrs = asar.getprints() self.ptr = ptrs[0] print(f'Routine {self.name} was applied correctly') else: print(asar.geterrors()) raise PatchException(f'Routine {self.name} encountered an error while patching') os.remove(f'tmp_{self.name}.asm')
def patch_sprite(self, rom: Rom): import asar with open(f'tmp_{self.name}.asm', 'w') as f: f.write(str(self)) (success, rom_data) = asar.patch(f'tmp_{self.name}.asm', rom.data) if success: rom.data = rom_data ptrs = asar.getprints() self.set_ptrs(ptrs[0][-6:], ptrs[1][-6:]) print(f'Sprite {self.name} was applied correctly') else: print(asar.geterrors()) raise PatchException( f'Sprite {self.name} encountered an error while patching') os.remove(f'tmp_{self.name}.asm')
def load(self, filename): if self.is_running: self.stop() self.rom = Rom() self.rom.load(filename) if self.rom.is_valid: self.memory = Mapper(self.rom.mapper_type) if self.memory == None: raise Exception('Unknown mapper: %d' % self.rom.mapper_type) self.memory.load() self.ppu.set_mirroring(self.rom.get_mirrowing()) return self.rom.is_valid
#! /usr/bin/env python3 # coding=utf-8 """" :author joelcostamagna created on 2018-03-09 14:55 :version 0.1 """ from bus import Bus from Cpu import Cpu from rom import Rom if __name__ == '__main__': # Creation du bus a la base de l ’ ordinateur pour les communications bus = Bus() # Creation du cpu en le reliant au bus cpu = Cpu(bus) # Creation de la rom en la reliant au bus rom = Rom( bus ) # Creation du GUI # Connexion du GUI aux composants # Boucle sans fin du programme
label = f"pcm_{addr:X}" # find in E and J pat = mf_u.read_bytes(addr, size) addr_e = mf_e.find_bytes(pat) addr_j = mf_j.find_bytes(pat) ad = {"U": addr, "E": addr_e, "J": addr_j} y = yaml_data_entry(desc, label, "PcmSample", ad, None, size) print(y) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("rom_dir", type=str) parser.add_argument("-g", "--game", type=str, choices=["mf", "zm"]) parser.add_argument("-r", "--region", type=str, choices=["U", "E", "J"]) args = parser.parse_args() # read rom files games = [args.game] if args.game else GAMES regions = [args.region] if args.region else REGIONS roms = {} for game in games: roms[game] = {} for region in regions: name = f"{game}_{region}.gba".lower() path = os.path.join(args.rom_dir, name) rom = Rom(path) roms[game][region] = rom dump_room_sprites(roms)
class Nes: #class ExecutionThread(Thread): # def __init__(self, nes): # self.nes = nes # Thread.__init__(self) # # def run(self): # print "Execution thread started." # while self.nes.isRunning: # self.nes.cpu.emulate() class Options: CPU_FREQ_NTSC= 1789772.5 #1789772.72727272d CPU_FREQ_PAL= 1773447.4 def __init__(self): self.preferredFrameRate= 60, self.fpsInterval= 500 # Time between updating FPS in ms self.showDisplay= True self.emulateSound= False self.sampleRate= 44100 # Sound sample rate in hz def __init__(self): self.cpu = CPU(self) self.ppu = PPU(self) self.papu = PAPU(self) self.keyboard = Keyboard(self) self.rom = None self.romFile = None self.mmap = None self.isRunning = False self.limitFrames = True self.fpsFrameCount = 0 self.opts = Nes.Options() self.frameTime = self.opts.preferredFrameRate #self.executionThread = Nes.ExecutionThread(self) def reset(self): if self.mmap: self.mmap.reset() self.cpu.reset() self.ppu.reset() self.papu.reset() def start(self): if (self.rom and self.rom.valid): if (not self.isRunning): self.isRunning = True; self.ppu.startFrame() #self.executionThread.start() else: print "There is no ROM loaded, or it is invalid." def printFps(self): pass def stop(self): self.isRunning = False def reloadRom(self): if self.romFile: self.loadRom(self.romFile) def loadRom(self, file): if self.isRunning: self.stop() print "Loading rom {0}...".format(file) # Load ROM file self.rom = Rom(self) self.rom.load(file) if self.rom.valid: print "Rom loaded." self.reset() print "Creating rom mapper..." self.mmap = self.rom.createMapper() if not self.mmap: return self.mmap.loadROM() # TODO: self.ppu.setMirroring(self.rom.getMirroringType()) self.romFile = file print "Initialized NES, ready to start." else: print "Invalid ROM: {0}".format(file) return self.rom.valid
import logging import sys from memory import Memory from rom import Rom mem = Memory() romF = Rom() def init(): logging.basicConfig(level=logging.DEBUG) # inicializar memoria # mem = Memory() # abrir archivo de bios with open("bios.rom", mode="rb") as biosFile: boot = biosFile.read() # b para binario??? logging.debug("print boot") logging.debug(boot) # mem.load(boot, "C000") mem.load(boot, 49152) init() logging.debug("initializing...") logging.debug("init done...") logging.debug("Loading ROM...") if sys.argv[1]: logging.debug("argument supplied %s" % sys.argv[1])
from rom import Rom romFil = open("OJD-rom.csv", "r") alleRom = [] for linje in romFil : romData = linje.split(",") nyttRom = Rom(int(romData[0]), romData[1], romData[2], int(romData[3])) alleRom.append(nyttRom) for rom in alleRom : if rom.passer(8, "Linux"): rom.skrivLinje()
def __init__(self, data=None, fromq=None, toq=None): self.ram = Ram(32768, fromq, toq) self.rom = Rom(32768, data=data) self.register_a = Register() self.register_d = Register() self.program_counter = Register()
local_sprites.append(OWSprite(file)) return local_sprites try: asar.init(dll_path='./asar.dll') except OSError: print('asar.dll wasn\'t found') exit(-1) if len(sys.argv) == 1: romname = input('Insert the name of your rom here:\n') else: romname = sys.argv[1] rom = Rom(romname) try: rom.autoclean_rom('./global_ow_code/autoclean_routines.asm') routines = create_routines() sprites = create_sprites() m = open('./global_ow_code/routines.asm', 'w') with open('./global_ow_code/autoclean_routines.asm', 'w') as f, \ open('./global_ow_code/_OverworldInitPtr.bin', 'wb') as init_table, \ open('./global_ow_code/_OverworldMainPtr.bin', 'wb') as main_table: for routine in routines: routine.patch_routine(rom) f.write(routine.create_autoclean()) m.write(routine.create_macro()) m.close() for sprite in sprites: sprite.patch_sprite(rom)