diff --git a/Changelog.md b/Changelog.md index d9390d5..a83be98 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,9 @@ Changelog ========= +# Version 1.2.9 +- `-nMEM` Hide memory regions with case sensitive substring (ex hide all RAM: `-nMEM:RAM`) + # Version 1.2.8 - `-sJ` JSON output - `-Q` Suppress output of warnings and errors diff --git a/README.md b/README.md index e40f456..6217881 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Examples of color output. `-sRe` with `-sRp` for percentage based color on row e ### Usage ``` romusage input_file.[map|noi|ihx|cdb|.gb[c]|.pocket|.duck|.gg|.sms] [options] -version 1.2.8, by bbbbbr +version 1.2.9, by bbbbbr Options -h : Show this help @@ -53,10 +53,11 @@ Options -smROM : Show Merged ROM_0 and ROM_1 output (i.e. bare 32K ROM) -smWRAM : Show Merged WRAM_0 and WRAM_1 output (i.e DMG/MGB not CGB) -sm* compatible with banked ROM_x or WRAM_x when used with -B --sJ : Show JSON output. Some options not applicable. When used, -Q recommended --nB : Hide warning banner (for .cdb output) --nA : Hide areas (shown by default in .cdb output) --z : Hide areas smaller than SIZE -z:DECSIZE +-sJ : Show JSON output. Some options not applicable. When used, -Q recommended +-nB : Hide warning banner (for .cdb output) +-nA : Hide areas (shown by default in .cdb output) +-z : Hide areas smaller than SIZE -z:DECSIZE +-nMEM : Hide banks matching case sensitive substring (ex hide all RAM: -nMEM:RAM) Use: Read a .map, .noi, .cdb or .ihx file to display area sizes Example 1: "romusage build/MyProject.map" diff --git a/src/bank_templates.c b/src/bank_templates.c index 5bf39d7..34eb4ed 100644 --- a/src/bank_templates.c +++ b/src/bank_templates.c @@ -37,25 +37,25 @@ // ===== Game Boy ===== // ROM -const bank_item ROM_0 = {"ROM_0", 0x0000, 0x3FFF, BANKED_NO, 0x7FFF, 0,0,0, BANK_MEM_TYPE_ROM, BANK_STARTNUM_0, BANK_MERGED_NO}; -const bank_item ROM_X_banked = {"ROM_", 0x4000, 0x7FFF, BANKED_YES, 0x7FFF, 0,0,0, BANK_MEM_TYPE_ROM, BANK_STARTNUM_1, BANK_MERGED_NO}; +const bank_item ROM_0 = {"ROM_0", 0x0000, 0x3FFF, BANKED_NO, 0x7FFF, 0,0,0, BANK_MEM_TYPE_ROM, BANK_STARTNUM_0, BANK_MERGED_NO, HIDDEN_NO}; +const bank_item ROM_X_banked = {"ROM_", 0x4000, 0x7FFF, BANKED_YES, 0x7FFF, 0,0,0, BANK_MEM_TYPE_ROM, BANK_STARTNUM_1, BANK_MERGED_NO, HIDDEN_NO}; // Merged version -const bank_item ROM_nonbanked = {"ROM", 0x0000, 0x7FFF, BANKED_YES, 0x7FFF, 0,0,0, BANK_MEM_TYPE_ROM, BANK_STARTNUM_0, BANK_MERGED_YES}; +const bank_item ROM_nonbanked = {"ROM", 0x0000, 0x7FFF, BANKED_YES, 0x7FFF, 0,0,0, BANK_MEM_TYPE_ROM, BANK_STARTNUM_0, BANK_MERGED_YES, HIDDEN_NO}; // VRAM -const bank_item VRAM = {"VRAM_", 0x8000, 0x9FFF, BANKED_YES, 0x9FFF, 0,0,0, BANK_MEM_TYPE_VRAM, BANK_STARTNUM_0, BANK_MERGED_NO}; +const bank_item VRAM = {"VRAM_", 0x8000, 0x9FFF, BANKED_YES, 0x9FFF, 0,0,0, BANK_MEM_TYPE_VRAM, BANK_STARTNUM_0, BANK_MERGED_NO, HIDDEN_NO}; // SRAM -const bank_item SRAM = {"SRAM_", 0xA000, 0xBFFF, BANKED_YES, 0xBFFF, 0,0,0, BANK_MEM_TYPE_SRAM, BANK_STARTNUM_0, BANK_MERGED_NO}; +const bank_item SRAM = {"SRAM_", 0xA000, 0xBFFF, BANKED_YES, 0xBFFF, 0,0,0, BANK_MEM_TYPE_SRAM, BANK_STARTNUM_0, BANK_MERGED_NO, HIDDEN_NO}; // WRAM -const bank_item WRAM_0 = {"WRAM_LO", 0xC000, 0xCFFF, BANKED_NO, 0xDFFF, 0,0,0, BANK_MEM_TYPE_WRAM, BANK_STARTNUM_0, BANK_MERGED_NO}; -const bank_item WRAM_X_banked = {"WRAM_HI_",0xD000, 0xDFFF, BANKED_YES, 0xDFFF, 0,0,0, BANK_MEM_TYPE_WRAM, BANK_STARTNUM_1, BANK_MERGED_NO}; +const bank_item WRAM_0 = {"WRAM_LO", 0xC000, 0xCFFF, BANKED_NO, 0xDFFF, 0,0,0, BANK_MEM_TYPE_WRAM, BANK_STARTNUM_0, BANK_MERGED_NO, HIDDEN_NO}; +const bank_item WRAM_X_banked = {"WRAM_HI_",0xD000, 0xDFFF, BANKED_YES, 0xDFFF, 0,0,0, BANK_MEM_TYPE_WRAM, BANK_STARTNUM_1, BANK_MERGED_NO, HIDDEN_NO}; // Merged version -const bank_item WRAM_nonbanked = {"WRAM", 0xC000, 0xDFFF, BANKED_YES, 0xDFFF, 0,0,0, BANK_MEM_TYPE_WRAM, BANK_STARTNUM_0, BANK_MERGED_YES}; +const bank_item WRAM_nonbanked = {"WRAM", 0xC000, 0xDFFF, BANKED_YES, 0xDFFF, 0,0,0, BANK_MEM_TYPE_WRAM, BANK_STARTNUM_0, BANK_MERGED_YES, HIDDEN_NO}; // HRAM -const bank_item HRAM = {"HRAM", 0xFF80, 0xFFFE, BANKED_NO, 0xFFFE, 0,0,0, BANK_MEM_TYPE_HRAM, BANK_STARTNUM_0, BANK_MERGED_NO}; +const bank_item HRAM = {"HRAM", 0xFF80, 0xFFFE, BANKED_NO, 0xFFFE, 0,0,0, BANK_MEM_TYPE_HRAM, BANK_STARTNUM_0, BANK_MERGED_NO, HIDDEN_NO}; // ===== Game Gear ===== @@ -66,15 +66,15 @@ const bank_item HRAM = {"HRAM", 0xFF80, 0xFFFE, BANKED_NO, 0xFFFE, // _LIT_ is at base address 0x8000 (assets) // _DATA_N is also at base address 0x8000 (RAM) -const bank_item smsgg_ROM_0 = {"ROM_0", 0x0000, 0x3FFF, BANKED_NO, 0x7FFF, 0,0,0, BANK_MEM_TYPE_ROM, BANK_STARTNUM_0, BANK_MERGED_NO}; -const bank_item smsgg_ROM_X_banked = {"ROM_", 0x4000, 0x7FFF, BANKED_YES, 0x7FFF, 0,0,0, BANK_MEM_TYPE_ROM, BANK_STARTNUM_1, BANK_MERGED_NO}; +const bank_item smsgg_ROM_0 = {"ROM_0", 0x0000, 0x3FFF, BANKED_NO, 0x7FFF, 0,0,0, BANK_MEM_TYPE_ROM, BANK_STARTNUM_0, BANK_MERGED_NO, HIDDEN_NO}; +const bank_item smsgg_ROM_X_banked = {"ROM_", 0x4000, 0x7FFF, BANKED_YES, 0x7FFF, 0,0,0, BANK_MEM_TYPE_ROM, BANK_STARTNUM_1, BANK_MERGED_NO, HIDDEN_NO}; // Merged version -const bank_item smsgg_ROM_nonbanked = {"ROM", 0x0000, 0x7FFF, BANKED_YES, 0x7FFF, 0,0,0, BANK_MEM_TYPE_ROM, BANK_STARTNUM_0, BANK_MERGED_YES}; +const bank_item smsgg_ROM_nonbanked = {"ROM", 0x0000, 0x7FFF, BANKED_YES, 0x7FFF, 0,0,0, BANK_MEM_TYPE_ROM, BANK_STARTNUM_0, BANK_MERGED_YES, HIDDEN_NO}; -const bank_item smsgg_LIT_X_banked = {"LIT_", 0x8000, 0xBFFF, BANKED_YES, 0xBFFF, 0,0,0, BANK_MEM_TYPE_ROM, BANK_STARTNUM_1, BANK_MERGED_NO}; +const bank_item smsgg_LIT_X_banked = {"LIT_", 0x8000, 0xBFFF, BANKED_YES, 0xBFFF, 0,0,0, BANK_MEM_TYPE_ROM, BANK_STARTNUM_1, BANK_MERGED_NO, HIDDEN_NO}; // Data can also be in the 0x8000 region.. requires some special handling in banks_check() -const bank_item smsgg_DATA_X_banked = {"DATA_", 0x8000, 0xBFFF, BANKED_YES, 0xBFFF, 0,0,0, BANK_MEM_TYPE_SRAM, BANK_STARTNUM_1, BANK_MERGED_NO}; -const bank_item smsgg_RAM_nonbanked = {"RAM", 0xC000, 0xDFFF, BANKED_YES, 0xDFFF, 0,0,0, BANK_MEM_TYPE_WRAM, BANK_STARTNUM_0, BANK_MERGED_YES}; +const bank_item smsgg_DATA_X_banked = {"DATA_", 0x8000, 0xBFFF, BANKED_YES, 0xBFFF, 0,0,0, BANK_MEM_TYPE_SRAM, BANK_STARTNUM_1, BANK_MERGED_NO, HIDDEN_NO}; +const bank_item smsgg_RAM_nonbanked = {"RAM", 0xC000, 0xDFFF, BANKED_YES, 0xDFFF, 0,0,0, BANK_MEM_TYPE_WRAM, BANK_STARTNUM_0, BANK_MERGED_YES, HIDDEN_NO}; static int bank_template_add(int idx, bank_item * p_bank_templates, const bank_item * p_bank) { diff --git a/src/banks.c b/src/banks.c index cd5c9c1..b25360f 100644 --- a/src/banks.c +++ b/src/banks.c @@ -657,6 +657,16 @@ static void bank_fill_area_gaps_with_unknown(void) { } +// Check if a bank name matches any substrings on the hide list +static bool bank_name_check_hidden(char * str_bank_name) { + + for (int c = 0; c < banks_hide_count; c++) { + if (strstr(str_bank_name, banks_hide_list[c])) return true; + } + return false; +} + + // Print banks to output void banklist_finalize_and_show(void) { @@ -672,6 +682,7 @@ void banklist_finalize_and_show(void) { for (c = 0; c < bank_list.count; c++) { // Sort areas in bank and calculate usage banks[c].size_used = bank_areas_calc_used(&banks[c], banks[c].start, banks[c].end); + banks[c].hidden = bank_name_check_hidden(banks[c].name); if (get_option_area_sort() == OPT_AREA_SORT_SIZE_DESC) qsort (banks[c].area_list.p_array, banks[c].area_list.count, sizeof(area_item), area_item_compare_size_desc); diff --git a/src/banks.h b/src/banks.h index 8ce9f31..762b7e8 100644 --- a/src/banks.h +++ b/src/banks.h @@ -39,6 +39,9 @@ #define BANK_MERGED_NO false #define BANK_MERGED_YES true +#define HIDDEN_NO false +#define HIDDEN_YES true + #define MINIGRAPH_SIZE (2 * 14) // Number of characters wide (inside edge brackets) #define LARGEGRAPH_BYTES_PER_CHAR 16 @@ -79,6 +82,7 @@ typedef struct bank_item { int base_bank_num; bool is_merged_bank; // End of templating vars + bool hidden; // TODO: track overflow bytes and report them in graph list_type area_list; diff --git a/src/banks_print.c b/src/banks_print.c index e824664..4deda9c 100644 --- a/src/banks_print.c +++ b/src/banks_print.c @@ -254,12 +254,15 @@ void banklist_printall(list_type * p_bank_list) { // Print all banks for (c = 0; c < p_bank_list->count; c++) { - bank_print_info(&banks[c]); - fprintf(stdout,"\n"); + if (!banks[c].hidden) { + bank_print_info(&banks[c]); + fprintf(stdout,"\n"); - if (get_option_area_sort() != OPT_AREA_SORT_HIDE) // This is a hack-workaround, TODO:fixme - if (banks_display_areas) - bank_print_area(&banks[c]); + if (get_option_area_sort() != OPT_AREA_SORT_HIDE) { // This is a hack-workaround, TODO:fixme + if (banks_display_areas) + bank_print_area(&banks[c]); + } + } } // End: Print all banks loop @@ -333,10 +336,12 @@ void banklist_printall_json(list_type * p_bank_list) { // Print each bank as an array object item for (c = 0; c < p_bank_list->count; c++) { - // Comma separator between array items - if (c > 0) fprintf(stdout," ,\n"); + if (!banks[c].hidden) { + // Comma separator between array items + if (c > 0) fprintf(stdout," ,\n"); - bank_print_info_json(&banks[c]); + bank_print_info_json(&banks[c]); + } } // JSON array footer diff --git a/src/common.c b/src/common.c index fa9deec..1ff12e9 100644 --- a/src/common.c +++ b/src/common.c @@ -3,6 +3,7 @@ // bbbbbr 2020 #include +#include #include #include #include @@ -38,6 +39,8 @@ bool option_percentage_based_color = false; uint32_t option_area_hide_size = OPT_AREA_HIDE_SIZE_DEFAULT; bool exit_error = false; +int banks_hide_count = 0; +char banks_hide_list[BANKS_HIDE_SZ][DEFAULT_STR_LEN]; // Turn on/off display of areas within bank @@ -151,7 +154,7 @@ void set_option_area_hide_size(uint32_t value) { // -sP:DEFAULT:ROM:VRAM:SRAM:WRAM:HRAM // // Custom color scheme for output -bool option_set_displayed_bank_range(char * arg_str) { +bool set_option_displayed_bank_range(char * arg_str) { #define MAX_SPLIT_WORDS 4 #define EXPECTED_COLS 3 @@ -223,6 +226,19 @@ bool get_option_display_asciistyle(void) { } +// Add a substring for hiding banks +bool set_option_banks_hide_add(char * str_bank_hide_substring) { + + if (banks_hide_count < BANKS_HIDE_SZ) { + snprintf(banks_hide_list[banks_hide_count], (DEFAULT_STR_LEN - 1), "%s", str_bank_hide_substring); + banks_hide_count++; + return true; + } else + log_error("Error: no bank hide string slots available\n"); + + + return false; +} void set_exit_error(void) { diff --git a/src/common.h b/src/common.h index c740a40..143985e 100644 --- a/src/common.h +++ b/src/common.h @@ -38,6 +38,9 @@ #define OPT_PLAT_GAMEBOY 0u #define OPT_PLAT_SMS_GG_GBDK 1u // GBDK specific layout of sms/gg +#define BANKS_HIDE_SZ 30 // How many hide substrings to support +#define BANKS_HIDE_MAX (BANKS_HIDE_SZ - 1) + extern bool banks_display_areas; extern bool banks_display_headers; @@ -64,6 +67,9 @@ extern unsigned int option_merged_banks; extern uint32_t option_area_hide_size; extern bool exit_error; +extern int banks_hide_count; +extern char banks_hide_list[BANKS_HIDE_SZ][DEFAULT_STR_LEN]; + void set_option_all_areas_exclusive(bool value); void set_option_quiet_mode(bool value); @@ -81,9 +87,10 @@ void set_option_show_compact(bool value); void set_option_show_json(bool value); void set_option_summarized(bool value); -bool option_set_displayed_bank_range(char * arg_str); +bool set_option_displayed_bank_range(char * arg_str); void set_option_merged_banks(unsigned int value); +bool set_option_banks_hide_add(char * str_bank_hide_substring); int get_option_input_source(void); int get_option_area_sort(void); @@ -99,4 +106,5 @@ uint32_t round_up_power_of_2(uint32_t val); uint32_t min(uint32_t a, uint32_t b); uint32_t max(uint32_t a, uint32_t b); + #endif // _COMMON_H \ No newline at end of file diff --git a/src/romusage.c b/src/romusage.c index 5a97f9d..9b037b1 100644 --- a/src/romusage.c +++ b/src/romusage.c @@ -19,7 +19,7 @@ #include "cdb_file.h" #include "rom_file.h" -#define VERSION "version 1.2.8" +#define VERSION "version 1.2.9" void static display_cdb_warning(void); void static display_help(void); @@ -73,10 +73,11 @@ static void display_help(void) { "-smROM : Show Merged ROM_0 and ROM_1 output (i.e. bare 32K ROM)\n" "-smWRAM : Show Merged WRAM_0 and WRAM_1 output (i.e DMG/MGB not CGB)\n" " -sm* compatible with banked ROM_x or WRAM_x when used with -B\n" - "-sJ : Show JSON output. Some options not applicable. When used, -Q recommended\n" - "-nB : Hide warning banner (for .cdb output)\n" - "-nA : Hide areas (shown by default in .cdb output)\n" - "-z : Hide areas smaller than SIZE -z:DECSIZE\n" + "-sJ : Show JSON output. Some options not applicable. When used, -Q recommended\n" + "-nB : Hide warning banner (for .cdb output)\n" + "-nA : Hide areas (shown by default in .cdb output)\n" + "-z : Hide areas smaller than SIZE -z:DECSIZE\n" + "-nMEM : Hide banks matching case sensitive substring (ex hide all RAM: -nMEM:RAM)\n" "\n" "Use: Read a .map, .noi, .cdb or .ihx file to display area sizes\n" "Example 1: \"romusage build/MyProject.map\"\n" @@ -145,7 +146,7 @@ int handle_args(int argc, char * argv[]) { } else if (strstr(argv[i], "-sP") == argv[i]) { if (!set_option_custom_bank_colors(argv[i])) { fprintf(stdout,"malformed custom color palette: %s\n\n", argv[i]); - display_help(); + // display_help(); return false; } } else if (strstr(argv[i], "-sH") == argv[i]) { @@ -178,9 +179,9 @@ int handle_args(int argc, char * argv[]) { } else if (strstr(argv[i], "-B") == argv[i]) { set_option_summarized(true); } else if (strstr(argv[i], "-F") == argv[i]) { - if (!option_set_displayed_bank_range(argv[i])) { + if (!set_option_displayed_bank_range(argv[i])) { fprintf(stdout,"Malformed -F forced display max bank range\n\n"); - display_help(); + // display_help(); return false; } @@ -199,13 +200,21 @@ int handle_args(int argc, char * argv[]) { } else if (strstr(argv[i], "-z:") == argv[i]) { set_option_area_hide_size( strtol(argv[i] + 3, NULL, 10)); + } else if (strstr(argv[i], "-nMEM:") == argv[i]) { + if (!set_option_banks_hide_add(argv[i] + strlen("-nMEM:"))) { + fprintf(stdout,"Adding memory region to hide failed: %s\n\n", argv[i]); + // display_help(); + return false; + } + } else if ((strstr(argv[i], "-m") == argv[i]) || (strstr(argv[i], "-e") == argv[i])) { if (!area_manual_queue(argv[i])) { fprintf(stdout,"Malformed manual area argument: %s\n\n", argv[i]); - display_help(); + // display_help(); return false; } + } else if (argv[i][0] == '-') { fprintf(stdout,"Unknown argument: %s\n\n", argv[i]); display_help();