Preload FMV locations on game boot-up, just like BGMs

This commit is contained in:
Lucas S. Vieira 2024-12-24 23:33:58 -03:00
parent ff7d5825aa
commit b9f8bc2f6f
5 changed files with 48 additions and 33 deletions

View file

@ -2,6 +2,7 @@
#define MDEC_H
#include "render.h"
#include <psxcd.h>
//#define BLOCK_SIZE 24
#define BLOCK_SIZE 16
@ -39,13 +40,21 @@ typedef struct {
uint32_t _reserved;
} STR_Header;
typedef enum {
FMV_SONICTEAM = 0,
FMV_PS30YRS = 1,
FMV_NUM_VIDEOS = FMV_PS30YRS + 1,
} FMVOption;
// Load all locations of FMVs on disc
void mdec_fmv_init();
// Use this function as main playback entrypoint.
// It will override the game loop and be stuck in a playback loop.
// Do not call the other functions directly unless you know what you're doing.
void mdec_play(const char *filepath);
void mdec_play(FMVOption);
void mdec_start(const char *filepath);
void mdec_start(volatile CdlLOC *loc);
void mdec_stop();
void mdec_loop();

View file

@ -2,12 +2,7 @@
#define SCREENS_FMV_H
#include "screen.h"
typedef enum {
FMV_SONICTEAM = 0,
FMV_PS30YRS = 1,
FMV_NUM_VIDEOS = FMV_PS30YRS + 1,
} FMVOption;
#include "mdec.h"
void screen_fmv_load();
void screen_fmv_unload(void *);

View file

@ -21,6 +21,7 @@
#include "memalloc.h"
#include "screen.h"
#include "basic_font.h"
#include "mdec.h"
/*
Locations of common textures on frame buffer:
@ -68,6 +69,7 @@ main(void)
// Initial loads from disc
render_loading_logo();
sound_bgm_init();
mdec_fmv_init();
// Set first scene
scene_change(SCREEN_DISCLAIMER);

View file

@ -29,9 +29,6 @@ static volatile VLC_TableV2 *lookup_table;
// Accessed by DMA, therefore must not be on heap
static volatile STR_Header sector_header;
// STR file location on CD
static volatile CdlFILE file;
static int decode_errors;
static int frame_time;
static volatile int should_abort;
@ -50,16 +47,44 @@ StreamBuffer *_mdec_get_next_frame(void);
int _mdec_should_abort();
void _mdec_swap_buffers();
// FMV table register
typedef struct {
const char *filename;
CdlLOC loc;
} FMVTableEntry;
static volatile FMVTableEntry fmv_table[] = {
{ "\\FMV\\SONICT.STR;1", (CdlLOC){ 0 } },
{ "\\FMV\\PS30YRS.STR;1", (CdlLOC){ 0 } },
};
void
mdec_play(const char *filepath)
mdec_fmv_init()
{
mdec_start(filepath);
CdlFILE file;
for(int i = 0; i < FMV_NUM_VIDEOS; i++) {
// Find file on CD.
// We won't be using the util.h library since we need to find
// the actual file position to stream
if(!CdSearchFile((CdlFILE *)&file, fmv_table[i].filename)) {
printf("Could not find .STR file %s.\n", fmv_table[i].filename);
fmv_table[i].loc = (CdlLOC){ 0 };
}
fmv_table[i].loc = file.pos;
}
}
void
mdec_play(FMVOption option)
{
mdec_start(&fmv_table[option].loc);
mdec_loop();
mdec_stop();
}
void
mdec_start(const char *filepath)
mdec_start(volatile CdlLOC *loc)
{
printf("Preparing MDEC playback.\n");
should_abort = 0;
@ -83,15 +108,6 @@ mdec_start(const char *filepath)
decode_errors = 0;
frame_time = 1;
// Find file on CD.
// We won't be using the util.h library since we need to find
// the actual file position to stream
if(!CdSearchFile((CdlFILE *)&file, filepath)) {
printf("Could not find .STR file %s.\n", filepath);
// TODO: Halt forever?
return;
}
// Prepare context
str_ctx->frame_id = -1;
@ -104,7 +120,7 @@ mdec_start(const char *filepath)
// Start reading in real-time mode (doesn't retry in case of errors).
uint8_t mode = CdlModeRT | CdlModeSpeed | CdlModeAP;
CdControl(CdlSetmode, (const uint8_t *)&mode, 0);
CdControlF(CdlReadS, (const void *)&file.pos);
CdControlF(CdlReadS, (const void *)loc);
// Wait for first frame to be buffered.
_mdec_get_next_frame();

View file

@ -1,6 +1,7 @@
#include "screens/fmv.h"
#include <stdlib.h>
#include <psxcd.h>
#include "screen.h"
#include "mdec.h"
@ -29,15 +30,7 @@ void
screen_fmv_update(void *)
{
for(uint8_t i = 0; i < fmv_count; i++) {
const char *fmvpath = NULL;
switch(fmv_queue[i]) {
case FMV_SONICTEAM: fmvpath = "\\FMV\\SONICT.STR;1"; break;
case FMV_PS30YRS: fmvpath = "\\FMV\\PS30YRS.STR;1"; break;
default: break;
}
if(fmvpath) mdec_play(fmvpath);
mdec_play(fmv_queue[i]);
}
scene_change(next_screen);
}