Merge pull request #425 from PikalaxALT/sync_task

Sync task.c from Emerald
This commit is contained in:
GriffinR
2021-04-27 15:57:31 -04:00
committed by GitHub
+6 -18
View File
@@ -139,32 +139,20 @@ void TaskDummy(u8 taskId)
{
}
#define TASK_DATA_OP(taskId, offset, op) \
{ \
u32 tasksAddr = (u32)gTasks; \
u32 addr = taskId * sizeof(struct Task) + offset; \
u32 dataAddr = tasksAddr + offsetof(struct Task, data); \
addr += dataAddr; \
op; \
}
void SetTaskFuncWithFollowupFunc(u8 taskId, TaskFunc func, TaskFunc followupFunc)
{
TASK_DATA_OP(taskId, 28, *((u16 *)addr) = (u32)followupFunc)
TASK_DATA_OP(taskId, 30, *((u16 *)addr) = (u32)followupFunc >> 16)
u8 followupFuncIndex = NUM_TASK_DATA - 2; // Should be const.
gTasks[taskId].data[followupFuncIndex] = (s16)((u32)followupFunc);
gTasks[taskId].data[followupFuncIndex + 1] = (s16)((u32)followupFunc >> 16); // Store followupFunc as two half-words in the data array.
gTasks[taskId].func = func;
}
void SwitchTaskToFollowupFunc(u8 taskId)
{
s32 func;
u8 followupFuncIndex = NUM_TASK_DATA - 2; // Should be const.
gTasks[taskId].func = NULL;
TASK_DATA_OP(taskId, 28, func = *((u16 *)addr))
TASK_DATA_OP(taskId, 30, func |= *((s16 *)addr) << 16)
gTasks[taskId].func = (TaskFunc)func;
gTasks[taskId].func = (TaskFunc)((u16)(gTasks[taskId].data[followupFuncIndex]) | (gTasks[taskId].data[followupFuncIndex + 1] << 16));
}
bool8 FuncIsActiveTask(TaskFunc func)