diff --git a/notes/m2-notes.txt b/notes/m2-notes.txt index c55bc9a4..18fc3865 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 3565d5bd..cf4436a0 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 56da11f8..71db6329 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 2ebbcaa3..d50c4f0c 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 //---------------------------------------------------------