Support < and > prefixes for high and low bytes in VC patch templates (#1172)

This commit is contained in:
Rangi
2025-03-08 11:14:56 -05:00
committed by GitHub
parent 6d6d5938e5
commit 3e2121b21a
2 changed files with 19 additions and 3 deletions

View File

@@ -183,6 +183,16 @@ int parse_arg_value(const char *arg, bool absolute, const struct Symbol *symbols
return parse_number(arg, 0);
}
// Symbols may take the low or high part
enum { SYM_WHOLE, SYM_LOW, SYM_HIGH } part = SYM_WHOLE;
if (arg[0] == '<') {
part = SYM_LOW;
arg++;
} else if (arg[0] == '>') {
part = SYM_HIGH;
arg++;
}
// Symbols evaluate to their offset or address, plus an optional offset mod
int offset_mod = 0;
char *plus = strchr(arg, '+');
@@ -190,9 +200,13 @@ int parse_arg_value(const char *arg, bool absolute, const struct Symbol *symbols
offset_mod = parse_number(plus, 0);
*plus = '\0';
}
// Symbols evaluate to their offset or address
const char *sym_name = !strcmp(arg, "@") ? patch_name : arg; // "@" is the current patch label
const struct Symbol *symbol = symbol_find(symbols, sym_name);
return (absolute ? symbol->offset : symbol->address) + offset_mod;
int value = (absolute ? symbol->offset : symbol->address) + offset_mod;
return part == SYM_LOW ? value & 0xff : part == SYM_HIGH ? value >> 8 : value;
}
void interpret_command(char *command, const struct Symbol *current_hook, const struct Symbol *symbols, struct Buffer *patches, FILE *restrict new_rom, FILE *restrict orig_rom, FILE *restrict output) {