diff --git a/src/c/locs.c b/src/c/locs.c index 146d60c..3663e62 100644 --- a/src/c/locs.c +++ b/src/c/locs.c @@ -1,6 +1,7 @@ #include "locs.h" int *fileselect_pixels_location = (int*) 0x2015000; +byte *cursorValues = (byte*) 0x3000A00; int *window_flags = (int*) 0x300130C; byte *character_general_data = (byte*) 0x3001D40; PC (*pc_stats)[4] = (PC(*)[4]) 0x3001D54; diff --git a/src/c/locs.h b/src/c/locs.h index e3d7783..4f5d9d3 100644 --- a/src/c/locs.h +++ b/src/c/locs.h @@ -7,6 +7,8 @@ #include "window.h" #include "psi.h" +extern int *fileselect_pixels_location; +extern byte *cursorValues; extern int *window_flags; extern PC (*pc_stats)[4]; extern int *cash_on_hand; @@ -23,7 +25,6 @@ extern unsigned short *palette_mask; extern WINDOW **window_pointers; extern short *active_window_party_member; extern unsigned short **tilemap_pointer; -extern int *fileselect_pixels_location; extern int *vram; extern int *m2_misc_offsets; extern byte *m2_misc_strings; diff --git a/src/c/psi.c b/src/c/psi.c index 77536bf..447fd4b 100644 --- a/src/c/psi.c +++ b/src/c/psi.c @@ -5,141 +5,507 @@ void psiWindow_buffer(CHARACTER psiCharacter, PSIWindow typeOfWindow, PSIClasses printableClasses) { - PC *char_data = &(m2_ness_data[psiCharacter]); - PSIPrintInfo *printInfo; - int level = 0; - int thing2 = 0; - byte *str = 0; - byte *boolCmpWindowType = (byte*)(&(typeOfWindow)); - byte *boolCmpPrintableClasses = (byte*)(&(printableClasses)); - byte *address = (byte*)0x3000A00; - WINDOW *window = getWindow(7); - SpecialPSIFlag *SpecialPSIFlags = (SpecialPSIFlag*)(character_general_data + 0x22A); - bool print[0x11]; - for(int i = 0; i < 0x11; i ++) - print[i] = true; + PC *char_data = &(m2_ness_data[psiCharacter]); + PSIPrintInfo *printInfo; + int level = 0; + int thing2 = 0; + byte *str = 0; + byte *boolCmpWindowType = (byte*)(&(typeOfWindow)); + byte *boolCmpPrintableClasses = (byte*)(&(printableClasses)); + byte (*possibleTargets)[3][4] = (byte(*)[3][4])cursorValues; + WINDOW *window = getWindow(7); + SpecialPSIFlag *SpecialPSIFlags = (SpecialPSIFlag*)(character_general_data + 0x22A); + bool print[0x11]; + for(int i = 0; i < 0x11; i ++) + print[i] = true; - for(int i = 0; i < 4; i++) - { - (*(address + i)) = 0; - (*(address + i + 4)) = 0; - (*(address + i + 8)) = 0; - } - - if(psiCharacter == POO && typeOfWindow.Classes_Window && printableClasses.Offense) - { - if(SpecialPSIFlags->Poo_Starstorm_Alpha) - { - printInfo = &(psi_print_info[20]); - psiPrint_buffer(20 + 1, window, print[6 - 1], printInfo); - print[6 - 1] = false; - } - if(SpecialPSIFlags->Poo_Starstorm_Omega) - { - printInfo = &(psi_print_info[21]); - psiPrint_buffer(21 + 1, window, print[6 - 1], printInfo); - print[6 - 1] = false; - } - } - - - printInfo = &(psi_print_info[0]); - for(int i = 0; printInfo->PSIID != 0; i++) - { - if(psiCharacter != JEFF) - { - int val = psiCharacter == POO ? 2 : psiCharacter; - level = printInfo->levelLearnt[val]; - } - - if(level != 0) - { - byte *boolCmpWindowTypePrintInfo = (byte*)(&(printInfo->windowType)); - if((*boolCmpWindowType) & (*boolCmpWindowTypePrintInfo)) - { - if(char_data->level >= level) - { - byte *boolCmpPrintableClassesPrintInfo = (byte*)(&(printInfo->possibleClasses)); - if((*boolCmpPrintableClasses) & (*boolCmpPrintableClassesPrintInfo)) - { - psiPrint_buffer(i + 1, window, print[printInfo->PSIID - 1], printInfo); - print[printInfo->PSIID - 1] = false; - } - } - } - } - printInfo = &(psi_print_info[i + 1]); - } - - if(psiCharacter == NESS && typeOfWindow.Character_Window && printableClasses.Other) - { - if(SpecialPSIFlags->Ness_Teleport_Alpha) - { - printInfo = &(psi_print_info[0x32]); - psiPrint_buffer(0x32 + 1, window, print[0x11 - 1], printInfo); - print[0x11 - 1] = false; - } - if(SpecialPSIFlags->Ness_Teleport_Beta) - { - printInfo = &(psi_print_info[0x33]); - psiPrint_buffer(0x33 + 1, window, print[0x11 - 1], printInfo); - print[0x11 - 1] = false; - } - } + for(int i = 0; i < 4; i++) + { + (*possibleTargets)[0][i] = 0; + (*possibleTargets)[1][i] = 0; + (*possibleTargets)[2][i] = 0; + } + + if(psiCharacter == POO && typeOfWindow.Classes_Window && printableClasses.Offense) + { + if(SpecialPSIFlags->Poo_Starstorm_Alpha) + { + printInfo = &(psi_print_info[20]); + psiPrint_buffer(20 + 1, window, print[6 - 1], printInfo); + print[6 - 1] = false; + } + if(SpecialPSIFlags->Poo_Starstorm_Omega) + { + printInfo = &(psi_print_info[21]); + psiPrint_buffer(21 + 1, window, print[6 - 1], printInfo); + print[6 - 1] = false; + } + } + + + printInfo = &(psi_print_info[0]); + for(int i = 0; printInfo->PSIID != 0; i++) + { + if(psiCharacter != JEFF) + { + int val = psiCharacter == POO ? 2 : psiCharacter; + level = printInfo->levelLearnt[val]; + } + + if(level != 0) + { + byte *boolCmpWindowTypePrintInfo = (byte*)(&(printInfo->windowType)); + if((*boolCmpWindowType) & (*boolCmpWindowTypePrintInfo)) + { + if(char_data->level >= level) + { + byte *boolCmpPrintableClassesPrintInfo = (byte*)(&(printInfo->possibleClasses)); + if((*boolCmpPrintableClasses) & (*boolCmpPrintableClassesPrintInfo)) + { + psiPrint_buffer(i + 1, window, print[printInfo->PSIID - 1], printInfo); + print[printInfo->PSIID - 1] = false; + } + } + } + } + printInfo = &(psi_print_info[i + 1]); + } + + if(psiCharacter == NESS && typeOfWindow.Character_Window && printableClasses.Other) + { + if(SpecialPSIFlags->Ness_Teleport_Alpha) + { + printInfo = &(psi_print_info[0x32]); + psiPrint_buffer(0x32 + 1, window, print[0x11 - 1], printInfo); + print[0x11 - 1] = false; + } + if(SpecialPSIFlags->Ness_Teleport_Beta) + { + printInfo = &(psi_print_info[0x33]); + psiPrint_buffer(0x33 + 1, window, print[0x11 - 1], printInfo); + print[0x11 - 1] = false; + } + } } void psiTargetWindow_buffer(byte target) { - WINDOW *window = getWindow(0x9); //Target Window - PSIPrintInfo *printInfo = &(psi_print_info[target - 1]); - byte *string_group1 = (byte*)(0x8B204E4); - byte extract = (printInfo->PSIID); - byte value = 0; - byte value2 = 0; - byte *str = 0; - if(extract != 4) - { - value = (*(string_group1 + (printInfo->PSIPrintInfoID * 12))); - value = (value * 0x64); - value2 = (*(string_group1 + (printInfo->PSIPrintInfoID * 12) + 1)); - value2 = (value2 * 0x14); - str = (byte*)(0x8B74390 + value + value2); //It doesn't use the pointer to the description the struct has but it obtains it like this... - } - else - str = (byte*)(0x8B74390); - printstr_hlight_buffer(window, str, 0, 0, 0); - - str = m2_strlookup((int*)0x8B17EE4, (byte*)0x8B17424, 0x1B); - printstr_buffer(window, str, 0, 1, 0); + WINDOW *window = getWindow(0x9); //Target Window + PSIPrintInfo *printInfo = &(psi_print_info[target - 1]); + byte *string_group1 = (byte*)(0x8B204E4); + byte extract = (printInfo->PSIID); + byte value = 0; + byte value2 = 0; + byte *str = 0; + if(extract != 4) + { + value = (*(string_group1 + (printInfo->PSIPrintInfoID * 12))); + value = (value * 0x64); + value2 = (*(string_group1 + (printInfo->PSIPrintInfoID * 12) + 1)); + value2 = (value2 * 0x14); + str = (byte*)(0x8B74390 + value + value2); //It doesn't use the pointer to the description the struct has but it obtains it like this... + } + else + str = (byte*)(0x8B74390); + printstr_hlight_buffer(window, str, 0, 0, 0); + + str = m2_strlookup((int*)0x8B17EE4, (byte*)0x8B17424, 0x1B); + printstr_buffer(window, str, 0, 1, 0); - value = (*(string_group1 + (printInfo->PSIPrintInfoID * 12) + 3)); - str = (window->number_text_area + 0x12); - m2_formatnumber(value, str, 2); - (*(window->number_text_area + 0x14)) = 0; - (*(window->number_text_area + 0x15)) = 0xFF; - printstr_buffer(window, str, 7, 1, 0); + value = (*(string_group1 + (printInfo->PSIPrintInfoID * 12) + 3)); + str = (window->number_text_area + 0x12); + m2_formatnumber(value, str, 2); + (*(window->number_text_area + 0x14)) = 0; + (*(window->number_text_area + 0x15)) = 0xFF; + printstr_buffer(window, str, 7, 1, 0); } void psiPrint_buffer(byte value, WINDOW* window, bool printPSILine, PSIPrintInfo *printInfo) { - byte *str = 0; - byte *address = (byte*)0x3000A00; + byte *str = 0; + byte (*possibleTargets)[3][4] = (byte(*)[3][4])cursorValues; - if(printPSILine) - { - byte PSIID = printInfo->PSIID; - str = (byte*)(0x8B74228 + (PSIID * 0x14)); - printstr_hlight_buffer(window, str, 0, printInfo->YPrinting << 1, 0); - if(PSIID == 1) - { - str = (byte*)(m2_ness_name + (7 * 4) + (8 * 2)); //Go to Rockin's name - print_string_in_buffer(str, 0x71, ((printInfo->YPrinting << 1) + window->window_y) << 3, (int*)(0x2014000 - 0x2000)); - } - } - - byte symbol = printInfo->symbol; - str = (byte*)(0x8B1B904 + (symbol * 3)); - printstr_hlight_buffer(window, str, printInfo->XSymbol + 1, printInfo->YPrinting << 1, 0); - int val = ((((printInfo->XSymbol - 9) >> 0x1F) + printInfo->XSymbol - 9) >> 1) + (printInfo->YPrinting << 2); - (*(address + val)) = value; -} \ No newline at end of file + if(printPSILine) + { + byte PSIID = printInfo->PSIID; + str = (byte*)(0x8B74228 + (PSIID * 0x14)); + printstr_hlight_buffer(window, str, 0, printInfo->YPrinting << 1, 0); + if(PSIID == 1) + { + str = (byte*)(m2_ness_name + (7 * 4) + (8 * 2)); //Go to Rockin's name + print_string_in_buffer(str, 0x71, ((printInfo->YPrinting << 1) + window->window_y) << 3, (int*)(OVERWORLD_BUFFER - 0x2000)); + } + } + + byte symbol = printInfo->symbol; + str = (byte*)(0x8B1B904 + (symbol * 3)); + printstr_hlight_buffer(window, str, printInfo->XSymbol + 1, printInfo->YPrinting << 1, 0); + int targetX = (((printInfo->XSymbol - 9) >> 0x1F) + printInfo->XSymbol - 9) >> 1; + (*possibleTargets)[printInfo->YPrinting][targetX] = value; +} + +int PSITargetWindowInput(WINDOW* window) +{ + + if (!(window->flags_unknown3a & 0x10)) + { + window->flags_unknown3a |= 0x10; + + // Draw window header + map_tile(0xB3, window->window_x, window->window_y - 1); + clear_name_header(window); + copy_name_header(window, *active_window_party_member); + } + + return PSITargetInput(window); +} + +int PSITargetInput(WINDOW* window) +{ + short topX = window->cursor_x; + short topY = window->cursor_y; + short beforeX = topX; + short beforeY = topY; + short currentX = beforeX; + short currentY = beforeY; + byte (*possibleTargets)[3][4] = (byte(*)[3][4])cursorValues; + byte target = (*possibleTargets)[currentY][currentX]; + + if(target == 0) + { + currentX = 0; + for(currentY = 0; currentY < 3 && (*possibleTargets)[currentY][currentX] == 0; currentY++) + { + for(currentX = 0; currentX < 4 && (*possibleTargets)[currentY][currentX] == 0; currentX++); + if(currentX == 4) + currentX = 0; + } + if(currentY < 3) + { + topX = currentX; + topY = currentY; + beforeX = currentX; + beforeY = currentY; + } + else + return ACTION_ERROR; + } + + map_tile(0x1FF, window->window_x + (currentX * 2) + 9, window->window_y + currentY * 2); + map_tile(0x1FF, window->window_x + (currentX * 2) + 9, window->window_y + currentY * 2 + 1); + + PAD_STATE state = *pad_state; + PAD_STATE state_shadow = *pad_state_shadow; + + if(state.up) + { + currentY--; + if(currentY < 0 && window->hold) + currentY = 0; + else if(currentY < 0) + { + currentY = 2; + while((*possibleTargets)[currentY][currentX] == 0) + currentY--; + } + else + { + for(int i = 0; (*possibleTargets)[currentY][currentX] == 0 && i <= 2;) + { + if((*possibleTargets)[currentY][currentX] != 0) + break; + currentX--; + if(currentX < 0) + { + i++; + currentY--; + currentX = beforeX; + } + if(currentY < 0) + currentY = 2; + } + } + } + + beforeX = currentX; + beforeY = currentY; + + if(state.down) + { + currentY++; + if(currentY > 2 && window->hold) + currentY = 2; + else if(currentY > 2) + { + currentY = 0; + while((*possibleTargets)[currentY][currentX] == 0) + currentY++; + } + else + { + for(int i = 0; (*possibleTargets)[currentY][currentX] == 0 && i <= 2;) + { + if((*possibleTargets)[currentY][currentX] != 0) + break; + currentX--; + if(currentX < 0) + { + i++; + currentY++; + currentX = beforeX; + } + if(currentY > 2) + { + if(window->hold) + { + currentY = beforeY; + currentX = beforeX; + break; + } + currentY = 0; + } + } + } + } + + beforeX = currentX; + beforeY = currentY; + + if(state.right) + { + currentX++; + if(state_shadow.up && window->hold) + currentX--; + else if(currentX > 3) + { + if(window->hold) + currentX = 3; + else + { + currentX = 0; + while((*possibleTargets)[currentY][currentX] == 0) + currentX++; + } + } + else + { + if((*possibleTargets)[currentY][currentX] != 0); + else + { + if(state_shadow.down || state_shadow.up) + currentX = beforeX; + else if(currentY == 0) + { + short tmpX = currentX; + while(currentY <= 1) + { + currentX = tmpX; + while(currentX < 3) + { + if((*possibleTargets)[currentY][currentX] != 0) + break; + currentX++; + } + if((*possibleTargets)[currentY][currentX] != 0) + break; + currentY++; + } + if(currentY == 2) + { + currentY = beforeY; + if(window->hold) + currentX = beforeX; + else + { + currentX = 0; + while((*possibleTargets)[currentY][currentX] == 0) + currentX++; + } + } + } + else + { + short tmpX = currentX; + for(currentY = 2; currentY >= 0; currentY--) + { + currentX = tmpX; + while(currentX < 3) + { + if((*possibleTargets)[currentY][currentX] != 0) + break; + currentX++; + } + if((*possibleTargets)[currentY][currentX] != 0) + break; + } + if(currentY < 0) + { + currentY = beforeY; + if(window->hold) + currentX = beforeX; + else + { + currentX = 0; + while((*possibleTargets)[currentY][currentX] == 0) + currentX++; + } + } + } + } + } + } + + beforeX = currentX; + beforeY = currentY; + + if(state.left) + { + currentX--; + if(state_shadow.up && window->hold) + currentX++; + else if(currentX < 0) + { + if(window->hold) + currentX = 0; + else + { + currentX = 3; + while((*possibleTargets)[currentY][currentX] == 0) + currentX--; + } + } + else + { + if((*possibleTargets)[currentY][currentX] != 0); + else + { + if(state_shadow.down || state_shadow.up) + currentX = beforeX; + else if(currentY == 0) + { + short tmpX = currentX; + while(currentY <= 1) + { + currentX = tmpX; + while(currentX > 0) + { + if((*possibleTargets)[currentY][currentX] != 0) + break; + currentX--; + } + if((*possibleTargets)[currentY][currentX] != 0) + break; + currentY++; + } + if(currentY == 2) + { + currentY = beforeY; + if(window->hold) + currentX = beforeX; + else + { + currentX = 3; + while((*possibleTargets)[currentY][currentX] == 0) + currentX--; + } + } + } + else + { + short tmpX = currentX; + for(currentY = 2; currentY >= 0; currentY--) + { + currentX = tmpX; + while(currentX > 0) + { + if((*possibleTargets)[currentY][currentX] != 0) + break; + currentX--; + } + if((*possibleTargets)[currentY][currentX] != 0) + break; + } + if(currentY < 0) + { + currentY = beforeY; + if(window->hold) + currentX = beforeX; + else + { + currentX = 3; + while((*possibleTargets)[currentY][currentX] == 0) + currentX--; + } + } + } + } + } + } + + window->cursor_x = currentX; + window->cursor_y = currentY; + + target = (*possibleTargets)[currentY][currentX]; + if(currentX != topX || currentY != topY) + window->vwf_skip = false; + + bool beforeVWF = window->vwf_skip; + + if(!window->vwf_skip) + { + clear_window_buffer(getWindow(9), (int*)(OVERWORLD_BUFFER - 0x2000)); + psiTargetWindow_buffer(target); + window->vwf_skip = true; + } + + if(state_shadow.right || state_shadow.left || state_shadow.up || state_shadow.down) + { + window->counter = 0; + int flag = *window_flags; + if(state.up || state.down) + { + if(currentY != topY) + m2_soundeffect(0x12F); + } + if(state.left || state.right) + { + if(currentX != topX) + m2_soundeffect(0x12E); + } + window->hold = true; + } + else + window->hold = false; + + if(state.b || state.select) + { + m2_soundeffect(0x12E); + window->counter = 0; + return ACTION_STEPOUT; + } + + window->cursor_x_delta = target; + + if(state.a || state.l) + { + if(beforeVWF) + m2_soundeffect(0x12D); + window->counter = 0xFFFF; + return target; + } + + if (window->counter != 0xFFFF) + { + window->counter++; + + // Draw cursor for current item + map_special_character((window->counter <= 7) ? 0x99 : 0x9A, + window->window_x + (window->cursor_x * 2) + 9, + window->window_y + window->cursor_y * 2); + + if (window->counter > 0x10) + window->counter = 0; + } + + return ACTION_NONE; +} diff --git a/src/c/psi.h b/src/c/psi.h index 577d7dc..f223bfb 100644 --- a/src/c/psi.h +++ b/src/c/psi.h @@ -39,6 +39,8 @@ typedef struct SpecialPSIFlag { void psiWindow_buffer(CHARACTER psiCharacter, PSIWindow typeOfWindow, PSIClasses printableClasses); void psiTargetWindow_buffer(byte target); void psiPrint_buffer(byte value, WINDOW* window, bool printPSILine, PSIPrintInfo *printInfo); +int PSITargetWindowInput(WINDOW* window); +int PSITargetInput(WINDOW* window); extern PSIPrintInfo m2_psi_print_table[]; diff --git a/src/c/status.c b/src/c/status.c index 575ca1c..99d6a53 100644 --- a/src/c/status.c +++ b/src/c/status.c @@ -9,9 +9,9 @@ void printNumberOfStatus(int maxLength, int value, int blankX, int y, int strX, int end = setNumber_getLength(value, str, maxLength); str[end] = 0; str[end + 1] = 0xFF; - print_blankstr_buffer(blankX, y, width, (int*)(0x2014000 - 0x2000)); + print_blankstr_buffer(blankX, y, width, (int*)(OVERWORLD_BUFFER - 0x2000)); int x = (strX - (end * 6)); - print_string_in_buffer(str, x, y << 3, (int*)(0x2014000 - 0x2000)); + print_string_in_buffer(str, x, y << 3, (int*)(OVERWORLD_BUFFER - 0x2000)); } void printStatusSymbolArrangement(unsigned short symbolTile, WINDOW* window) @@ -59,7 +59,7 @@ int statusNumbersPrint(WINDOW* window, bool doNotPrint) printNumberOfStatus(7, experienceLevelUp - character_data->experience, 2, 0xD, 0x3D, 6); } else - print_blankstr_buffer(2, 0xD, 6, (int*)(0x2014000 - 0x2000)); + print_blankstr_buffer(2, 0xD, 6, (int*)(OVERWORLD_BUFFER - 0x2000)); printNumberOfStatus(3, character_data->offense_effective, 0x19, 0x1, 0xE1, 4); printNumberOfStatus(3, character_data->defense_effective, 0x19, 0x3, 0xE1, 4); printNumberOfStatus(3, character_data->speed_effective, 0x19, 0x5, 0xE1, 4); @@ -67,13 +67,13 @@ int statusNumbersPrint(WINDOW* window, bool doNotPrint) printNumberOfStatus(3, character_data->vitality_effective, 0x19, 0x9, 0xE1, 4); printNumberOfStatus(3, character_data->iq_effective, 0x19, 0xB, 0xE1, 4); printNumberOfStatus(3, character_data->luck_effective, 0x19, 0xD, 0xE1, 4); - print_blankstr_buffer(5, 0xF, 0x14, (int*)(0x2014000 - 0x2000)); + print_blankstr_buffer(5, 0xF, 0x14, (int*)(OVERWORLD_BUFFER - 0x2000)); if((*active_window_party_member) != JEFF) { byte *str = m2_strlookup((int*)0x8B17EE4, (byte*)0x8B17424, 0x13); - print_string_in_buffer(str, 0x2C, (0xF) << 3, (int*)(0x2014000 - 0x2000)); + print_string_in_buffer(str, 0x2C, (0xF) << 3, (int*)(OVERWORLD_BUFFER - 0x2000)); } - print_blankstr_buffer(1, 0x3, 0xA, (int*)(0x2014000 - 0x2000)); + print_blankstr_buffer(1, 0x3, 0xA, (int*)(OVERWORLD_BUFFER - 0x2000)); unsigned short symbolTile = ailmentTileSetup(character_data, 0); if(symbolTile == 0) { @@ -225,18 +225,18 @@ int statusWindowNumbers(WINDOW* window, bool doNotPrint) int statusWindowText(WINDOW* window) { if(window->redraw) - buffer_drawwindow(window, (int*)(0x2014000 - 0x2000)); + buffer_drawwindow(window, (int*)(OVERWORLD_BUFFER - 0x2000)); if(window->loaded_code != 0 && ((*script_readability) == 0)) { window->delay = 0; while(true) { while(window->text_y >= window->window_height || window->window_y + window->text_y > 0x1F) - properScroll(window, (int*)(0x2014000 - 0x2000)); + properScroll(window, (int*)(OVERWORLD_BUFFER - 0x2000)); byte *str = window->text_start + window->text_offset; if((*(str + 1)) == 0xFF) { - int returnedLength = customcodes_parse_generic(*str, str, window, (int*)(0x2014000 - 0x2000)); + int returnedLength = customcodes_parse_generic(*str, str, window, (int*)(OVERWORLD_BUFFER - 0x2000)); if(returnedLength != 0) { if(returnedLength < 0) @@ -267,7 +267,7 @@ int statusWindowText(WINDOW* window) window->text_y += 2; window->text_x = 0; } - weld_entry_custom_buffer(window, str, 0, 0xF, (int*)(0x2014000 - 0x2000)); + weld_entry_custom_buffer(window, str, 0, 0xF, (int*)(OVERWORLD_BUFFER - 0x2000)); window->text_offset++; } } diff --git a/src/c/vwf.c b/src/c/vwf.c index 280165d..82391f3 100644 --- a/src/c/vwf.c +++ b/src/c/vwf.c @@ -901,7 +901,7 @@ int print_window_with_buffer(WINDOW* window) while(window->loaded_code !=0) { window->delay = delay; - print_character_with_codes(window, (int*)(0x2014000 - ((*tile_offset) * 32))); + print_character_with_codes(window, (int*)(OVERWORLD_BUFFER - ((*tile_offset) * 32))); } } return 0; @@ -1138,7 +1138,7 @@ byte print_character_with_codes(WINDOW* window, int* dest) } else { - handle_first_window_buffer(window, (int*)(0x2014000 - ((*tile_offset) * 32))); + handle_first_window_buffer(window, (int*)(OVERWORLD_BUFFER - ((*tile_offset) * 32))); window->delay = window->delay_between_prints; if(x > 0x1F) { @@ -1264,7 +1264,7 @@ void printstr_buffer(WINDOW* window, byte* str, unsigned short x, unsigned short while(output != 1) { window->delay = 0; - output = print_character_with_codes(window, (int*)(0x2014000 - ((*tile_offset) * 32))); + output = print_character_with_codes(window, (int*)(OVERWORLD_BUFFER - ((*tile_offset) * 32))); } window->text_start = tmpTextStart; @@ -1286,7 +1286,7 @@ unsigned short printstr_hlight_buffer(WINDOW* window, byte* str, unsigned short palette_mask_highlight += 0x1000; (*palette_mask) = palette_mask_highlight; - unsigned short printed_Characters = print_string_in_buffer(str, printX, printY, (int*)(0x2014000 - ((*tile_offset) * 32))); + unsigned short printed_Characters = print_string_in_buffer(str, printX, printY, (int*)(OVERWORLD_BUFFER - ((*tile_offset) * 32))); (*palette_mask) = tmpPaletteMsk; @@ -1314,13 +1314,13 @@ int initWindow_buffer(WINDOW* window, byte* text_start, unsigned short delay_bet window->flags_unknown1 |= 1; window->redraw = true; if(text_start == NULL) - buffer_drawwindow(window, (int*)(0x2014000 - 0x2000)); + buffer_drawwindow(window, (int*)(OVERWORLD_BUFFER - 0x2000)); return 0; } void clearWindowTiles_buffer(WINDOW* window) { - clear_window_buffer(window, (int*)(0x2014000 - 0x2000)); + clear_window_buffer(window, (int*)(OVERWORLD_BUFFER - 0x2000)); window->text_x = 0; window->text_y = 0; } diff --git a/src/c/vwf.h b/src/c/vwf.h index 609d24d..2fbfcbb 100644 --- a/src/c/vwf.h +++ b/src/c/vwf.h @@ -21,6 +21,8 @@ #define WINDOW_HEADER_Y 0x11 #define WINDOW_HEADER_TILE (WINDOW_HEADER_X + (WINDOW_HEADER_Y * 32)) +#define OVERWORLD_BUFFER 0x203C000 + #define CUSTOMCC_SET_X 0x5F #define CUSTOMCC_ADD_X 0x60 @@ -117,6 +119,7 @@ extern byte m12_other_str7[]; extern byte m12_other_str8[]; extern byte m2_cstm_last_printed[]; extern byte *m2_script_readability; +extern int overworld_buffer; extern PC m2_ness_data[]; extern void cpufastset(void *source, void *dest, int mode); diff --git a/src/c/window.h b/src/c/window.h index 1451525..df9a246 100644 --- a/src/c/window.h +++ b/src/c/window.h @@ -7,7 +7,8 @@ typedef enum WINDOW_ACTION { ACTION_NONE = 0, ACTION_STEPIN = 1, - ACTION_STEPOUT = -1 + ACTION_STEPOUT = -1, + ACTION_ERROR = -2 } WINDOW_ACTION; typedef struct WINDOW { diff --git a/src/data/m2-functions-table.bin b/src/data/m2-functions-table.bin new file mode 100644 index 0000000..4a3210e --- /dev/null +++ b/src/data/m2-functions-table.bin @@ -0,0 +1 @@ +*A+a+}++****++++%,9,M,a,E2u,Y2,**,***,*17i/;m<** \ No newline at end of file diff --git a/src/m2-hack.asm b/src/m2-hack.asm index d322136..fcd5946 100644 --- a/src/m2-hack.asm +++ b/src/m2-hack.asm @@ -60,6 +60,7 @@ mov r3,6 .org 0x80B8890 :: bl print_window_with_buffer :: bl b8894_printCashWindowAndStore //Main window + Cash Window out of Status menu .org 0x80B831A :: bl initWindow_buffer .org 0x80B8320 :: bl b8320_statusWindowTextStore +.org 0x80BEAA6 :: bl beaa6_fix_sounds //--------------------------------------------------------- // BAC18 hacks (status window) @@ -229,6 +230,9 @@ mov r0,0x50 //Do not redraw unless it is needed .org 0x80B8CD2 :: bl b8cd2_psi_window +//Fix multiple sounds issue when going inside the psi window +.org 0x80B8D40 :: bl b8d40_psi_going_inner_window + //Sets up for the target window .org 0x80B8DB4 :: bl b8db4_psi_inner_window @@ -1233,6 +1237,11 @@ nop //.org 0x80BD9F6 :: mov r2,#0x16 //Jeff //.org 0x80BDA02 :: mov r2,#0x1B //Poo +//============================================================================== +// Fix functions table +//============================================================================== + +.org 0x80F2B30 :: dw m2_functions_table //============================================================================== // File select hacks @@ -1486,11 +1495,15 @@ flyovertextLater: m2_coord_table_file: .incbin "data/m2-coord-table-file-select.bin" +m2_functions_table: +.incbin "data/m2-functions-table.bin" + //============================================================================== // Existing subroutines/data //============================================================================== +.definelabel overworld_buffer ,0x203C000 .definelabel m2_ness_data ,0x3001D54 .definelabel m2_ness_name ,0x3001F10 .definelabel m2_old_paula_name ,0x3001F16 diff --git a/src/m2-vwf-entries.asm b/src/m2-vwf-entries.asm index eb7f6ae..32ffc68 100644 --- a/src/m2-vwf-entries.asm +++ b/src/m2-vwf-entries.asm @@ -357,6 +357,21 @@ bl store_pixels_overworld pop {pc} .pool +//============================================================================== +// Calls m2_soundeffect only if we're going in either talk or check +beaa6_fix_sounds: +push {lr} +mov r1,r10 +add r1,r1,r4 +cmp r1,#0 +beq @@sound +cmp r1,#4 +bne @@end +@@sound: +bl m2_soundeffect +@@end: +pop {pc} + //============================================================================== // Only if the character changed store the buffer - called when reading inputs bac6e_statusWindowNumbersInputManagement: @@ -1877,7 +1892,7 @@ ldrh r1,[r0,#0x36] //Stores the cursor's Y of the window push {r1} ldrh r1,[r0,#0x34] //Stores the cursor's X of the window push {r1} -bl 0x80C438C //Input management, target printing and header printing function. Now the function takes the cursor's Y and X as arguments too in the stack +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 lsl r0,r0,#0x10 lsr r4,r0,#0x10 //Properly stores the output into r4 @@ -1945,6 +1960,14 @@ bx r0 //Jump to the next useful piece of code .pool +//============================================================================== +//Fixes issue with sounds when going from the PSI window to the inner PSI window +b8d40_psi_going_inner_window: +push {lr} +bl PSITargetWindowInput +bl store_pixels_overworld_psi_window +pop {pc} + //============================================================================== //It sets things up to make it so the target window is only printed once b8db4_psi_inner_window: @@ -1955,7 +1978,7 @@ ldrh r1,[r0,#0x36] //Stores the cursor's Y of the window push {r1} ldrh r1,[r0,#0x34] //Stores the cursor's X of the window push {r1} -bl 0x80C438C //Input management, target printing and header printing function. Now the function takes the cursor's Y and X as arguments too in the stack +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 @@ -2004,7 +2027,7 @@ ldrh r1,[r0,#0x36] //Stores the cursor's Y of the window push {r1} ldrh r1,[r0,#0x34] //Stores the cursor's X of the window push {r1} -bl 0x80C438C //Input management, target printing and header printing function. Now the function takes the cursor's Y and X as arguments too in the stack +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 @@ -2811,7 +2834,7 @@ push {r0-r1,lr} ldr r1,=#0x40000C8 //DMA transfer 2 ldr r0,=#0x6002000 //Source str r0,[r1] -ldr r0,=#0x2014000 //Target +ldr r0,=#overworld_buffer //Target str r0,[r1,#4] ldr r0,=#0xA4001000 //Store 0x4000 bytes - When HBlank and in words of 32 bits str r0,[r1,#8] @@ -2823,7 +2846,7 @@ pop {r0-r1,pc} store_pixels_overworld: push {r0-r1,lr} ldr r1,=#0x40000C8 //DMA transfer 2 -ldr r0,=#0x2014000 //Source +ldr r0,=#overworld_buffer //Source str r0,[r1] ldr r0,=#0x6002000 //Target str r0,[r1,#4] @@ -2839,7 +2862,7 @@ push {r0-r1,lr} ldr r1,=#0x40000C8 //DMA transfer 2 ldr r0,=#0x6002000 //Source str r0,[r1] -ldr r0,=#0x2014000 //Target +ldr r0,=#overworld_buffer //Target str r0,[r1,#4] ldr r0,=#0x94000800 //Store 0x1800 bytes - When VBlank and in words of 32 bits str r0,[r1,#8] @@ -2851,7 +2874,7 @@ pop {r0-r1,pc} store_pixels_overworld_psi_window: push {r0-r1,lr} ldr r1,=#0x40000C8 //DMA transfer 2 -ldr r0,=#0x2014000 //Source +ldr r0,=#overworld_buffer //Source str r0,[r1] ldr r0,=#0x6002000 //Target str r0,[r1,#4]