ref: f9c0df811bb275e2a745f5552ff884a6427212ae
parent: 5e9de74735d09b2a43e8d1c6314f2a7839b6e55a
parent: 4a294824b03717f1bff0dbd887763b433c2b6253
author: Rangi <35663410+Rangi42@users.noreply.github.com>
date: Wed Jun 3 08:29:20 EDT 2020
Merge pull request #728 from Rangi42/master Add tools/free_space.py
--- a/engine/gfx/color.asm
+++ b/engine/gfx/color.asm
@@ -1334,6 +1334,9 @@
PartyMenuOBPals:
INCLUDE "gfx/stats/party_menu_ob.pal"
+UnusedBattleObjectPals:
+INCLUDE "gfx/battle_anims/unused_battle_anims.pal"
+
UnusedGSTitleBGPals:
INCLUDE "gfx/title/unused_gs_bg.pal"
--- /dev/null
+++ b/gfx/battle_anims/unused_battle_anims.pal
@@ -1,0 +1,30 @@
+; gray
+ RGB 31, 31, 31
+ RGB 21, 21, 21
+ RGB 13, 13, 13
+ RGB 07, 07, 07
+; yellow
+ RGB 31, 31, 31
+ RGB 31, 31, 07
+ RGB 31, 16, 01
+ RGB 07, 07, 07
+; red
+ RGB 31, 31, 31
+ RGB 31, 19, 24
+ RGB 30, 10, 06
+ RGB 07, 07, 07
+; green
+ RGB 31, 31, 31
+ RGB 12, 25, 01
+ RGB 05, 14, 00
+ RGB 07, 07, 07
+; blue
+ RGB 31, 31, 31
+ RGB 08, 12, 31
+ RGB 01, 04, 31
+ RGB 07, 07, 07
+; brown
+ RGB 31, 31, 31
+ RGB 24, 18, 07
+ RGB 20, 15, 03
+ RGB 07, 07, 07
--- a/gfx/stats/party_menu_ob.pal
+++ b/gfx/stats/party_menu_ob.pal
@@ -37,33 +37,3 @@
RGB 31, 19, 10
RGB 31, 07, 04
RGB 00, 00, 00
-
- RGB 31, 31, 31
- RGB 21, 21, 21
- RGB 13, 13, 13
- RGB 07, 07, 07
-
- RGB 31, 31, 31
- RGB 31, 31, 07
- RGB 31, 16, 01
- RGB 07, 07, 07
-
- RGB 31, 31, 31
- RGB 31, 19, 24
- RGB 30, 10, 06
- RGB 07, 07, 07
-
- RGB 31, 31, 31
- RGB 12, 25, 01
- RGB 05, 14, 00
- RGB 07, 07, 07
-
- RGB 31, 31, 31
- RGB 08, 12, 31
- RGB 01, 04, 31
- RGB 07, 07, 07
-
- RGB 31, 31, 31
- RGB 24, 18, 07
- RGB 20, 15, 03
- RGB 07, 07, 07
--- /dev/null
+++ b/tools/free_space.py
@@ -1,0 +1,73 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+"""
+Usage: python3 free_space.py [BANK=none] [pokecrystal.map]
+
+Calculate the free space in the ROM or its individual banks.
+
+The BANK argument allows printing free space in one, all, or none of the ROM's banks.
+Valid arguments are numbers (in decimal "42" or hexadecimal "0x2A"), "all" or "none".
+If not specified, defaults to "none".
+"""
+
+import sys
+
+from mapreader import MapReader
+
+def main():
+ print_bank = 'none'
+ mapfile = 'pokecrystal.map'
+
+ if len(sys.argv) >= 2 and sys.argv[1].startswith('BANK='):
+ print_bank = sys.argv[1].split('=', 1)[-1]
+ if len(sys.argv) >= 3:
+ mapfile = sys.argv[2]
+ elif len(sys.argv) >= 3 and sys.argv[2].startswith('BANK='):
+ print_bank = sys.argv[2].split('=', 1)[-1]
+ mapfile = sys.argv[1]
+
+ if print_bank not in {'all', 'none'}:
+ try:
+ if print_bank.startswith('0x') or print_bank.startswith('0X'):
+ print_bank = int(print_bank[2:], 16)
+ else:
+ print_bank = int(print_bank)
+ except ValueError:
+ error = 'Error: invalid BANK: %s' % print_bank
+ if print_bank.isalnum():
+ error += ' (did you mean: 0x%s?)' % print_bank
+ print(error, file=sys.stderr)
+ sys.exit(1)
+
+ num_banks = 0x80
+ bank_size = 0x4000 # bytes
+ total_size = num_banks * bank_size
+
+ r = MapReader()
+ with open(mapfile, 'r', encoding='utf-8') as f:
+ l = f.readlines()
+ r.read_map_data(l)
+
+ free_space = 0
+ per_bank = []
+ default_bank_data = {'sections': [], 'used': 0, 'slack': bank_size}
+ for bank in range(num_banks):
+ bank_data = r.bank_data['ROM0 bank'] if bank == 0 else r.bank_data['ROMX bank']
+ data = bank_data.get(bank, default_bank_data)
+ used = data['used']
+ slack = data['slack']
+ per_bank.append((used, slack))
+ free_space += slack
+
+ print('Free space: %d/%d (%.2f%%)' % (free_space, total_size, free_space * 100.0 / total_size))
+ if print_bank != 'none':
+ print()
+ print('bank, used, free')
+ for bank in range(num_banks):
+ used, slack = per_bank[bank]
+ if print_bank in {'all', bank}:
+ print('$%02X, %d, %d' % (bank, used, slack))
+
+if __name__ == '__main__':
+ main()