Implement makercode as expected

This commit is contained in:
Gwilym Inzani 2023-04-08 21:18:27 +01:00
parent 89c883466a
commit 7ec077e08a
2 changed files with 15 additions and 4 deletions

View file

@ -14,7 +14,7 @@ fn main() -> Result<()> {
.arg(arg!(-o --output <OUTPUT> "Set output file, defaults to replacing INPUT's extension to .gba").value_parser(value_parser!(PathBuf)))
.arg(arg!(-t --title <TITLE> "Set the title. At most 12 bytes. Defaults to truncating the input file name"))
.arg(arg!(-c --gamecode <GAME_CODE> "Sets the game code, 4 bytes"))
.arg(arg!(-m --makercode <MAKER_CODE> "Set the maker code, 0-65535").value_parser(value_parser!(u16)))
.arg(arg!(-m --makercode <MAKER_CODE> "Set the maker code, 2 bytes"))
.arg(arg!(-r --gameversion <VERSION> "Set the version of the game, 0-255").value_parser(value_parser!(u8)))
.arg(arg!(-p "Ignored for compatibility with gbafix"))
.get_matches();
@ -43,8 +43,19 @@ fn main() -> Result<()> {
}
}
if let Some(maker_code) = matches.get_one::<u16>("makercode") {
header.maker_code = maker_code.to_le_bytes();
if let Some(maker_code) = matches.get_one::<String>("makercode") {
let maker_code = maker_code.as_bytes();
if maker_code.len() > 2 {
bail!(
"Maker code must be at most 2 bytes, got {}",
maker_code.len()
);
}
header.maker_code = [
*maker_code.first().unwrap_or(&0),
*maker_code.get(1).unwrap_or(&0),
];
}
if let Some(game_version) = matches.get_one::<u8>("gameversion") {

View file

@ -105,7 +105,7 @@ _build-rom folder name:
mkdir -p examples/target/examples
just gbafix --title "${INTERNAL_NAME:0:12}" --gamecode "${INTERNAL_NAME:0:4}" "$TARGET_FOLDER/thumbv4t-none-eabi/release/$GAME_NAME" -o "$GBA_FILE"
just gbafix --title "${INTERNAL_NAME:0:12}" --gamecode "${INTERNAL_NAME:0:4}" --makercode GC "$TARGET_FOLDER/thumbv4t-none-eabi/release/$GAME_NAME" -o "$GBA_FILE"
cp -v "$GBA_FILE" "examples/target/examples/$GAME_NAME.gba"