diff options
-rw-r--r-- | asm/link_rfu_2.s | 4 | ||||
-rw-r--r-- | asm/mystery_gift_menu.s | 251 | ||||
-rw-r--r-- | data/mystery_gift_menu.s | 14 | ||||
-rw-r--r-- | graphics/interface/unk_textbox_border.png | bin | 0 -> 141 bytes | |||
-rw-r--r-- | include/new_menu_helpers.h | 1 | ||||
-rw-r--r-- | include/text_window.h | 2 | ||||
-rw-r--r-- | ld_script.txt | 3 | ||||
-rw-r--r-- | src/mystery_gift_menu.c | 188 |
8 files changed, 201 insertions, 262 deletions
diff --git a/asm/link_rfu_2.s b/asm/link_rfu_2.s index d36eeca20..bad221798 100644 --- a/asm/link_rfu_2.s +++ b/asm/link_rfu_2.s @@ -5152,7 +5152,7 @@ sub_80FAD98: @ 80FAD98 bne _080FAE30 ldr r6, _080FAE18 @ =gMain ldr r1, [r6, 0x4] - ldr r0, _080FAE1C @ =sub_814208C + ldr r0, _080FAE1C @ =c2_mystery_gift_e_reader_run cmp r1, r0 bne _080FADC0 ldr r1, _080FAE20 @ =gWirelessCommType @@ -5199,7 +5199,7 @@ _080FADF8: _080FAE10: .4byte gUnknown_3005450 _080FAE14: .4byte gUnknown_3005E10 _080FAE18: .4byte gMain -_080FAE1C: .4byte sub_814208C +_080FAE1C: .4byte c2_mystery_gift_e_reader_run _080FAE20: .4byte gWirelessCommType _080FAE24: .4byte c2_800ACD4 _080FAE28: .4byte 0x0000069e diff --git a/asm/mystery_gift_menu.s b/asm/mystery_gift_menu.s index d6be6db09..baf5b55f5 100644 --- a/asm/mystery_gift_menu.s +++ b/asm/mystery_gift_menu.s @@ -5,253 +5,14 @@ .text - thumb_func_start sub_8142078 -sub_8142078: @ 8142078 - push {lr} - bl ProcessSpriteCopyRequests - bl LoadOam - bl TransferPlttBuffer - pop {r0} - bx r0 - thumb_func_end sub_8142078 - - thumb_func_start sub_814208C -sub_814208C: @ 814208C - push {lr} - bl RunTasks - bl RunTextPrinters - bl AnimateSprites - bl BuildOamBuffer - pop {r0} - bx r0 - thumb_func_end sub_814208C - - thumb_func_start sub_81420A4 -sub_81420A4: @ 81420A4 - push {r4-r7,lr} - sub sp, 0xC - adds r7, r0, 0 - ldr r0, _081420C4 @ =gMain - movs r1, 0x87 - lsls r1, 3 - adds r6, r0, r1 - ldrb r5, [r6] - cmp r5, 0x1 - bne _081420BA - b _081421EC -_081420BA: - cmp r5, 0x1 - bgt _081420C8 - cmp r5, 0 - beq _081420D6 - b _081422A0 - .align 2, 0 -_081420C4: .4byte gMain -_081420C8: - cmp r5, 0x2 - bne _081420CE - b _08142254 -_081420CE: - cmp r5, 0x3 - bne _081420D4 - b _08142274 -_081420D4: - b _081422A0 -_081420D6: - movs r0, 0 - bl SetVBlankCallback - bl ResetPaletteFade - bl ResetSpriteData - bl FreeAllSpritePalettes - bl ResetTasks - bl ScanlineEffect_Stop - movs r0, 0x1 - bl ResetBgsAndClearDma3BusyFlags - ldr r1, _081421E0 @ =gUnknown_8466D60 - movs r0, 0 - movs r2, 0x4 - bl InitBgsFromTemplates - movs r0, 0 - movs r1, 0 - movs r2, 0 - bl ChangeBgX - movs r0, 0 - movs r1, 0 - movs r2, 0 - bl ChangeBgY - movs r0, 0x1 - movs r1, 0 - movs r2, 0 - bl ChangeBgX - movs r0, 0x1 - movs r1, 0 - movs r2, 0 - bl ChangeBgY - movs r0, 0x2 - movs r1, 0 - movs r2, 0 - bl ChangeBgX - movs r0, 0x2 - movs r1, 0 - movs r2, 0 - bl ChangeBgY - movs r0, 0x3 - movs r1, 0 - movs r2, 0 - bl ChangeBgX - movs r0, 0x3 - movs r1, 0 - movs r2, 0 - bl ChangeBgY - movs r4, 0x80 - lsls r4, 4 - adds r0, r4, 0 - bl Alloc - adds r1, r0, 0 - movs r0, 0x3 - bl SetBgTilemapBuffer - adds r0, r4, 0 - bl Alloc - adds r1, r0, 0 - movs r0, 0x2 - bl SetBgTilemapBuffer - adds r0, r4, 0 - bl Alloc - adds r1, r0, 0 - movs r0, 0x1 - bl SetBgTilemapBuffer - adds r0, r4, 0 - bl Alloc - adds r1, r0, 0 - movs r0, 0 - bl SetBgTilemapBuffer - movs r0, 0 - movs r1, 0xA - movs r2, 0xE0 - bl sub_814FE40 - movs r0, 0 - movs r1, 0x1 - movs r2, 0xF0 - bl sub_814FDA0 - ldr r1, _081421E4 @ =gUnknown_8466D30 - movs r2, 0x80 - lsls r2, 1 - str r5, [sp] - movs r0, 0x3 - movs r3, 0 - bl sub_80F696C - ldr r0, _081421E8 @ =gUnknown_8466D70 - bl InitWindows - bl DeactivateAllTextPrinters - movs r1, 0xC0 - lsls r1, 7 - movs r0, 0 - bl ClearGpuRegBits - movs r0, 0x50 - movs r1, 0 - bl SetGpuReg - movs r0, 0x52 - movs r1, 0 - bl SetGpuReg - movs r0, 0x54 - movs r1, 0 - bl SetGpuReg - b _0814226C - .align 2, 0 -_081421E0: .4byte gUnknown_8466D60 -_081421E4: .4byte gUnknown_8466D30 -_081421E8: .4byte gUnknown_8466D70 -_081421EC: - ldr r0, _08142250 @ =gUnknown_8466D10 - movs r1, 0 - movs r2, 0x20 - bl LoadPalette - movs r0, 0x2 - bl stdpal_get - movs r1, 0xD0 - movs r2, 0x20 - bl LoadPalette - movs r4, 0x20 - str r4, [sp] - str r4, [sp, 0x4] - movs r5, 0x11 - str r5, [sp, 0x8] - movs r0, 0 - movs r1, 0 - movs r2, 0 - movs r3, 0 - bl FillBgTilemapBufferRect - str r4, [sp] - str r4, [sp, 0x4] - str r5, [sp, 0x8] - movs r0, 0x1 - movs r1, 0 - movs r2, 0 - movs r3, 0 - bl FillBgTilemapBufferRect - str r4, [sp] - str r4, [sp, 0x4] - str r5, [sp, 0x8] - movs r0, 0x2 - movs r1, 0 - movs r2, 0 - movs r3, 0 - bl FillBgTilemapBufferRect - bl sub_8142420 - lsls r0, r7, 24 - lsrs r0, 24 - movs r1, 0 - bl sub_8142344 - b _0814226C - .align 2, 0 -_08142250: .4byte gUnknown_8466D10 -_08142254: - movs r0, 0x3 - bl CopyBgTilemapBufferToVram - movs r0, 0x2 - bl CopyBgTilemapBufferToVram - movs r0, 0x1 - bl CopyBgTilemapBufferToVram - movs r0, 0 - bl CopyBgTilemapBufferToVram -_0814226C: - ldrb r0, [r6] - adds r0, 0x1 - strb r0, [r6] - b _081422A0 -_08142274: - movs r0, 0 - bl ShowBg - movs r0, 0x3 - bl ShowBg - ldr r0, _08142298 @ =0x00000149 - bl PlayBGM - ldr r0, _0814229C @ =sub_8142078 - bl SetVBlankCallback - movs r0, 0xC5 - bl EnableInterrupts - movs r0, 0x1 - b _081422A2 - .align 2, 0 -_08142298: .4byte 0x00000149 -_0814229C: .4byte sub_8142078 -_081422A0: - movs r0, 0 -_081422A2: - add sp, 0xC - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_81420A4 - thumb_func_start sub_81422AC sub_81422AC: @ 81422AC push {lr} movs r0, 0 - bl sub_81420A4 + bl HandleMysteryGiftOrEReaderSetup cmp r0, 0 beq _081422C8 - ldr r0, _081422CC @ =sub_814208C + ldr r0, _081422CC @ =c2_mystery_gift_e_reader_run bl SetMainCallback2 ldr r1, _081422D0 @ =gUnknown_203F3B8 movs r0, 0 @@ -261,7 +22,7 @@ _081422C8: pop {r0} bx r0 .align 2, 0 -_081422CC: .4byte sub_814208C +_081422CC: .4byte c2_mystery_gift_e_reader_run _081422D0: .4byte gUnknown_203F3B8 thumb_func_end sub_81422AC @@ -269,10 +30,10 @@ _081422D0: .4byte gUnknown_203F3B8 sub_81422D4: @ 81422D4 push {lr} movs r0, 0x1 - bl sub_81420A4 + bl HandleMysteryGiftOrEReaderSetup cmp r0, 0 beq _081422F0 - ldr r0, _081422F4 @ =sub_814208C + ldr r0, _081422F4 @ =c2_mystery_gift_e_reader_run bl SetMainCallback2 ldr r1, _081422F8 @ =gUnknown_203F3B8 movs r0, 0x1 @@ -282,7 +43,7 @@ _081422F0: pop {r0} bx r0 .align 2, 0 -_081422F4: .4byte sub_814208C +_081422F4: .4byte c2_mystery_gift_e_reader_run _081422F8: .4byte gUnknown_203F3B8 thumb_func_end sub_81422D4 diff --git a/data/mystery_gift_menu.s b/data/mystery_gift_menu.s deleted file mode 100644 index 9caee4467..000000000 --- a/data/mystery_gift_menu.s +++ /dev/null @@ -1,14 +0,0 @@ - .section .rodata - .align 2 - -gUnknown_8466D10:: @ 8466D10 - .incbin "baserom.gba", 0x466D10, 0x20 - -gUnknown_8466D30:: @ 8466D30 - .incbin "baserom.gba", 0x466D30, 0x30 - -gUnknown_8466D60:: @ 8466D60 - .incbin "baserom.gba", 0x466D60, 0x10 - -gUnknown_8466D70:: @ 8466D70 - .incbin "baserom.gba", 0x466D70, 0x20 diff --git a/graphics/interface/unk_textbox_border.png b/graphics/interface/unk_textbox_border.png Binary files differnew file mode 100644 index 000000000..6cc6a64ac --- /dev/null +++ b/graphics/interface/unk_textbox_border.png diff --git a/include/new_menu_helpers.h b/include/new_menu_helpers.h index b17326667..fc9c1b9dc 100644 --- a/include/new_menu_helpers.h +++ b/include/new_menu_helpers.h @@ -30,5 +30,6 @@ void Menu_LoadStdPalAt(u16); void * malloc_and_decompress(const void * src, u32 * size); u16 sub_80F796C(void); void sub_80F6B08(u8 bgId, u8 left, u8 top, u8 width, u8 height, u8 palette); +void sub_80F696C(u8 bgId, const void * gfx, u32 size, u16 a3, u8 a4); #endif // GUARD_NEW_MENU_HELPERS_H diff --git a/include/text_window.h b/include/text_window.h index 8a4113c62..2afc52a08 100644 --- a/include/text_window.h +++ b/include/text_window.h @@ -23,5 +23,7 @@ void sub_8098C6C(u8 bg, u16 destOffset, u8 palOffset); void sub_814FEAC(u8 windowId, u16 tileStart, u8 palette); void sub_814FF2C(u8 windowId, u16 tileStart, u8 palette); void sub_815001C(u8 windowId, u16 tileStart, u8 palette); +void sub_814FE40(u8 windowId, u16 tileStart, u8 palette); +void sub_814FDA0(u8 windowId, u16 tileStart, u8 palette); #endif // GUARD_TEXT_WINDOW_H diff --git a/ld_script.txt b/ld_script.txt index 283c711f7..6c50d0e5a 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -241,6 +241,7 @@ SECTIONS { asm/buy_menu_helpers.o(.text); asm/slot_machine.o(.text); src/roamer.o(.text); + src/mystery_gift_menu.o(.text); asm/mystery_gift_menu.o(.text); asm/link_rfu_4.o(.text); src/mevent.o(.text); @@ -409,7 +410,7 @@ SECTIONS { data/buy_menu_helpers.o(.rodata); data/slot_machine.o(.rodata); src/roamer.o(.rodata); - data/mystery_gift_menu.o(.rodata); + src/mystery_gift_menu.o(.rodata); data/link_rfu_4.o(.rodata); src/mevent.o(.rodata); src/mevent_server_helpers.o(.rodata); diff --git a/src/mystery_gift_menu.c b/src/mystery_gift_menu.c new file mode 100644 index 000000000..7b7fd71a1 --- /dev/null +++ b/src/mystery_gift_menu.c @@ -0,0 +1,188 @@ +#include "global.h" +#include "palette.h" +#include "dma3.h" +#include "gpu_regs.h" +#include "bg.h" +#include "task.h" +#include "scanline_effect.h" +#include "malloc.h" +#include "text.h" +#include "window.h" +#include "text_window.h" +#include "new_menu_helpers.h" +#include "sound.h" +#include "mystery_gift_menu.h" +#include "link_rfu.h" +#include "constants/songs.h" + +EWRAM_DATA u8 sDownArrowCounterAndYCoordIdx[8] = {}; +EWRAM_DATA bool8 gGiftIsFromEReader = FALSE; + +static const u16 gUnkTextboxBorderPal[] = INCBIN_U16("graphics/interface/unk_textbox_border.gbapal"); +static const u32 gUnkTextboxBorderGfx[] = INCBIN_U32("graphics/interface/unk_textbox_border.4bpp.lz"); + +struct MysteryGiftTaskData +{ + u16 curPromptWindowId; + u16 unk2; + u16 unk4; + u16 unk6; + u8 state; + u8 textState; + u8 unkA; + u8 unkB; + u8 IsCardOrNews; + u8 source; + u8 prevPromptWindowId; + u8 * buffer; +}; + +static const struct BgTemplate sBGTemplates[] = { + { + .bg = 0, + .charBaseIndex = 2, + .mapBaseIndex = 15, + .screenSize = 0, + .paletteMode = 0, + .priority = 0, + .baseTile = 0x000 + }, { + .bg = 1, + .charBaseIndex = 0, + .mapBaseIndex = 14, + .screenSize = 0, + .paletteMode = 0, + .priority = 1, + .baseTile = 0x000 + }, { + .bg = 2, + .charBaseIndex = 0, + .mapBaseIndex = 13, + .screenSize = 0, + .paletteMode = 0, + .priority = 2, + .baseTile = 0x000 + }, { + .bg = 3, + .charBaseIndex = 0, + .mapBaseIndex = 12, + .screenSize = 0, + .paletteMode = 0, + .priority = 3, + .baseTile = 0x000 + } +}; + +static const struct WindowTemplate sMainWindows[] = { + { + .priority = 0x00, + .tilemapLeft = 0x00, + .tilemapTop = 0x00, + .width = 0x1e, + .height = 0x02, + .paletteNum = 0x0f, + .baseBlock = 0x0013 + }, { + .priority = 0x00, + .tilemapLeft = 0x01, + .tilemapTop = 0x0f, + .width = 0x1c, + .height = 0x04, + .paletteNum = 0x0f, + .baseBlock = 0x004f + }, { + .priority = 0x00, + .tilemapLeft = 0x00, + .tilemapTop = 0x0f, + .width = 0x1e, + .height = 0x05, + .paletteNum = 0x0d, + .baseBlock = 0x004f + }, { + 0xFF + } +}; + +void vblankcb_mystery_gift_e_reader_run(void) +{ + ProcessSpriteCopyRequests(); + LoadOam(); + TransferPlttBuffer(); +} + +void c2_mystery_gift_e_reader_run(void) +{ + RunTasks(); + RunTextPrinters(); + AnimateSprites(); + BuildOamBuffer(); +} + +bool32 HandleMysteryGiftOrEReaderSetup(s32 mg_or_ereader) +{ + switch (gMain.state) + { + case 0: + SetVBlankCallback(NULL); + ResetPaletteFade(); + ResetSpriteData(); + FreeAllSpritePalettes(); + ResetTasks(); + ScanlineEffect_Stop(); + ResetBgsAndClearDma3BusyFlags(1); + + InitBgsFromTemplates(0, sBGTemplates, ARRAY_COUNT(sBGTemplates)); + ChangeBgX(0, 0, 0); + ChangeBgY(0, 0, 0); + ChangeBgX(1, 0, 0); + ChangeBgY(1, 0, 0); + ChangeBgX(2, 0, 0); + ChangeBgY(2, 0, 0); + ChangeBgX(3, 0, 0); + ChangeBgY(3, 0, 0); + + SetBgTilemapBuffer(3, Alloc(0x800)); + SetBgTilemapBuffer(2, Alloc(0x800)); + SetBgTilemapBuffer(1, Alloc(0x800)); + SetBgTilemapBuffer(0, Alloc(0x800)); + + sub_814FE40(0, 10, 0xE0); + sub_814FDA0(0, 1, 0xF0); + sub_80F696C(3, gUnkTextboxBorderGfx, 0x100, 0, 0); + InitWindows(sMainWindows); + DeactivateAllTextPrinters(); + ClearGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON | DISPCNT_WIN1_ON); + SetGpuReg(REG_OFFSET_BLDCNT, 0); + SetGpuReg(REG_OFFSET_BLDALPHA, 0); + SetGpuReg(REG_OFFSET_BLDY, 0); + gMain.state++; + break; + case 1: + LoadPalette(gUnkTextboxBorderPal, 0, 0x20); + LoadPalette(stdpal_get(2), 0xd0, 0x20); + FillBgTilemapBufferRect(0, 0x000, 0, 0, 32, 32, 0x11); + FillBgTilemapBufferRect(1, 0x000, 0, 0, 32, 32, 0x11); + FillBgTilemapBufferRect(2, 0x000, 0, 0, 32, 32, 0x11); + sub_8142420(); + sub_8142344(mg_or_ereader, 0); + gMain.state++; + break; + case 2: + CopyBgTilemapBufferToVram(3); + CopyBgTilemapBufferToVram(2); + CopyBgTilemapBufferToVram(1); + CopyBgTilemapBufferToVram(0); + gMain.state++; + break; + case 3: + ShowBg(0); + ShowBg(3); + PlayBGM(BGM_FRLG_MYSTERY_GIFT); + SetVBlankCallback(vblankcb_mystery_gift_e_reader_run); + EnableInterrupts(INTR_FLAG_VBLANK | INTR_FLAG_VCOUNT | INTR_FLAG_TIMER3 | INTR_FLAG_SERIAL); + return TRUE; + } + + return FALSE; +} + |