def setup_module(): global vars, symbol_table, execution_address """Load the Emulator from the ROM script and Mandelbrot """ reload(asm) name, _ = os.path.splitext(os.path.basename(SCRIPT)) script_globals = {"__file__": str(SCRIPT.absolute()), "__name__": name} with SCRIPT.open("rb") as file: exec(compile(file.read(), SCRIPT, "exec"), script_globals) Emulator.load_rom_from_asm_module() vars = SimpleNamespace(**script_globals) # This sequence of calls is roughly taken from compilegcl.py old_rom_size = asm._romSize program = gcl.Program("Mandelbrot", forRom=False) user_code = asm.symbol("userCode") user_vars = asm.symbol("userVars") program.org(user_code) asm.align(1) asm.zpReset(user_vars) with GCL.open("r", encoding="utf-8") as fp: for line in fp.readlines(): program.line(line) program.end() asm.end() # Copy the resulting data straight into RAM, in the appropriate blocks data = asm.getRom1()[old_rom_size:] index, more_data = 0, bool(data) while more_data: start_address = int.from_bytes(data[index:index + 2], "big", signed=False) index += 2 size = data[index] or 256 index += 1 chunk = data[index:index + size] index += size RAM[start_address:start_address + len(chunk)] = chunk more_data = data[index] execution_address = program.execute symbol_table = program.vars
if args.gt1x: asm.loadBindings('Core/interface-dev.json') userCode = asm.symbol('userCode') userVars = asm.symbol('userVars') print('Compiling file %s' % args.gclSource) program = gcl.Program('Main', forRom=False) program.org(userCode) asm.align(1) # Forces default maximum ROM size asm.zpReset(userVars) # User variables can start here for line in open(args.gclSource).readlines(): program.line(line) program.end() asm.end() # End assembly data = asm.getRom1() #----------------------------------------------------------------------- # Append ending #----------------------------------------------------------------------- address = program.execute # Inject patch for reliable start using ROM v1 Loader application # See: https://forum.gigatron.io/viewtopic.php?p=27#p27 if program.needPatch: patchArea = 0x5b86 # Somewhere after the ROMv1 Loader's buffer print('Apply patch $%04x' % patchArea) data = data[:-1] # Remove terminating zero data += bytes([ patchArea>>8, patchArea&255, 6, # Patch segment, 6 bytes at $5b80