prg = open(prgfile,"rb") temp = array.array('B') temp.fromfile(prg,flen(prg)) addr = temp.pop(0) + 256*temp.pop(0) if ((CompConfig == C128Config) or (CompConfig == C12832KConfig)) and (addr == 0x4001): addr = 0x1C01 item['load'] = addr if item['run'] == 0: # if there is no run address item['run'] = addr if addr == CompConfig['run']: # try to find SYS address try: sysidx = temp.index(0x9E,0,32) # find address sysaddr = 0 for i in range(sysidx+1, sysidx+10): if temp[i] == 0x20: continue elif temp[i] >= 0x30 and temp[i] <= 0x39: sysaddr = sysaddr*10 + temp[i] - 0x30 else: break if sysaddr < addr or sysaddr >= addr + len(temp): raise ValueError(f"Start address outside executable: {prgfile}") item['run'] = sysaddr except ValueError as e: pass item['len'] = temp.buffer_info()[1] item['data'] = temp items_no += 1 load_list.append(item['prg']) if items_no > MAX_MENU_ITEMS: error("Cartridge menu %s can have max %d programs, but %d supplied." % (menuid, MAX_MENU_ITEMS, items_no)) width = menu['width'] if width == 0: width = min( max( [ len(x['name'])+3 for x in menu['items'] ] ), 34 ) else: width = min(menu['width'],34) menu['width'] = width
sysidx = temp.index(0x9E,0,32)sysidx = temp[0:32].index(0x9E)