decompile diploma.c

This commit is contained in:
ProjectRevoTPP 2017-10-07 22:54:32 -04:00
parent 07e29b70bc
commit f0775000a1
11 changed files with 263 additions and 416 deletions

View File

@ -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.

View File

@ -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}

View File

@ -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

BIN
graphics/misc/diploma.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

19
graphics/misc/diploma_hoenn.pal Executable file
View File

@ -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

BIN
graphics/misc/diploma_map.bin Executable file

Binary file not shown.

View File

@ -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

View File

@ -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);

220
src/diploma.c Executable file
View File

@ -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);
}

View File

@ -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);

View File

@ -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