From b2e8ee836d6334e525df3163d7b018b64f68ec95 Mon Sep 17 00:00:00 2001 From: Edouard Veyrier Date: Mon, 2 Apr 2018 20:06:40 +0200 Subject: [PATCH] sub_81607EC and sub_816082C --- asm/learn_move.s | 4 ++ include/learn_move.h | 9 +++- ld_script.txt | 1 + src/learn_move.c | 100 ++++++++++++++++++++++++++++++++----------- sym_ewram.txt | 11 ++--- 5 files changed, 90 insertions(+), 35 deletions(-) diff --git a/asm/learn_move.s b/asm/learn_move.s index 5fd507c2d9..4f0a6abb4b 100644 --- a/asm/learn_move.s +++ b/asm/learn_move.s @@ -178,6 +178,7 @@ sub_8160740: @ 8160740 .pool thumb_func_end sub_8160740 +/* thumb_func_start sub_81607EC sub_81607EC: @ 81607EC push {lr} @@ -204,7 +205,9 @@ sub_81607EC: @ 81607EC bx r0 .pool thumb_func_end sub_81607EC +*/ +/* thumb_func_start sub_816082C sub_816082C: @ 816082C push {lr} @@ -217,6 +220,7 @@ sub_816082C: @ 816082C pop {r0} bx r0 thumb_func_end sub_816082C +*/ thumb_func_start sub_816084C sub_816084C: @ 816084C diff --git a/include/learn_move.h b/include/learn_move.h index 7779e85a0f..6ab2ba6f48 100644 --- a/include/learn_move.h +++ b/include/learn_move.h @@ -1,6 +1,7 @@ #ifndef GUARD_LEARN_MOVE_H #define GUARD_LEARN_MOVE_H +//this struct is probably wrong struct LearnMoveStruct { u8 state; @@ -26,7 +27,9 @@ struct LearnMoveStruct u8 unk2C6; }; -struct LearnMoveStruct *gUnknown_0203BC34 = NULL; +//struct LearnMoveStruct *gUnknown_0203BC34 = NULL; + +//extern u8 *gUnknown_0203BC34; void sub_8160624(void); void sub_8160638(void); @@ -37,6 +40,8 @@ void sub_8160638(void); //const struct SpritePalette gUnknown_085CEBB8 = {gDexArrows_Pal, 5526}; //const struct SpriteSheet gUnknown_085CEBB0 = {gDexArrows_Gfx, sizeof(gDexArrows_Gfx), 5525}; -u8 *gUnknown_0203BC38 = (void*)0x0203BC38; +//u8 *gUnknown_0203BC38 = (void*)0x0203BC38; +//extern u8 gUnknown_0203BC38[8]; +//u8 gUnknown_0203BC38; #endif //GUARD_LEARN_MOVE_H diff --git a/ld_script.txt b/ld_script.txt index 464dc78413..ac1c80c22f 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -490,6 +490,7 @@ SECTIONS { src/battle_controller_safari.o(.rodata); data/battle_anim_815A0D4.o(.rodata); data/learn_move.o(.rodata); + src/learn_move.o(.rodata); src/roamer.o(.rodata); data/battle_tower.o(.rodata); src/use_pokeblock.o(.rodata); diff --git a/src/learn_move.c b/src/learn_move.c index faa73a2d0b..0f5063faeb 100644 --- a/src/learn_move.c +++ b/src/learn_move.c @@ -5,20 +5,34 @@ #include "sprite.h" #include "palette.h" #include "menu.h" +#include "menu_helpers.h" #include "list_menu.h" #include "malloc.h" #include "field_screen.h" #include "event_data.h" +#include "bg.h" +#include "gpu_regs.h" #include "learn_move.h" -extern void (*gFieldCallback)(void); -extern struct LearnMoveStruct *gUnknown_0203BC34; +EWRAM_DATA u8 *gUnknown_0203BC34 = 0; +EWRAM_DATA u8 gUnknown_0203BC38[8] = {0}; + +extern void (*gFieldCallback)(void); +extern const struct SpritePalette gUnknown_085CEBB8; +extern const struct SpriteSheet gUnknown_085CEBB0; +extern const struct BgTemplate gUnknown_085CEC28; +extern void sub_81D2824(u16); +//extern struct LearnMoveStruct *gUnknown_0203BC34; + +//static struct LearnMoveStruct *sLearnMoveStruct; -static struct LearnMoveStruct *sLearnMoveStruct; static void sub_8160664(u8 taskId); void sub_81606A0(void); //CB2_InitLearnMove void sub_8160740(void); +void sub_81607EC(void); +void sub_816082C(void); + void sub_8160624(void) //VBlankCB_LearnMove { LoadOam(); @@ -45,12 +59,9 @@ void sub_8160664(u8 taskId) // void sub_81606A0(void) //CB2_InitLearnMove // { -// //FIXME -// void (*sub_81607EC)(void) = (void*)0x081607EC; -// void (*sub_81D2824)(u16) = (void*)0x081D2824; -// void (*sub_81610B8)(void) = (void*)0x081610B8; -// void (*sub_8161280)(void) = (void*)0x08161280; -// +// //AGBPrint("test\n"); +// //AGBPrintFlush(); +// //NoCashGBAPrint("test\n"); // //Less calls than pokeruby, is it normal ? // ResetSpriteData(); // FreeAllSpritePalettes(); @@ -58,34 +69,46 @@ void sub_8160664(u8 taskId) // clear_scheduled_bg_copies_to_vram(); // // //LearnMoveStruct** -// //r1 = &gSpecialVar_0x8004; //What is this global ? -// //u8* partyMon = gUnknown_0203BC34 + 0x44 //partyMon ? -// //*partyMon = r1; // gUnknown_0203BC34 = AllocZeroed(0x118);//gUnknown_0203BC34 is a global pointer to LearnMoveStruct ? -// gUnknown_0203BC34->partyMon = gSpecialVar_0x8004; +// //gUnknown_0203BC34->movesToLearn[0] = gSpecialVar_0x8004; +// ((u8*)gUnknown_0203BC34)[68] = gSpecialVar_0x8004; // // SetVBlankCallback(sub_8160624); +// //SetVBlankCallback(/*FIXME sub_8160624*/ (void()(u16))0x081D2824); // sub_81607EC(); // sub_81D2824(0); // // //gUnknown_0203BC38 ? +// // weird instruction // (gUnknown_0203BC38)[0] = 0; // (gUnknown_0203BC38)[2] = 0; // (gUnknown_0203BC38)[4] = 0; // -// sub_8161280(); -// LoadSpriteSheet(/*FIXME &gUnknown_085CEBB0*/(void*)0x085CEBB0); -// LoadSpritePalette(/*FIXME &gUnknown_085CEBB8*/(void*)0x085CEBB8); -// sub_81610B8(); +// //FIXME +// //sub_8161280(); +// __asm__("bl sub_8161280"); // -// ListMenuInit(&gMultiuseListMenuTemplate, 0, 0); +// //LoadSpriteSheet(/*FIXME &gUnknown_085CEBB0*/(void*)0x085CEBB0); +// //LoadSpritePalette(/*FIXME &gUnknown_085CEBB8*/(void*)0x085CEBB8); +// LoadSpriteSheet(&gUnknown_085CEBB0); +// LoadSpritePalette(&gUnknown_085CEBB8); +// //sub_81610B8(); +// //FIXME +// __asm__("bl sub_81610B8"); +// +// ((u8*)gUnknown_0203BC34)[274] = ListMenuInit(&gMultiuseListMenuTemplate, gUnknown_0203BC38[0], gUnknown_0203BC38[2]); // FillPalette(0, 0, 2); -// SetMainCallback2(/*FIXME sub_816082C*/(void*)0x0816082C); +// //SetMainCallback2(sub_816082C/*(void*)0x0816082C()*/); +// //SetMainCallback2(sub_816082C/*(void*)0x0816082C()*/); +// //FIXME +// __asm__( +// "ldr r0, =sub_816082C", +// "bl SetMainCallback2" +// ); // } -// + // void sub_8160740(void) // { -// void (*sub_81607EC)(void) = (void*)0x081607EC; // void (*sub_81D2824)(u16) = (void*)0x081D2824; // void (*sub_81610B8)(void) = (void*)0x081610B8; // void (*sub_8161280)(void) = (void*)0x08161280; @@ -105,15 +128,42 @@ void sub_8160664(u8 taskId) // sub_81607EC(); // // //gUnknown_0203BC38 ? -// sub_81D2824(*((u8*)&gUnknown_0203BC38 + 4)); +// sub_81D2824(gUnknown_0203BC38[4]); // sub_8161280(); // -// LoadSpriteSheet(/*FIXME &gUnknown_085CEBB0*/(void*)0x085CEBB0); -// LoadSpritePalette(/*FIXME &gUnknown_085CEBB8*/(void*)0x085CEBB8); +// LoadSpriteSheet(&gUnknown_085CEBB0); +// LoadSpritePalette(&gUnknown_085CEBB8); +// //LoadSpriteSheet(/*FIXME &gUnknown_085CEBB0*/(void*)0x085CEBB0); +// //LoadSpritePalette(/*FIXME &gUnknown_085CEBB8*/(void*)0x085CEBB8); // // data = ListMenuInit(&gMultiuseListMenuTemplate, *gUnknown_0203BC38, *((u8*)gUnknown_0203BC38 + 2)); // *(u8*)(gUnknown_0203BC34 + 274) = data; // FillPalette(0, 0, 2); // SetMainCallback2(/*FIXME sub_816082C*/(void*)0x0816082C); // } -// */ + +void sub_81607EC(void) +{ + ResetVramOamAndBgCntRegs(); + ResetBgsAndClearDma3BusyFlags(0); + InitBgsFromTemplates(0, &gUnknown_085CEC28, 2); + ResetAllBgsCoordinates(); + SetGpuReg(0, 0x1040); + ShowBg(0); + ShowBg(1); + SetGpuReg(0x50, 0); +} +void sub_816082C(void) +{ + //FIXME + //sub_8160868(); + //void(*sub_8160868)(void) = (void (*)(void))0x08160868; + //sub_8160868(); + __asm__("bl sub_8160868"); + RunTasks(); + AnimateSprites(); + BuildOamBuffer(); + do_scheduled_bg_tilemap_copies_to_vram(); + UpdatePaletteFade(); + +} diff --git a/sym_ewram.txt b/sym_ewram.txt index 96862ccd55..b88df9b0f7 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -784,19 +784,14 @@ gUnknown_0203ABB8: @ 203ABB8 .space 0x4 .include "src/save.o" - + .space 0x4 /*unused var?*/ .include "src/mystery_event_script.o" -gUnknown_0203BC34: @ 203BC34 - .space 0x4 - -gUnknown_0203BC38: @ 203BC38 - .space 0x8 - + .include "src/learn_move.o" .include "src/decoration_inventory.o" - .include "src/roamer.o" + .include "src/roamer.o" gUnknown_0203BC88: @ 203BC88 .space 0x4