Merge pull request #150 from Lorenzooone/psi_battle_nopp_fix

Fix windows when the "Not enough PP!" message shows up in battle
This commit is contained in:
jeffman 2021-12-05 13:30:20 -05:00 committed by GitHub
commit 8f24089e13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 128 additions and 95 deletions

View File

@ -36,6 +36,7 @@ $input_c_files =
$input_c_test_files =
"src/c/tests/main_test.c",
"src/c/tests/utils.c",
"src/c/tests/battle_test.c",
"src/c/tests/debug_printf/test_print.c",
"src/c/tests/debug_printf/mgba.c",

View File

@ -37,3 +37,4 @@ byte* __attribute__((naked)) m2_malloc(int size) {}
void __attribute__((naked)) m2_free(int* address) {}
void __attribute__((naked)) m2_title_teardown() {}
void __attribute__((naked)) vblank() {}
void __attribute__((naked)) reg_ram_reset(int flag) {}

View File

@ -1,8 +1,6 @@
#include "battle_test.h"
#include "utils.h"
#include "debug_printf/test_print.h"
#include "../locs.h"
bool text_stayed_inside(WINDOW* window);
void test_encounter_text()
{
@ -44,7 +42,7 @@ void test_death_text()
assert_message(text_stayed_inside(window_pointers[2]), "Death text for Enemy %d", j);
}
m2_btl_user_ptr->letter = 0x17;
m2_btl_user_ptr->letter = W_LETTER - INITIAL_SYMBOL_ENEMY;
m2_btl_user_ptr->unknown_3[0] = 0;
for(int j = 0; j <= 230; j++)
@ -58,38 +56,10 @@ void test_death_text()
}
bool text_stayed_inside(WINDOW* window)
{
for(int i = 0; i < window->window_height; i++)
if((*tilemap_pointer)[(0x20*(window->window_y + i))+window->window_x + window->window_width] != RIGHT_BORDER_TILE)
return false;
return true;
}
void setup_ness_name()
{
for(int i = 0; i < 5; i++)
*(pc_names + i) = W_LETTER;
*(pc_names + 5) = 0;
*(pc_names + 6) = 0xFF;
}
void setup_king_name()
{
for(int i = 0; i < 6; i++)
*(pc_names + KING_OFFSET + i) = W_LETTER;
*(pc_names + KING_OFFSET + 6) = 0;
*(pc_names + KING_OFFSET + 7) = 0xFF;
}
void setup_battle_tests()
static void _setup()
{
(window_pointers[2]) = (struct WINDOW*)0x2029F88;
(window_pointers[2])->window_x = 4;
(window_pointers[2])->window_y = 1;
(window_pointers[2])->window_width = 0x16;
(window_pointers[2])->window_height = 4;
(window_pointers[2])->window_area = (window_pointers[2])->window_width * (window_pointers[2])->window_height;
m2_setupwindow((window_pointers[2]), 4, 1, 0x16, 4);
m2_btl_user_ptr = (BATTLE_DATA*)0x2021110;
m2_btl_target_ptr = (BATTLE_DATA*)0x2021110;
setup_ness_name();
@ -103,14 +73,8 @@ void setup_battle_tests()
m2_script_readability = false;
}
void do_battle_tests()
{
test_encounter_text();
test_death_text();
}
void start_battle_tests()
{
setup_battle_tests();
do_battle_tests();
run_test(test_encounter_text);
run_test(test_death_text);
}

View File

@ -1,9 +1,7 @@
#include "../battle_data.h"
#include "debug_printf/test_print.h"
#define W_LETTER 0x87
#define KING_OFFSET 0x1C
#define RIGHT_BORDER_TILE 0x0095
#define INITIAL_SYMBOL_ENEMY 0x70
void start_battle_tests();

View File

@ -6,24 +6,10 @@ void start_tests()
{
start_session();
blank_memory();
start_battle_tests();
blank_memory();
end_session();
while(1)
vblank();
}
void blank_memory()
{
int blank_value = 0;
cpufastset(&blank_value, (void*)EWRAM, CPUFASTSET_FILL | (EWRAM_SIZE >> 2));
cpufastset(&blank_value, (void*)IWRAM, CPUFASTSET_FILL | (IWRAM_SIZE >> 3));
cpufastset(&blank_value, (void*)IO, CPUFASTSET_FILL | (IO_SIZE >> 2));
cpufastset(&blank_value, (void*)PALETTES, CPUFASTSET_FILL | (PALETTES_SIZE >> 2));
cpufastset(&blank_value, (void*)VRAM, CPUFASTSET_FILL | (VRAM_SIZE >> 2));
cpufastset(&blank_value, (void*)OBJECTS, CPUFASTSET_FILL | (OBJECTS_SIZE >> 2));
}

View File

@ -1,21 +1,5 @@
#include "debug_printf/test_print.h"
#define CPUFASTSET_FILL (0x1000000)
#define EWRAM (0x2000000)
#define EWRAM_SIZE (0x40000)
#define IWRAM (0x3000000)
#define IWRAM_SIZE (0x8000)
#define IO (0x4000000)
#define IO_SIZE (0x400)
#define PALETTES (0x5000000)
#define PALETTES_SIZE (0x400)
#define VRAM (0x6000000)
#define VRAM_SIZE (0x18000)
#define OBJECTS (0x7000000)
#define OBJECTS_SIZE (0x400)
void start_tests();
void blank_memory();
extern void vblank();
extern void cpufastset(void *source, void *dest, int mode);
extern void vblank();

44
src/c/tests/utils.c Normal file
View File

@ -0,0 +1,44 @@
#include "utils.h"
#define CPUFASTSET_FILL (0x1000000)
#define IWRAM (0x3000000)
#define IWRAM_SIZE (0x8000-0x2000)
#define NON_IWRAM_RESET 0xFD
#define RIGHT_BORDER_TILE 0x0095
void blank_memory()
{
int blank_value = 0;
cpufastset(&blank_value, (void*)IWRAM, CPUFASTSET_FILL | (IWRAM_SIZE >> 2));
reg_ram_reset(NON_IWRAM_RESET);
}
void setup_ness_name()
{
for(int i = 0; i < 5; i++)
*(pc_names + i) = W_LETTER;
*(pc_names + 5) = 0;
*(pc_names + 6) = 0xFF;
}
void setup_king_name()
{
for(int i = 0; i < 6; i++)
*(pc_names + KING_OFFSET + i) = W_LETTER;
*(pc_names + KING_OFFSET + 6) = 0;
*(pc_names + KING_OFFSET + 7) = 0xFF;
}
bool text_stayed_inside(WINDOW* window)
{
if(window->redraw)
return true;
for(int i = 0; i < window->window_height; i++)
if((*tilemap_pointer)[(0x20*(window->window_y + i))+window->window_x + window->window_width] != RIGHT_BORDER_TILE)
return false;
return true;
}

24
src/c/tests/utils.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef TEST_UTILS
#define TEST_UTILS
#include "../window.h"
#include "../locs.h"
#define W_LETTER 0x87
#define KING_OFFSET 0x1C
#define run_test(func) \
blank_memory();\
_setup();\
func();
void setup_ness_name();
void setup_king_name();
void blank_memory();
bool text_stayed_inside(WINDOW* window);
extern void cpufastset(void *source, void *dest, int mode);
extern void reg_ram_reset(int flag);
extern int m2_setupwindow(WINDOW* window, short window_x, short window_y, short window_width, short window_height);
#endif

View File

@ -526,6 +526,17 @@ mov r0,0x50
//Do not redraw unless it is needed
.org 0x80E079A :: bl e079a_battle_psi_window
//Handle background window
.org 0x80E079E :: bl e06ec_clear_window
.org 0x80E0888 :: bl e06ec_redraw_psi
.org 0x80E0A16 :: bl e06ec_redraw_bash_psi
//Handle coming back from the "Not enough PP!" window
.org 0x80E0B10 :: bl initWindow_buffer
.org 0x80E0B2A :: bl initWindow_cursor_buffer
.org 0x80E0B30 :: bl print_window_with_buffer
.org 0x80E0B34 :: bl e0b34_psi_not_enough_pp_reverse_windows :: b 0x80E0B52
//---------------------------------------------------------
// C4B2C hacks (Equip window render)
//---------------------------------------------------------
@ -853,10 +864,6 @@ b 0x80D3A14
.org 0x80DCC36 :: mov r2,2 // "to X" position
.org 0x80DCCE0 :: mov r2,2 // "to the Front Row" position
.org 0x80E079E :: bl e06ec_clear_window
.org 0x80E0888 :: bl e06ec_redraw_psi
.org 0x80E0A16 :: bl e06ec_redraw_bash_psi
//---------------------------------------------------------
// Equipment number printing in dialogue window
//---------------------------------------------------------
@ -2384,11 +2391,14 @@ disclaimer_map:
.definelabel m2_psitargetwindow ,0x80B8AE0
.definelabel m2_isequipped ,0x80BC670
.definelabel m2_swapwindowbuf ,0x80BD7AC
.definelabel m2_setup_window ,0x80BD844
.definelabel m2_setup_bg_window ,0x80BD844
.definelabel m2_setupwindow ,0x80BE188
.definelabel m2_strlookup ,0x80BE260
.definelabel m2_initwindow ,0x80BE458
.definelabel m2_resetwindow ,0x80BE490
.definelabel m2_initwindow_cursor ,0x80BE4C8
.definelabel m2_statuswindow_numbers,0x80C0A5C
.definelabel m2_menuwindow ,0x80C1C98
.definelabel m2_psiwindow ,0x80C1FBC
.definelabel m2_drawwindow ,0x80C87D0
.definelabel m2_print_window ,0x80C8BE4
@ -2399,9 +2409,6 @@ disclaimer_map:
.definelabel m2_scrolltext ,0x80CA4BC
.definelabel m2_formatnumber ,0x80CA65C
.definelabel m2_clearwindowtiles ,0x80CA834
.definelabel m2_menuwindow ,0x80C1C98
.definelabel m2_setupwindow ,0x80BE188
.definelabel m2_resetwindow ,0x80BE490
.definelabel m2_sub_d3c50 ,0x80D3C50
.definelabel m2_hpwindow_up ,0x80D3F0C
.definelabel m2_curhpwindow_down ,0x80D41D8
@ -2412,6 +2419,7 @@ disclaimer_map:
.definelabel m2_set_target_name ,0x80DAE00
.definelabel m2_setupbattlename ,0x80DCD00
.definelabel m2_stat_symb_checker ,0x8B0EDA4
.definelabel reg_ram_reset ,0x80F47CC
.definelabel vblank ,0x80F47E4
.definelabel m2_div ,0x80F49D8
.definelabel m2_remainder ,0x80F4A70

View File

@ -2297,21 +2297,21 @@ pop {r4,pc}
//==============================================================================
//It sets things up to make it so the target window is only printed once
e0854_psi_inner_window_battle:
push {lr}
ldrb r1,[r0,#3]
push {r4,lr}
mov r4,r0
ldrb r1,[r4,#3]
push {r1}
ldrh r1,[r0,#0x36] //Stores the cursor's Y of the window
ldrh r1,[r4,#0x36] //Stores the cursor's Y of the window
push {r1}
ldrh r1,[r0,#0x34] //Stores the cursor's X of the window
ldrh r1,[r4,#0x34] //Stores the cursor's X of the window
push {r1}
bl PSITargetWindowInput //Input management, target printing and header printing function. Now the function takes the cursor's Y and X as arguments too in the stack
pop {r2}
ldr r3,[r4,0x24] //Target window
ldrh r1,[r3,#0x34] //Stores the cursor's X of the window
ldrh r1,[r4,#0x34] //Stores the cursor's X of the window
cmp r1,r2
bne @@store_buffer_first
pop {r2}
ldrh r1,[r3,#0x36] //Stores the cursor's Y of the window
ldrh r1,[r4,#0x36] //Stores the cursor's Y of the window
cmp r1,r2
bne @@store_buffer_second
pop {r2}
@ -2334,11 +2334,34 @@ bl store_pixels_overworld_psi_window
cmp r0,#0
beq @@ending
mov r2,#0 //Sets vwf_skip to false since the window is change
ldr r1,[r5,0x24] //Target window
strb r2,[r1,#3]
mov r2,#0 //Sets vwf_skip to false since the window is changed
strb r2,[r4,#3]
@@ending:
pop {r4,pc}
.pool
//==============================================================================
//Reverses the order in which the target window and the psi window are printed
//when the "Not enough PP!" message goes away in battle in order to make it so
//the graphics are properly stored.
e0b34_psi_not_enough_pp_reverse_windows:
push {lr}
ldr r0,[r4,#0x24] //Initializes the target window
mov r1,#0
mov r2,#0
bl initWindow_buffer
ldr r0,[r4,#0x1C] //Target window printing
bl 0x80C438C
ldr r0,[r4,#0x20] //PSI window printing, grab the type from the types menu
ldrh r0,[r0,#0x36]
add r0,#1
lsl r0,r0,#0x10
asr r0,r0,#0x10
bl 0x80BAE98 //Do the printing
pop {pc}
.pool

View File

@ -628,7 +628,7 @@
"OffsetLocation": 11632708,
"OldPointer": 11631182,
"Old": "だれに?[00 FF]",
"New": "Who?[00 FF]"
"New": "Whom?[00 FF]"
},
{
"Index": 88,