#ifndef GUARD_SCRIPT_H #define GUARD_SCRIPT_H struct ScriptContext; typedef bool8 (*ScrCmdFunc)(struct ScriptContext *); typedef u8 Script[]; struct ScriptContext { u8 stackDepth; u8 mode; u8 comparisonResult; u8 (*nativePtr)(void); const u8 *scriptPtr; const u8 *stack[20]; ScrCmdFunc *cmdTable; ScrCmdFunc *cmdTableEnd; u32 data[4]; }; #define ScriptReadByte(ctx) (*(ctx->scriptPtr++)) void InitScriptContext(struct ScriptContext *ctx, void *cmdTable, void *cmdTableEnd); u8 SetupBytecodeScript(struct ScriptContext *ctx, const u8 *ptr); void SetupNativeScript(struct ScriptContext *ctx, bool8 (*ptr)(void)); void StopScript(struct ScriptContext *ctx); bool8 RunScriptCommand(struct ScriptContext *ctx); 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); // Formerly ScriptContext2_Enable / Disable / IsEnabled void LockPlayerFieldControls(void); void UnlockPlayerFieldControls(void); bool8 ArePlayerFieldControlsLocked(void); // Formerly ScriptContext1_*() // The ScriptContext_* functions work with the primary script context, // which yields control back to native code should the script make a wait call. // Re-initializes the global script context to zero. void ScriptContext_Init(void); // Checks if the global script context is able to be run right now. bool8 ScriptContext_IsEnabled(void); // Runs the script until the script makes a wait* call, then returns true if // there's more script to run, or false if the script has hit the end. // This function also returns false if the context is finished // or waiting (after a call to _Stop) bool8 ScriptContext_RunScript(void); // Sets up a new script in the global context and enables the context void ScriptContext_SetupScript(const u8 *ptr); // Puts the script into waiting mode; usually called from a wait* script command. void ScriptContext_Stop(void); // Puts the script into running mode. void ScriptContext_Enable(void); // Formerly ScriptContext2_RunNewScript() // Sets up and runs a script in its own context immediately. The script will be // finished when this function returns. Used mainly by all of the map header // scripts (except the frame table scripts). void RunScriptImmediately(const u8 *ptr); u8 *MapHeaderGetScriptTable(u8 tag); void MapHeaderRunScriptType(u8 tag); u8 *MapHeaderCheckScriptTable(u8 tag); void RunOnLoadMapScript(void); void RunOnTransitionMapScript(void); void RunOnResumeMapScript(void); void RunOnReturnToFieldMapScript(void); void RunOnDiveWarpMapScript(void); bool8 TryRunOnFrameMapScript(void); void TryRunOnWarpIntoMapScript(void); u32 CalculateRamScriptChecksum(void); void ClearRamScript(void); bool8 InitRamScript(const u8 *script, u16 scriptSize, u8 mapGroup, u8 mapNum, u8 objectId); const u8 *GetRamScript(u8 objectId, const u8 *script); bool32 ValidateSavedRamScript(void); u8 *GetSavedRamScriptIfValid(void); void InitRamScript_NoObjectEvent(u8 *script, u16 scriptSize); // srccmd.h void SetMovingNpcId(u16 npcId); #endif // GUARD_SCRIPT_H