added VolumeDirectory and modified ELF boot code to allow a directory on the user's computer to appear as the DVD drive. Linux support needs to be added. Added functionality to the Wii DI. Clicking on a data symbol in the code window sets the memory list to that address.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@624 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
ef1aba784e
commit
29664c880a
|
@ -393,6 +393,33 @@ bool CBoot::EmulatedBIOS_Wii(bool _bDebug)
|
|||
return true;
|
||||
}
|
||||
|
||||
void CBoot::Load_FST(bool _bIsWii)
|
||||
{
|
||||
if(VolumeHandler::IsValid())
|
||||
{
|
||||
// copy first 20 bytes of disc to start of Mem 1
|
||||
VolumeHandler::ReadToPtr(Memory::GetPointer(0x80000000), 0, 0x20);
|
||||
|
||||
// copy of game id
|
||||
Memory::Write_U32(Memory::Read_U32(0x80000000), 0x80003180);
|
||||
|
||||
u32 shift = 0;
|
||||
if(_bIsWii)
|
||||
shift = 2;
|
||||
|
||||
u32 fstOffset = VolumeHandler::Read32(0x0424) << shift;
|
||||
u32 fstSize = VolumeHandler::Read32(0x0428) << shift;
|
||||
u32 maxFstSize = VolumeHandler::Read32(0x042c) << shift;
|
||||
|
||||
u32 arenaHigh = 0x817FFFF4 - maxFstSize;
|
||||
Memory::Write_U32(arenaHigh, 0x00000034);
|
||||
|
||||
// load FST
|
||||
VolumeHandler::ReadToPtr(Memory::GetPointer(arenaHigh), fstOffset, fstSize);
|
||||
Memory::Write_U32(arenaHigh, 0x00000038);
|
||||
Memory::Write_U32(maxFstSize, 0x0000003c);
|
||||
}
|
||||
}
|
||||
|
||||
void CBoot::UpdateDebugger_MapLoaded(const char *_gameID)
|
||||
{
|
||||
|
@ -546,12 +573,11 @@ bool CBoot::BootUp(const SCoreStartupParameter& _StartupPara)
|
|||
PanicAlert("Warning - starting ELF in wrong console mode!");
|
||||
}
|
||||
|
||||
VolumeHandler::SetVolumeName(_StartupPara.m_strDefaultGCM);
|
||||
// stop apploader from running when BIOS boots
|
||||
VolumeHandler::SetVolumeName("");
|
||||
|
||||
if (elfWii)
|
||||
{
|
||||
if (VolumeHandler::IsWii() && (!_StartupPara.m_strDefaultGCM.empty()))
|
||||
VolumeHandler::SetVolumeName(_StartupPara.m_strDefaultGCM.c_str());
|
||||
|
||||
EmulatedBIOS_Wii(false);
|
||||
}
|
||||
else
|
||||
|
@ -563,6 +589,24 @@ bool CBoot::BootUp(const SCoreStartupParameter& _StartupPara)
|
|||
}
|
||||
}
|
||||
|
||||
// load image or create virtual drive from directory
|
||||
if(!_StartupPara.m_strDVDRoot.empty())
|
||||
{
|
||||
VolumeHandler::SetVolumeDirectory(_StartupPara.m_strDVDRoot, elfWii);
|
||||
}
|
||||
else if(!_StartupPara.m_strDefaultGCM.empty())
|
||||
{
|
||||
VolumeHandler::SetVolumeName(_StartupPara.m_strDefaultGCM);
|
||||
}
|
||||
else
|
||||
{
|
||||
VolumeHandler::SetVolumeDirectory(_StartupPara.m_strFilename, elfWii);
|
||||
}
|
||||
|
||||
DVDInterface::SetDiscInside(VolumeHandler::IsValid());
|
||||
|
||||
Load_FST(elfWii);
|
||||
|
||||
Boot_ELF(_StartupPara.m_strFilename.c_str());
|
||||
UpdateDebugger_MapLoaded();
|
||||
CBreakPoints::AddAutoBreakpoints();
|
||||
|
|
|
@ -57,6 +57,8 @@ private:
|
|||
static void EmulatedBIOS(bool _bDebug);
|
||||
static bool EmulatedBIOS_Wii(bool _bDebug);
|
||||
static bool Load_BIOS(const std::string& _rBiosFilename);
|
||||
|
||||
static void Load_FST(bool _bIsWii);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -80,6 +80,7 @@ struct SCoreStartupParameter
|
|||
std::string m_strMemoryCardB;
|
||||
std::string m_strSRAM;
|
||||
std::string m_strDefaultGCM;
|
||||
std::string m_strDVDRoot;
|
||||
std::string m_strUniqueID;
|
||||
|
||||
//
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "VolumeCreator.h"
|
||||
#include "Filesystem.h"
|
||||
|
||||
|
||||
// __________________________________________________________________________________________________
|
||||
//
|
||||
CWII_IPC_HLE_Device_di::CWII_IPC_HLE_Device_di(u32 _DeviceID, const std::string& _rDeviceName )
|
||||
|
@ -36,7 +37,7 @@ CWII_IPC_HLE_Device_di::CWII_IPC_HLE_Device_di(u32 _DeviceID, const std::string&
|
|||
, m_pFileSystem(NULL)
|
||||
{
|
||||
|
||||
m_pVolume = DiscIO::CreateVolumeFromFilename(Core::GetStartupParameter().m_strFilename);
|
||||
m_pVolume = VolumeHandler::GetVolume();
|
||||
if (m_pVolume)
|
||||
m_pFileSystem = DiscIO::CreateFileSystem(m_pVolume);
|
||||
}
|
||||
|
@ -103,6 +104,9 @@ bool CWII_IPC_HLE_Device_di::IOCtlV(u32 _CommandAddress)
|
|||
return true;
|
||||
}
|
||||
|
||||
// Hack
|
||||
u8 coverByte = 0;
|
||||
|
||||
// __________________________________________________________________________________________________
|
||||
//
|
||||
u32 CWII_IPC_HLE_Device_di::ExecuteCommand(u32 _BufferIn, u32 _BufferInSize, u32 _BufferOut, u32 _BufferOutSize)
|
||||
|
@ -114,13 +118,46 @@ u32 CWII_IPC_HLE_Device_di::ExecuteCommand(u32 _BufferIn, u32 _BufferInSize, u32
|
|||
case 0x12:
|
||||
{
|
||||
Memory::Memset(_BufferOut, 0, _BufferOutSize);
|
||||
|
||||
u8* buffer = Memory::GetPointer(_BufferOut);
|
||||
|
||||
// rev
|
||||
buffer[0] = 0x01;
|
||||
buffer[1] = 0x02;
|
||||
|
||||
// dev code
|
||||
buffer[2] = 0x03;
|
||||
buffer[3] = 0x04;
|
||||
|
||||
// firmware date
|
||||
buffer[4] = 0x20;
|
||||
buffer[5] = 0x08;
|
||||
buffer[6] = 0x08;
|
||||
buffer[7] = 0x29;
|
||||
|
||||
LOG(WII_IPC_HLE, "%s executes DVDLowInquiry (Buffer 0x%08x, 0x%x)", GetDeviceName().c_str(), _BufferOut, _BufferOutSize);
|
||||
|
||||
return 0x1;
|
||||
}
|
||||
break;
|
||||
|
||||
// DVDLowReadDiskID
|
||||
case 0x70:
|
||||
{
|
||||
// TODO - verify that this is correct
|
||||
VolumeHandler::ReadToPtr(Memory::GetPointer(_BufferOut), 0, _BufferOutSize);
|
||||
|
||||
LOG(WII_IPC_HLE, "%s executes DVDLowReadDiskID (Buffer 0x%08x, 0x%x)", GetDeviceName().c_str(), _BufferOut, _BufferOutSize);
|
||||
|
||||
return 0x1;
|
||||
}
|
||||
break;
|
||||
|
||||
// DVDLowRead
|
||||
// TODO - find out if 80, 8d, or and d0 need to do something specific
|
||||
case 0x80:
|
||||
case 0x8d:
|
||||
case 0xd0:
|
||||
case 0x71:
|
||||
{
|
||||
u32 Size = Memory::Read_U32(_BufferIn+0x04);
|
||||
|
@ -151,10 +188,30 @@ u32 CWII_IPC_HLE_Device_di::ExecuteCommand(u32 _BufferIn, u32 _BufferInSize, u32
|
|||
}
|
||||
break;
|
||||
|
||||
// DVDLowWaitForCoverClose
|
||||
case 0x79:
|
||||
{
|
||||
Memory::Memset(_BufferOut, 0, _BufferOutSize);
|
||||
LOG(WII_IPC_HLE, "%s executes DVDLowWaitForCoverClose (Buffer 0x%08x, 0x%x)", GetDeviceName().c_str(), _BufferOut, _BufferOutSize);
|
||||
return 4;
|
||||
}
|
||||
break;
|
||||
|
||||
// DVDLowGetCoverReg - called by "Legend of Spyro"
|
||||
case 0x7a:
|
||||
{
|
||||
// HACK - swiching the 4th byte between 0 and 1 gets through this check
|
||||
Memory::Memset(_BufferOut, 0, _BufferOutSize);
|
||||
|
||||
u8* buffer = Memory::GetPointer(_BufferOut);
|
||||
buffer[3] = coverByte;
|
||||
|
||||
if(coverByte)
|
||||
coverByte = 0;
|
||||
else
|
||||
coverByte = 0x01;
|
||||
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -166,6 +223,25 @@ u32 CWII_IPC_HLE_Device_di::ExecuteCommand(u32 _BufferIn, u32 _BufferInSize, u32
|
|||
}
|
||||
break;
|
||||
|
||||
// DVDLowGetCoverStatus
|
||||
case 0x88:
|
||||
{
|
||||
Memory::Memset(_BufferOut, 0, _BufferOutSize);
|
||||
LOG(WII_IPC_HLE, "%s executes DVDLowGetCoverStatus (Buffer 0x%08x, 0x%x)", GetDeviceName().c_str(), _BufferOut, _BufferOutSize);
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
|
||||
// DVDLowReset
|
||||
case 0x8a:
|
||||
{
|
||||
Memory::Memset(_BufferOut, 0, _BufferOutSize);
|
||||
LOG(WII_IPC_HLE, "%s executes DVDLowReset (Buffer 0x%08x, 0x%x)", GetDeviceName().c_str(), _BufferOut, _BufferOutSize);
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
// DVDLowSeek
|
||||
case 0xab:
|
||||
{}
|
||||
|
@ -175,8 +251,15 @@ u32 CWII_IPC_HLE_Device_di::ExecuteCommand(u32 _BufferIn, u32 _BufferInSize, u32
|
|||
case 0xe3:
|
||||
{
|
||||
Memory::Memset(_BufferOut, 0, _BufferOutSize);
|
||||
u32 eject = Memory::Read_U32(_BufferIn + 0x04);
|
||||
|
||||
LOG(WII_IPC_HLE, "%s executes DVDLowStopMotor (Buffer 0x%08x, 0x%x)", GetDeviceName().c_str(), _BufferOut, _BufferOutSize);
|
||||
PanicAlert("Weird. Nobody should call DVDLowStopMotor.");
|
||||
|
||||
if(eject)
|
||||
{
|
||||
LOG(WII_IPC_HLE, "Eject disc", GetDeviceName().c_str(), _BufferOut, _BufferOutSize);
|
||||
// TODO: eject the disc
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -103,6 +103,7 @@ void SymbolDB::AddKnownSymbol(u32 startAddr, u32 size, const char *name, int typ
|
|||
Symbol tf;
|
||||
tf.name = name;
|
||||
tf.type = type;
|
||||
tf.address = startAddr;
|
||||
if (tf.type == Symbol::SYMBOL_FUNCTION) {
|
||||
PPCAnalyst::AnalyzeFunction(startAddr, tf, size);
|
||||
checksumToFunction[tf.hash] = &(functions[startAddr]);
|
||||
|
|
|
@ -38,6 +38,16 @@ void SetVolumeName(const std::string& _rFullPath)
|
|||
g_pVolume = DiscIO::CreateVolumeFromFilename(_rFullPath);
|
||||
}
|
||||
|
||||
void SetVolumeDirectory(const std::string& _rFullPath, bool _bIsWii)
|
||||
{
|
||||
if (g_pVolume)
|
||||
{
|
||||
delete g_pVolume;
|
||||
g_pVolume = NULL;
|
||||
}
|
||||
|
||||
g_pVolume = DiscIO::CreateVolumeFromDirectory(_rFullPath, _bIsWii);
|
||||
}
|
||||
|
||||
u32 Read32(u64 _Offset)
|
||||
{
|
||||
|
@ -52,7 +62,7 @@ u32 Read32(u64 _Offset)
|
|||
|
||||
bool ReadToPtr(u8* ptr, u64 _dwOffset, u64 _dwLength)
|
||||
{
|
||||
if (g_pVolume != NULL)
|
||||
if (g_pVolume != NULL && ptr)
|
||||
{
|
||||
g_pVolume->Read(_dwOffset, _dwLength, ptr);
|
||||
return true;
|
||||
|
|
|
@ -28,6 +28,8 @@ namespace VolumeHandler
|
|||
|
||||
void SetVolumeName(const std::string& _rFullPath);
|
||||
|
||||
void SetVolumeDirectory(const std::string& _rFullPath, bool _bIsWii);
|
||||
|
||||
u32 Read32(u64 _Offset);
|
||||
|
||||
bool ReadToPtr(u8* ptr, u64 _dwOffset, u64 _dwLength);
|
||||
|
|
|
@ -644,11 +644,19 @@ void CCodeWindow::OnSymbolListChange(wxCommandEvent& event)
|
|||
if (index >= 0) {
|
||||
Symbol* pSymbol = static_cast<Symbol *>(symbols->GetClientData(index));
|
||||
if (pSymbol != NULL)
|
||||
{
|
||||
if(pSymbol->type == Symbol::SYMBOL_DATA)
|
||||
{
|
||||
if(m_MemoryWindow && m_MemoryWindow->IsVisible())
|
||||
m_MemoryWindow->JumpToAddress(pSymbol->address);
|
||||
}
|
||||
else
|
||||
{
|
||||
JumpToAddress(pSymbol->address);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CCodeWindow::OnSymbolListContextMenu(wxContextMenuEvent& event)
|
||||
{
|
||||
|
|
|
@ -597,6 +597,14 @@
|
|||
RelativePath=".\Src\VolumeCreator.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Src\VolumeDirectory.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Src\VolumeDirectory.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Src\VolumeGC.cpp"
|
||||
>
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "VolumeCreator.h"
|
||||
|
||||
#include "Volume.h"
|
||||
#include "VolumeDirectory.h"
|
||||
#include "VolumeGC.h"
|
||||
#include "VolumeWiiCrypted.h"
|
||||
|
||||
|
@ -103,6 +104,14 @@ IVolume* CreateVolumeFromFilename(const std::string& _rFilename)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
IVolume* CreateVolumeFromDirectory(const std::string& _rDirectory, bool _bIsWii)
|
||||
{
|
||||
if(CVolumeDirectory::IsValidDirectory(_rDirectory))
|
||||
return new CVolumeDirectory(_rDirectory, _bIsWii);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool IsVolumeWiiDisc(const IVolume *_rVolume)
|
||||
{
|
||||
u32 MagicWord = 0;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
namespace DiscIO
|
||||
{
|
||||
IVolume* CreateVolumeFromFilename(const std::string& _rFilename);
|
||||
IVolume* CreateVolumeFromDirectory(const std::string& _rDirectory, bool _bIsWii);
|
||||
bool IsVolumeWiiDisc(const IVolume *_rVolume);
|
||||
} // namespace
|
||||
|
||||
|
|
|
@ -0,0 +1,504 @@
|
|||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
|
||||
// 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, version 2.0.
|
||||
|
||||
// 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 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
#include "stdafx.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#include <io.h>
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "VolumeDirectory.h"
|
||||
#include "FileBlob.h"
|
||||
|
||||
const u8 ENTRY_SIZE = 0x0c;
|
||||
const u8 FILE_ENTRY = 0;
|
||||
const u8 DIRECTORY_ENTRY = 1;
|
||||
const u64 FST_ADDRESS = 0x440;
|
||||
const u32 MAX_NAME_LENGTH = 0x3df;
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
|
||||
|
||||
CVolumeDirectory::CVolumeDirectory(const std::string& _rDirectory, bool _bIsWii) :
|
||||
m_totalNameSize(0),
|
||||
m_FSTData(NULL), m_dataStartAddress(-1), m_fstSize(0)
|
||||
{
|
||||
m_rootDirectory = ExtractDirectoryName(_rDirectory);
|
||||
|
||||
// create the default disk header
|
||||
m_diskHeader = new u8[FST_ADDRESS];
|
||||
memset(m_diskHeader, 0, (size_t)FST_ADDRESS);
|
||||
SetUniqueID("RZDE01");
|
||||
SetName("Default name");
|
||||
|
||||
if(_bIsWii)
|
||||
{
|
||||
SetDiskTypeWii();
|
||||
}
|
||||
else
|
||||
{
|
||||
SetDiskTypeGC();
|
||||
}
|
||||
|
||||
BuildFST();
|
||||
}
|
||||
|
||||
CVolumeDirectory::~CVolumeDirectory()
|
||||
{
|
||||
delete m_FSTData;
|
||||
m_FSTData = NULL;
|
||||
|
||||
delete m_diskHeader;
|
||||
m_diskHeader = NULL;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
bool CVolumeDirectory::IsValidDirectory(const std::string& _rDirectory)
|
||||
{
|
||||
std::string directoryName = ExtractDirectoryName(_rDirectory);
|
||||
|
||||
WIN32_FIND_DATA ffd;
|
||||
HANDLE hFind = FindFirstFile(directoryName.c_str(), &ffd);
|
||||
|
||||
if (hFind == INVALID_HANDLE_VALUE)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
bool CVolumeDirectory::IsValidDirectory(const std::string& _rDirectory)
|
||||
{
|
||||
// TODO - Insert linux stuff here
|
||||
}
|
||||
#endif
|
||||
|
||||
bool CVolumeDirectory::Read(u64 _Offset, u64 _Length, u8* _pBuffer) const
|
||||
{
|
||||
if(_Offset < FST_ADDRESS)
|
||||
{
|
||||
WriteToBuffer(0, FST_ADDRESS, m_diskHeader, _Offset, _Length, _pBuffer);
|
||||
}
|
||||
|
||||
if(_Offset < m_dataStartAddress)
|
||||
{
|
||||
WriteToBuffer(FST_ADDRESS, m_fstSize, m_FSTData, _Offset, _Length, _pBuffer);
|
||||
}
|
||||
|
||||
if(m_virtualDisk.size() == 0)
|
||||
return true;
|
||||
|
||||
// Determine which file the offset refers to
|
||||
std::map<u64, std::string>::const_iterator fileIter = m_virtualDisk.lower_bound(_Offset);
|
||||
if(fileIter->first > _Offset && fileIter != m_virtualDisk.begin())
|
||||
--fileIter;
|
||||
|
||||
// zero fill to start of file data
|
||||
PadToAddress(fileIter->first, _Offset, _Length, _pBuffer);
|
||||
|
||||
while(fileIter != m_virtualDisk.end() && _Length > 0)
|
||||
{
|
||||
_dbg_assert_(DVDINTERFACE, fileIter->first <= _Offset);
|
||||
u64 fileOffset = _Offset - fileIter->first;
|
||||
|
||||
PlainFileReader* reader = PlainFileReader::Create(fileIter->second.c_str());
|
||||
if(reader == NULL)
|
||||
return false;
|
||||
|
||||
u64 fileSize = reader->GetDataSize();
|
||||
|
||||
if(fileOffset < fileSize)
|
||||
{
|
||||
u64 fileBytes = fileSize - fileOffset;
|
||||
if(_Length < fileBytes)
|
||||
fileBytes = _Length;
|
||||
|
||||
if(!reader->Read(fileOffset, fileBytes, _pBuffer))
|
||||
return false;
|
||||
|
||||
_Length -= fileBytes;
|
||||
_pBuffer += fileBytes;
|
||||
_Offset += fileBytes;
|
||||
}
|
||||
|
||||
++fileIter;
|
||||
|
||||
if(fileIter != m_virtualDisk.end())
|
||||
{
|
||||
_dbg_assert_(DVDINTERFACE, fileIter->first >= _Offset);
|
||||
PadToAddress(fileIter->first, _Offset, _Length, _pBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
std::string CVolumeDirectory::GetName() const
|
||||
{
|
||||
_dbg_assert_(DVDINTERFACE, m_diskHeader);
|
||||
std::string name = (char*)(m_diskHeader + 0x20);
|
||||
return name;
|
||||
}
|
||||
|
||||
void CVolumeDirectory::SetName(std::string _Name)
|
||||
{
|
||||
_dbg_assert_(DVDINTERFACE, m_diskHeader);
|
||||
|
||||
u32 length = _Name.length();
|
||||
if(length > MAX_NAME_LENGTH)
|
||||
length = MAX_NAME_LENGTH;
|
||||
|
||||
memcpy(m_diskHeader + 0x20, _Name.c_str(), length);
|
||||
m_diskHeader[length + 0x20] = 0;
|
||||
}
|
||||
|
||||
std::string CVolumeDirectory::GetUniqueID() const
|
||||
{
|
||||
_dbg_assert_(DVDINTERFACE, m_diskHeader);
|
||||
|
||||
char buffer[7];
|
||||
memcpy(buffer, m_diskHeader, 6);
|
||||
buffer[6] = 0;
|
||||
|
||||
std::string id = buffer;
|
||||
return id;
|
||||
}
|
||||
|
||||
void CVolumeDirectory::SetUniqueID(std::string _ID)
|
||||
{
|
||||
_dbg_assert_(DVDINTERFACE, m_diskHeader);
|
||||
|
||||
u32 length = _ID.length();
|
||||
if(length > 6)
|
||||
length = 6;
|
||||
|
||||
memcpy(m_diskHeader, _ID.c_str(), length);
|
||||
}
|
||||
|
||||
IVolume::ECountry CVolumeDirectory::GetCountry() const
|
||||
{
|
||||
_dbg_assert_(DVDINTERFACE, m_diskHeader);
|
||||
|
||||
u8 CountryCode = m_diskHeader[3];
|
||||
|
||||
ECountry country = COUNTRY_UNKNOWN;
|
||||
|
||||
switch (CountryCode)
|
||||
{
|
||||
case 'S':
|
||||
country = COUNTRY_EUROPE;
|
||||
break; // PAL // <- that is shitty :) zelda demo disc
|
||||
|
||||
case 'P':
|
||||
country = COUNTRY_EUROPE;
|
||||
break; // PAL
|
||||
|
||||
case 'D':
|
||||
country = COUNTRY_EUROPE;
|
||||
break; // PAL
|
||||
|
||||
case 'F':
|
||||
country = COUNTRY_FRANCE;
|
||||
break; // PAL
|
||||
|
||||
case 'X':
|
||||
country = COUNTRY_EUROPE;
|
||||
break; // XIII <- uses X but is PAL rip
|
||||
|
||||
case 'E':
|
||||
country = COUNTRY_USA;
|
||||
break; // USA
|
||||
|
||||
case 'J':
|
||||
country = COUNTRY_JAP;
|
||||
break; // JAP
|
||||
|
||||
case 'O':
|
||||
country = COUNTRY_UNKNOWN;
|
||||
break; // SDK
|
||||
|
||||
default:
|
||||
country = COUNTRY_UNKNOWN;
|
||||
break;
|
||||
}
|
||||
|
||||
return(country);
|
||||
}
|
||||
|
||||
u64 CVolumeDirectory::GetSize() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string CVolumeDirectory::ExtractDirectoryName(const std::string& _rDirectory)
|
||||
{
|
||||
std::string directoryName = _rDirectory;
|
||||
|
||||
size_t lastSlash = directoryName.find_last_of('\\');
|
||||
|
||||
if(lastSlash != directoryName.size() - 1)
|
||||
{
|
||||
size_t extensionStart = directoryName.find_last_of('.');
|
||||
if(extensionStart != std::string::npos && extensionStart > lastSlash)
|
||||
{
|
||||
directoryName.resize(lastSlash);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
directoryName.resize(directoryName.size() - 1);
|
||||
}
|
||||
|
||||
return directoryName;
|
||||
}
|
||||
|
||||
void CVolumeDirectory::SetDiskTypeWii()
|
||||
{
|
||||
_dbg_assert_(DVDINTERFACE, m_diskHeader);
|
||||
|
||||
m_diskHeader[0x18] = 0x5d;
|
||||
m_diskHeader[0x19] = 0x1c;
|
||||
m_diskHeader[0x1a] = 0x9e;
|
||||
m_diskHeader[0x1b] = 0xa3;
|
||||
memset(m_diskHeader + 0x1c, 0, 4);
|
||||
|
||||
m_addressShift = 2;
|
||||
}
|
||||
|
||||
void CVolumeDirectory::SetDiskTypeGC()
|
||||
{
|
||||
_dbg_assert_(DVDINTERFACE, m_diskHeader);
|
||||
|
||||
memset(m_diskHeader + 0x18, 0, 4);
|
||||
m_diskHeader[0x1c] = 0xc2;
|
||||
m_diskHeader[0x1d] = 0x33;
|
||||
m_diskHeader[0x1e] = 0x9f;
|
||||
m_diskHeader[0x1f] = 0x3d;
|
||||
|
||||
m_addressShift = 0;
|
||||
}
|
||||
|
||||
void CVolumeDirectory::BuildFST()
|
||||
{
|
||||
if(m_FSTData)
|
||||
{
|
||||
delete m_FSTData;
|
||||
}
|
||||
|
||||
FSTEntry rootEntry;
|
||||
|
||||
// read data from physical disk to rootEntry
|
||||
u32 totalEntries = AddDirectoryEntries(m_rootDirectory, rootEntry) + 1;
|
||||
|
||||
m_fstNameOffset = totalEntries * ENTRY_SIZE; // offset in FST nameTable
|
||||
m_fstSize = m_fstNameOffset + m_totalNameSize;
|
||||
m_FSTData = new u8[(u32)m_fstSize];
|
||||
|
||||
// 4 byte aligned start of data on disk
|
||||
m_dataStartAddress = (FST_ADDRESS + m_fstSize + 3) & 0xfffffffc;
|
||||
u64 curDataAddress = m_dataStartAddress;
|
||||
|
||||
u32 fstOffset = 0; // offset within FST data
|
||||
u32 nameOffset = 0; // offset within name table
|
||||
u32 rootOffset = 0; // offset of root of FST
|
||||
|
||||
// write root entry
|
||||
WriteEntryData(fstOffset, DIRECTORY_ENTRY, 0, 0, totalEntries);
|
||||
|
||||
for(std::vector<FSTEntry>::iterator iter = rootEntry.children.begin(); iter != rootEntry.children.end(); ++iter)
|
||||
{
|
||||
WriteEntry(*iter, fstOffset, nameOffset, curDataAddress, rootOffset);
|
||||
}
|
||||
|
||||
// overflow check
|
||||
_dbg_assert_(DVDINTERFACE, nameOffset == m_fstSize);
|
||||
|
||||
// write FST size and location
|
||||
_dbg_assert_(DVDINTERFACE, m_diskHeader);
|
||||
Write32((u32)(FST_ADDRESS >> m_addressShift), 0x0424, m_diskHeader);
|
||||
Write32((u32)m_fstSize, 0x0428, m_diskHeader);
|
||||
Write32((u32)m_fstSize, 0x042c, m_diskHeader);
|
||||
}
|
||||
|
||||
void CVolumeDirectory::WriteToBuffer(u64 _SrcStartAddress, u64 _SrcLength, u8* _Src,
|
||||
u64& _Address, u64& _Length, u8*& _pBuffer) const
|
||||
{
|
||||
_dbg_assert_(DVDINTERFACE, _Address >= _SrcStartAddress);
|
||||
|
||||
u64 srcOffset = _Address - _SrcStartAddress;
|
||||
|
||||
if(srcOffset < _SrcLength)
|
||||
{
|
||||
u64 srcBytes = _SrcLength - srcOffset;
|
||||
if(_Length < srcBytes)
|
||||
srcBytes = _Length;
|
||||
|
||||
memcpy(_pBuffer, _Src + srcOffset, (size_t)srcBytes);
|
||||
|
||||
_Length -= srcBytes;
|
||||
_pBuffer += srcBytes;
|
||||
_Address += srcBytes;
|
||||
}
|
||||
}
|
||||
|
||||
void CVolumeDirectory::PadToAddress(u64 _StartAddress, u64& _Address, u64& _Length, u8*& _pBuffer) const
|
||||
{
|
||||
if(_StartAddress <= _Address)
|
||||
return;
|
||||
|
||||
u64 padBytes = _StartAddress - _Address;
|
||||
if(padBytes > _Length)
|
||||
padBytes = _Length;
|
||||
|
||||
if(_Length > 0)
|
||||
{
|
||||
memset(_pBuffer, 0, (size_t)padBytes);
|
||||
_Length -= padBytes;
|
||||
_pBuffer += padBytes;
|
||||
_Address += padBytes;
|
||||
}
|
||||
}
|
||||
|
||||
void CVolumeDirectory::Write32(u32 data, u32 offset, u8* buffer)
|
||||
{
|
||||
buffer[offset++] = (data >> 24);
|
||||
buffer[offset++] = (data >> 16) & 0xff;
|
||||
buffer[offset++] = (data >> 8) & 0xff;
|
||||
buffer[offset] = (data) & 0xff;
|
||||
}
|
||||
|
||||
void CVolumeDirectory::WriteEntryData(u32& entryOffset, u8 type, u32 nameOffset, u64 dataOffset, u32 length)
|
||||
{
|
||||
m_FSTData[entryOffset++] = type;
|
||||
|
||||
m_FSTData[entryOffset++] = (nameOffset >> 16) & 0xff;
|
||||
m_FSTData[entryOffset++] = (nameOffset >> 8) & 0xff;
|
||||
m_FSTData[entryOffset++] = (nameOffset) & 0xff;
|
||||
|
||||
Write32((u32)(dataOffset >> m_addressShift), entryOffset, m_FSTData);
|
||||
entryOffset += 4;
|
||||
|
||||
Write32((u32)length, entryOffset, m_FSTData);
|
||||
entryOffset += 4;
|
||||
}
|
||||
|
||||
void CVolumeDirectory::WriteEntryName(u32& nameOffset, const std::string& name)
|
||||
{
|
||||
strncpy((char*)(m_FSTData + nameOffset + m_fstNameOffset), name.c_str(), name.length() + 1);
|
||||
|
||||
nameOffset += (name.length() + 1);
|
||||
}
|
||||
|
||||
void CVolumeDirectory::WriteEntry(const FSTEntry& entry, u32& fstOffset, u32& nameOffset, u64& dataOffset, u32 parentEntryNum)
|
||||
{
|
||||
if(entry.isDirectory)
|
||||
{
|
||||
u32 myOffset = fstOffset;
|
||||
u32 myEntryNum = myOffset / ENTRY_SIZE;
|
||||
WriteEntryData(fstOffset, DIRECTORY_ENTRY, nameOffset, parentEntryNum, myEntryNum + entry.size + 1);
|
||||
WriteEntryName(nameOffset, entry.virtualName);
|
||||
|
||||
for(std::vector<FSTEntry>::const_iterator iter = entry.children.begin(); iter != entry.children.end(); ++iter)
|
||||
{
|
||||
WriteEntry(*iter, fstOffset, nameOffset, dataOffset, myEntryNum);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// put entry in FST
|
||||
WriteEntryData(fstOffset, FILE_ENTRY, nameOffset, dataOffset, entry.size);
|
||||
WriteEntryName(nameOffset, entry.virtualName);
|
||||
|
||||
// write entry to virtual disk
|
||||
_dbg_assert_(DVDINTERFACE, m_virtualDisk.find(dataOffset) == m_virtualDisk.end());
|
||||
m_virtualDisk.insert(make_pair(dataOffset, entry.physicalName));
|
||||
|
||||
// 4 byte aligned
|
||||
dataOffset = (dataOffset + entry.size + 3) & 0xfffffffc;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
bool ReadFoundFile(const WIN32_FIND_DATA& ffd, CVolumeDirectory::FSTEntry& entry)
|
||||
{
|
||||
// ignore files starting with a .
|
||||
if(strncmp(ffd.cFileName, ".", 1) == 0)
|
||||
return false;
|
||||
|
||||
entry.virtualName = ffd.cFileName;
|
||||
|
||||
if(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
{
|
||||
entry.isDirectory = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
entry.isDirectory = false;
|
||||
entry.size = ffd.nFileSizeLow;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
u32 CVolumeDirectory::AddDirectoryEntries(const std::string& _Directory, FSTEntry& parentEntry)
|
||||
{
|
||||
// Find the first file in the directory.
|
||||
WIN32_FIND_DATA ffd;
|
||||
std::string searchName = _Directory + "\\*";
|
||||
HANDLE hFind = FindFirstFile(searchName.c_str(), &ffd);
|
||||
|
||||
u32 foundEntries = 0;
|
||||
|
||||
if (hFind != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
do
|
||||
{
|
||||
FSTEntry entry;
|
||||
|
||||
if(ReadFoundFile(ffd, entry))
|
||||
{
|
||||
entry.physicalName = _Directory + "\\" + entry.virtualName;
|
||||
if(entry.isDirectory)
|
||||
{
|
||||
u32 childEntries = AddDirectoryEntries(entry.physicalName, entry);
|
||||
entry.size = childEntries;
|
||||
foundEntries += childEntries;
|
||||
}
|
||||
|
||||
++foundEntries;
|
||||
|
||||
parentEntry.children.push_back(entry);
|
||||
m_totalNameSize += entry.virtualName.length() + 1;
|
||||
}
|
||||
} while (FindNextFile(hFind, &ffd) != 0);
|
||||
}
|
||||
|
||||
FindClose(hFind);
|
||||
|
||||
return foundEntries;
|
||||
}
|
||||
#else
|
||||
void CVolumeDirectory::AddDirectoryEntries(const std::string& _Directory, const std::string& _FSTDirectory, FSTEntry& parentEntry)
|
||||
{
|
||||
// TODO - Insert linux stuff here
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace
|
|
@ -0,0 +1,109 @@
|
|||
// Copyright (C) 2003-2008 Dolphin Project.
|
||||
|
||||
// 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, version 2.0.
|
||||
|
||||
// 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 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Volume.h"
|
||||
#include "Common.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
//
|
||||
// --- this volume type is used for reading files directly from the hard drive ---
|
||||
//
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
|
||||
class CVolumeDirectory
|
||||
: public IVolume
|
||||
{
|
||||
public:
|
||||
|
||||
CVolumeDirectory(const std::string& _rDirectory, bool _bIsWii);
|
||||
|
||||
~CVolumeDirectory();
|
||||
|
||||
static bool IsValidDirectory(const std::string& _rDirectory);
|
||||
|
||||
bool Read(u64 _Offset, u64 _Length, u8* _pBuffer) const;
|
||||
|
||||
std::string GetName() const;
|
||||
void SetName(std::string);
|
||||
|
||||
std::string GetUniqueID() const;
|
||||
void SetUniqueID(std::string _ID);
|
||||
|
||||
ECountry GetCountry() const;
|
||||
|
||||
u64 GetSize() const;
|
||||
|
||||
void BuildFST();
|
||||
|
||||
struct FSTEntry
|
||||
{
|
||||
bool isDirectory;
|
||||
u32 size; // file length or number of entries from children
|
||||
std::string physicalName; // name on disk
|
||||
std::string virtualName; // name in FST names table
|
||||
std::vector<FSTEntry> children;
|
||||
};
|
||||
|
||||
private:
|
||||
static std::string ExtractDirectoryName(const std::string& _rDirectory);
|
||||
|
||||
void SetDiskTypeWii();
|
||||
void SetDiskTypeGC();
|
||||
|
||||
// writing to read buffer
|
||||
void WriteToBuffer(u64 _SrcStartAddress, u64 _SrcLength, u8* _Src,
|
||||
u64& _Address, u64& _Length, u8*& _pBuffer) const;
|
||||
|
||||
void PadToAddress(u64 _StartAddress, u64& _Address, u64& _Length, u8*& _pBuffer) const;
|
||||
|
||||
void Write32(u32 data, u32 offset, u8* buffer);
|
||||
|
||||
// FST creation
|
||||
void WriteEntryData(u32& entryOffset, u8 type, u32 nameOffset, u64 dataOffset, u32 length);
|
||||
void WriteEntryName(u32& nameOffset, const std::string& name);
|
||||
void WriteEntry(const FSTEntry& entry, u32& fstOffset, u32& nameOffset, u64& dataOffset, u32 parentEntryNum);
|
||||
|
||||
// returns number of entries found in _Directory
|
||||
u32 AddDirectoryEntries(const std::string& _Directory, FSTEntry& parentEntry);
|
||||
|
||||
std::string m_rootDirectory;
|
||||
|
||||
std::map<u64, std::string> m_virtualDisk;
|
||||
|
||||
u32 m_totalNameSize;
|
||||
|
||||
// gc has no shift, wii has 2 bit shift
|
||||
u32 m_addressShift;
|
||||
|
||||
// first address on disk containing file data
|
||||
u64 m_dataStartAddress;
|
||||
|
||||
u64 m_fstNameOffset;
|
||||
|
||||
u64 m_fstSize;
|
||||
|
||||
u8* m_FSTData;
|
||||
u8* m_diskHeader;
|
||||
};
|
||||
} // namespace
|
||||
|
|
@ -70,6 +70,7 @@ void SConfig::SaveSettings()
|
|||
ini.Set("Core", "SkipIdle", m_LocalCoreStartupParameter.bSkipIdle);
|
||||
ini.Set("Core", "LockThreads", m_LocalCoreStartupParameter.bLockThreads);
|
||||
ini.Set("Core", "DefaultGCM", m_LocalCoreStartupParameter.m_strDefaultGCM);
|
||||
ini.Set("Core", "DVDRoot", m_LocalCoreStartupParameter.m_strDVDRoot);
|
||||
ini.Set("Core", "OptimizeQuantizers", m_LocalCoreStartupParameter.bOptimizeQuantizers);
|
||||
}
|
||||
|
||||
|
@ -122,6 +123,7 @@ void SConfig::LoadSettings()
|
|||
ini.Get("Core", "SkipIdle", &m_LocalCoreStartupParameter.bSkipIdle, true);
|
||||
ini.Get("Core", "LockThreads", &m_LocalCoreStartupParameter.bLockThreads, true);
|
||||
ini.Get("Core", "DefaultGCM", &m_LocalCoreStartupParameter.m_strDefaultGCM);
|
||||
ini.Get("Core", "DVDRoot", &m_LocalCoreStartupParameter.m_strDVDRoot);
|
||||
ini.Get("Core", "OptimizeQuantizers", &m_LocalCoreStartupParameter.bOptimizeQuantizers, true);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue