Skip to content

Commit

Permalink
Decompiled LIB func_us_801AFE0C/func_psp_0925D8D8 (#2243)
Browse files Browse the repository at this point in the history
func_us_801AFE0C/func_psp_0925D8D8
PSX: https://decomp.me/scratch/L5A5D
PSP: https://decomp.me/scratch/ydeqP

Code is shared but not merged.

Added PAD_NONE (value of 0) in game.h macros to make this function a
little more self documenting.
Also fixed a tiny error with where I put castle flag offset 0x29
previously.
  • Loading branch information
ProjectOblivion authored Feb 22, 2025
1 parent 7516577 commit 3e73b09
Show file tree
Hide file tree
Showing 7 changed files with 497 additions and 46 deletions.
5 changes: 2 additions & 3 deletions config/symbols.pspeu.stlib.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
D_80097910 = 0x091CE5A0;
D_80097928 = 0x091CE5B0;
D_80076E98 = 0x091E5140;
CreateEntityFromLayout = 0x09237700;
CreateEntityWhenInVerticalRange = 0x09237820;
CreateEntityWhenInHorizontalRange = 0x092379B8;
Expand Down Expand Up @@ -120,6 +117,7 @@ CutsceneRun = 0x0925AFE8;
CutsceneSkip = 0x0925B380;
LIB_EntityCutscene = 0x0925B470;
LIB_EntityBackgroundBlock = 0x0925D350;
func_us_801AFE0C = 0x0925D8D8;
EntityLibrarianChair = 0x0925E018;
PlayerIsWithinHitbox = 0x0926CE18;
EntityLockCamera = 0x0926CF18;
Expand All @@ -143,6 +141,7 @@ LIB_RedDoorTiles = 0x09275F08;
LIB_EntityUpdates = 0x09275F18;
g_EInitObtainable = 0x09276058;
g_EInitParticle = 0x09276068;
D_us_80180824 = 0x09276078;
g_EInitInteractable = 0x09276088;
g_EInitUnkId13 = 0x09276098;
g_EInitLockCamera = 0x092760A8;
Expand Down
4 changes: 4 additions & 0 deletions config/symbols.pspeu.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ D_8017A000 = 0x08D27C40;
D_8017D000 = 0x08D2AC40;
DestroyEntitiesFromIndex = 0x0913E838;
g_CutsceneHasControl = 0x091CE598;
D_80097910 = 0x091CE5A0;
D_80097928 = 0x091CE5B0;
g_StageId = 0x091CE5B8;
g_IsUsingCd = 0x091CE5C8;
g_LoadFile = 0x091CE5D8;
Expand Down Expand Up @@ -104,6 +106,8 @@ PLAYER_facingLeft = 0x091E1694;
PLAYER_zPriority = 0x091E16A4;
PLAYER_step = 0x91E16AC;
PLAYER_step_s = 0x91E16AE;
D_80073510 = 0x091E17B8;
D_80076E98 = 0x091E5140;
g_Pix = 0x091ED5F8;
g_Clut = 0x091F5DF8;
g_Clut_2800 = 0x091F85F8;
Expand Down
2 changes: 1 addition & 1 deletion include/castle_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ typedef enum {
/* 0x21 */ NO2_SECRET_CEILING_OPEN = 33,
/* 0x22 */ NO2_STAGE_FLAG = 34,
/* 0x28 */ RNO2_SECRET_WALL_OPEN = 40, // See 0x20 note
/* 0x29 */ RNO2_SECRET_FLOOR_OPEN = 41,
/* 0x30 */ NO4_TO_NP3_SHORTCUT = 48,
/* 0x31 */ NO0_TO_NP3_SHORTCUT = 49,
/* 0x32 */ WRP_TO_NP3_SHORTCUT = 50,
/* 0x29 */ RNO2_SECRET_FLOOR_OPEN = 41,

// Used for tracking the steps to unlock the jewel sword room
// Bit 1 is set when the left side rocks are destroyed
Expand Down
85 changes: 46 additions & 39 deletions include/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,47 +143,54 @@ typedef enum {
#define DISP_STAGE_NEXT_X DISP_STAGE_W
#endif

#define BUTTON_COUNT 8
#define PAD_COUNT 2

#if !defined(VERSION_PSP)
#define PAD_L2 0x0001
#define PAD_R2 0x0002
#define PAD_L1 0x0004
#define PAD_R1 0x0008
#define PAD_TRIANGLE 0x0010
#define PAD_CIRCLE 0x0020
#define PAD_CROSS 0x0040
#define PAD_SQUARE 0x0080
#define PAD_SELECT 0x0100
#define PAD_L3 0x0200
#define PAD_R3 0x0400
#define PAD_START 0x0800
#define PAD_UP 0x1000
#define PAD_RIGHT 0x2000
#define PAD_DOWN 0x4000
#define PAD_LEFT 0x8000

// PSP buttons use same order as PSX, rather than by
// value for logical conistency between the two
typedef enum {
BUTTON_COUNT = 8,
PAD_COUNT = 2,
PAD_NONE = 0x0000,
// R3 button on a DS3 controller attached to PSP
// for debug mode may not be captured in these
#ifdef VERSION_PSP
PAD_L2 = 0x0002,
PAD_R2 = 0x0400,
PAD_L1 = 0x0100,
PAD_R1 = 0x0200,
PAD_TRIANGLE = 0x1000,
PAD_CIRCLE = 0x2000,
PAD_CROSS = 0x4000,
PAD_SQUARE = 0x8000,
PAD_SELECT = 0x0001,
PAD_L3 = 0x0000, // No L3 on PSP
PAD_R3 = 0x0000, // No R3 on PSP
PAD_START = 0x0008,
PAD_UP = 0x0010,
PAD_RIGHT = 0x0020,
PAD_DOWN = 0x0040,
PAD_LEFT = 0x0080,
#else
#define PAD_L2 0x0002
#define PAD_R2 0x0400
#define PAD_L1 0x0100
#define PAD_R1 0x0200
#define PAD_TRIANGLE 0x1000
#define PAD_CIRCLE 0x2000
#define PAD_CROSS 0x4000
#define PAD_SQUARE 0x8000
#define PAD_SELECT 0x0001
#define PAD_START 0x0008
#define PAD_UP 0x0010
#define PAD_RIGHT 0x0020
#define PAD_DOWN 0x0040
#define PAD_LEFT 0x0080
PAD_L2 = 0x0001,
PAD_R2 = 0x0002,
PAD_L1 = 0x0004,
PAD_R1 = 0x0008,
PAD_TRIANGLE = 0x0010,
PAD_CIRCLE = 0x0020,
PAD_CROSS = 0x0040,
PAD_SQUARE = 0x0080,
PAD_SELECT = 0x0100,
PAD_L3 = 0x0200,
PAD_R3 = 0x0400,
PAD_START = 0x0800,
PAD_UP = 0x1000,
PAD_RIGHT = 0x2000,
PAD_DOWN = 0x4000,
PAD_LEFT = 0x8000,
#endif

// Game Buttons unofficially refers to buttons used in playing the game.
// Direction, action and shoulder buttons. Any button except start or select.
#define GAMEBUTTONS (~(PAD_START | PAD_SELECT))
PAD_SIM_UNK20000 = 0x20000,
// Game Buttons unofficially refers to buttons used in playing the game.
// Any button except start or select.
GAMEBUTTONS = (~(PAD_START | PAD_SELECT)),
} PlayerPad;

#define MAX_PRIM_COUNT 0x500
#define MAX_PRIM_ALLOC_COUNT 0x400
Expand Down
1 change: 1 addition & 0 deletions include/sfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ enum SfxModes {
#define CD_SOUND_COMMAND_FADE_OUT_1 3
#define CD_SOUND_COMMAND_START_XA 4
#define CD_SOUND_COMMAND_6 6
#define CD_SOUND_COMMAND_7 7
#define CD_SOUND_COMMAND_8 8
#define CD_SOUND_COMMAND_10 10
#define CD_SOUND_COMMAND_12 12
Expand Down
222 changes: 221 additions & 1 deletion src/st/lib/unk_2FA80.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,227 @@ INCLUDE_RODATA("st/lib/nonmatchings/unk_2FA80", D_us_801ACD3C);

INCLUDE_RODATA("st/lib/nonmatchings/unk_2FA80", D_us_801ACD60);

INCLUDE_ASM("st/lib/nonmatchings/unk_2FA80", func_us_801AFE0C);
extern s8 D_80073510;
extern u16 D_us_80180824;

// This is probably EntityLibrarian, but I don't know for sure
void func_us_801AFE0C(Entity* self) {
Tilemap* tilemap = &g_Tilemap;
Entity* entity = g_Entities;

switch (self->step) {
case 0:
#ifdef VERSION_PSP
func_psp_0925D4D0();
#endif
InitializeEntity(&D_us_80180824);
if (entity->posX.i.hi < 0x100) {
// I expect these two sounds to be the same, but 0x202 has not yet been defined.
// This leads me to think that the macro that has been defined for sfx 0x302
// is only accurate for PSX and does not align with the sfx for PSP here.
#ifdef VERSION_PSP
g_api.PlaySfx(0x302);
#else
g_api.PlaySfx(0x202);
#endif
}
if (g_CastleFlags[MET_LIBRARIAN]) {
self->step = 8;
break;
}
#ifdef VERSION_PSP
g_Player.padSim = PAD_LEFT | PAD_SIM_UNK20000;
g_Player.D_80072EFC = 1;
#endif
break;
case 1:
D_80073510 = 1;
g_PauseAllowed = false;
g_unkGraphicsStruct.pauseEnemies = true;
g_Player.padSim = PAD_LEFT;
g_Player.D_80072EFC = 1;
if (g_Player.status & PLAYER_STATUS_BAT_FORM) {
g_Player.padSim = PAD_R1;
} else if (g_Player.status & PLAYER_STATUS_MIST_FORM) {
#ifdef VERSION_PSP
g_Player.padSim = PAD_NONE;
#else
g_Player.padSim = PAD_L1;
#endif
} else if (g_Player.status & PLAYER_STATUS_WOLF_FORM) {
#ifdef VERSION_PSP
g_Player.padSim = PAD_L1;
#else
g_Player.padSim = PAD_R2;
#endif
}
g_Player.D_80072EFC = 1;
SetStep(2);
break;
case 2:
if (entity->posX.i.hi > 0xE8) {
if (g_Player.status & PLAYER_STATUS_TRANSFORM) {
g_Player.padSim = PAD_NONE;
if (g_Timer & 1) {
if (g_Player.status & PLAYER_STATUS_BAT_FORM) {
#ifdef VERSION_PSP
g_Player.padSim = PAD_R1 | PAD_SIM_UNK20000;
#else
g_Player.padSim = PAD_R1;
#endif
} else if (g_Player.status & PLAYER_STATUS_MIST_FORM) {
#ifdef VERSION_PSP
g_Player.padSim = PAD_NONE | PAD_SIM_UNK20000;
#else
g_Player.padSim = PAD_L1;
#endif
} else if (g_Player.status & PLAYER_STATUS_WOLF_FORM) {
#ifdef VERSION_PSP
g_Player.padSim = PAD_L1 | PAD_SIM_UNK20000;
#else
g_Player.padSim = PAD_R2;
#endif
}
}
} else {
g_Player.padSim = PAD_LEFT;
}
} else {
g_CutsceneFlags |= 1;
g_Player.padSim = PAD_NONE;
entity->posX.i.hi = 0xE8;
self->step++;
}
g_Player.D_80072EFC = 1;
break;
case 3:
if (g_CutsceneFlags & 0x40) {
if (entity->posX.i.hi > 0x74) {
D_80073510 = 1;
g_Player.padSim = PAD_LEFT;
} else {
entity->posX.i.hi = 0x74;
g_Player.padSim = PAD_NONE;
self->step++;
}
} else {
entity->posX.i.hi = 0xE8;
}
g_Player.D_80072EFC = 1;
break;
case 4:
g_Player.padSim = PAD_NONE | PAD_SIM_UNK20000;
g_Player.D_80072EFC = 1;
self->step++;
break;
case 5:
g_CastleFlags[MET_LIBRARIAN] = 1;
g_api.TimeAttackController(
TIMEATTACK_EVENT_MEET_MASTER_LIBRARIAN, TIMEATTACK_SET_RECORD);
g_Player.D_80072EFC = 1;
self->step++;
/* fallthrough */
case 6:
if (g_CutsceneFlags & 0x100) {
g_CutsceneFlags |= 0x2000;
self->step = 0x10;
break;
}
entity->posX.i.hi = 0x74;
break;
case 8:
self->step++;
/* fallthrough */
case 9:
if (entity->posX.i.hi > 0xFF) {
g_api.PlaySfx(CD_SOUND_COMMAND_7);
DestroyEntity(self);
break;
}
if (entity->posX.i.hi < 0x75) {
switch (self->step_s) {
case 0:
D_80073510 = 1;
g_PauseAllowed = false;
g_unkGraphicsStruct.pauseEnemies = true;
g_Player.padSim = PAD_NONE;
g_Player.D_80072EFC = 0x10;
self->step_s++;
g_CutsceneFlags |= 1;
break;
case 1:
if (g_Player.status & PLAYER_STATUS_TRANSFORM) {
g_Player.padSim = PAD_NONE;
if (g_Timer & 1) {
if (g_Player.status & PLAYER_STATUS_BAT_FORM) {
g_Player.padSim = PAD_R1;
} else if (g_Player.status & PLAYER_STATUS_MIST_FORM) {
#ifdef VERSION_PSP
g_Player.padSim = PAD_NONE;
#else
g_Player.padSim = PAD_L1;
#endif
} else if (g_Player.status & PLAYER_STATUS_WOLF_FORM) {
#ifdef VERSION_PSP
g_Player.padSim = PAD_L1;
#else
g_Player.padSim = PAD_R2;
#endif
}
}
} else {
g_Player.padSim = PAD_LEFT;
self->step_s++;
}
g_Player.D_80072EFC = 1;
break;
case 2:
g_Player.padSim = PAD_NONE;
g_Player.D_80072EFC = 0x80;
SetStep(10);
break;
}
entity->posX.i.hi = 0x74;
}
break;
case 10:
if (!g_Player.D_80072EFC && (g_Player.pl_vram_flag & 1)) {
g_Player.padSim = PAD_NONE | PAD_SIM_UNK20000;
g_Player.D_80072EFC = 1;
self->step++;
}
entity->posX.i.hi = 0x74;
break;
case 11:
g_Player.padSim = PAD_NONE | PAD_SIM_UNK20000;
g_Player.D_80072EFC = 1;
if (g_CutsceneFlags & 0x100) {
g_CutsceneFlags |= 0x2000;
self->step = 0x10;
}
break;
case 16:
#ifdef VERSION_PSP
g_PauseAllowed = false;
#endif
g_Player.D_80072EFC = 0x20;
g_Player.padSim = PAD_RIGHT;
D_80097928 = 1;
self->step++;
break;
case 17:
#ifdef VERSION_PSP
g_PauseAllowed = false;
#endif
if (!g_Player.D_80072EFC) {
#ifdef VERSION_PSP
g_PauseAllowed = true;
#endif
SetStep(9);
}
break;
}
}

extern u8 D_us_801811FC[];
extern u8 D_us_80181204[];
Expand Down
Loading

0 comments on commit 3e73b09

Please sign in to comment.