From 0064333e4aa1bacb42f840ba67d38a9aced8816e Mon Sep 17 00:00:00 2001 From: GriffinR Date: Tue, 26 Jan 2021 02:16:26 -0500 Subject: [PATCH] Clean up scrcmd.c --- asm/macros/event.inc | 15 +- .../LilycoveCity_ContestLobby/scripts.inc | 4 +- data/script_cmd_table.inc | 4 +- data/scripts/trainer_battle.inc | 2 +- data/text/braille.inc | 154 +++--------------- include/constants/weather.h | 5 +- include/event_object_movement.h | 6 +- src/event_object_movement.c | 8 +- src/scrcmd.c | 98 +++++------ src/script.c | 6 +- src/shop.c | 9 +- 11 files changed, 107 insertions(+), 204 deletions(-) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index eafd19b1c..7fff4d987 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -930,6 +930,17 @@ .4byte \text .endm + @ Formatting for the braille window, to be put at the start of a pointer used by braillemessage. + @ These are from RS and are ignored in Emerald (see ScrCmd_braillemessage, and comment above) + .macro brailleformat winLeft:req, winTop:req, winRight:req, winBottom:req, textLeft:req, textTop:req + .byte \winLeft + .byte \winTop + .byte \winRight + .byte \winBottom + .byte \textLeft + .byte \textTop + .endm + @ Gives the player one of the specified (species) Pokemon at level level holding item. The trailing 0s are unused parameters .macro givemon species:req, level:req, item:req .byte 0x79 @@ -1550,7 +1561,7 @@ .2byte \y .endm - .macro cmdD8 + .macro selectapproachingtrainer .byte 0xd8 .endm @@ -1562,7 +1573,7 @@ .byte 0xda .endm - .macro message3 pointer:req + .macro messageinstant pointer:req .byte 0xdb .4byte \pointer .endm diff --git a/data/maps/LilycoveCity_ContestLobby/scripts.inc b/data/maps/LilycoveCity_ContestLobby/scripts.inc index 51c38e3f4..3a3b3d86b 100644 --- a/data/maps/LilycoveCity_ContestLobby/scripts.inc +++ b/data/maps/LilycoveCity_ContestLobby/scripts.inc @@ -783,7 +783,7 @@ LilycoveCity_ContestLobby_EventScript_TrySetUpLinkContest:: @ 821AA15 goto_if_eq LilycoveCity_ContestLobby_EventScript_CancelLinkError compare VAR_RESULT, LINKUP_FAILED_CONTEST_GMODE goto_if_eq LilycoveCity_ContestLobby_EventScript_CancelLinkModeDifference - message3 LilycoveCity_ContestLobby_Text_Transmitting + messageinstant LilycoveCity_ContestLobby_Text_Transmitting contestlinktransfer switch VAR_0x8004 case 0, LilycoveCity_ContestLobby_EventScript_StartLinkContest @@ -926,7 +926,7 @@ LilycoveCity_ContestLobby_EventScript_TryJoinLinkGroup:: @ 821AC38 return LilycoveCity_ContestLobby_EventScript_LinkLeaderDecided:: @ 821AC3D - message3 LilycoveCity_ContestLobby_Text_Transmitting + messageinstant LilycoveCity_ContestLobby_Text_Transmitting contestlinktransfer goto LilycoveCity_ContestLobby_EventScript_StartLinkContest end diff --git a/data/script_cmd_table.inc b/data/script_cmd_table.inc index 7edb5c4b7..f4da025d1 100644 --- a/data/script_cmd_table.inc +++ b/data/script_cmd_table.inc @@ -216,10 +216,10 @@ gScriptCmdTable:: @ 81DB67C .4byte ScrCmd_initrotatingtilepuzzle @ 0xd5 .4byte ScrCmd_freerotatingtilepuzzle @ 0xd6 .4byte ScrCmd_warpmossdeepgym @ 0xd7 - .4byte ScrCmd_cmdD8 @ 0xd8 + .4byte ScrCmd_selectapproachingtrainer @ 0xd8 .4byte ScrCmd_cmdD9 @ 0xd9 .4byte ScrCmd_closebraillemessage @ 0xda - .4byte ScrCmd_cmdDB @ 0xdb + .4byte ScrCmd_messageinstant @ 0xdb .4byte ScrCmd_fadescreenswapbuffers @ 0xdc .4byte ScrCmd_buffertrainerclassname @ 0xdd .4byte ScrCmd_buffertrainername @ 0xde diff --git a/data/scripts/trainer_battle.inc b/data/scripts/trainer_battle.inc index aa96e7b35..5c77d80b5 100644 --- a/data/scripts/trainer_battle.inc +++ b/data/scripts/trainer_battle.inc @@ -1,5 +1,5 @@ EventScript_271354:: @ 8271354 - cmdD8 + selectapproachingtrainer cmdD9 EventScript_ShowSecondTrainerIntro:: @ 8271356 diff --git a/data/text/braille.inc b/data/text/braille.inc index 30f9b44d4..57b77e393 100644 --- a/data/text/braille.inc +++ b/data/text/braille.inc @@ -1,222 +1,112 @@ Underwater_SealedChamber_Braille_GoUpHere: @ 82A6B15 - .byte 4 - .byte 6 - .byte 26 - .byte 13 - .byte 7 - .byte 9 + brailleformat 4, 6, 26, 13, 7, 9 .braille "GO UP HERE.$" SealedChamber_OuterRoom_Braille_ABC: @ 82A6B27 - .byte 7 - .byte 6 - .byte 21 - .byte 13 - .byte 10 - .byte 9 + brailleformat 7, 6, 21, 13, 10, 9 .braille "ABC$" SealedChamber_OuterRoom_Braille_GHI: @ 82A6B31 - .byte 7 - .byte 6 - .byte 21 - .byte 13 - .byte 10 - .byte 9 + brailleformat 7, 6, 21, 13, 10, 9 .braille "GHI$" SealedChamber_OuterRoom_Braille_MNO: @ 82A6B3B - .byte 7 - .byte 6 - .byte 21 - .byte 13 - .byte 10 - .byte 9 + brailleformat 7, 6, 21, 13, 10, 9 .braille "MNO$" SealedChamber_OuterRoom_Braille_TUV: @ 82A6B45 - .byte 7 - .byte 6 - .byte 21 - .byte 13 - .byte 10 - .byte 9 + brailleformat 7, 6, 21, 13, 10, 9 .braille "TUV$" SealedChamber_OuterRoom_Braille_DEF: @ 82A6B4F - .byte 7 - .byte 6 - .byte 21 - .byte 13 - .byte 10 - .byte 9 + brailleformat 7, 6, 21, 13, 10, 9 .braille "DEF$" SealedChamber_OuterRoom_Braille_JKL: @ 82A6B59 - .byte 7 - .byte 6 - .byte 21 - .byte 13 - .byte 10 - .byte 9 + brailleformat 7, 6, 21, 13, 10, 9 .braille "JKL$" SealedChamber_OuterRoom_Braille_PQRS: @ 82A6B63 - .byte 7 - .byte 6 - .byte 21 - .byte 13 - .byte 10 - .byte 9 + brailleformat 7, 6, 21, 13, 10, 9 .braille "PQRS$" SealedChamber_OuterRoom_Braille_Period: @ 82A6B6E - .byte 9 - .byte 6 - .byte 19 - .byte 13 - .byte 12 - .byte 9 + brailleformat 9, 6, 19, 13, 12, 9 .braille ".$" SealedChamber_OuterRoom_Braille_WXYZ: @ 82A6B76 - .byte 7 - .byte 6 - .byte 21 - .byte 13 - .byte 10 - .byte 9 + brailleformat 7, 6, 21, 13, 10, 9 .braille "WXYZ$" SealedChamber_OuterRoom_Braille_Comma: @ 82A6B81 - .byte 9 - .byte 6 - .byte 19 - .byte 13 - .byte 12 - .byte 9 + brailleformat 9, 6, 19, 13, 12, 9 .braille ",$" SealedChamber_OuterRoom_Braille_DigHere: @ 82A6B89 - .byte 7 - .byte 4 - .byte 23 - .byte 15 - .byte 10 - .byte 7 + brailleformat 7, 4, 23, 15, 10, 7 .braille "DIG HERE.$" SealedChamber_InnerRoom_Braille_FirstWailordLastRelicanth: @ 82A6B99 - .byte 0 - .byte 0 - .byte 29 - .byte 19 - .byte 3 - .byte 3 + brailleformat 0, 0, 29, 19, 3, 3 .braille "FIRST COMES\n" .braille "WAILORD.\n" .braille "LAST COMES\n" .braille "RELICANTH.$" SealedChamber_InnerRoom_Braille_InThisCaveWeHaveLived: @ 82A6BCA - .byte 2 - .byte 0 - .byte 26 - .byte 19 - .byte 5 - .byte 3 + brailleformat 2, 0, 26, 19, 5, 3 .braille "IN THIS\n" .braille "CAVE WE\n" .braille "HAVE\n" .braille "LIVED.$" SealedChamber_InnerRoom_Braille_WeOweAllToThePokemon: @ 82A6BEC - .byte 7 - .byte 2 - .byte 23 - .byte 17 - .byte 10 - .byte 5 + brailleformat 7, 2, 23, 17, 10, 5 .braille "WE OWE ALL\n" .braille "TO THE\n" .braille "POKEMON.$" SealedChamber_InnerRoom_Braille_ButWeSealedThePokemonAway: @ 82A6C0D - .byte 3 - .byte 0 - .byte 25 - .byte 19 - .byte 6 - .byte 3 + brailleformat 3, 0, 25, 19, 6, 3 .braille "BUT, WE\n" .braille "SEALED THE\n" .braille "POKEMON\n" .braille "AWAY.$" SealedChamber_InnerRoom_Braille_WeFearedIt: @ 82A6C34 - .byte 5 - .byte 6 - .byte 25 - .byte 13 - .byte 8 - .byte 9 + brailleformat 5, 6, 25, 13, 8, 9 .braille "WE FEARED IT.$" SealedChamber_InnerRoom_Braille_ThoseWithCourageHope: @ 82A6C48 - .byte 6 - .byte 0 - .byte 24 - .byte 19 - .byte 9 - .byte 3 + brailleformat 6, 0, 24, 19, 9, 3 .braille "THOSE WITH\n" .braille "COURAGE,\n" .braille "THOSE WITH\n" .braille "HOPE.$" SealedChamber_InnerRoom_Braille_OpenDoorEternalPokemonWaits: @ 82A6C73 - .byte 3 - .byte 2 - .byte 27 - .byte 17 - .byte 6 - .byte 5 + brailleformat 3, 2, 27, 17, 6, 5 .braille "OPEN A DOOR.\n" .braille "AN ETERNAL\n" .braille "POKEMON\n" .braille "WAITS.$" DesertRuins_Braille_UseRockSmash: @ 82A6CA0 - .byte 1 - .byte 0 - .byte 27 - .byte 19 - .byte 4 - .byte 3 + brailleformat 1, 0, 27, 19, 4, 3 .braille "LEFT, LEFT,\n" .braille "DOWN, DOWN.\n" .braille "THEN, USE\n" .braille "ROCK SMASH.$" IslandCave_Braille_RunLapAroundWall: @ 82A6CD4 - .byte 5 - .byte 0 - .byte 25 - .byte 19 - .byte 8 - .byte 3 + brailleformat 5, 0, 25, 19, 8, 3 .braille "STAY CLOSE\n" .braille "TO THE WALL.\n" .braille "RUN AROUND\n" .braille "ONE LAP.$" AncientTomb_Braille_ShineInTheMiddle: @ 82A6D06 - .byte 3 - .byte 0 - .byte 25 - .byte 19 - .byte 6 - .byte 3 + brailleformat 3, 0, 25, 19, 6, 3 .braille "THOSE WHO\n" .braille "INHERIT OUR\n" .braille "WILL, SHINE\n" diff --git a/include/constants/weather.h b/include/constants/weather.h index aa0309882..becbdda87 100644 --- a/include/constants/weather.h +++ b/include/constants/weather.h @@ -39,8 +39,6 @@ // These are the "abnormal weather events" that are used // to find Kyogre and Groudon. -#define ABNORMAL_WEATHER_LOCATIONS (MARINE_CAVE_LOCATIONS + TERRA_CAVE_LOCATIONS) -#define ABNORMAL_WEATHER_NONE 0 // Groudon/Terra Cave locations #define TERRA_CAVE_LOCATIONS_START 1 @@ -66,4 +64,7 @@ #define ABNORMAL_WEATHER_ROUTE_129_EAST (MARINE_CAVE_LOCATIONS_START + 7) #define MARINE_CAVE_LOCATIONS 8 +#define ABNORMAL_WEATHER_LOCATIONS (MARINE_CAVE_LOCATIONS + TERRA_CAVE_LOCATIONS) +#define ABNORMAL_WEATHER_NONE 0 + #endif // GUARD_CONSTANTS_WEATHER_H diff --git a/include/event_object_movement.h b/include/event_object_movement.h index cd76cac11..5b008ead6 100644 --- a/include/event_object_movement.h +++ b/include/event_object_movement.h @@ -106,11 +106,11 @@ void ObjectEventSetGraphicsId(struct ObjectEvent *, u8 graphicsId); void ObjectEventTurn(struct ObjectEvent *, u8); void ObjectEventTurnByLocalIdAndMap(u8, u8, u8, u8); const struct ObjectEventGraphicsInfo *GetObjectEventGraphicsInfo(u8 graphicsId); -void npc_by_local_id_and_map_set_field_1_bit_x20(u8, u8, u8, u8); +void SetObjectInvisibility(u8, u8, u8, bool8); void FreeAndReserveObjectSpritePalettes(void); void SetObjectEventSpritePosByLocalIdAndMap(u8 localId, u8 mapNum, u8 mapGroup, s16 x, s16 y); -void sub_808E7E4(u8, u8, u8); -void sub_808E78C(u8, u8, u8, u8); +void ResetObjectPriority(u8, u8, u8); +void SetObjectPriority(u8, u8, u8, u8); void sub_808E75C(s16, s16); void ObjectEventGetLocalIdAndMap(struct ObjectEvent *objectEvent, void *localId, void *mapNum, void *mapGroup); void ShiftObjectEventCoords(struct ObjectEvent *, s16, s16); diff --git a/src/event_object_movement.c b/src/event_object_movement.c index d9c06eb10..46d8d6d32 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -1888,13 +1888,13 @@ static void SetObjectEventDynamicGraphicsId(struct ObjectEvent *objectEvent) } } -void npc_by_local_id_and_map_set_field_1_bit_x20(u8 localId, u8 mapNum, u8 mapGroup, u8 state) +void SetObjectInvisibility(u8 localId, u8 mapNum, u8 mapGroup, bool8 invisible) { u8 objectEventId; if (!TryGetObjectEventIdByLocalIdAndMap(localId, mapNum, mapGroup, &objectEventId)) { - gObjectEvents[objectEventId].invisible = state; + gObjectEvents[objectEventId].invisible = invisible; } } @@ -1918,7 +1918,7 @@ void sub_808E75C(s16 x, s16 y) } } -void sub_808E78C(u8 localId, u8 mapNum, u8 mapGroup, u8 subpriority) +void SetObjectPriority(u8 localId, u8 mapNum, u8 mapGroup, u8 subpriority) { u8 objectEventId; struct ObjectEvent *objectEvent; @@ -1933,7 +1933,7 @@ void sub_808E78C(u8 localId, u8 mapNum, u8 mapGroup, u8 subpriority) } } -void sub_808E7E4(u8 localId, u8 mapNum, u8 mapGroup) +void ResetObjectPriority(u8 localId, u8 mapNum, u8 mapGroup) { u8 objectEventId; struct ObjectEvent *objectEvent; diff --git a/src/scrcmd.c b/src/scrcmd.c index f36a44187..1feda180c 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -53,8 +53,8 @@ typedef u16 (*SpecialFunc)(void); typedef void (*NativeFunc)(void); -EWRAM_DATA const u8 *gUnknown_020375C0 = NULL; -static EWRAM_DATA u32 gUnknown_020375C4 = 0; +EWRAM_DATA const u8 *gRamScriptRetAddr = NULL; +static EWRAM_DATA u32 sAddressOffset = 0; // For relative addressing in vgoto etc., used by saved scripts (e.g. Mystery Event) static EWRAM_DATA u16 sPauseCounter = 0; static EWRAM_DATA u16 sMovingNpcId = 0; static EWRAM_DATA u16 sMovingNpcMapBank = 0; @@ -192,7 +192,7 @@ bool8 ScrCmd_setvaddress(struct ScriptContext *ctx) u32 addr1 = (u32)ctx->scriptPtr - 1; u32 addr2 = ScriptReadWord(ctx); - gUnknown_020375C4 = addr2 - addr1; + sAddressOffset = addr2 - addr1; return FALSE; } @@ -200,7 +200,7 @@ bool8 ScrCmd_vgoto(struct ScriptContext *ctx) { u32 addr = ScriptReadWord(ctx); - ScriptJump(ctx, (u8 *)(addr - gUnknown_020375C4)); + ScriptJump(ctx, (u8 *)(addr - sAddressOffset)); return FALSE; } @@ -208,14 +208,14 @@ bool8 ScrCmd_vcall(struct ScriptContext *ctx) { u32 addr = ScriptReadWord(ctx); - ScriptCall(ctx, (u8 *)(addr - gUnknown_020375C4)); + ScriptCall(ctx, (u8 *)(addr - sAddressOffset)); return FALSE; } bool8 ScrCmd_vgoto_if(struct ScriptContext *ctx) { u8 condition = ScriptReadByte(ctx); - const u8 *ptr = (const u8 *)(ScriptReadWord(ctx) - gUnknown_020375C4); + const u8 *ptr = (const u8 *)(ScriptReadWord(ctx) - sAddressOffset); if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) ScriptJump(ctx, ptr); @@ -225,7 +225,7 @@ bool8 ScrCmd_vgoto_if(struct ScriptContext *ctx) bool8 ScrCmd_vcall_if(struct ScriptContext *ctx) { u8 condition = ScriptReadByte(ctx); - const u8 *ptr = (const u8 *)(ScriptReadWord(ctx) - gUnknown_020375C4); + const u8 *ptr = (const u8 *)(ScriptReadWord(ctx) - sAddressOffset); if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) ScriptCall(ctx, ptr); @@ -282,7 +282,7 @@ bool8 ScrCmd_callstd_if(struct ScriptContext *ctx) bool8 ScrCmd_returnram(struct ScriptContext *ctx) { - ScriptJump(ctx, gUnknown_020375C0); + ScriptJump(ctx, gRamScriptRetAddr); return FALSE; } @@ -378,32 +378,30 @@ bool8 ScrCmd_setorcopyvar(struct ScriptContext *ctx) return FALSE; } -u8 compare_012(u16 a1, u16 a2) +u8 Compare(u16 a, u16 b) { - if (a1 < a2) + if (a < b) return 0; - if (a1 == a2) + if (a == b) return 1; return 2; } -// comparelocaltolocal bool8 ScrCmd_compare_local_to_local(struct ScriptContext *ctx) { const u8 value1 = ctx->data[ScriptReadByte(ctx)]; const u8 value2 = ctx->data[ScriptReadByte(ctx)]; - ctx->comparisonResult = compare_012(value1, value2); + ctx->comparisonResult = Compare(value1, value2); return FALSE; } -// comparelocaltoimm bool8 ScrCmd_compare_local_to_value(struct ScriptContext *ctx) { const u8 value1 = ctx->data[ScriptReadByte(ctx)]; const u8 value2 = ScriptReadByte(ctx); - ctx->comparisonResult = compare_012(value1, value2); + ctx->comparisonResult = Compare(value1, value2); return FALSE; } @@ -412,7 +410,7 @@ bool8 ScrCmd_compare_local_to_addr(struct ScriptContext *ctx) const u8 value1 = ctx->data[ScriptReadByte(ctx)]; const u8 value2 = *(const u8 *)ScriptReadWord(ctx); - ctx->comparisonResult = compare_012(value1, value2); + ctx->comparisonResult = Compare(value1, value2); return FALSE; } @@ -421,7 +419,7 @@ bool8 ScrCmd_compare_addr_to_local(struct ScriptContext *ctx) const u8 value1 = *(const u8 *)ScriptReadWord(ctx); const u8 value2 = ctx->data[ScriptReadByte(ctx)]; - ctx->comparisonResult = compare_012(value1, value2); + ctx->comparisonResult = Compare(value1, value2); return FALSE; } @@ -430,7 +428,7 @@ bool8 ScrCmd_compare_addr_to_value(struct ScriptContext *ctx) const u8 value1 = *(const u8 *)ScriptReadWord(ctx); const u8 value2 = ScriptReadByte(ctx); - ctx->comparisonResult = compare_012(value1, value2); + ctx->comparisonResult = Compare(value1, value2); return FALSE; } @@ -439,7 +437,7 @@ bool8 ScrCmd_compare_addr_to_addr(struct ScriptContext *ctx) const u8 value1 = *(const u8 *)ScriptReadWord(ctx); const u8 value2 = *(const u8 *)ScriptReadWord(ctx); - ctx->comparisonResult = compare_012(value1, value2); + ctx->comparisonResult = Compare(value1, value2); return FALSE; } @@ -448,7 +446,7 @@ bool8 ScrCmd_compare_var_to_value(struct ScriptContext *ctx) const u16 value1 = *GetVarPointer(ScriptReadHalfword(ctx)); const u16 value2 = ScriptReadHalfword(ctx); - ctx->comparisonResult = compare_012(value1, value2); + ctx->comparisonResult = Compare(value1, value2); return FALSE; } @@ -457,7 +455,7 @@ bool8 ScrCmd_compare_var_to_var(struct ScriptContext *ctx) const u16 *ptr1 = GetVarPointer(ScriptReadHalfword(ctx)); const u16 *ptr2 = GetVarPointer(ScriptReadHalfword(ctx)); - ctx->comparisonResult = compare_012(*ptr1, *ptr2); + ctx->comparisonResult = Compare(*ptr1, *ptr2); return FALSE; } @@ -1120,7 +1118,7 @@ bool8 ScrCmd_showobject_at(struct ScriptContext *ctx) u8 mapGroup = ScriptReadByte(ctx); u8 mapNum = ScriptReadByte(ctx); - npc_by_local_id_and_map_set_field_1_bit_x20(localId, mapNum, mapGroup, 0); + SetObjectInvisibility(localId, mapNum, mapGroup, FALSE); return FALSE; } @@ -1130,7 +1128,7 @@ bool8 ScrCmd_hideobject_at(struct ScriptContext *ctx) u8 mapGroup = ScriptReadByte(ctx); u8 mapNum = ScriptReadByte(ctx); - npc_by_local_id_and_map_set_field_1_bit_x20(localId, mapNum, mapGroup, 1); + SetObjectInvisibility(localId, mapNum, mapGroup, TRUE); return FALSE; } @@ -1141,7 +1139,7 @@ bool8 ScrCmd_setobjectpriority(struct ScriptContext *ctx) u8 mapNum = ScriptReadByte(ctx); u8 priority = ScriptReadByte(ctx); - sub_808E78C(localId, mapNum, mapGroup, priority + 83); + SetObjectPriority(localId, mapNum, mapGroup, priority + 83); return FALSE; } @@ -1151,7 +1149,7 @@ bool8 ScrCmd_resetobjectpriority(struct ScriptContext *ctx) u8 mapGroup = ScriptReadByte(ctx); u8 mapNum = ScriptReadByte(ctx); - sub_808E7E4(localId, mapNum, mapGroup); + ResetObjectPriority(localId, mapNum, mapGroup); return FALSE; } @@ -1299,7 +1297,8 @@ bool8 ScrCmd_messageautoscroll(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_cmdDB(struct ScriptContext *ctx) +// Prints all at once. Skips waiting for player input. Only used by link contests +bool8 ScrCmd_messageinstant(struct ScriptContext *ctx) { const u8 *msg = (const u8 *)ScriptReadWord(ctx); @@ -1489,27 +1488,30 @@ bool8 ScrCmd_braillemessage(struct ScriptContext *ctx) u8 xWindow, yWindow, xText, yText; u8 temp; + // + 6 for the 6 bytes at the start of a braille message (brailleformat macro) + // In RS these bytes are used to position the text and window, but + // in Emerald they are unused and position is calculated below instead StringExpandPlaceholders(gStringVar4, ptr + 6); width = GetStringWidth(6, gStringVar4, -1) / 8u; - if (width > 0x1C) - width = 0x1C; + if (width > 28) + width = 28; - for (i = 0, height = 4; gStringVar4[i] != 0xFF;) + for (i = 0, height = 4; gStringVar4[i] != EOS;) { - if (gStringVar4[i++] == 0xFE) + if (gStringVar4[i++] == CHAR_NEWLINE) height += 3; } - if (height > 0x12) - height = 0x12; + if (height > 18) + height = 18; temp = width + 2; - xWindow = (0x1E - temp) / 2; + xWindow = (30 - temp) / 2; temp = height + 2; - yText = (0x14 - temp) / 2; + yText = (20 - temp) / 2; xText = xWindow; xWindow += 1; @@ -1539,9 +1541,9 @@ bool8 ScrCmd_closebraillemessage(struct ScriptContext *ctx) bool8 ScrCmd_vmessage(struct ScriptContext *ctx) { - u32 v1 = ScriptReadWord(ctx); + u32 msg = ScriptReadWord(ctx); - ShowFieldMessage((u8 *)(v1 - gUnknown_020375C4)); + ShowFieldMessage((u8 *)(msg - sAddressOffset)); return FALSE; } @@ -1651,7 +1653,7 @@ bool8 ScrCmd_bufferstring(struct ScriptContext *ctx) bool8 ScrCmd_vloadword(struct ScriptContext *ctx) { - const u8 *ptr = (u8 *)(ScriptReadWord(ctx) - gUnknown_020375C4); + const u8 *ptr = (u8 *)(ScriptReadWord(ctx) - sAddressOffset); StringExpandPlaceholders(gStringVar4, ptr); return FALSE; @@ -1662,7 +1664,7 @@ bool8 ScrCmd_vbufferstring(struct ScriptContext *ctx) u8 stringVarIndex = ScriptReadByte(ctx); u32 addr = ScriptReadWord(ctx); - const u8 *src = (u8 *)(addr - gUnknown_020375C4); + const u8 *src = (u8 *)(addr - sAddressOffset); u8 *dest = sScriptStringVars[stringVarIndex]; StringCopy(dest, src); return FALSE; @@ -1900,6 +1902,7 @@ bool8 ScrCmd_pokemartdecoration(struct ScriptContext *ctx) return TRUE; } +// Changes clerk dialogue slightly from above. See MART_TYPE_DECOR2 bool8 ScrCmd_pokemartdecoration2(struct ScriptContext *ctx) { const void *ptr = (void *)ScriptReadWord(ctx); @@ -2104,6 +2107,7 @@ bool8 ScrCmd_setdoorclosed(struct ScriptContext *ctx) return FALSE; } +// Below two are functions for elevators in RS, do nothing in Emerald bool8 ScrCmd_addelevmenuitem(struct ScriptContext *ctx) { u8 v3 = ScriptReadByte(ctx); @@ -2135,9 +2139,9 @@ bool8 ScrCmd_addcoins(struct ScriptContext *ctx) u16 coins = VarGet(ScriptReadHalfword(ctx)); if (AddCoins(coins) == TRUE) - gSpecialVar_Result = 0; + gSpecialVar_Result = FALSE; else - gSpecialVar_Result = 1; + gSpecialVar_Result = TRUE; return FALSE; } @@ -2146,9 +2150,9 @@ bool8 ScrCmd_removecoins(struct ScriptContext *ctx) u16 coins = VarGet(ScriptReadHalfword(ctx)); if (RemoveCoins(coins) == TRUE) - gSpecialVar_Result = 0; + gSpecialVar_Result = FALSE; else - gSpecialVar_Result = 1; + gSpecialVar_Result = TRUE; return FALSE; } @@ -2180,7 +2184,7 @@ bool8 ScrCmd_freerotatingtilepuzzle(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_cmdD8(struct ScriptContext *ctx) +bool8 ScrCmd_selectapproachingtrainer(struct ScriptContext *ctx) { gSelectedObjectEvent = GetCurrentApproachingTrainerObjectEventId(); return FALSE; @@ -2225,12 +2229,12 @@ bool8 ScrCmd_checkmonobedience(struct ScriptContext *ctx) // See GetSavedRamScriptIfValid, which is NULL if ValidateReceivedWonderCard returns FALSE bool8 ScrCmd_gotoram(struct ScriptContext *ctx) { - const u8* v1 = GetSavedRamScriptIfValid(); + const u8* script = GetSavedRamScriptIfValid(); - if (v1) + if (script) { - gUnknown_020375C0 = ctx->scriptPtr; - ScriptJump(ctx, v1); + gRamScriptRetAddr = ctx->scriptPtr; + ScriptJump(ctx, script); } return FALSE; } diff --git a/src/script.c b/src/script.c index e6557aa75..69899fdb3 100644 --- a/src/script.c +++ b/src/script.c @@ -7,7 +7,7 @@ #define RAM_SCRIPT_MAGIC 51 -extern const u8* gUnknown_020375C0; +extern const u8* gRamScriptRetAddr; // ewram bss static u8 sScriptContext1Status; @@ -363,7 +363,7 @@ bool8 InitRamScript(const u8 *script, u16 scriptSize, u8 mapGroup, u8 mapNum, u8 const u8 *GetRamScript(u8 objectId, const u8 *script) { struct RamScriptData *scriptData = &gSaveBlock1Ptr->ramScript.data; - gUnknown_020375C0 = NULL; + gRamScriptRetAddr = NULL; if (scriptData->magic != RAM_SCRIPT_MAGIC) return script; if (scriptData->mapGroup != gSaveBlock1Ptr->location.mapGroup) @@ -379,7 +379,7 @@ const u8 *GetRamScript(u8 objectId, const u8 *script) } else { - gUnknown_020375C0 = script; + gRamScriptRetAddr = script; return scriptData->script; } } diff --git a/src/shop.c b/src/shop.c index a447982fc..04afc7d0b 100755 --- a/src/shop.c +++ b/src/shop.c @@ -965,8 +965,9 @@ static void Task_BuyMenu(u8 taskId) if (gMartInfo.martType == MART_TYPE_DECOR) StringExpandPlaceholders(gStringVar4, gText_Var1IsItThatllBeVar2); - else + else // MART_TYPE_DECOR2 StringExpandPlaceholders(gStringVar4, gText_YouWantedVar1ThatllBeVar2); + BuyMenuDisplayMessage(taskId, gStringVar4, BuyMenuConfirmPurchase); } } @@ -1069,13 +1070,9 @@ static void BuyMenuTryMakePurchase(u8 taskId) if (DecorationAdd(tItemId)) { if (gMartInfo.martType == MART_TYPE_DECOR) - { BuyMenuDisplayMessage(taskId, gText_ThankYouIllSendItHome, BuyMenuSubtractMoney); - } - else - { + else // MART_TYPE_DECOR2 BuyMenuDisplayMessage(taskId, gText_ThanksIllSendItHome, BuyMenuSubtractMoney); - } } else {