diff --git a/asm/diploma.s b/asm/diploma.s deleted file mode 100644 index 4f21fe39d..000000000 --- a/asm/diploma.s +++ /dev/null @@ -1,387 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start sub_8177874 -sub_8177874: @ 8177874 - push {lr} - bl LoadOam - bl ProcessSpriteCopyRequests - bl TransferPlttBuffer - pop {r0} - bx r0 - thumb_func_end sub_8177874 - - thumb_func_start sub_8177888 -sub_8177888: @ 8177888 - push {r4,r5,lr} - sub sp, 0xC - movs r0, 0 - bl SetVBlankCallback - movs r0, 0 - movs r1, 0 - bl SetGpuReg - movs r0, 0xE - movs r1, 0 - bl SetGpuReg - movs r0, 0xC - movs r1, 0 - bl SetGpuReg - movs r0, 0xA - movs r1, 0 - bl SetGpuReg - movs r0, 0x8 - movs r1, 0 - bl SetGpuReg - movs r0, 0x1C - movs r1, 0 - bl SetGpuReg - movs r0, 0x1E - movs r1, 0 - bl SetGpuReg - movs r0, 0x18 - movs r1, 0 - bl SetGpuReg - movs r0, 0x1A - movs r1, 0 - bl SetGpuReg - movs r0, 0x14 - movs r1, 0 - bl SetGpuReg - movs r0, 0x16 - movs r1, 0 - bl SetGpuReg - movs r0, 0x10 - movs r1, 0 - bl SetGpuReg - movs r0, 0x12 - movs r1, 0 - bl SetGpuReg - add r1, sp, 0x4 - movs r0, 0 - strh r0, [r1] - ldr r1, =0x040000d4 - add r0, sp, 0x4 - str r0, [r1] - movs r0, 0xC0 - lsls r0, 19 - str r0, [r1, 0x4] - ldr r0, =0x8100c000 - str r0, [r1, 0x8] - ldr r0, [r1, 0x8] - movs r5, 0 - str r5, [sp, 0x8] - add r0, sp, 0x8 - str r0, [r1] - movs r0, 0xE0 - lsls r0, 19 - str r0, [r1, 0x4] - ldr r0, =0x85000100 - str r0, [r1, 0x8] - ldr r0, [r1, 0x8] - add r0, sp, 0x4 - strh r5, [r0] - str r0, [r1] - movs r0, 0xA0 - lsls r0, 19 - str r0, [r1, 0x4] - ldr r0, =0x81000200 - str r0, [r1, 0x8] - ldr r0, [r1, 0x8] - bl remove_some_task - bl ResetTasks - bl ResetSpriteData - bl ResetPaletteFade - bl FreeAllSpritePalettes - ldr r0, =gUnknown_085E7088 - movs r1, 0 - movs r2, 0x40 - bl LoadPalette - ldr r4, =gUnknown_0203BCF0 - movs r0, 0x80 - lsls r0, 5 - bl Alloc - str r0, [r4] - bl sub_8177B44 - bl sub_8177B9C - bl reset_temp_tile_data_buffers - ldr r1, =gUnknown_085E7804 - str r5, [sp] - movs r0, 0x1 - movs r2, 0 - movs r3, 0 - bl decompress_and_copy_tile_data_to_vram -_0817797C: - bl free_temp_tile_data_buffers_if_possible - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, 0 - bne _0817797C - ldr r0, =gUnknown_085E70C8 - ldr r1, =gUnknown_0203BCF0 - ldr r1, [r1] - bl LZDecompressWram - movs r0, 0x1 - bl CopyBgTilemapBufferToVram - bl pokedex_diploma_something - movs r4, 0x1 - negs r4, r4 - adds r0, r4, 0 - movs r1, 0x10 - movs r2, 0 - bl BlendPalettes - str r5, [sp] - adds r0, r4, 0 - movs r1, 0 - movs r2, 0x10 - movs r3, 0 - bl BeginNormalPaletteFade - movs r0, 0x1 - bl EnableInterrupts - ldr r0, =sub_8177874 - bl SetVBlankCallback - ldr r0, =sub_8177A08 - bl SetMainCallback2 - ldr r0, =sub_8177A20 - movs r1, 0 - bl CreateTask - add sp, 0xC - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8177888 - - thumb_func_start sub_8177A08 -sub_8177A08: @ 8177A08 - push {lr} - bl RunTasks - bl AnimateSprites - bl BuildOamBuffer - bl UpdatePaletteFade - pop {r0} - bx r0 - thumb_func_end sub_8177A08 - - thumb_func_start sub_8177A20 -sub_8177A20: @ 8177A20 - push {lr} - lsls r0, 24 - lsrs r2, r0, 24 - ldr r0, =gPaletteFade - ldrb r1, [r0, 0x7] - movs r0, 0x80 - ands r0, r1 - cmp r0, 0 - bne _08177A40 - ldr r0, =gTasks - lsls r1, r2, 2 - adds r1, r2 - lsls r1, 3 - adds r1, r0 - ldr r0, =sub_8177A50 - str r0, [r1] -_08177A40: - pop {r0} - bx r0 - .pool - thumb_func_end sub_8177A20 - - thumb_func_start sub_8177A50 -sub_8177A50: @ 8177A50 - push {r4,lr} - sub sp, 0x4 - lsls r0, 24 - lsrs r4, r0, 24 - ldr r0, =gMain - ldrh r1, [r0, 0x2E] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0 - beq _08177A82 - movs r0, 0x1 - negs r0, r0 - movs r1, 0 - str r1, [sp] - movs r2, 0 - movs r3, 0x10 - bl BeginNormalPaletteFade - ldr r1, =gTasks - lsls r0, r4, 2 - adds r0, r4 - lsls r0, 3 - adds r0, r1 - ldr r1, =sub_8177A98 - str r1, [r0] -_08177A82: - add sp, 0x4 - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8177A50 - - thumb_func_start sub_8177A98 -sub_8177A98: @ 8177A98 - push {r4,lr} - lsls r0, 24 - lsrs r4, r0, 24 - ldr r0, =gPaletteFade - ldrb r1, [r0, 0x7] - movs r0, 0x80 - ands r0, r1 - cmp r0, 0 - bne _08177AC2 - ldr r0, =gUnknown_0203BCF0 - ldr r0, [r0] - bl Free - bl FreeAllWindowBuffers - adds r0, r4, 0 - bl DestroyTask - ldr r0, =sub_80861E8 - bl SetMainCallback2 -_08177AC2: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8177A98 - - thumb_func_start pokedex_diploma_something -pokedex_diploma_something: @ 8177AD4 - push {r4,lr} - bl sub_80C0944 - lsls r0, 16 - cmp r0, 0 - beq _08177AFC - movs r1, 0x80 - lsls r1, 1 - movs r0, 0x14 - bl SetGpuReg - ldr r0, =gStringVar1 - ldr r1, =gText_DexNational - bl StringCopy - b _08177B0C - .pool -_08177AFC: - movs r0, 0x14 - movs r1, 0 - bl SetGpuReg - ldr r0, =gStringVar1 - ldr r1, =gText_DexHoenn - bl StringCopy -_08177B0C: - ldr r4, =gStringVar4 - ldr r1, =gText_PokedexDiploma - adds r0, r4, 0 - bl StringExpandPlaceholders - adds r0, r4, 0 - movs r1, 0 - movs r2, 0x1 - bl sub_8177BCC - movs r0, 0 - bl PutWindowTilemap - movs r0, 0 - movs r1, 0x3 - bl CopyWindowToVram - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end pokedex_diploma_something - - thumb_func_start sub_8177B44 -sub_8177B44: @ 8177B44 - push {lr} - movs r0, 0 - bl ResetBgsAndClearDma3BusyFlags - ldr r1, =gUnknown_085E81FC - movs r0, 0 - movs r2, 0x2 - bl InitBgsFromTemplates - ldr r0, =gUnknown_0203BCF0 - ldr r1, [r0] - movs r0, 0x1 - bl SetBgTilemapBuffer - movs r1, 0x82 - lsls r1, 5 - movs r0, 0 - bl SetGpuReg - movs r0, 0 - bl ShowBg - movs r0, 0x1 - bl ShowBg - movs r0, 0x50 - movs r1, 0 - bl SetGpuReg - movs r0, 0x52 - movs r1, 0 - bl SetGpuReg - movs r0, 0x54 - movs r1, 0 - bl SetGpuReg - pop {r0} - bx r0 - .pool - thumb_func_end sub_8177B44 - - thumb_func_start sub_8177B9C -sub_8177B9C: @ 8177B9C - push {lr} - ldr r0, =gUnknown_085E8204 - bl InitWindows - bl DeactivateAllTextPrinters - ldr r0, =gUnknown_0860F074 - movs r1, 0xF0 - movs r2, 0x20 - bl LoadPalette - movs r0, 0 - movs r1, 0 - bl FillWindowPixelBuffer - movs r0, 0 - bl PutWindowTilemap - pop {r0} - bx r0 - .pool - thumb_func_end sub_8177B9C - - thumb_func_start sub_8177BCC -sub_8177BCC: @ 8177BCC - push {r4-r6,lr} - sub sp, 0x18 - adds r6, r0, 0 - adds r4, r1, 0 - adds r5, r2, 0 - lsls r4, 24 - lsrs r4, 24 - lsls r5, 24 - lsrs r5, 24 - ldr r1, =gUnknown_085E8214 - add r0, sp, 0x14 - movs r2, 0x3 - bl memcpy - movs r0, 0 - str r0, [sp] - str r0, [sp, 0x4] - add r0, sp, 0x14 - str r0, [sp, 0x8] - movs r0, 0x1 - negs r0, r0 - str r0, [sp, 0xC] - str r6, [sp, 0x10] - movs r0, 0 - movs r1, 0x1 - adds r2, r4, 0 - adds r3, r5, 0 - bl AddTextPrinterParametrized2 - add sp, 0x18 - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8177BCC - - .align 2, 0 @ Don't pad with nop. diff --git a/asm/rom4.s b/asm/rom4.s index 8423d0d9a..0a624620d 100644 --- a/asm/rom4.s +++ b/asm/rom4.s @@ -1375,7 +1375,7 @@ _080850C8: bl warp_shift bl set_current_map_header_from_sav1_save_old_name bl CopyFieldObjectTemplatesToSav1 - bl sav2_set_x9_depending_on_sav1_map + bl TrySetMapSaveWarpStatus bl ClearTempFieldEventData bl wild_pokemon_reroll bl prev_quest_postbuffer_cursor_backup_reset @@ -1463,7 +1463,7 @@ _080851A2: lsls r0, 24 lsrs r6, r0, 24 bl sub_80EB218 - bl sav2_set_x9_depending_on_sav1_map + bl TrySetMapSaveWarpStatus bl ClearTempFieldEventData bl wild_pokemon_reroll bl prev_quest_postbuffer_cursor_backup_reset diff --git a/asm/rom6.s b/asm/rom6.s index 0b35ab0e8..2ed9d888e 100644 --- a/asm/rom6.s +++ b/asm/rom6.s @@ -4705,7 +4705,7 @@ _08137CAC: thumb_func_start sub_8137CB4 sub_8137CB4: @ 8137CB4 push {lr} - ldr r0, =sub_8177888 + ldr r0, =CB2_ShowDiploma bl SetMainCallback2 bl ScriptContext2_Enable pop {r0} diff --git a/asm/save_location.s b/asm/save_location.s deleted file mode 100755 index 1a5b3c6da..000000000 --- a/asm/save_location.s +++ /dev/null @@ -1,205 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start sav1_are_mapnumbers_in_given_list -sav1_are_mapnumbers_in_given_list: @ 81AFC84 - push {r4,lr} - adds r2, r0, 0 - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - movs r1, 0x4 - ldrsb r1, [r0, r1] - lsls r1, 8 - ldrb r0, [r0, 0x5] - lsls r0, 24 - asrs r0, 24 - adds r0, r1 - lsls r0, 16 - lsrs r3, r0, 16 - ldrh r0, [r2] - ldr r1, =0x0000ffff - cmp r0, r1 - beq _081AFCC4 - adds r4, r1, 0 - adds r1, r2, 0 -_081AFCAA: - ldrh r0, [r1] - cmp r0, r3 - bne _081AFCBC - movs r0, 0x1 - b _081AFCC6 - .pool -_081AFCBC: - adds r1, 0x2 - ldrh r0, [r1] - cmp r0, r4 - bne _081AFCAA -_081AFCC4: - movs r0, 0 -_081AFCC6: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sav1_are_mapnumbers_in_given_list - - thumb_func_start sav1_is_in_pokecenter -sav1_is_in_pokecenter: @ 81AFCCC - push {lr} - ldr r0, =gUnknown_086143BC - bl sav1_are_mapnumbers_in_given_list - pop {r1} - bx r1 - .pool - thumb_func_end sav1_is_in_pokecenter - - thumb_func_start sub_81AFCDC -sub_81AFCDC: @ 81AFCDC - push {lr} - ldr r0, =gUnknown_0861440A - bl sav1_are_mapnumbers_in_given_list - pop {r1} - bx r1 - .pool - thumb_func_end sub_81AFCDC - - thumb_func_start sub_81AFCEC -sub_81AFCEC: @ 81AFCEC - push {lr} - ldr r0, =gUnknown_0861440E - bl sav1_are_mapnumbers_in_given_list - pop {r1} - bx r1 - .pool - thumb_func_end sub_81AFCEC - - thumb_func_start sav2_set_x9_bit3_when_sav1_in_pokecenter -sav2_set_x9_bit3_when_sav1_in_pokecenter: @ 81AFCFC - push {lr} - bl sav1_is_in_pokecenter - cmp r0, 0 - bne _081AFD18 - ldr r0, =gSaveBlock2Ptr - ldr r2, [r0] - ldrb r1, [r2, 0x9] - movs r0, 0xFD - ands r0, r1 - b _081AFD22 - .pool -_081AFD18: - ldr r0, =gSaveBlock2Ptr - ldr r2, [r0] - ldrb r1, [r2, 0x9] - movs r0, 0x2 - orrs r0, r1 -_081AFD22: - strb r0, [r2, 0x9] - pop {r0} - bx r0 - .pool - thumb_func_end sav2_set_x9_bit3_when_sav1_in_pokecenter - - thumb_func_start sub_81AFD2C -sub_81AFD2C: @ 81AFD2C - push {lr} - bl sub_81AFCDC - cmp r0, 0 - bne _081AFD48 - ldr r0, =gSaveBlock2Ptr - ldr r2, [r0] - ldrb r1, [r2, 0x9] - movs r0, 0xFB - ands r0, r1 - b _081AFD52 - .pool -_081AFD48: - ldr r0, =gSaveBlock2Ptr - ldr r2, [r0] - ldrb r1, [r2, 0x9] - movs r0, 0x4 - orrs r0, r1 -_081AFD52: - strb r0, [r2, 0x9] - pop {r0} - bx r0 - .pool - thumb_func_end sub_81AFD2C - - thumb_func_start sub_81AFD5C -sub_81AFD5C: @ 81AFD5C - push {lr} - bl sub_81AFCEC - cmp r0, 0 - bne _081AFD78 - ldr r0, =gSaveBlock2Ptr - ldr r2, [r0] - ldrb r1, [r2, 0x9] - movs r0, 0xF7 - ands r0, r1 - b _081AFD82 - .pool -_081AFD78: - ldr r0, =gSaveBlock2Ptr - ldr r2, [r0] - ldrb r1, [r2, 0x9] - movs r0, 0x8 - orrs r0, r1 -_081AFD82: - strb r0, [r2, 0x9] - pop {r0} - bx r0 - .pool - thumb_func_end sub_81AFD5C - - thumb_func_start sav2_set_x9_depending_on_sav1_map -sav2_set_x9_depending_on_sav1_map: @ 81AFD8C - push {lr} - bl sav2_set_x9_bit3_when_sav1_in_pokecenter - bl sub_81AFD2C - bl sub_81AFD5C - pop {r0} - bx r0 - thumb_func_end sav2_set_x9_depending_on_sav1_map - - thumb_func_start sub_81AFDA0 -sub_81AFDA0: @ 81AFDA0 - ldr r0, =gSaveBlock2Ptr - ldr r2, [r0] - adds r2, 0xA8 - ldr r0, [r2] - movs r1, 0x80 - lsls r1, 8 - orrs r0, r1 - movs r1, 0x1 - orrs r0, r1 - movs r1, 0x2 - orrs r0, r1 - movs r1, 0x4 - orrs r0, r1 - movs r1, 0x10 - orrs r0, r1 - movs r1, 0x20 - orrs r0, r1 - movs r1, 0x8 - orrs r0, r1 - str r0, [r2] - bx lr - .pool - thumb_func_end sub_81AFDA0 - - thumb_func_start sub_81AFDD0 -sub_81AFDD0: @ 81AFDD0 - ldr r0, =gSaveBlock2Ptr - ldr r2, [r0] - ldrb r1, [r2, 0x9] - movs r0, 0x80 - orrs r0, r1 - strb r0, [r2, 0x9] - bx lr - .pool - thumb_func_end sub_81AFDD0 - - .align 2, 0 @ Don't pad with nop. diff --git a/data/diploma.s b/data/diploma.s deleted file mode 100644 index 43a3d9c70..000000000 --- a/data/diploma.s +++ /dev/null @@ -1,22 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .section .rodata - -gUnknown_085E7088:: @ 85E7088 - .incbin "baserom.gba", 0x5e7088, 0x40 - -gUnknown_085E70C8:: @ 85E70C8 - .incbin "baserom.gba", 0x5e70c8, 0x73c - -gUnknown_085E7804:: @ 85E7804 - .incbin "baserom.gba", 0x5e7804, 0x9f8 - -gUnknown_085E81FC:: @ 85E81FC - .incbin "baserom.gba", 0x5e81fc, 0x8 - -gUnknown_085E8204:: @ 85E8204 - .incbin "baserom.gba", 0x5e8204, 0x10 - -gUnknown_085E8214:: @ 85E8214 - .incbin "baserom.gba", 0x5e8214, 0x4 diff --git a/data/save_location.s b/data/save_location.s deleted file mode 100644 index eabed7d86..000000000 --- a/data/save_location.s +++ /dev/null @@ -1,13 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .section .rodata - -gUnknown_086143BC:: @ 86143BC - .incbin "baserom.gba", 0x6143bc, 0x4e - -gUnknown_0861440A:: @ 861440A - .incbin "baserom.gba", 0x61440a, 0x4 - -gUnknown_0861440E:: @ 861440E - .incbin "baserom.gba", 0x61440e, 0x2 diff --git a/graphics/misc/diploma.png b/graphics/misc/diploma.png new file mode 100755 index 000000000..d9607dce6 Binary files /dev/null and b/graphics/misc/diploma.png differ diff --git a/graphics/misc/diploma_hoenn.pal b/graphics/misc/diploma_hoenn.pal new file mode 100755 index 000000000..2890eb24a --- /dev/null +++ b/graphics/misc/diploma_hoenn.pal @@ -0,0 +1,19 @@ +JASC-PAL +0100 +16 +24 41 82 +255 255 222 +246 238 230 +205 230 139 +172 222 49 +238 238 222 +222 230 230 +255 222 197 +222 222 189 +246 246 180 +238 230 180 +213 213 156 +230 230 139 +255 255 123 +238 238 106 +255 205 172 diff --git a/graphics/misc/diploma_map.bin b/graphics/misc/diploma_map.bin new file mode 100755 index 000000000..e9a47fa44 Binary files /dev/null and b/graphics/misc/diploma_map.bin differ diff --git a/graphics/misc/diploma_national.pal b/graphics/misc/diploma_national.pal new file mode 100755 index 000000000..03c37bf22 --- /dev/null +++ b/graphics/misc/diploma_national.pal @@ -0,0 +1,19 @@ +JASC-PAL +0100 +16 +24 41 82 +255 255 222 +255 255 189 +230 238 90 +213 222 0 +238 238 222 +222 230 230 +255 222 197 +222 222 189 +246 246 180 +238 230 180 +213 213 156 +230 230 139 +255 255 123 +238 238 106 +255 205 172 diff --git a/ld_script.txt b/ld_script.txt index 12815bcd5..bfd72e8b6 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -218,7 +218,7 @@ SECTIONS { asm/hall_of_fame.o(.text); asm/credits.o(.text); src/lottery_corner.o(.text); - asm/diploma.o(.text); + src/diploma.o(.text); asm/berry_tag_screen.o(.text); asm/mystery_event_menu.o(.text); src/save_failed_screen.o(.text); @@ -244,7 +244,7 @@ SECTIONS { asm/list_menu.o(.text); asm/menu_indicators.o(.text); asm/unk_text_util.o(.text); - asm/save_location.o(.text); + src/save_location.o(.text); asm/item_icon.o(.text); asm/party_menu.o(.text); asm/battle_tent.o(.text); @@ -430,7 +430,7 @@ SECTIONS { data/hall_of_fame.o(.rodata); data/credits.o(.rodata); src/lottery_corner.o(.rodata); - data/diploma.o(.rodata); + src/diploma.o(.rodata); data/strings.o(.rodata); data/berry_tag_screen.o(.rodata); data/mystery_event_menu.o(.rodata); @@ -451,7 +451,7 @@ SECTIONS { data/battle_frontier_2.o(.rodata); data/item_menu.o(.rodata); data/menu_indicators.o(.rodata); - data/save_location.o(.rodata); + src/save_location.o(.rodata); data/item_icon.o(.rodata); data/party_menu.o(.rodata); data/battle_tent.o(.rodata); diff --git a/src/diploma.c b/src/diploma.c new file mode 100755 index 000000000..f2cbcabb7 --- /dev/null +++ b/src/diploma.c @@ -0,0 +1,218 @@ +#include "global.h" +#include "palette.h" +#include "main.h" +#include "gpu_regs.h" +#include "unknown_task.h" +#include "task.h" +#include "malloc.h" +#include "decompress.h" +#include "bg.h" +#include "window.h" +#include "string_util.h" +#include "text.h" + +extern void reset_temp_tile_data_buffers(void); +extern int decompress_and_copy_tile_data_to_vram(u8 bg_id, void *src, int size, u16 offset, u8 mode); +extern bool8 free_temp_tile_data_buffers_if_possible(void); +extern void sub_80861E8(void); // rom4 +extern bool16 sub_80C0944(void); +extern void AddTextPrinterParametrized2(u8 windowId, u8 fontId, u8 x, u8 y, u8 letterSpacing, u8 lineSpacing, struct TextColor *color, s8 speed, u8 *str); + +extern u16 gUnknown_0860F074[]; + +extern u8 gText_DexNational[]; +extern u8 gText_DexHoenn[]; +extern u8 gText_PokedexDiploma[]; + +static void MainCB2(void); +static void Task_DiplomaFadeIn(u8); +static void Task_DiplomaWaitForKeyPress(u8); +static void Task_DiplomaFadeOut(u8); +static void DisplayDiplomaText(void); +static void InitDiplomaBg(void); +static void InitDiplomaWindow(void); +static void PrintDiplomaText(u8 *, u8, u8); + +EWRAM_DATA void **gDiplomaTilemapPtr = {NULL}; + +static void VBlankCB(void) +{ + LoadOam(); + ProcessSpriteCopyRequests(); + TransferPlttBuffer(); +} + +static const u16 gDiplomaPalettes[][16] = +{ + INCBIN_U16("graphics/misc/diploma_national.gbapal"), + INCBIN_U16("graphics/misc/diploma_hoenn.gbapal"), +}; + +static const u8 gDiplomaTilemap[] = INCBIN_U8("graphics/misc/diploma_map.bin.lz"); +static const u8 gDiplomaTiles[] = INCBIN_U8("graphics/misc/diploma.4bpp.lz"); + +void CB2_ShowDiploma(void) +{ + SetVBlankCallback(NULL); + SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_BG3CNT, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_BG2CNT, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_BG1CNT, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_BG0CNT, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_BG3HOFS, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_BG3VOFS, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_BG2HOFS, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_BG2VOFS, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_BG1HOFS, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_BG1VOFS, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_BG0HOFS, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_BG0VOFS, DISPCNT_MODE_0); + // why doesn't this one use the dma manager either? + DmaFill16(3, 0, VRAM, VRAM_SIZE); + DmaFill32(3, 0, OAM, OAM_SIZE); + DmaFill16(3, 0, PLTT, PLTT_SIZE); + remove_some_task(); + ResetTasks(); + ResetSpriteData(); + ResetPaletteFade(); + FreeAllSpritePalettes(); + LoadPalette(gDiplomaPalettes, 0, 64); + gDiplomaTilemapPtr = malloc(0x1000); + InitDiplomaBg(); + InitDiplomaWindow(); + reset_temp_tile_data_buffers(); + decompress_and_copy_tile_data_to_vram(1, &gDiplomaTiles, 0, 0, 0); + while (free_temp_tile_data_buffers_if_possible()) + ; + LZDecompressWram(&gDiplomaTilemap, gDiplomaTilemapPtr); + CopyBgTilemapBufferToVram(1); + DisplayDiplomaText(); + BlendPalettes(-1, 16, 0); + BeginNormalPaletteFade(-1, 0, 16, 0, 0); + EnableInterrupts(1); + SetVBlankCallback(VBlankCB); + SetMainCallback2(MainCB2); + CreateTask(Task_DiplomaFadeIn, 0); +} + +static void MainCB2(void) +{ + RunTasks(); + AnimateSprites(); + BuildOamBuffer(); + UpdatePaletteFade(); +} + +static void Task_DiplomaFadeIn(u8 taskId) +{ + if (!gPaletteFade.active) + gTasks[taskId].func = Task_DiplomaWaitForKeyPress; +} + +static void Task_DiplomaWaitForKeyPress(u8 taskId) +{ + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) + { + BeginNormalPaletteFade(-1, 0, 0, 16, 0); + gTasks[taskId].func = Task_DiplomaFadeOut; + } +} + +static void Task_DiplomaFadeOut(u8 taskId) +{ + if (!gPaletteFade.active) + { + Free(gDiplomaTilemapPtr); + FreeAllWindowBuffers(); + DestroyTask(taskId); + SetMainCallback2(sub_80861E8); + } +} + +static void DisplayDiplomaText(void) +{ + if (sub_80C0944()) + { + SetGpuReg(REG_OFFSET_BG1HOFS, DISPCNT_BG0_ON); + StringCopy(gStringVar1, gText_DexNational); + } + else + { + SetGpuReg(REG_OFFSET_BG1HOFS, DISPCNT_MODE_0); + StringCopy(gStringVar1, gText_DexHoenn); + } + StringExpandPlaceholders(gStringVar4, gText_PokedexDiploma); + PrintDiplomaText(gStringVar4, 0, 1); + PutWindowTilemap(0); + CopyWindowToVram(0, 3); +} + +static const struct BgTemplate gDiplomaBgTemplates[2] = +{ + { + .bg = 0, + .charBaseIndex = 1, + .mapBaseIndex = 31, + .screenSize = 0, + .paletteMode = 0, + .priority = 0, + .baseTile = 0, + }, + { + .bg = 1, + .charBaseIndex = 0, + .mapBaseIndex = 6, + .screenSize = 1, + .paletteMode = 0, + .priority = 1, + .baseTile = 0, + }, +}; + +static void InitDiplomaBg(void) +{ + ResetBgsAndClearDma3BusyFlags(0); + InitBgsFromTemplates(0, gDiplomaBgTemplates, 2); + SetBgTilemapBuffer(1, gDiplomaTilemapPtr); + SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); + ShowBg(0); + ShowBg(1); + SetGpuReg(REG_OFFSET_BLDCNT, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_BLDALPHA, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_BLDY, DISPCNT_MODE_0); +} + +static const struct WindowTemplate gDiplomaWinTemplates[2] = +{ + { + .priority = 0, + .tilemapLeft = 5, + .tilemapTop = 2, + .width = 20, + .height = 16, + .paletteNum = 15, + .baseBlock = 1, + }, + DUMMY_WIN_TEMPLATE, +}; + +static void InitDiplomaWindow(void) +{ + InitWindows(gDiplomaWinTemplates); + DeactivateAllTextPrinters(); + LoadPalette(gUnknown_0860F074, 0xF0, 0x20); + FillWindowPixelBuffer(0, 0); + PutWindowTilemap(0); +} + +static void PrintDiplomaText(u8 *text, u8 var1, u8 var2) +{ + struct TextColor color = + { + .fgColor = 0, + .bgColor = 2, + .shadowColor = 3, + }; + + AddTextPrinterParametrized2(0, 1, var1, var2, 0, 0, &color, -1, text); +} diff --git a/src/save_failed_screen.c b/src/save_failed_screen.c index 7a7c30388..3f49b89e6 100755 --- a/src/save_failed_screen.c +++ b/src/save_failed_screen.c @@ -13,7 +13,7 @@ #define MSG_WIN_TOP 12 #define CLOCK_WIN_TOP (MSG_WIN_TOP - 4) -extern void AddTextPrinterParametrized2(u8 windowId, u8 fontId, u8 x, u8 y, u8 letterSpacing, u8 lineSpacing, struct TextColor *color, u8 speed, u8 *str); +extern void AddTextPrinterParametrized2(u8 windowId, u8 fontId, u8 x, u8 y, u8 letterSpacing, u8 lineSpacing, struct TextColor *color, s8 speed, u8 *str); extern void (*gGameContinueCallback)(void); diff --git a/src/save_location.c b/src/save_location.c new file mode 100755 index 000000000..87067e14d --- /dev/null +++ b/src/save_location.c @@ -0,0 +1,145 @@ +#include "global.h" +#include "map_constants.h" + +// used to make the list defines a little less ugly. +#define MAP(name) ((MAP_GROUP_##name << 8) + (MAP_ID_##name)) + +// specialSaveWarp flags +#define POKECENTER_SAVEWARP (1 << 1) +#define LOBBY_SAVEWARP (1 << 2) +#define UNK_SPECIAL_SAVE_WARP_FLAG_3 (1 << 3) + +static bool32 IsCurMapInLocationList(const u16 *list) +{ + u16 locSum = (gSaveBlock1Ptr->location.mapGroup << 8) + (gSaveBlock1Ptr->location.mapNum); + + // im sure it was written a different way, but for the love of christ I cant figure out how to write it different where it still matches. + if (*list != 0xFFFF) + { + u16 termValue = 0xFFFF; + const u16 *localList; + for (localList = list; *localList != termValue; localList++) + if (*localList == locSum) + return TRUE; + } + return FALSE; +} + +// TODO: Not require a packed u16 array for these lists +static const u16 gSaveLocationPokeCenterList[] = +{ + MAP(OLDALE_TOWN_POKEMON_CENTER_1F), + MAP(OLDALE_TOWN_POKEMON_CENTER_2F), + MAP(DEWFORD_TOWN_POKEMON_CENTER_1F), + MAP(DEWFORD_TOWN_POKEMON_CENTER_2F), + MAP(LAVARIDGE_TOWN_POKEMON_CENTER_1F), + MAP(LAVARIDGE_TOWN_POKEMON_CENTER_2F), + MAP(FALLARBOR_TOWN_POKEMON_CENTER_1F), + MAP(FALLARBOR_TOWN_POKEMON_CENTER_2F), + MAP(VERDANTURF_TOWN_POKEMON_CENTER_1F), + MAP(VERDANTURF_TOWN_POKEMON_CENTER_2F), + MAP(PACIFIDLOG_TOWN_POKEMON_CENTER_1F), + MAP(PACIFIDLOG_TOWN_POKEMON_CENTER_2F), + MAP(PETALBURG_CITY_POKEMON_CENTER_1F), + MAP(PETALBURG_CITY_POKEMON_CENTER_2F), + MAP(SLATEPORT_CITY_POKEMON_CENTER_1F), + MAP(SLATEPORT_CITY_POKEMON_CENTER_2F), + MAP(MAUVILLE_CITY_POKEMON_CENTER_1F), + MAP(MAUVILLE_CITY_POKEMON_CENTER_2F), + MAP(RUSTBORO_CITY_POKEMON_CENTER_1F), + MAP(RUSTBORO_CITY_POKEMON_CENTER_2F), + MAP(FORTREE_CITY_POKEMON_CENTER_1F), + MAP(FORTREE_CITY_POKEMON_CENTER_2F), + MAP(LILYCOVE_CITY_POKEMON_CENTER_1F), + MAP(LILYCOVE_CITY_POKEMON_CENTER_2F), + MAP(MOSSDEEP_CITY_POKEMON_CENTER_1F), + MAP(MOSSDEEP_CITY_POKEMON_CENTER_2F), + MAP(SOOTOPOLIS_CITY_POKEMON_CENTER_1F), + MAP(SOOTOPOLIS_CITY_POKEMON_CENTER_2F), + MAP(EVER_GRANDE_CITY_POKEMON_CENTER_1F), + MAP(EVER_GRANDE_CITY_POKEMON_CENTER_2F), + MAP(EVER_GRANDE_CITY_POKEMON_LEAGUE_1F), + MAP(EVER_GRANDE_CITY_POKEMON_LEAGUE_2F), + MAP(BATTLE_FRONTIER_POKEMON_CENTER_1F), + MAP(BATTLE_FRONTIER_POKEMON_CENTER_2F), + MAP(SINGLE_BATTLE_COLOSSEUM), + MAP(TRADE_CENTER), + MAP(RECORD_CORNER), + MAP(DOUBLE_BATTLE_COLOSSEUM), + 0xFFFF, +}; + +static bool32 IsCurMapPokeCenter(void) +{ + return IsCurMapInLocationList(gSaveLocationPokeCenterList); +} + +static const u16 gSaveLocationReloadLocList[] = // there's only 1 location, and it's presumed its for the save reload feature for battle tower +{ + MAP(BATTLE_TOWER_LOBBY), + 0xFFFF, +}; + +static bool32 IsCurMapReloadLocation(void) +{ + return IsCurMapInLocationList(gSaveLocationReloadLocList); +} + +// nulled out list. unknown what this would have been +static const u16 gUnknown_0861440E[] = +{ + 0xFFFF, +}; + +bool32 sub_81AFCEC(void) +{ + return IsCurMapInLocationList(gUnknown_0861440E); +} + +static void TrySetPokeCenterWarpStatus(void) +{ + if (IsCurMapPokeCenter() == FALSE) + gSaveBlock2Ptr->specialSaveWarp &= ~(POKECENTER_SAVEWARP); + else + gSaveBlock2Ptr->specialSaveWarp |= POKECENTER_SAVEWARP; +} + +static void TrySetReloadWarpStatus(void) +{ + if (!IsCurMapReloadLocation()) + gSaveBlock2Ptr->specialSaveWarp &= ~(LOBBY_SAVEWARP); + else + gSaveBlock2Ptr->specialSaveWarp |= LOBBY_SAVEWARP; +} + +// this function definitely sets a warp status, but because the list is empty, it's unknown what this does yet. +static void sub_81AFD5C(void) +{ + if (!sub_81AFCEC()) + gSaveBlock2Ptr->specialSaveWarp &= ~(UNK_SPECIAL_SAVE_WARP_FLAG_3); + else + gSaveBlock2Ptr->specialSaveWarp |= UNK_SPECIAL_SAVE_WARP_FLAG_3; +} + +void TrySetMapSaveWarpStatus(void) +{ + TrySetPokeCenterWarpStatus(); + TrySetReloadWarpStatus(); + sub_81AFD5C(); +} + +void sub_81AFDA0(void) +{ + gSaveBlock2Ptr->field_A8 |= 0x8000; + gSaveBlock2Ptr->field_A8 |= 0x1; + gSaveBlock2Ptr->field_A8 |= 0x2; + gSaveBlock2Ptr->field_A8 |= 0x4; + gSaveBlock2Ptr->field_A8 |= 0x10; + gSaveBlock2Ptr->field_A8 |= 0x20; + gSaveBlock2Ptr->field_A8 |= 0x8; +} + +void sub_81AFDD0(void) +{ + gSaveBlock2Ptr->specialSaveWarp |= 0x80; +} diff --git a/sym_ewram.txt b/sym_ewram.txt index 0299dad2e..944a51b62 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -1610,9 +1610,7 @@ gUnknown_0203BCE8: @ 203BCE8 .space 0x4 .include "src/lottery_corner.o" - -gUnknown_0203BCF0: @ 203BCF0 - .space 0x4 + .include "src/diploma.o" gUnknown_0203BCF4: @ 203BCF4 .space 0x4