diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/battle_transition.c | 4 | ||||
-rw-r--r-- | src/berry_fix_program.c | 2 | ||||
-rw-r--r--[-rwxr-xr-x] | src/braille_puzzles.c | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | src/clear_save_data_screen.c | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | src/diploma.c | 2 | ||||
-rw-r--r-- | src/egg_hatch.c | 4 | ||||
-rw-r--r-- | src/evolution_scene.c | 2 | ||||
-rw-r--r--[-rwxr-xr-x] | src/field_map_obj.c | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | src/field_special_scene.c | 0 | ||||
-rw-r--r-- | src/hall_of_fame.c | 2 | ||||
-rw-r--r-- | src/hof_pc.c | 46 | ||||
-rw-r--r--[-rwxr-xr-x] | src/libisagbprn.c | 0 | ||||
-rw-r--r-- | src/link.c | 2 | ||||
-rw-r--r-- | src/mail.c | 26 | ||||
-rw-r--r-- | src/main.c | 4 | ||||
-rw-r--r-- | src/mystery_event_msg.c | 13 | ||||
-rw-r--r-- | src/mystery_event_script.c | 396 | ||||
-rw-r--r-- | src/option_menu.c | 662 | ||||
-rw-r--r-- | src/pokeblock.c | 2 | ||||
-rw-r--r--[-rwxr-xr-x] | src/pokemon_summary_screen.c | 4 | ||||
-rw-r--r--[-rwxr-xr-x] | src/save_failed_screen.c | 3 | ||||
-rw-r--r--[-rwxr-xr-x] | src/save_location.c | 0 | ||||
-rw-r--r-- | src/starter_choose.c | 4 | ||||
-rw-r--r-- | src/text_window.c | 114 | ||||
-rw-r--r-- | src/wallclock.c | 2 |
25 files changed, 1232 insertions, 62 deletions
diff --git a/src/battle_transition.c b/src/battle_transition.c index ca2134837..e003e0fce 100644 --- a/src/battle_transition.c +++ b/src/battle_transition.c @@ -2730,6 +2730,10 @@ static bool8 Phase2_ShredSplit_Func2(struct Task *task) return FALSE; } +// This function never increments the state counter, because the loop condition +// is always false, resulting in the game being stuck in an infinite loop. +// It's possible this transition is only partially +// done and the second part was left out. static bool8 Phase2_ShredSplit_Func3(struct Task *task) { u16 i; diff --git a/src/berry_fix_program.c b/src/berry_fix_program.c index f233dc645..8a9b0caed 100644 --- a/src/berry_fix_program.c +++ b/src/berry_fix_program.c @@ -141,7 +141,7 @@ void InitBerryFixProgram(void) SetVBlankCallback(NULL); ResetSpriteData(); ResetTasks(); - remove_some_task(); + ScanlineEffect_Stop(); SetGpuReg(REG_OFFSET_DISPCNT, 0x0000); berry_fix_mb_manager = AllocZeroed(0x50); berry_fix_mb_manager->state = 0; diff --git a/src/braille_puzzles.c b/src/braille_puzzles.c index 55e75bfbf..55e75bfbf 100755..100644 --- a/src/braille_puzzles.c +++ b/src/braille_puzzles.c diff --git a/src/clear_save_data_screen.c b/src/clear_save_data_screen.c index 6d6a1545b..6d6a1545b 100755..100644 --- a/src/clear_save_data_screen.c +++ b/src/clear_save_data_screen.c diff --git a/src/diploma.c b/src/diploma.c index d4a269757..fedc10bd0 100755..100644 --- a/src/diploma.c +++ b/src/diploma.c @@ -72,7 +72,7 @@ void CB2_ShowDiploma(void) DmaFill16(3, 0, VRAM, VRAM_SIZE); DmaFill32(3, 0, OAM, OAM_SIZE); DmaFill16(3, 0, PLTT, PLTT_SIZE); - remove_some_task(); + ScanlineEffect_Stop(); ResetTasks(); ResetSpriteData(); ResetPaletteFade(); diff --git a/src/egg_hatch.c b/src/egg_hatch.c index ed1e7f4cc..b3cd88585 100644 --- a/src/egg_hatch.c +++ b/src/egg_hatch.c @@ -63,7 +63,7 @@ extern void sub_806A068(u16, u8); extern void fade_screen(u8, u8); extern void overworld_free_bg_tilemaps(void); extern void sub_80AF168(void); -extern void remove_some_task(void); +extern void ScanlineEffect_Stop(void); extern void c2_exit_to_overworld_2_switch(void); extern void play_some_sound(void); extern void DoNamingScreen(u8, const u8*, u16, u8, u32, MainCallback); @@ -506,7 +506,7 @@ static void CB2_EggHatch_0(void) FreeAllSpritePalettes(); ResetSpriteData(); ResetTasks(); - remove_some_task(); + ScanlineEffect_Stop(); m4aSoundVSyncOn(); gMain.state++; break; diff --git a/src/evolution_scene.c b/src/evolution_scene.c index 536eb6979..2ce788f8e 100644 --- a/src/evolution_scene.c +++ b/src/evolution_scene.c @@ -266,7 +266,7 @@ void EvolutionScene(struct Pokemon* mon, u16 speciesToEvolve, bool8 canStopEvo, sub_80356D0(); LoadBattleTextboxAndBackground(); ResetSpriteData(); - remove_some_task(); + ScanlineEffect_Stop(); ResetTasks(); FreeAllSpritePalettes(); diff --git a/src/field_map_obj.c b/src/field_map_obj.c index df80494b3..df80494b3 100755..100644 --- a/src/field_map_obj.c +++ b/src/field_map_obj.c diff --git a/src/field_special_scene.c b/src/field_special_scene.c index a704beaab..a704beaab 100755..100644 --- a/src/field_special_scene.c +++ b/src/field_special_scene.c diff --git a/src/hall_of_fame.c b/src/hall_of_fame.c index 4465f65a3..3e70e22fa 100644 --- a/src/hall_of_fame.c +++ b/src/hall_of_fame.c @@ -1302,7 +1302,7 @@ static void ClearVramOamPltt_LoadHofPal(void) static void sub_8174F70(void) { - remove_some_task(); + ScanlineEffect_Stop(); ResetTasks(); ResetSpriteData(); reset_temp_tile_data_buffers(); diff --git a/src/hof_pc.c b/src/hof_pc.c new file mode 100644 index 000000000..e772f04e8 --- /dev/null +++ b/src/hof_pc.c @@ -0,0 +1,46 @@ +#include "global.h" +#include "hall_of_fame.h" +#include "main.h" +#include "palette.h" +#include "overworld.h" +#include "script.h" +#include "script_menu.h" +#include "task.h" + +extern void (*gFieldCallback)(void); +extern void (*gUnknown_0300485C)(void); + +extern void Overworld_PlaySpecialMapMusic(void); +extern bool16 ScrSpecial_CreatePCMenu(void); +extern void ScriptMenu_DisplayPCStartupPrompt(void); + +static void ReshowPCMenuAfterHallOfFamePC(void); +static void Task_WaitForPaletteFade(u8); + +void AccessHallOfFamePC(void) +{ + SetMainCallback2(CB2_DoHallOfFamePC); + ScriptContext2_Enable(); +} + +void ReturnFromHallOfFamePC(void) +{ + SetMainCallback2(c2_exit_to_overworld_2_switch); + gFieldCallback = ReshowPCMenuAfterHallOfFamePC; +} + +static void ReshowPCMenuAfterHallOfFamePC(void) +{ + ScriptContext2_Enable(); + Overworld_PlaySpecialMapMusic(); + ScrSpecial_CreatePCMenu(); + ScriptMenu_DisplayPCStartupPrompt(); + BeginNormalPaletteFade(0xFFFFFFFF, 0, 0x10, 0, 0); + CreateTask(Task_WaitForPaletteFade, 10); +} + +static void Task_WaitForPaletteFade(u8 taskId) +{ + if (!gPaletteFade.active) + DestroyTask(taskId); +} diff --git a/src/libisagbprn.c b/src/libisagbprn.c index e0e979e95..e0e979e95 100755..100644 --- a/src/libisagbprn.c +++ b/src/libisagbprn.c diff --git a/src/link.c b/src/link.c index 65c5d3982..5a47e2fac 100644 --- a/src/link.c +++ b/src/link.c @@ -1637,7 +1637,7 @@ void CB2_LinkError(void) ResetPaletteFadeControl(); FillPalette(0, 0, 2); ResetTasks(); - remove_some_task(); + ScanlineEffect_Stop(); if (gWirelessCommType) { if (!sLinkErrorBuffer.unk_06) diff --git a/src/mail.c b/src/mail.c index 68a55e242..c3cbe4a3c 100644 --- a/src/mail.c +++ b/src/mail.c @@ -240,30 +240,6 @@ static const struct MailLayout sUnknown_0859F458[] = { { 0x05, 0x09, 0x60, 0x05, 0x1e, Unknown_0859F444 } }; -// What the heck are these meant to be? Call them u16 for now. - -static const u16 Unknown_0859F4E8[] = { - 0x00, 0x4000, 0x00, 0x00 -}; - -static const u16 Unknown_0859F4F0[] = { - 0x00, 0x00, -1, 0x00 -}; - -static const u16 Unknown_0859F4F8[] = { - 0x04, 0x00, -1, 0x00 -}; - -static const u16 Unknown_0859F500[] = { - 0x00, 0x40, -1, 0x00 -}; - -static const u16 *const sUnknown_0859F508[] = { - Unknown_0859F4F0, - Unknown_0859F4F8, - Unknown_0859F500 -}; - // .text void ReadMail(struct MailStruct *mail, void (*callback)(void), bool8 flag) @@ -329,7 +305,7 @@ static bool8 MailReadBuildGraphics(void) { case 0: SetVBlankCallback(NULL); - remove_some_task(); + ScanlineEffect_Stop(); SetGpuReg(REG_OFFSET_DISPCNT, 0x0000); break; case 1: diff --git a/src/main.c b/src/main.c index 822aeda21..9f3a815b0 100644 --- a/src/main.c +++ b/src/main.c @@ -23,6 +23,8 @@ #include "intro.h" #include "main.h" +extern void sub_800B9B8(void); +extern u8 gUnknown_03002748; extern u32 *gUnknown_0203CF5C; static void VBlankIntr(void); @@ -405,7 +407,7 @@ void DoSoftReset(void) { REG_IME = 0; m4aSoundVSyncOff(); - remove_some_task(); + ScanlineEffect_Stop(); DmaStop(1); DmaStop(2); DmaStop(3); diff --git a/src/mystery_event_msg.c b/src/mystery_event_msg.c new file mode 100644 index 000000000..74261179b --- /dev/null +++ b/src/mystery_event_msg.c @@ -0,0 +1,13 @@ +#include "global.h" + +const u8 gText_MysteryGiftBerry[] = _("Obtained a {STR_VAR_2} BERRY!\nDad has it at PETALBURG GYM."); +const u8 gText_MysteryGiftBerryTransform[] = _("The {STR_VAR_1} BERRY transformed into\none {STR_VAR_2} BERRY."); +const u8 gText_MysteryGiftBerryObtained[] = _("The {STR_VAR_1} BERRY has already been\nobtained."); +const u8 gText_MysteryGiftSpecialRibbon[] = _("A special RIBBON was awarded to\nyour party POKéMON."); +const u8 gText_MysteryGiftNationalDex[] = _("The POKéDEX has been upgraded\nwith the NATIONAL MODE."); +const u8 gText_MysteryGiftRareWord[] = _("A rare word has been added."); +const u8 gText_MysteryGiftSentOver[] = _("{STR_VAR_1} was sent over!"); +const u8 gText_MysteryGiftFullParty[] = _("Your party is full.\n{STR_VAR_1} could not be sent over."); +const u8 gText_MysteryGiftNewTrainer[] = _("A new TRAINER has arrived in\nHOENN."); +const u8 gText_MysteryGiftNewAdversaryInBattleTower[] = _("A new adversary has arrived in the\nBATTLE TOWER."); +const u8 gText_MysteryGiftCantBeUsed[] = _("This data can’t be used in\nthis version."); diff --git a/src/mystery_event_script.c b/src/mystery_event_script.c new file mode 100644 index 000000000..8822cd05a --- /dev/null +++ b/src/mystery_event_script.c @@ -0,0 +1,396 @@ +#include "global.h" +#include "berry.h" +#include "battle_tower.h" +#include "easy_chat.h" +#include "event_data.h" +#include "mail.h" +#include "mystery_event_script.h" +#include "pokedex.h" +#include "pokemon.h" +#include "pokemon_size_record.h" +#include "script.h" +#include "constants/species.h" +#include "strings.h" +#include "string_util.h" +#include "text.h" +#include "util.h" +#include "mystery_event_msg.h" +#include "pokemon_storage_system.h" + +extern void sub_811EFC0(u8); +extern void ValidateEReaderTrainer(void); + +extern ScrCmdFunc gMysteryEventScriptCmdTable[]; +extern ScrCmdFunc gMysteryEventScriptCmdTableEnd[]; + +#define LANGUAGE_MASK 0x1 +#define VERSION_MASK 0x200 + +EWRAM_DATA static struct ScriptContext sMysteryEventScriptContext = {0}; + +static bool32 CheckCompatibility(u16 a1, u32 a2, u16 a3, u32 a4) +{ + if (!(a1 & LANGUAGE_MASK)) + return FALSE; + + if (!(a2 & LANGUAGE_MASK)) + return FALSE; + + if (!(a3 & 0x4)) + return FALSE; + + if (!(a4 & VERSION_MASK)) + return FALSE; + + return TRUE; +} + +static void SetIncompatible(void) +{ + StringExpandPlaceholders(gStringVar4, gText_MysteryGiftCantBeUsed); + SetMysteryEventScriptStatus(3); +} + +static void InitMysteryEventScript(struct ScriptContext *ctx, u8 *script) +{ + InitScriptContext(ctx, gMysteryEventScriptCmdTable, gMysteryEventScriptCmdTableEnd); + SetupBytecodeScript(ctx, script); + ctx->data[0] = (u32)script; + ctx->data[1] = 0; + ctx->data[2] = 0; + ctx->data[3] = 0; +} + +static bool32 RunMysteryEventScriptCommand(struct ScriptContext *ctx) +{ + if (RunScriptCommand(ctx) && ctx->data[3]) + return TRUE; + else + return FALSE; +} + +void sub_8153870(u8 *script) +{ + InitMysteryEventScript(&sMysteryEventScriptContext, script); +} + +bool32 sub_8153884(u32 *a0) +{ + bool32 ret = RunMysteryEventScriptCommand(&sMysteryEventScriptContext); + *a0 = sMysteryEventScriptContext.data[2]; + + return ret; +} + +u32 RunMysteryEventScript(u8 *script) +{ + struct ScriptContext *ctx = &sMysteryEventScriptContext; + InitMysteryEventScript(ctx, script); + while (RunMysteryEventScriptCommand(ctx)); + + return ctx->data[2]; +} + +void SetMysteryEventScriptStatus(u32 val) +{ + sMysteryEventScriptContext.data[2] = val; +} + +static int CalcRecordMixingGiftChecksum(void) +{ + unsigned int i; + int sum = 0; + u8 *data = (u8*)(&gSaveBlock1Ptr->recordMixingGift.data); + + for (i = 0; i < sizeof(gSaveBlock1Ptr->recordMixingGift.data); i++) + sum += data[i]; + + return sum; +} + +static bool32 IsRecordMixingGiftValid(void) +{ + struct RecordMixingGiftData *data = &gSaveBlock1Ptr->recordMixingGift.data; + int checksum = CalcRecordMixingGiftChecksum(); + + if (data->unk0 == 0 + || data->quantity == 0 + || data->itemId == 0 + || checksum == 0 + || checksum != gSaveBlock1Ptr->recordMixingGift.checksum) + return FALSE; + else + return TRUE; +} + +static void ClearRecordMixingGift(void) +{ + CpuFill16(0, &gSaveBlock1Ptr->recordMixingGift, sizeof(gSaveBlock1Ptr->recordMixingGift)); +} + +static void SetRecordMixingGift(u8 unk, u8 quantity, u16 itemId) +{ + if (!unk || !quantity || !itemId) + { + ClearRecordMixingGift(); + } + else + { + gSaveBlock1Ptr->recordMixingGift.data.unk0 = unk; + gSaveBlock1Ptr->recordMixingGift.data.quantity = quantity; + gSaveBlock1Ptr->recordMixingGift.data.itemId = itemId; + gSaveBlock1Ptr->recordMixingGift.checksum = CalcRecordMixingGiftChecksum(); + } +} + +u16 GetRecordMixingGift(void) +{ + struct RecordMixingGiftData *data = &gSaveBlock1Ptr->recordMixingGift.data; + + if (!IsRecordMixingGiftValid()) + { + ClearRecordMixingGift(); + return 0; + } + else + { + u16 itemId = data->itemId; + data->quantity--; + if (data->quantity == 0) + ClearRecordMixingGift(); + else + gSaveBlock1Ptr->recordMixingGift.checksum = CalcRecordMixingGiftChecksum(); + + return itemId; + } +} + +bool8 MEScrCmd_end(struct ScriptContext *ctx) +{ + StopScript(ctx); + return TRUE; +} + +bool8 MEScrCmd_checkcompat(struct ScriptContext *ctx) +{ + u16 v1; + u32 v2; + u16 v3; + u32 v4; + + ctx->data[1] = ScriptReadWord(ctx); + v1 = ScriptReadHalfword(ctx); + v2 = ScriptReadWord(ctx); + v3 = ScriptReadHalfword(ctx); + v4 = ScriptReadWord(ctx); + + if (CheckCompatibility(v1, v2, v3, v4) == TRUE) + ctx->data[3] = 1; + else + SetIncompatible(); + + return TRUE; +} + +bool8 MEScrCmd_nop(struct ScriptContext *ctx) +{ + return FALSE; +} + +bool8 MEScrCmd_setstatus(struct ScriptContext *ctx) +{ + u8 value = ScriptReadByte(ctx); + ctx->data[2] = value; + return FALSE; +} + +bool8 MEScrCmd_setmsg(struct ScriptContext *ctx) +{ + u8 value = ScriptReadByte(ctx); + u8 *str = (u8 *)(ScriptReadWord(ctx) - ctx->data[1] + ctx->data[0]); + if (value == 0xFF || value == ctx->data[2]) + StringExpandPlaceholders(gStringVar4, str); + return FALSE; +} + +bool8 MEScrCmd_runscript(struct ScriptContext *ctx) +{ + u8 *script = (u8 *)(ScriptReadWord(ctx) - ctx->data[1] + ctx->data[0]); + ScriptContext2_RunNewScript(script); + return FALSE; +} + +bool8 MEScrCmd_setenigmaberry(struct ScriptContext *ctx) +{ + u8 *str; + const u8 *message; + bool32 haveBerry = IsEnigmaBerryValid(); + u8 *berry = (u8 *)(ScriptReadWord(ctx) - ctx->data[1] + ctx->data[0]); + StringCopyN(gStringVar1, gSaveBlock1Ptr->enigmaBerry.berry.name, BERRY_NAME_COUNT); + SetEnigmaBerry(berry); + StringCopyN(gStringVar2, gSaveBlock1Ptr->enigmaBerry.berry.name, BERRY_NAME_COUNT); + + if (!haveBerry) + { + str = gStringVar4; + message = gText_MysteryGiftBerry; + } + else if (StringCompare(gStringVar1, gStringVar2)) + { + str = gStringVar4; + message = gText_MysteryGiftBerryTransform; + } + else + { + str = gStringVar4; + message = gText_MysteryGiftBerryObtained; + } + + StringExpandPlaceholders(str, message); + + ctx->data[2] = 2; + + if (IsEnigmaBerryValid() == TRUE) + VarSet(VAR_ENIGMA_BERRY_AVAILABLE, 1); + else + ctx->data[2] = 1; + + return FALSE; +} + +bool8 MEScrCmd_giveribbon(struct ScriptContext *ctx) +{ + u8 index = ScriptReadByte(ctx); + u8 ribbonId = ScriptReadByte(ctx); + GiveGiftRibbonToParty(index, ribbonId); + StringExpandPlaceholders(gStringVar4, gText_MysteryGiftSpecialRibbon); + ctx->data[2] = 2; + return FALSE; +} + +bool8 MEScrCmd_initramscript(struct ScriptContext *ctx) +{ + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + u8 objectId = ScriptReadByte(ctx); + u8 *script = (u8 *)(ScriptReadWord(ctx) - ctx->data[1] + ctx->data[0]); + u8 *scriptEnd = (u8 *)(ScriptReadWord(ctx) - ctx->data[1] + ctx->data[0]); + InitRamScript(script, scriptEnd - script, mapGroup, mapNum, objectId); + return FALSE; +} + +bool8 MEScrCmd_givenationaldex(struct ScriptContext *ctx) +{ + EnableNationalPokedex(); + StringExpandPlaceholders(gStringVar4, gText_MysteryGiftNationalDex); + ctx->data[2] = 2; + return FALSE; +} + +bool8 MEScrCmd_addrareword(struct ScriptContext *ctx) +{ + sub_811EFC0(ScriptReadByte(ctx)); + StringExpandPlaceholders(gStringVar4, gText_MysteryGiftRareWord); + ctx->data[2] = 2; + return FALSE; +} + +bool8 MEScrCmd_setrecordmixinggift(struct ScriptContext *ctx) +{ + u8 unk = ScriptReadByte(ctx); + u8 quantity = ScriptReadByte(ctx); + u16 itemId = ScriptReadHalfword(ctx); + SetRecordMixingGift(unk, quantity, itemId); + return FALSE; +} + +bool8 MEScrCmd_givepokemon(struct ScriptContext *ctx) +{ + struct MailStruct mail; + struct Pokemon pokemon; + u16 species; + u16 heldItem; + u32 data = ScriptReadWord(ctx) - ctx->data[1] + ctx->data[0]; + void *pokemonPtr = (void *)data; + void *mailPtr = (void *)(data + sizeof(struct Pokemon)); + + pokemon = *(struct Pokemon *)pokemonPtr; + species = GetMonData(&pokemon, MON_DATA_SPECIES2); + + if (species == SPECIES_EGG) + StringCopyN(gStringVar1, gText_EggNickname, POKEMON_NAME_LENGTH + 1); + else + StringCopyN(gStringVar1, gText_Pokemon, POKEMON_NAME_LENGTH + 1); + + if (gPlayerPartyCount == PARTY_SIZE) + { + StringExpandPlaceholders(gStringVar4, gText_MysteryGiftFullParty); + ctx->data[2] = 3; + } + else + { + memcpy(&gPlayerParty[5], pokemonPtr, sizeof(struct Pokemon)); + memcpy(&mail, mailPtr, sizeof(struct MailStruct)); + + if (species != SPECIES_EGG) + { + u16 pokedexNum = SpeciesToNationalPokedexNum(species); + GetSetPokedexFlag(pokedexNum, FLAG_SET_SEEN); + GetSetPokedexFlag(pokedexNum, FLAG_SET_CAUGHT); + } + + heldItem = GetMonData(&gPlayerParty[5], MON_DATA_HELD_ITEM); + if (ItemIsMail(heldItem)) + GiveMailToMon2(&gPlayerParty[5], &mail); + CompactPartySlots(); + CalculatePlayerPartyCount(); + StringExpandPlaceholders(gStringVar4, gText_MysteryGiftSentOver); + ctx->data[2] = 2; + } + + return FALSE; +} + +bool8 MEScrCmd_addtrainer(struct ScriptContext *ctx) +{ + u32 data = ScriptReadWord(ctx) - ctx->data[1] + ctx->data[0]; + memcpy((void*)(gSaveBlock2Ptr) + 0xBEC, (void *)data, 0xBC); + ValidateEReaderTrainer(); + StringExpandPlaceholders(gStringVar4, gText_MysteryGiftNewTrainer); + ctx->data[2] = 2; + return FALSE; +} + +bool8 MEScrCmd_enableresetrtc(struct ScriptContext *ctx) +{ + EnableResetRTC(); + StringExpandPlaceholders(gStringVar4, gText_InGameClockUsable); + ctx->data[2] = 2; + return FALSE; +} + +bool8 MEScrCmd_checksum(struct ScriptContext *ctx) +{ + int checksum = ScriptReadWord(ctx); + u8 *data = (u8 *)(ScriptReadWord(ctx) - ctx->data[1] + ctx->data[0]); + u8 *dataEnd = (u8 *)(ScriptReadWord(ctx) - ctx->data[1] + ctx->data[0]); + if (checksum != CalcByteArraySum(data, dataEnd - data)) + { + ctx->data[3] = 0; + ctx->data[2] = 1; + } + return TRUE; +} + +bool8 MEScrCmd_crc(struct ScriptContext *ctx) +{ + int crc = ScriptReadWord(ctx); + u8 *data = (u8 *)(ScriptReadWord(ctx) - ctx->data[1] + ctx->data[0]); + u8 *dataEnd = (u8 *)(ScriptReadWord(ctx) - ctx->data[1] + ctx->data[0]); + if (crc != CalcCRC16(data, dataEnd - data)) + { + ctx->data[3] = 0; + ctx->data[2] = 1; + } + return TRUE; +} diff --git a/src/option_menu.c b/src/option_menu.c new file mode 100644 index 000000000..7f92756ab --- /dev/null +++ b/src/option_menu.c @@ -0,0 +1,662 @@ +#include "global.h" +#include "option_menu.h" +#include "main.h" +#include "menu.h" +#include "unknown_task.h" +#include "palette.h" +#include "sprite.h" +#include "task.h" +#include "bg.h" +#include "gpu_regs.h" +#include "window.h" +#include "text.h" +#include "text_window.h" +#include "international_string_util.h" +#include "strings.h" + +extern void SetPokemonCryStereo(u32 val); + +// Task data +enum +{ + TD_MENUSELECTION, + TD_TEXTSPEED, + TD_BATTLESCENE, + TD_BATTLESTYLE, + TD_SOUND, + TD_BUTTONMODE, + TD_FRAMETYPE, +}; + +// Menu items +enum +{ + MENUITEM_TEXTSPEED, + MENUITEM_BATTLESCENE, + MENUITEM_BATTLESTYLE, + MENUITEM_SOUND, + MENUITEM_BUTTONMODE, + MENUITEM_FRAMETYPE, + MENUITEM_CANCEL, + MENUITEM_COUNT, +}; + +// Window Ids +enum +{ + WIN_TEXT_OPTION, + WIN_OPTIONS +}; + +// this file's functions +static void Task_OptionMenuFadeIn(u8 taskId); +static void Task_OptionMenuProcessInput(u8 taskId); +static void Task_OptionMenuSave(u8 taskId); +static void Task_OptionMenuFadeOut(u8 taskId); +static void HighlightOptionMenuItem(u8 selection); +static u8 TextSpeed_ProcessInput(u8 selection); +static void TextSpeed_DrawChoices(u8 selection); +static u8 BattleScene_ProcessInput(u8 selection); +static void BattleScene_DrawChoices(u8 selection); +static u8 BattleStyle_ProcessInput(u8 selection); +static void BattleStyle_DrawChoices(u8 selection); +static u8 Sound_ProcessInput(u8 selection); +static void Sound_DrawChoices(u8 selection); +static u8 FrameType_ProcessInput(u8 selection); +static void FrameType_DrawChoices(u8 selection); +static u8 ButtonMode_ProcessInput(u8 selection); +static void ButtonMode_DrawChoices(u8 selection); +static void DrawTextOption(void); +static void DrawOptionMenuTexts(void); +static void sub_80BB154(void); + +// EWRAM vars +EWRAM_DATA static bool8 sArrowPressed = FALSE; + +// const rom data +static const u16 sUnknown_0855C604[] = INCBIN_U16("graphics/misc/option_menu_text.gbapal"); +// note: this is only used in the Japanese release +static const u8 sEqualSignGfx[] = INCBIN_U8("graphics/misc/option_menu_equals_sign.4bpp"); + +static const u8 *const sOptionMenuItemsNames[MENUITEM_COUNT] = +{ + gText_TextSpeed, + gText_BattleScene, + gText_BattleStyle, + gText_Sound, + gText_ButtonMode, + gText_Frame, + gText_OptionMenuCancel, +}; + +static const struct WindowTemplate sOptionMenuWinTemplates[] = +{ + {1, 2, 1, 0x1A, 2, 1, 2}, + {0, 2, 5, 0x1A, 0xE, 1, 0x36}, + DUMMY_WIN_TEMPLATE +}; + +static const struct BgTemplate sOptionMenuBgTemplates[] = +{ + { + .bg = 1, + .charBaseIndex = 1, + .mapBaseIndex = 30, + .screenSize = 0, + .paletteMode = 0, + .priority = 0, + .baseTile = 0 + }, + { + .bg = 0, + .charBaseIndex = 1, + .mapBaseIndex = 31, + .screenSize = 0, + .paletteMode = 0, + .priority = 1, + .baseTile = 0 + } +}; + +static const u16 sUnknown_0855C6A0[] = {0x7E51}; + +// code +static void MainCB2(void) +{ + RunTasks(); + AnimateSprites(); + BuildOamBuffer(); + UpdatePaletteFade(); +} + +static void VBlankCB(void) +{ + LoadOam(); + ProcessSpriteCopyRequests(); + TransferPlttBuffer(); +} + +void CB2_InitOptionMenu(void) +{ + switch (gMain.state) + { + default: + case 0: + SetVBlankCallback(NULL); + gMain.state++; + break; + case 1: + { + u8 *addr; + u32 size; + + addr = (u8 *)VRAM; + size = 0x18000; + while (1) + { + DmaFill16(3, 0, addr, 0x1000); + addr += 0x1000; + size -= 0x1000; + if (size <= 0x1000) + { + DmaFill16(3, 0, addr, size); + break; + } + } + DmaClear32(3, OAM, OAM_SIZE); + DmaClear16(3, PLTT, PLTT_SIZE); + SetGpuReg(REG_OFFSET_DISPCNT, 0); + ResetBgsAndClearDma3BusyFlags(0); + InitBgsFromTemplates(0, sOptionMenuBgTemplates, ARRAY_COUNT(sOptionMenuBgTemplates)); + 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); + InitWindows(sOptionMenuWinTemplates); + DeactivateAllTextPrinters(); + SetGpuReg(REG_OFFSET_WIN0H, 0); + SetGpuReg(REG_OFFSET_WIN0V, 0); + SetGpuReg(REG_OFFSET_WININ, 1); + SetGpuReg(REG_OFFSET_WINOUT, 35); + SetGpuReg(REG_OFFSET_BLDCNT, 193); + SetGpuReg(REG_OFFSET_BLDALPHA, 0); + SetGpuReg(REG_OFFSET_BLDY, 4); + SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON | DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); + ShowBg(0); + ShowBg(1); + gMain.state++; + } + break; + case 2: + ResetPaletteFade(); + ScanlineEffect_Stop(); + ResetTasks(); + ResetSpriteData(); + gMain.state++; + break; + case 3: + LoadBgTiles(1, GetWindowFrameTilesPal(gSaveBlock2Ptr->optionsWindowFrameType)->tiles, 0x120, 0x1A2); + gMain.state++; + break; + case 4: + LoadPalette(sUnknown_0855C6A0, 0, sizeof(sUnknown_0855C6A0)); + LoadPalette(GetWindowFrameTilesPal(gSaveBlock2Ptr->optionsWindowFrameType)->pal, 0x70, 0x20); + gMain.state++; + break; + case 5: + LoadPalette(sUnknown_0855C604, 0x10, sizeof(sUnknown_0855C604)); + gMain.state++; + break; + case 6: + PutWindowTilemap(0); + DrawTextOption(); + gMain.state++; + break; + case 7: + gMain.state++; + break; + case 8: + PutWindowTilemap(1); + DrawOptionMenuTexts(); + gMain.state++; + case 9: + sub_80BB154(); + gMain.state++; + break; + case 10: + { + u8 taskId = CreateTask(Task_OptionMenuFadeIn, 0); + + gTasks[taskId].data[TD_MENUSELECTION] = 0; + gTasks[taskId].data[TD_TEXTSPEED] = gSaveBlock2Ptr->optionsTextSpeed; + gTasks[taskId].data[TD_BATTLESCENE] = gSaveBlock2Ptr->optionsBattleSceneOff; + gTasks[taskId].data[TD_BATTLESTYLE] = gSaveBlock2Ptr->optionsBattleStyle; + gTasks[taskId].data[TD_SOUND] = gSaveBlock2Ptr->optionsSound; + gTasks[taskId].data[TD_BUTTONMODE] = gSaveBlock2Ptr->optionsButtonMode; + gTasks[taskId].data[TD_FRAMETYPE] = gSaveBlock2Ptr->optionsWindowFrameType; + + TextSpeed_DrawChoices(gTasks[taskId].data[TD_TEXTSPEED]); + BattleScene_DrawChoices(gTasks[taskId].data[TD_BATTLESCENE]); + BattleStyle_DrawChoices(gTasks[taskId].data[TD_BATTLESTYLE]); + Sound_DrawChoices(gTasks[taskId].data[TD_SOUND]); + ButtonMode_DrawChoices(gTasks[taskId].data[TD_BUTTONMODE]); + FrameType_DrawChoices(gTasks[taskId].data[TD_FRAMETYPE]); + HighlightOptionMenuItem(gTasks[taskId].data[TD_MENUSELECTION]); + + CopyWindowToVram(WIN_OPTIONS, 3); + gMain.state++; + break; + } + case 11: + BeginNormalPaletteFade(-1, 0, 0x10, 0, 0); + SetVBlankCallback(VBlankCB); + SetMainCallback2(MainCB2); + return; + } +} + +static void Task_OptionMenuFadeIn(u8 taskId) +{ + if (!gPaletteFade.active) + gTasks[taskId].func = Task_OptionMenuProcessInput; +} + +static void Task_OptionMenuProcessInput(u8 taskId) +{ + if (gMain.newKeys & A_BUTTON) + { + if (gTasks[taskId].data[TD_MENUSELECTION] == MENUITEM_CANCEL) + gTasks[taskId].func = Task_OptionMenuSave; + } + else if (gMain.newKeys & B_BUTTON) + { + gTasks[taskId].func = Task_OptionMenuSave; + } + else if (gMain.newKeys & DPAD_UP) + { + if (gTasks[taskId].data[TD_MENUSELECTION] > 0) + gTasks[taskId].data[TD_MENUSELECTION]--; + else + gTasks[taskId].data[TD_MENUSELECTION] = 6; + HighlightOptionMenuItem(gTasks[taskId].data[TD_MENUSELECTION]); + } + else if (gMain.newKeys & DPAD_DOWN) + { + if (gTasks[taskId].data[TD_MENUSELECTION] <= 5) + gTasks[taskId].data[TD_MENUSELECTION]++; + else + gTasks[taskId].data[TD_MENUSELECTION] = 0; + HighlightOptionMenuItem(gTasks[taskId].data[TD_MENUSELECTION]); + } + else + { + u8 previousOption; + + switch (gTasks[taskId].data[TD_MENUSELECTION]) + { + case MENUITEM_TEXTSPEED: + previousOption = gTasks[taskId].data[TD_TEXTSPEED]; + gTasks[taskId].data[TD_TEXTSPEED] = TextSpeed_ProcessInput(gTasks[taskId].data[TD_TEXTSPEED]); + + if (previousOption != gTasks[taskId].data[TD_TEXTSPEED]) + TextSpeed_DrawChoices(gTasks[taskId].data[TD_TEXTSPEED]); + break; + case MENUITEM_BATTLESCENE: + previousOption = gTasks[taskId].data[TD_BATTLESCENE]; + gTasks[taskId].data[TD_BATTLESCENE] = BattleScene_ProcessInput(gTasks[taskId].data[TD_BATTLESCENE]); + + if (previousOption != gTasks[taskId].data[TD_BATTLESCENE]) + BattleScene_DrawChoices(gTasks[taskId].data[TD_BATTLESCENE]); + break; + case MENUITEM_BATTLESTYLE: + previousOption = gTasks[taskId].data[TD_BATTLESTYLE]; + gTasks[taskId].data[TD_BATTLESTYLE] = BattleStyle_ProcessInput(gTasks[taskId].data[TD_BATTLESTYLE]); + + if (previousOption != gTasks[taskId].data[TD_BATTLESTYLE]) + BattleStyle_DrawChoices(gTasks[taskId].data[TD_BATTLESTYLE]); + break; + case MENUITEM_SOUND: + previousOption = gTasks[taskId].data[TD_SOUND]; + gTasks[taskId].data[TD_SOUND] = Sound_ProcessInput(gTasks[taskId].data[TD_SOUND]); + + if (previousOption != gTasks[taskId].data[TD_SOUND]) + Sound_DrawChoices(gTasks[taskId].data[TD_SOUND]); + break; + case MENUITEM_BUTTONMODE: + previousOption = gTasks[taskId].data[TD_BUTTONMODE]; + gTasks[taskId].data[TD_BUTTONMODE] = ButtonMode_ProcessInput(gTasks[taskId].data[TD_BUTTONMODE]); + + if (previousOption != gTasks[taskId].data[TD_BUTTONMODE]) + ButtonMode_DrawChoices(gTasks[taskId].data[TD_BUTTONMODE]); + break; + case MENUITEM_FRAMETYPE: + previousOption = gTasks[taskId].data[TD_FRAMETYPE]; + gTasks[taskId].data[TD_FRAMETYPE] = FrameType_ProcessInput(gTasks[taskId].data[TD_FRAMETYPE]); + + if (previousOption != gTasks[taskId].data[TD_FRAMETYPE]) + FrameType_DrawChoices(gTasks[taskId].data[TD_FRAMETYPE]); + break; + default: + return; + } + + if (sArrowPressed) + { + sArrowPressed = FALSE; + CopyWindowToVram(WIN_OPTIONS, 2); + } + } +} + +static void Task_OptionMenuSave(u8 taskId) +{ + gSaveBlock2Ptr->optionsTextSpeed = gTasks[taskId].data[TD_TEXTSPEED]; + gSaveBlock2Ptr->optionsBattleSceneOff = gTasks[taskId].data[TD_BATTLESCENE]; + gSaveBlock2Ptr->optionsBattleStyle = gTasks[taskId].data[TD_BATTLESTYLE]; + gSaveBlock2Ptr->optionsSound = gTasks[taskId].data[TD_SOUND]; + gSaveBlock2Ptr->optionsButtonMode = gTasks[taskId].data[TD_BUTTONMODE]; + gSaveBlock2Ptr->optionsWindowFrameType = gTasks[taskId].data[TD_FRAMETYPE]; + + BeginNormalPaletteFade(-1, 0, 0, 0x10, 0); + gTasks[taskId].func = Task_OptionMenuFadeOut; +} + +static void Task_OptionMenuFadeOut(u8 taskId) +{ + if (!gPaletteFade.active) + { + DestroyTask(taskId); + FreeAllWindowBuffers(); + SetMainCallback2(gMain.savedCallback); + } +} + +static void HighlightOptionMenuItem(u8 index) +{ + SetGpuReg(REG_OFFSET_WIN0H, WIN_RANGE(16, 224)); + SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(index * 16 + 40, index * 16 + 56)); +} + +static void DrawOptionMenuChoice(const u8 *text, u8 x, u8 y, u8 style) +{ + u8 dst[16]; + u16 i; + + for (i = 0; *text != EOS && i <= 14; i++) + dst[i] = *(text++); + + if (style != 0) + { + dst[2] = 4; + dst[5] = 5; + } + + dst[i] = EOS; + PrintTextOnWindow(WIN_OPTIONS, 1, dst, x, y + 1, TEXT_SPEED_FF, NULL); +} + +static u8 TextSpeed_ProcessInput(u8 selection) +{ + if (gMain.newKeys & DPAD_RIGHT) + { + if (selection <= 1) + selection++; + else + selection = 0; + + sArrowPressed = TRUE; + } + if (gMain.newKeys & DPAD_LEFT) + { + if (selection != 0) + selection--; + else + selection = 2; + + sArrowPressed = TRUE; + } + return selection; +} + +static void TextSpeed_DrawChoices(u8 selection) +{ + u8 styles[3]; + s32 widthSlow, widthMid, widthFast, xMid; + + styles[0] = 0; + styles[1] = 0; + styles[2] = 0; + styles[selection] = 1; + + DrawOptionMenuChoice(gText_TextSpeedSlow, 104, 0, styles[0]); + + widthSlow = GetStringWidth(1, gText_TextSpeedSlow, 0); + widthMid = GetStringWidth(1, gText_TextSpeedMid, 0); + widthFast = GetStringWidth(1, gText_TextSpeedFast, 0); + + widthMid -= 94; + xMid = (widthSlow - widthMid - widthFast) / 2 + 104; + DrawOptionMenuChoice(gText_TextSpeedMid, xMid, 0, styles[1]); + + DrawOptionMenuChoice(gText_TextSpeedFast, GetStringRightAlignXOffset(1, gText_TextSpeedFast, 198), 0, styles[2]); +} + +static u8 BattleScene_ProcessInput(u8 selection) +{ + if (gMain.newKeys & (DPAD_LEFT | DPAD_RIGHT)) + { + selection ^= 1; + sArrowPressed = TRUE; + } + + return selection; +} + +static void BattleScene_DrawChoices(u8 selection) +{ + u8 styles[2]; + + styles[0] = 0; + styles[1] = 0; + styles[selection] = 1; + + DrawOptionMenuChoice(gText_BattleSceneOn, 104, 16, styles[0]); + DrawOptionMenuChoice(gText_BattleSceneOff, GetStringRightAlignXOffset(1, gText_BattleSceneOff, 198), 16, styles[1]); +} + +static u8 BattleStyle_ProcessInput(u8 selection) +{ + if (gMain.newKeys & (DPAD_LEFT | DPAD_RIGHT)) + { + selection ^= 1; + sArrowPressed = TRUE; + } + + return selection; +} + +static void BattleStyle_DrawChoices(u8 selection) +{ + u8 styles[2]; + + styles[0] = 0; + styles[1] = 0; + styles[selection] = 1; + + DrawOptionMenuChoice(gText_BattleStyleShift, 104, 32, styles[0]); + DrawOptionMenuChoice(gText_BattleStyleSet, GetStringRightAlignXOffset(1, gText_BattleStyleSet, 198), 32, styles[1]); +} + +static u8 Sound_ProcessInput(u8 selection) +{ + if (gMain.newKeys & (DPAD_LEFT | DPAD_RIGHT)) + { + selection ^= 1; + SetPokemonCryStereo(selection); + sArrowPressed = TRUE; + } + + return selection; +} + +static void Sound_DrawChoices(u8 selection) +{ + u8 styles[2]; + + styles[0] = 0; + styles[1] = 0; + styles[selection] = 1; + + DrawOptionMenuChoice(gText_SoundMono, 104, 48, styles[0]); + DrawOptionMenuChoice(gText_SoundStereo, GetStringRightAlignXOffset(1, gText_SoundStereo, 198), 48, styles[1]); +} + +static u8 FrameType_ProcessInput(u8 selection) +{ + if (gMain.newKeys & DPAD_RIGHT) + { + if (selection < WINDOW_FRAMES_COUNT - 1) + selection++; + else + selection = 0; + + LoadBgTiles(1, GetWindowFrameTilesPal(selection)->tiles, 0x120, 0x1A2); + LoadPalette(GetWindowFrameTilesPal(selection)->pal, 0x70, 0x20); + sArrowPressed = TRUE; + } + if (gMain.newKeys & DPAD_LEFT) + { + if (selection != 0) + selection--; + else + selection = WINDOW_FRAMES_COUNT - 1; + + LoadBgTiles(1, GetWindowFrameTilesPal(selection)->tiles, 0x120, 0x1A2); + LoadPalette(GetWindowFrameTilesPal(selection)->pal, 0x70, 0x20); + sArrowPressed = TRUE; + } + return selection; +} + +static void FrameType_DrawChoices(u8 selection) +{ + u8 text[16]; + u8 n = selection + 1; + u16 i; + + for (i = 0; gText_FrameTypeNumber[i] != EOS && i <= 5; i++) + text[i] = gText_FrameTypeNumber[i]; + + // Convert a number to decimal string + if (n / 10 != 0) + { + text[i] = n / 10 + CHAR_0; + i++; + text[i] = n % 10 + CHAR_0; + i++; + } + else + { + text[i] = n % 10 + CHAR_0; + i++; + text[i] = 0x77; + i++; + } + + text[i] = EOS; + + DrawOptionMenuChoice(gText_FrameType, 104, 80, 0); + DrawOptionMenuChoice(text, 128, 80, 1); +} + +static u8 ButtonMode_ProcessInput(u8 selection) +{ + if (gMain.newKeys & DPAD_RIGHT) + { + if (selection <= 1) + selection++; + else + selection = 0; + + sArrowPressed = TRUE; + } + if (gMain.newKeys & DPAD_LEFT) + { + if (selection != 0) + selection--; + else + selection = 2; + + sArrowPressed = TRUE; + } + return selection; +} + +static void ButtonMode_DrawChoices(u8 selection) +{ + s32 widthNormal, widthLR, widthLA, xLR; + u8 styles[3]; + + styles[0] = 0; + styles[1] = 0; + styles[2] = 0; + styles[selection] = 1; + + DrawOptionMenuChoice(gText_ButtonTypeNormal, 104, 64, styles[0]); + + widthNormal = GetStringWidth(1, gText_ButtonTypeNormal, 0); + widthLR = GetStringWidth(1, gText_ButtonTypeLR, 0); + widthLA = GetStringWidth(1, gText_ButtonTypeLEqualsA, 0); + + widthLR -= 94; + xLR = (widthNormal - widthLR - widthLA) / 2 + 104; + DrawOptionMenuChoice(gText_ButtonTypeLR, xLR, 64, styles[1]); + + DrawOptionMenuChoice(gText_ButtonTypeLEqualsA, GetStringRightAlignXOffset(1, gText_ButtonTypeLEqualsA, 198), 64, styles[2]); +} + +static void DrawTextOption(void) +{ + FillWindowPixelBuffer(WIN_TEXT_OPTION, 0x11); + PrintTextOnWindow(WIN_TEXT_OPTION, 1, gText_Option, 8, 1, TEXT_SPEED_FF, NULL); + CopyWindowToVram(WIN_TEXT_OPTION, 3); +} + +static void DrawOptionMenuTexts(void) +{ + u8 i; + + FillWindowPixelBuffer(WIN_OPTIONS, 0x11); + for (i = 0; i < MENUITEM_COUNT; i++) + { + PrintTextOnWindow(WIN_OPTIONS, 1, sOptionMenuItemsNames[i], 8, (i * 16) + 1, TEXT_SPEED_FF, NULL); + } + CopyWindowToVram(WIN_OPTIONS, 3); +} + +static void sub_80BB154(void) +{ + // bg, tileNum, x, y, width, height, pal + FillBgTilemapBufferRect(1, 0x1A2, 1, 0, 1, 1, 7); + FillBgTilemapBufferRect(1, 0x1A3, 2, 0, 0x1B, 1, 7); + FillBgTilemapBufferRect(1, 0x1A4, 28, 0, 1, 1, 7); + FillBgTilemapBufferRect(1, 0x1A5, 1, 1, 1, 2, 7); + FillBgTilemapBufferRect(1, 0x1A7, 28, 1, 1, 2, 7); + FillBgTilemapBufferRect(1, 0x1A8, 1, 3, 1, 1, 7); + FillBgTilemapBufferRect(1, 0x1A9, 2, 3, 0x1B, 1, 7); + FillBgTilemapBufferRect(1, 0x1AA, 28, 3, 1, 1, 7); + FillBgTilemapBufferRect(1, 0x1A2, 1, 4, 1, 1, 7); + FillBgTilemapBufferRect(1, 0x1A3, 2, 4, 0x1A, 1, 7); + FillBgTilemapBufferRect(1, 0x1A4, 28, 4, 1, 1, 7); + FillBgTilemapBufferRect(1, 0x1A5, 1, 5, 1, 0x12, 7); + FillBgTilemapBufferRect(1, 0x1A7, 28, 5, 1, 0x12, 7); + FillBgTilemapBufferRect(1, 0x1A8, 1, 19, 1, 1, 7); + FillBgTilemapBufferRect(1, 0x1A9, 2, 19, 0x1A, 1, 7); + FillBgTilemapBufferRect(1, 0x1AA, 28, 19, 1, 1, 7); + + CopyBgTilemapBufferToVram(1); +} diff --git a/src/pokeblock.c b/src/pokeblock.c index 737f2c6f3..573eed52b 100644 --- a/src/pokeblock.c +++ b/src/pokeblock.c @@ -419,7 +419,7 @@ static bool8 InitPokeblockMenu(void) gMain.state++; break; case 1: - remove_some_task(); + ScanlineEffect_Stop(); gMain.state++; break; case 2: diff --git a/src/pokemon_summary_screen.c b/src/pokemon_summary_screen.c index 31af2bf2f..5ec5410ca 100755..100644 --- a/src/pokemon_summary_screen.c +++ b/src/pokemon_summary_screen.c @@ -75,7 +75,7 @@ extern u8 sub_81221AC(); extern void SetVBlankHBlankCallbacksToNull(); extern void ResetVramOamAndBgCntRegs(); extern void clear_scheduled_bg_copies_to_vram(); -extern void remove_some_task(); +extern void ScanlineEffect_Stop(); extern void ResetBgsAndClearDma3BusyFlags(u32 leftoverFireRedLeafGreenVariable); extern void ShowBg(u8 a); extern void SetGpuReg(u8 regOffset, u16 value); @@ -455,7 +455,7 @@ bool8 sub_81BFB10(void) gMain.state++; break; case 1: - remove_some_task(); + ScanlineEffect_Stop(); gMain.state++; break; case 2: diff --git a/src/save_failed_screen.c b/src/save_failed_screen.c index efe38fbae..8764daa5f 100755..100644 --- a/src/save_failed_screen.c +++ b/src/save_failed_screen.c @@ -9,6 +9,7 @@ #include "menu.h" #include "save.h" #include "gba/flash_internal.h" +#include "text_window.h" #define MSG_WIN_TOP 12 #define CLOCK_WIN_TOP (MSG_WIN_TOP - 4) @@ -21,9 +22,7 @@ extern const u8 gBirchHelpGfx[]; extern const u8 gBirchBagTilemap[]; extern const u8 gBirchGrassTilemap[]; extern const u16 gBirchBagGrassPal[]; -extern const u16 gTextWindowFrame1_Pal[]; extern const u16 gUnknown_0860F074[]; -extern const u32 gTextWindowFrame1_Gfx[]; extern struct SaveSection gSaveDataBuffer; extern u8 gText_SaveFailedCheckingBackup[]; diff --git a/src/save_location.c b/src/save_location.c index 262aaf40c..262aaf40c 100755..100644 --- a/src/save_location.c +++ b/src/save_location.c diff --git a/src/starter_choose.c b/src/starter_choose.c index c2c553d46..83a7b8112 100644 --- a/src/starter_choose.c +++ b/src/starter_choose.c @@ -53,7 +53,7 @@ extern const u8 gUnknown_085B1E0C[]; extern const u8 gUnknown_085B1E28[][2]; extern void sub_809882C(u8, u16, u8); -extern void remove_some_task(void); +extern void ScanlineEffect_Stop(void); extern void clear_scheduled_bg_copies_to_vram(void); extern void dp13_810BB8C(void); extern void do_scheduled_bg_tilemap_copies_to_vram(void); @@ -134,7 +134,7 @@ void CB2_ChooseStarter(void) DeactivateAllTextPrinters(); sub_809882C(0, 0x2A8, 0xD0); clear_scheduled_bg_copies_to_vram(); - remove_some_task(); + ScanlineEffect_Stop(); ResetTasks(); ResetSpriteData(); ResetPaletteFade(); diff --git a/src/text_window.c b/src/text_window.c index c5334b11e..33cd7cffe 100644 --- a/src/text_window.c +++ b/src/text_window.c @@ -3,21 +3,92 @@ #include "text_window.h" #include "window.h" #include "palette.h" - -extern u8 LoadBgTiles(u8 bg, const void *src, u16 size, u16 destOffset); -extern void FillBgTilemapBufferRect(u8 bg, u16 tileNum, u8 x, u8 y, u8 width, u8 height, u8 palette); - -extern const struct TilesPal gUnknown_0851021C[]; -extern const u32 gMessageBox_Gfx[]; -extern const u16 gUnknown_0851017C[]; -extern const u16 gUnknown_08DDD728[]; - -const struct TilesPal* sub_8098758(u8 id) +#include "bg.h" +#include "graphics.h" + +// const rom data +const u32 gTextWindowFrame1_Gfx[] = INCBIN_U32("graphics/text_window/1.4bpp"); +static const u32 sTextWindowFrame2_Gfx[] = INCBIN_U32("graphics/text_window/2.4bpp"); +static const u32 sTextWindowFrame3_Gfx[] = INCBIN_U32("graphics/text_window/3.4bpp"); +static const u32 sTextWindowFrame4_Gfx[] = INCBIN_U32("graphics/text_window/4.4bpp"); +static const u32 sTextWindowFrame5_Gfx[] = INCBIN_U32("graphics/text_window/5.4bpp"); +static const u32 sTextWindowFrame6_Gfx[] = INCBIN_U32("graphics/text_window/6.4bpp"); +static const u32 sTextWindowFrame7_Gfx[] = INCBIN_U32("graphics/text_window/7.4bpp"); +static const u32 sTextWindowFrame8_Gfx[] = INCBIN_U32("graphics/text_window/8.4bpp"); +static const u32 sTextWindowFrame9_Gfx[] = INCBIN_U32("graphics/text_window/9.4bpp"); +static const u32 sTextWindowFrame10_Gfx[] = INCBIN_U32("graphics/text_window/10.4bpp"); +static const u32 sTextWindowFrame11_Gfx[] = INCBIN_U32("graphics/text_window/11.4bpp"); +static const u32 sTextWindowFrame12_Gfx[] = INCBIN_U32("graphics/text_window/12.4bpp"); +static const u32 sTextWindowFrame13_Gfx[] = INCBIN_U32("graphics/text_window/13.4bpp"); +static const u32 sTextWindowFrame14_Gfx[] = INCBIN_U32("graphics/text_window/14.4bpp"); +static const u32 sTextWindowFrame15_Gfx[] = INCBIN_U32("graphics/text_window/15.4bpp"); +static const u32 sTextWindowFrame16_Gfx[] = INCBIN_U32("graphics/text_window/16.4bpp"); +static const u32 sTextWindowFrame17_Gfx[] = INCBIN_U32("graphics/text_window/17.4bpp"); +static const u32 sTextWindowFrame18_Gfx[] = INCBIN_U32("graphics/text_window/18.4bpp"); +static const u32 sTextWindowFrame19_Gfx[] = INCBIN_U32("graphics/text_window/19.4bpp"); +static const u32 sTextWindowFrame20_Gfx[] = INCBIN_U32("graphics/text_window/20.4bpp"); + +const u16 gTextWindowFrame1_Pal[] = INCBIN_U16("graphics/text_window/1.gbapal"); +static const u16 sTextWindowFrame2_Pal[] = INCBIN_U16("graphics/text_window/2.gbapal"); +static const u16 sTextWindowFrame3_Pal[] = INCBIN_U16("graphics/text_window/3.gbapal"); +static const u16 sTextWindowFrame4_Pal[] = INCBIN_U16("graphics/text_window/4.gbapal"); +static const u16 sTextWindowFrame5_Pal[] = INCBIN_U16("graphics/text_window/5.gbapal"); +static const u16 sTextWindowFrame6_Pal[] = INCBIN_U16("graphics/text_window/6.gbapal"); +static const u16 sTextWindowFrame7_Pal[] = INCBIN_U16("graphics/text_window/7.gbapal"); +static const u16 sTextWindowFrame8_Pal[] = INCBIN_U16("graphics/text_window/8.gbapal"); +static const u16 sTextWindowFrame9_Pal[] = INCBIN_U16("graphics/text_window/9.gbapal"); +static const u16 sTextWindowFrame10_Pal[] = INCBIN_U16("graphics/text_window/10.gbapal"); +static const u16 sTextWindowFrame11_Pal[] = INCBIN_U16("graphics/text_window/11.gbapal"); +static const u16 sTextWindowFrame12_Pal[] = INCBIN_U16("graphics/text_window/12.gbapal"); +static const u16 sTextWindowFrame13_Pal[] = INCBIN_U16("graphics/text_window/13.gbapal"); +static const u16 sTextWindowFrame14_Pal[] = INCBIN_U16("graphics/text_window/14.gbapal"); +static const u16 sTextWindowFrame15_Pal[] = INCBIN_U16("graphics/text_window/15.gbapal"); +static const u16 sTextWindowFrame16_Pal[] = INCBIN_U16("graphics/text_window/16.gbapal"); +static const u16 sTextWindowFrame17_Pal[] = INCBIN_U16("graphics/text_window/17.gbapal"); +static const u16 sTextWindowFrame18_Pal[] = INCBIN_U16("graphics/text_window/18.gbapal"); +static const u16 sTextWindowFrame19_Pal[] = INCBIN_U16("graphics/text_window/19.gbapal"); +static const u16 sTextWindowFrame20_Pal[] = INCBIN_U16("graphics/text_window/20.gbapal"); + +static const u16 sUnknown_0851017C[][16] = { - if (id > 19) - return &gUnknown_0851021C[0]; + INCBIN_U16("graphics/text_window/message_box.gbapal"), + INCBIN_U16("graphics/text_window/text_pal1.gbapal"), + INCBIN_U16("graphics/text_window/text_pal2.gbapal"), + INCBIN_U16("graphics/text_window/text_pal3.gbapal"), + INCBIN_U16("graphics/text_window/text_pal4.gbapal") +}; + +static const struct TilesPal sWindowFrames[WINDOW_FRAMES_COUNT] = +{ + {gTextWindowFrame1_Gfx, gTextWindowFrame1_Pal}, + {sTextWindowFrame2_Gfx, sTextWindowFrame2_Pal}, + {sTextWindowFrame3_Gfx, sTextWindowFrame3_Pal}, + {sTextWindowFrame4_Gfx, sTextWindowFrame4_Pal}, + {sTextWindowFrame5_Gfx, sTextWindowFrame5_Pal}, + {sTextWindowFrame6_Gfx, sTextWindowFrame6_Pal}, + {sTextWindowFrame7_Gfx, sTextWindowFrame7_Pal}, + {sTextWindowFrame8_Gfx, sTextWindowFrame8_Pal}, + {sTextWindowFrame9_Gfx, sTextWindowFrame9_Pal}, + {sTextWindowFrame10_Gfx, sTextWindowFrame10_Pal}, + {sTextWindowFrame11_Gfx, sTextWindowFrame11_Pal}, + {sTextWindowFrame12_Gfx, sTextWindowFrame12_Pal}, + {sTextWindowFrame13_Gfx, sTextWindowFrame13_Pal}, + {sTextWindowFrame14_Gfx, sTextWindowFrame14_Pal}, + {sTextWindowFrame15_Gfx, sTextWindowFrame15_Pal}, + {sTextWindowFrame16_Gfx, sTextWindowFrame16_Pal}, + {sTextWindowFrame17_Gfx, sTextWindowFrame17_Pal}, + {sTextWindowFrame18_Gfx, sTextWindowFrame18_Pal}, + {sTextWindowFrame19_Gfx, sTextWindowFrame19_Pal}, + {sTextWindowFrame20_Gfx, sTextWindowFrame20_Pal} +}; + +// code +const struct TilesPal *GetWindowFrameTilesPal(u8 id) +{ + if (id >= WINDOW_FRAMES_COUNT) + return &sWindowFrames[0]; else - return &gUnknown_0851021C[id]; + return &sWindowFrames[id]; } void copy_textbox_border_tile_patterns_to_vram(u8 windowId, u16 destOffset, u8 palOffset) @@ -33,8 +104,8 @@ void box_border_load_tiles_and_pal(u8 windowId, u16 destOffset, u8 palOffset) void sub_80987D4(u8 windowId, u8 frameId, u16 destOffset, u8 palOffset) { - LoadBgTiles(GetWindowAttribute(windowId, WINDOW_PRIORITY), gUnknown_0851021C[frameId].tiles, 0x120, destOffset); - LoadPalette(gUnknown_0851021C[frameId].pal, palOffset, 0x20); + LoadBgTiles(GetWindowAttribute(windowId, WINDOW_PRIORITY), sWindowFrames[frameId].tiles, 0x120, destOffset); + LoadPalette(sWindowFrames[frameId].pal, palOffset, 0x20); } void sub_809882C(u8 windowId, u16 destOffset, u8 palOffset) @@ -89,7 +160,7 @@ void rbox_fill_rectangle(u8 windowId) FillBgTilemapBufferRect(bgLayer, 0, tilemapLeft - 1, tilemapTop - 1, width + 2, height + 2, 0x11); } -const u16* stdpal_get(u8 id) +const u16 *stdpal_get(u8 id) { switch (id) { @@ -110,16 +181,17 @@ const u16* stdpal_get(u8 id) id = 0x40; break; } - return &gUnknown_0851017C[id]; + + return (const u16 *)(sUnknown_0851017C) + id; } -const u16* GetOverworldTextboxPalettePtr(void) +const u16 *GetOverworldTextboxPalettePtr(void) { - return gUnknown_08DDD728; + return gMessageBox_Pal; } void sub_8098C6C(u8 bg, u16 destOffset, u8 palOffset) { - LoadBgTiles(bg, gUnknown_0851021C[gSaveBlock2Ptr->optionsWindowFrameType].tiles, 0x120, destOffset); - LoadPalette(sub_8098758(gSaveBlock2Ptr->optionsWindowFrameType)->pal, palOffset, 0x20); + LoadBgTiles(bg, sWindowFrames[gSaveBlock2Ptr->optionsWindowFrameType].tiles, 0x120, destOffset); + LoadPalette(GetWindowFrameTilesPal(gSaveBlock2Ptr->optionsWindowFrameType)->pal, palOffset, 0x20); } diff --git a/src/wallclock.c b/src/wallclock.c index ea6137c5d..dbea24b4c 100644 --- a/src/wallclock.c +++ b/src/wallclock.c @@ -578,7 +578,7 @@ static void LoadWallClockGraphics(void) DeactivateAllTextPrinters(); sub_809882C(0, 0x250, 0xd0); clear_scheduled_bg_copies_to_vram(); - remove_some_task(); + ScanlineEffect_Stop(); ResetTasks(); ResetSpriteData(); ResetPaletteFade(); |