Restore RELEASE target, tweak MDEC code to prevent optimizations

This commit is contained in:
Lucas S. Vieira 2024-10-30 01:44:57 -03:00
parent f9261e3d6e
commit 493e595cc8
4 changed files with 53 additions and 25 deletions

View file

@ -21,6 +21,22 @@
"warnings": { "warnings": {
"dev": false "dev": false
} }
},
{
"name": "release",
"displayName": "Release configuration",
"description": "Build the project using PSn00bSDK on Release target",
"generator": "Unix Makefiles",
"toolchainFile": "$env{PSN00BSDK_LIBS}/cmake/sdk.cmake",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"PSN00BSDK_TC": "",
"PSN00BSDK_TARGET": "mipsel-none-elf"
},
"warnings": {
"dev": false
}
} }
] ]
} }

View file

@ -32,18 +32,30 @@ run: ./build/engine.cue
-run -interpreter -fastboot -stdout \ -run -interpreter -fastboot -stdout \
-iso ./build/engine.cue -iso ./build/engine.cue
# Run on pcsx-redux, but don't build
dry-run:
pcsx-redux-appimage \
-run -interpreter -fastboot -stdout \
-iso ./build/engine.cue
# Target for running the image on Mednafen # Target for running the image on Mednafen
mednafen: ./build/engine.cue mednafen: ./build/engine.cue
mednafen $< mednafen $<
# Run PCSX-Redux emulator # Emulate on Mednafen, but do not build
emu: emu:
2>/dev/null 1>&2 pcsx-redux -gdb -gdb-port 3333 -run -interpreter -fastboot & mednafen ./build/engine.cue
# Run debugger # Run debugger
debug: debug:
gdb-multiarch gdb-multiarch
# Build on release target
release: purge cook
cmake --preset release .
cd build && make iso
tochd -d . -- ./build/engine.cue
# ======================================= # =======================================
# Targets for executable building # Targets for executable building
# ======================================= # =======================================

View file

@ -16,18 +16,18 @@
// Since the stream context in this case can use approx. 320K of RAM, // Since the stream context in this case can use approx. 320K of RAM,
// it seems like a better choice to let it live on the heap. // it seems like a better choice to let it live on the heap.
// No need to manage this using an arena allocator, though. // No need to manage this using an arena allocator, though.
static StreamContext *str_ctx = NULL; static volatile StreamContext *str_ctx = NULL;
// MDEC lookup table, generally lives on the scratchpad // MDEC lookup table, generally lives on the scratchpad
// Using v2 because it looks much better after AVI conversion! // Using v2 because it looks much better after AVI conversion!
static VLC_TableV2 *lookup_table; static volatile VLC_TableV2 *lookup_table;
// Temporary area for CD sectors read from CD. // Temporary area for CD sectors read from CD.
// Accessed by DMA, therefore must not be on heap // Accessed by DMA, therefore must not be on heap
static STR_Header sector_header; static volatile STR_Header sector_header;
// STR file location on CD // STR file location on CD
static CdlFILE file; static volatile CdlFILE file;
static int decode_errors; static int decode_errors;
static int frame_time; static int frame_time;
@ -67,7 +67,7 @@ mdec_start(const char *filepath)
// Copy MDEC lookup table to scratchpad // Copy MDEC lookup table to scratchpad
lookup_table = fastalloc_malloc(sizeof(VLC_TableV2)); lookup_table = fastalloc_malloc(sizeof(VLC_TableV2));
DecDCTvlcCopyTableV2(lookup_table); DecDCTvlcCopyTableV2((VLC_TableV2 *)lookup_table);
// Setup stream context // Setup stream context
if(!str_ctx) str_ctx = malloc(sizeof(StreamContext)); if(!str_ctx) str_ctx = malloc(sizeof(StreamContext));
@ -80,7 +80,7 @@ mdec_start(const char *filepath)
// Find file on CD. // Find file on CD.
// We won't be using the util.h library since we need to find // We won't be using the util.h library since we need to find
// the actual file position to stream // the actual file position to stream
if(!CdSearchFile(&file, filepath)) { if(!CdSearchFile((CdlFILE *)&file, filepath)) {
printf("Could not find .STR file %s.\n", filepath); printf("Could not find .STR file %s.\n", filepath);
// TODO: Halt forever? // TODO: Halt forever?
return; return;
@ -99,7 +99,7 @@ mdec_start(const char *filepath)
// Start reading in real-time mode (doesn't retry in case of errors). // Start reading in real-time mode (doesn't retry in case of errors).
uint8_t mode = CdlModeRT | CdlModeSpeed; uint8_t mode = CdlModeRT | CdlModeSpeed;
CdControl(CdlSetmode, (const uint8_t *)&mode, 0); CdControl(CdlSetmode, (const uint8_t *)&mode, 0);
CdControl(CdlReadS, &file.pos, 0); CdControl(CdlReadS, (const void *)&file.pos, 0);
// Wait for first frame to be buffered. // Wait for first frame to be buffered.
_mdec_get_next_frame(); _mdec_get_next_frame();
@ -114,7 +114,7 @@ mdec_stop()
CdControlB(CdlPause, 0, 0); CdControlB(CdlPause, 0, 0);
if(str_ctx) { if(str_ctx) {
free(str_ctx); free((void *)str_ctx);
str_ctx = NULL; str_ctx = NULL;
} }
fastalloc_free(); fastalloc_free();
@ -207,7 +207,7 @@ mdec_loop()
str_ctx->frame_width = VRAM_X_COORD(frame->width); str_ctx->frame_width = VRAM_X_COORD(frame->width);
DecDCTout( DecDCTout(
str_ctx->slices[str_ctx->cur_slice], (uint32_t *)str_ctx->slices[str_ctx->cur_slice],
BLOCK_SIZE * str_ctx->slice_pos.h / 2); BLOCK_SIZE * str_ctx->slice_pos.h / 2);
if(debug_mode) frame_time = (TIMER_VALUE(1) - frame_start) & 0xffff; if(debug_mode) frame_time = (TIMER_VALUE(1) - frame_start) & 0xffff;
@ -232,14 +232,14 @@ _mdec_dma_callback(void)
// Upload the decoded slice to VRAM and start decoding // Upload the decoded slice to VRAM and start decoding
// the next slice into another buffer, if any // the next slice into another buffer, if any
LoadImage(&str_ctx->slice_pos, str_ctx->slices[str_ctx->cur_slice]); LoadImage((const RECT *)&str_ctx->slice_pos, (const uint32_t *)str_ctx->slices[str_ctx->cur_slice]);
str_ctx->cur_slice ^= 0x1; str_ctx->cur_slice ^= 0x1;
str_ctx->slice_pos.x += BLOCK_SIZE; str_ctx->slice_pos.x += BLOCK_SIZE;
if(str_ctx->slice_pos.x < str_ctx->frame_width) { if(str_ctx->slice_pos.x < str_ctx->frame_width) {
DecDCTout( DecDCTout(
str_ctx->slices[str_ctx->cur_slice], (uint32_t *)str_ctx->slices[str_ctx->cur_slice],
BLOCK_SIZE * str_ctx->slice_pos.h / 2); BLOCK_SIZE * str_ctx->slice_pos.h / 2);
} }
} }
@ -266,13 +266,13 @@ _mdec_cd_event_callback(CdlIntrResult event, uint8_t *)
void void
_mdec_cd_sector_handler(void) _mdec_cd_sector_handler(void)
{ {
StreamBuffer *frame = &str_ctx->frames[str_ctx->cur_frame]; volatile StreamBuffer *frame = &str_ctx->frames[str_ctx->cur_frame];
// Fetch .STR header of the sector that has been read and // Fetch .STR header of the sector that has been read and
// make sure it is valid. If not, assume the file has ended // make sure it is valid. If not, assume the file has ended
// and set frame_ready as a signal for the playback loop to // and set frame_ready as a signal for the playback loop to
// stop playback. // stop playback.
CdGetSector(&sector_header, sizeof(STR_Header) >> 2); CdGetSector((void *)&sector_header, sizeof(STR_Header) >> 2);
if(sector_header.magic != 0x0160) { if(sector_header.magic != 0x0160) {
str_ctx->frame_ready = -1; str_ctx->frame_ready = -1;
return; return;
@ -311,7 +311,7 @@ _mdec_cd_sector_handler(void)
// Append payload contained in this sector to the current buffer // Append payload contained in this sector to the current buffer
str_ctx->sector_count--; str_ctx->sector_count--;
CdGetSector( CdGetSector(
&(frame->bs_data[2016 / 4 * sector_header.sector_id]), (void *)&(frame->bs_data[2016 / 4 * sector_header.sector_id]),
2016 / 4); 2016 / 4);
} }
@ -329,7 +329,7 @@ _mdec_get_next_frame(void)
} }
str_ctx->frame_ready = 0; str_ctx->frame_ready = 0;
return &str_ctx->frames[str_ctx->cur_frame ^ 0x1]; return (StreamBuffer *)&str_ctx->frames[str_ctx->cur_frame ^ 0x1];
} }

View file

@ -33,10 +33,10 @@ static int32_t next_channel = 0;
/* static XACDSector _sector; */ /* static XACDSector _sector; */
// Current .XA audio data start location. // Current .XA audio data start location.
static CdlLOC _xa_loc; static volatile CdlLOC _xa_loc;
static int _xa_should_play = 0; static volatile int _xa_should_play = 0;
static uint32_t _cd_status = 0; static volatile uint32_t _cd_status = 0;
static uint32_t _xa_loopback_sector = 0; static volatile uint32_t _xa_loopback_sector = 0;
// Read error threshold. If surpasses the limit, restart the music. // Read error threshold. If surpasses the limit, restart the music.
#define CD_MAX_ERR_THRESHOLD 10 #define CD_MAX_ERR_THRESHOLD 10
@ -199,7 +199,7 @@ sound_play_xa(const char *filename, int double_speed,
_cd_elapsed_sectors = 0; _cd_elapsed_sectors = 0;
_xa_loopback_sector = loopback_sector; _xa_loopback_sector = loopback_sector;
CdControl(CdlSetfilter, &filter, 0); CdControl(CdlSetfilter, &filter, 0);
CdControl(CdlReadS, &_xa_loc, 0); CdControl(CdlReadS, (const void *)&_xa_loc, 0);
_xa_should_play = 1; _xa_should_play = 1;
} }
@ -216,7 +216,7 @@ _xa_cd_event_callback(CdlIntrResult event, uint8_t * /* payload */)
// Loop back to beginning // Loop back to beginning
_cd_err_threshold = 0; _cd_err_threshold = 0;
_cd_elapsed_sectors = 0; _cd_elapsed_sectors = 0;
CdControlF(CdlReadS, &_xa_loc); CdControlF(CdlReadS, (const void *)&_xa_loc);
} }
break; break;
case CdlDiskError: case CdlDiskError: