Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Libretro
snes9x2002
Commits
69234219
Commit
69234219
authored
Jun 04, 2021
by
Libretro-Admin
Browse files
Backport file handling optimizations from snes9x 2010
parent
b6f65569
Pipeline
#29652
passed with stages
in 1 minute and 37 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
libretro/libretro.c
View file @
69234219
...
...
@@ -591,8 +591,7 @@ bool retro_load_game(const struct retro_game_info *game)
/* Hack. S9x cannot do stuff from RAM. <_< */
memstream_set_buffer
((
uint8_t
*
)
game
->
data
,
game
->
size
);
loaded
=
LoadROM
(
""
);
if
(
!
loaded
)
if
(
!
(
loaded
=
LoadROM
()))
return
false
;
//S9xGraphicsInit();
...
...
@@ -691,7 +690,9 @@ const char *S9xStringInput(const char *message) { return NULL; }
//bool S9xPollAxis(uint32 id, int16 *value) { return false; }
void
S9xExit
()
{
exit
(
1
);
}
bool8
S9xOpenSoundDevice
(
int
mode
,
bool8
stereo
,
int
buffer_size
)
{
bool8
S9xOpenSoundDevice
(
int
mode
,
bool8
stereo
,
int
buffer_size
)
{
//so.sixteen_bit = 1;
so
.
stereo
=
TRUE
;
//so.buffer_size = 534;
...
...
@@ -701,71 +702,4 @@ bool8 S9xOpenSoundDevice (int mode, bool8 stereo, int buffer_size) {
const
char
*
emptyString
=
""
;
const
char
*
S9xBasename
(
const
char
*
filename
)
{
return
emptyString
;
}
void
S9xMessage
(
int
a
,
int
b
,
const
char
*
msg
)
{
}
/* S9x weirdness. */
#ifndef _WIN32
void
_splitpath
(
const
char
*
path
,
char
*
drive
,
char
*
dir
,
char
*
fname
,
char
*
ext
)
{
const
char
*
slash
,
*
dot
;
slash
=
strrchr
(
path
,
SLASH_CHAR
);
dot
=
strrchr
(
path
,
'.'
);
if
(
dot
&&
slash
&&
dot
<
slash
)
dot
=
NULL
;
if
(
!
slash
)
{
*
dir
=
0
;
strcpy
(
fname
,
path
);
if
(
dot
)
{
fname
[
dot
-
path
]
=
0
;
strcpy
(
ext
,
dot
+
1
);
}
else
*
ext
=
0
;
}
else
{
strcpy
(
dir
,
path
);
dir
[
slash
-
path
]
=
0
;
strcpy
(
fname
,
slash
+
1
);
if
(
dot
)
{
fname
[
dot
-
slash
-
1
]
=
0
;
strcpy
(
ext
,
dot
+
1
);
}
else
*
ext
=
0
;
}
}
void
_makepath
(
char
*
path
,
const
char
*
a
,
const
char
*
dir
,
const
char
*
fname
,
const
char
*
ext
)
{
if
(
dir
&&
*
dir
)
{
strcpy
(
path
,
dir
);
strcat
(
path
,
SLASH_STR
);
}
else
*
path
=
0
;
strcat
(
path
,
fname
);
if
(
ext
&&
*
ext
)
{
strcat
(
path
,
"."
);
strcat
(
path
,
ext
);
}
}
#endif
void
S9xMessage
(
int
a
,
int
b
,
const
char
*
msg
)
{
}
src/memmap.c
View file @
69234219
...
...
@@ -289,20 +289,15 @@ void FreeSDD1Data ()
/* LoadROM() */
/* This function loads a Snes-Backup image */
/**********************************************************************************************/
bool8_32
LoadROM
(
const
char
*
filename
)
bool8_32
LoadROM
(
void
)
{
int
hi_score
,
lo_score
;
int32
TotalFileSize
=
0
;
unsigned
long
FileSize
=
0
;
int
retry_count
=
0
;
STREAM
ROMFile
;
bool8_32
Interleaved
=
FALSE
;
bool8_32
Interleaved
=
FALSE
;
bool8_32
Tales
=
FALSE
;
char
dir
[
_MAX_PATH
+
1
];
char
drive
[
_MAX_DRIVE
+
1
];
char
name
[
_MAX_PATH
+
1
];
char
ext
[
_MAX_PATH
+
1
];
char
fname
[
_MAX_PATH
+
1
];
int
i
;
memset
(
&
SNESGameFixes
,
0
,
sizeof
(
SNESGameFixes
));
...
...
@@ -313,87 +308,29 @@ bool8_32 LoadROM (const char *filename)
Memory
.
CalculatedSize
=
0
;
again:
_splitpath
(
filename
,
drive
,
dir
,
name
,
ext
);
_makepath
(
fname
,
drive
,
dir
,
name
,
ext
);
#ifdef __WIN32__
memmove
(
&
ext
[
0
],
&
ext
[
1
],
4
);
#endif
{
int
calc_size
;
uint8
*
ptr
;
bool8_32
more
=
FALSE
;
if
((
ROMFile
=
OPEN_STREAM
(
fname
,
"rb"
))
==
NULL
)
if
((
ROMFile
=
OPEN_STREAM
(
"rb"
))
==
NULL
)
return
(
FALSE
);
strcpy
(
Memory
.
ROMFilename
,
fname
);
Memory
.
HeaderCount
=
0
;
ptr
=
Memory
.
ROM
;
more
=
FALSE
;
do
{
int
len
;
int
calc_size
;
ptr
=
Memory
.
ROM
;
FileSize
=
READ_STREAM
(
ptr
,
MAX_ROM_SIZE
+
0x200
-
(
ptr
-
Memory
.
ROM
),
ROMFile
);
CLOSE_STREAM
(
ROMFile
);
calc_size
=
(
FileSize
/
0x2000
)
*
0x2000
;
FileSize
=
READ_STREAM
(
ptr
,
MAX_ROM_SIZE
+
0x200
-
(
ptr
-
Memory
.
ROM
),
ROMFile
);
CLOSE_STREAM
(
ROMFile
);
calc_size
=
(
FileSize
/
0x2000
)
*
0x2000
;
if
((
FileSize
-
calc_size
==
512
&&
!
Settings
.
ForceNoHeader
)
||
Settings
.
ForceHeader
)
{
memmove
(
ptr
,
ptr
+
512
,
calc_size
);
Memory
.
HeaderCount
++
;
FileSize
-=
512
;
}
ptr
+=
FileSize
;
TotalFileSize
+=
FileSize
;
if
(
ptr
-
Memory
.
ROM
<
MAX_ROM_SIZE
+
0x200
&&
(
isdigit
(
ext
[
0
])
&&
ext
[
1
]
==
0
&&
ext
[
0
]
<
'9'
))
{
more
=
TRUE
;
ext
[
0
]
++
;
#ifdef __WIN32__
memmove
(
&
ext
[
1
],
&
ext
[
0
],
4
);
ext
[
0
]
=
'.'
;
#endif
_makepath
(
fname
,
drive
,
dir
,
name
,
ext
);
}
else
if
(
ptr
-
Memory
.
ROM
<
MAX_ROM_SIZE
+
0x200
&&
(((
len
=
strlen
(
name
))
==
7
||
len
==
8
)
&&
strncasecmp
(
name
,
"sf"
,
2
)
==
0
&&
isdigit
(
name
[
2
])
&&
isdigit
(
name
[
3
])
&&
isdigit
(
name
[
4
])
&&
isdigit
(
name
[
5
])
&&
isalpha
(
name
[
len
-
1
])))
{
more
=
TRUE
;
name
[
len
-
1
]
++
;
#ifdef __WIN32__
memmove
(
&
ext
[
1
],
&
ext
[
0
],
4
);
ext
[
0
]
=
'.'
;
#endif
_makepath
(
fname
,
drive
,
dir
,
name
,
ext
);
}
else
more
=
FALSE
;
}
while
(
more
&&
(
ROMFile
=
OPEN_STREAM
(
fname
,
"rb"
))
!=
NULL
);
}
if
(
Memory
.
HeaderCount
==
0
)
S9xMessage
(
S9X_INFO
,
S9X_HEADERS_INFO
,
"No ROM file header found."
);
else
{
if
(
Memory
.
HeaderCount
==
1
)
S9xMessage
(
S9X_INFO
,
S9X_HEADERS_INFO
,
"Found ROM file header (and ignored it)."
);
else
S9xMessage
(
S9X_INFO
,
S9X_HEADERS_INFO
,
"Found multiple ROM file headers (and ignored them)."
);
if
((
FileSize
-
calc_size
==
512
&&
!
Settings
.
ForceNoHeader
)
||
Settings
.
ForceHeader
)
{
memmove
(
ptr
,
ptr
+
512
,
calc_size
);
Memory
.
HeaderCount
++
;
FileSize
-=
512
;
}
ptr
+=
FileSize
;
TotalFileSize
+=
FileSize
;
}
hi_score
=
ScoreHiROM
(
FALSE
);
...
...
src/memmap.h
View file @
69234219
...
...
@@ -80,40 +80,40 @@
#define MEMMAP_MASK (MEMMAP_BLOCK_SIZE - 1)
#define MEMMAP_MAX_SDD1_LOGGED_ENTRIES (0x10000 / 8)
bool8_32
LoadROM
(
const
char
*
);
bool8_32
LoadROM
(
void
);
void
InitROM
(
bool8_32
);
bool8_32
MemoryInit
();
void
MemoryDeinit
();
void
FreeSDD1Data
();
bool8_32
MemoryInit
(
void
);
void
MemoryDeinit
(
void
);
void
FreeSDD1Data
(
void
);
void
WriteProtectROM
();
void
FixROMSpeed
();
void
MapRAM
();
void
MapExtraRAM
();
void
WriteProtectROM
(
void
);
void
FixROMSpeed
(
void
);
void
MapRAM
(
void
);
void
MapExtraRAM
(
void
);
void
LoROMMap
();
void
LoROM24MBSMap
();
void
SRAM512KLoROMMap
();
void
SRAM1024KLoROMMap
();
void
SufamiTurboLoROMMap
();
void
HiROMMap
();
void
SuperFXROMMap
();
void
LoROMMap
(
void
);
void
LoROM24MBSMap
(
void
);
void
SRAM512KLoROMMap
(
void
);
void
SRAM1024KLoROMMap
(
void
);
void
SufamiTurboLoROMMap
(
void
);
void
HiROMMap
(
void
);
void
SuperFXROMMap
(
void
);
void
TalesROMMap
(
bool8_32
);
void
AlphaROMMap
();
void
SA1ROMMap
();
void
BSHiROMMap
();
void
ApplyROMFixes
();
void
AlphaROMMap
(
void
);
void
SA1ROMMap
(
void
);
void
BSHiROMMap
(
void
);
void
ApplyROMFixes
(
void
);
const
char
*
TVStandard
();
const
char
*
Speed
();
const
char
*
StaticRAMSize
();
const
char
*
MapType
();
const
char
*
MapMode
();
const
char
*
KartContents
();
const
char
*
Size
();
const
char
*
Headers
();
const
char
*
ROMID
();
const
char
*
CompanyID
();
const
char
*
TVStandard
(
void
);
const
char
*
Speed
(
void
);
const
char
*
StaticRAMSize
(
void
);
const
char
*
MapType
(
void
);
const
char
*
MapMode
(
void
);
const
char
*
KartContents
(
void
);
const
char
*
Size
(
void
);
const
char
*
Headers
(
void
);
const
char
*
ROMID
(
void
);
const
char
*
CompanyID
(
void
);
uint32
caCRC32
(
uint8
*
array
,
uint32
size
);
enum
...
...
@@ -157,14 +157,13 @@ typedef struct
uint8
*
SDD1Index
;
uint8
*
SDD1Data
;
uint32
SDD1Entries
;
char
ROMFilename
[
_MAX_PATH
];
}
CMemory
;
extern
CMemory
Memory
;
extern
uint8
*
SRAM
;
extern
uint8
*
ROM
;
extern
uint8
*
RegRAM
;
void
S9xDeinterleaveMode2
();
void
S9xDeinterleaveMode2
(
void
);
#ifdef NO_INLINE_SET_GET
uint8
S9xGetByte
(
uint32
Address
,
struct
SCPUState
*
);
...
...
src/port.h
View file @
69234219
...
...
@@ -126,13 +126,6 @@ typedef short int16_32;
void
S9xGenerateSound
(
void
);
#ifndef _MSC_VER
void
_makepath
(
char
*
path
,
const
char
*
drive
,
const
char
*
dir
,
const
char
*
fname
,
const
char
*
ext
);
void
_splitpath
(
const
char
*
path
,
char
*
drive
,
char
*
dir
,
char
*
fname
,
char
*
ext
);
#endif
#define strcasecmp strcmp
#define strncasecmp strncmp
...
...
src/snapshot.c
View file @
69234219
...
...
@@ -408,11 +408,8 @@ static FreezeData SnapSA1 [] =
};
#endif
//static char ROMFilename [_MAX_PATH];
//static char SnapshotFilename [_MAX_PATH];
static
void
Freeze
();
static
int
Unfreeze
();
static
void
Freeze
(
void
);
static
int
Unfreeze
(
void
);
void
FreezeStruct
(
char
*
name
,
void
*
base
,
FreezeData
*
fields
,
int
num_fields
);
void
FreezeBlock
(
char
*
name
,
uint8
*
block
,
int
size
);
...
...
@@ -488,8 +485,7 @@ static void Freeze()
}
sprintf
(
buffer
,
"%s:%04d
\n
"
,
SNAPSHOT_MAGIC
,
SNAPSHOT_VERSION
);
statef_write
(
buffer
,
strlen
(
buffer
));
sprintf
(
buffer
,
"NAM:%06d:%s%c"
,
strlen
(
Memory
.
ROMFilename
)
+
1
,
Memory
.
ROMFilename
,
0
);
strcpy
(
buffer
,
"NAM:1:0"
);
statef_write
(
buffer
,
strlen
(
buffer
)
+
1
);
FreezeStruct
(
"CPU"
,
&
CPU
,
SnapCPU
,
COUNT
(
SnapCPU
));
FreezeStruct
(
"REG"
,
&
Registers
,
SnapRegisters
,
COUNT
(
SnapRegisters
));
...
...
@@ -555,13 +551,6 @@ static int Unfreeze(void)
if
((
result
=
UnfreezeBlock
(
"NAM"
,
(
uint8
*
)
rom_filename
,
512
))
!=
SUCCESS
)
return
(
result
);
if
(
strcasecmp
(
rom_filename
,
Memory
.
ROMFilename
)
!=
0
&&
strcasecmp
(
S9xBasename
(
rom_filename
),
S9xBasename
(
Memory
.
ROMFilename
))
!=
0
)
{
S9xMessage
(
S9X_WARNING
,
S9X_FREEZE_ROM_NAME
,
"Current loaded ROM image doesn't match that required by freeze-game file."
);
}
old_flags
=
CPU
.
Flags
;
#ifdef USE_SA1
sa1_old_flags
=
SA1
.
Flags
;
...
...
src/snes9x.h
View file @
69234219
...
...
@@ -53,7 +53,7 @@
#define STREAM memstream_t *
#define READ_STREAM(p, l, s) memstream_read(s, p, l)
#define WRITE_STREAM(p, l, s) memstream_write(s, p, l)
#define OPEN_STREAM(
f, m)
memstream_open(0)
#define OPEN_STREAM(
m)
memstream_open(0)
#define CLOSE_STREAM(s) memstream_close(s)
#define SEEK_STREAM(p,r,s) memstream_seek(p,r,s)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment