From f300f853c8675817d00bbbc0caf57e5f80d6b573 Mon Sep 17 00:00:00 2001 From: Diegoisawesome Date: Thu, 12 Oct 2017 14:36:26 -0500 Subject: [PATCH] Add const qualifiers to scrcmd --- include/script.h | 4 +- include/script_movement.h | 2 +- include/shop.h | 6 +-- include/text.h | 2 +- src/scrcmd.c | 98 +++++++++++++++++++-------------------- src/script.c | 4 +- src/text.c | 2 +- 7 files changed, 59 insertions(+), 59 deletions(-) diff --git a/include/script.h b/include/script.h index ec6a212bc..2b5f8c2ce 100644 --- a/include/script.h +++ b/include/script.h @@ -28,8 +28,8 @@ void StopScript(struct ScriptContext *ctx); bool8 RunScriptCommand(struct ScriptContext *ctx); u8 ScriptPush(struct ScriptContext *ctx, const u8 *ptr); const u8 *ScriptPop(struct ScriptContext *ctx); -void ScriptJump(struct ScriptContext *ctx, u8 *ptr); -void ScriptCall(struct ScriptContext *ctx, u8 *ptr); +void ScriptJump(struct ScriptContext *ctx, const u8 *ptr); +void ScriptCall(struct ScriptContext *ctx, const u8 *ptr); void ScriptReturn(struct ScriptContext *ctx); u16 ScriptReadHalfword(struct ScriptContext *ctx); u32 ScriptReadWord(struct ScriptContext *ctx); diff --git a/include/script_movement.h b/include/script_movement.h index 8f505cc67..4c3fa6002 100644 --- a/include/script_movement.h +++ b/include/script_movement.h @@ -1,7 +1,7 @@ #ifndef GUARD_SCRIPT_MOVEMENT_H #define GUARD_SCRIPT_MOVEMENT_H -bool8 ScriptMovement_StartObjectMovementScript(u8, u8, u8, u8 *); +bool8 ScriptMovement_StartObjectMovementScript(u8, u8, u8, const u8 *); bool8 ScriptMovement_IsObjectMovementFinished(u8, u8, u8); void sub_80D338C(void); diff --git a/include/shop.h b/include/shop.h index d14c839ee..ee2887779 100644 --- a/include/shop.h +++ b/include/shop.h @@ -1,8 +1,8 @@ #ifndef GUARD_SHOP_H #define GUARD_SHOP_H -void CreatePokemartMenu(u16 *); -void CreateDecorationShop1Menu(u16 *); -void CreateDecorationShop2Menu(u16 *); +void CreatePokemartMenu(const u16 *); +void CreateDecorationShop1Menu(const u16 *); +void CreateDecorationShop2Menu(const u16 *); #endif // GUARD_SHOP_H diff --git a/include/text.h b/include/text.h index c3b27f7f1..594661717 100644 --- a/include/text.h +++ b/include/text.h @@ -196,7 +196,7 @@ u8 gGlyphDimensions[0x2]; void SetFontsPointer(const struct FontInfo *fonts); void DeactivateAllTextPrinters(void); -u16 PrintTextOnWindow(u8 windowId, u8 fontId, u8 *str, u8 x, u8 y, u8 speed, void (*callback)(struct TextSubPrinter *, u16)); +u16 PrintTextOnWindow(u8 windowId, u8 fontId, const u8 *str, u8 x, u8 y, u8 speed, void (*callback)(struct TextSubPrinter *, u16)); bool16 AddTextPrinter(struct TextSubPrinter *textSubPrinter, u8 speed, void (*callback)(struct TextSubPrinter *, u16)); void RunTextPrinters(void); bool16 IsTextPrinterActive(u8 id); diff --git a/src/scrcmd.c b/src/scrcmd.c index f2c11e4b0..1bc7d709a 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -73,9 +73,9 @@ extern u16 gScriptContestCategory; IWRAM_DATA u8 gUnknown_03000F30; -extern SpecialFunc gSpecials[]; -extern u8 *gStdScripts[]; -extern u8 *gStdScripts_End[]; +extern const SpecialFunc gSpecials[]; +extern const u8 *gStdScripts[]; +extern const u8 *gStdScripts_End[]; void sub_809BDB4(void); @@ -157,7 +157,7 @@ bool8 ScrCmd_waitstate(struct ScriptContext *ctx) bool8 ScrCmd_goto(struct ScriptContext *ctx) { - u8 *ptr = (u8 *)ScriptReadWord(ctx); + const u8 *ptr = (const u8 *)ScriptReadWord(ctx); ScriptJump(ctx, ptr); return FALSE; @@ -171,7 +171,7 @@ bool8 ScrCmd_return(struct ScriptContext *ctx) bool8 ScrCmd_call(struct ScriptContext *ctx) { - u8 *ptr = (u8 *)ScriptReadWord(ctx); + const u8 *ptr = (const u8 *)ScriptReadWord(ctx); ScriptCall(ctx, ptr); return FALSE; @@ -180,7 +180,7 @@ bool8 ScrCmd_call(struct ScriptContext *ctx) bool8 ScrCmd_goto_if(struct ScriptContext *ctx) { u8 condition = ScriptReadByte(ctx); - u8 *ptr = (u8 *)ScriptReadWord(ctx); + const u8 *ptr = (const u8 *)ScriptReadWord(ctx); if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) ScriptJump(ctx, ptr); @@ -190,7 +190,7 @@ bool8 ScrCmd_goto_if(struct ScriptContext *ctx) bool8 ScrCmd_call_if(struct ScriptContext *ctx) { u8 condition = ScriptReadByte(ctx); - u8 *ptr = (u8 *)ScriptReadWord(ctx); + const u8 *ptr = (const u8 *)ScriptReadWord(ctx); if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) ScriptCall(ctx, ptr); @@ -225,7 +225,7 @@ bool8 ScrCmd_vcall(struct ScriptContext *ctx) bool8 ScrCmd_vgoto_if(struct ScriptContext *ctx) { u8 condition = ScriptReadByte(ctx); - u8 *ptr = (u8 *)(ScriptReadWord(ctx) - gUnknown_020375C4); + const u8 *ptr = (const u8 *)(ScriptReadWord(ctx) - gUnknown_020375C4); if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) ScriptJump(ctx, ptr); @@ -235,7 +235,7 @@ bool8 ScrCmd_vgoto_if(struct ScriptContext *ctx) bool8 ScrCmd_vcall_if(struct ScriptContext *ctx) { u8 condition = ScriptReadByte(ctx); - u8 *ptr = (u8 *)(ScriptReadWord(ctx) - gUnknown_020375C4); + const u8 *ptr = (const u8 *)(ScriptReadWord(ctx) - gUnknown_020375C4); if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) ScriptCall(ctx, ptr); @@ -245,7 +245,7 @@ bool8 ScrCmd_vcall_if(struct ScriptContext *ctx) bool8 ScrCmd_gotostd(struct ScriptContext *ctx) { u8 index = ScriptReadByte(ctx); - u8 **ptr = &gStdScripts[index]; + const u8 **ptr = &gStdScripts[index]; if (ptr < gStdScripts_End) ScriptJump(ctx, *ptr); @@ -255,7 +255,7 @@ bool8 ScrCmd_gotostd(struct ScriptContext *ctx) bool8 ScrCmd_callstd(struct ScriptContext *ctx) { u8 index = ScriptReadByte(ctx); - u8 **ptr = &gStdScripts[index]; + const u8 **ptr = &gStdScripts[index]; if (ptr < gStdScripts_End) ScriptCall(ctx, *ptr); @@ -269,7 +269,7 @@ bool8 ScrCmd_gotostd_if(struct ScriptContext *ctx) if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) { - u8 **ptr = &gStdScripts[index]; + const u8 **ptr = &gStdScripts[index]; if (ptr < gStdScripts_End) ScriptJump(ctx, *ptr); } @@ -283,7 +283,7 @@ bool8 ScrCmd_callstd_if(struct ScriptContext *ctx) if (sScriptConditionTable[condition][ctx->comparisonResult] == 1) { - u8 **ptr = &gStdScripts[index]; + const u8 **ptr = &gStdScripts[index]; if (ptr < gStdScripts_End) ScriptCall(ctx, *ptr); } @@ -292,7 +292,7 @@ bool8 ScrCmd_callstd_if(struct ScriptContext *ctx) bool8 ScrCmd_gotoram(struct ScriptContext *ctx) { - ScriptJump(ctx, (u8 *)gUnknown_020375C0); + ScriptJump(ctx, (const u8 *)gUnknown_020375C0); return FALSE; } @@ -323,7 +323,7 @@ bool8 ScrCmd_loadbytefromaddr(struct ScriptContext *ctx) { u8 index = ScriptReadByte(ctx); - ctx->data[index] = *(u8 *)ScriptReadWord(ctx); + ctx->data[index] = *(const u8 *)ScriptReadWord(ctx); return FALSE; } @@ -363,7 +363,7 @@ bool8 ScrCmd_copylocal(struct ScriptContext *ctx) bool8 ScrCmd_copybyte(struct ScriptContext *ctx) { u8 *ptr = (u8 *)ScriptReadWord(ctx); - *ptr = *(u8 *)ScriptReadWord(ctx); + *ptr = *(const u8 *)ScriptReadWord(ctx); return FALSE; } @@ -400,8 +400,8 @@ u8 compare_012(u16 a1, u16 a2) // comparelocaltolocal bool8 ScrCmd_compare_local_to_local(struct ScriptContext *ctx) { - u8 value1 = ctx->data[ScriptReadByte(ctx)]; - u8 value2 = ctx->data[ScriptReadByte(ctx)]; + const u8 value1 = ctx->data[ScriptReadByte(ctx)]; + const u8 value2 = ctx->data[ScriptReadByte(ctx)]; ctx->comparisonResult = compare_012(value1, value2); return FALSE; @@ -410,8 +410,8 @@ bool8 ScrCmd_compare_local_to_local(struct ScriptContext *ctx) // comparelocaltoimm bool8 ScrCmd_compare_local_to_value(struct ScriptContext *ctx) { - u8 value1 = ctx->data[ScriptReadByte(ctx)]; - u8 value2 = ScriptReadByte(ctx); + const u8 value1 = ctx->data[ScriptReadByte(ctx)]; + const u8 value2 = ScriptReadByte(ctx); ctx->comparisonResult = compare_012(value1, value2); return FALSE; @@ -419,8 +419,8 @@ bool8 ScrCmd_compare_local_to_value(struct ScriptContext *ctx) bool8 ScrCmd_compare_local_to_addr(struct ScriptContext *ctx) { - u8 value1 = ctx->data[ScriptReadByte(ctx)]; - u8 value2 = *(u8 *)ScriptReadWord(ctx); + const u8 value1 = ctx->data[ScriptReadByte(ctx)]; + const u8 value2 = *(const u8 *)ScriptReadWord(ctx); ctx->comparisonResult = compare_012(value1, value2); return FALSE; @@ -428,8 +428,8 @@ bool8 ScrCmd_compare_local_to_addr(struct ScriptContext *ctx) bool8 ScrCmd_compare_addr_to_local(struct ScriptContext *ctx) { - u8 value1 = *(u8 *)ScriptReadWord(ctx); - u8 value2 = ctx->data[ScriptReadByte(ctx)]; + const u8 value1 = *(const u8 *)ScriptReadWord(ctx); + const u8 value2 = ctx->data[ScriptReadByte(ctx)]; ctx->comparisonResult = compare_012(value1, value2); return FALSE; @@ -437,8 +437,8 @@ bool8 ScrCmd_compare_addr_to_local(struct ScriptContext *ctx) bool8 ScrCmd_compare_addr_to_value(struct ScriptContext *ctx) { - u8 value1 = *(u8 *)ScriptReadWord(ctx); - u8 value2 = ScriptReadByte(ctx); + const u8 value1 = *(const u8 *)ScriptReadWord(ctx); + const u8 value2 = ScriptReadByte(ctx); ctx->comparisonResult = compare_012(value1, value2); return FALSE; @@ -446,8 +446,8 @@ bool8 ScrCmd_compare_addr_to_value(struct ScriptContext *ctx) bool8 ScrCmd_compare_addr_to_addr(struct ScriptContext *ctx) { - u8 value1 = *(u8 *)ScriptReadWord(ctx); - u8 value2 = *(u8 *)ScriptReadWord(ctx); + const u8 value1 = *(const u8 *)ScriptReadWord(ctx); + const u8 value2 = *(const u8 *)ScriptReadWord(ctx); ctx->comparisonResult = compare_012(value1, value2); return FALSE; @@ -455,8 +455,8 @@ bool8 ScrCmd_compare_addr_to_addr(struct ScriptContext *ctx) bool8 ScrCmd_compare_var_to_value(struct ScriptContext *ctx) { - u16 value1 = *GetVarPointer(ScriptReadHalfword(ctx)); - u16 value2 = ScriptReadHalfword(ctx); + const u16 value1 = *GetVarPointer(ScriptReadHalfword(ctx)); + const u16 value2 = ScriptReadHalfword(ctx); ctx->comparisonResult = compare_012(value1, value2); return FALSE; @@ -464,8 +464,8 @@ bool8 ScrCmd_compare_var_to_value(struct ScriptContext *ctx) bool8 ScrCmd_compare_var_to_var(struct ScriptContext *ctx) { - u16 *ptr1 = GetVarPointer(ScriptReadHalfword(ctx)); - u16 *ptr2 = GetVarPointer(ScriptReadHalfword(ctx)); + const u16 *ptr1 = GetVarPointer(ScriptReadHalfword(ctx)); + const u16 *ptr2 = GetVarPointer(ScriptReadHalfword(ctx)); ctx->comparisonResult = compare_012(*ptr1, *ptr2); return FALSE; @@ -1003,7 +1003,7 @@ bool8 ScrCmd_fadeinbgm(struct ScriptContext *ctx) bool8 ScrCmd_applymovement(struct ScriptContext *ctx) { u16 localId = VarGet(ScriptReadHalfword(ctx)); - void *movementScript = (void *)ScriptReadWord(ctx); + const void *movementScript = (const void *)ScriptReadWord(ctx); ScriptMovement_StartObjectMovementScript(localId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, movementScript); sMovingNpcId = localId; @@ -1013,7 +1013,7 @@ bool8 ScrCmd_applymovement(struct ScriptContext *ctx) bool8 ScrCmd_applymovement_at(struct ScriptContext *ctx) { u16 localId = VarGet(ScriptReadHalfword(ctx)); - void *movementScript = (void *)ScriptReadWord(ctx); + const void *movementScript = (const void *)ScriptReadWord(ctx); u8 mapGroup = ScriptReadByte(ctx); u8 mapNum = ScriptReadByte(ctx); @@ -1274,30 +1274,30 @@ bool8 ScrCmd_release(struct ScriptContext *ctx) bool8 ScrCmd_message(struct ScriptContext *ctx) { - u8 *msg = (u8 *)ScriptReadWord(ctx); + const u8 *msg = (const u8 *)ScriptReadWord(ctx); if (msg == NULL) - msg = (u8 *)ctx->data[0]; + msg = (const u8 *)ctx->data[0]; ShowFieldMessage(msg); return FALSE; } bool8 ScrCmd_cmdDF(struct ScriptContext *ctx) { - u8 *msg = (u8 *)ScriptReadWord(ctx); + const u8 *msg = (const u8 *)ScriptReadWord(ctx); if (msg == NULL) - msg = (u8 *)ctx->data[0]; + msg = (const u8 *)ctx->data[0]; sub_8098238(msg); return FALSE; } bool8 ScrCmd_messageautoscroll(struct ScriptContext *ctx) { - u8 *msg = (u8 *)ScriptReadWord(ctx); + const u8 *msg = (const u8 *)ScriptReadWord(ctx); if (msg == NULL) - msg = (u8 *)ctx->data[0]; + msg = (const u8 *)ctx->data[0]; gTextFlags.flag_2 = TRUE; gTextFlags.flag_3 = TRUE; ShowFieldAutoScrollMessage(msg); @@ -1306,10 +1306,10 @@ bool8 ScrCmd_messageautoscroll(struct ScriptContext *ctx) bool8 ScrCmd_cmdDB(struct ScriptContext *ctx) { - u8 *msg = (u8 *)ScriptReadWord(ctx); + const u8 *msg = (const u8 *)ScriptReadWord(ctx); if (msg == NULL) - msg = (u8 *)ctx->data[0]; + msg = (const u8 *)ctx->data[0]; sub_81973A4(); sub_81973C4(0, 1); PrintTextOnWindow(0, 1, msg, 0, 1, 0, 0); @@ -1780,7 +1780,7 @@ bool8 ScrCmd_cmdE1(struct ScriptContext *ctx) bool8 ScrCmd_getstring(struct ScriptContext *ctx) { u8 stringVarIndex = ScriptReadByte(ctx); - u8 *text = (u8 *)ScriptReadWord(ctx); + const u8 *text = (u8 *)ScriptReadWord(ctx); StringCopy(sScriptStringVars[stringVarIndex], text); return FALSE; @@ -1788,7 +1788,7 @@ bool8 ScrCmd_getstring(struct ScriptContext *ctx) bool8 ScrCmd_vloadword(struct ScriptContext *ctx) { - u8 *ptr = (u8 *)(ScriptReadWord(ctx) - gUnknown_020375C4); + const u8 *ptr = (u8 *)(ScriptReadWord(ctx) - gUnknown_020375C4); StringExpandPlaceholders(gStringVar4, ptr); return FALSE; @@ -1799,7 +1799,7 @@ bool8 ScrCmd_vgetstring(struct ScriptContext *ctx) u8 stringVarIndex = ScriptReadByte(ctx); u32 addr = ScriptReadWord(ctx); - u8 *src = (u8 *)(addr - gUnknown_020375C4); + const u8 *src = (u8 *)(addr - gUnknown_020375C4); u8 *dest = sScriptStringVars[stringVarIndex]; StringCopy(dest, src); return FALSE; @@ -2022,7 +2022,7 @@ bool8 ScrCmd_dowildbattle(struct ScriptContext *ctx) bool8 ScrCmd_pokemart(struct ScriptContext *ctx) { - void *ptr = (void *)ScriptReadWord(ctx); + const void *ptr = (void *)ScriptReadWord(ctx); CreatePokemartMenu(ptr); ScriptContext1_Stop(); @@ -2031,7 +2031,7 @@ bool8 ScrCmd_pokemart(struct ScriptContext *ctx) bool8 ScrCmd_pokemartdecor(struct ScriptContext *ctx) { - void *ptr = (void *)ScriptReadWord(ctx); + const void *ptr = (void *)ScriptReadWord(ctx); CreateDecorationShop1Menu(ptr); ScriptContext1_Stop(); @@ -2040,7 +2040,7 @@ bool8 ScrCmd_pokemartdecor(struct ScriptContext *ctx) bool8 ScrCmd_pokemartbp(struct ScriptContext *ctx) { - void *ptr = (void *)ScriptReadWord(ctx); + const void *ptr = (void *)ScriptReadWord(ctx); CreateDecorationShop2Menu(ptr); ScriptContext1_Stop(); @@ -2360,7 +2360,7 @@ bool8 ScrCmd_cmdCE(struct ScriptContext *ctx) bool8 ScrCmd_cmdCF(struct ScriptContext *ctx) { - u8* v1 = sub_8099244(); + const u8* v1 = sub_8099244(); if (v1) { diff --git a/src/script.c b/src/script.c index b2809a137..5a1c5daa9 100644 --- a/src/script.c +++ b/src/script.c @@ -134,12 +134,12 @@ const u8 *ScriptPop(struct ScriptContext *ctx) return ctx->stack[ctx->stackDepth]; } -void ScriptJump(struct ScriptContext *ctx, u8 *ptr) +void ScriptJump(struct ScriptContext *ctx, const u8 *ptr) { ctx->scriptPtr = ptr; } -void ScriptCall(struct ScriptContext *ctx, u8 *ptr) +void ScriptCall(struct ScriptContext *ctx, const u8 *ptr) { ScriptPush(ctx, ctx->scriptPtr); ctx->scriptPtr = ptr; diff --git a/src/text.c b/src/text.c index 7cc46cd92..8108a6867 100644 --- a/src/text.c +++ b/src/text.c @@ -145,7 +145,7 @@ void DeactivateAllTextPrinters (void) gTextPrinters[printer].sub_union.sub.active = 0; } -u16 PrintTextOnWindow(u8 windowId, u8 fontId, u8 *str, u8 x, u8 y, u8 speed, void (*callback)(struct TextSubPrinter *, u16)) +u16 PrintTextOnWindow(u8 windowId, u8 fontId, const u8 *str, u8 x, u8 y, u8 speed, void (*callback)(struct TextSubPrinter *, u16)) { struct TextSubPrinter subPrinter;