From 8d885fa94dada4bb748d39d660aa62c96b2c1de0 Mon Sep 17 00:00:00 2001 From: zeromus Date: Tue, 19 Jun 2012 20:44:05 +0000 Subject: [PATCH] fix savestate engine to throw errors when a buggy SFORMAT is passed to AddExState, and fix those errors in m015 and m253 --- src/boards/15.cpp | 5 +++-- src/boards/253.cpp | 2 +- src/state.cpp | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/boards/15.cpp b/src/boards/15.cpp index 175e8b99..88491dc4 100644 --- a/src/boards/15.cpp +++ b/src/boards/15.cpp @@ -27,8 +27,8 @@ static uint8 *WRAM=NULL; static uint32 WRAMSIZE; static SFORMAT StateRegs[]= { - {&latchea, 2, "LATCHEA"}, - {&latched, 1, "LATCHED"}, + {&latchea, 2, "AREG"}, + {&latched, 1, "DREG"}, {0} }; @@ -64,6 +64,7 @@ static DECLFW(M15Write) { latchea=A; latched=V; + printf("%04X = %02X\n",A,V); Sync(); } diff --git a/src/boards/253.cpp b/src/boards/253.cpp index 22bceec8..3ff5b042 100644 --- a/src/boards/253.cpp +++ b/src/boards/253.cpp @@ -37,7 +37,7 @@ static SFORMAT StateRegs[]= {&IRQa, 4, "IRQA"}, {&IRQCount, 4, "IRQC"}, {&IRQLatch, 4, "IRQL"}, - {&IRQClock, 4, "IRQCL"}, + {&IRQClock, 4, "IRQK"}, {0} }; diff --git a/src/state.cpp b/src/state.cpp index 31e50ed2..95bf97fb 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -842,6 +842,25 @@ void ResetExState(void (*PreSave)(void), void (*PostSave)(void)) void AddExState(void *v, uint32 s, int type, char *desc) { + if(s==~0) + { + SFORMAT* sf = (SFORMAT*)v; + std::map names; + while(sf->v) + { + char tmp[5] = {0}; + memcpy(tmp,sf->desc,4); + std::string desc = tmp; + if(names.find(desc) != names.end()) + { + printf("OH NO!!! YOU HAVE AN INVALID SFORMAT! POST A BUG TICKET ALONG WITH INFO ON THE ROM YOURE USING\n"); + exit(0); + } + names[desc] = true; + sf++; + } + } + if(desc) { SFMDATA[SFEXINDEX].desc=(char *)FCEU_malloc(strlen(desc)+1);