shithub: zelda3

Download patch

ref: 1c4e0e1b7fea9dac2dc294926f0d12267d015faa
parent: a7a859b9652859b33a452bb436a3bc9b60a3e5bd
author: Snesrev <snesrev@protonmail.com>
date: Tue Oct 4 19:55:31 EDT 2022

Update Makefile and silence warnings (Fixes #136)

--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@
 PYTHON:=/usr/bin/env python3
 CFLAGS:=$(if $(CFLAGS),$(CFLAGS),-O2)
 
-CFLAGS:=${CFLAGS} $(shell sdl2-config --cflags)
+CFLAGS:=${CFLAGS} $(shell sdl2-config --cflags) -DSYSTEM_VOLUME_MIXER_AVAILABLE=0
 LDFLAGS:=${LDFLAGS} $(shell sdl2-config --libs)
 
 .PHONY: all clean clean_obj clean_gen
--- a/main.c
+++ b/main.c
@@ -157,7 +157,8 @@
       buf[pos] = 0;
       if (step != 0) {
         printf("Found zelda3.ini in %s\n", buf);
-        chdir(buf);
+        int err = chdir(buf);
+        (void)err;
       }
       return;
     }
--- a/zelda_rtl.c
+++ b/zelda_rtl.c
@@ -560,21 +560,26 @@
   //  printf("\n");
 }
 
+void ReadFromFile(FILE *f, void *data, size_t n) {
+  if (fread(data, 1, n, f) != n)
+    Die("fread failed\n");
+}
+
 void StateRecorder_Load(StateRecorder *sr, FILE *f, bool replay_mode) {
   // todo: fix robustness on invalid data.
   uint32 hdr[8] = { 0 };
-  fread(hdr, 1, sizeof(hdr), f);
+  ReadFromFile(f, hdr, sizeof(hdr));
 
   assert(hdr[0] == 1);
 
   sr->total_frames = hdr[1];
   ByteArray_Resize(&sr->log, hdr[2]);
-  fread(sr->log.data, 1, sr->log.size, f);
+  ReadFromFile(f, sr->log.data, sr->log.size);
   sr->last_inputs = hdr[3];
   sr->frames_since_last = hdr[4];
 
   ByteArray_Resize(&sr->base_snapshot, (hdr[5] & 1) ? hdr[6] : 0);
-  fread(sr->base_snapshot.data, 1, sr->base_snapshot.size, f);
+  ReadFromFile(f, sr->base_snapshot.data, sr->base_snapshot.size);
 
   sr->replay_next_cmd_at = 0;
 
@@ -603,7 +608,7 @@
 
     ByteArray arr = { 0 };
     ByteArray_Resize(&arr, hdr[6]);
-    fread(arr.data, 1, arr.size, f);
+    ReadFromFile(f, arr.data, arr.size);
     LoadFuncState state = { arr.data, arr.data + arr.size };
     LoadSnesState(&loadFunc, &state);
     ByteArray_Destroy(&arr);
@@ -1063,7 +1068,8 @@
 void ZeldaReadSram() {
   FILE *f = fopen("saves/sram.dat", "rb");
   if (f) {
-    fread(g_zenv.sram, 1, 8192, f);
+    if (fread(g_zenv.sram, 1, 8192, f) != 8192)
+      fprintf(stderr, "Error reading saves/sram.dat\n");
     fclose(f);
     EmuSynchronizeWholeState();
   }