misc: put some debug stuff in savestates
authornotaz <notasas@gmail.com>
Thu, 27 Mar 2025 20:48:20 +0000 (22:48 +0200)
committernotaz <notasas@gmail.com>
Thu, 27 Mar 2025 20:51:00 +0000 (22:51 +0200)
for issue reports where people provide savestates

.gitignore
Makefile
frontend/main.c
jni/Android.mk
libpcsxcore/misc.c
libpcsxcore/misc.h

index 5717500..b4aa211 100644 (file)
@@ -12,8 +12,8 @@ pcsx.map
 config.mak
 config.log
 cheatpops.db
-frontend/revision.h
-tools
+/include/revision.h
+/tools
 obj/
 .vscode/
 .vscode/ipch/*
index 46b57e4..4ec5baa 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -464,10 +464,11 @@ endif
 
 # misc
 OBJS += frontend/main.o frontend/plugin.o
-frontend/main.o: CFLAGS += -DBUILTIN_GPU=$(BUILTIN_GPU)
+frontend/main.o libpcsxcore/misc.o: CFLAGS += -DBUILTIN_GPU=$(BUILTIN_GPU)
 
-frontend/menu.o frontend/main.o: frontend/revision.h
-frontend/plat_sdl.o frontend/libretro.o: frontend/revision.h
+frontend/menu.o frontend/main.o: include/revision.h
+frontend/plat_sdl.o frontend/libretro.o: include/revision.h
+libpcsxcore/misc.o: include/revision.h
 
 CFLAGS += $(CFLAGS_LAST)
 
@@ -479,7 +480,7 @@ frontend/libpicofe/%.c:
 libpcsxcore/gte_nf.o: libpcsxcore/gte.c
        $(CC) -c -o $@ $^ $(CFLAGS) -DFLAGLESS
 
-frontend/revision.h: FORCE
+include/revision.h: FORCE
        @(git describe --always || echo) | sed -e 's/.*/#define REV "\0"/' > $@_
        @diff -q $@_ $@ > /dev/null 2>&1 || cp $@_ $@
        @rm $@_
@@ -502,7 +503,7 @@ else
 endif
 
 clean: $(PLAT_CLEAN) clean_plugins
-       $(RM) $(TARGET) *.o $(OBJS) $(TARGET).map frontend/revision.h
+       $(RM) $(TARGET) *.o $(OBJS) $(TARGET).map include/revision.h
 
 ifneq ($(PLUGINS),)
 plugins_: $(PLUGINS)
index 56f8fd4..b282ec3 100644 (file)
@@ -436,49 +436,6 @@ static void log_wrong_cpu(void)
 #endif // DO_CPU_CHECKS
 }
 
-#define MKSTR2(x) #x
-#define MKSTR(x) MKSTR2(x)
-static const char *get_build_info(void)
-{
-       return " ("
-#ifdef __VERSION__
-               "cc " __VERSION__ " "
-#endif
-#if defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 8
-               "64bit "
-#elif defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 4
-               "32bit "
-#endif
-#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-               "be "
-#endif
-#if defined(__PIC__) || defined(__pic__)
-               "pic "
-#endif
-#if defined(__aarch64__)
-               "arm64"
-#elif defined(__arm__)
-               "arm"
-#endif
-#ifdef __ARM_ARCH
-               "v" MKSTR(__ARM_ARCH) " "
-#endif
-#if defined(__AVX__)
-               "avx "
-#elif defined(__SSSE3__)
-               "ssse3 "
-#elif defined(__ARM_NEON) || defined(__ARM_NEON__)
-               "neon "
-#endif
-#if defined(LIGHTREC)
-               "lightrec "
-#elif !defined(DRC_DISABLE)
-               "ari64 "
-#endif
-               "gpu=" MKSTR(BUILTIN_GPU)
-               ")";
-}
-
 int emu_core_preinit(void)
 {
        // what is the name of the config file?
@@ -508,7 +465,7 @@ int emu_core_preinit(void)
 
 int emu_core_init(void)
 {
-       SysPrintf("Starting PCSX-ReARMed " REV "%s\n", get_build_info());
+       SysPrintf("Starting PCSX-ReARMed " REV " (%s)\n", get_build_info());
        SysPrintf("build time: " __DATE__ " " __TIME__ "\n");
 
 #if defined(__arm__) && defined(__ARM_FP)
index 9c45e67..81c2e12 100644 (file)
@@ -1,9 +1,9 @@
 LOCAL_PATH := $(call my-dir)
 include $(CLEAR_VARS)
 
-$(shell cd "$(LOCAL_PATH)" && ((git describe --always || echo) | sed -e 's/.*/#define REV "\0"/' > ../frontend/revision.h_))
-$(shell cd "$(LOCAL_PATH)" && (diff -q ../frontend/revision.h_ ../frontend/revision.h > /dev/null 2>&1 || cp ../frontend/revision.h_ ../frontend/revision.h))
-$(shell cd "$(LOCAL_PATH)" && (rm ../frontend/revision.h_))
+$(shell cd "$(LOCAL_PATH)" && ((git describe --always || echo) | sed -e 's/.*/#define REV "\0"/' > ../include/revision.h_))
+$(shell cd "$(LOCAL_PATH)" && (diff -q ../include/revision.h_ ../include/revision.h > /dev/null 2>&1 || cp ../include/revision.h_ ../include/revision.h))
+$(shell cd "$(LOCAL_PATH)" && (rm ../include/revision.h_))
 
 USE_LIBRETRO_VFS ?= 0
 USE_ASYNC_CDROM ?= 1
index 41999a5..a3e90e1 100644 (file)
 #include "psxbios.h"
 #include "database.h"
 #include <zlib.h>
+#include "revision.h"
 
 char CdromId[10] = "";
 char CdromLabel[33] = "";
 int  CdromFrontendId; // for frontend use
 
+static u32 save_counter;
+
 // PSX Executable types
 #define PSX_EXE     1
 #define CPE_EXE     2
@@ -204,6 +207,8 @@ int LoadCdrom() {
        u32 sp = 0;
        int i, ret;
 
+       save_counter = 0;
+
        if (!Config.HLE) {
                if (psxRegs.pc != 0x80030000) // BiosBootBypass'ed or custom BIOS?
                        return 0;
@@ -527,6 +532,8 @@ size_t fread_to_ram(void *ptr, size_t size, size_t nmemb, FILE *stream)
                memcpy(ptr, tmp, size * nmemb);
                free(tmp);
        }
+       else
+               ret = fread(ptr, size, nmemb, stream);
        return ret;
 }
 
@@ -661,12 +668,24 @@ struct PcsxSaveFuncs SaveFuncs = {
        zlib_open, zlib_read, zlib_write, zlib_seek, zlib_close
 };
 
-static const char PcsxHeader[32] = "STv4 PCSX v" PCSX_VERSION;
+static const char PcsxHeader[32] = "STv4 PCSXra " REV;
 
 // Savestate Versioning!
 // If you make changes to the savestate version, please increment the value below.
 static const u32 SaveVersion = 0x8b410006;
 
+struct origin_info {
+       boolean icache_emulation;
+       boolean DisableStalls;
+       boolean PreciseExceptions;
+       boolean TurboCD;
+       s8 GpuListWalking;
+       s8 FractionalFramerate;
+       u8 Cpu;
+       u8 PsxType;
+       char build_info[64];
+};
+
 #define MISC_MAGIC 0x4353494d
 struct misc_save_data {
        u32 magic;
@@ -678,17 +697,21 @@ struct misc_save_data {
        u32 gpuSr;
        u32 frame_counter;
        int CdromFrontendId;
+       u32 save_counter;
 };
 
+#define EX_SCREENPIC_SIZE (128 * 96 * 3)
+
 int SaveState(const char *file) {
        struct misc_save_data *misc = (void *)(psxH + 0xf000);
-       void *f;
+       struct origin_info oi = { 0, };
        GPUFreeze_t *gpufP = NULL;
        SPUFreezeHdr_t spufH;
        SPUFreeze_t *spufP = NULL;
-       unsigned char *pMem = NULL;
+       u8 buf[EX_SCREENPIC_SIZE];
        int result = -1;
        int Size;
+       void *f;
 
        assert(!psxRegs.branching);
        assert(!psxRegs.cpuInRecursion);
@@ -706,6 +729,7 @@ int SaveState(const char *file) {
        misc->gpuSr = HW_GPU_STATUS;
        misc->frame_counter = frame_counter;
        misc->CdromFrontendId = CdromFrontendId;
+       misc->save_counter = ++save_counter;
 
        psxCpu->Notify(R3000ACPU_NOTIFY_BEFORE_SAVE, NULL);
 
@@ -713,11 +737,22 @@ int SaveState(const char *file) {
        SaveFuncs.write(f, (void *)&SaveVersion, sizeof(u32));
        SaveFuncs.write(f, (void *)&Config.HLE, sizeof(boolean));
 
-       pMem = (unsigned char *)malloc(128 * 96 * 3);
-       if (pMem == NULL) goto cleanup;
-       GPU_getScreenPic(pMem);
-       SaveFuncs.write(f, pMem, 128 * 96 * 3);
-       free(pMem);
+       oi.icache_emulation = Config.icache_emulation;
+       oi.DisableStalls = Config.DisableStalls;
+       oi.PreciseExceptions = Config.PreciseExceptions;
+       oi.TurboCD = Config.TurboCD;
+       oi.GpuListWalking = Config.GpuListWalking;
+       oi.FractionalFramerate = Config.FractionalFramerate;
+       oi.Cpu = Config.Cpu;
+       oi.PsxType = Config.PsxType;
+       snprintf(oi.build_info, sizeof(oi.build_info), "%s", get_build_info());
+
+       // this was space for ScreenPic
+       assert(sizeof(buf) >= EX_SCREENPIC_SIZE);
+       assert(sizeof(oi) - 3 <= EX_SCREENPIC_SIZE);
+       memset(buf, 0, sizeof(buf));
+       memcpy(buf + 3, &oi, sizeof(oi));
+       SaveFuncs.write(f, buf, EX_SCREENPIC_SIZE);
 
        if (Config.HLE)
                psxBiosFreeze(1);
@@ -802,7 +837,9 @@ int LoadState(const char *file) {
        if (Config.HLE)
                psxBiosInit();
 
-       SaveFuncs.seek(f, 128 * 96 * 3, SEEK_CUR);
+       // ex-ScreenPic space
+       SaveFuncs.seek(f, EX_SCREENPIC_SIZE, SEEK_CUR);
+
        SaveFuncs.read(f, psxM, 0x00200000);
        SaveFuncs.read(f, psxR, 0x00080000);
        SaveFuncs.read(f, psxH, 0x00010000);
@@ -822,6 +859,8 @@ int LoadState(const char *file) {
                HW_GPU_STATUS = misc->gpuSr;
                frame_counter = misc->frame_counter;
                CdromFrontendId = misc->CdromFrontendId;
+               if (misc->save_counter)
+                       save_counter = misc->save_counter;
        }
 
        if (Config.HLE)
@@ -1013,3 +1052,54 @@ u16 calcCrc(const u8 *d, int len) {
 
        return ~crc;
 }
+
+#define MKSTR2(x) #x
+#define MKSTR(x) MKSTR2(x)
+const char *get_build_info(void)
+{
+       return ""
+#ifdef __VERSION__
+               "cc " __VERSION__ " "
+#endif
+#if defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 8
+               "64bit "
+#elif defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 4
+               "32bit "
+#endif
+#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+               "be "
+#endif
+#if defined(__PIE__) || defined(__pie__)
+               "pie "
+#endif
+#if defined(__PIC__) || defined(__pic__)
+               "pic "
+#endif
+#if defined(__aarch64__)
+               "arm64"
+#elif defined(__arm__)
+               "arm"
+#endif
+#ifdef __ARM_ARCH
+               "v" MKSTR(__ARM_ARCH) " "
+#endif
+#ifdef __thumb__
+               "thumb "
+#endif
+#if defined(__AVX__)
+               "avx "
+#elif defined(__SSSE3__)
+               "ssse3 "
+#elif defined(__ARM_NEON) || defined(__ARM_NEON__)
+               "neon "
+#endif
+#if defined(__ARM_FEATURE_SVE) && __ARM_FEATURE_SVE
+               "sve "
+#endif
+#if defined(LIGHTREC)
+               "lightrec "
+#elif !defined(DRC_DISABLE)
+               "ari64 "
+#endif
+               "gpu=" MKSTR(BUILTIN_GPU);
+}
index 303af7b..f1e319b 100644 (file)
@@ -74,6 +74,8 @@ int RecvPcsxInfo();
 void trim(char *str);
 u16 calcCrc(const u8 *d, int len);
 
+const char *get_build_info(void);
+
 #ifdef __cplusplus
 }
 #endif