Clean up scrcmd.c

This commit is contained in:
GriffinR 2021-01-26 02:16:26 -05:00
parent 8fe4d004e3
commit 0064333e4a
11 changed files with 107 additions and 204 deletions

View File

@ -930,6 +930,17 @@
.4byte \text .4byte \text
.endm .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 @ 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 .macro givemon species:req, level:req, item:req
.byte 0x79 .byte 0x79
@ -1550,7 +1561,7 @@
.2byte \y .2byte \y
.endm .endm
.macro cmdD8 .macro selectapproachingtrainer
.byte 0xd8 .byte 0xd8
.endm .endm
@ -1562,7 +1573,7 @@
.byte 0xda .byte 0xda
.endm .endm
.macro message3 pointer:req .macro messageinstant pointer:req
.byte 0xdb .byte 0xdb
.4byte \pointer .4byte \pointer
.endm .endm

View File

@ -783,7 +783,7 @@ LilycoveCity_ContestLobby_EventScript_TrySetUpLinkContest:: @ 821AA15
goto_if_eq LilycoveCity_ContestLobby_EventScript_CancelLinkError goto_if_eq LilycoveCity_ContestLobby_EventScript_CancelLinkError
compare VAR_RESULT, LINKUP_FAILED_CONTEST_GMODE compare VAR_RESULT, LINKUP_FAILED_CONTEST_GMODE
goto_if_eq LilycoveCity_ContestLobby_EventScript_CancelLinkModeDifference goto_if_eq LilycoveCity_ContestLobby_EventScript_CancelLinkModeDifference
message3 LilycoveCity_ContestLobby_Text_Transmitting messageinstant LilycoveCity_ContestLobby_Text_Transmitting
contestlinktransfer contestlinktransfer
switch VAR_0x8004 switch VAR_0x8004
case 0, LilycoveCity_ContestLobby_EventScript_StartLinkContest case 0, LilycoveCity_ContestLobby_EventScript_StartLinkContest
@ -926,7 +926,7 @@ LilycoveCity_ContestLobby_EventScript_TryJoinLinkGroup:: @ 821AC38
return return
LilycoveCity_ContestLobby_EventScript_LinkLeaderDecided:: @ 821AC3D LilycoveCity_ContestLobby_EventScript_LinkLeaderDecided:: @ 821AC3D
message3 LilycoveCity_ContestLobby_Text_Transmitting messageinstant LilycoveCity_ContestLobby_Text_Transmitting
contestlinktransfer contestlinktransfer
goto LilycoveCity_ContestLobby_EventScript_StartLinkContest goto LilycoveCity_ContestLobby_EventScript_StartLinkContest
end end

View File

@ -216,10 +216,10 @@ gScriptCmdTable:: @ 81DB67C
.4byte ScrCmd_initrotatingtilepuzzle @ 0xd5 .4byte ScrCmd_initrotatingtilepuzzle @ 0xd5
.4byte ScrCmd_freerotatingtilepuzzle @ 0xd6 .4byte ScrCmd_freerotatingtilepuzzle @ 0xd6
.4byte ScrCmd_warpmossdeepgym @ 0xd7 .4byte ScrCmd_warpmossdeepgym @ 0xd7
.4byte ScrCmd_cmdD8 @ 0xd8 .4byte ScrCmd_selectapproachingtrainer @ 0xd8
.4byte ScrCmd_cmdD9 @ 0xd9 .4byte ScrCmd_cmdD9 @ 0xd9
.4byte ScrCmd_closebraillemessage @ 0xda .4byte ScrCmd_closebraillemessage @ 0xda
.4byte ScrCmd_cmdDB @ 0xdb .4byte ScrCmd_messageinstant @ 0xdb
.4byte ScrCmd_fadescreenswapbuffers @ 0xdc .4byte ScrCmd_fadescreenswapbuffers @ 0xdc
.4byte ScrCmd_buffertrainerclassname @ 0xdd .4byte ScrCmd_buffertrainerclassname @ 0xdd
.4byte ScrCmd_buffertrainername @ 0xde .4byte ScrCmd_buffertrainername @ 0xde

View File

@ -1,5 +1,5 @@
EventScript_271354:: @ 8271354 EventScript_271354:: @ 8271354
cmdD8 selectapproachingtrainer
cmdD9 cmdD9
EventScript_ShowSecondTrainerIntro:: @ 8271356 EventScript_ShowSecondTrainerIntro:: @ 8271356

View File

@ -1,222 +1,112 @@
Underwater_SealedChamber_Braille_GoUpHere: @ 82A6B15 Underwater_SealedChamber_Braille_GoUpHere: @ 82A6B15
.byte 4 brailleformat 4, 6, 26, 13, 7, 9
.byte 6
.byte 26
.byte 13
.byte 7
.byte 9
.braille "GO UP HERE.$" .braille "GO UP HERE.$"
SealedChamber_OuterRoom_Braille_ABC: @ 82A6B27 SealedChamber_OuterRoom_Braille_ABC: @ 82A6B27
.byte 7 brailleformat 7, 6, 21, 13, 10, 9
.byte 6
.byte 21
.byte 13
.byte 10
.byte 9
.braille "ABC$" .braille "ABC$"
SealedChamber_OuterRoom_Braille_GHI: @ 82A6B31 SealedChamber_OuterRoom_Braille_GHI: @ 82A6B31
.byte 7 brailleformat 7, 6, 21, 13, 10, 9
.byte 6
.byte 21
.byte 13
.byte 10
.byte 9
.braille "GHI$" .braille "GHI$"
SealedChamber_OuterRoom_Braille_MNO: @ 82A6B3B SealedChamber_OuterRoom_Braille_MNO: @ 82A6B3B
.byte 7 brailleformat 7, 6, 21, 13, 10, 9
.byte 6
.byte 21
.byte 13
.byte 10
.byte 9
.braille "MNO$" .braille "MNO$"
SealedChamber_OuterRoom_Braille_TUV: @ 82A6B45 SealedChamber_OuterRoom_Braille_TUV: @ 82A6B45
.byte 7 brailleformat 7, 6, 21, 13, 10, 9
.byte 6
.byte 21
.byte 13
.byte 10
.byte 9
.braille "TUV$" .braille "TUV$"
SealedChamber_OuterRoom_Braille_DEF: @ 82A6B4F SealedChamber_OuterRoom_Braille_DEF: @ 82A6B4F
.byte 7 brailleformat 7, 6, 21, 13, 10, 9
.byte 6
.byte 21
.byte 13
.byte 10
.byte 9
.braille "DEF$" .braille "DEF$"
SealedChamber_OuterRoom_Braille_JKL: @ 82A6B59 SealedChamber_OuterRoom_Braille_JKL: @ 82A6B59
.byte 7 brailleformat 7, 6, 21, 13, 10, 9
.byte 6
.byte 21
.byte 13
.byte 10
.byte 9
.braille "JKL$" .braille "JKL$"
SealedChamber_OuterRoom_Braille_PQRS: @ 82A6B63 SealedChamber_OuterRoom_Braille_PQRS: @ 82A6B63
.byte 7 brailleformat 7, 6, 21, 13, 10, 9
.byte 6
.byte 21
.byte 13
.byte 10
.byte 9
.braille "PQRS$" .braille "PQRS$"
SealedChamber_OuterRoom_Braille_Period: @ 82A6B6E SealedChamber_OuterRoom_Braille_Period: @ 82A6B6E
.byte 9 brailleformat 9, 6, 19, 13, 12, 9
.byte 6
.byte 19
.byte 13
.byte 12
.byte 9
.braille ".$" .braille ".$"
SealedChamber_OuterRoom_Braille_WXYZ: @ 82A6B76 SealedChamber_OuterRoom_Braille_WXYZ: @ 82A6B76
.byte 7 brailleformat 7, 6, 21, 13, 10, 9
.byte 6
.byte 21
.byte 13
.byte 10
.byte 9
.braille "WXYZ$" .braille "WXYZ$"
SealedChamber_OuterRoom_Braille_Comma: @ 82A6B81 SealedChamber_OuterRoom_Braille_Comma: @ 82A6B81
.byte 9 brailleformat 9, 6, 19, 13, 12, 9
.byte 6
.byte 19
.byte 13
.byte 12
.byte 9
.braille ",$" .braille ",$"
SealedChamber_OuterRoom_Braille_DigHere: @ 82A6B89 SealedChamber_OuterRoom_Braille_DigHere: @ 82A6B89
.byte 7 brailleformat 7, 4, 23, 15, 10, 7
.byte 4
.byte 23
.byte 15
.byte 10
.byte 7
.braille "DIG HERE.$" .braille "DIG HERE.$"
SealedChamber_InnerRoom_Braille_FirstWailordLastRelicanth: @ 82A6B99 SealedChamber_InnerRoom_Braille_FirstWailordLastRelicanth: @ 82A6B99
.byte 0 brailleformat 0, 0, 29, 19, 3, 3
.byte 0
.byte 29
.byte 19
.byte 3
.byte 3
.braille "FIRST COMES\n" .braille "FIRST COMES\n"
.braille "WAILORD.\n" .braille "WAILORD.\n"
.braille "LAST COMES\n" .braille "LAST COMES\n"
.braille "RELICANTH.$" .braille "RELICANTH.$"
SealedChamber_InnerRoom_Braille_InThisCaveWeHaveLived: @ 82A6BCA SealedChamber_InnerRoom_Braille_InThisCaveWeHaveLived: @ 82A6BCA
.byte 2 brailleformat 2, 0, 26, 19, 5, 3
.byte 0
.byte 26
.byte 19
.byte 5
.byte 3
.braille "IN THIS\n" .braille "IN THIS\n"
.braille "CAVE WE\n" .braille "CAVE WE\n"
.braille "HAVE\n" .braille "HAVE\n"
.braille "LIVED.$" .braille "LIVED.$"
SealedChamber_InnerRoom_Braille_WeOweAllToThePokemon: @ 82A6BEC SealedChamber_InnerRoom_Braille_WeOweAllToThePokemon: @ 82A6BEC
.byte 7 brailleformat 7, 2, 23, 17, 10, 5
.byte 2
.byte 23
.byte 17
.byte 10
.byte 5
.braille "WE OWE ALL\n" .braille "WE OWE ALL\n"
.braille "TO THE\n" .braille "TO THE\n"
.braille "POKEMON.$" .braille "POKEMON.$"
SealedChamber_InnerRoom_Braille_ButWeSealedThePokemonAway: @ 82A6C0D SealedChamber_InnerRoom_Braille_ButWeSealedThePokemonAway: @ 82A6C0D
.byte 3 brailleformat 3, 0, 25, 19, 6, 3
.byte 0
.byte 25
.byte 19
.byte 6
.byte 3
.braille "BUT, WE\n" .braille "BUT, WE\n"
.braille "SEALED THE\n" .braille "SEALED THE\n"
.braille "POKEMON\n" .braille "POKEMON\n"
.braille "AWAY.$" .braille "AWAY.$"
SealedChamber_InnerRoom_Braille_WeFearedIt: @ 82A6C34 SealedChamber_InnerRoom_Braille_WeFearedIt: @ 82A6C34
.byte 5 brailleformat 5, 6, 25, 13, 8, 9
.byte 6
.byte 25
.byte 13
.byte 8
.byte 9
.braille "WE FEARED IT.$" .braille "WE FEARED IT.$"
SealedChamber_InnerRoom_Braille_ThoseWithCourageHope: @ 82A6C48 SealedChamber_InnerRoom_Braille_ThoseWithCourageHope: @ 82A6C48
.byte 6 brailleformat 6, 0, 24, 19, 9, 3
.byte 0
.byte 24
.byte 19
.byte 9
.byte 3
.braille "THOSE WITH\n" .braille "THOSE WITH\n"
.braille "COURAGE,\n" .braille "COURAGE,\n"
.braille "THOSE WITH\n" .braille "THOSE WITH\n"
.braille "HOPE.$" .braille "HOPE.$"
SealedChamber_InnerRoom_Braille_OpenDoorEternalPokemonWaits: @ 82A6C73 SealedChamber_InnerRoom_Braille_OpenDoorEternalPokemonWaits: @ 82A6C73
.byte 3 brailleformat 3, 2, 27, 17, 6, 5
.byte 2
.byte 27
.byte 17
.byte 6
.byte 5
.braille "OPEN A DOOR.\n" .braille "OPEN A DOOR.\n"
.braille "AN ETERNAL\n" .braille "AN ETERNAL\n"
.braille "POKEMON\n" .braille "POKEMON\n"
.braille "WAITS.$" .braille "WAITS.$"
DesertRuins_Braille_UseRockSmash: @ 82A6CA0 DesertRuins_Braille_UseRockSmash: @ 82A6CA0
.byte 1 brailleformat 1, 0, 27, 19, 4, 3
.byte 0
.byte 27
.byte 19
.byte 4
.byte 3
.braille "LEFT, LEFT,\n" .braille "LEFT, LEFT,\n"
.braille "DOWN, DOWN.\n" .braille "DOWN, DOWN.\n"
.braille "THEN, USE\n" .braille "THEN, USE\n"
.braille "ROCK SMASH.$" .braille "ROCK SMASH.$"
IslandCave_Braille_RunLapAroundWall: @ 82A6CD4 IslandCave_Braille_RunLapAroundWall: @ 82A6CD4
.byte 5 brailleformat 5, 0, 25, 19, 8, 3
.byte 0
.byte 25
.byte 19
.byte 8
.byte 3
.braille "STAY CLOSE\n" .braille "STAY CLOSE\n"
.braille "TO THE WALL.\n" .braille "TO THE WALL.\n"
.braille "RUN AROUND\n" .braille "RUN AROUND\n"
.braille "ONE LAP.$" .braille "ONE LAP.$"
AncientTomb_Braille_ShineInTheMiddle: @ 82A6D06 AncientTomb_Braille_ShineInTheMiddle: @ 82A6D06
.byte 3 brailleformat 3, 0, 25, 19, 6, 3
.byte 0
.byte 25
.byte 19
.byte 6
.byte 3
.braille "THOSE WHO\n" .braille "THOSE WHO\n"
.braille "INHERIT OUR\n" .braille "INHERIT OUR\n"
.braille "WILL, SHINE\n" .braille "WILL, SHINE\n"

View File

@ -39,8 +39,6 @@
// These are the "abnormal weather events" that are used // These are the "abnormal weather events" that are used
// to find Kyogre and Groudon. // to find Kyogre and Groudon.
#define ABNORMAL_WEATHER_LOCATIONS (MARINE_CAVE_LOCATIONS + TERRA_CAVE_LOCATIONS)
#define ABNORMAL_WEATHER_NONE 0
// Groudon/Terra Cave locations // Groudon/Terra Cave locations
#define TERRA_CAVE_LOCATIONS_START 1 #define TERRA_CAVE_LOCATIONS_START 1
@ -66,4 +64,7 @@
#define ABNORMAL_WEATHER_ROUTE_129_EAST (MARINE_CAVE_LOCATIONS_START + 7) #define ABNORMAL_WEATHER_ROUTE_129_EAST (MARINE_CAVE_LOCATIONS_START + 7)
#define MARINE_CAVE_LOCATIONS 8 #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 #endif // GUARD_CONSTANTS_WEATHER_H

View File

@ -106,11 +106,11 @@ void ObjectEventSetGraphicsId(struct ObjectEvent *, u8 graphicsId);
void ObjectEventTurn(struct ObjectEvent *, u8); void ObjectEventTurn(struct ObjectEvent *, u8);
void ObjectEventTurnByLocalIdAndMap(u8, u8, u8, u8); void ObjectEventTurnByLocalIdAndMap(u8, u8, u8, u8);
const struct ObjectEventGraphicsInfo *GetObjectEventGraphicsInfo(u8 graphicsId); 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 FreeAndReserveObjectSpritePalettes(void);
void SetObjectEventSpritePosByLocalIdAndMap(u8 localId, u8 mapNum, u8 mapGroup, s16 x, s16 y); void SetObjectEventSpritePosByLocalIdAndMap(u8 localId, u8 mapNum, u8 mapGroup, s16 x, s16 y);
void sub_808E7E4(u8, u8, u8); void ResetObjectPriority(u8, u8, u8);
void sub_808E78C(u8, u8, u8, u8); void SetObjectPriority(u8, u8, u8, u8);
void sub_808E75C(s16, s16); void sub_808E75C(s16, s16);
void ObjectEventGetLocalIdAndMap(struct ObjectEvent *objectEvent, void *localId, void *mapNum, void *mapGroup); void ObjectEventGetLocalIdAndMap(struct ObjectEvent *objectEvent, void *localId, void *mapNum, void *mapGroup);
void ShiftObjectEventCoords(struct ObjectEvent *, s16, s16); void ShiftObjectEventCoords(struct ObjectEvent *, s16, s16);

View File

@ -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; u8 objectEventId;
if (!TryGetObjectEventIdByLocalIdAndMap(localId, mapNum, mapGroup, &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; u8 objectEventId;
struct ObjectEvent *objectEvent; 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; u8 objectEventId;
struct ObjectEvent *objectEvent; struct ObjectEvent *objectEvent;

View File

@ -53,8 +53,8 @@
typedef u16 (*SpecialFunc)(void); typedef u16 (*SpecialFunc)(void);
typedef void (*NativeFunc)(void); typedef void (*NativeFunc)(void);
EWRAM_DATA const u8 *gUnknown_020375C0 = NULL; EWRAM_DATA const u8 *gRamScriptRetAddr = NULL;
static EWRAM_DATA u32 gUnknown_020375C4 = 0; 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 sPauseCounter = 0;
static EWRAM_DATA u16 sMovingNpcId = 0; static EWRAM_DATA u16 sMovingNpcId = 0;
static EWRAM_DATA u16 sMovingNpcMapBank = 0; static EWRAM_DATA u16 sMovingNpcMapBank = 0;
@ -192,7 +192,7 @@ bool8 ScrCmd_setvaddress(struct ScriptContext *ctx)
u32 addr1 = (u32)ctx->scriptPtr - 1; u32 addr1 = (u32)ctx->scriptPtr - 1;
u32 addr2 = ScriptReadWord(ctx); u32 addr2 = ScriptReadWord(ctx);
gUnknown_020375C4 = addr2 - addr1; sAddressOffset = addr2 - addr1;
return FALSE; return FALSE;
} }
@ -200,7 +200,7 @@ bool8 ScrCmd_vgoto(struct ScriptContext *ctx)
{ {
u32 addr = ScriptReadWord(ctx); u32 addr = ScriptReadWord(ctx);
ScriptJump(ctx, (u8 *)(addr - gUnknown_020375C4)); ScriptJump(ctx, (u8 *)(addr - sAddressOffset));
return FALSE; return FALSE;
} }
@ -208,14 +208,14 @@ bool8 ScrCmd_vcall(struct ScriptContext *ctx)
{ {
u32 addr = ScriptReadWord(ctx); u32 addr = ScriptReadWord(ctx);
ScriptCall(ctx, (u8 *)(addr - gUnknown_020375C4)); ScriptCall(ctx, (u8 *)(addr - sAddressOffset));
return FALSE; return FALSE;
} }
bool8 ScrCmd_vgoto_if(struct ScriptContext *ctx) bool8 ScrCmd_vgoto_if(struct ScriptContext *ctx)
{ {
u8 condition = ScriptReadByte(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) if (sScriptConditionTable[condition][ctx->comparisonResult] == 1)
ScriptJump(ctx, ptr); ScriptJump(ctx, ptr);
@ -225,7 +225,7 @@ bool8 ScrCmd_vgoto_if(struct ScriptContext *ctx)
bool8 ScrCmd_vcall_if(struct ScriptContext *ctx) bool8 ScrCmd_vcall_if(struct ScriptContext *ctx)
{ {
u8 condition = ScriptReadByte(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) if (sScriptConditionTable[condition][ctx->comparisonResult] == 1)
ScriptCall(ctx, ptr); ScriptCall(ctx, ptr);
@ -282,7 +282,7 @@ bool8 ScrCmd_callstd_if(struct ScriptContext *ctx)
bool8 ScrCmd_returnram(struct ScriptContext *ctx) bool8 ScrCmd_returnram(struct ScriptContext *ctx)
{ {
ScriptJump(ctx, gUnknown_020375C0); ScriptJump(ctx, gRamScriptRetAddr);
return FALSE; return FALSE;
} }
@ -378,32 +378,30 @@ bool8 ScrCmd_setorcopyvar(struct ScriptContext *ctx)
return FALSE; return FALSE;
} }
u8 compare_012(u16 a1, u16 a2) u8 Compare(u16 a, u16 b)
{ {
if (a1 < a2) if (a < b)
return 0; return 0;
if (a1 == a2) if (a == b)
return 1; return 1;
return 2; return 2;
} }
// comparelocaltolocal
bool8 ScrCmd_compare_local_to_local(struct ScriptContext *ctx) bool8 ScrCmd_compare_local_to_local(struct ScriptContext *ctx)
{ {
const u8 value1 = ctx->data[ScriptReadByte(ctx)]; const u8 value1 = ctx->data[ScriptReadByte(ctx)];
const u8 value2 = ctx->data[ScriptReadByte(ctx)]; const u8 value2 = ctx->data[ScriptReadByte(ctx)];
ctx->comparisonResult = compare_012(value1, value2); ctx->comparisonResult = Compare(value1, value2);
return FALSE; return FALSE;
} }
// comparelocaltoimm
bool8 ScrCmd_compare_local_to_value(struct ScriptContext *ctx) bool8 ScrCmd_compare_local_to_value(struct ScriptContext *ctx)
{ {
const u8 value1 = ctx->data[ScriptReadByte(ctx)]; const u8 value1 = ctx->data[ScriptReadByte(ctx)];
const u8 value2 = ScriptReadByte(ctx); const u8 value2 = ScriptReadByte(ctx);
ctx->comparisonResult = compare_012(value1, value2); ctx->comparisonResult = Compare(value1, value2);
return FALSE; return FALSE;
} }
@ -412,7 +410,7 @@ bool8 ScrCmd_compare_local_to_addr(struct ScriptContext *ctx)
const u8 value1 = ctx->data[ScriptReadByte(ctx)]; const u8 value1 = ctx->data[ScriptReadByte(ctx)];
const u8 value2 = *(const u8 *)ScriptReadWord(ctx); const u8 value2 = *(const u8 *)ScriptReadWord(ctx);
ctx->comparisonResult = compare_012(value1, value2); ctx->comparisonResult = Compare(value1, value2);
return FALSE; return FALSE;
} }
@ -421,7 +419,7 @@ bool8 ScrCmd_compare_addr_to_local(struct ScriptContext *ctx)
const u8 value1 = *(const u8 *)ScriptReadWord(ctx); const u8 value1 = *(const u8 *)ScriptReadWord(ctx);
const u8 value2 = ctx->data[ScriptReadByte(ctx)]; const u8 value2 = ctx->data[ScriptReadByte(ctx)];
ctx->comparisonResult = compare_012(value1, value2); ctx->comparisonResult = Compare(value1, value2);
return FALSE; return FALSE;
} }
@ -430,7 +428,7 @@ bool8 ScrCmd_compare_addr_to_value(struct ScriptContext *ctx)
const u8 value1 = *(const u8 *)ScriptReadWord(ctx); const u8 value1 = *(const u8 *)ScriptReadWord(ctx);
const u8 value2 = ScriptReadByte(ctx); const u8 value2 = ScriptReadByte(ctx);
ctx->comparisonResult = compare_012(value1, value2); ctx->comparisonResult = Compare(value1, value2);
return FALSE; return FALSE;
} }
@ -439,7 +437,7 @@ bool8 ScrCmd_compare_addr_to_addr(struct ScriptContext *ctx)
const u8 value1 = *(const u8 *)ScriptReadWord(ctx); const u8 value1 = *(const u8 *)ScriptReadWord(ctx);
const u8 value2 = *(const u8 *)ScriptReadWord(ctx); const u8 value2 = *(const u8 *)ScriptReadWord(ctx);
ctx->comparisonResult = compare_012(value1, value2); ctx->comparisonResult = Compare(value1, value2);
return FALSE; return FALSE;
} }
@ -448,7 +446,7 @@ bool8 ScrCmd_compare_var_to_value(struct ScriptContext *ctx)
const u16 value1 = *GetVarPointer(ScriptReadHalfword(ctx)); const u16 value1 = *GetVarPointer(ScriptReadHalfword(ctx));
const u16 value2 = ScriptReadHalfword(ctx); const u16 value2 = ScriptReadHalfword(ctx);
ctx->comparisonResult = compare_012(value1, value2); ctx->comparisonResult = Compare(value1, value2);
return FALSE; return FALSE;
} }
@ -457,7 +455,7 @@ bool8 ScrCmd_compare_var_to_var(struct ScriptContext *ctx)
const u16 *ptr1 = GetVarPointer(ScriptReadHalfword(ctx)); const u16 *ptr1 = GetVarPointer(ScriptReadHalfword(ctx));
const u16 *ptr2 = GetVarPointer(ScriptReadHalfword(ctx)); const u16 *ptr2 = GetVarPointer(ScriptReadHalfword(ctx));
ctx->comparisonResult = compare_012(*ptr1, *ptr2); ctx->comparisonResult = Compare(*ptr1, *ptr2);
return FALSE; return FALSE;
} }
@ -1120,7 +1118,7 @@ bool8 ScrCmd_showobject_at(struct ScriptContext *ctx)
u8 mapGroup = ScriptReadByte(ctx); u8 mapGroup = ScriptReadByte(ctx);
u8 mapNum = 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; return FALSE;
} }
@ -1130,7 +1128,7 @@ bool8 ScrCmd_hideobject_at(struct ScriptContext *ctx)
u8 mapGroup = ScriptReadByte(ctx); u8 mapGroup = ScriptReadByte(ctx);
u8 mapNum = 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; return FALSE;
} }
@ -1141,7 +1139,7 @@ bool8 ScrCmd_setobjectpriority(struct ScriptContext *ctx)
u8 mapNum = ScriptReadByte(ctx); u8 mapNum = ScriptReadByte(ctx);
u8 priority = ScriptReadByte(ctx); u8 priority = ScriptReadByte(ctx);
sub_808E78C(localId, mapNum, mapGroup, priority + 83); SetObjectPriority(localId, mapNum, mapGroup, priority + 83);
return FALSE; return FALSE;
} }
@ -1151,7 +1149,7 @@ bool8 ScrCmd_resetobjectpriority(struct ScriptContext *ctx)
u8 mapGroup = ScriptReadByte(ctx); u8 mapGroup = ScriptReadByte(ctx);
u8 mapNum = ScriptReadByte(ctx); u8 mapNum = ScriptReadByte(ctx);
sub_808E7E4(localId, mapNum, mapGroup); ResetObjectPriority(localId, mapNum, mapGroup);
return FALSE; return FALSE;
} }
@ -1299,7 +1297,8 @@ bool8 ScrCmd_messageautoscroll(struct ScriptContext *ctx)
return FALSE; 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); const u8 *msg = (const u8 *)ScriptReadWord(ctx);
@ -1489,27 +1488,30 @@ bool8 ScrCmd_braillemessage(struct ScriptContext *ctx)
u8 xWindow, yWindow, xText, yText; u8 xWindow, yWindow, xText, yText;
u8 temp; 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); StringExpandPlaceholders(gStringVar4, ptr + 6);
width = GetStringWidth(6, gStringVar4, -1) / 8u; width = GetStringWidth(6, gStringVar4, -1) / 8u;
if (width > 0x1C) if (width > 28)
width = 0x1C; 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; height += 3;
} }
if (height > 0x12) if (height > 18)
height = 0x12; height = 18;
temp = width + 2; temp = width + 2;
xWindow = (0x1E - temp) / 2; xWindow = (30 - temp) / 2;
temp = height + 2; temp = height + 2;
yText = (0x14 - temp) / 2; yText = (20 - temp) / 2;
xText = xWindow; xText = xWindow;
xWindow += 1; xWindow += 1;
@ -1539,9 +1541,9 @@ bool8 ScrCmd_closebraillemessage(struct ScriptContext *ctx)
bool8 ScrCmd_vmessage(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; return FALSE;
} }
@ -1651,7 +1653,7 @@ bool8 ScrCmd_bufferstring(struct ScriptContext *ctx)
bool8 ScrCmd_vloadword(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); StringExpandPlaceholders(gStringVar4, ptr);
return FALSE; return FALSE;
@ -1662,7 +1664,7 @@ bool8 ScrCmd_vbufferstring(struct ScriptContext *ctx)
u8 stringVarIndex = ScriptReadByte(ctx); u8 stringVarIndex = ScriptReadByte(ctx);
u32 addr = ScriptReadWord(ctx); u32 addr = ScriptReadWord(ctx);
const u8 *src = (u8 *)(addr - gUnknown_020375C4); const u8 *src = (u8 *)(addr - sAddressOffset);
u8 *dest = sScriptStringVars[stringVarIndex]; u8 *dest = sScriptStringVars[stringVarIndex];
StringCopy(dest, src); StringCopy(dest, src);
return FALSE; return FALSE;
@ -1900,6 +1902,7 @@ bool8 ScrCmd_pokemartdecoration(struct ScriptContext *ctx)
return TRUE; return TRUE;
} }
// Changes clerk dialogue slightly from above. See MART_TYPE_DECOR2
bool8 ScrCmd_pokemartdecoration2(struct ScriptContext *ctx) bool8 ScrCmd_pokemartdecoration2(struct ScriptContext *ctx)
{ {
const void *ptr = (void *)ScriptReadWord(ctx); const void *ptr = (void *)ScriptReadWord(ctx);
@ -2104,6 +2107,7 @@ bool8 ScrCmd_setdoorclosed(struct ScriptContext *ctx)
return FALSE; return FALSE;
} }
// Below two are functions for elevators in RS, do nothing in Emerald
bool8 ScrCmd_addelevmenuitem(struct ScriptContext *ctx) bool8 ScrCmd_addelevmenuitem(struct ScriptContext *ctx)
{ {
u8 v3 = ScriptReadByte(ctx); u8 v3 = ScriptReadByte(ctx);
@ -2135,9 +2139,9 @@ bool8 ScrCmd_addcoins(struct ScriptContext *ctx)
u16 coins = VarGet(ScriptReadHalfword(ctx)); u16 coins = VarGet(ScriptReadHalfword(ctx));
if (AddCoins(coins) == TRUE) if (AddCoins(coins) == TRUE)
gSpecialVar_Result = 0; gSpecialVar_Result = FALSE;
else else
gSpecialVar_Result = 1; gSpecialVar_Result = TRUE;
return FALSE; return FALSE;
} }
@ -2146,9 +2150,9 @@ bool8 ScrCmd_removecoins(struct ScriptContext *ctx)
u16 coins = VarGet(ScriptReadHalfword(ctx)); u16 coins = VarGet(ScriptReadHalfword(ctx));
if (RemoveCoins(coins) == TRUE) if (RemoveCoins(coins) == TRUE)
gSpecialVar_Result = 0; gSpecialVar_Result = FALSE;
else else
gSpecialVar_Result = 1; gSpecialVar_Result = TRUE;
return FALSE; return FALSE;
} }
@ -2180,7 +2184,7 @@ bool8 ScrCmd_freerotatingtilepuzzle(struct ScriptContext *ctx)
return FALSE; return FALSE;
} }
bool8 ScrCmd_cmdD8(struct ScriptContext *ctx) bool8 ScrCmd_selectapproachingtrainer(struct ScriptContext *ctx)
{ {
gSelectedObjectEvent = GetCurrentApproachingTrainerObjectEventId(); gSelectedObjectEvent = GetCurrentApproachingTrainerObjectEventId();
return FALSE; return FALSE;
@ -2225,12 +2229,12 @@ bool8 ScrCmd_checkmonobedience(struct ScriptContext *ctx)
// See GetSavedRamScriptIfValid, which is NULL if ValidateReceivedWonderCard returns FALSE // See GetSavedRamScriptIfValid, which is NULL if ValidateReceivedWonderCard returns FALSE
bool8 ScrCmd_gotoram(struct ScriptContext *ctx) bool8 ScrCmd_gotoram(struct ScriptContext *ctx)
{ {
const u8* v1 = GetSavedRamScriptIfValid(); const u8* script = GetSavedRamScriptIfValid();
if (v1) if (script)
{ {
gUnknown_020375C0 = ctx->scriptPtr; gRamScriptRetAddr = ctx->scriptPtr;
ScriptJump(ctx, v1); ScriptJump(ctx, script);
} }
return FALSE; return FALSE;
} }

View File

@ -7,7 +7,7 @@
#define RAM_SCRIPT_MAGIC 51 #define RAM_SCRIPT_MAGIC 51
extern const u8* gUnknown_020375C0; extern const u8* gRamScriptRetAddr;
// ewram bss // ewram bss
static u8 sScriptContext1Status; 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) const u8 *GetRamScript(u8 objectId, const u8 *script)
{ {
struct RamScriptData *scriptData = &gSaveBlock1Ptr->ramScript.data; struct RamScriptData *scriptData = &gSaveBlock1Ptr->ramScript.data;
gUnknown_020375C0 = NULL; gRamScriptRetAddr = NULL;
if (scriptData->magic != RAM_SCRIPT_MAGIC) if (scriptData->magic != RAM_SCRIPT_MAGIC)
return script; return script;
if (scriptData->mapGroup != gSaveBlock1Ptr->location.mapGroup) if (scriptData->mapGroup != gSaveBlock1Ptr->location.mapGroup)
@ -379,7 +379,7 @@ const u8 *GetRamScript(u8 objectId, const u8 *script)
} }
else else
{ {
gUnknown_020375C0 = script; gRamScriptRetAddr = script;
return scriptData->script; return scriptData->script;
} }
} }

View File

@ -965,8 +965,9 @@ static void Task_BuyMenu(u8 taskId)
if (gMartInfo.martType == MART_TYPE_DECOR) if (gMartInfo.martType == MART_TYPE_DECOR)
StringExpandPlaceholders(gStringVar4, gText_Var1IsItThatllBeVar2); StringExpandPlaceholders(gStringVar4, gText_Var1IsItThatllBeVar2);
else else // MART_TYPE_DECOR2
StringExpandPlaceholders(gStringVar4, gText_YouWantedVar1ThatllBeVar2); StringExpandPlaceholders(gStringVar4, gText_YouWantedVar1ThatllBeVar2);
BuyMenuDisplayMessage(taskId, gStringVar4, BuyMenuConfirmPurchase); BuyMenuDisplayMessage(taskId, gStringVar4, BuyMenuConfirmPurchase);
} }
} }
@ -1069,13 +1070,9 @@ static void BuyMenuTryMakePurchase(u8 taskId)
if (DecorationAdd(tItemId)) if (DecorationAdd(tItemId))
{ {
if (gMartInfo.martType == MART_TYPE_DECOR) if (gMartInfo.martType == MART_TYPE_DECOR)
{
BuyMenuDisplayMessage(taskId, gText_ThankYouIllSendItHome, BuyMenuSubtractMoney); BuyMenuDisplayMessage(taskId, gText_ThankYouIllSendItHome, BuyMenuSubtractMoney);
} else // MART_TYPE_DECOR2
else
{
BuyMenuDisplayMessage(taskId, gText_ThanksIllSendItHome, BuyMenuSubtractMoney); BuyMenuDisplayMessage(taskId, gText_ThanksIllSendItHome, BuyMenuSubtractMoney);
}
} }
else else
{ {