PSP WRP functions (#1178)

A bunch of functions where I am using the shared headers whenever I
could. The plan is to switch into C files on the first good opportunity.
This commit is contained in:
Luciano Ciccariello 2024-05-26 19:58:12 +01:00 committed by GitHub
parent b0d6f28633
commit fdb4b11359
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
23 changed files with 143 additions and 261 deletions

View File

@ -54,7 +54,6 @@ segments:
- [0xBDA0, c, wrp_psp/BDA0]
- [0xBFD8, c, wrp_psp/BFD8]
- [0xC3F0, c, wrp_psp/C3F0]
- [0xD010, c, wrp_psp/D010]
- [0xD0E0, c, wrp_psp/st_init_wrp]
- [0xD1B8, c, wrp/e_breakable]
- [0xD338, c, wrp/st_debug]

View File

@ -65,6 +65,7 @@ segments:
- [0x16FC0, c, update]
- [0x172BC, c, update_stage_entities]
- [0x173C4, c]
- [0x1C63C, c]
- [0x1C7DC, c]
- [0x1D074, c, entity_relic_orb]
- [0x1DB44, c, entity_heart_drop]

View File

@ -3,14 +3,14 @@ CreateEntityWhenInVerticalRange = 0x09237820;
CreateEntityWhenInHorizontalRange = 0x092379b8;
FindFirstEntityToTheRight = 0x09237b50;
FindFirstEntityToTheLeft = 0x09237bc0;
func_8018A170 = 0x09237c48;
func_8018A26C = 0x09237d88;
CreateEntitiesToTheRight = 0x09237c48;
CreateEntitiesToTheLeft = 0x09237d88;
FindFirstEntityAbove = 0x09237ee0;
FindFirstEntityBelow = 0x09237f58;
func_8018A424 = 0x09237fe0;
func_8018A520 = 0x09238128;
CreateEntitiesAbove = 0x09237fe0;
CreateEntitiesBelow = 0x09238128;
InitRoomEntities = 0x09238288;
func_8018A7AC = 0x092384b8;
UpdateRoomPosition = 0x092384b8;
CreateEntityFromCurrentEntity = 0x09238598;
CreateEntityFromEntity = 0x09238620;
EntityStageNamePopup = 0x092386a8;
@ -70,6 +70,7 @@ func_801870B0 = 0x09244ac8;
EntityWarpRoom = 0x09244d28;
EntityWarpSmallRocks = 0x09245c50;
c_HeartPrizes = 0x09246500;
D_80181420 = 0x09246AE0;
g_eBreakableInit = 0x09246E90;
D_80180488 = 0x09246EE0;
g_eInitGeneric2 = 0x09246EF0;

View File

@ -720,7 +720,7 @@ typedef struct {
/* 0x08 */ u16 drawFlags;
/* 0x0A */ u16 drawMode;
/* 0x0C */ u32 unkC;
/* 0x10 */ const u8* unk10;
/* 0x10 */ u8* unk10;
} ObjInit2; // size = 0x14
typedef struct GpuBuffer { // also called 'DB' in the PSY-Q samples

View File

@ -27,7 +27,12 @@ extern LayoutEntity* g_pStObjLayoutHorizontal[];
*/
extern LayoutEntity* g_pStObjLayoutVertical[];
#if defined(VERSION_PSP)
extern PfnEntityUpdate* PfnEntityUpdates;
#else
extern PfnEntityUpdate PfnEntityUpdates[];
#endif
extern u16 g_ItemIconSlots[0x20];
extern u16 UNK_Invincibility0[];
@ -52,7 +57,6 @@ void CreateEntityFromEntity(u16 entityId, Entity* source, Entity* entity);
void CreateEntityFromLayout(Entity* entity, LayoutEntity* initDesc);
void DestroyEntity(Entity*);
void DestroyEntitiesFromIndex(s16 index);
s32 AnimateEntity(const u8 frames[], Entity* entity);
void MoveEntity();
void FallEntity(void);
Entity* AllocEntity(Entity* start, Entity* end);

View File

@ -1,11 +1,14 @@
s32 AnimateEntity(const u8 frames[], Entity* entity) {
s32 flag = 0;
u16 currentFrameIndex = entity->animFrameIdx * 2;
u8* currentFrame = frames + currentFrameIndex;
u8 AnimateEntity(u8 frames[], Entity* entity) {
u16 flag;
u16 currentFrameIndex;
u8* currentFrame;
if (entity->animFrameDuration == 0) {
if (currentFrame[0] > 0) {
flag = 0x80;
flag = 0;
currentFrameIndex = entity->animFrameIdx * 2;
currentFrame = frames + currentFrameIndex;
if (!entity->animFrameDuration) {
if (currentFrame[0]) {
if (currentFrame[0] == 0xFF) {
return 0;
}
@ -13,10 +16,11 @@ s32 AnimateEntity(const u8 frames[], Entity* entity) {
entity->animFrameDuration = *currentFrame++;
entity->animCurFrame = *currentFrame++;
entity->animFrameIdx++;
flag |= 0x80;
} else {
currentFrame = frames;
entity->animFrameIdx = 0;
entity->animFrameDuration = 0;
currentFrame = frames;
entity->animFrameDuration = *currentFrame++;
entity->animCurFrame = *currentFrame++;
entity->animFrameIdx++;
@ -24,9 +28,9 @@ s32 AnimateEntity(const u8 frames[], Entity* entity) {
}
}
entity->animFrameDuration = entity->animFrameDuration - 1;
entity->animFrameDuration--;
entity->animCurFrame = currentFrame[-1];
flag |= true;
return (u8)flag;
}
return flag;
}

View File

@ -1,11 +1,13 @@
extern PfnEntityUpdate PfnEntityUpdates[];
void CreateEntityFromLayout(Entity* entity, LayoutEntity* initDesc) {
Tilemap* tilemap;
tilemap = &g_Tilemap;
DestroyEntity(entity);
entity->entityId = initDesc->entityId & 0x3FF;
entity->pfnUpdate = PfnEntityUpdates[entity->entityId - 1];
entity->posX.i.hi = initDesc->posX - g_Tilemap.scrollX.i.hi;
entity->posY.i.hi = initDesc->posY - g_Tilemap.scrollY.i.hi;
entity->posX.i.hi = (s16)initDesc->posX - tilemap->scrollX.i.hi;
entity->posY.i.hi = (s16)initDesc->posY - tilemap->scrollY.i.hi;
entity->params = initDesc->params;
entity->entityRoomIndex = initDesc->entityRoomIndex >> 8;
entity->unk68 = (initDesc->entityId >> 0xA) & 7;

View File

@ -1,79 +1,74 @@
void CreateEntityWhenInVerticalRange(LayoutEntity* layoutObj) {
void CreateEntityWhenInVerticalRange(LayoutEntity* obj) {
s16 yClose;
s16 yFar;
s16 posY;
Entity* entity;
Tilemap* tilemap;
posY = g_Tilemap.scrollY.i.hi;
tilemap = &g_Tilemap;
posY = tilemap->scrollY.i.hi;
yClose = posY - 0x40;
yFar = posY + 0x120;
if (yClose < 0) {
yClose = 0;
}
posY = layoutObj->posY;
if (posY < yClose) {
posY = obj->posY;
if (posY < yClose || posY > yFar) {
return;
}
if (yFar < posY) {
return;
}
switch (layoutObj->entityId & 0xE000) {
switch (obj->entityId & 0xE000) {
case 0x0:
entity =
&g_Entities[STAGE_ENTITY_START + (u8)layoutObj->entityRoomIndex];
if (entity->entityId == E_NONE) {
CreateEntityFromLayout(entity, layoutObj);
g_Entities + STAGE_ENTITY_START + (obj->entityRoomIndex & 0xFF);
if (!entity->entityId) {
CreateEntityFromLayout(entity, obj);
}
break;
case 0x8000:
break;
case 0xA000:
entity =
&g_Entities[STAGE_ENTITY_START + (u8)layoutObj->entityRoomIndex];
CreateEntityFromLayout(entity, layoutObj);
g_Entities + STAGE_ENTITY_START + (obj->entityRoomIndex & 0xFF);
CreateEntityFromLayout(entity, obj);
break;
case 0x8000:
break;
}
}
void CreateEntityWhenInHorizontalRange(LayoutEntity* layoutObj) {
void CreateEntityWhenInHorizontalRange(LayoutEntity* obj) {
s16 xClose;
s16 xFar;
s16 posX;
Entity* entity;
Tilemap* tilemap;
posX = g_Tilemap.scrollX.i.hi;
tilemap = &g_Tilemap;
posX = tilemap->scrollX.i.hi;
xClose = posX - 0x40;
xFar = posX + 0x140;
if (xClose < 0) {
xClose = 0;
}
posX = layoutObj->posX;
if (posX < xClose) {
posX = obj->posX;
if (posX < xClose || posX > xFar) {
return;
}
if (xFar < posX) {
return;
}
switch (layoutObj->entityId & 0xE000) {
switch (obj->entityId & 0xE000) {
case 0x0:
entity =
&g_Entities[STAGE_ENTITY_START + (u8)layoutObj->entityRoomIndex];
if (entity->entityId == E_NONE) {
CreateEntityFromLayout(entity, layoutObj);
g_Entities + STAGE_ENTITY_START + (obj->entityRoomIndex & 0xFF);
if (!entity->entityId) {
CreateEntityFromLayout(entity, obj);
}
break;
case 0x8000:
break;
case 0xA000:
entity =
&g_Entities[STAGE_ENTITY_START + (u8)layoutObj->entityRoomIndex];
CreateEntityFromLayout(entity, layoutObj);
g_Entities + STAGE_ENTITY_START + (obj->entityRoomIndex & 0xFF);
CreateEntityFromLayout(entity, obj);
break;
case 0x8000:
break;
}
}

View File

@ -533,38 +533,3 @@ void CollectLifeVessel(void) {
void DestroyCurrentEntity(void) { DestroyEntity(g_CurrentEntity); }
INCLUDE_ASM("st/dre/nonmatchings/173C4", EntityPrizeDrop);
void EntityExplosion(Entity* entity) {
u32 temp_v0;
u32 temp;
if (!entity->step) {
InitializeEntity(g_InitializeEntityData0);
entity->animSet = ANIMSET_DRA(2);
entity->animFrameIdx = 0;
entity->animFrameDuration = 0;
entity->drawMode = 0x30;
if (entity->params & 0xF0) {
entity->palette = 0x8195;
entity->drawMode = DRAW_TPAGE;
}
temp_v0 = entity->params & 0xFF00;
if (temp_v0 != 0) {
entity->zPriority = (u16)(temp_v0 >> 8);
}
entity->params &= 0xF;
entity->velocityY = D_801811B0[entity->params];
return;
}
entity->posY.val += entity->velocityY;
if (!AnimateEntity(D_8018125C[entity->params], entity)) {
DestroyEntity(entity);
}
}
#include "../blink_item.h"

36
src/st/dre/1C63C.c Normal file
View File

@ -0,0 +1,36 @@
#include "dre.h"
void EntityExplosion(Entity* entity) {
u32 temp_v0;
u32 temp;
if (!entity->step) {
InitializeEntity(g_InitializeEntityData0);
entity->animSet = ANIMSET_DRA(2);
entity->animFrameIdx = 0;
entity->animFrameDuration = 0;
entity->drawMode = 0x30;
if (entity->params & 0xF0) {
entity->palette = 0x8195;
entity->drawMode = DRAW_TPAGE;
}
temp_v0 = entity->params & 0xFF00;
if (temp_v0 != 0) {
entity->zPriority = (u16)(temp_v0 >> 8);
}
entity->params &= 0xF;
entity->velocityY = D_801811B0[entity->params];
return;
}
entity->posY.val += entity->velocityY;
if (!AnimateEntity(D_8018125C[entity->params], entity)) {
DestroyEntity(entity);
}
}
#include "../blink_item.h"

View File

@ -1,23 +1,4 @@
void UnkEntityFunc0(s32 slope, s16 speed) {
Entity* entity;
s32 moveX;
s32 moveY;
moveX = rcos((u16)slope) * speed;
entity = g_CurrentEntity;
if (moveX < 0) {
moveX += 15;
}
entity->velocityX = moveX >> 4;
moveY = rsin((u16)slope) * speed;
entity = g_CurrentEntity;
if (moveY < 0) {
moveY += 15;
}
entity->velocityY = moveY >> 4;
}
void UnkEntityFunc0(u16 slope, s16 speed) {
g_CurrentEntity->velocityX = rcos(slope) * speed / 16;
g_CurrentEntity->velocityY = rsin(slope) * speed / 16;
}

View File

@ -7,7 +7,6 @@ extern u16 D_80180DC4[];
extern u16 D_80180DF4[];
extern u16 g_ItemIconSlots[];
extern u16 UNK_Invincibility0[];
extern PfnEntityUpdate PfnEntityUpdates[];
extern s16 D_80180A94[];
extern LayoutEntity* D_80180310[];

View File

@ -493,6 +493,7 @@ void func_801903C8(Entity* entity) {
}
}
extern PfnEntityUpdate PfnEntityUpdates[];
void func_80190494(u16 entityId, Entity* src, Entity* dst) {
DestroyEntity(dst);
dst->entityId = entityId;

View File

@ -11,7 +11,6 @@ extern u8 g_eBreakableDrawModes[];
void CreateEntityFromCurrentEntity(u16 entityId, Entity* entity);
void ReplaceBreakableWithItemDrop(Entity*);
s32 AnimateEntity(const u8 frames[], Entity* entity);
Entity* AllocEntity(Entity* start, Entity* end);
void EntityBreakable(Entity* entity) {

View File

@ -1,5 +1,4 @@
#include "common.h"
#include "game.h"
#include <game.h>
// redeclaring for the moment due to header conflict with Random() definition
typedef struct {
@ -40,9 +39,9 @@ void FindFirstEntityToTheLeft(s16 posX) {
}
}
INCLUDE_ASM("st/wrp_psp/psp/wrp_psp/4D0", func_8018A170);
INCLUDE_ASM("st/wrp_psp/psp/wrp_psp/4D0", CreateEntitiesToTheRight);
INCLUDE_ASM("st/wrp_psp/psp/wrp_psp/4D0", func_8018A26C);
INCLUDE_ASM("st/wrp_psp/psp/wrp_psp/4D0", CreateEntitiesToTheLeft);
void FindFirstEntityAbove(s16 arg0) {
while (true) {
@ -65,13 +64,13 @@ void FindFirstEntityBelow(s16 arg0) {
}
}
INCLUDE_ASM("st/wrp_psp/psp/wrp_psp/4D0", func_8018A424);
INCLUDE_ASM("st/wrp_psp/psp/wrp_psp/4D0", CreateEntitiesAbove);
INCLUDE_ASM("st/wrp_psp/psp/wrp_psp/4D0", func_8018A520);
INCLUDE_ASM("st/wrp_psp/psp/wrp_psp/4D0", CreateEntitiesBelow);
INCLUDE_ASM("st/wrp_psp/psp/wrp_psp/4D0", InitRoomEntities);
INCLUDE_ASM("st/wrp_psp/psp/wrp_psp/4D0", func_8018A7AC);
INCLUDE_ASM("st/wrp_psp/psp/wrp_psp/4D0", UpdateRoomPosition);
extern PfnEntityUpdate* PfnEntityUpdates;
void CreateEntityFromCurrentEntity(u16 entityId, Entity* entity) {

View File

@ -1,7 +1,5 @@
#include "common.h"
#include "../wrp/wrp.h"
INCLUDE_ASM("st/wrp_psp/psp/wrp_psp/80", CreateEntityFromLayout);
#include "../create_entity_from_layout.h"
INCLUDE_ASM("st/wrp_psp/psp/wrp_psp/80", CreateEntityWhenInVerticalRange);
INCLUDE_ASM("st/wrp_psp/psp/wrp_psp/80", CreateEntityWhenInHorizontalRange);
#include "../create_entity_in_range.h"

View File

@ -1,4 +1,4 @@
#include "common.h"
#include "../wrp/wrp.h"
INCLUDE_ASM("st/wrp_psp/psp/wrp_psp/95D0", TestCollisions);

View File

@ -1,8 +1,29 @@
#include "../wrp/wrp.h"
INCLUDE_ASM("st/wrp_psp/psp/wrp_psp/BDA0", EntityRoomForeground);
extern ObjInit2 D_80181420[];
void EntityRoomForeground(Entity* entity) {
ObjInit2* objInit = &D_80181420[entity->params];
INCLUDE_ASM("st/wrp_psp/psp/wrp_psp/BDA0", DestroyEntity);
if (!entity->step) {
InitializeEntity(g_eInitGeneric2);
entity->animSet = objInit->animSet;
entity->zPriority = objInit->zPriority;
entity->unk5A = objInit->unk4.u;
entity->palette = objInit->palette;
entity->drawFlags = objInit->drawFlags;
entity->drawMode = objInit->drawMode;
if (objInit->unkC != 0) {
entity->flags = objInit->unkC;
}
if (entity->params > 4) {
entity->drawFlags |= DRAW_COLORS;
entity->rotZ = 0x800;
}
}
AnimateEntity(objInit->unk10, entity);
}
#include "../../destroy_entity.h"
void PreventEntityFromRespawning(Entity* entity) {
if (entity->entityRoomIndex) {

View File

@ -1,7 +1,7 @@
#include "common.h"
#include "game.h"
INCLUDE_ASM("st/wrp_psp/psp/wrp_psp/BFD8", AnimateEntity);
#include "../animate_entity.h"
u8 GetSideToPlayer() {
u8 side = 0;
@ -41,7 +41,10 @@ Entity* AllocEntity(Entity* start, Entity* end) {
return NULL;
}
INCLUDE_ASM("st/wrp_psp/psp/wrp_psp/BFD8", UnkEntityFunc0);
void UnkEntityFunc0(u16 slope, s16 speed) {
g_CurrentEntity->velocityX = rcos(slope) * speed / 16;
g_CurrentEntity->velocityY = rsin(slope) * speed / 16;
}
u16 func_8018C160(Entity* a, Entity* b) {
s32 diffX = b->posX.i.hi - a->posX.i.hi;

View File

@ -33,3 +33,5 @@ void UnkPolyFunc2(Primitive* prim) {
prim->next->type = PRIM_LINE_G2;
prim->next->drawMode = 0xA;
}
INCLUDE_ASM("st/wrp_psp/psp/wrp_psp/C3F0", PrimDecreaseBrightness);

View File

@ -1,3 +0,0 @@
#include "common.h"
INCLUDE_ASM("st/wrp_psp/psp/wrp_psp/D010", PrimDecreaseBrightness);

View File

@ -1,39 +0,0 @@
#include "../wrp/wrp.h"
#include <sfx.h>
extern u16 g_eBreakableInit[];
extern u8* g_eBreakableAnimations[];
extern u8 g_eBreakableHitboxes[];
extern u8 g_eBreakableExplosionTypes[];
extern u16 g_eBreakableanimSets[];
extern u8 g_eBreakableDrawModes[];
void CreateEntityFromCurrentEntity(u16 entityId, Entity* entity);
void ReplaceBreakableWithItemDrop(Entity*);
s32 AnimateEntity(const u8 frames[], Entity* entity);
Entity* AllocEntity(Entity* start, Entity* end);
void EntityBreakable(Entity* entity) {
u16 breakableType = entity->params >> 0xC;
if (entity->step) {
AnimateEntity(g_eBreakableAnimations[breakableType], entity);
if (entity->unk44) { // If the candle is destroyed
Entity* entityDropItem;
g_api.PlaySfx(NA_SE_BREAK_CANDLE);
entityDropItem = AllocEntity(&g_Entities[224], &g_Entities[256]);
if (entityDropItem != NULL) {
CreateEntityFromCurrentEntity(E_EXPLOSION, entityDropItem);
entityDropItem->params =
g_eBreakableExplosionTypes[breakableType];
}
ReplaceBreakableWithItemDrop(entity);
}
} else {
InitializeEntity(g_eBreakableInit);
entity->zPriority = g_unkGraphicsStruct.g_zEntityCenter.unk - 0x14;
entity->drawMode = g_eBreakableDrawModes[breakableType];
entity->hitboxHeight = g_eBreakableHitboxes[breakableType];
entity->animSet = g_eBreakableanimSets[breakableType];
}
}

View File

@ -1,86 +0,0 @@
#include <game.h>
extern ObjInit2 D_801804E0[];
extern u16 g_eInitGeneric2[];
void func_80186FD0(Entity* self) {
ObjInit2* objInit = &D_801804E0[self->params];
if (!self->step) {
InitializeEntity(g_eInitGeneric2);
self->animSet = objInit->animSet;
self->zPriority = objInit->zPriority;
self->unk5A = objInit->unk4.u;
self->palette = objInit->palette;
self->drawFlags = objInit->drawFlags;
self->drawMode = objInit->drawMode;
if (objInit->unkC) {
self->flags = objInit->unkC;
}
if (self->params == 1) {
self->rotX = self->rotY = 0x0200;
}
}
AnimateEntity(objInit->unk10, self);
}
u16 D_80180488[];
u8 D_80180528[];
u8 D_80180530[];
u16 D_80180538[];
void func_801870B0(Entity* entity) {
u16 var_s0;
u16 params;
u16* tilemapProps;
entity->unk6D[0] = 0;
params = entity->params;
if (entity->step) {
switch (params) {
case 4:
case 5:
if (g_Tilemap.x) {
return;
}
break;
case 6:
if (g_pads->pressed & PAD_TRIANGLE) {
g_Tilemap.x = 0;
g_Tilemap.width = 1280;
entity->step++;
return;
}
break;
}
if (entity->unk44) {
var_s0 = GetSideToPlayer();
if (entity->ext.generic.unk7C.u) {
var_s0 &= 2;
var_s0 *= 2;
} else {
var_s0 &= 1;
var_s0 *= 4;
}
params = (params << 3) + var_s0;
tilemapProps = &D_80180538[params];
g_Tilemap.x = *tilemapProps++;
g_Tilemap.y = *tilemapProps++;
g_Tilemap.width = *tilemapProps++;
g_Tilemap.height = *tilemapProps;
}
} else {
InitializeEntity(D_80180488);
var_s0 = entity->ext.generic.unk7C.u = D_80180530[params];
if (var_s0) {
entity->hitboxWidth = D_80180528[params];
entity->hitboxHeight = 16;
} else {
entity->hitboxWidth = 16;
entity->hitboxHeight = D_80180528[params];
}
}
}