Skip to content

Commit

Permalink
https://github.com/jeffman/Mother2GbaTranslation/issues/100
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorenzooone committed Feb 23, 2020
1 parent 87987ab commit 4a82480
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion notes/m2-notes.txt
Expand Up @@ -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
Expand Down
54 changes: 54 additions & 0 deletions src/c/vwf.c
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/c/vwf.h
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions src/m2-hack.asm
Expand Up @@ -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
//---------------------------------------------------------
Expand Down

0 comments on commit 4a82480

Please sign in to comment.