More Descriptive func_801B9744 (#1137)

This adds some additional context for func_801B9744 and renames globals
to fit their assumed purpose.

Migrated various stream metadata to C definitions.

The makefile changes add a dependency on `sel.h` to all the objects that
get built from the `st/sel` directory.

Co-authored-by: Jonathan Hohle <jon@ttkb.co>
This commit is contained in:
Jonathan Hohle 2024-06-11 10:47:59 -07:00 committed by GitHub
parent 00d07f6a10
commit 312c8441f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 94 additions and 33 deletions

View File

@ -219,6 +219,8 @@ $(BUILD_DIR)/F_NZ0.BIN:
sel: stsel_dirs $(BUILD_DIR)/SEL.BIN
$(BUILD_DIR)/SEL.BIN: $(BUILD_DIR)/stsel.elf
$(OBJCOPY) -O binary $< $@
$(BUILD_DIR)/src/st/sel/%.c.o: src/st/sel/%.c $(MASPSX_APP) $(CC1PSX) src/st/sel/sel.h
$(CPP) $(CPP_FLAGS) -lang-c $< | $(SOTNSTR) | $(ICONV) | $(CC) $(CC_FLAGS) $(PSXCC_FLAGS) | $(MASPSX) | $(AS) $(AS_FLAGS) -o $@
st0: stst0_dirs $(BUILD_DIR)/ST0.BIN $(BUILD_DIR)/F_ST0.BIN
$(BUILD_DIR)/ST0.BIN: $(BUILD_DIR)/stst0.elf

View File

@ -83,7 +83,8 @@ segments:
- [0x64FC, .data, config_us] # enemies
- [0xA37C, .data, config_us] # exp table
- [0xA50C, .data, lba_stage]
- [0xB2CC, data]
- [0xB2CC, .data, stream_info]
- [0xB304, data]
- [0xCD54, .data, CD54]
- [0xDBD4, data]
- [0x176C0, rodata]

View File

@ -698,6 +698,7 @@ g_CastleFlags_0x34 = 0x8003BE20;
g_CastleFlags_0x35 = 0x8003BE21;
g_CastleFlags_0x62 = 0x8003BE4E;
g_CastleFlags_0x63 = 0x8003BE4F;
g_CurrentStream = 0x8003C100;
g_ClutIds = 0x8003C104;
D_8003C708_unk2 = 0x8003C70A;
D_8003C708_unk4 = 0x8003C70C;

View File

@ -1,7 +1,7 @@
g_EntityGfxs = 0x80180760;
g_StreamWidth = 0x8018B2FC;
g_StreamHeight = 0x8018B300;
g_Streams = 0x8018B2EC;
func_801B69F8 = 0x801B69F8;
StreamDiskIsReady = 0x801B9744;
StreamNextVlc = 0x801B988C;
func_801BAB70 = 0x801BAB70;
DecDCTvlc = 0x801BABA4;
@ -10,6 +10,7 @@ g_MemCardRStepSub = 0x801BAFF0;
g_MemCardRetryCount = 0x801BAFF8;
g_MemcardRetryCount = 0x801BC2F8;
g_MemcardFd = 0x801BC2FC;
g_StreamDiskIsReady = 0x801BC344;
g_Dialogue = 0x801BC354;
g_MemCardSelectorX = 0x801BC3D8;
g_MemCardSelectorY = 0x801BC3DC;
@ -32,6 +33,7 @@ g_SaveSummary_1_padding = 0x801BD02C;
g_StreamEndFrame = 0x801BD034;
g_StreamIsRGB24 = 0x801BD038;
g_StreamRewindSwitch = 0x801BD044;
g_StreamImageBuffer = 0x801BD048;
g_InputCursorPos = 0x801D6B08;
g_MemcardBlockRead = 0x801D6B10;
g_InputSaveName = 0x801D6B14;

View File

@ -712,6 +712,7 @@ g_CastleFlags_0x34 = 0x8003BE20;
g_CastleFlags_0x35 = 0x8003BE21;
g_CastleFlags_0x62 = 0x8003BE4E;
g_CastleFlags_0x63 = 0x8003BE4F;
g_CurrentStream = 0x8003C100;
g_ClutIds = 0x8003C104;
D_8003C708_unk2 = 0x8003C70A;
D_8003C708_unk4 = 0x8003C70C;

View File

@ -366,6 +366,7 @@ extern EnemyDef g_EnemyDefs[400];
extern s32 g_ExpNext[];
extern u16 D_800AC958[];
extern CdFile* D_800ACC74[];
extern s32 g_CurrentStream;
extern Vram g_Vram;
extern s32 D_800ACE44;
extern s16 D_800ACE88[];

View File

@ -577,7 +577,7 @@ void HandleVideoPlayback(void) {
case 5:
if (!g_IsUsingCd) {
D_8003C728 = 1;
D_8003C100 = 1;
g_CurrentStream = 1;
g_GameStep++;
}
break;

View File

@ -80,7 +80,7 @@ s32 D_801BB010;
s32 D_801BB014;
u16 D_801BB0F8[0x30][0x30];
s32 D_801BC340;
s32 D_801BC344;
s32 g_StreamDiscStatus;
s32 D_801BC348;
s32 D_801BC34C;
s32 D_801BC350;
@ -99,7 +99,7 @@ u32 g_StreamEndFrame;
u32 g_StreamIsRGB24[1];
u32 D_801BD03C;
u32 D_801BD040;
s32 g_StreamRewindSwitch[0x5001];
s32 g_StreamRewindSwitch[1];
s32 D_801D104C[0x1680];
s32 D_801D6B04;
s32 g_InputCursorPos;

View File

@ -74,6 +74,7 @@ s32 D_8006C384;
s32 D_8006C388;
s32 D_8006C38C;
s32 D_8006C390;
s32 g_CurrentStream;
u16 g_ClutIds[0x400];
s32 D_8003C738;
u8 g_CastleFlags[0x300];

View File

@ -376,7 +376,7 @@ void SEL_Init(s32 objLayoutId) {
}
g_IsTimeAttackUnlocked = true;
D_8003C728 = 1;
D_8003C100 = 0;
g_CurrentStream = 0;
D_8003C9A4 = 1;
break;
@ -388,7 +388,7 @@ void SEL_Init(s32 objLayoutId) {
}
#endif
g_IsTimeAttackUnlocked = false;
D_8003C100 = 0;
g_CurrentStream = 0;
func_801B18F4();
g_GameState = Game_Title;
D_8003C9A4 = 0;

View File

@ -339,9 +339,9 @@ void func_801B60D4(void) {
if (!g_IsUsingCd) {
D_8003C728 = 1;
if (D_800978B4 == 0) {
D_8003C100 = 2;
g_CurrentStream = 2;
} else {
D_8003C100 = 3;
g_CurrentStream = 3;
}
D_8003C9A4++;
}
@ -350,7 +350,7 @@ void func_801B60D4(void) {
case 1:
func_801B9C80();
if (D_8003C728 == 0) {
D_8003C100 = 0;
g_CurrentStream = 0;
func_801B18F4();
}
if (D_800978B4 != 0) {

View File

@ -92,12 +92,35 @@ typedef struct {
const char* line2;
} StageName;
typedef struct {
u_long* vlcbuf[2]; // 0x00
int vlcid; // 0x08
u_short* imgbuf[2]; // 0x0c
int imgid; // 0x20
RECT rect[2]; // 0x24
int rectid; // 0x32
RECT slice;
int isdone;
} DECENV;
typedef struct {
u32 cdOffset;
u16 frameCount;
u16 isRGB24;
} StreamInfo;
extern s32 g_CurrentStream;
extern const char* D_801803A8[10];
extern StageName D_80180128[80];
extern const s32 D_801A7B8C[2];
extern void* g_Cluts[];
extern void* g_EntityGfxs[];
extern StreamInfo g_StreamInfo0;
extern StreamInfo g_StreamInfo1;
extern StreamInfo g_StreamInfo2;
extern StreamInfo g_StreamInfo3;
extern StreamInfo* g_Streams[4];
extern s16** g_SpriteBanks[]; // g_SpriteBanks
extern void* D_8018C404[]; // unknown type
@ -175,7 +198,7 @@ extern const char D_8018BC54[];
extern s32 g_MemcardRetryCount;
extern s32 g_MemcardFd;
extern s32 D_801BC340;
extern s32 D_801BC344;
extern s32 g_StreamDiskIsReady;
extern s32 D_801BC348;
extern s32 D_801BC34C;
extern s32 D_801BC350;
@ -193,8 +216,10 @@ extern u32 D_801BD030;
extern u32 g_StreamEndFrame;
extern u32 D_801BD03C;
extern u32 D_801BD040;
extern s32 g_StreamRewindSwitch[0x5001];
extern s32 g_StreamRewindSwitch[1];
extern u8 g_StreamImageBuffer[0x14000];
extern s32 D_801D104C[0x1680];
extern DECENV* D_801D6A4C[2];
extern s32 D_801D6B04;
extern s32 g_InputCursorPos;
extern s32 D_801D6B0C;

View File

@ -1,36 +1,28 @@
#include "sel.h"
extern s32 g_StreamWidth;
extern int g_StreamHeight;
extern u32 g_StreamEndFrame;
extern s32 g_StreamRewindSwitch[];
typedef struct {
u_long* vlcbuf[2];
int vlcid;
u_short* imgbuf[2];
int imgid;
RECT rect[2];
int rectid;
RECT slice;
int isdone;
} DECENV;
s32 func_801B9744(void) {
// Check if CD data is ready as long as its not related to reading the position
// of the laser. The status is cached in the `g_StreamDiskIsReady` global.
//
// returns:
// 0 - disk isn't ready for a request
// 1 - disk is ready
s32 StreamDiskIsReady() {
u8 res;
int ret;
// if CD data isn't ready
if (CdSync(1, &res) == CdlNoIntr) {
return D_801BC344 = 0;
return g_StreamDiskIsReady = 0;
}
ret = CdLastCom();
if (ret >= CdlGetlocL && ret <= CdlGetlocP || !(res & CdlStatShellOpen)) {
// clear the command
CdControlF(1, NULL);
return D_801BC344 = 0;
return g_StreamDiskIsReady = 0;
}
return D_801BC344 = 1;
return g_StreamDiskIsReady = 1;
}
u_long* StreamNext(DECENV* dec) {

35
src/st/sel/stream_info.c Normal file
View File

@ -0,0 +1,35 @@
#include "sel.h"
StreamInfo g_StreamInfo0 = {
.cdOffset = 0x5a49,
.frameCount = 0x8f,
.isRGB24 = 1,
};
StreamInfo g_StreamInfo1 = {
.cdOffset = 0x3631,
.frameCount = 0x39a,
.isRGB24 = 1,
};
StreamInfo g_StreamInfo2 = {
.cdOffset = 0x207d,
.frameCount = 0x221,
.isRGB24 = 1,
};
StreamInfo g_StreamInfo3 = {
.cdOffset = 0x36f,
.frameCount = 0x2e4,
.isRGB24 = 1,
};
StreamInfo* g_Streams[] = {
&g_StreamInfo0,
&g_StreamInfo1,
&g_StreamInfo2,
&g_StreamInfo3,
};
s32 g_StreamWidth = 0;
s32 g_StreamHeight = 0;