| 1 | /* Mednafen - Multi-system Emulator |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 16 | */ |
| 17 | |
| 18 | #include <stdint.h> |
| 19 | #include <stdlib.h> |
| 20 | #include <string.h> |
| 21 | |
| 22 | #include <boolean.h>cxx . . $ `<file>/libretro-common/include/boolean.h`/ |
| 23 | #include <retro_inline.h>cxx . . $ `<file>/libretro-common/include/retro_inline.h`/ |
| 24 | #include <compat/msvc.h>cxx . . $ `<file>/libretro-common/include/compat/msvc.h`/ |
| 25 | #include <compat/strl.h>cxx . . $ `<file>/libretro-common/include/compat/strl.h`/ |
| 26 | |
| 27 | #include "state.h"cxx . . $ `<file>/mednafen/state.h`/ |
| 28 | |
| 29 | #define SSEEK_ENDcxx . . $ `mednafen/state.c:29:9`! 2 |
| 30 | #define SSEEK_CURcxx . . $ `mednafen/state.c:30:9`! 1 |
| 31 | #define SSEEK_SETcxx . . $ `mednafen/state.c:31:9`! 0 |
| 32 | |
| 33 | #define RLSBcxx . . $ `mednafen/state.c:33:9`! MDFNSTATE_RLSB //0x80000000 |
| 34 | |
| 35 | /* Forward declaration */ |
| 36 | int StateActioncxx . . $ StateAction(a45b884b8cf568d5).(StateMemcxx . . $ StateMem# *sm, int load, int data_only); |
| 37 | |
| 38 | static INLINEcxx . . $ `<built-in>:421:9`! void MDFN_en32lsbcxx . . $ MDFN_en32lsb(e1e8b00c42c42532).(uint8_tcxx . . $ uint8_t# *buf, uint32_tcxx . . $ uint32_t# morp) |
| 39 | { |
| 40 | buf[0]=morp; |
| 41 | buf[1]=morp>>8; |
| 42 | buf[2]=morp>>16; |
| 43 | buf[3]=morp>>24; |
| 44 | } |
| 45 | |
| 46 | static INLINEcxx . . $ `<built-in>:421:9`! uint32_tcxx . . $ uint32_t# MDFN_de32lsbcxx . . $ MDFN_de32lsb(ca1608e2c87725e2).(const uint8_tcxx . . $ uint8_t# *morp) |
| 47 | { |
| 48 | return(morp[0]|(morp[1]<<8)|(morp[2]<<16)|(morp[3]<<24)); |
| 49 | } |
| 50 | |
| 51 | #ifdef MSB_FIRST |
| 52 | static INLINE void Endian_A64_Swap(void *src, uint32_t nelements) |
| 53 | { |
| 54 | uint32_t i; |
| 55 | uint8_t *nsrc = (uint8_t *)src; |
| 56 | |
| 57 | for(i = 0; i < nelements; i++) |
| 58 | { |
| 59 | unsigned z; |
| 60 | uint8_t *base = &nsrc[i * 8]; |
| 61 | |
| 62 | for(z = 0; z < 4; z++) |
| 63 | { |
| 64 | uint8_t tmp = base[z]; |
| 65 | |
| 66 | base[z] = base[7 - z]; |
| 67 | base[7 - z] = tmp; |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | static INLINE void Endian_A32_Swap(void *src, uint32_t nelements) |
| 73 | { |
| 74 | uint32_t i; |
| 75 | uint8_t *nsrc = (uint8_t *)src; |
| 76 | |
| 77 | for(i = 0; i < nelements; i++) |
| 78 | { |
| 79 | uint8_t tmp1 = nsrc[i * 4]; |
| 80 | uint8_t tmp2 = nsrc[i * 4 + 1]; |
| 81 | |
| 82 | nsrc[i * 4] = nsrc[i * 4 + 3]; |
| 83 | nsrc[i * 4 + 1] = nsrc[i * 4 + 2]; |
| 84 | |
| 85 | nsrc[i * 4 + 2] = tmp2; |
| 86 | nsrc[i * 4 + 3] = tmp1; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | void Endian_A16_Swap(void *src, uint32_t nelements) |
| 91 | { |
| 92 | uint32_t i; |
| 93 | uint8_t *nsrc = (uint8_t *)src; |
| 94 | |
| 95 | for(i = 0; i < nelements; i++) |
| 96 | { |
| 97 | uint8_t tmp = nsrc[i * 2]; |
| 98 | |
| 99 | nsrc[i * 2] = nsrc[i * 2 + 1]; |
| 100 | nsrc[i * 2 + 1] = tmp; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | static INLINE void FlipByteOrder(uint8_t *src, uint32_t count) |
| 105 | { |
| 106 | uint8_t *start=src; |
| 107 | uint8_t *end=src+count-1; |
| 108 | |
| 109 | if((count&1) || !count) |
| 110 | return; /* This shouldn't happen. */ |
| 111 | |
| 112 | count >>= 1; |
| 113 | |
| 114 | while(count--) |
| 115 | { |
| 116 | uint8_t tmp; |
| 117 | |
| 118 | tmp=*end; |
| 119 | *end=*start; |
| 120 | *start=tmp; |
| 121 | end--; |
| 122 | start++; |
| 123 | } |
| 124 | } |
| 125 | #endif |
| 126 | |
| 127 | static int32_tcxx . . $ int32_t# smem_readcxx . . $ smem_read(f3982eecb66031e).(StateMemcxx . . $ StateMem# *st, void *buffer, uint32_tcxx . . $ uint32_t# len) |
| 128 | { |
| 129 | if ((len + st->loccxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#loc.) > st->lencxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#len.) |
| 130 | return 0; |
| 131 | |
| 132 | memcpycxx . . $ memcpy(cc817cb175f282d).(buffer, st->datacxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#data. + st->loccxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#loc., len); |
| 133 | st->loccxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#loc. += len; |
| 134 | |
| 135 | return(len); |
| 136 | } |
| 137 | |
| 138 | static int32_tcxx . . $ int32_t# smem_writecxx . . $ smem_write(f3982eecb66031e).(StateMemcxx . . $ StateMem# *st, void *buffer, uint32_tcxx . . $ uint32_t# len) |
| 139 | { |
| 140 | if ((len + st->loccxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#loc.) > st->mallocedcxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#malloced.) |
| 141 | { |
| 142 | uint32_tcxx . . $ uint32_t# newsize = (st->mallocedcxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#malloced. >= 32768) ? st->mallocedcxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#malloced. : (st->initial_malloccxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#initial_malloc. ? st->initial_malloccxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#initial_malloc. : 32768); |
| 143 | |
| 144 | while(newsize < (len + st->loccxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#loc.)) |
| 145 | newsize *= 2; |
| 146 | st->datacxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#data. = (uint8_tcxx . . $ uint8_t# *)realloccxx . . $ realloc(417ab160f6baadc6).(st->datacxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#data., newsize); |
| 147 | st->mallocedcxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#malloced. = newsize; |
| 148 | } |
| 149 | memcpycxx . . $ memcpy(cc817cb175f282d).(st->datacxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#data. + st->loccxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#loc., buffer, len); |
| 150 | st->loccxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#loc. += len; |
| 151 | |
| 152 | if (st->loccxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#loc. > st->lencxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#len.) |
| 153 | st->lencxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#len. = st->loccxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#loc.; |
| 154 | |
| 155 | return(len); |
| 156 | } |
| 157 | |
| 158 | static int32_tcxx . . $ int32_t# smem_seekcxx . . $ smem_seek(bece8f0ac61bc7de).(StateMemcxx . . $ StateMem# *st, uint32_tcxx . . $ uint32_t# offset, int whence) |
| 159 | { |
| 160 | switch(whence) |
| 161 | { |
| 162 | case SSEEK_SETcxx . . $ `mednafen/state.c:31:9`!: |
| 163 | st->loccxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#loc. = offset; |
| 164 | break; |
| 165 | case SSEEK_ENDcxx . . $ `mednafen/state.c:29:9`!: |
| 166 | st->loccxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#loc. = st->lencxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#len. - offset; |
| 167 | break; |
| 168 | case SSEEK_CURcxx . . $ `mednafen/state.c:30:9`!: |
| 169 | st->loccxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#loc. += offset; |
| 170 | break; |
| 171 | } |
| 172 | |
| 173 | if(st->loccxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#loc. > st->lencxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#len.) |
| 174 | { |
| 175 | st->loccxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#loc. = st->lencxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#len.; |
| 176 | return(-1); |
| 177 | } |
| 178 | |
| 179 | return(0); |
| 180 | } |
| 181 | |
| 182 | static int smem_write32lecxx . . $ smem_write32le(776f7c4058af06c3).(StateMemcxx . . $ StateMem# *st, uint32_tcxx . . $ uint32_t# b) |
| 183 | { |
| 184 | uint8_tcxx . . $ uint8_t# s[4]; |
| 185 | s[0]=b; |
| 186 | s[1]=b>>8; |
| 187 | s[2]=b>>16; |
| 188 | s[3]=b>>24; |
| 189 | return((smem_writecxx . . $ smem_write(f3982eecb66031e).(st, s, 4)<4)?0:4); |
| 190 | } |
| 191 | |
| 192 | static int smem_read32lecxx . . $ smem_read32le(24a07498b85603a0).(StateMemcxx . . $ StateMem# *st, uint32_tcxx . . $ uint32_t# *b) |
| 193 | { |
| 194 | uint8_tcxx . . $ uint8_t# s[4]; |
| 195 | |
| 196 | if(smem_readcxx . . $ smem_read(f3982eecb66031e).(st, s, 4) < 4) |
| 197 | return(0); |
| 198 | |
| 199 | *b = s[0] | (s[1] << 8) | (s[2] << 16) | (s[3] << 24); |
| 200 | |
| 201 | return(4); |
| 202 | } |
| 203 | |
| 204 | static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! SubWritecxx . . $ SubWrite(ad20ba8c6dea56a3).(StateMemcxx . . $ StateMem# *st, SFORMATcxx . . $ SFORMAT# *sf) |
| 205 | { |
| 206 | /* Size can sometimes be zero, so also check for the text name. |
| 207 | * These two should both be zero only at the end of a struct. */ |
| 208 | while(sf->sizecxx . . $ $anonymous_type_8d6ca9fa7c8baca5_1#size. || sf->namecxx . . $ $anonymous_type_8d6ca9fa7c8baca5_1#name.) |
| 209 | { |
| 210 | int32_tcxx . . $ int32_t# bytesize; |
| 211 | char nameo[1 + 256]; |
| 212 | |
| 213 | if(!sf->sizecxx . . $ $anonymous_type_8d6ca9fa7c8baca5_1#size. || !sf->vcxx . . $ $anonymous_type_8d6ca9fa7c8baca5_1#v.) |
| 214 | { |
| 215 | sf++; |
| 216 | continue; |
| 217 | } |
| 218 | |
| 219 | /* Link to another struct. */ |
| 220 | if(sf->sizecxx . . $ $anonymous_type_8d6ca9fa7c8baca5_1#size. == (uint32_tcxx . . $ uint32_t#)~0) |
| 221 | { |
| 222 | if(!SubWritecxx . . $ SubWrite(ad20ba8c6dea56a3).(st, (SFORMATcxx . . $ SFORMAT# *)sf->vcxx . . $ $anonymous_type_8d6ca9fa7c8baca5_1#v.)) |
| 223 | return(0); |
| 224 | |
| 225 | sf++; |
| 226 | continue; |
| 227 | } |
| 228 | |
| 229 | bytesize = sf->sizecxx . . $ $anonymous_type_8d6ca9fa7c8baca5_1#size.; |
| 230 | nameo[0] = strlcpycxx . . $ `libretro-common/include/compat/strl.h:46:9`!(nameo + 1, sf->name, 256); |
| 231 | |
| 232 | smem_writecxx . . $ smem_write(f3982eecb66031e).(st, nameo, 1 + nameo[0]); |
| 233 | smem_write32lecxx . . $ smem_write32le(776f7c4058af06c3).(st, bytesize); |
| 234 | |
| 235 | #ifdef MSB_FIRST |
| 236 | /* Flip the byte order... */ |
| 237 | if(sf->flags & MDFNSTATE_BOOL) { } |
| 238 | else if(sf->flags & MDFNSTATE_RLSB64) |
| 239 | Endian_A64_Swap(sf->v, bytesize / sizeof(uint64_t)); |
| 240 | else if(sf->flags & MDFNSTATE_RLSB32) |
| 241 | Endian_A32_Swap(sf->v, bytesize / sizeof(uint32_t)); |
| 242 | else if(sf->flags & MDFNSTATE_RLSB16) |
| 243 | Endian_A16_Swap(sf->v, bytesize / sizeof(uint16_t)); |
| 244 | else if(sf->flags & RLSB) |
| 245 | FlipByteOrder((uint8_t*)sf->v, bytesize); |
| 246 | #endif |
| 247 | |
| 248 | /* Special case for the evil bool type, |
| 249 | * to convert bool to 1-byte elements. |
| 250 | * Don't do it if we're only saving the raw data. */ |
| 251 | if(sf->flagscxx . . $ $anonymous_type_8d6ca9fa7c8baca5_1#flags. & MDFNSTATE_BOOLcxx . . $ `mednafen/state.h:34:9`!) |
| 252 | { |
| 253 | int32_tcxx . . $ int32_t# bool_monster; |
| 254 | for (bool_monster = 0; bool_monster < bytesize; bool_monster++) |
| 255 | { |
| 256 | uint8_tcxx . . $ uint8_t# tmp_bool = ((boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! *)sf->vcxx . . $ $anonymous_type_8d6ca9fa7c8baca5_1#v.)[bool_monster]; |
| 257 | smem_writecxx . . $ smem_write(f3982eecb66031e).(st, &tmp_bool, 1); |
| 258 | } |
| 259 | } |
| 260 | else |
| 261 | smem_writecxx . . $ smem_write(f3982eecb66031e).(st, (uint8_tcxx . . $ uint8_t# *)sf->vcxx . . $ $anonymous_type_8d6ca9fa7c8baca5_1#v., bytesize); |
| 262 | |
| 263 | #ifdef MSB_FIRST |
| 264 | /* Now restore the original byte order. */ |
| 265 | if(sf->flags & MDFNSTATE_BOOL) |
| 266 | { |
| 267 | |
| 268 | } |
| 269 | else if(sf->flags & MDFNSTATE_RLSB64) |
| 270 | Endian_A64_Swap(sf->v, bytesize / sizeof(uint64_t)); |
| 271 | else if(sf->flags & MDFNSTATE_RLSB32) |
| 272 | Endian_A32_Swap(sf->v, bytesize / sizeof(uint32_t)); |
| 273 | else if(sf->flags & MDFNSTATE_RLSB16) |
| 274 | Endian_A16_Swap(sf->v, bytesize / sizeof(uint16_t)); |
| 275 | else if(sf->flags & RLSB) |
| 276 | FlipByteOrder((uint8_t*)sf->v, bytesize); |
| 277 | #endif |
| 278 | sf++; |
| 279 | } |
| 280 | |
| 281 | return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 282 | } |
| 283 | |
| 284 | static int WriteStateChunkcxx . . $ WriteStateChunk(3cb24b6ce25cfb57).(StateMemcxx . . $ StateMem# *st, const char *sname, SFORMATcxx . . $ SFORMAT# *sf) |
| 285 | { |
| 286 | int32_tcxx . . $ int32_t# data_start_pos; |
| 287 | int32_tcxx . . $ int32_t# end_pos; |
| 288 | |
| 289 | uint8_tcxx . . $ uint8_t# sname_tmp[32]; |
| 290 | size_t sname_len = strlencxx . . $ strlen(751346f8406fd082).(sname); |
| 291 | |
| 292 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(sname_tmp, 0, sizeof(sname_tmp)); |
| 293 | memcpycxx . . $ memcpy(cc817cb175f282d).((char *)sname_tmp, sname, (sname_len < 32) ? sname_len : 32); |
| 294 | |
| 295 | smem_writecxx . . $ smem_write(f3982eecb66031e).(st, sname_tmp, 32); |
| 296 | |
| 297 | smem_write32lecxx . . $ smem_write32le(776f7c4058af06c3).(st, 0); // We'll come back and write this later. |
| 298 | |
| 299 | data_start_pos = st->loccxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#loc.; |
| 300 | |
| 301 | if(!SubWritecxx . . $ SubWrite(ad20ba8c6dea56a3).(st, sf)) |
| 302 | return(0); |
| 303 | |
| 304 | end_pos = st->loccxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#loc.; |
| 305 | |
| 306 | smem_seekcxx . . $ smem_seek(bece8f0ac61bc7de).(st, data_start_pos - 4, SSEEK_SETcxx . . $ `mednafen/state.c:31:9`!); |
| 307 | smem_write32lecxx . . $ smem_write32le(776f7c4058af06c3).(st, end_pos - data_start_pos); |
| 308 | smem_seekcxx . . $ smem_seek(bece8f0ac61bc7de).(st, end_pos, SSEEK_SETcxx . . $ `mednafen/state.c:31:9`!); |
| 309 | |
| 310 | return(end_pos - data_start_pos); |
| 311 | } |
| 312 | |
| 313 | static SFORMATcxx . . $ SFORMAT# *FindSFcxx . . $ FindSF(4480ff28afbfffaf).(const char *name, SFORMATcxx . . $ SFORMAT# *sf) |
| 314 | { |
| 315 | /* Size can sometimes be zero, so also check for the text name. |
| 316 | * These two should both be zero only at the end of a struct. */ |
| 317 | while(sf->sizecxx . . $ $anonymous_type_8d6ca9fa7c8baca5_1#size. || sf->namecxx . . $ $anonymous_type_8d6ca9fa7c8baca5_1#name.) |
| 318 | { |
| 319 | if(!sf->sizecxx . . $ $anonymous_type_8d6ca9fa7c8baca5_1#size. || !sf->vcxx . . $ $anonymous_type_8d6ca9fa7c8baca5_1#v.) |
| 320 | { |
| 321 | sf++; |
| 322 | continue; |
| 323 | } |
| 324 | |
| 325 | /* Link to another SFORMAT structure. */ |
| 326 | if (sf->sizecxx . . $ $anonymous_type_8d6ca9fa7c8baca5_1#size. == (uint32_tcxx . . $ uint32_t#)~0) |
| 327 | { |
| 328 | SFORMATcxx . . $ SFORMAT# *temp_sf = FindSFcxx . . $ FindSF(4480ff28afbfffaf).(name, (SFORMATcxx . . $ SFORMAT#*)sf->vcxx . . $ $anonymous_type_8d6ca9fa7c8baca5_1#v.); |
| 329 | if (temp_sf) |
| 330 | return temp_sf; |
| 331 | } |
| 332 | else |
| 333 | { |
| 334 | if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(sf->namecxx . . $ $anonymous_type_8d6ca9fa7c8baca5_1#name., name)) |
| 335 | return sf; |
| 336 | } |
| 337 | |
| 338 | sf++; |
| 339 | } |
| 340 | |
| 341 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 342 | } |
| 343 | |
| 344 | static int ReadStateChunkcxx . . $ ReadStateChunk(96770ba063a35803).(StateMemcxx . . $ StateMem# *st, SFORMATcxx . . $ SFORMAT# *sf, int size) |
| 345 | { |
| 346 | int temp = st->loccxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#loc.; |
| 347 | |
| 348 | while (st->loccxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#loc. < (temp + size)) |
| 349 | { |
| 350 | /* Don't change to char unless cast |
| 351 | * toa[0] to unsigned to smem_read() |
| 352 | * and other places. */ |
| 353 | uint8_tcxx . . $ uint8_t# toa[1 + 256]; |
| 354 | uint32_tcxx . . $ uint32_t# recorded_size = 0; /* In bytes */ |
| 355 | SFORMATcxx . . $ SFORMAT# *tmp = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 356 | |
| 357 | if(smem_readcxx . . $ smem_read(f3982eecb66031e).(st, toa, 1) != 1) |
| 358 | return(0); |
| 359 | |
| 360 | if(smem_readcxx . . $ smem_read(f3982eecb66031e).(st, toa + 1, toa[0]) != toa[0]) |
| 361 | return 0; |
| 362 | |
| 363 | toa[1 + toa[0]] = 0; |
| 364 | |
| 365 | smem_read32lecxx . . $ smem_read32le(24a07498b85603a0).(st, &recorded_size); |
| 366 | |
| 367 | tmp = FindSFcxx . . $ FindSF(4480ff28afbfffaf).((char*)toa + 1, sf); |
| 368 | |
| 369 | if(tmp) |
| 370 | { |
| 371 | uint32_tcxx . . $ uint32_t# expected_size = tmp->sizecxx . . $ $anonymous_type_8d6ca9fa7c8baca5_1#size.; /* In bytes */ |
| 372 | |
| 373 | if(recorded_size != expected_size) |
| 374 | { |
| 375 | if(smem_seekcxx . . $ smem_seek(bece8f0ac61bc7de).(st, recorded_size, SSEEK_CURcxx . . $ `mednafen/state.c:30:9`!) < 0) |
| 376 | return(0); |
| 377 | } |
| 378 | else |
| 379 | { |
| 380 | smem_readcxx . . $ smem_read(f3982eecb66031e).(st, (uint8_tcxx . . $ uint8_t# *)tmp->vcxx . . $ $anonymous_type_8d6ca9fa7c8baca5_1#v., expected_size); |
| 381 | |
| 382 | if(tmp->flagscxx . . $ $anonymous_type_8d6ca9fa7c8baca5_1#flags. & MDFNSTATE_BOOLcxx . . $ `mednafen/state.h:34:9`!) |
| 383 | { |
| 384 | int32_tcxx . . $ int32_t# bool_monster; |
| 385 | /* Converting downwards is necessary |
| 386 | * for the case of sizeof(bool) > 1 */ |
| 387 | for(bool_monster = expected_size - 1; bool_monster >= 0; bool_monster--) |
| 388 | ((boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! *)tmp->vcxx . . $ $anonymous_type_8d6ca9fa7c8baca5_1#v.)[bool_monster] = ((uint8_tcxx . . $ uint8_t# *)tmp->vcxx . . $ $anonymous_type_8d6ca9fa7c8baca5_1#v.)[bool_monster]; |
| 389 | } |
| 390 | |
| 391 | #ifdef MSB_FIRST |
| 392 | if(tmp->flags & MDFNSTATE_RLSB64) |
| 393 | Endian_A64_Swap(tmp->v, expected_size / sizeof(uint64_t)); |
| 394 | else if(tmp->flags & MDFNSTATE_RLSB32) |
| 395 | Endian_A32_Swap(tmp->v, expected_size / sizeof(uint32_t)); |
| 396 | else if(tmp->flags & MDFNSTATE_RLSB16) |
| 397 | Endian_A16_Swap(tmp->v, expected_size / sizeof(uint16_t)); |
| 398 | else if(tmp->flags & RLSB) |
| 399 | FlipByteOrder((uint8_t*)tmp->v, expected_size); |
| 400 | #endif |
| 401 | } |
| 402 | } |
| 403 | else |
| 404 | { |
| 405 | if(smem_seekcxx . . $ smem_seek(bece8f0ac61bc7de).(st, recorded_size, SSEEK_CURcxx . . $ `mednafen/state.c:30:9`!) < 0) |
| 406 | return(0); |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | return 1; |
| 411 | } |
| 412 | |
| 413 | static int MDFNSS_StateAction_internalcxx . . $ MDFNSS_StateAction_internal(6862ceab0c69af86).(StateMemcxx . . $ StateMem# *st, int load, int data_only, |
| 414 | struct SSDescriptorcxx . . $ SSDescriptor# *section) |
| 415 | { |
| 416 | if(load) |
| 417 | { |
| 418 | char sname[32]; |
| 419 | |
| 420 | uint32_tcxx . . $ uint32_t# tmp_size = 0; |
| 421 | int found = 0; |
| 422 | uint32_tcxx . . $ uint32_t# total = 0; |
| 423 | |
| 424 | while(smem_readcxx . . $ smem_read(f3982eecb66031e).(st, (uint8_tcxx . . $ uint8_t# *)sname, 32) == 32) |
| 425 | { |
| 426 | if(smem_read32lecxx . . $ smem_read32le(24a07498b85603a0).(st, &tmp_size) != 4) |
| 427 | return(0); |
| 428 | |
| 429 | total += tmp_size + 32 + 4; |
| 430 | |
| 431 | // Yay, we found the section |
| 432 | if(!strncmpcxx . . $ strncmp(fd278af2f295fa2e).(sname, section->namecxx . . $ SSDescriptor#name., 32)) |
| 433 | { |
| 434 | if(!ReadStateChunkcxx . . $ ReadStateChunk(96770ba063a35803).(st, section->sfcxx . . $ SSDescriptor#sf., tmp_size)) |
| 435 | return(0); |
| 436 | found = 1; |
| 437 | break; |
| 438 | } |
| 439 | else |
| 440 | { |
| 441 | if(smem_seekcxx . . $ smem_seek(bece8f0ac61bc7de).(st, tmp_size, SSEEK_CURcxx . . $ `mednafen/state.c:30:9`!) < 0) |
| 442 | return(0); |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | if(smem_seekcxx . . $ smem_seek(bece8f0ac61bc7de).(st, -total, SSEEK_CURcxx . . $ `mednafen/state.c:30:9`!) < 0) |
| 447 | return(0); |
| 448 | |
| 449 | if(!found) // Not found. We are sad! |
| 450 | return(0); |
| 451 | } |
| 452 | else |
| 453 | { |
| 454 | if(!WriteStateChunkcxx . . $ WriteStateChunk(3cb24b6ce25cfb57).(st, section->namecxx . . $ SSDescriptor#name., section->sfcxx . . $ SSDescriptor#sf.)) |
| 455 | return(0); |
| 456 | } |
| 457 | |
| 458 | return(1); |
| 459 | } |
| 460 | |
| 461 | int MDFNSS_StateActioncxx . . $ MDFNSS_StateAction(3f628545d3b0df83).(void *st_p, int load, int data_only, SFORMATcxx . . $ SFORMAT# *sf, const char *name, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! optional) |
| 462 | { |
| 463 | struct SSDescriptorcxx . . $ SSDescriptor# love; |
| 464 | StateMemcxx . . $ StateMem# *st = (StateMemcxx . . $ StateMem#*)st_p; |
| 465 | |
| 466 | love.sfcxx . . $ SSDescriptor#sf. = sf; |
| 467 | love.namecxx . . $ SSDescriptor#name. = name; |
| 468 | |
| 469 | return MDFNSS_StateAction_internalcxx . . $ MDFNSS_StateAction_internal(6862ceab0c69af86).(st, load, 0, &love); |
| 470 | } |
| 471 | |
| 472 | int MDFNSS_SaveSMcxx . . $ MDFNSS_SaveSM(d855d810c36bab0b).(void *st_p, int a, int b, const void*c, const void*d, const void*e) |
| 473 | { |
| 474 | uint32_tcxx . . $ uint32_t# sizy; |
| 475 | uint8_tcxx . . $ uint8_t# header[32]; |
| 476 | StateMemcxx . . $ StateMem# *st = (StateMemcxx . . $ StateMem#*)st_p; |
| 477 | static const char *header_magic = "MDFNSVST"; |
| 478 | int neowidth = 0, neoheight = 0; |
| 479 | |
| 480 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(header, 0, sizeof(header)); |
| 481 | memcpycxx . . $ memcpy(cc817cb175f282d).(header, header_magic, 8); |
| 482 | |
| 483 | MDFN_en32lsbcxx . . $ MDFN_en32lsb(e1e8b00c42c42532).(header + 16, MEDNAFEN_VERSION_NUMERICcxx . . $ `<built-in>:415:9`!); |
| 484 | MDFN_en32lsbcxx . . $ MDFN_en32lsb(e1e8b00c42c42532).(header + 24, neowidth); |
| 485 | MDFN_en32lsbcxx . . $ MDFN_en32lsb(e1e8b00c42c42532).(header + 28, neoheight); |
| 486 | smem_writecxx . . $ smem_write(f3982eecb66031e).(st, header, 32); |
| 487 | |
| 488 | if(!StateActioncxx . . $ StateAction(a45b884b8cf568d5).(st, 0, 0)) |
| 489 | return(0); |
| 490 | |
| 491 | sizy = st->loccxx . . $ $anonymous_type_8d6ca9fa7c8baca5_0#loc.; |
| 492 | smem_seekcxx . . $ smem_seek(bece8f0ac61bc7de).(st, 16 + 4, SSEEK_SETcxx . . $ `mednafen/state.c:31:9`!); |
| 493 | smem_write32lecxx . . $ smem_write32le(776f7c4058af06c3).(st, sizy); |
| 494 | |
| 495 | return(1); |
| 496 | } |
| 497 | |
| 498 | int MDFNSS_LoadSMcxx . . $ MDFNSS_LoadSM(4d015e8c0eefb98e).(void *st_p, int a, int b) |
| 499 | { |
| 500 | uint8_tcxx . . $ uint8_t# header[32]; |
| 501 | uint32_tcxx . . $ uint32_t# stateversion; |
| 502 | StateMemcxx . . $ StateMem# *st = (StateMemcxx . . $ StateMem#*)st_p; |
| 503 | |
| 504 | smem_readcxx . . $ smem_read(f3982eecb66031e).(st, header, 32); |
| 505 | |
| 506 | if(memcmpcxx . . $ memcmp(36f949851efa3055).(header, "MEDNAFENSVESTATE", 16) && memcmpcxx . . $ memcmp(36f949851efa3055).(header, "MDFNSVST", 8)) |
| 507 | return(0); |
| 508 | |
| 509 | stateversion = MDFN_de32lsbcxx . . $ MDFN_de32lsb(ca1608e2c87725e2).(header + 16); |
| 510 | |
| 511 | return(StateActioncxx . . $ StateAction(a45b884b8cf568d5).(st, stateversion, 0)); |
| 512 | } |