From 4a824807bb943f893ad8ac552a019037bbcf47dc Mon Sep 17 00:00:00 2001 From: Lorenzooone Date: Sun, 23 Feb 2020 03:56:36 +0100 Subject: [PATCH 1/2] https://github.com/jeffman/Mother2GbaTranslation/issues/100 --- notes/m2-notes.txt | 2 +- src/c/vwf.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++ src/c/vwf.h | 3 +++ src/m2-hack.asm | 13 +++++++++++ 4 files changed, 71 insertions(+), 1 deletion(-) diff --git a/notes/m2-notes.txt b/notes/m2-notes.txt index c55bc9a..18fc386 100644 --- a/notes/m2-notes.txt +++ b/notes/m2-notes.txt @@ -95,7 +95,7 @@ English names: [00]: A menu [01]: Money [02]: ? - [03]: Action subject ("Who?", etc.) + [03]: Action subject ("Who?", etc.) / Money window (called by script) [04]: New equipment selection [05]: Offense/Defense [06]: Equip diff --git a/src/c/vwf.c b/src/c/vwf.c index 3565d5b..cf4436a 100644 --- a/src/c/vwf.c +++ b/src/c/vwf.c @@ -841,6 +841,60 @@ int print_string(byte *str, int x, int y) return (charCount & 0xFFFF) | (totalWidth << 16); } +// Edited version which recognizes the 5F FF code +// Returns: ____XXXX = number of characters printed +// XXXX____ = number of pixels printed +// x, y: pixels +int print_string_edited(byte *str, int x, int y) +{ + if (str == NULL) + return 0; + + byte chr; + int initial_x = x; + int charCount = 0; + + while (!(str[1] == 0xFF && str[0] == 0x00)) + { + if(str[1] != 0xFF) + { + x += print_character(decode_character(*str++), x, y); + charCount++; + } + else if(str[0] == 0x5F) + { + x += str[2]; + str += 3; + } + } + + int totalWidth = x - initial_x; + + return (charCount & 0xFFFF) | (totalWidth << 16); +} + +unsigned short printstr_hlight_edited(WINDOW* window, byte* str, unsigned short x, unsigned short y, bool highlight) +{ + return printstr_hlight_pixels_edited(window, str, x << 3, y << 4, highlight); +} + +unsigned short printstr_hlight_pixels_edited(WINDOW* window, byte* str, unsigned short x, unsigned short y, bool highlight) +{ + unsigned short printX = x + ((window->window_x) << 3); + unsigned short printY = y + ((window->window_y) << 3); + unsigned short tmpPaletteMsk = (*palette_mask); + unsigned short palette_mask_highlight = tmpPaletteMsk; + if(highlight) + palette_mask_highlight += 0x1000; + (*palette_mask) = palette_mask_highlight; + + unsigned short printed_Characters = print_string_edited(str, printX, printY); + + (*palette_mask) = tmpPaletteMsk; + + return printed_Characters; +} + int print_menu_string(WINDOW* window) { byte *menu_text = window->menu_text; diff --git a/src/c/vwf.h b/src/c/vwf.h index 56da11f..71db632 100644 --- a/src/c/vwf.h +++ b/src/c/vwf.h @@ -76,6 +76,9 @@ void copy_tile(int xSource, int ySource, int xDest, int yDest); void copy_tile_up(int x, int y); void print_space(WINDOW *window); int print_string(byte *str, int x, int y); +int print_string_edited(byte *str, int x, int y); +unsigned short printstr_hlight_edited(WINDOW* window, byte* str, unsigned short x, unsigned short y, bool highlight); +unsigned short printstr_hlight_pixels_edited(WINDOW* window, byte* str, unsigned short x, unsigned short y, bool highlight); int print_menu_string(WINDOW* window); void print_number_menu(WINDOW* window, int style); void print_number_menu_current(byte digit, WINDOW* window); diff --git a/src/m2-hack.asm b/src/m2-hack.asm index 2ebbcaa..d50c4f0 100644 --- a/src/m2-hack.asm +++ b/src/m2-hack.asm @@ -877,6 +877,19 @@ b 0x80B8A2E .org 0x80B785C :: mov r0,0xC // allocate 2 extra bytes for cash window string .org 0x80B786C :: mov r3,6 // make window 1 fewer tiles wide +//--------------------------------------------------------- +// B8A60 hacks (print current cash balance, called from script. Since the script is already executing, +// this version cannot use m2_printnextch, so it requires an edited version of m2_printstr_hlight which recognizes 5F FF) +//--------------------------------------------------------- + +.org 0x80B8A80 +ldr r2,[r5,#0] +mov r1,0x30 // right-align to 48 pixels +bl format_cash_window +b 0x80B8AAA + +.org 0x80B8AC0 :: bl printstr_hlight_edited + //--------------------------------------------------------- // [68 FF] - clear window //--------------------------------------------------------- From 63421fa3cc2acf7b828dd3ed2ed4ed9739ffa782 Mon Sep 17 00:00:00 2001 From: Lorenzooone Date: Sun, 23 Feb 2020 05:26:55 +0100 Subject: [PATCH 2/2] Update to make 5F FF act as it should --- src/c/vwf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/c/vwf.c b/src/c/vwf.c index cf4436a..3828e11 100644 --- a/src/c/vwf.c +++ b/src/c/vwf.c @@ -863,7 +863,7 @@ int print_string_edited(byte *str, int x, int y) } else if(str[0] == 0x5F) { - x += str[2]; + x = initial_x + str[2]; str += 3; } }