SHARE
TWEET

bank_ends.py

a guest Jan 31st, 2017 29 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. F1 = open("pokeprism.gbc", "rb")
  2. F2 = open("pokeprism00.gbc", "rb")
  3. bank_diff = 0x4000
  4. num_banks = 0x80
  5. bank_ends = []
  6. bank_space = []
  7. for bank in range(num_banks):
  8.     empty_bank = True
  9.     for i in range(bank_diff):
  10.         F1.seek((bank + 1) * bank_diff - i - 1)
  11.         F2.seek((bank + 1) * bank_diff - i - 1)
  12.         if F1.read(1) == F2.read(1):
  13.             bank_space.append(i)
  14.             bank_ends.append(bank_diff * (1 + (bank != 0)) - i)
  15.             empty_bank = False
  16.             break
  17.     if empty_bank:
  18.         bank_space.append(bank_diff)
  19.         bank_ends.append(bank_diff)
  20. F1.close()
  21. F2.close()
  22.  
  23. for bank, end, space in zip(range(num_banks), bank_ends, bank_space):
  24.     print("Bank ${:02x}: ${:04x} (${:04x})".format(bank, end, space))
  25. print("")
  26.  
  27. free_banks = sorted(range(num_banks), key = bank_space.__getitem__, reverse = True)
  28. for bank in free_banks:
  29.     space = bank_space[bank]
  30.     print("Bank ${:02x} has ${:04x} bytes of free space".format(bank, space))
  31. print("")
  32.  
  33. total_size = bank_diff * num_banks
  34. free_space = sum(bank_space)
  35. pct_free = free_space * 100 / total_size
  36. print("Free space: {:d}/{:d} ({:d}%)".format(free_space, total_size, pct_free))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top