2010-04-25 00:31:27 +00:00
|
|
|
/*
|
2009-02-09 21:15:56 +00:00
|
|
|
* Copyright (C) 2007 Gabest
|
|
|
|
* http://www.gabest.org
|
|
|
|
*
|
|
|
|
* 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; either version 2, or (at your option)
|
|
|
|
* any later version.
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2009-02-09 21:15:56 +00:00
|
|
|
* 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 for more details.
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2009-02-09 21:15:56 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GNU Make; see the file COPYING. If not, write to
|
2010-04-25 00:31:27 +00:00
|
|
|
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
2009-02-09 21:15:56 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "cdvd.h"
|
|
|
|
#include "SettingsDlg.h"
|
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
static HMODULE s_hModule;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
|
|
|
|
{
|
|
|
|
switch(ul_reason_for_call)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
s_hModule = hModule;
|
|
|
|
case DLL_THREAD_ATTACH:
|
|
|
|
case DLL_THREAD_DETACH:
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
CDVDolioApp theApp;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
const char* CDVDolioApp::m_ini = "inis/CDVDolio.ini";
|
|
|
|
const char* CDVDolioApp::m_section = "Settings";
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
CDVDolioApp::CDVDolioApp()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
HMODULE CDVDolioApp::GetModuleHandle()
|
|
|
|
{
|
|
|
|
return s_hModule;
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
string CDVDolioApp::GetConfig(const char* entry, const char* value)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-06-19 00:11:56 +00:00
|
|
|
char buff[4096] = {0};
|
|
|
|
GetPrivateProfileString(m_section, entry, value, buff, countof(buff), m_ini);
|
|
|
|
return string(buff);
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
void CDVDolioApp::SetConfig(const char* entry, const char* value)
|
|
|
|
{
|
|
|
|
WritePrivateProfileString(m_section, entry, value, m_ini);
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
int CDVDolioApp::GetConfig(const char* entry, int value)
|
|
|
|
{
|
|
|
|
return GetPrivateProfileInt(m_section, entry, value, m_ini);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CDVDolioApp::SetConfig(const char* entry, int value)
|
|
|
|
{
|
|
|
|
char buff[32] = {0};
|
|
|
|
itoa(value, buff, 10);
|
|
|
|
SetConfig(entry, buff);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
#define PS2E_LT_CDVD 0x08
|
|
|
|
#define PS2E_CDVD_VERSION 0x0005
|
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
EXPORT_C_(uint32) PS2EgetLibType()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
return PS2E_LT_CDVD;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(char*) PS2EgetLibName()
|
|
|
|
{
|
|
|
|
return "CDVDolio"; // olio = OverLapped I/O (duh)
|
|
|
|
}
|
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
EXPORT_C_(uint32) PS2EgetLibVersion2(UINT32 type)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-06-19 00:11:56 +00:00
|
|
|
const uint32 revision = 0;
|
|
|
|
const uint32 build = 1;
|
|
|
|
const uint32 minor = 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
return (build << 0) | (revision << 8) | (PS2E_CDVD_VERSION << 16) | (minor << 24);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
CDVD::CDVD()
|
2009-02-09 21:15:56 +00:00
|
|
|
: m_hFile(INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
memset(&m_overlapped, 0, sizeof(m_overlapped));
|
|
|
|
m_overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
|
|
|
m_cache.pending = false;
|
|
|
|
m_cache.count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CDVD::~CDVD()
|
|
|
|
{
|
|
|
|
CloseHandle(m_overlapped.hEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
LARGE_INTEGER CDVD::MakeOffset(int lsn)
|
|
|
|
{
|
|
|
|
LARGE_INTEGER offset;
|
|
|
|
offset.QuadPart = (LONGLONG)lsn * m_block.size + m_block.offset;
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CDVD::SyncRead(int lsn)
|
|
|
|
{
|
|
|
|
return Read(lsn) && GetBuffer();
|
|
|
|
}
|
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
bool CDVD::Open(const char* path)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-06-19 00:11:56 +00:00
|
|
|
m_label.clear();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
uint32 share = FILE_SHARE_READ;
|
|
|
|
uint32 flags = FILE_ATTRIBUTE_READONLY | FILE_FLAG_SEQUENTIAL_SCAN | FILE_FLAG_OVERLAPPED;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
m_hFile = CreateFile(path, GENERIC_READ, share, NULL, OPEN_EXISTING, flags, (HANDLE)NULL);
|
|
|
|
|
|
|
|
if(m_hFile == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_block.count = 0;
|
|
|
|
m_block.size = 2048;
|
|
|
|
m_block.offset = 0;
|
|
|
|
|
|
|
|
GET_LENGTH_INFORMATION info;
|
|
|
|
DWORD ret = 0;
|
|
|
|
|
|
|
|
if(GetFileSizeEx(m_hFile, &info.Length) || DeviceIoControl(m_hFile, IOCTL_DISK_GET_LENGTH_INFO, NULL, 0, &info, sizeof(info), &ret, NULL))
|
|
|
|
{
|
|
|
|
m_block.count = (int)(info.Length.QuadPart / m_block.size);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!SyncRead(16) || memcmp(&m_buff[24 + 1], "CD001", 5) != 0)
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
m_label = string((const char*)&m_buff[24 + 40], 32);
|
|
|
|
|
|
|
|
// trim
|
|
|
|
|
|
|
|
{
|
|
|
|
string::size_type i = m_label.find_first_not_of(' ');
|
|
|
|
string::size_type j = m_label.find_last_not_of(' ');
|
|
|
|
|
|
|
|
if(i == string::npos)
|
|
|
|
{
|
|
|
|
m_label.clear();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_label = m_label.substr(i, (j != string::npos ? j + 1 : string::npos) - i);
|
|
|
|
}
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
// m_block.count = *(DWORD*)&m_buff[24 + 80];
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CDVD::Close()
|
|
|
|
{
|
|
|
|
if(m_hFile != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
CancelIo(m_hFile);
|
|
|
|
CloseHandle(m_hFile);
|
|
|
|
m_hFile = INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_cache.pending = false;
|
|
|
|
m_cache.count = 0;
|
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
m_label.clear();
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
const char* CDVD::GetLabel()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-06-19 00:11:56 +00:00
|
|
|
return m_label.c_str();
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CDVD::Read(int lsn, int mode)
|
|
|
|
{
|
|
|
|
if(mode != CDVD_MODE_2048) return false;
|
|
|
|
|
|
|
|
if(lsn < 0) lsn += m_block.count;
|
|
|
|
|
|
|
|
if(lsn < 0 || lsn >= m_block.count) return false;
|
|
|
|
|
|
|
|
if(m_cache.pending)
|
|
|
|
{
|
|
|
|
CancelIo(m_hFile);
|
|
|
|
ResetEvent(m_overlapped.hEvent);
|
|
|
|
m_cache.pending = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(lsn >= m_cache.start && lsn < m_cache.start + m_cache.count)
|
|
|
|
{
|
|
|
|
memcpy(&m_buff[24], &m_cache.buff[(lsn - m_cache.start) * 2048], 2048);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_cache.pending = true;
|
|
|
|
m_cache.start = lsn;
|
|
|
|
m_cache.count = min(CACHE_BLOCK_COUNT, m_block.count - m_cache.start);
|
|
|
|
|
|
|
|
LARGE_INTEGER offset = MakeOffset(lsn);
|
|
|
|
|
|
|
|
m_overlapped.Offset = offset.LowPart;
|
|
|
|
m_overlapped.OffsetHigh = offset.HighPart;
|
|
|
|
|
|
|
|
if(!ReadFile(m_hFile, m_cache.buff, m_cache.count * 2048, NULL, &m_overlapped))
|
|
|
|
{
|
|
|
|
switch(GetLastError())
|
|
|
|
{
|
|
|
|
case ERROR_IO_PENDING:
|
|
|
|
break;
|
|
|
|
case ERROR_HANDLE_EOF:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
uint8* CDVD::GetBuffer()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
DWORD size = 0;
|
|
|
|
|
|
|
|
if(m_cache.pending)
|
|
|
|
{
|
|
|
|
if(GetOverlappedResult(m_hFile, &m_overlapped, &size, TRUE))
|
|
|
|
{
|
|
|
|
memcpy(&m_buff[24], m_cache.buff, 2048);
|
|
|
|
|
|
|
|
m_cache.pending = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return &m_buff[24];
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
uint32 CDVD::GetTN(cdvdTN* buff)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
buff->strack = 1;
|
|
|
|
buff->etrack = 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
uint32 CDVD::GetTD(BYTE track, cdvdTD* buff)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
if(track == 0)
|
|
|
|
{
|
|
|
|
buff->lsn = m_block.count;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buff->type = CDVD_MODE1_TRACK;
|
|
|
|
buff->lsn = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CDVD s_cdvd;
|
|
|
|
|
|
|
|
//
|
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
EXPORT_C_(uint32) CDVDinit()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C CDVDshutdown()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
EXPORT_C_(uint32) CDVDopen(const char* title)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-06-19 00:11:56 +00:00
|
|
|
string path;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
int i = theApp.GetConfig("drive", -1);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if(i >= 'A' && i <= 'Z')
|
|
|
|
{
|
2009-06-19 00:11:56 +00:00
|
|
|
path = format("\\\\.\\%c:", i);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-06-19 00:11:56 +00:00
|
|
|
path = theApp.GetConfig("iso", "");
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
return s_cdvd.Open(path.c_str()) ? 0 : -1;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C CDVDclose()
|
|
|
|
{
|
|
|
|
s_cdvd.Close();
|
|
|
|
}
|
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
EXPORT_C_(uint32) CDVDreadTrack(int lsn, int mode)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
return s_cdvd.Read(lsn, mode) ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
EXPORT_C_(uint8*) CDVDgetBuffer()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
return s_cdvd.GetBuffer();
|
|
|
|
}
|
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
EXPORT_C_(uint32) CDVDreadSubQ(uint32 lsn, cdvdSubQ* subq)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
EXPORT_C_(uint32) CDVDgetTN(cdvdTN* buff)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
return s_cdvd.GetTN(buff);
|
|
|
|
}
|
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
EXPORT_C_(uint32) CDVDgetTD(uint8 track, cdvdTD* buff)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
return s_cdvd.GetTD(track, buff);
|
|
|
|
}
|
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
EXPORT_C_(uint32) CDVDgetTOC(void* toc)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
return -1; // TODO
|
|
|
|
}
|
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
EXPORT_C_(uint32) CDVDgetDiskType()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
return CDVD_TYPE_PS2DVD; // TODO
|
|
|
|
}
|
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
EXPORT_C_(uint32) CDVDgetTrayStatus()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
return CDVD_TRAY_CLOSE;
|
|
|
|
}
|
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
EXPORT_C_(uint32) CDVDctrlTrayOpen()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
EXPORT_C_(uint32) CDVDctrlTrayClose()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C CDVDconfigure()
|
|
|
|
{
|
2009-06-19 00:11:56 +00:00
|
|
|
CDVDSettingsDlg dlg;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if(IDOK == dlg.DoModal())
|
|
|
|
{
|
|
|
|
CDVDshutdown();
|
|
|
|
CDVDinit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C CDVDabout()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-06-19 00:11:56 +00:00
|
|
|
EXPORT_C_(uint32) CDVDtest()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|