From 626cfc8c7ea2c0dad9df7c2dae898b0cb1c57124 Mon Sep 17 00:00:00 2001 From: Lorenzooone Date: Mon, 23 Sep 2019 01:49:38 +0200 Subject: [PATCH] Goods buffers (Stored goods' one isn't complete yet) --- src/c/ext.c | 3 +- src/c/goods.c | 17 ++- src/c/vwf.c | 127 +++++++++++++++- src/c/vwf.h | 6 + src/m2-customcodes.asm | 32 +++- src/m2-hack.asm | 66 ++++++++- src/m2-vwf-entries.asm | 255 ++++++++++++++++++++++++++++++-- working/m12-strings-english.txt | 12 +- 8 files changed, 478 insertions(+), 40 deletions(-) diff --git a/src/c/ext.c b/src/c/ext.c index 7544fb9..80c808d 100644 --- a/src/c/ext.c +++ b/src/c/ext.c @@ -19,4 +19,5 @@ int __attribute__((naked)) m2_setupwindow(WINDOW* window, short window_x, short int __attribute__((naked)) m2_clearwindowtiles(WINDOW* window) {} int __attribute__((naked)) customcodes_parse_generic(int code, char* parserAddress, WINDOW* window, int* dest) {} void __attribute__((naked)) m2_printstr(WINDOW* window, byte* str, unsigned short x, unsigned short y, bool highlight) {} -void __attribute__((naked)) m2_setupbattlename(short value) {} \ No newline at end of file +void __attribute__((naked)) m2_setupbattlename(short value) {} +void __attribute__((naked)) store_pixels_overworld() {} \ No newline at end of file diff --git a/src/c/goods.c b/src/c/goods.c index 15e35c4..50319bb 100644 --- a/src/c/goods.c +++ b/src/c/goods.c @@ -110,14 +110,15 @@ int goods_outer_process(WINDOW* window, int y_offset, bool give) } *active_window_party_member = current_pc; - m2_hpwindow_up(current_pc); - clear_name_header(window); - copy_name_header(window, current_pc); // Print item names if (!window->vwf_skip) { goods_print_items(window, current_items, y_offset); + m2_hpwindow_up(current_pc); //Why were these done repeatedly? I made it so they're done only when printing, however if there is a reason why they shouldn't, feel free to put them back + clear_name_header(window); + copy_name_header(window, current_pc); + store_pixels_overworld(); window->vwf_skip = true; } @@ -417,10 +418,13 @@ int goods_inner_process(WINDOW *window, unsigned short *items) clear_name_header(window); copy_name_header(window, *active_window_party_member); - m2_clearwindowtiles(window); + clearWindowTiles_buffer(window); if (weird_value > 0) + { goods_print_items(window, items, 0); + store_pixels_overworld(); + } } if (state_shadow.up || state_shadow.down || state_shadow.left || state_shadow.right) @@ -479,6 +483,7 @@ int goods_inner_process(WINDOW *window, unsigned short *items) // Erases the slot before printing. Prints blanks for null items. void goods_print_items(WINDOW *window, unsigned short *items, int y_offset) { + byte* dest = (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER)); int item_x = (window->window_x << 3) + 8; int item_y = (window->window_y + y_offset) << 3; @@ -488,7 +493,7 @@ void goods_print_items(WINDOW *window, unsigned short *items, int y_offset) int x = item_x + ((i & 1) * 88); int y = item_y + ((i >> 1) * 16); - print_blankstr(x >> 3, y >> 3, 11); + print_blankstr_buffer(x >> 3, y >> 3, 11, dest); if (item > 0) { @@ -501,7 +506,7 @@ void goods_print_items(WINDOW *window, unsigned short *items, int y_offset) } byte *item_str = m2_strlookup(m2_items_offsets, m2_items_strings, item); - print_string(item_str, x + x_offset, y); + print_string_in_buffer(item_str, x + x_offset, y, dest); } } } diff --git a/src/c/vwf.c b/src/c/vwf.c index 63e7f65..56c8c75 100644 --- a/src/c/vwf.c +++ b/src/c/vwf.c @@ -153,6 +153,23 @@ int count_pixels_to_tiles(byte *str, int length, int startingPos) return tiles; } +//For strings without any control code besides the 00 FF one +int count_pixels_to_tiles_normal_string(byte *str, int startingPos) +{ + int pixels = startingPos; + for(int i = 0;; i++) + { + if((str[i + 1] != 0xFF)) //The latter one is not really needed + pixels += (m2_widths_table[0][decode_character(str[i])] & 0xFF); + else + break; + } + int tiles = (pixels - startingPos)>> 3; + if(((pixels - startingPos) & 7) != 0) + tiles +=1; + return tiles; +} + byte print_character(byte chr, int x, int y) { return print_character_formatted(chr, x, y, 0, 0xF); @@ -408,7 +425,6 @@ byte print_character_with_callback_1bpp_buffer(byte chr, int x, int y, byte *des int tileIndex = get_tile_number_with_offset_buffer(tileX + dTileX, tileY + dTileY); int tileIndexRight = get_tile_number_with_offset_buffer(tileX + dTileX + 1, tileY + dTileY); bool availableSwap = (dTileY != (tileHeight - 1)); - bool usedRight = false; int realTileIndex = tileIndex; int realTileIndexRight = tileIndexRight; bool useful = false; //Maybe we go over the maximum tile height, let's make sure the extra tile is properly set IF it's useful @@ -424,9 +440,6 @@ byte print_character_with_callback_1bpp_buffer(byte chr, int x, int y, byte *des unsigned short tmpCanvasRow = canvasRow; canvasRow |= glyphRow; - if((canvasRow >> 8) != (tmpCanvasRow >> 8)) - usedRight = true; - if(!availableSwap && ((row + offsetY) >> 3) == 1 && canvasRow != tmpCanvasRow) //This changed the canvas, then it's useful... IF it's the extra vertical tile useful = true; @@ -452,12 +465,12 @@ byte print_character_with_callback_1bpp_buffer(byte chr, int x, int y, byte *des if (tilemapPtr != NULL) { tilemapPtr[tileX + dTileX + ((tileY + dTileY) * tilemapWidth)] = paletteMask | getTileCallback(tileX + dTileX, tileY + dTileY); - if(usedRight) + if(renderedWidth - 8 + offsetX > 0 && offsetX != 0) tilemapPtr[tileX + dTileX + 1 + ((tileY + dTileY) * tilemapWidth)] = paletteMask | getTileCallback(tileX + dTileX + 1, tileY + dTileY); if(useful) { tilemapPtr[tileX + dTileX + ((tileY + tmpTileY) * tilemapWidth)] = paletteMask | getTileCallback(tileX + dTileX, tileY + tmpTileY); - if(usedRight) + if(renderedWidth - 8 + offsetX > 0 && offsetX != 0) tilemapPtr[tileX + dTileX + 1 + ((tileY + tmpTileY) * tilemapWidth)] = paletteMask | getTileCallback(tileX + dTileX + 1, tileY + tmpTileY); } } @@ -786,6 +799,7 @@ int print_menu_string(WINDOW* window) break; default: looping = false; + window->menu_text = NULL; //Otherwise it will keep printing indefinetly break; } } @@ -1482,6 +1496,38 @@ int printstr_buffer(WINDOW* window, byte* str, unsigned short x, unsigned short return retValue; } +//Instead of printing an highlighted version of the string, it just highlights the corresponding arrangements +int highlight_string(WINDOW* window, byte* str, unsigned short x, unsigned short y, bool highlight) +{ + int retValue = 0; + if(highlight) + { + unsigned short palette_mask_highlight = (*palette_mask) + (highlight == true ? 0x1000 : 0); + unsigned short* arrangementBase = (*tilemap_pointer) + window->window_x + x + ((window->window_y + (y << 1)) << 5); + int totalTiles = count_pixels_to_tiles_normal_string(str, 0); + for(int i = 0; i < totalTiles; i++) + { + arrangementBase[i] = (arrangementBase[i] & 0x0FFF) | palette_mask_highlight; + arrangementBase[i + 0x20] = (arrangementBase[i + 0x20] & 0x0FFF) | palette_mask_highlight; + } + retValue = (x + totalTiles) << 3; + } + return retValue; +} + +//Highlights "Talk to" +void highlight_talk_to() +{ + char Talk_to[] = "Talk to"; + byte str[0xA]; + int i; + for(i = 0; i < (sizeof(Talk_to) - 1); i++) + str[i] = encode_ascii(Talk_to[i]); + str[i++] = 0; + str[i] = 0xFF; + highlight_string(getWindow(0), str, 1, 0, true); +} + unsigned short printstr_hlight_buffer(WINDOW* window, byte* str, unsigned short x, unsigned short y, bool highlight) { return printstr_hlight_pixels_buffer(window, str, x << 3, y << 4, highlight); @@ -1529,6 +1575,39 @@ int initWindow_buffer(WINDOW* window, byte* text_start, unsigned short delay_bet return 0; } +//A different initWindow called by some windows +int initWindow_cursor_buffer(WINDOW* window, byte* text_start, unsigned short cursor_x_delta, unsigned short unknown7a, unsigned short cursor_x_base) +{ + window->vwf_skip = false; + window->unknown3 = 0; + window->text_x = 0; + window->text_y = 0; + window->text_offset = 0; + window->text_start = text_start; + window->text_start2 = text_start; + window->delay_between_prints = 0; + window->delay = 0; + window->counter = 0; + window->loaded_code = 1; + if(!window->enable) + { + window->cursor_y = 0; + window->unknown6 = 0; + window->unknown6a = 0; + window->unknown7 = 0; + window->unknown7a = unknown7a; + window->cursor_x = cursor_x_base; + window->cursor_x_base = cursor_x_base; + window->cursor_x_delta = cursor_x_delta; + } + window->enable = true; + window->flags_unknown1 |= 1; + window->redraw = true; + if(text_start == NULL) + buffer_drawwindow(window, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); + return 0; +} + void clearWindowTiles_buffer(WINDOW* window) { clear_window_buffer(window, (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER))); @@ -1883,6 +1962,42 @@ void store_pixels_overworld_buffer(int totalYs) } } +void store_pixels_overworld_buffer_totalTiles(int totalTiles) +{ + byte* buffer = (byte*)(OVERWORLD_BUFFER - ((*tile_offset) * TILESET_OFFSET_BUFFER_MULTIPLIER)); + for(int i = 0; i < totalTiles; i++) + { + //Not using functions for the tile values saves about 30k cycles on average + int tile = m2_coord_table[i] + *tile_offset; + int addedValue = (i >> 5) << 6; + int tile_buffer = (i & 0x1F) + addedValue + *tile_offset; + int* bufferValues = (int*)(&buffer[(tile_buffer * 8)]); + unsigned int first_half = bufferValues[0]; + unsigned int second_half = bufferValues[1]; + vram[(tile * 8) + 0] = m2_bits_to_nybbles_fast[(first_half >> 0) & 0xFF]; + vram[(tile * 8) + 1] = m2_bits_to_nybbles_fast[(first_half >> 8) & 0xFF]; + vram[(tile * 8) + 2] = m2_bits_to_nybbles_fast[(first_half >> 0x10) & 0xFF]; + vram[(tile * 8) + 3] = m2_bits_to_nybbles_fast[(first_half >> 0x18) & 0xFF]; + vram[(tile * 8) + 4] = m2_bits_to_nybbles_fast[(second_half >> 0) & 0xFF]; + vram[(tile * 8) + 5] = m2_bits_to_nybbles_fast[(second_half >> 8) & 0xFF]; + vram[(tile * 8) + 6] = m2_bits_to_nybbles_fast[(second_half >> 0x10) & 0xFF]; + vram[(tile * 8) + 7] = m2_bits_to_nybbles_fast[(second_half >> 0x18) & 0xFF]; + //Do the tile right below (Saves about 50k cycles on average) + tile += 0x20; + bufferValues += 0x40; + first_half = bufferValues[0]; + second_half = bufferValues[1]; + vram[(tile * 8) + 0] = m2_bits_to_nybbles_fast[(first_half >> 0) & 0xFF]; + vram[(tile * 8) + 1] = m2_bits_to_nybbles_fast[(first_half >> 8) & 0xFF]; + vram[(tile * 8) + 2] = m2_bits_to_nybbles_fast[(first_half >> 0x10) & 0xFF]; + vram[(tile * 8) + 3] = m2_bits_to_nybbles_fast[(first_half >> 0x18) & 0xFF]; + vram[(tile * 8) + 4] = m2_bits_to_nybbles_fast[(second_half >> 0) & 0xFF]; + vram[(tile * 8) + 5] = m2_bits_to_nybbles_fast[(second_half >> 8) & 0xFF]; + vram[(tile * 8) + 6] = m2_bits_to_nybbles_fast[(second_half >> 0x10) & 0xFF]; + vram[(tile * 8) + 7] = m2_bits_to_nybbles_fast[(second_half >> 0x18) & 0xFF]; + } +} + // x, y, width: tile coordinates void print_blankstr_window_buffer(int x, int y, int width, WINDOW* window) { diff --git a/src/c/vwf.h b/src/c/vwf.h index a1877be..4996f4d 100644 --- a/src/c/vwf.h +++ b/src/c/vwf.h @@ -36,6 +36,7 @@ int get_tile_number_with_offset_buffer(int x, int y); int ascii_strlen(char *str); int wrapper_count_pixels_to_tiles(byte *str, int length); int count_pixels_to_tiles(byte *str, int length, int startingPos); +int count_pixels_to_tiles_normal_string(byte *str, int startingPos); int expand_bit_depth(byte row, byte foreground); byte reduce_bit_depth(int row, int foregroundRow); byte print_character(byte chr, int x, int y); @@ -104,6 +105,7 @@ void copy_tile_up_buffer(int x, int y, byte *dest); void setStuffWindow_Graphics(); void clearWindowTiles_buffer(WINDOW* window); int initWindow_buffer(WINDOW* window, byte* text_start, unsigned short delay_between_prints); +int initWindow_cursor_buffer(WINDOW* window, byte* text_start, unsigned short cursor_x_delta, unsigned short unknown7a, unsigned short cursor_x_base); void print_blankstr_buffer(int x, int y, int width, byte *dest); void print_blankstr_window_buffer(int x, int y, int width, WINDOW* window); int print_alphabet_buffer(WINDOW* window); @@ -114,10 +116,13 @@ void printCashWindow(); WINDOW* getWindow(int index); void printTinyArrow(int x, int y); int printstr_buffer(WINDOW* window, byte* str, unsigned short x, unsigned short y, bool highlight); +int highlight_string(WINDOW* window, byte* str, unsigned short x, unsigned short y, bool highlight); +void highlight_talk_to(); unsigned short printstr_hlight_buffer(WINDOW* window, byte* str, unsigned short x, unsigned short y, bool highlight); unsigned short printstr_hlight_pixels_buffer(WINDOW* window, byte* str, unsigned short x, unsigned short y, bool highlight); void load_pixels_overworld_buffer(); void store_pixels_overworld_buffer(int totalYs); +void store_pixels_overworld_buffer_totalTiles(int totalTiles); extern unsigned short m2_coord_table[]; extern byte m2_ness_name[]; @@ -155,3 +160,4 @@ extern void m2_sub_d3c50(); extern void m2_sub_d6844(); extern int m2_setupwindow(WINDOW* window, short window_x, short window_y, short window_width, short window_height); extern void m2_setupbattlename(short value); +extern void store_pixels_overworld(); diff --git a/src/m2-customcodes.asm b/src/m2-customcodes.asm index d462005..9211a96 100644 --- a/src/m2-customcodes.asm +++ b/src/m2-customcodes.asm @@ -111,7 +111,7 @@ b @@end //-------------------------------- // 5D FF: Print give text cmp r4,0x5D -bne @@end +bne @@next4 // 5D FF should be treated as a renderable code push {r0-r3} @@ -156,6 +156,36 @@ bl give_print pop {r0} mov r3,#0 sub r3,r3,#1 //r3 is now -1 +b @@end + +@@next4: + +//-------------------------------- +// 5C FF: UNUSED (Was previously used but instead preferred using 5B FF + +@@next5: + +//-------------------------------- +// 5B FF: Print main window (if enabled) without restore of window buffer +cmp r4,#0x5B +bne @@next6 +bl generic_reprinting_first_menu_talk_to_highlight +mov r3,#2 +b @@end + +@@next6: +//-------------------------------- +// 5A FF: Restore the dialogue window +cmp r4,#0x5A +bne @@end +ldr r0,=#0x3005230 +ldr r0,[r0,#8] +mov r1,#0 +strh r1,[r0,#0x2A] +strh r1,[r0,#0x2C] +strb r1,[r0,#3] +bl m2_drawwindow +mov r3,#2 //-------------------------------- @@end: diff --git a/src/m2-hack.asm b/src/m2-hack.asm index 0e6e3da..3811845 100644 --- a/src/m2-hack.asm +++ b/src/m2-hack.asm @@ -63,6 +63,7 @@ mov r3,6 .org 0x80B8890 :: bl print_window_with_buffer :: bl b8894_printCashWindowAndStore //Main window + Cash Window out of Status menu .org 0x80B8664 :: bl print_window_with_buffer :: bl b8894_printCashWindowAndStore //Main window + Cash Window out of PSI menu .org 0x80B8740 :: bl print_window_with_buffer :: bl b8894_printCashWindowAndStore //Main window + Cash Window out of Equip menu +.org 0x80B859C :: bl print_window_with_buffer :: bl b8894_printCashWindowAndStore //Main window + Cash Window out of Goods menu .org 0x80B831A :: bl initWindow_buffer .org 0x80B8320 :: bl b8320_statusWindowTextStore @@ -78,6 +79,8 @@ mov r3,6 //--------------------------------------------------------- .org 0x80DC22A :: bl dc22a_load_buffer_battle +.org 0x80DC8C8 :: lsl r1,r0,#4 :: nop //Fixes wrong pointer +.org 0x80DC8DE :: nop :: nop //Removes useless print //--------------------------------------------------------- // PSI battle window hacks @@ -276,6 +279,62 @@ mov r3,6 .org 0x80BBDF0 :: mov r2,#0x54 :: mov r3,#0x13 :: bl printNumberEquip //Change second defense number's position - Defensive Equipment .org 0x80BBE20 :: mov r2,#0x54 :: mov r3,#3 :: bl bb1aa_printnumberequip_store //Change second offense number's position - Defensive Equipment +//--------------------------------------------------------- +// Goods window hacks +//--------------------------------------------------------- + +.org 0x80B7F4E :: bl c5f80_printstr_hlight_buffer_store_buffer //Prints the balance window +.org 0x80B7F72 :: bl initWindow_cursor_buffer //Sets up the goods window +.org 0x80B97A8 :: bl initWindow_buffer //Prints "Who?" going into the window +.org 0x80B97AE :: bl baf9c_print_window_store_buffer_top +.org 0x80B992A :: bl initWindow_buffer //Prints "Who?" coming from the inner window +.org 0x80B9930 :: bl baf9c_print_window_store_buffer_top +.org 0x80B986E :: bl initWindow_buffer +.org 0x80B98B8 :: bl b98b8_print_window_store_buffer_needed //Prints "Which?" going into the window +.org 0x80B99A0 :: bl highlight_string //Highlight chosen item +.org 0x80B9A4C :: bl baf9c_print_window_store_buffer_needed //Prints "Use\nDrop\n,etc." going into the window +.org 0x80B9ADE :: bl initWindow_buffer +.org 0x80BA688 :: bl baf9c_print_window_store_buffer_top //Prints "Use\nDrop\n,etc." going out of the give window +.org 0x80BA340 :: bl initWindow_buffer //Prints "Who?" going into the window +.org 0x80BA346 :: bl print_window_with_buffer +.org 0x80BA37A :: bl initWindow_buffer //initiates the Give window +.org 0x80BA7FA :: bl initWindow_buffer //initiates the inventory window out of help +.org 0x80BA810 :: bl initWindow_buffer //initiates the options window out of help + +//--------------------------------------------------------- +// Goods window hacks - Stored Goods +//--------------------------------------------------------- + +//Choose inventory +.org 0x80BCDB4 :: bl initWindow_buffer +//First enter window - More than one page +.org 0x80C63BC :: bl initWindow_buffer +.org 0x80C63CC :: bl printstr_hlight_buffer //->Stored Goods(X) +.org 0x80C6412 :: bl printstr_hlight_buffer //Left part of the inventory +.org 0x80C643E :: bl printstr_hlight_buffer //Right part of the inventory +//First enter window - Only one page +.org 0x80C6492 :: bl initWindow_buffer +.org 0x80C64DA :: bl printstr_hlight_buffer //Left part of the inventory +.org 0x80C6518 :: bl printstr_hlight_buffer //Right part of the inventory +.org 0x80C694A :: bl clearWindowTiles_buffer +//When pressing arrow to switch page +.org 0x80C69D8 :: mov r0,#0x12 //Proper address to "->Stored Goods(3)" string +.org 0x80C69EE :: bl printstr_hlight_buffer //->Stored Goods(X) +.org 0x80C6A6C :: bl printstr_hlight_buffer //Left part of the inventory +.org 0x80C6AA4 :: bl printstr_hlight_buffer //Right part of the inventory +.org 0x80C6AC0 :: bl c6ac0_store_buffer_stored_goods_switch_page + +//--------------------------------------------------------- +// Goods window hacks - in battle +//--------------------------------------------------------- + +.org 0x80E05C0 :: lsl r1,r0,#4 :: nop //Fixes wrong pointer +.org 0x80E05D8 :: nop :: nop //Removes useless print +.org 0x80E0C46 :: bl initWindow_cursor_buffer //initiates the goods window in battle +.org 0x80E0CE4 :: bl e0ce4_redraw_battle_window_first_four //Reprints the background window for the target choosing items +.org 0x80E0D1E :: bl printstr_hlight_buffer //Prints the chosen item +.org 0x80E0EFA :: bl initWindow_buffer :: ldr r0,[r4,#0xC] :: bl print_window_with_buffer //Out of ally target window +.org 0x80E0FAA :: bl e0faa_redraw_battle_window_first_two //--------------------------------------------------------- // BAEF8 hacks (equip window) @@ -1021,12 +1080,6 @@ bl ba7be_reprint_first_menu .org 0x80B9AA2 bl b9aa2_reprint_first_menu -//--------------------------------------------------------- -// C6BA2 hacks (Fixes main window after exiting the Stored Goods window) -//--------------------------------------------------------- -.org 0x80C6BA2 -bl c6ba2_reprint_first_menu - //--------------------------------------------------------- // BCEB0 hacks (Fixes main window after exiting the pickup menu) //--------------------------------------------------------- @@ -1772,6 +1825,7 @@ m2_coord_table_file: .definelabel m2_setup_window ,0x80BD844 .definelabel m2_strlookup ,0x80BE260 .definelabel m2_initwindow ,0x80BE458 +.definelabel m2_initwindow_cursor ,0x80BE4C8 .definelabel m2_statuswindow_numbers,0x80C0A5C .definelabel m2_psiwindow ,0x80C1FBC .definelabel m2_drawwindow ,0x80C87D0 diff --git a/src/m2-vwf-entries.asm b/src/m2-vwf-entries.asm index aa60a5f..ad0d718 100644 --- a/src/m2-vwf-entries.asm +++ b/src/m2-vwf-entries.asm @@ -833,6 +833,39 @@ bl 0x80C2480 //Prints the target pop {pc} .pool +//============================================================================== +//Redraw main battle window for "goods" targets +e0ce4_redraw_battle_window_first_four: +push {lr} +push {r0-r3} +mov r0,#3 +mov r1,#3 +mov r2,#4 +bl printBattleMenu +pop {r0-r3} +bl initWindow_buffer +pop {pc} + +//============================================================================== +//Redraw main battle window for going back to Goods from targets +e0faa_redraw_battle_window_first_two: +push {r4,lr} +push {r0-r3} +mov r0,#1 +mov r1,#1 +mov r2,#4 +bl printBattleMenu +pop {r0-r3} +ldr r4,[sp,#8] +add sp,#-4 +str r4,[sp,#0] +bl initWindow_cursor_buffer +mov r0,#4 +bl store_pixels_overworld_buffer_totalTiles +mov r0,#0 +add sp,#4 +pop {r4,pc} + //============================================================================== //Calls the funcion which loads the targets in and then stores the buffer ba8ac_load_targets_print: @@ -848,7 +881,6 @@ bl store_pixels_overworld @@end: pop {pc} - //============================================================================== // Print "PSI " c239c_print_psi: @@ -1572,6 +1604,8 @@ add r2,#1 cmp r2,#9 bne @@cycle +bl store_pixels_overworld // Stores buffer after printing happened + pop {pc} .pool @@ -1608,6 +1642,7 @@ str r2,[r3,#0] //Store it mov r2,#0 //No y offset bl goods_print_items //Print the inventory +bl store_pixels_overworld pop {r2} ldr r3,=m2_active_window_pc //Restore pc of the window @@ -1691,7 +1726,15 @@ mov r2,#5 mov r3,#2 bl 0x80BE4C8 //Let it do its things ldr r0,[r4,#0] -bl 0x80C8BE4 //Print text in the window +bl print_window_with_buffer //Print text in the window +mov r2,#1 +ldr r0,[r4,#4] //Cash window place in ram +ldrb r0,[r0,#0] +and r2,r0 +cmp r2,#0 +bne @@insidecash +bl store_pixels_overworld_options //Only this window must be reprinted +b @@end @@cash: //Cash @@ -1702,6 +1745,7 @@ and r2,r0 cmp r2,#0 beq @@end //Check if window is enabled before printing in it +@@insidecash: ldr r2,=#0x300130C ldr r0,[r2,#0] mov r1,#2 @@ -1720,9 +1764,104 @@ bl format_cash_window ldr r0,[r4,#4] ldr r1,[r5,#0] mov r2,#0 -bl m2_initwindow //Let it do its things +bl initWindow_buffer //Let it do its things ldr r0,[r4,#4] -bl 0x80C8BE4 //Print text in the window +bl print_window_with_buffer //Print text in the window +bl store_pixels_overworld_psi_window + +@@end: +ldr r4,[sp,#4] +strb r4,[r6,#0] //Restore expected amount of lines to be written +add sp,#8 +pop {r0-r6} +pop {pc} + +.pool + +//============================================================================== +//Reprints both the Main window and the Cash window if need be, but highlights "Talk to" +generic_reprinting_first_menu_talk_to_highlight: +push {lr} +push {r0-r6} +add sp,#-8 +ldr r6,=#0x3005078 //Make sure the game expects only the right amount of lines to be written (so only 1) +ldrb r4,[r6,#0] +str r4,[sp,#4] +mov r4,#0 +strb r4,[r6,#0] +ldr r4,=#0x3005230 //Window generic address + +//Main window +mov r2,#1 +ldr r0,[r4,#0] //Main window place in ram +ldrb r0,[r0,#0] +and r2,r0 +cmp r2,#0 +beq @@cash //Check if window is enabled before printing in it + +ldr r0,=#0x8B17EE4 +ldr r1,=#0x8B17424 +ldr r3,=m2_psi_exist //Flag which if not 0xFF means no one has PSI +ldrb r3,[r3,#0] +cmp r3,#0xFF +beq @@psiNotFound +mov r2,#0 +b @@keep_going +@@psiNotFound: +mov r2,#1 +@@keep_going: +bl m2_strlookup //Load the proper menu string based on m2_psi_exist +mov r1,#0 +str r1,[sp,#0] +mov r1,r0 +ldr r0,[r4,#0] +mov r2,#5 +mov r3,#2 +bl 0x80BE4C8 //Let it do its things +ldr r0,[r4,#0] +bl print_window_with_buffer //Print text in the window +bl highlight_talk_to +mov r2,#1 +ldr r0,[r4,#4] //Cash window place in ram +ldrb r0,[r0,#0] +and r2,r0 +cmp r2,#0 +bne @@insidecash +bl store_pixels_overworld_options //Only this window must be reprinted +b @@end + +@@cash: +//Cash +mov r2,#1 +ldr r0,[r4,#4] //Cash window place in ram +ldrb r0,[r0,#0] +and r2,r0 +cmp r2,#0 +beq @@end //Check if window is enabled before printing in it + +@@insidecash: +ldr r2,=#0x300130C +ldr r0,[r2,#0] +mov r1,#2 +orr r0,r1 +str r0,[r2,#0] +ldr r0,=#0x3001D40 +mov r1,#0xD2 +lsl r1,r1,#3 +add r0,r0,r1 +ldr r0,[r0,#0] //Load the money +ldr r5,=#0x3005200 +ldr r1,[r5,#0] +mov r2,r1 //Load the string address +mov r1,#0x30 //Padding +bl format_cash_window +ldr r0,[r4,#4] +ldr r1,[r5,#0] +mov r2,#0 +bl initWindow_buffer //Let it do its things +ldr r0,[r4,#4] +bl print_window_with_buffer //Print text in the window +bl store_pixels_overworld_psi_window @@end: ldr r4,[sp,#4] @@ -1742,15 +1881,6 @@ mov r0,#1 bl m2_swapwindowbuf pop {pc} -//============================================================================== -//Specific call to generic_reprinting_first_menu which then calls a DMA transfer of the old arrangement -c6ba2_reprint_first_menu: -push {lr} -bl generic_reprinting_first_menu -mov r0,#1 -bl 0x80BD7F8 -pop {pc} - //============================================================================== //Specific call to b9aa2_special_string, needed for the help function ba7be_reprint_first_menu: @@ -1802,7 +1932,23 @@ mov r2,#5 mov r3,#2 bl 0x80BE4C8 //Let it do its things ldr r0,[r4,#0] -bl 0x80C8BE4 //Print text in the window +ldrb r1,[r0,#0] +mov r2,#0xDF +and r2,r1 +strb r2,[r0,#0] //Do not redraw the window +mov r3,r0 +mov r0,#1 +mov r1,#2 +mov r2,#4 +bl print_blankstr_window_buffer //Clears PSI +mov r0,#1 +mov r1,#4 +mov r2,#4 +ldr r3,[r4,#0] +bl print_blankstr_window_buffer //Clears Check +ldr r0,[r4,#0] +bl print_window_with_buffer //Print text in the window +bl store_pixels_overworld_options @@end: ldr r4,[sp,#4] @@ -2127,6 +2273,15 @@ bx r0 //Jump to the next useful piece of code .pool +//============================================================================== +//Stores the buffer for the Stored Goods window when switching the page +c6ac0_store_buffer_stored_goods_switch_page: +mov r0,#8 +str r0,[sp,#0x2C] +push {lr} +bl store_pixels_overworld +pop {pc} + //============================================================================== //Calls print_window_with_buffer and then stores the buffer baf9c_print_window_store_buffer: @@ -2135,6 +2290,51 @@ bl print_window_with_buffer bl store_pixels_overworld pop {pc} +//============================================================================== +//Calls print_window_with_buffer and then stores the buffer if need be +baf9c_print_window_store_buffer_needed: +push {lr} +add sp,#-4 +mov r1,#0x44 +add r1,r1,r0 +ldrb r1,[r1,#0] +str r1,[sp,#0] +bl print_window_with_buffer +ldr r1,[sp,#0] +cmp r1,#0 +beq @@end +bl store_pixels_overworld_use +@@end: +add sp,#4 +pop {pc} + +//============================================================================== +//Calls print_window_with_buffer and then stores the buffer if need be - Special edition which does only a few tiles +b98b8_print_window_store_buffer_needed: +push {lr} +add sp,#-4 +mov r1,#0x44 +add r1,r1,r0 +ldrb r1,[r1,#0] +str r1,[sp,#0] +bl print_window_with_buffer +ldr r1,[sp,#0] +cmp r1,#0 +beq @@end +mov r0,#4 +bl store_pixels_overworld_buffer_totalTiles +@@end: +add sp,#4 +pop {pc} + +//============================================================================== +//Calls print_window_with_buffer and then stores the buffer +baf9c_print_window_store_buffer_top: +push {lr} +bl print_window_with_buffer +bl store_pixels_overworld_top +pop {pc} + //============================================================================== //Calls printstr_hlight_buffer and then stores the buffer c5f80_printstr_hlight_buffer_store_buffer: @@ -3086,6 +3286,33 @@ mov r0,#0x10 bl store_pixels_overworld_buffer pop {r0-r3,pc} +//============================================================================== +//Stores the buffer into the vram. This avoids screen tearing. +store_pixels_overworld_options: +push {r0-r3,lr} +swi #5 //The improved performances allow using a VBlank before the storage in order to prevent screen tearing effectively +mov r0,#6 +bl store_pixels_overworld_buffer +pop {r0-r3,pc} + +//============================================================================== +//Stores the buffer into the vram. This avoids screen tearing. +store_pixels_overworld_use: +push {r0-r3,lr} +swi #5 //The improved performances allow using a VBlank before the storage in order to prevent screen tearing effectively +mov r0,#8 +bl store_pixels_overworld_buffer +pop {r0-r3,pc} + +//============================================================================== +//Stores the buffer into the vram. This avoids screen tearing. +store_pixels_overworld_top: +push {r0-r3,lr} +swi #5 //The improved performances allow using a VBlank before the storage in order to prevent screen tearing effectively +mov r0,#0x2 +bl store_pixels_overworld_buffer +pop {r0-r3,pc} + //============================================================================== //Stores the buffer into the vram. This avoids screen tearing. store_pixels_overworld_player_naming: diff --git a/working/m12-strings-english.txt b/working/m12-strings-english.txt index cad506f..7107348 100644 --- a/working/m12-strings-english.txt +++ b/working/m12-strings-english.txt @@ -2227,7 +2227,7 @@ ^L2231^@Oh, it's my line now? Ooops!^L3409^[86 FF _L2485_][04 FF _L2240_][05 FF _L5243_]^L5243^@What the hey?[01 FF] Well, see you![1D FF][00 FF] ^L2232^[D4 FF 05 00][01 FF]@You have too much stuff.[1D FF][00 FF] ^L2233^[D4 FF 74 00][1B FF 3C 00][86 FF _L5525_][00 FF] -^L2236^[86 FF _L4952_][82 FF _L5246_][F4 FF 01 00 01 00][DD FF 02 00 00 00 00 00 00 00][81 FF _L5247_]@What do you want to store?[02 FF][69 FF][86 FF _L2489_][82 FF _L5248_][88 FF][F4 FF 00 00 00 00][81 FF _L5249_][89 FF][AB FF 00 00][D4 FF 76 00]@The [90 FF 00][1A FF 02 00]?[01 FF] Don't worry, I'll keep it safe.[1B FF 0F 00][02 FF][89 FF][F3 FF 00 00 00 00]^L5250^@Do you have anything else that[01 FF] you want me to store?[03 FF 00 00][04 FF _L2236_][05 FF _L5248_][80 FF _L5248_]^L5247^@I'm sorry.[01 FF] My locker is full.[02 FF][80 FF _L5248_] +^L2236^[86 FF _L4952_][82 FF _L5246_][F4 FF 01 00 01 00][DD FF 02 00 00 00 00 00 00 00][81 FF _L5247_]@What do you want to store?[02 FF][69 FF][86 FF _L2489_][82 FF _L5865_][88 FF][F4 FF 00 00 00 00][81 FF _L5249_][89 FF][AB FF 00 00][D4 FF 76 00][5A FF]@The [90 FF 00][1A FF 02 00]?[01 FF] Don't worry, I'll keep it safe.[1B FF 0F 00][02 FF][89 FF][F3 FF 00 00 00 00]^L5250^@Do you have anything else that[01 FF] you want me to store?[03 FF 00 00][04 FF _L2236_][05 FF _L5248_][80 FF _L5248_]^L5247^@I'm sorry.[01 FF] My locker is full.[02 FF][80 FF _L5248_] ^L2237^@Ooops![1B FF 14 00] You seem to be[01 FF] carrying too much stuff[01 FF] already![1D FF][00 FF] ^L2238^[D4 FF 74 00][1B FF 3C 00][8A FF][C6 FF][D4 FF 66 00][1B FF 64 00][8B FF][86 FF _L5525_][00 FF] ^L2240^@What do you want me to do?^L5255^[03 FF 12 00][04 FF _L2236_][05 FF _L5244_][1C FF 49 00 _L5245_]@Well, take care and I'll talk to[01 FF] you later![1D FF][00 FF]^L5245^@Well, take care and talk to you[01 FF] later![02 FF]@Oh, I said ![02 FF]@It just slipped out of my mouth,[02 FF]@just like I was talking to you[01 FF] when you were gone...[1D FF][00 FF] @@ -4550,8 +4550,8 @@ ^L5044^[8D FF 01 00][A8 FF 00][8A FF][8B FF][8B FF][B6 FF 02 00][8A FF][8B FF][82 FF _L5046_][87 FF][00 FF] [A8 FF 00][82 FF _L5045_][82 FF _L3640_][82 FF _L3640_]^L5045^[C7 FF][87 FF][00 FF] ^L5046^[00 FF] -^L5047^[8B FF][00 FF] -^L5048^[87 FF][62 FF][87 FF][8A FF][82 FF _L5047_][87 FF][91 FF 00][81 FF _L5047_][8B FF][87 FF][89 FF][80 FF _L5048_] +^L5047^[8B FF][00 FF]^L5864^[8B FF][5B FF][5A FF][00 FF] +^L5048^[87 FF][62 FF][87 FF][8A FF][82 FF _L5047_][87 FF][91 FF 00][81 FF _L5864_][8B FF][87 FF][89 FF][80 FF _L5048_] ^L5049^[A8 FF 01][88 FF]@I can examine one of you for[01 FF] $[B8 FF 00][1A FF 04 00].[9C FF][69 FF][03 FF 15 00][86 FF _L4957_][95 FF 02 _L5354_ _L5355_]^L5355^@You really don't need any[01 FF] treatment?[01 FF] All right.^L5367^[86 FF _L5356_][1D FF][00 FF]^L5354^[99 FF 00 00 00 00][81 FF _L5357_][96 FF 02][81 FF _L5358_]@Who is sick?[69 FF][EC FF][01 FF][82 FF _L5355_]^L5366^[88 FF][ED FF 00 00 01 00][95 FF 08 _L5359_ _L5360_ _L5361_ _L5361_ _L5362_ _L5363_ _L5364_ _L5365_]^L5358^[8D FF 01 00][80 FF _L5366_] ^L5051^[A8 FF 01][86 FF _L5371_][82 FF _L5372_]@Who do you want to see?[69 FF][EC FF][01 FF][82 FF _L5373_][88 FF][92 FF 00 01 02][82 FF _L5374_][89 FF][87 FF]@[90 FF 00][1A FF 01 00] was just brought[01 FF] in, and is still unconscious.[02 FF][87 FF]@Please pay $[B8 FF 00][1A FF 04 00] for[01 FF] the doctor's fee.[03 FF 00 00][86 FF _L4957_][95 FF 02 _L5375_ _L5376_]^L5376^@Your friend, right?... It's very[01 FF] serious.[1D FF][00 FF]^L5375^[99 FF 00 00 00 00][81 FF _L5377_][9B FF 00 00 00 00][9C FF][89 FF][EE FF 00 00 01 00 01 00][89 FF][EE FF 00 00 02 00 01 00][89 FF][EE FF 00 00 06 00 01 00][89 FF][87 FF][F7 FF 00 00 64 00][F8 FF 00 00 64 00][D4 FF 25 00][1B FF 32 00]@I'm so glad that you recovered,[01 FF] [90 FF 00][1A FF 01 00].[02 FF]@Come back any time you need.[1D FF][00 FF] ^L5053^[BF FF][BC FF 01 00]^L5447^[A8 FF 01][96 FF 00][81 FF _L5445_][8D FF 00 00][82 FF _L5446_][92 FF 00 02 02][81 FF _L5446_][C0 FF][80 FF _L5447_] @@ -4680,10 +4680,10 @@ ^L5238^@I don't think you can carry[01 FF] everything.[02 FF][78 FF 01 00 01 00]@Well, I'll leave just[01 FF] the [90 FF 00][1A FF 02 00].[02 FF][86 FF _L5240_][78 FF 02 00 01 00][77 FF 00 00][78 FF 03 00 01 00][82 FF _L5241_][77 FF 00 00]^L5241^[00 FF] ^L5239^@I don't think you can carry[01 FF] everything.[02 FF][78 FF 01 00 01 00]@Well, I'll leave just[01 FF] the [90 FF 00][1A FF 02 00][01 FF] and[78 FF 02 00 01 00] the [90 FF 00][1A FF 02 00].[02 FF][86 FF _L5240_][78 FF 03 00 01 00][77 FF 00 00][00 FF] ^L5240^[83 FF 49 00][BD FF 01 _L5223_][9C FF][D4 FF 76 00]@OK, here we are.[01 FF] Thank you![1D FF][C6 FF][86 FF _L4023_][86 FF _L4910_][00 FF] -^L5244^[BC FF 01 00][F5 FF][82 FF _L5251_][91 FF FF][82 FF _L5252_]@What would you like[01 FF] returned?[02 FF][69 FF]^L5254^[F1 FF][82 FF _L5248_][87 FF][88 FF][86 FF _L5048_][82 FF _L5253_][8A FF][8B FF][D4 FF 74 00][F2 FF 00 00 00 00][AB FF 00 00]@The [90 FF 00][1A FF 02 00]?[01 FF] Take good care of it.[02 FF]@Is there anything else you want[01 FF] returned?[03 FF 00 00][04 FF _L5244_][05 FF _L5248_][80 FF _L5248_]^L5253^[87 FF][69 FF][80 FF _L5254_] +^L5244^[BC FF 01 00][F5 FF][82 FF _L5251_][91 FF FF][82 FF _L5252_]@What would you like[01 FF] returned?[02 FF][69 FF]^L5254^[F1 FF][82 FF _L5865_][87 FF][88 FF][86 FF _L5048_][82 FF _L5253_][8A FF][8B FF][D4 FF 74 00][F2 FF 00 00 00 00][AB FF 00 00]@The [90 FF 00][1A FF 02 00]?[01 FF] Take good care of it.[02 FF]@Is there anything else you want[01 FF] returned?[03 FF 00 00][04 FF _L5244_][05 FF _L5248_][80 FF _L5248_]^L5253^[87 FF][69 FF][80 FF _L5254_] ^L5246^@I don't think you have anything[01 FF] to store.[02 FF][80 FF _L5248_] -^L5248^@Do you need anything else from[01 FF] me?[80 FF _L5255_] -^L5249^@I think you should hang on to[01 FF] that.[02 FF][80 FF _L5250_] +^L5865^[5B FF][5A FF]^L5248^@Do you need anything else from[01 FF] me?[80 FF _L5255_] +^L5249^[5A FF]@I think you should hang on to[01 FF] that.[02 FF][80 FF _L5250_] ^L5251^@I'm not storing any of your[01 FF] stuff.[02 FF][80 FF _L5248_] ^L5252^@I think you are already carrying[01 FF] too many things.[02 FF][80 FF _L5248_] ^L5261^[22 FF]@Our delivery men got tired and[01 FF] quit.[02 FF]@So, we decided to close the[01 FF] shop.[02 FF]@Thank you for consistently[01 FF] using us for all of your pizza[01 FF] needs.[1B FF 14 00][01 FF][D4 FF 0B 00] (Click!)[1D FF][00 FF]