Clean ipl device code a bit

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3103 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Shawn Hoffman 2009-04-29 15:17:36 +00:00
parent 2673eed2cc
commit 9984be6580
2 changed files with 67 additions and 55 deletions

View File

@ -23,7 +23,8 @@
#include "MemoryUtil.h" #include "MemoryUtil.h"
// english // english
SRAM sram_dump= {{0x04, 0x6B, 0xFB, 0x91, 0x00, 0x00, 0x00, 0x00, SRAM sram_dump = {{
0x04, 0x6B, 0xFB, 0x91, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x40, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x40,
0x05, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -49,9 +50,13 @@ SRAM sram_dump_german = {{
// We should provide an option to choose from the above, or figure out the checksum (the algo in yagcd seems wrong) // We should provide an option to choose from the above, or figure out the checksum (the algo in yagcd seems wrong)
// so that people can change default language. // so that people can change default language.
static const char iplver[0x100] = "(C) 1999-2001 Nintendo. All rights reserved." static const char iplverPAL[0x100] = "(C) 1999-2001 Nintendo. All rights reserved."
"(C) 1999 ArtX Inc. All rights reserved." "(C) 1999 ArtX Inc. All rights reserved."
"PAL Revision 1.0 "; "PAL Revision 1.0 ";
static const char iplverNTSC[0x100] = "(C) 1999-2001 Nintendo. All rights reserved."
"(C) 1999 ArtX Inc. All rights reserved.";
CEXIIPL::CEXIIPL() : CEXIIPL::CEXIIPL() :
m_uPosition(0), m_uPosition(0),
@ -59,61 +64,28 @@ CEXIIPL::CEXIIPL() :
m_uRWOffset(0), m_uRWOffset(0),
m_count(0) m_count(0)
{ {
// Load the IPL // Determine region
m_pIPL = (u8*)AllocateMemoryPages(ROM_SIZE); m_bNTSC = SConfig::GetInstance().m_LocalCoreStartupParameter.bNTSC;
FILE* pStream = NULL;
pStream = fopen(FONT_ANSI_FILE, "rb");
if (pStream != NULL)
{
fseek(pStream, 0, SEEK_END);
size_t filesize = (size_t)ftell(pStream);
rewind(pStream);
fread(m_pIPL + 0x001fcf00, 1, filesize, pStream); // Create the IPL
fclose(pStream); m_pIPL = (u8*)AllocateMemoryPages(ROM_SIZE);
}
else
{
/* This is a poor way to handle failure. We should either not display this message unless fonts
are actually accessed, or better yet, emulate them using a system font. -bushing */
// JP: But I want to see this error
#ifndef __APPLE__
PanicAlert("Error: failed to load '" FONT_ANSI_FILE "'. Fonts in a few games may not work, or"
" crash the game.");
#endif
}
pStream = fopen(FONT_SJIS_FILE, "rb"); // Copy header
if (pStream != NULL) memcpy(m_pIPL, m_bNTSC ? iplverNTSC : iplverPAL, sizeof(m_bNTSC ? iplverNTSC : iplverPAL));
{
fseek(pStream, 0, SEEK_END);
size_t filesize = (size_t)ftell(pStream);
rewind(pStream);
fread(m_pIPL + 0x001aff00, 1, filesize, pStream); // Load fonts
fclose(pStream); LoadFileToIPL(FONT_SJIS_FILE, 0x001aff00);
} LoadFileToIPL(FONT_ANSI_FILE, 0x001fcf00);
else
{
// Heh, BIOS fonts don't really work in JAP games anyway ... we get bogus characters.
// JP: But I want to see this error
#ifndef __APPLE__
PanicAlert("Error: failed to load '" FONT_SJIS_FILE "'. Fonts in a few Japanese games may"
" not work or crash the game.");
#endif
}
memcpy(m_pIPL, iplver, sizeof(iplver));
// Clear RTC // Clear RTC
memset(m_RTC, 0, sizeof(m_RTC)); memset(m_RTC, 0, sizeof(m_RTC));
// SRAM // SRAM
pStream = fopen(SConfig::GetInstance().m_LocalCoreStartupParameter.m_strSRAM.c_str(), "rb"); FILE *file = fopen(SConfig::GetInstance().m_LocalCoreStartupParameter.m_strSRAM.c_str(), "rb");
if (pStream != NULL) if (file != NULL)
{ {
fread(&m_SRAM, 1, 64, pStream); fread(&m_SRAM, 1, 64, file);
fclose(pStream); fclose(file);
} }
else else
{ {
@ -148,6 +120,28 @@ CEXIIPL::~CEXIIPL()
} }
} }
void CEXIIPL::LoadFileToIPL(const char* filename, u32 offset)
{
FILE* pStream = NULL;
pStream = fopen(filename, "rb");
if (pStream != NULL)
{
fseek(pStream, 0, SEEK_END);
size_t filesize = (size_t)ftell(pStream);
rewind(pStream);
fread(m_pIPL + offset, 1, filesize, pStream);
fclose(pStream);
}
else
{
// This is a poor way to handle failure. We should either not display this message unless fonts
// are actually accessed, or better yet, emulate them using a system font. -bushing
PanicAlert("Error: failed to load %s. Fonts in a few games may not work, or crash the game.",
filename);
}
}
void CEXIIPL::SetCS(int _iCS) void CEXIIPL::SetCS(int _iCS)
{ {
if (_iCS) if (_iCS)
@ -195,7 +189,6 @@ void CEXIIPL::TransferByte(u8& _uByte)
// wii stuff perhaps wii SRAM? // wii stuff perhaps wii SRAM?
INFO_LOG(EXPANSIONINTERFACE, "EXI IPL-DEV: WII something (perhaps SRAM?)"); INFO_LOG(EXPANSIONINTERFACE, "EXI IPL-DEV: WII something (perhaps SRAM?)");
} }
// debug only
else if ((m_uAddress & 0x60000000) == 0) else if ((m_uAddress & 0x60000000) == 0)
{ {
INFO_LOG(EXPANSIONINTERFACE, "EXI IPL-DEV: IPL access"); INFO_LOG(EXPANSIONINTERFACE, "EXI IPL-DEV: IPL access");
@ -236,6 +229,20 @@ void CEXIIPL::TransferByte(u8& _uByte)
{ {
if ((m_uAddress & 0x80000000) == 0) if ((m_uAddress & 0x80000000) == 0)
_uByte = m_pIPL[((m_uAddress >> 6) & ROM_MASK) + m_uRWOffset]; _uByte = m_pIPL[((m_uAddress >> 6) & ROM_MASK) + m_uRWOffset];
#if 0
u32 position = ((m_uAddress >> 6) & ROM_MASK) + m_uRWOffset;
char msg[5] = "";
if (position >= 0 && position < 0x100)
sprintf(msg, "COPY");
else if (position >= 0x00000100 && position <= 0x001aeee8)
sprintf(msg, "BIOS");
else if (position >= 0x001AFF00 && position <= 0x001FA0E0)
sprintf(msg, "SJIS");
else if (position >= 0x001FCF00 && position <= 0x001FF474)
sprintf(msg, "ANSI");
WARN_LOG(EXPANSIONINTERFACE, "m_pIPL[0x%08x] = 0x%02x %s\t0x%08x 0x%08x 0x%08x",
position, _uByte, msg, m_uPosition,m_uAddress,m_uRWOffset);
#endif
} }
// //
// --- Real Time Clock (RTC) --- // --- Real Time Clock (RTC) ---
@ -281,10 +288,10 @@ void CEXIIPL::TransferByte(u8& _uByte)
((m_uAddress & 0x7FFFFF00) == 0x21000800)) ((m_uAddress & 0x7FFFFF00) == 0x21000800))
{ {
// WII only RTC flags... afaik just the wii menu initialize it // WII only RTC flags... afaik just the wii menu initialize it
// if (m_uAddress & 0x80000000) // if (m_uAddress & 0x80000000)
// m_SRAM.p_SRAM[(m_uAddress & 0x3F) + m_uRWOffset] = _uByte; // m_SRAM.p_SRAM[(m_uAddress & 0x3F) + m_uRWOffset] = _uByte;
// else // else
// _uByte = m_SRAM.p_SRAM[(m_uAddress & 0x3F) + m_uRWOffset]; // _uByte = m_SRAM.p_SRAM[(m_uAddress & 0x3F) + m_uRWOffset];
} }
m_uRWOffset++; m_uRWOffset++;
} }

View File

@ -38,6 +38,9 @@ private:
ROM_MASK = (ROM_SIZE - 1) ROM_MASK = (ROM_SIZE - 1)
}; };
// Region
bool m_bNTSC;
//! IPL //! IPL
u8* m_pIPL; u8* m_pIPL;
@ -57,6 +60,8 @@ private:
int m_count; int m_count;
virtual void TransferByte(u8 &_uByte); virtual void TransferByte(u8 &_uByte);
void LoadFileToIPL(const char* filename, u32 offset);
}; };
#endif #endif