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
RACE
Commits
d0bb666b
Commit
d0bb666b
authored
Oct 04, 2020
by
Libretro-Admin
Browse files
Cleanups
parent
f40cb9c4
Changes
1
Hide whitespace changes
Inline
Side-by-side
flash.cpp
View file @
d0bb666b
...
@@ -23,17 +23,6 @@
...
@@ -23,17 +23,6 @@
#include "types.h"
#include "types.h"
#include "flash.h"
#include "flash.h"
#if 0
#define DEBUG_FLASH
#endif
#ifdef DEBUG_FLASH
FILE
*
debugFile
=
NULL
;
#define stderr debugFile
#define stdout debugFile
#endif
/* Manuf ID's
/* Manuf ID's
Supported
Supported
0x98 Toshiba
0x98 Toshiba
...
@@ -153,10 +142,6 @@ unsigned char blockNumFromAddr(unsigned int addr)
...
@@ -153,10 +142,6 @@ unsigned char blockNumFromAddr(unsigned int addr)
return
(
bootBlockStartAddr
/
0x10000
)
+
3
;
return
(
bootBlockStartAddr
/
0x10000
)
+
3
;
}
}
#ifdef DEBUG_FLASH
fprintf
(
debugFile
,
"blockNumFromAddr: addr=0x%08X returning=%d
\n
"
,
addr
,
addr
/
0x10000
);
#endif
return
addr
/
0x10000
;
return
addr
/
0x10000
;
}
}
...
@@ -182,10 +167,6 @@ unsigned int blockNumToAddr(unsigned char chip, unsigned char blockNum)
...
@@ -182,10 +167,6 @@ unsigned int blockNumToAddr(unsigned char chip, unsigned char blockNum)
if
(
chip
)
if
(
chip
)
addr
+=
0x200000
;
addr
+=
0x200000
;
#ifdef DEBUG_FLASH
fprintf
(
debugFile
,
"blockNumToAddr: chip=%d blockNum=%d addr=0x%08X
\n
"
,
chip
,
blockNum
,
addr
);
#endif
return
addr
;
return
addr
;
}
}
...
@@ -207,49 +188,41 @@ unsigned int blockSize(unsigned char blockNum)
...
@@ -207,49 +188,41 @@ unsigned int blockSize(unsigned char blockNum)
return
0x10000
;
return
0x10000
;
}
}
void
setupNGFfilename
()
void
setupNGFfilename
(
void
)
{
{
int
dotSpot
=
-
1
,
pos
=
0
;
int
dotSpot
=
-
1
,
pos
=
0
;
int
slashSpot
=
-
1
;
int
slashSpot
=
-
1
;
if
(
strlen
(
ngfFilename
)
!=
0
)
{
#ifdef DEBUG_FLASH
fprintf
(
debugFile
,
"setupNGFfilename: %s file already opened
\n
"
,
ngfFilename
);
return
;
/* already set up */
#endif
}
strcpy
(
ngfFilename
,
SAVEGAME_DIR
);
strcpy
(
ngfFilename
,
SAVEGAME_DIR
);
pos
=
strlen
(
m_emuInfo
.
RomFileName
);
pos
=
strlen
(
m_emuInfo
.
RomFileName
);
while
(
pos
>=
0
)
while
(
pos
>=
0
)
{
{
if
(
m_emuInfo
.
RomFileName
[
pos
]
==
path_default_slash_c
())
if
(
m_emuInfo
.
RomFileName
[
pos
]
==
path_default_slash_c
())
{
{
slashSpot
=
pos
;
slashSpot
=
pos
;
break
;
break
;
}
}
pos
--
;
pos
--
;
}
}
strcat
(
ngfFilename
,
&
m_emuInfo
.
RomFileName
[
slashSpot
+
1
]);
strcat
(
ngfFilename
,
&
m_emuInfo
.
RomFileName
[
slashSpot
+
1
]);
for
(
pos
=
strlen
(
ngfFilename
);
pos
>=
0
&&
dotSpot
==
-
1
;
pos
--
)
for
(
pos
=
strlen
(
ngfFilename
);
pos
>=
0
&&
dotSpot
==
-
1
;
pos
--
)
{
{
if
(
ngfFilename
[
pos
]
==
'.'
)
if
(
ngfFilename
[
pos
]
==
'.'
)
dotSpot
=
pos
;
dotSpot
=
pos
;
}
}
if
(
dotSpot
==
-
1
)
if
(
dotSpot
==
-
1
)
{
{
fprintf
(
stderr
,
"setupNGFfilename: Couldn't find the . in %s file
\n
"
,
ngfFilename
);
fprintf
(
stderr
,
"setupNGFfilename: Couldn't find the . in %s file
\n
"
,
ngfFilename
);
return
;
return
;
}
}
strcpy
(
&
ngfFilename
[
dotSpot
+
1
],
"ngf"
);
strcpy
(
&
ngfFilename
[
dotSpot
+
1
],
"ngf"
);
fprintf
(
stdout
,
"setupNGFfilename: using %s for save-game info
\n
"
,
ngfFilename
);
fprintf
(
stdout
,
"setupNGFfilename: using %s for save-game info
\n
"
,
ngfFilename
);
}
}
/* write all the dirty blocks out to a file */
/* write all the dirty blocks out to a file */
...
@@ -264,12 +237,7 @@ void writeSaveGameFile(void)
...
@@ -264,12 +237,7 @@ void writeSaveGameFile(void)
NGFheaderStruct
NGFheader
;
NGFheaderStruct
NGFheader
;
blockStruct
block
;
blockStruct
block
;
#ifdef DEBUG_FLASH
setupNGFfilename
();
fprintf
(
debugFile
,
"writeSaveGameFile: entry totalBlocks=%d
\n
"
,
totalBlocks
);
#endif
setupNGFfilename
();
ngfFile
=
fopen
(
ngfFilename
,
"wb"
);
ngfFile
=
fopen
(
ngfFilename
,
"wb"
);
if
(
!
ngfFile
)
if
(
!
ngfFile
)
...
@@ -287,9 +255,6 @@ void writeSaveGameFile(void)
...
@@ -287,9 +255,6 @@ void writeSaveGameFile(void)
{
{
if
(
blocksDirty
[
0
][
i
])
if
(
blocksDirty
[
0
][
i
])
{
{
#ifdef DEBUG_FLASH
fprintf
(
debugFile
,
"writeSaveGameFile: found 1st chip dirty block %d
\n
"
,
i
);
#endif
NGFheader
.
numBlocks
++
;
NGFheader
.
numBlocks
++
;
NGFheader
.
fileLen
+=
blockSize
(
i
);
NGFheader
.
fileLen
+=
blockSize
(
i
);
}
}
...
@@ -301,9 +266,6 @@ void writeSaveGameFile(void)
...
@@ -301,9 +266,6 @@ void writeSaveGameFile(void)
{
{
if
(
blocksDirty
[
1
][
i
])
if
(
blocksDirty
[
1
][
i
])
{
{
#ifdef DEBUG_FLASH
fprintf
(
debugFile
,
"writeSaveGameFile: found 2nd chip dirty block %d
\n
"
,
i
);
#endif
NGFheader
.
numBlocks
++
;
NGFheader
.
numBlocks
++
;
NGFheader
.
fileLen
+=
blockSize
(
i
);
NGFheader
.
fileLen
+=
blockSize
(
i
);
}
}
...
@@ -329,9 +291,6 @@ void writeSaveGameFile(void)
...
@@ -329,9 +291,6 @@ void writeSaveGameFile(void)
block
.
NGPCaddr
=
blockNumToAddr
(
0
,
i
)
+
0x200000
;
block
.
NGPCaddr
=
blockNumToAddr
(
0
,
i
)
+
0x200000
;
block
.
len
=
blockSize
(
i
);
block
.
len
=
blockSize
(
i
);
#ifdef DEBUG_FLASH
fprintf
(
debugFile
,
"writeSaveGameFile: writing 1st chip block=%d addr=0x%08X len=0x%X
\n
"
,
i
,
block
.
NGPCaddr
,
block
.
len
);
#endif
bytes
=
fwrite
(
&
block
,
1
,
sizeof
(
blockStruct
),
ngfFile
);
bytes
=
fwrite
(
&
block
,
1
,
sizeof
(
blockStruct
),
ngfFile
);
if
(
bytes
!=
sizeof
(
blockStruct
))
if
(
bytes
!=
sizeof
(
blockStruct
))
...
@@ -360,10 +319,6 @@ void writeSaveGameFile(void)
...
@@ -360,10 +319,6 @@ void writeSaveGameFile(void)
block
.
NGPCaddr
=
blockNumToAddr
(
1
,
i
)
+
0x600000
;
block
.
NGPCaddr
=
blockNumToAddr
(
1
,
i
)
+
0x600000
;
block
.
len
=
blockSize
(
i
);
block
.
len
=
blockSize
(
i
);
#ifdef DEBUG_FLASH
fprintf
(
debugFile
,
"writeSaveGameFile: writing 2nd chip block=%d addr=0x%08X len=0x%X
\n
"
,
i
,
block
.
NGPCaddr
,
block
.
len
);
#endif
bytes
=
fwrite
(
&
block
,
1
,
sizeof
(
blockStruct
),
ngfFile
);
bytes
=
fwrite
(
&
block
,
1
,
sizeof
(
blockStruct
),
ngfFile
);
if
(
bytes
!=
sizeof
(
blockStruct
))
if
(
bytes
!=
sizeof
(
blockStruct
))
{
{
...
@@ -394,10 +349,6 @@ void writeSaveGameFile(void)
...
@@ -394,10 +349,6 @@ void writeSaveGameFile(void)
system("sync");
system("sync");
#endif
#endif
#endif
#endif
#ifdef DEBUG_FLASH
fprintf
(
debugFile
,
"writeSaveGameFile: exit
\n
"
);
#endif
}
}
/* read the save-game file and overlay it onto mainrom */
/* read the save-game file and overlay it onto mainrom */
...
@@ -411,11 +362,7 @@ void loadSaveGameFile(void)
...
@@ -411,11 +362,7 @@ void loadSaveGameFile(void)
NGFheaderStruct
NGFheader
;
NGFheaderStruct
NGFheader
;
blockStruct
*
blockHeader
;
blockStruct
*
blockHeader
;
#ifdef DEBUG_FLASH
setupNGFfilename
();
fprintf
(
debugFile
,
"loadSaveGameFile: entry
\n
"
);
#endif
setupNGFfilename
();
ngfFile
=
fopen
(
ngfFilename
,
"rb"
);
ngfFile
=
fopen
(
ngfFilename
,
"rb"
);
if
(
!
ngfFile
)
if
(
!
ngfFile
)
...
@@ -507,9 +454,6 @@ void loadSaveGameFile(void)
...
@@ -507,9 +454,6 @@ void loadSaveGameFile(void)
free
(
blockMem
);
free
(
blockMem
);
#ifdef DEBUG_FLASH
fprintf
(
debugFile
,
"loadSaveGameFile: exit
\n
"
);
#endif
}
}
void
flashWriteByte
(
unsigned
int
addr
,
unsigned
char
data
,
unsigned
char
operation
)
void
flashWriteByte
(
unsigned
int
addr
,
unsigned
char
data
,
unsigned
char
operation
)
...
@@ -521,13 +465,6 @@ void flashWriteByte(unsigned int addr, unsigned char data, unsigned char operati
...
@@ -521,13 +465,6 @@ void flashWriteByte(unsigned int addr, unsigned char data, unsigned char operati
if
(
blockNumFromAddr
(
addr
)
==
0
)
/* hack because DWARP writes to bank 0 */
if
(
blockNumFromAddr
(
addr
)
==
0
)
/* hack because DWARP writes to bank 0 */
return
;
return
;
#ifdef DEBUG_FLASH
if
(
debugFile
!=
NULL
&&
operation
==
FLASH_WRITE
)
{
fprintf
(
debugFile
,
"fWB: addr=0x%08X data=0x%02X
\n
"
,
addr
,
data
);
}
#endif
/* set a dirty flag for the block that we are writing to */
/* set a dirty flag for the block that we are writing to */
if
(
addr
<
0x200000
)
if
(
addr
<
0x200000
)
{
{
...
@@ -573,12 +510,6 @@ unsigned char flashReadInfo(unsigned int addr)
...
@@ -573,12 +510,6 @@ unsigned char flashReadInfo(unsigned int addr)
void
flashChipWrite
(
unsigned
int
addr
,
unsigned
char
data
)
void
flashChipWrite
(
unsigned
int
addr
,
unsigned
char
data
)
{
{
#ifdef DEBUG_FLASH
if
(
debugFile
!=
NULL
)
{
fprintf
(
debugFile
,
"fCW: addr=0x%08X data=0x%02X cycle=%02d command=%02d
\n
"
,
addr
,
data
,
currentWriteCycle
,
currentCommand
);
}
#endif
if
(
addr
>=
0x800000
&&
cartSize
!=
32
)
if
(
addr
>=
0x800000
&&
cartSize
!=
32
)
return
;
return
;
...
@@ -711,20 +642,11 @@ void flashChipWrite(unsigned int addr, unsigned char data)
...
@@ -711,20 +642,11 @@ void flashChipWrite(unsigned int addr, unsigned char data)
void
flashShutdown
(
void
)
void
flashShutdown
(
void
)
{
{
writeSaveGameFile
();
writeSaveGameFile
();
#ifdef DEBUG_FLASH
fclose
(
debugFile
);
#endif
}
}
/* this should be called when a ROM is loaded */
/* this should be called when a ROM is loaded */
void
flashStartup
(
void
)
void
flashStartup
(
void
)
{
{
#ifdef DEBUG_FLASH
if
(
debugFile
==
NULL
)
{
debugFile
=
fopen
(
"flashDebug.txt"
,
"wt"
);
}
#endif
memset
(
blocksDirty
[
0
],
0
,
MAX_BLOCKS
*
sizeof
(
blocksDirty
[
0
][
0
]));
memset
(
blocksDirty
[
0
],
0
,
MAX_BLOCKS
*
sizeof
(
blocksDirty
[
0
][
0
]));
memset
(
blocksDirty
[
1
],
0
,
MAX_BLOCKS
*
sizeof
(
blocksDirty
[
0
][
0
]));
memset
(
blocksDirty
[
1
],
0
,
MAX_BLOCKS
*
sizeof
(
blocksDirty
[
0
][
0
]));
needToWriteFile
=
0
;
needToWriteFile
=
0
;
...
@@ -734,12 +656,6 @@ void flashStartup(void)
...
@@ -734,12 +656,6 @@ void flashStartup(void)
void
vectFlashWrite
(
unsigned
char
chip
,
unsigned
int
to
,
unsigned
char
*
fromAddr
,
unsigned
int
numBytes
)
void
vectFlashWrite
(
unsigned
char
chip
,
unsigned
int
to
,
unsigned
char
*
fromAddr
,
unsigned
int
numBytes
)
{
{
#ifdef DEBUG_FLASH
if
(
debugFile
!=
NULL
)
{
fprintf
(
debugFile
,
"vFW: chip=%d to=0x%08X *fromAddr=%02x num=%d
\n
"
,
chip
,
to
,
*
fromAddr
,
numBytes
);
}
#endif
if
(
chip
)
if
(
chip
)
to
+=
0x200000
;
to
+=
0x200000
;
...
@@ -768,13 +684,6 @@ void vectFlashErase(unsigned char chip, unsigned char blockNum)
...
@@ -768,13 +684,6 @@ void vectFlashErase(unsigned char chip, unsigned char blockNum)
unsigned
int
blockAddr
=
blockNumToAddr
(
chip
,
blockNum
);
unsigned
int
blockAddr
=
blockNumToAddr
(
chip
,
blockNum
);
unsigned
int
numBytes
=
blockSize
(
blockNum
);
unsigned
int
numBytes
=
blockSize
(
blockNum
);
#ifdef DEBUG_FLASH
if
(
debugFile
!=
NULL
)
{
fprintf
(
debugFile
,
"vectFlashErase: chip=%d blockNum=%d
\n
"
,
chip
,
blockNum
);
}
#endif
#if 0
#if 0
/* memset block to 0xFF */
/* memset block to 0xFF */
memset(&mainrom[blockAddr], 0xFF, numBytes);
memset(&mainrom[blockAddr], 0xFF, numBytes);
...
@@ -788,12 +697,6 @@ void vectFlashErase(unsigned char chip, unsigned char blockNum)
...
@@ -788,12 +697,6 @@ void vectFlashErase(unsigned char chip, unsigned char blockNum)
void
vectFlashChipErase
(
unsigned
char
chip
)
void
vectFlashChipErase
(
unsigned
char
chip
)
{
{
#ifdef DEBUG_FLASH
if
(
debugFile
!=
NULL
)
{
fprintf
(
debugFile
,
"vectFlashChipErase: chip=%d
\n
"
,
chip
);
}
#endif
}
}
void
setFlashSize
(
unsigned
int
romSize
)
void
setFlashSize
(
unsigned
int
romSize
)
...
...
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