Skip to content

Commit

Permalink
Add option to hide banks based on substring match -nMEM
Browse files Browse the repository at this point in the history
- bump version
- Update readme and changelog
  • Loading branch information
bbbbbr committed Jun 7, 2024
1 parent 8cd213a commit 40c4aa1
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 39 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
30 changes: 15 additions & 15 deletions src/bank_templates.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 =====
Expand All @@ -66,15 +66,15 @@ const bank_item HRAM = {"HRAM", 0xFF80, 0xFFFE, BANKED_NO, 0xFFFE,
// _LIT_<N> 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) {
Expand Down
11 changes: 11 additions & 0 deletions src/banks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/banks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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;
Expand Down
21 changes: 13 additions & 8 deletions src/banks_print.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// bbbbbr 2020

#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 9 additions & 1 deletion src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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
27 changes: 18 additions & 9 deletions src/romusage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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]) {
Expand Down Expand Up @@ -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;
}

Expand All @@ -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();
Expand Down

0 comments on commit 40c4aa1

Please sign in to comment.