From 4bf8710c195b366d3fdaf9c709e07b40f723ec90 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 18 Feb 2017 16:03:40 +0100 Subject: [PATCH] Cleanups --- mednafen/git.h | 2 - mednafen/mednafen-endian.c | 192 ------------------------------------- mednafen/mednafen-endian.h | 3 - mednafen/state.cpp | 88 ++++++++++++++--- mednafen/state.h | 5 +- 5 files changed, 78 insertions(+), 212 deletions(-) delete mode 100644 mednafen/mednafen-endian.c diff --git a/mednafen/git.h b/mednafen/git.h index 3a28c911..4bb5c24e 100644 --- a/mednafen/git.h +++ b/mednafen/git.h @@ -320,8 +320,6 @@ typedef struct const char *cspecial; /* Special cart expansion: DIP switches, barcode reader, etc. */ - std::vectorDesiredInput; // Desired input device for the input ports, NULL for don't care - // For mouse relative motion. double mouse_sensitivity; diff --git a/mednafen/mednafen-endian.c b/mednafen/mednafen-endian.c deleted file mode 100644 index 2edde009..00000000 --- a/mednafen/mednafen-endian.c +++ /dev/null @@ -1,192 +0,0 @@ -/* Mednafen - Multi-system Emulator - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mednafen-endian.h" - -void Endian_A16_Swap(void *src, uint32_t nelements) -{ - uint32_t i; - uint8_t *nsrc = (uint8_t *)src; - - for(i = 0; i < nelements; i++) - { - uint8_t tmp = nsrc[i * 2]; - - nsrc[i * 2] = nsrc[i * 2 + 1]; - nsrc[i * 2 + 1] = tmp; - } -} - -void Endian_A32_Swap(void *src, uint32_t nelements) -{ - uint32_t i; - uint8_t *nsrc = (uint8_t *)src; - - for(i = 0; i < nelements; i++) - { - uint8_t tmp1 = nsrc[i * 4]; - uint8_t tmp2 = nsrc[i * 4 + 1]; - - nsrc[i * 4] = nsrc[i * 4 + 3]; - nsrc[i * 4 + 1] = nsrc[i * 4 + 2]; - - nsrc[i * 4 + 2] = tmp2; - nsrc[i * 4 + 3] = tmp1; - } -} - -void Endian_A64_Swap(void *src, uint32_t nelements) -{ - uint32_t i; - uint8_t *nsrc = (uint8_t *)src; - - for(i = 0; i < nelements; i++) - { - unsigned z; - uint8_t *base = &nsrc[i * 8]; - - for(z = 0; z < 4; z++) - { - uint8_t tmp = base[z]; - - base[z] = base[7 - z]; - base[7 - z] = tmp; - } - } -} - -void Endian_A16_LE_to_NE(void *src, uint32_t nelements) -{ -#ifdef MSB_FIRST - uint32_t i; - uint8_t *nsrc = (uint8_t *)src; - - for(i = 0; i < nelements; i++) - { - uint8_t tmp = nsrc[i * 2]; - - nsrc[i * 2] = nsrc[i * 2 + 1]; - nsrc[i * 2 + 1] = tmp; - } -#endif -} - -void Endian_A16_BE_to_NE(void *src, uint32_t nelements) -{ -#ifndef MSB_FIRST - uint32_t i; - uint8_t *nsrc = (uint8_t *)src; - - for(i = 0; i < nelements; i++) - { - uint8_t tmp = nsrc[i * 2]; - - nsrc[i * 2] = nsrc[i * 2 + 1]; - nsrc[i * 2 + 1] = tmp; - } -#endif -} - - -void Endian_A32_LE_to_NE(void *src, uint32_t nelements) -{ -#ifdef MSB_FIRST - uint32_t i; - uint8_t *nsrc = (uint8_t *)src; - - for(i = 0; i < nelements; i++) - { - uint8_t tmp1 = nsrc[i * 4]; - uint8_t tmp2 = nsrc[i * 4 + 1]; - - nsrc[i * 4] = nsrc[i * 4 + 3]; - nsrc[i * 4 + 1] = nsrc[i * 4 + 2]; - - nsrc[i * 4 + 2] = tmp2; - nsrc[i * 4 + 3] = tmp1; - } -#endif -} - -void Endian_A64_LE_to_NE(void *src, uint32_t nelements) -{ -#ifdef MSB_FIRST - uint32_t i; - uint8_t *nsrc = (uint8_t *)src; - - for(i = 0; i < nelements; i++) - { - unsigned z; - uint8_t *base = &nsrc[i * 8]; - - for(z = 0; z < 4; z++) - { - uint8_t tmp = base[z]; - - base[z] = base[7 - z]; - base[7 - z] = tmp; - } - } -#endif -} - -void FlipByteOrder(uint8_t *src, uint32_t count) -{ - uint8_t *start=src; - uint8_t *end=src+count-1; - - if((count&1) || !count) - return; /* This shouldn't happen. */ - - count >>= 1; - - while(count--) - { - uint8_t tmp; - - tmp=*end; - *end=*start; - *start=tmp; - end--; - start++; - } -} - -int read32le(uint32_t *Bufo, FILE *fp) -{ - uint32_t buf; - if(fread(&buf,1,4,fp)<4) - return 0; -#ifdef MSB_FIRST - *(uint32_t*)Bufo=((buf&0xFF)<<24)|((buf&0xFF00)<<8)|((buf&0xFF0000)>>8)|((buf&0xFF000000)>>24); -#else - *(uint32_t*)Bufo=buf; -#endif - return 1; -} - -int read16le(char *d, FILE *fp) -{ -#ifdef MSB_FIRST - int ret=fread(d+1,1,1,fp); - ret+=fread(d,1,1,fp); - return ret<2?0:2; -#else - return((fread(d,1,2,fp)<2)?0:2); -#endif -} - diff --git a/mednafen/mednafen-endian.h b/mednafen/mednafen-endian.h index 73f568f1..5cbf500f 100644 --- a/mednafen/mednafen-endian.h +++ b/mednafen/mednafen-endian.h @@ -39,10 +39,7 @@ void Endian_A16_Swap(void *src, uint32_t nelements); void Endian_A32_Swap(void *src, uint32_t nelements); void Endian_A64_Swap(void *src, uint32_t nelements); -void Endian_A16_LE_to_NE(void *src, uint32_t nelements); void Endian_A16_BE_to_NE(void *src, uint32_t nelements); -void Endian_A32_LE_to_NE(void *src, uint32_t nelements); -void Endian_A64_LE_to_NE(void *src, uint32_t nelements); void FlipByteOrder(uint8_t *src, uint32_t count); diff --git a/mednafen/state.cpp b/mednafen/state.cpp index f568b45f..10a6e995 100644 --- a/mednafen/state.cpp +++ b/mednafen/state.cpp @@ -19,18 +19,84 @@ #include +#include + #include #include "mednafen.h" #include "driver.h" #include "general.h" #include "state.h" -#include "video.h" - -#include "mednafen-endian.h" #define RLSB MDFNSTATE_RLSB //0x80000000 +static inline void MDFN_en32lsb(uint8_t *buf, uint32_t morp) +{ + buf[0]=morp; + buf[1]=morp>>8; + buf[2]=morp>>16; + buf[3]=morp>>24; +} + +static inline uint32_t MDFN_de32lsb(const uint8_t *morp) +{ + return(morp[0]|(morp[1]<<8)|(morp[2]<<16)|(morp[3]<<24)); +} + +#ifdef MSB_FIRST +static inline void Endian_A16_Swap(void *src, uint32_t nelements) +{ + uint32_t i; + uint8_t *nsrc = (uint8_t *)src; + + for(i = 0; i < nelements; i++) + { + uint8_t tmp = nsrc[i * 2]; + + nsrc[i * 2] = nsrc[i * 2 + 1]; + nsrc[i * 2 + 1] = tmp; + } +} + +static inline void Endian_A32_Swap(void *src, uint32_t nelements) +{ + uint32_t i; + uint8_t *nsrc = (uint8_t *)src; + + for(i = 0; i < nelements; i++) + { + uint8_t tmp1 = nsrc[i * 4]; + uint8_t tmp2 = nsrc[i * 4 + 1]; + + nsrc[i * 4] = nsrc[i * 4 + 3]; + nsrc[i * 4 + 1] = nsrc[i * 4 + 2]; + + nsrc[i * 4 + 2] = tmp2; + nsrc[i * 4 + 3] = tmp1; + } +} + +static inline void Endian_A64_Swap(void *src, uint32_t nelements) +{ + uint32_t i; + uint8_t *nsrc = (uint8_t *)src; + + for(i = 0; i < nelements; i++) + { + unsigned z; + uint8_t *base = &nsrc[i * 8]; + + for(z = 0; z < 4; z++) + { + uint8_t tmp = base[z]; + + base[z] = base[7 - z]; + base[7 - z] = tmp; + } + } +} +#endif + int32_t smem_read(StateMem *st, void *buffer, uint32_t len) { if ((len + st->loc) > st->len) @@ -189,11 +255,11 @@ static bool SubWrite(StateMem *st, SFORMAT *sf, const char *name_prefix = NULL) } else if(sf->flags & MDFNSTATE_RLSB64) - Endian_A64_LE_to_NE(sf->v, bytesize / sizeof(uint64_t)); + Endian_A64_Swap(sf->v, bytesize / sizeof(uint64_t)); else if(sf->flags & MDFNSTATE_RLSB32) - Endian_A32_LE_to_NE(sf->v, bytesize / sizeof(uint32_t)); + Endian_A32_Swap(sf->v, bytesize / sizeof(uint32_t)); else if(sf->flags & MDFNSTATE_RLSB16) - Endian_A16_LE_to_NE(sf->v, bytesize / sizeof(uint16_t)); + Endian_A16_Swap(sf->v, bytesize / sizeof(uint16_t)); else if(sf->flags & RLSB) FlipByteOrder((uint8_t*)sf->v, bytesize); #endif @@ -350,11 +416,11 @@ static int ReadStateChunk(StateMem *st, SFORMAT *sf, int size) } #ifdef MSB_FIRST if(tmp->flags & MDFNSTATE_RLSB64) - Endian_A64_LE_to_NE(tmp->v, expected_size / sizeof(uint64_t)); + Endian_A64_Swap(tmp->v, expected_size / sizeof(uint64_t)); else if(tmp->flags & MDFNSTATE_RLSB32) - Endian_A32_LE_to_NE(tmp->v, expected_size / sizeof(uint32_t)); + Endian_A32_Swap(tmp->v, expected_size / sizeof(uint32_t)); else if(tmp->flags & MDFNSTATE_RLSB16) - Endian_A16_LE_to_NE(tmp->v, expected_size / sizeof(uint16_t)); + Endian_A16_Swap(tmp->v, expected_size / sizeof(uint16_t)); else if(tmp->flags & RLSB) FlipByteOrder((uint8_t*)tmp->v, expected_size); #endif @@ -378,7 +444,7 @@ static int ReadStateChunk(StateMem *st, SFORMAT *sf, int size) static int CurrentState = 0; /* This function is called by the game driver(NES, GB, GBA) to save a state. */ -int MDFNSS_StateAction(void *st_p, int load, int data_only, std::vector §ions) +static int MDFNSS_StateAction_internal(void *st_p, int load, int data_only, std::vector §ions) { StateMem *st = (StateMem*)st_p; std::vector::iterator section; @@ -454,7 +520,7 @@ int MDFNSS_StateAction(void *st_p, int load, int data_only, SFORMAT *sf, const c std::vector love; love.push_back(SSDescriptor(sf, name, optional)); - return(MDFNSS_StateAction(st, load, 0, love)); + return MDFNSS_StateAction_internal(st, load, 0, love); } int MDFNSS_SaveSM(void *st_p, int, int, const void*, const void*, const void*) diff --git a/mednafen/state.h b/mednafen/state.h index 6446e2bc..e9d20f86 100644 --- a/mednafen/state.h +++ b/mednafen/state.h @@ -89,9 +89,7 @@ INLINE uint32_t SF_FORCE_D(double *) { return(0); } #define SFEND { 0, 0, 0, 0 } -#include - -// State-Section Descriptor +/* State-Section Descriptor */ class SSDescriptor { public: @@ -111,7 +109,6 @@ class SSDescriptor bool optional; }; -int MDFNSS_StateAction(void *st, int load, int data_only, std::vector §ions); int MDFNSS_StateAction(void *st, int load, int data_only, SFORMAT *sf, const char *name, bool optional = 0); #endif