git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

commit a04c9befb5dedb5e7a1fcafdfd644c716b076976
parent 51a378d6ed27ad922e9e3737d5bde2c8163d6d02
Author: bbbbbr <bbbbbr@users.noreply.github.com>
Date:   Sun, 14 Apr 2024 23:07:27 -0700

Merge pull request #637 from bbbbbr/tools/bankpack_set_bank_type

Bankpack: -banktype arg, allow forcing a given bank type to CODE or LIT
Diffstat:
Mgbdk-support/bankpack/bankpack.c50+++++++++++++++++++++++++++++---------------------
Mgbdk-support/bankpack/obj_data.c6+++---
Mgbdk-support/bankpack/obj_data.h2+-
Mgbdk-support/bankpack/options.c50++++++++++++++++++++++++++++++++++++++++++++++++++
Mgbdk-support/bankpack/options.h5+++++
5 files changed, 88 insertions(+), 25 deletions(-)

diff --git a/gbdk-support/bankpack/bankpack.c b/gbdk-support/bankpack/bankpack.c @@ -27,27 +27,29 @@ static void display_help(void) { " Typically called by Lcc compiler driver before linker.\n" "\n" "Options\n" - "-h : Show this help\n" - "-lkin=<file> : Load object files specified in linker file <file>\n" - "-lkout=<file> : Write list of object files out to linker file <file>\n" - "-yt<mbctype> : Set MBC type per ROM byte 149 in Decimal or Hex (0xNN)\n" - " ([see pandocs](https://gbdev.io/pandocs/The_Cartridge_Header.html#0147---cartridge-type))\n" - "-mbc=N : Similar to -yt, but sets MBC type directly to N instead\n" - " of by intepreting ROM byte 149\n" - " mbc1 will exclude banks {0x20,0x40,0x60} max=127, \n" - " mbc2 max=15, mbc3 max=127, mbc5 max=255 (not 511!) \n" - "-min=N : Min assigned ROM bank is N (default 1)\n" - "-max=N : Max assigned ROM bank is N, error if exceeded\n" - "-ext=<.ext> : Write files out with <.ext> instead of source extension\n" - "-path=<path> : Write files out to <path> (<path> *MUST* already exist)\n" - "-sym=<prefix> : Add symbols starting with <prefix> to match + update list.\n" - " Default entry is \"___bank_\" (see below)\n" - "-cartsize : Print min required cart size as \"autocartsize:<NNN>\"\n" - "-plat=<plat> : Select platform specific behavior (default:gb) (gb,sms)\n" - "-random : Distribute banks randomly for testing (honors -min/-max)\n" - "-reserve=<b:n>: Reserve N bytes (hex) in bank B (decimal)\n" - " Ex: -reserve=105:30F reserves 0x30F bytes in bank 105\n" - "-v : Verbose output, show assignments\n" + "-h : Show this help\n" + "-lkin=<file> : Load object files specified in linker file <file>\n" + "-lkout=<file> : Write list of object files out to linker file <file>\n" + "-yt<mbctype> : Set MBC type per ROM byte 149 in Decimal or Hex (0xNN)\n" + " ([see pandocs](https://gbdev.io/pandocs/The_Cartridge_Header.html#0147---cartridge-type))\n" + "-mbc=N : Similar to -yt, but sets MBC type directly to N instead\n" + " of by intepreting ROM byte 149\n" + " mbc1 will exclude banks {0x20,0x40,0x60} max=127, \n" + " mbc2 max=15, mbc3 max=127, mbc5 max=255 (not 511!) \n" + "-min=N : Min assigned ROM bank is N (default 1)\n" + "-max=N : Max assigned ROM bank is N, error if exceeded\n" + "-ext=<.ext> : Write files out with <.ext> instead of source extension\n" + "-path=<path> : Write files out to <path> (<path> *MUST* already exist)\n" + "-sym=<prefix> : Add symbols starting with <prefix> to match + update list\n" + " Default entry is \"___bank_\" (see below)\n" + "-cartsize : Print min required cart size as \"autocartsize:<NNN>\"\n" + "-plat=<plat> : Select platform specific behavior (default:gb) (gb,sms)\n" + "-random : Distribute banks randomly for testing (honors -min/-max)\n" + "-reserve=<b:n> : Reserve N bytes (hex) in bank B (decimal)\n" + " Ex: -reserve=105:30F reserves 0x30F bytes in bank 105\n" + "-banktype=<b:t>: Set bank B (decimal) to use type T (CODE or LIT). For sms/gg\n" + " Ex: -banktype=2:LIT sets bank 2 to type LIT\n" + "-v : Verbose output, show assignments\n" "\n" "Example: \"bankpack -ext=.rel -path=some/newpath/ file1.o file2.o\"\n" "Unless -ext or -path specify otherwise, input files are overwritten.\n" @@ -119,6 +121,12 @@ static int handle_args(int argc, char * argv[]) { display_help(); return false; } + } else if (strstr(argv[i], "-banktype=") == argv[i]) { + if (!option_bank_set_type(argv[i])) { + fprintf(stdout,"BankPack: ERROR! Malformed argument: %s\n\n", argv[i]); + display_help(); + return false; + } } else { printf("BankPack: Warning: Ignoring unknown option %s\n", argv[i]); } diff --git a/gbdk-support/bankpack/obj_data.c b/gbdk-support/bankpack/obj_data.c @@ -95,7 +95,7 @@ int areas_add(char * area_str, uint32_t file_id) { // Only match areas which are banked ("_CODE_" vs "_CODE") and ("_LIT_") if (AREA_LINE_RECORDS == sscanf(area_str,"A _CODE _%3d size %4x flags %*4x addr %*4x", &newarea.bank_num_in, &newarea.size)) { - newarea.type = BANK_TYPE_DEFAULT; + newarea.type = BANK_TYPE_CODE; } else if (AREA_LINE_RECORDS == sscanf(area_str,"A _LIT_%3d size %4x flags %*4x addr %*4x", &newarea.bank_num_in, &newarea.size)) { @@ -222,7 +222,7 @@ static void bank_report_mixed_area_error(bank_item * p_bank, uint16_t bank_num, printf("BankPack: ERROR! Bank %d already assigned different area type.\n" " Can't mix _CODE_ and _LIT_ areas in the same bank for this platform.\n" - " Area %s, bank %d, file:%s\n", + " Rejecting: Area %s, bank %d, file:%s\n", p_area->bank_num_in, p_area->name, bank_num, file_get_name_in_by_id(p_area->file_id)); if (option_get_verbose()) @@ -230,7 +230,7 @@ static void bank_report_mixed_area_error(bank_item * p_bank, uint16_t bank_num, } -// Checks whether mixing area types in the same bankshould be rejected +// Checks whether mixing area types in the same bank should be rejected static bool bank_check_mixed_area_types_ok(bank_item * p_bank, uint16_t bank_num, area_item * p_area) { // Don't allow mixing of _CODE_ and _LIT_ for sms/gg ports diff --git a/gbdk-support/bankpack/obj_data.h b/gbdk-support/bankpack/obj_data.h @@ -13,7 +13,7 @@ #define SYMBOL_REWRITE_RECORDS 2 // Name, DefVal #define BANK_TYPE_UNSET 0 -#define BANK_TYPE_DEFAULT 1 +#define BANK_TYPE_CODE 1 // Default type is CODE #define BANK_TYPE_LIT_EXCLUSIVE 2 diff --git a/gbdk-support/bankpack/options.c b/gbdk-support/bankpack/options.c @@ -107,6 +107,56 @@ int option_bank_reserve_bytes(char * arg_str) { } +// Format: -banktype=DECIMAL_BANKNUM:BANK_TYPE_STRING +// Force a given bank to a specific type (mainly for SMS/GG with CODE and LIT types) +// Should be called *after* obj_data_init() has initialized banks +int option_bank_set_type(char * arg_str) { + + bank_item * banks = (bank_item *)banklist.p_array; + + char cols; + char * p_str; + char * p_words[ARG_BANK_SET_TYPE_MAX_SPLIT_WORDS]; + char arg_str_copy[ARG_BANK_SET_TYPE_MAX_LEN]; // copy arg since strtok modifies strings it operates on + snprintf(arg_str_copy, sizeof(arg_str_copy), "%s", arg_str); + + // Split string into words using "-:=" as delimiters + cols = 0; + p_str = strtok(arg_str_copy,"-:="); + while (p_str != NULL) + { + p_words[cols++] = p_str; + p_str = strtok(NULL, "-:="); + if (cols >= ARG_BANK_SET_TYPE_MAX_SPLIT_WORDS) break; + } + + if (cols == ARG_BANK_SET_TYPE_REC_COUNT_MATCH) { + + uint32_t bank_num = strtol(p_words[1], NULL, 10); // [1] Decimal Bank Number + uint32_t bank_type = BANK_TYPE_UNSET; + + if (strncmp(p_words[2], "CODE", strlen("CODE") + 1) == 0) { + bank_type = BANK_TYPE_CODE; + } else if (strncmp(p_words[2], "LIT", strlen("LIT") + 1) == 0) { + bank_type = BANK_TYPE_LIT_EXCLUSIVE; + } else { + printf("BankPack: ERROR! Bank type %s for %s is invalid\n", p_words[2], arg_str); + exit(EXIT_FAILURE); + } + + if ((bank_num < BANK_NUM_ROM_MIN) || (bank_num > BANK_NUM_ROM_MAX)) { + printf("BankPack: ERROR! Bank number %d for %s is invalid (min: %d, max: %d)\n", bank_num, arg_str, BANK_NUM_ROM_MIN, BANK_NUM_ROM_MAX); + exit(EXIT_FAILURE); + } + + // Params were valid, set the bank type + banks[bank_num].type = bank_type; + return true; + } else + return false; // Signal failure +} + + int option_get_platform(void) { return option_platform; } diff --git a/gbdk-support/bankpack/options.h b/gbdk-support/bankpack/options.h @@ -7,6 +7,10 @@ #define ARG_BANK_RESERVE_SIZE_REC_COUNT_MATCH 3u #define ARG_BANK_RESERVE_SIZE_MAX_SPLIT_WORDS (ARG_BANK_RESERVE_SIZE_REC_COUNT_MATCH + 1u) +#define ARG_BANK_SET_TYPE_MAX_LEN 256u // -banktype=255:LIT +#define ARG_BANK_SET_TYPE_REC_COUNT_MATCH 3u +#define ARG_BANK_SET_TYPE_MAX_SPLIT_WORDS (ARG_BANK_RESERVE_SIZE_REC_COUNT_MATCH + 1u) + #define PLATFORM_GB 0 #define PLATFORM_SMS 1 #define PLATFORM_DEFAULT PLATFORM_GB @@ -30,6 +34,7 @@ void option_set_random_assign(bool is_enabled); bool option_get_random_assign(void); int option_bank_reserve_bytes(char * arg_str); +int option_bank_set_type(char * arg_str); void option_set_platform(char * platform_str); int option_get_platform(void);

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.