shithub: psxe

Download patch

ref: 9ddca2f9ecca955261ce8bba32c6ddc4fcac24e3
parent: 5b22040640c602f8a8b712d8343b45b675889db6
author: allkern <aurealinbox@gmail.com>
date: Wed Dec 20 06:46:22 EST 2023

Improve stability

--- a/.gitignore
+++ b/.gitignore
@@ -11,6 +11,7 @@
 bios/
 roms/
 snap/
+*.BIN
 *.bin
 *.dll
 *.exe
--- a/frontend/config.c
+++ b/frontend/config.c
@@ -72,6 +72,10 @@
     memset(cfg, 0, sizeof(psxe_config_t));
 }
 
+void psxe_cfg_destroy(psxe_config_t* cfg) {
+    free(cfg);
+}
+
 void psxe_cfg_load_defaults(psxe_config_t* cfg) {
     cfg->bios = NULL;
     cfg->bios_search = "bios";
--- a/frontend/main.c
+++ b/frontend/main.c
@@ -91,6 +91,8 @@
         psx_load_exe(psx, cfg->exe);
     }
 
+    psxe_cfg_destroy(cfg);
+
     while (psxe_screen_is_open(screen)) {
         psx_update(psx);
     }
--- a/psx/dev/gpu.c
+++ b/psx/dev/gpu.c
@@ -346,6 +346,9 @@
 }
 
 void gpu_render_rect(psx_gpu_t* gpu, rect_data_t data) {
+    if ((data.v0.x >= 1024) || (data.v0.y >= 512))
+        return;
+
     uint16_t width, height;
 
     switch ((data.attrib >> 3) & 3) {
@@ -394,9 +397,8 @@
                 if (!texel)
                     goto skip;
 
-                if (transp) {
+                if (transp)
                     transp = (texel & 0x8000) != 0;
-                }
 
                 int tr = ((texel >> 0 ) & 0x1f) << 3;
                 int tg = ((texel >> 5 ) & 0x1f) << 3;
@@ -802,7 +804,7 @@
 
                 if (textured && raw)
                     rect.v0.c = 0x808080;
-                
+
                 gpu_render_rect(gpu, rect);
 
                 gpu->state = GPU_STATE_RECV_CMD;
--- a/psx/dev/mdec.c
+++ b/psx/dev/mdec.c
@@ -190,7 +190,7 @@
         size_t block_size = (mdec->output_depth == 3) ? 512 : 768;
         size_t size = block_size;
 
-        ptrdiff_t bytes_processed = 0;
+        unsigned long bytes_processed = 0;
 
         int block_count = 1;
 
--- a/psx/dev/spu.c
+++ b/psx/dev/spu.c
@@ -427,7 +427,6 @@
 }
 
 void psx_spu_destroy(psx_spu_t* spu) {
-    printf("psx_spu_destroy called\n");
     free(spu->ram);
     free(spu);
 }
--- a/psx/disc/cue.c
+++ b/psx/disc/cue.c
@@ -68,7 +68,16 @@
 void cue_add_track(psxd_cue_t* cue) {
     ++cue->num_tracks;
 
-    cue->track = realloc(cue->track, cue->num_tracks * sizeof(cue_track_t*));
+    cue_track_t** new_track = realloc(cue->track, cue->num_tracks * sizeof(cue_track_t*));
+
+    if (!new_track) {
+        printf("Fatal error: Couldn't allocate a new CUE track\n");
+
+        exit(1);
+    }
+
+    cue->track = new_track;
+
     cue->track[cue->num_tracks - 1] = malloc(sizeof(cue_track_t));
 
     memset(cue->track[cue->num_tracks - 1], 0, sizeof(cue_track_t));
@@ -218,13 +227,13 @@
         return cue->error;
     
     int track = atoi(cue->buf) - 1;
-    
+
     if (track != cue->num_tracks)
         ERROR_OUT(PE_NON_SEQUENTIAL_TRACKS);
     
     cue_add_track(cue);
 
-    cue->track[track]->filename = malloc(strlen(cue->current_file));
+    cue->track[track]->filename = malloc(strlen(cue->current_file) + 1);
 
     // Copy current file to track filename
     strcpy(cue->track[track]->filename, cue->current_file);
@@ -313,15 +322,15 @@
 }
 
 int psxd_cue_load(psxd_cue_t* cue, const char* path) {
-    log_fatal("Parsing CUE...");
-
     FILE* file = fopen(path, "rb");
 
-    if (ferror(file) || !file) {
-        fclose(file);
+    if (!file) {
+        log_fatal("Couldn't open file \'%s\'", path);
 
         return 1;
     }
+
+    log_fatal("Parsing CUE...");
 
     if (cue_parse(cue, file)) {
         log_fatal("CUE error %s (%u)",
--