From e0fbd5daad0646c77d1f587d2763bc707df5d417 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 21 Jan 2018 13:32:11 +0100 Subject: [PATCH] text window cleanup --- data/graphics.s | 2 +- data/text_window.s | 196 --------------------------------------- include/graphics.h | 4 + include/text_window.h | 13 ++- ld_script.txt | 2 +- src/option_menu.c | 13 +-- src/save_failed_screen.c | 3 +- src/text_window.c | 106 +++++++++++++++++---- 8 files changed, 110 insertions(+), 229 deletions(-) delete mode 100644 data/text_window.s diff --git a/data/graphics.s b/data/graphics.s index 11244eb99..8527e570d 100644 --- a/data/graphics.s +++ b/data/graphics.s @@ -5041,7 +5041,7 @@ gUnknown_08DDD704:: @ 8DDD704 .incbin "graphics/unknown/unknown_DDD704.bin" @ textbox tilemap?? .align 2 -gUnknown_08DDD728:: @ 8DDD728 +gMessageBox_Pal:: @ 8DDD728 .incbin "graphics/text_window/message_box.gbapal" .align 2 diff --git a/data/text_window.s b/data/text_window.s deleted file mode 100644 index 8acbe5a25..000000000 --- a/data/text_window.s +++ /dev/null @@ -1,196 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .section .rodata - - .align 2 -gTextWindowFrame1_Gfx:: @ 850E87C - .incbin "graphics/text_window/1.4bpp" - - .align 2 -gTextWindowFrame2_Gfx:: @ 850E99C - .incbin "graphics/text_window/2.4bpp" - - .align 2 -gTextWindowFrame3_Gfx:: @ 850EABC - .incbin "graphics/text_window/3.4bpp" - - .align 2 -gTextWindowFrame4_Gfx:: @ 850EBDC - .incbin "graphics/text_window/4.4bpp" - - .align 2 -gTextWindowFrame5_Gfx:: @ 850ECFC - .incbin "graphics/text_window/5.4bpp" - - .align 2 -gTextWindowFrame6_Gfx:: @ 850EE1C - .incbin "graphics/text_window/6.4bpp" - - .align 2 -gTextWindowFrame7_Gfx:: @ 850EF3C - .incbin "graphics/text_window/7.4bpp" - - .align 2 -gTextWindowFrame8_Gfx:: @ 850F05C - .incbin "graphics/text_window/8.4bpp" - - .align 2 -gTextWindowFrame9_Gfx:: @ 850F17C - .incbin "graphics/text_window/9.4bpp" - - .align 2 -gTextWindowFrame10_Gfx:: @ 850F29C - .incbin "graphics/text_window/10.4bpp" - - .align 2 -gTextWindowFrame11_Gfx:: @ 850F3BC - .incbin "graphics/text_window/11.4bpp" - - .align 2 -gTextWindowFrame12_Gfx:: @ 850F4DC - .incbin "graphics/text_window/12.4bpp" - - .align 2 -gTextWindowFrame13_Gfx:: @ 850F5FC - .incbin "graphics/text_window/13.4bpp" - - .align 2 -gTextWindowFrame14_Gfx:: @ 850F71C - .incbin "graphics/text_window/14.4bpp" - - .align 2 -gTextWindowFrame15_Gfx:: @ 850F83C - .incbin "graphics/text_window/15.4bpp" - - .align 2 -gTextWindowFrame16_Gfx:: @ 850F95C - .incbin "graphics/text_window/16.4bpp" - - .align 2 -gTextWindowFrame17_Gfx:: @ 850FA7C - .incbin "graphics/text_window/17.4bpp" - - .align 2 -gTextWindowFrame18_Gfx:: @ 850FB9C - .incbin "graphics/text_window/18.4bpp" - - .align 2 -gTextWindowFrame19_Gfx:: @ 850FCBC - .incbin "graphics/text_window/19.4bpp" - - .align 2 -gTextWindowFrame20_Gfx:: @ 850FDDC - .incbin "graphics/text_window/20.4bpp" - - .align 2 -gTextWindowFrame1_Pal:: @ 850FEFC - .incbin "graphics/text_window/1.gbapal" - - .align 2 -gTextWindowFrame2_Pal:: @ 850FF1C - .incbin "graphics/text_window/2.gbapal" - - .align 2 -gTextWindowFrame3_Pal:: @ 850FF3C - .incbin "graphics/text_window/3.gbapal" - - .align 2 -gTextWindowFrame4_Pal:: @ 850FF5C - .incbin "graphics/text_window/4.gbapal" - - .align 2 -gTextWindowFrame5_Pal:: @ 850FF7C - .incbin "graphics/text_window/5.gbapal" - - .align 2 -gTextWindowFrame6_Pal:: @ 850FF9C - .incbin "graphics/text_window/6.gbapal" - - .align 2 -gTextWindowFrame7_Pal:: @ 850FFBC - .incbin "graphics/text_window/7.gbapal" - - .align 2 -gTextWindowFrame8_Pal:: @ 850FFDC - .incbin "graphics/text_window/8.gbapal" - - .align 2 -gTextWindowFrame9_Pal:: @ 850FFFC - .incbin "graphics/text_window/9.gbapal" - - .align 2 -gTextWindowFrame10_Pal:: @ 851001C - .incbin "graphics/text_window/10.gbapal" - - .align 2 -gTextWindowFrame11_Pal:: @ 851003C - .incbin "graphics/text_window/11.gbapal" - - .align 2 -gTextWindowFrame12_Pal:: @ 851005C - .incbin "graphics/text_window/12.gbapal" - - .align 2 -gTextWindowFrame13_Pal:: @ 851007C - .incbin "graphics/text_window/13.gbapal" - - .align 2 -gTextWindowFrame14_Pal:: @ 851009C - .incbin "graphics/text_window/14.gbapal" - - .align 2 -gTextWindowFrame15_Pal:: @ 85100BC - .incbin "graphics/text_window/15.gbapal" - - .align 2 -gTextWindowFrame16_Pal:: @ 85100DC - .incbin "graphics/text_window/16.gbapal" - - .align 2 -gTextWindowFrame17_Pal:: @ 85100FC - .incbin "graphics/text_window/17.gbapal" - - .align 2 -gTextWindowFrame18_Pal:: @ 851011C - .incbin "graphics/text_window/18.gbapal" - - .align 2 -gTextWindowFrame19_Pal:: @ 851013C - .incbin "graphics/text_window/19.gbapal" - - .align 2 -gTextWindowFrame20_Pal:: @ 851015C - .incbin "graphics/text_window/20.gbapal" - - .align 2 -gUnknown_0851017C:: @ 851017C - .incbin "graphics/text_window/message_box.gbapal" - - .incbin "graphics/text_window/text_pal1.gbapal" - .incbin "graphics/text_window/text_pal2.gbapal" - .incbin "graphics/text_window/text_pal3.gbapal" - .incbin "graphics/text_window/text_pal4.gbapal" - - .align 2 -gUnknown_0851021C:: @ 851021C - .4byte gTextWindowFrame1_Gfx, gTextWindowFrame1_Pal - .4byte gTextWindowFrame2_Gfx, gTextWindowFrame2_Pal - .4byte gTextWindowFrame3_Gfx, gTextWindowFrame3_Pal - .4byte gTextWindowFrame4_Gfx, gTextWindowFrame4_Pal - .4byte gTextWindowFrame5_Gfx, gTextWindowFrame5_Pal - .4byte gTextWindowFrame6_Gfx, gTextWindowFrame6_Pal - .4byte gTextWindowFrame7_Gfx, gTextWindowFrame7_Pal - .4byte gTextWindowFrame8_Gfx, gTextWindowFrame8_Pal - .4byte gTextWindowFrame9_Gfx, gTextWindowFrame9_Pal - .4byte gTextWindowFrame10_Gfx, gTextWindowFrame10_Pal - .4byte gTextWindowFrame11_Gfx, gTextWindowFrame11_Pal - .4byte gTextWindowFrame12_Gfx, gTextWindowFrame12_Pal - .4byte gTextWindowFrame13_Gfx, gTextWindowFrame13_Pal - .4byte gTextWindowFrame14_Gfx, gTextWindowFrame14_Pal - .4byte gTextWindowFrame15_Gfx, gTextWindowFrame15_Pal - .4byte gTextWindowFrame16_Gfx, gTextWindowFrame16_Pal - .4byte gTextWindowFrame17_Gfx, gTextWindowFrame17_Pal - .4byte gTextWindowFrame18_Gfx, gTextWindowFrame18_Pal - .4byte gTextWindowFrame19_Gfx, gTextWindowFrame19_Pal - .4byte gTextWindowFrame20_Gfx, gTextWindowFrame20_Pal diff --git a/include/graphics.h b/include/graphics.h index 85e31aec9..5917e9d2a 100644 --- a/include/graphics.h +++ b/include/graphics.h @@ -1,6 +1,10 @@ #ifndef GUARD_GRAPHICS_H #define GUARD_GRAPHICS_H +// overworld +extern const u32 gMessageBox_Gfx[]; +extern const u16 gMessageBox_Pal[]; + // interface pokeballs extern const u8 gInterfaceGfx_PokeBall[]; extern const u8 gInterfacePal_PokeBall[]; diff --git a/include/text_window.h b/include/text_window.h index f9a458cc3..e6a753fcb 100644 --- a/include/text_window.h +++ b/include/text_window.h @@ -1,12 +1,17 @@ #ifndef GUARD_TEXT_WINDOW_H #define GUARD_TEXT_WINDOW_H +#define WINDOW_FRAMES_COUNT 20 + struct TilesPal { - u32 *tiles; - u16 *pal; + const u32 *tiles; + const u16 *pal; }; +extern const u32 gTextWindowFrame1_Gfx[]; +extern const u16 gTextWindowFrame1_Pal[]; + const struct TilesPal* GetWindowFrameTilesPal(u8 id); void copy_textbox_border_tile_patterns_to_vram(u8 windowId, u16 destOffset, u8 palOffset); void sub_809882C(u8 windowId, u16 destOffset, u8 palOffset); @@ -15,8 +20,8 @@ void box_border_load_tiles_and_pal(u8 windowId, u16 destOffset, u8 palOffset); void sub_8098858(u8 windowId, u16 tileNum, u8 palNum); void sub_80989E0(u8 windowId, u16 tileNum, u8 palNum); void rbox_fill_rectangle(u8 windowId); -const u16* stdpal_get(u8 id); -const u16* GetOverworldTextboxPalettePtr(void); +const u16 *stdpal_get(u8 id); +const u16 *GetOverworldTextboxPalettePtr(void); void sub_8098C6C(u8 bg, u16 destOffset, u8 palOffset); #endif // GUARD_TEXT_WINDOW_H diff --git a/ld_script.txt b/ld_script.txt index c06eb1408..dc411c8cb 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -405,7 +405,7 @@ SECTIONS { data/field_map_obj.o(.rodata); data/field_ground_effect.o(.rodata); data/map_obj_8097404.o(.rodata); - data/text_window.o(.rodata); + src/text_window.o(.rodata); src/scrcmd.o(.rodata); data/coord_event_weather.o(.rodata); data/field_tasks.o(.rodata); diff --git a/src/option_menu.c b/src/option_menu.c index b76d9e0e6..7f92756ab 100644 --- a/src/option_menu.c +++ b/src/option_menu.c @@ -262,9 +262,7 @@ void CB2_InitOptionMenu(void) static void Task_OptionMenuFadeIn(u8 taskId) { if (!gPaletteFade.active) - { gTasks[taskId].func = Task_OptionMenuProcessInput; - } } static void Task_OptionMenuProcessInput(u8 taskId) @@ -517,12 +515,11 @@ static void Sound_DrawChoices(u8 selection) DrawOptionMenuChoice(gText_SoundStereo, GetStringRightAlignXOffset(1, gText_SoundStereo, 198), 48, styles[1]); } -// TODO: 19 should be defined in text_window.h static u8 FrameType_ProcessInput(u8 selection) { if (gMain.newKeys & DPAD_RIGHT) { - if (selection < 19) + if (selection < WINDOW_FRAMES_COUNT - 1) selection++; else selection = 0; @@ -536,7 +533,7 @@ static u8 FrameType_ProcessInput(u8 selection) if (selection != 0) selection--; else - selection = 19; + selection = WINDOW_FRAMES_COUNT - 1; LoadBgTiles(1, GetWindowFrameTilesPal(selection)->tiles, 0x120, 0x1A2); LoadPalette(GetWindowFrameTilesPal(selection)->pal, 0x70, 0x20); @@ -601,7 +598,7 @@ static u8 ButtonMode_ProcessInput(u8 selection) static void ButtonMode_DrawChoices(u8 selection) { - s32 widthNormal, widthLR, widthLA, yLR; + s32 widthNormal, widthLR, widthLA, xLR; u8 styles[3]; styles[0] = 0; @@ -616,8 +613,8 @@ static void ButtonMode_DrawChoices(u8 selection) widthLA = GetStringWidth(1, gText_ButtonTypeLEqualsA, 0); widthLR -= 94; - yLR = (widthNormal - widthLR - widthLA) / 2 + 104; - DrawOptionMenuChoice(gText_ButtonTypeLR, yLR, 64, styles[1]); + xLR = (widthNormal - widthLR - widthLA) / 2 + 104; + DrawOptionMenuChoice(gText_ButtonTypeLR, xLR, 64, styles[1]); DrawOptionMenuChoice(gText_ButtonTypeLEqualsA, GetStringRightAlignXOffset(1, gText_ButtonTypeLEqualsA, 198), 64, styles[2]); } diff --git a/src/save_failed_screen.c b/src/save_failed_screen.c index efe38fbae..8764daa5f 100755 --- a/src/save_failed_screen.c +++ b/src/save_failed_screen.c @@ -9,6 +9,7 @@ #include "menu.h" #include "save.h" #include "gba/flash_internal.h" +#include "text_window.h" #define MSG_WIN_TOP 12 #define CLOCK_WIN_TOP (MSG_WIN_TOP - 4) @@ -21,9 +22,7 @@ extern const u8 gBirchHelpGfx[]; extern const u8 gBirchBagTilemap[]; extern const u8 gBirchGrassTilemap[]; extern const u16 gBirchBagGrassPal[]; -extern const u16 gTextWindowFrame1_Pal[]; extern const u16 gUnknown_0860F074[]; -extern const u32 gTextWindowFrame1_Gfx[]; extern struct SaveSection gSaveDataBuffer; extern u8 gText_SaveFailedCheckingBackup[]; diff --git a/src/text_window.c b/src/text_window.c index 4c357ec7f..33cd7cffe 100644 --- a/src/text_window.c +++ b/src/text_window.c @@ -3,21 +3,92 @@ #include "text_window.h" #include "window.h" #include "palette.h" +#include "bg.h" +#include "graphics.h" -extern u8 LoadBgTiles(u8 bg, const void *src, u16 size, u16 destOffset); -extern void FillBgTilemapBufferRect(u8 bg, u16 tileNum, u8 x, u8 y, u8 width, u8 height, u8 palette); +// const rom data +const u32 gTextWindowFrame1_Gfx[] = INCBIN_U32("graphics/text_window/1.4bpp"); +static const u32 sTextWindowFrame2_Gfx[] = INCBIN_U32("graphics/text_window/2.4bpp"); +static const u32 sTextWindowFrame3_Gfx[] = INCBIN_U32("graphics/text_window/3.4bpp"); +static const u32 sTextWindowFrame4_Gfx[] = INCBIN_U32("graphics/text_window/4.4bpp"); +static const u32 sTextWindowFrame5_Gfx[] = INCBIN_U32("graphics/text_window/5.4bpp"); +static const u32 sTextWindowFrame6_Gfx[] = INCBIN_U32("graphics/text_window/6.4bpp"); +static const u32 sTextWindowFrame7_Gfx[] = INCBIN_U32("graphics/text_window/7.4bpp"); +static const u32 sTextWindowFrame8_Gfx[] = INCBIN_U32("graphics/text_window/8.4bpp"); +static const u32 sTextWindowFrame9_Gfx[] = INCBIN_U32("graphics/text_window/9.4bpp"); +static const u32 sTextWindowFrame10_Gfx[] = INCBIN_U32("graphics/text_window/10.4bpp"); +static const u32 sTextWindowFrame11_Gfx[] = INCBIN_U32("graphics/text_window/11.4bpp"); +static const u32 sTextWindowFrame12_Gfx[] = INCBIN_U32("graphics/text_window/12.4bpp"); +static const u32 sTextWindowFrame13_Gfx[] = INCBIN_U32("graphics/text_window/13.4bpp"); +static const u32 sTextWindowFrame14_Gfx[] = INCBIN_U32("graphics/text_window/14.4bpp"); +static const u32 sTextWindowFrame15_Gfx[] = INCBIN_U32("graphics/text_window/15.4bpp"); +static const u32 sTextWindowFrame16_Gfx[] = INCBIN_U32("graphics/text_window/16.4bpp"); +static const u32 sTextWindowFrame17_Gfx[] = INCBIN_U32("graphics/text_window/17.4bpp"); +static const u32 sTextWindowFrame18_Gfx[] = INCBIN_U32("graphics/text_window/18.4bpp"); +static const u32 sTextWindowFrame19_Gfx[] = INCBIN_U32("graphics/text_window/19.4bpp"); +static const u32 sTextWindowFrame20_Gfx[] = INCBIN_U32("graphics/text_window/20.4bpp"); -extern const struct TilesPal gUnknown_0851021C[20]; -extern const u32 gMessageBox_Gfx[]; -extern const u16 gUnknown_0851017C[]; -extern const u16 gUnknown_08DDD728[]; +const u16 gTextWindowFrame1_Pal[] = INCBIN_U16("graphics/text_window/1.gbapal"); +static const u16 sTextWindowFrame2_Pal[] = INCBIN_U16("graphics/text_window/2.gbapal"); +static const u16 sTextWindowFrame3_Pal[] = INCBIN_U16("graphics/text_window/3.gbapal"); +static const u16 sTextWindowFrame4_Pal[] = INCBIN_U16("graphics/text_window/4.gbapal"); +static const u16 sTextWindowFrame5_Pal[] = INCBIN_U16("graphics/text_window/5.gbapal"); +static const u16 sTextWindowFrame6_Pal[] = INCBIN_U16("graphics/text_window/6.gbapal"); +static const u16 sTextWindowFrame7_Pal[] = INCBIN_U16("graphics/text_window/7.gbapal"); +static const u16 sTextWindowFrame8_Pal[] = INCBIN_U16("graphics/text_window/8.gbapal"); +static const u16 sTextWindowFrame9_Pal[] = INCBIN_U16("graphics/text_window/9.gbapal"); +static const u16 sTextWindowFrame10_Pal[] = INCBIN_U16("graphics/text_window/10.gbapal"); +static const u16 sTextWindowFrame11_Pal[] = INCBIN_U16("graphics/text_window/11.gbapal"); +static const u16 sTextWindowFrame12_Pal[] = INCBIN_U16("graphics/text_window/12.gbapal"); +static const u16 sTextWindowFrame13_Pal[] = INCBIN_U16("graphics/text_window/13.gbapal"); +static const u16 sTextWindowFrame14_Pal[] = INCBIN_U16("graphics/text_window/14.gbapal"); +static const u16 sTextWindowFrame15_Pal[] = INCBIN_U16("graphics/text_window/15.gbapal"); +static const u16 sTextWindowFrame16_Pal[] = INCBIN_U16("graphics/text_window/16.gbapal"); +static const u16 sTextWindowFrame17_Pal[] = INCBIN_U16("graphics/text_window/17.gbapal"); +static const u16 sTextWindowFrame18_Pal[] = INCBIN_U16("graphics/text_window/18.gbapal"); +static const u16 sTextWindowFrame19_Pal[] = INCBIN_U16("graphics/text_window/19.gbapal"); +static const u16 sTextWindowFrame20_Pal[] = INCBIN_U16("graphics/text_window/20.gbapal"); -const struct TilesPal* GetWindowFrameTilesPal(u8 id) +static const u16 sUnknown_0851017C[][16] = { - if (id >= ARRAY_COUNT(gUnknown_0851021C)) - return &gUnknown_0851021C[0]; + INCBIN_U16("graphics/text_window/message_box.gbapal"), + INCBIN_U16("graphics/text_window/text_pal1.gbapal"), + INCBIN_U16("graphics/text_window/text_pal2.gbapal"), + INCBIN_U16("graphics/text_window/text_pal3.gbapal"), + INCBIN_U16("graphics/text_window/text_pal4.gbapal") +}; + +static const struct TilesPal sWindowFrames[WINDOW_FRAMES_COUNT] = +{ + {gTextWindowFrame1_Gfx, gTextWindowFrame1_Pal}, + {sTextWindowFrame2_Gfx, sTextWindowFrame2_Pal}, + {sTextWindowFrame3_Gfx, sTextWindowFrame3_Pal}, + {sTextWindowFrame4_Gfx, sTextWindowFrame4_Pal}, + {sTextWindowFrame5_Gfx, sTextWindowFrame5_Pal}, + {sTextWindowFrame6_Gfx, sTextWindowFrame6_Pal}, + {sTextWindowFrame7_Gfx, sTextWindowFrame7_Pal}, + {sTextWindowFrame8_Gfx, sTextWindowFrame8_Pal}, + {sTextWindowFrame9_Gfx, sTextWindowFrame9_Pal}, + {sTextWindowFrame10_Gfx, sTextWindowFrame10_Pal}, + {sTextWindowFrame11_Gfx, sTextWindowFrame11_Pal}, + {sTextWindowFrame12_Gfx, sTextWindowFrame12_Pal}, + {sTextWindowFrame13_Gfx, sTextWindowFrame13_Pal}, + {sTextWindowFrame14_Gfx, sTextWindowFrame14_Pal}, + {sTextWindowFrame15_Gfx, sTextWindowFrame15_Pal}, + {sTextWindowFrame16_Gfx, sTextWindowFrame16_Pal}, + {sTextWindowFrame17_Gfx, sTextWindowFrame17_Pal}, + {sTextWindowFrame18_Gfx, sTextWindowFrame18_Pal}, + {sTextWindowFrame19_Gfx, sTextWindowFrame19_Pal}, + {sTextWindowFrame20_Gfx, sTextWindowFrame20_Pal} +}; + +// code +const struct TilesPal *GetWindowFrameTilesPal(u8 id) +{ + if (id >= WINDOW_FRAMES_COUNT) + return &sWindowFrames[0]; else - return &gUnknown_0851021C[id]; + return &sWindowFrames[id]; } void copy_textbox_border_tile_patterns_to_vram(u8 windowId, u16 destOffset, u8 palOffset) @@ -33,8 +104,8 @@ void box_border_load_tiles_and_pal(u8 windowId, u16 destOffset, u8 palOffset) void sub_80987D4(u8 windowId, u8 frameId, u16 destOffset, u8 palOffset) { - LoadBgTiles(GetWindowAttribute(windowId, WINDOW_PRIORITY), gUnknown_0851021C[frameId].tiles, 0x120, destOffset); - LoadPalette(gUnknown_0851021C[frameId].pal, palOffset, 0x20); + LoadBgTiles(GetWindowAttribute(windowId, WINDOW_PRIORITY), sWindowFrames[frameId].tiles, 0x120, destOffset); + LoadPalette(sWindowFrames[frameId].pal, palOffset, 0x20); } void sub_809882C(u8 windowId, u16 destOffset, u8 palOffset) @@ -89,7 +160,7 @@ void rbox_fill_rectangle(u8 windowId) FillBgTilemapBufferRect(bgLayer, 0, tilemapLeft - 1, tilemapTop - 1, width + 2, height + 2, 0x11); } -const u16* stdpal_get(u8 id) +const u16 *stdpal_get(u8 id) { switch (id) { @@ -110,16 +181,17 @@ const u16* stdpal_get(u8 id) id = 0x40; break; } - return &gUnknown_0851017C[id]; + + return (const u16 *)(sUnknown_0851017C) + id; } -const u16* GetOverworldTextboxPalettePtr(void) +const u16 *GetOverworldTextboxPalettePtr(void) { - return gUnknown_08DDD728; + return gMessageBox_Pal; } void sub_8098C6C(u8 bg, u16 destOffset, u8 palOffset) { - LoadBgTiles(bg, gUnknown_0851021C[gSaveBlock2Ptr->optionsWindowFrameType].tiles, 0x120, destOffset); + LoadBgTiles(bg, sWindowFrames[gSaveBlock2Ptr->optionsWindowFrameType].tiles, 0x120, destOffset); LoadPalette(GetWindowFrameTilesPal(gSaveBlock2Ptr->optionsWindowFrameType)->pal, palOffset, 0x20); }