shithub: psxe

Download patch

ref: 93dd1f50e171d69f8fd9e9f929ae488850f3e4b2
parent: eac209e87ad4d1ad323c9302cb5493498cc61fca
author: allkern <lisandroaalarcon@gmail.com>
date: Mon Sep 4 08:09:11 EDT 2023

Fix CUE alloc

--- a/psx/disc/cue.c
+++ b/psx/disc/cue.c
@@ -68,9 +68,6 @@
 void* cue_alloc_block(void* buf, size_t* block_size, size_t ext) {
     *block_size += ext;
 
-    if (!buf)
-        return malloc(*block_size);
-    
     return realloc(buf, *block_size);
 }
 
@@ -300,8 +297,6 @@
 
     size_t offset = 0;
 
-    void* buf = NULL;
-
     for (int i = 0; i < cue->num_tracks; i++) {
         cue_track_t* track = cue->track[i];
 
@@ -320,10 +315,10 @@
         track->disc_offset.m = track->disc_offset.s / 60;
         track->disc_offset.s -= track->disc_offset.m * 60;
 
-        buf = cue_alloc_block(buf, &offset, track->size);
+        cue->buf = cue_alloc_block(cue->buf, &offset, track->size);
 
         fseek(file, 0, SEEK_SET);
-        fread((uint8_t*)buf + (offset - track->size), 1, track->size, file);
+        fread(cue->buf + (offset - track->size), 1, track->size, file);
 
         fclose(file);
     }
@@ -345,19 +340,21 @@
 int psxd_cue_seek(void* udata, msf_t msf) {
     psxd_cue_t* cue = udata;
 
-    log_fatal("CUE seek to %02u:%02u:%02u", msf.m, msf.s, msf.f);
-
     // To-do: Check for OOB seeks
 
-    uint32_t sectors = (((msf.m * 60) + (msf.s - 2)) * CUE_SECTORS_PER_SECOND) + msf.f;
+    uint32_t sectors = (((msf.m * 60) + msf.s - 2) * CUE_SECTORS_PER_SECOND) + msf.f;
 
     cue->seek_offset = sectors * CUE_SECTOR_SIZE;
 
+    log_fatal("CUE seek to %02u:%02u:%02u (%08x < %08x)", msf.m, msf.s, msf.f, cue->seek_offset, cue->buf_size);
+
     return 0;
 }
 
 int psxd_cue_read_sector(void* udata, void* buf) {
     psxd_cue_t* cue = udata;
+
+    log_fatal("Reading sector at offset %08x", cue->seek_offset);
 
     memcpy(buf, cue->buf + cue->seek_offset, CUE_SECTOR_SIZE);
 
--