From f0775000a1cd87174e9b3a5a6a365e189309385e Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sat, 7 Oct 2017 22:54:32 -0400 Subject: [PATCH 1/3] decompile diploma.c --- asm/diploma.s | 387 ----------------------------- asm/rom6.s | 2 +- data/diploma.s | 22 -- graphics/misc/diploma.png | Bin 0 -> 2064 bytes graphics/misc/diploma_hoenn.pal | 19 ++ graphics/misc/diploma_map.bin | Bin 0 -> 4096 bytes graphics/misc/diploma_national.pal | 19 ++ ld_script.txt | 4 +- src/diploma.c | 220 ++++++++++++++++ src/save_failed_screen.c | 2 +- sym_ewram.txt | 4 +- 11 files changed, 263 insertions(+), 416 deletions(-) delete mode 100644 asm/diploma.s delete mode 100644 data/diploma.s create mode 100755 graphics/misc/diploma.png create mode 100755 graphics/misc/diploma_hoenn.pal create mode 100755 graphics/misc/diploma_map.bin create mode 100755 graphics/misc/diploma_national.pal create mode 100755 src/diploma.c diff --git a/asm/diploma.s b/asm/diploma.s deleted file mode 100644 index 4f21fe39d3..0000000000 --- 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/rom6.s b/asm/rom6.s index c53e6fe6e0..0a89608116 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/data/diploma.s b/data/diploma.s deleted file mode 100644 index 43a3d9c704..0000000000 --- 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/graphics/misc/diploma.png b/graphics/misc/diploma.png new file mode 100755 index 0000000000000000000000000000000000000000..d9607dce6f2f5a8d97bf9629fcd1ea0622099fa7 GIT binary patch literal 2064 zcmV+r2=DiaP)000M@ zNkl-{jP!iuJ zB!-;jB68f7Ld1`^m~qSlh+q~k7XWx>>g2p?3yN=(V}LVMnMHS^_KGK7eFBgq#O9g+ z(CY!mVhZgjib;G|KFj1Y?gA}}L;i_uZg{W8S4=`W|D$|(EhV6+1@r;b!SmY+K#FtpLS(o$q#99iW-#y2Q0c*2ugZS#B#KOx#N)0Q6T$lmJlgjld0fxe!eP zKvxG)1Vnia2sMC-k>rO8{qTzxj4X`XfJhMxOaL)2$t6D&(~19jIv^4rY%2g%sREe7 z24sWlXlO!I9nb9oA~96{l7LXTAXCRn5n&E-z^9Q0;5mpOdwdwZfCma-sa`Ng$^o;b zA5w_`ClqTl#Stz<$Q9K*f5SRp$MG z?!qz>nqknv+vipk@Um25%nx8!YpemDt3GzHBuv?yCYG7&X?bn-EzE51{g=7+JM&THr51x2n!kmIc;@1zU)L5CiW$ zJPr_WA1gAYy=rQJ)L=+@}*`FyVmCvql!u z00^Jc>J*zb^{&Q3L)(W2fcgPrX?+OGnpvaM$)wMRW+}%)`CfZD>(%C zu6Fd;L!DKKrVkoG?FeS9)A`i@`IWO%T|y6l`N6cYg9;W4ZmzIQZ@wxCan=CM_4={OC7eab_aqJ|(I!_*7ffCz#hE@Y$vKzV}A zG`)hE$@Z_P1KmmG)YJiXEN*j^ew@)MXr4|}7`nLFD;$q6*)ylEc>wqw{8E5ds4(=% uzfoiRIDp^n=mbw=2*A0IV?Xtk0P-KX_Kr4>ZYQn)0000bcD6o%g~Ie~?4+c(JxEU-Wnmnbe#T%x$7hD*ITNgHp{CTXPZ?(Xj1e~IQB zrjvWiSK6QWf$q*bbMKw|oM-p!+}prLHnEv?tPiA?BRG;Hb%fSxz19WNtWDae4T{U7 zhrR4$KRekK$XJf!c#hX`I##>1Gmw7m(_Za~@-1v-8>cgJ19Q5zX{)wG`F3`224{xo zIL1?$zyuYI*Eo&n;QBLlhIVLsl%L9JA(l*J5|gP+VT!6IYmz1^0~I2irc*&gDGL=K?O|qHFk5U7AaG87|Xhxh$XQGkm&F^Q*arYq^f=xq%zG zDc}$8EW$*W&^7#*tGPHA@5Cjz1TQ|`$N7jq z%`-g9b3D%ryvR$}^oQ3oaKD&KxRlGdoGZAJtFHLlU5ERp_ruRNa|^d}8@F=@cXAgy ze7hg`{##tDYx|c9lR1Tld4xxKjK_I`CwYpkz9q`{xL()i`dz2%3S<;Va}3AmXdR_p zzS9p*zwh(Cz9-5zxJK9Hnq8f%4`c!-auO%$M4h1ZzRnL$vv2Z^z9GsF?BU8VxW0J> z2whwsZ9>$|+nXKu&pOb6Ml_)rb*K-d79%hcBV~ltO1;zt(kxBVC=D{O=pOW<5B=yw zS0H0C4&yOi#>rUelFmT-rB8aLC(5^=6>XS~$PLWt(k89a66M>`ff<+?qT>(`K>`v) zBwpeqB7^JClo`???NNRzriEA{5lKjfA_Xa;k}OG*C=67HV46&g^4*vf;!}}^bYvhC zS;&%1$&hqOlhhDDOS)tDvyp>b><}N@Ux*?UqXeZWLz$FHi4;qb z6o&ZN{&G~H5>=>14QixXs-#jXq&&pO_LrLqQ)#M9wW%>Rw%S(NN?T#e?cfuLAhy5I z6q#aEVoFV!DYK=v#NL8iFaMZt!|fOXi=h~X;eq}yl7+HB=F2>pD|2MFz$ay&@XXT8XmWYWn@kUI7Nw8w$?JIZ{ui{5Fg=Ve1cE$89u+_Z#Nxgm+X`svR$^xR@ow(uj0SJm-q@_ z;~RX7@9;f-z>ny#?RMb%Z!xXrl$?|ka$JtdQ8^-qui__T3Vy=R_yxb>H~fx2@F!Yr zOO)?1y{6Cfn@-ae$S91)7>tq8GD^B^ryZPr+h==iPn2&kji$*on>te;$OKHpButWt dGC}HXogJKJ+hiMULzExb!_9HC1OL|!`~`@zlY9UG literal 0 HcmV?d00001 diff --git a/graphics/misc/diploma_national.pal b/graphics/misc/diploma_national.pal new file mode 100755 index 0000000000..03c37bf22f --- /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 de6ba62f15..39e5c5bc16 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); @@ -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); diff --git a/src/diploma.c b/src/diploma.c new file mode 100755 index 0000000000..765b018bc8 --- /dev/null +++ b/src/diploma.c @@ -0,0 +1,220 @@ +#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) +{ + void **mallocPtr; + + 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 7a7c30388d..3f49b89e6b 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/sym_ewram.txt b/sym_ewram.txt index b1572bf25a..166ea64d01 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -1629,9 +1629,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 From f775ccd571f82df745f608c23758185741867eab Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sat, 7 Oct 2017 22:58:21 -0400 Subject: [PATCH 2/3] forgot to remove unnecessary local ptr --- src/diploma.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/diploma.c b/src/diploma.c index 765b018bc8..f2cbcabb7b 100755 --- a/src/diploma.c +++ b/src/diploma.c @@ -53,8 +53,6 @@ static const u8 gDiplomaTiles[] = INCBIN_U8("graphics/misc/diploma.4bpp.lz"); void CB2_ShowDiploma(void) { - void **mallocPtr; - SetVBlankCallback(NULL); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0); SetGpuReg(REG_OFFSET_BG3CNT, DISPCNT_MODE_0); From a9d94cc5d62540f6f20b17280cb8f45adc5683b1 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sun, 8 Oct 2017 22:21:34 -0400 Subject: [PATCH 3/3] decompile save_location.c --- asm/rom4.s | 4 +- asm/save_location.s | 205 ------------------------------------------- data/save_location.s | 13 --- ld_script.txt | 4 +- src/save_location.c | 145 ++++++++++++++++++++++++++++++ 5 files changed, 149 insertions(+), 222 deletions(-) delete mode 100755 asm/save_location.s delete mode 100644 data/save_location.s create mode 100755 src/save_location.c diff --git a/asm/rom4.s b/asm/rom4.s index 8423d0d9a9..0a624620dd 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/save_location.s b/asm/save_location.s deleted file mode 100755 index 1a5b3c6da2..0000000000 --- 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/save_location.s b/data/save_location.s deleted file mode 100644 index eabed7d86a..0000000000 --- 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/ld_script.txt b/ld_script.txt index 39e5c5bc16..82588be3a9 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -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); @@ -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/save_location.c b/src/save_location.c new file mode 100755 index 0000000000..87067e14db --- /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; +}