GSdx: removed the last bit of mfc dependency from cdvdolio

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1398 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
gabest11 2009-06-19 00:11:56 +00:00
parent bc1b84295f
commit 7ad2d919b8
15 changed files with 1154 additions and 874 deletions

View File

@ -0,0 +1,177 @@
/*
* Copyright (C) 2007-2009 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.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#include "StdAfx.h"
#include "CDVD.h"
#include "CDVDDialog.h"
CDVDDialog::CDVDDialog(UINT id)
: m_id(id)
, m_hWnd(NULL)
{
}
INT_PTR CDVDDialog::DoModal()
{
return DialogBoxParam(theApp.GetModuleHandle(), MAKEINTRESOURCE(m_id), NULL, DialogProc, (LPARAM)this);
}
INT_PTR CALLBACK CDVDDialog::DialogProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
CDVDDialog* dlg = NULL;
if(message == WM_INITDIALOG)
{
dlg = (CDVDDialog*)lParam;
SetWindowLongPtr(hWnd, GWL_USERDATA, (LONG_PTR)dlg);
dlg->m_hWnd = hWnd;
MONITORINFO mi;
mi.cbSize = sizeof(mi);
GetMonitorInfo(MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST), &mi);
RECT r;
GetWindowRect(hWnd, &r);
int x = (mi.rcWork.left + mi.rcWork.right - (r.right - r.left)) / 2;
int y = (mi.rcWork.top + mi.rcWork.bottom - (r.bottom - r.top)) / 2;
SetWindowPos(hWnd, NULL, x, y, -1, -1, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
dlg->OnInit();
return true;
}
dlg = (CDVDDialog*)GetWindowLongPtr(hWnd, GWL_USERDATA);
return dlg != NULL ? dlg->OnMessage(message, wParam, lParam) : FALSE;
}
bool CDVDDialog::OnMessage(UINT message, WPARAM wParam, LPARAM lParam)
{
return message == WM_COMMAND ? OnCommand((HWND)lParam, LOWORD(wParam), HIWORD(wParam)) : false;
}
bool CDVDDialog::OnCommand(HWND hWnd, UINT id, UINT code)
{
if(id == IDOK || id == IDCANCEL)
{
EndDialog(m_hWnd, id);
return true;
}
return false;
}
string CDVDDialog::GetText(UINT id)
{
string s;
char* buff = NULL;
for(int size = 256, limit = 65536; size < limit; size <<= 1)
{
buff = new char[size];
if(GetDlgItemText(m_hWnd, id, buff, size))
{
s = buff;
size = limit;
}
delete [] buff;
}
return s;
}
int CDVDDialog::GetTextAsInt(UINT id)
{
return atoi(GetText(id).c_str());
}
void CDVDDialog::SetText(UINT id, const char* str)
{
SetDlgItemText(m_hWnd, id, str);
}
void CDVDDialog::SetTextAsInt(UINT id, int i)
{
char buff[32] = {0};
itoa(i, buff, 10);
SetText(id, buff);
}
void CDVDDialog::ComboBoxInit(UINT id, const CDVDSetting* settings, int count, uint32 selid, uint32 maxid)
{
HWND hWnd = GetDlgItem(m_hWnd, id);
SendMessage(hWnd, CB_RESETCONTENT, 0, 0);
for(int i = 0; i < count; i++)
{
if(settings[i].id <= maxid)
{
string str = settings[i].name;
if(!settings[i].note.empty())
{
str = str + " (" + settings[i].note + ")";
}
ComboBoxAppend(id, str.c_str(), (LPARAM)settings[i].id, settings[i].id == selid);
}
}
}
int CDVDDialog::ComboBoxAppend(UINT id, const char* str, LPARAM data, bool select)
{
HWND hWnd = GetDlgItem(m_hWnd, id);
int item = (int)SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)str);
SendMessage(hWnd, CB_SETITEMDATA, item, (LPARAM)data);
if(select)
{
SendMessage(hWnd, CB_SETCURSEL, item, 0);
}
return item;
}
bool CDVDDialog::ComboBoxGetSelData(UINT id, INT_PTR& data)
{
HWND hWnd = GetDlgItem(m_hWnd, id);
int item = SendMessage(hWnd, CB_GETCURSEL, 0, 0);
if(item >= 0)
{
data = SendMessage(hWnd, CB_GETITEMDATA, item, 0);
return true;
}
return false;
}

View File

@ -0,0 +1,59 @@
/*
* Copyright (C) 2007-2009 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.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#pragma once
struct CDVDSetting
{
uint32 id;
string name;
string note;
};
class CDVDDialog
{
int m_id;
static INT_PTR CALLBACK DialogProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
protected:
HWND m_hWnd;
virtual void OnInit() {}
virtual bool OnMessage(UINT message, WPARAM wParam, LPARAM lParam);
virtual bool OnCommand(HWND hWnd, UINT id, UINT code);
public:
CDVDDialog (UINT id);
virtual ~CDVDDialog () {}
INT_PTR DoModal();
string GetText(UINT id);
int GetTextAsInt(UINT id);
void SetText(UINT id, const char* str);
void SetTextAsInt(UINT id, int i);
void ComboBoxInit(UINT id, const CDVDSetting* settings, int count, uint32 selid, uint32 maxid = ~0);
int ComboBoxAppend(UINT id, const char* str, LPARAM data = 0, bool select = false);
bool ComboBoxGetSelData(UINT id, INT_PTR& data);
};

View File

@ -2,193 +2,156 @@
//
#include "stdafx.h"
#include "cdvd.h"
#include "CDVD.h"
#include "SettingsDlg.h"
#include <dbt.h>
#include <afxdlgs.h>
// CSettingsDlg dialog
IMPLEMENT_DYNAMIC(CSettingsDlg, CDialog)
CSettingsDlg::CSettingsDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSettingsDlg::IDD, pParent)
, m_iso(_T(""))
{
}
CSettingsDlg::~CSettingsDlg()
CDVDSettingsDlg::CDVDSettingsDlg()
: CDVDDialog(IDD_CONFIG)
{
}
BOOL CSettingsDlg::OnInitDialog()
void CDVDSettingsDlg::OnInit()
{
__super::OnInitDialog();
__super::OnInit();
InitDrive();
InitISO();
UpdateDrives();
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
SetText(IDC_EDIT1, theApp.GetConfig("iso", "").c_str());
}
void CSettingsDlg::InitDrive()
bool CDVDSettingsDlg::OnMessage(UINT message, WPARAM wParam, LPARAM lParam)
{
int drive = AfxGetApp()->GetProfileInt(_T("Settings"), _T("drive"), -1);
int sel = m_drive.GetCurSel();
if(sel >= 0)
if(message == WM_DEVICECHANGE && (wParam == DBT_DEVICEARRIVAL || wParam == DBT_DEVICEREMOVECOMPLETE))
{
drive = m_drive.GetItemData(sel);
UpdateDrives();
DEV_BROADCAST_HDR* p = (DEV_BROADCAST_HDR*)lParam;
if(p->dbch_devicetype == DBT_DEVTYP_VOLUME)
{
DEV_BROADCAST_VOLUME* v = (DEV_BROADCAST_VOLUME*)p;
for(int i = 0; i < 32; i++)
{
if(v->dbcv_unitmask & (1 << i))
{
// printf("%c:\n", 'A' + i);
// TODO
}
}
}
}
while(m_drive.GetCount() > 0)
return __super::OnMessage(message, wParam, lParam);
}
bool CDVDSettingsDlg::OnCommand(HWND hWnd, UINT id, UINT code)
{
if(id == IDOK)
{
m_drive.DeleteString(0);
INT_PTR data = 0;
if(!ComboBoxGetSelData(IDC_COMBO1, data))
{
data = -1;
}
theApp.SetConfig("drive", (int)data);
theApp.SetConfig("iso", GetText(IDC_EDIT1).c_str());
}
else if(id == IDC_BUTTON1 && code == BN_CLICKED)
{
char buff[MAX_PATH] = {0};
OPENFILENAME ofn;
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = m_hWnd;
ofn.lpstrFile = buff;
ofn.nMaxFile = countof(buff);
ofn.lpstrFilter = "ISO file\0*.iso\0All files\0*.*\0";
ofn.Flags = OFN_EXPLORER | OFN_ENABLESIZING | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
strcpy(ofn.lpstrFile, GetText(IDC_EDIT1).c_str());
if(GetOpenFileName(&ofn))
{
SetText(IDC_EDIT1, ofn.lpstrFile);
HWND hWnd = GetDlgItem(m_hWnd, IDC_COMBO1);
SendMessage(hWnd, CB_SETCURSEL, SendMessage(hWnd, CB_GETCOUNT, 0, 0) - 1, 0);
}
return true;
}
return __super::OnCommand(hWnd, id, code);
}
void CDVDSettingsDlg::UpdateDrives()
{
int drive = theApp.GetConfig("drive", -1);
INT_PTR data = 0;
if(ComboBoxGetSelData(IDC_COMBO1, data))
{
drive = (int)data;
}
vector<CDVDSetting> drives;
for(int i = 'A'; i <= 'Z'; i++)
{
CString path;
string path = format("%c:", i);
path.Format(_T("%c:"), i);
if(GetDriveType(path) == DRIVE_CDROM)
if(GetDriveType(path.c_str()) == DRIVE_CDROM)
{
CString label = path;
string label = path;
path.Format(_T("\\\\.\\%c:"), i);
path = format("\\\\.\\%c:", i);
CDVD cdvd;
if(cdvd.Open(path))
if(cdvd.Open(path.c_str()))
{
CString str = cdvd.GetLabel();
string str = cdvd.GetLabel();
if(str.IsEmpty())
if(str.empty())
{
str = _T("(no label)");
str = "(no label)";
}
label.Format(_T("[%s] %s"), CString(label), str);
label = "[" + label + "] " + str;
}
else
{
label.Format(_T("[%s] (not detected)"), CString(label));
label = "[" + label + "] (not detected)";
}
m_drive.SetItemData(m_drive.AddString(label), (DWORD_PTR)i);
CDVDSetting s;
s.id = i;
s.name = label;
drives.push_back(s);
}
}
m_drive.SetItemData(m_drive.AddString(_T("Other...")), (DWORD_PTR)-1);
for(int i = 0, j = m_drive.GetCount(); i < j; i++)
{
if((int)m_drive.GetItemData(i) == drive)
{
m_drive.SetCurSel(i);
CDVDSetting s;
return;
}
s.id = -1;
s.name = "Other...";
drives.push_back(s);
}
m_drive.SetCurSel(-1);
}
void CSettingsDlg::InitISO()
{
m_iso = AfxGetApp()->GetProfileString(_T("Settings"), _T("iso"), _T(""));
}
void CSettingsDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_COMBO1, m_drive);
DDX_Text(pDX, IDC_EDIT1, m_iso);
}
BEGIN_MESSAGE_MAP(CSettingsDlg, CDialog)
ON_BN_CLICKED(IDC_BUTTON1, &CSettingsDlg::OnBrowse)
ON_BN_CLICKED(IDOK, &CSettingsDlg::OnBnClickedOk)
END_MESSAGE_MAP()
// CSettingsDlg message handlers
LRESULT CSettingsDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if(message == WM_DEVICECHANGE)
{
if(wParam == DBT_DEVICEARRIVAL || wParam == DBT_DEVICEREMOVECOMPLETE)
{
InitDrive();
DEV_BROADCAST_HDR* p = (DEV_BROADCAST_HDR*)lParam;
if(p->dbch_devicetype == DBT_DEVTYP_VOLUME)
{
DEV_BROADCAST_VOLUME* v = (DEV_BROADCAST_VOLUME*)p;
for(int i = 0; i < 32; i++)
{
if(v->dbcv_unitmask & (1 << i))
{
TRACE(_T("%c:\n"), 'A' + i);
// TODO
}
}
}
}
}
return __super::WindowProc(message, wParam, lParam);
}
void CSettingsDlg::OnBrowse()
{
UpdateData();
CFileDialog fd(TRUE, NULL, m_iso,
OFN_EXPLORER | OFN_ENABLESIZING | OFN_HIDEREADONLY,
_T("ISO file|*.iso|All files|*.*|"), this);
if(fd.DoModal() == IDOK)
{
m_iso = fd.GetPathName();
UpdateData(FALSE);
for(int i = 0, j = m_drive.GetCount(); i < j; i++)
{
if((int)m_drive.GetItemData(i) < 0)
{
m_drive.SetCurSel(i);
break;
}
}
}
}
void CSettingsDlg::OnBnClickedOk()
{
UpdateData();
int i = m_drive.GetCurSel();
if(i >= 0)
{
i = (int)m_drive.GetItemData(i);
}
AfxGetApp()->WriteProfileInt(_T("Settings"), _T("drive"), i);
AfxGetApp()->WriteProfileString(_T("Settings"), _T("iso"), m_iso);
OnOK();
ComboBoxInit(IDC_COMBO1, &drives[0], drives.size(), drive);
}

View File

@ -1,35 +1,16 @@
#pragma once
#include "afxwin.h"
#include "CDVDDialog.h"
#include "resource.h"
// CSettingsDlg dialog
class CSettingsDlg : public CDialog
class CDVDSettingsDlg : public CDVDDialog
{
DECLARE_DYNAMIC(CSettingsDlg)
void UpdateDrives();
protected:
void InitDrive();
void InitISO();
void OnInit();
bool OnMessage(UINT message, WPARAM wParam, LPARAM lParam);
bool OnCommand(HWND hWnd, UINT id, UINT code);
public:
CSettingsDlg(CWnd* pParent = NULL); // standard constructor
virtual ~CSettingsDlg();
virtual BOOL OnInitDialog();
enum { IDD = IDD_CONFIG };
CComboBox m_drive;
CString m_iso;
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
afx_msg void OnBrowse();
afx_msg void OnBnClickedOk();
CDVDSettingsDlg();
};

View File

@ -22,55 +22,60 @@
#include "stdafx.h"
#include "cdvd.h"
#include "SettingsDlg.h"
#include <winioctl.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
static HMODULE s_hModule;
//
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//
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;
}
BEGIN_MESSAGE_MAP(cdvdApp, CWinApp)
END_MESSAGE_MAP()
return TRUE;
}
cdvdApp::cdvdApp()
CDVDolioApp theApp;
const char* CDVDolioApp::m_ini = "inis/CDVDolio.ini";
const char* CDVDolioApp::m_section = "Settings";
CDVDolioApp::CDVDolioApp()
{
}
cdvdApp theApp;
BOOL cdvdApp::InitInstance()
HMODULE CDVDolioApp::GetModuleHandle()
{
__super::InitInstance();
return s_hModule;
}
SetRegistryKey(_T("Gabest"));
string CDVDolioApp::GetConfig(const char* entry, const char* value)
{
char buff[4096] = {0};
GetPrivateProfileString(m_section, entry, value, buff, countof(buff), m_ini);
return string(buff);
}
return TRUE;
void CDVDolioApp::SetConfig(const char* entry, const char* value)
{
WritePrivateProfileString(m_section, entry, value, m_ini);
}
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);
}
//
@ -78,7 +83,7 @@ BOOL cdvdApp::InitInstance()
#define PS2E_LT_CDVD 0x08
#define PS2E_CDVD_VERSION 0x0005
EXPORT_C_(UINT32) PS2EgetLibType()
EXPORT_C_(uint32) PS2EgetLibType()
{
return PS2E_LT_CDVD;
}
@ -88,11 +93,11 @@ EXPORT_C_(char*) PS2EgetLibName()
return "CDVDolio"; // olio = OverLapped I/O (duh)
}
EXPORT_C_(UINT32) PS2EgetLibVersion2(UINT32 type)
EXPORT_C_(uint32) PS2EgetLibVersion2(UINT32 type)
{
const UINT32 revision = 0;
const UINT32 build = 1;
const UINT32 minor = 0;
const uint32 revision = 0;
const uint32 build = 1;
const uint32 minor = 0;
return (build << 0) | (revision << 8) | (PS2E_CDVD_VERSION << 16) | (minor << 24);
}
@ -125,12 +130,12 @@ bool CDVD::SyncRead(int lsn)
return Read(lsn) && GetBuffer();
}
bool CDVD::Open(CString path)
bool CDVD::Open(const char* path)
{
m_label.Empty();
m_label.clear();
DWORD share = FILE_SHARE_READ;
DWORD flags = FILE_ATTRIBUTE_READONLY | FILE_FLAG_SEQUENTIAL_SCAN | FILE_FLAG_OVERLAPPED;
uint32 share = FILE_SHARE_READ;
uint32 flags = FILE_ATTRIBUTE_READONLY | FILE_FLAG_SEQUENTIAL_SCAN | FILE_FLAG_OVERLAPPED;
m_hFile = CreateFile(path, GENERIC_READ, share, NULL, OPEN_EXISTING, flags, (HANDLE)NULL);
@ -164,8 +169,23 @@ bool CDVD::Open(CString path)
return false;
}
m_label = CString(CStringA((char*)&m_buff[24 + 40], 32));
m_label.Trim();
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);
}
}
// m_block.count = *(DWORD*)&m_buff[24 + 80];
@ -184,12 +204,12 @@ void CDVD::Close()
m_cache.pending = false;
m_cache.count = 0;
m_label.Empty();
m_label.clear();
}
CString CDVD::GetLabel()
const char* CDVD::GetLabel()
{
return m_label;
return m_label.c_str();
}
bool CDVD::Read(int lsn, int mode)
@ -237,7 +257,7 @@ bool CDVD::Read(int lsn, int mode)
return true;
}
BYTE* CDVD::GetBuffer()
uint8* CDVD::GetBuffer()
{
DWORD size = 0;
@ -258,7 +278,7 @@ BYTE* CDVD::GetBuffer()
return &m_buff[24];
}
UINT32 CDVD::GetTN(cdvdTN* buff)
uint32 CDVD::GetTN(cdvdTN* buff)
{
buff->strack = 1;
buff->etrack = 1;
@ -266,7 +286,7 @@ UINT32 CDVD::GetTN(cdvdTN* buff)
return 0;
}
UINT32 CDVD::GetTD(BYTE track, cdvdTD* buff)
uint32 CDVD::GetTD(BYTE track, cdvdTD* buff)
{
if(track == 0)
{
@ -285,7 +305,7 @@ static CDVD s_cdvd;
//
EXPORT_C_(UINT32) CDVDinit()
EXPORT_C_(uint32) CDVDinit()
{
return 0;
}
@ -294,22 +314,22 @@ EXPORT_C CDVDshutdown()
{
}
EXPORT_C_(UINT32) CDVDopen(const char* title)
EXPORT_C_(uint32) CDVDopen(const char* title)
{
CString path;
string path;
int i = AfxGetApp()->GetProfileInt(_T("Settings"), _T("drive"), -1);
int i = theApp.GetConfig("drive", -1);
if(i >= 'A' && i <= 'Z')
{
path.Format(_T("\\\\.\\%c:"), i);
path = format("\\\\.\\%c:", i);
}
else
{
path = AfxGetApp()->GetProfileString(_T("Settings"), _T("iso"), _T(""));
path = theApp.GetConfig("iso", "");
}
return s_cdvd.Open(path) ? 0 : -1;
return s_cdvd.Open(path.c_str()) ? 0 : -1;
}
EXPORT_C CDVDclose()
@ -317,61 +337,59 @@ EXPORT_C CDVDclose()
s_cdvd.Close();
}
EXPORT_C_(UINT32) CDVDreadTrack(int lsn, int mode)
EXPORT_C_(uint32) CDVDreadTrack(int lsn, int mode)
{
return s_cdvd.Read(lsn, mode) ? 0 : -1;
}
EXPORT_C_(BYTE*) CDVDgetBuffer()
EXPORT_C_(uint8*) CDVDgetBuffer()
{
return s_cdvd.GetBuffer();
}
EXPORT_C_(UINT32) CDVDreadSubQ(UINT32 lsn, cdvdSubQ* subq)
EXPORT_C_(uint32) CDVDreadSubQ(uint32 lsn, cdvdSubQ* subq)
{
return -1;
}
EXPORT_C_(UINT32) CDVDgetTN(cdvdTN* buff)
EXPORT_C_(uint32) CDVDgetTN(cdvdTN* buff)
{
return s_cdvd.GetTN(buff);
}
EXPORT_C_(UINT32) CDVDgetTD(BYTE track, cdvdTD* buff)
EXPORT_C_(uint32) CDVDgetTD(uint8 track, cdvdTD* buff)
{
return s_cdvd.GetTD(track, buff);
}
EXPORT_C_(UINT32) CDVDgetTOC(void* toc)
EXPORT_C_(uint32) CDVDgetTOC(void* toc)
{
return -1; // TODO
}
EXPORT_C_(UINT32) CDVDgetDiskType()
EXPORT_C_(uint32) CDVDgetDiskType()
{
return CDVD_TYPE_PS2DVD; // TODO
}
EXPORT_C_(UINT32) CDVDgetTrayStatus()
EXPORT_C_(uint32) CDVDgetTrayStatus()
{
return CDVD_TRAY_CLOSE;
}
EXPORT_C_(UINT32) CDVDctrlTrayOpen()
EXPORT_C_(uint32) CDVDctrlTrayOpen()
{
return 0;
}
EXPORT_C_(UINT32) CDVDctrlTrayClose()
EXPORT_C_(uint32) CDVDctrlTrayClose()
{
return 0;
}
EXPORT_C CDVDconfigure()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CSettingsDlg dlg;
CDVDSettingsDlg dlg;
if(IDOK == dlg.DoModal())
{
@ -384,7 +402,7 @@ EXPORT_C CDVDabout()
{
}
EXPORT_C_(UINT32) CDVDtest()
EXPORT_C_(uint32) CDVDtest()
{
return 0;
}

View File

@ -1,6 +1,6 @@
; cdvd.def : Declares the module parameters for the DLL.
LIBRARY "cdvd"
LIBRARY "CDVDolio"
EXPORTS
; Explicit exports can go here

View File

@ -21,48 +21,31 @@
#pragma once
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
class cdvdApp : public CWinApp
{
public:
cdvdApp();
public:
virtual BOOL InitInstance();
DECLARE_MESSAGE_MAP()
};
//
struct cdvdSubQ
{
BYTE ctrl:4; // control and mode bits
BYTE mode:4; // control and mode bits
BYTE trackNum; // current track number (1 to 99)
BYTE trackIndex; // current index within track (0 to 99)
BYTE trackM; // current minute location on the disc (BCD encoded)
BYTE trackS; // current sector location on the disc (BCD encoded)
BYTE trackF; // current frame location on the disc (BCD encoded)
BYTE pad; // unused
BYTE discM; // current minute offset from first track (BCD encoded)
BYTE discS; // current sector offset from first track (BCD encoded)
BYTE discF; // current frame offset from first track (BCD encoded)
uint8 ctrl:4; // control and mode bits
uint8 mode:4; // control and mode bits
uint8 trackNum; // current track number (1 to 99)
uint8 trackIndex; // current index within track (0 to 99)
uint8 trackM; // current minute location on the disc (BCD encoded)
uint8 trackS; // current sector location on the disc (BCD encoded)
uint8 trackF; // current frame location on the disc (BCD encoded)
uint8 pad; // unused
uint8 discM; // current minute offset from first track (BCD encoded)
uint8 discS; // current sector offset from first track (BCD encoded)
uint8 discF; // current frame offset from first track (BCD encoded)
};
struct cdvdTD // NOT bcd coded
{
UINT32 lsn;
BYTE type;
uint32 lsn;
uint8 type;
};
struct cdvdTN
{
BYTE strack; // number of the first track (usually 1)
BYTE etrack; // number of the last track
uint8 strack; // number of the first track (usually 1)
uint8 etrack; // number of the last track
};
// CDVDreadTrack mode values:
@ -109,14 +92,34 @@ struct cdvdTN
#define CACHE_BLOCK_COUNT 16
class CDVDolioApp
{
static const char* m_ini;
static const char* m_section;
public:
CDVDolioApp();
HMODULE GetModuleHandle();
string GetConfig(const char* entry, const char* value);
void SetConfig(const char* entry, const char* value);
int GetConfig(const char* entry, int value);
void SetConfig(const char* entry, int value);
};
extern CDVDolioApp theApp;
//
class CDVD
{
HANDLE m_hFile;
CString m_label;
string m_label;
OVERLAPPED m_overlapped;
struct {int count, size, offset;} m_block;
struct {BYTE buff[2048 * CACHE_BLOCK_COUNT]; bool pending; int start, count;} m_cache;
BYTE m_buff[2352];
struct {uint8 buff[2048 * CACHE_BLOCK_COUNT]; bool pending; int start, count;} m_cache;
uint8 m_buff[2352];
LARGE_INTEGER MakeOffset(int lsn);
bool SyncRead(int lsn);
@ -125,12 +128,12 @@ public:
CDVD();
virtual ~CDVD();
bool Open(CString path);
bool Open(const char* path);
void Close();
CString GetLabel();
const char* GetLabel();
bool Read(int lsn, int mode = CDVD_MODE_2048);
BYTE* GetBuffer();
UINT32 GetTN(cdvdTN* buff);
UINT32 GetTD(BYTE track, cdvdTD* buff);
uint8* GetBuffer();
uint32 GetTN(cdvdTN* buff);
uint32 GetTD(uint8 track, cdvdTD* buff);
};

File diff suppressed because it is too large Load Diff

View File

@ -6,3 +6,34 @@
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
string format(const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
int result = -1, length = 256;
char* buffer = NULL;
while(result == -1)
{
if(buffer) delete [] buffer;
buffer = new char[length + 1];
memset(buffer, 0, length + 1);
result = _vsnprintf(buffer, length, fmt, args);
length *= 2;
}
va_end(args);
string s(buffer);
delete [] buffer;
return s;
}

View File

@ -4,60 +4,98 @@
#pragma once
#pragma warning(disable: 4996)
#pragma warning(disable: 4996 4995 4324 4100 4101 4201)
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#endif
#ifdef _WINDOWS
// The following macros define the minimum required platform. The minimum required platform
// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run
// your application. The macros work by enabling all features available on platform versions up to and
// including the version specified.
// Modify the following defines if you have to target a platform prior to the ones specified below.
// Refer to MSDN for the latest info on corresponding values for different platforms.
#ifndef WINVER // Allow use of features specific to Windows 95 and Windows NT 4 or later.
#define WINVER 0x0510 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later.
#ifndef WINVER // Specifies that the minimum required platform is Windows Vista.
#define WINVER 0x0600 // Change this to the appropriate value to target other versions of Windows.
#endif
#ifndef _WIN32_WINNT // Allow use of features specific to Windows NT 4 or later.
#define _WIN32_WINNT 0x0400 // Change this to the appropriate value to target Windows 2000 or later.
#endif
#ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista.
#define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows.
#endif
#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later.
#ifndef _WIN32_WINDOWS // Specifies that the minimum required platform is Windows 98.
#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
#endif
#ifndef _WIN32_IE // Allow use of features specific to IE 4.0 or later.
#define _WIN32_IE 0x0400 // Change this to the appropriate value to target IE 5.0 or later.
#ifndef _WIN32_IE // Specifies that the minimum required platform is Internet Explorer 7.0.
#define _WIN32_IE 0x0700 // Change this to the appropriate value to target other versions of IE.
#endif
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <afxwin.h> // MFC core and standard components
//#include <afxext.h> // MFC extensions
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
//#include <afxmt.h>
#include <windows.h>
#include <commctrl.h>
#include <commdlg.h>
#include <shellapi.h>
#include <atlbase.h>
#include <atlcoll.h>
#include <atlpath.h>
#include <math.h>
#include <winioctl.h>
#define countof(a) (sizeof(a)/sizeof(a[0]))
#endif
// stdc
#include <math.h>
#include <time.h>
#include <intrin.h>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <hash_map>
using namespace std;
using namespace stdext;
extern string format(const char* fmt, ...);
// syntactic sugar
// put these into vc9/common7/ide/usertype.dat to have them highlighted
typedef unsigned char uint8;
typedef signed char int8;
typedef unsigned short uint16;
typedef signed short int16;
typedef unsigned int uint32;
typedef signed int int32;
typedef unsigned long long uint64;
typedef signed long long int64;
#define countof(a) (sizeof(a) / sizeof(a[0]))
#define EXPORT_C extern "C" __declspec(dllexport) void __stdcall
#define EXPORT_C_(type) extern "C" __declspec(dllexport) type __stdcall
#define ALIGN_STACK(n) __declspec(align(n)) int __dummy;
#ifndef RESTRICT
#ifdef __INTEL_COMPILER
#define RESTRICT restrict
#elif _MSC_VER >= 1400
#elif _MSC_VER >= 1400 // TODO: gcc
#define RESTRICT __restrict
#else
#define RESTRICT
#endif
#endif
#pragma warning(disable : 4995 4324 4100)
#if defined(_DEBUG) && defined(_MSC_VER)
#define ASSERT assert
#else
#define ASSERT(exp) ((void)0)
#endif
#ifdef _M_SSE
#error No SSE please!
#error No SSE please!
#endif

View File

@ -80,9 +80,7 @@ void GPUSettingsDlg::OnInit()
memset(&mode, 0, sizeof(mode));
m_modes.push_back(mode);
HWND hWnd = GetDlgItem(m_hWnd, IDC_RESOLUTION);
ComboBoxAppend(hWnd, "Windowed", (LPARAM)&m_modes.back(), true);
ComboBoxAppend(IDC_RESOLUTION, "Windowed", (LPARAM)&m_modes.back(), true);
if(CComPtr<IDirect3D9> d3d = Direct3DCreate9(D3D_SDK_VERSION))
{
@ -100,7 +98,7 @@ void GPUSettingsDlg::OnInit()
string str = format("%dx%d %dHz", mode.Width, mode.Height, mode.RefreshRate);
ComboBoxAppend(hWnd, str.c_str(), (LPARAM)&m_modes.back(), w == mode.Width && h == mode.Height && hz == mode.RefreshRate);
ComboBoxAppend(IDC_RESOLUTION, str.c_str(), (LPARAM)&m_modes.back(), w == mode.Width && h == mode.Height && hz == mode.RefreshRate);
}
}
}
@ -117,11 +115,11 @@ void GPUSettingsDlg::OnInit()
renderers.push_back(g_renderers[i]);
}
ComboBoxInit(GetDlgItem(m_hWnd, IDC_RENDERER), &renderers[0], renderers.size(), theApp.GetConfig("Renderer", 0));
ComboBoxInit(GetDlgItem(m_hWnd, IDC_FILTER), g_filter, countof(g_filter), theApp.GetConfig("filter", 0));
ComboBoxInit(GetDlgItem(m_hWnd, IDC_DITHERING), g_dithering, countof(g_dithering), theApp.GetConfig("dithering", 1));
ComboBoxInit(GetDlgItem(m_hWnd, IDC_ASPECTRATIO), g_aspectratio, countof(g_aspectratio), theApp.GetConfig("AspectRatio", 1));
ComboBoxInit(GetDlgItem(m_hWnd, IDC_SCALE), g_scale, countof(g_scale), theApp.GetConfig("scale_x", 0) | (theApp.GetConfig("scale_y", 0) << 2));
ComboBoxInit(IDC_RENDERER, &renderers[0], renderers.size(), theApp.GetConfig("Renderer", 0));
ComboBoxInit(IDC_FILTER, g_filter, countof(g_filter), theApp.GetConfig("filter", 0));
ComboBoxInit(IDC_DITHERING, g_dithering, countof(g_dithering), theApp.GetConfig("dithering", 1));
ComboBoxInit(IDC_ASPECTRATIO, g_aspectratio, countof(g_aspectratio), theApp.GetConfig("AspectRatio", 1));
ComboBoxInit(IDC_SCALE, g_scale, countof(g_scale), theApp.GetConfig("scale_x", 0) | (theApp.GetConfig("scale_y", 0) << 2));
SendMessage(GetDlgItem(m_hWnd, IDC_SWTHREADS), UDM_SETRANGE, 0, MAKELPARAM(16, 1));
SendMessage(GetDlgItem(m_hWnd, IDC_SWTHREADS), UDM_SETPOS, 0, MAKELPARAM(theApp.GetConfig("swthreads", 1), 0));
@ -139,7 +137,7 @@ bool GPUSettingsDlg::OnCommand(HWND hWnd, UINT id, UINT code)
{
INT_PTR data;
if(ComboBoxGetSelData(GetDlgItem(m_hWnd, IDC_RESOLUTION), data))
if(ComboBoxGetSelData(IDC_RESOLUTION, data))
{
const D3DDISPLAYMODE* mode = (D3DDISPLAYMODE*)data;
@ -148,27 +146,27 @@ bool GPUSettingsDlg::OnCommand(HWND hWnd, UINT id, UINT code)
theApp.SetConfig("ModeRefreshRate", (int)mode->RefreshRate);
}
if(ComboBoxGetSelData(GetDlgItem(m_hWnd, IDC_RENDERER), data))
if(ComboBoxGetSelData(IDC_RENDERER, data))
{
theApp.SetConfig("Renderer", (int)data);
}
if(ComboBoxGetSelData(GetDlgItem(m_hWnd, IDC_FILTER), data))
if(ComboBoxGetSelData(IDC_FILTER, data))
{
theApp.SetConfig("filter", (int)data);
}
if(ComboBoxGetSelData(GetDlgItem(m_hWnd, IDC_DITHERING), data))
if(ComboBoxGetSelData(IDC_DITHERING, data))
{
theApp.SetConfig("dithering", (int)data);
}
if(ComboBoxGetSelData(GetDlgItem(m_hWnd, IDC_ASPECTRATIO), data))
if(ComboBoxGetSelData(IDC_ASPECTRATIO, data))
{
theApp.SetConfig("AspectRatio", (int)data);
}
if(ComboBoxGetSelData(GetDlgItem(m_hWnd, IDC_SCALE), data))
if(ComboBoxGetSelData(IDC_SCALE, data))
{
theApp.SetConfig("scale_x", data & 3);
theApp.SetConfig("scale_y", (data >> 2) & 3);
@ -184,7 +182,7 @@ void GPUSettingsDlg::UpdateControls()
{
INT_PTR i;
if(ComboBoxGetSelData(GetDlgItem(m_hWnd, IDC_RENDERER), i))
if(ComboBoxGetSelData(IDC_RENDERER, i))
{
bool dx9 = i == 1;
bool dx10 = i == 2;

View File

@ -35,7 +35,7 @@ int GSCaptureDlg::GetSelCodec(Codec& c)
{
INT_PTR data = 0;
if(ComboBoxGetSelData(GetDlgItem(m_hWnd, IDC_CODECS), data))
if(ComboBoxGetSelData(IDC_CODECS, data))
{
if(data == 0) return 2;
@ -66,9 +66,7 @@ void GSCaptureDlg::OnInit()
string selected = theApp.GetConfig("CaptureVideoCodecDisplayName", "");
HWND hWnd = GetDlgItem(m_hWnd, IDC_CODECS);
ComboBoxAppend(hWnd, "Uncompressed", 0, true);
ComboBoxAppend(IDC_CODECS, "Uncompressed", 0, true);
BeginEnumSysDev(CLSID_VideoCompressorCategory, moniker)
{
@ -107,7 +105,7 @@ void GSCaptureDlg::OnInit()
string s(c.FriendlyName.begin(), c.FriendlyName.end());
ComboBoxAppend(hWnd, s.c_str(), (LPARAM)&m_codecs.back(), s == selected);
ComboBoxAppend(IDC_CODECS, s.c_str(), (LPARAM)&m_codecs.back(), s == selected);
}
EndEnumSysDev
}

View File

@ -123,8 +123,12 @@ void GSDialog::SetTextAsInt(UINT id, int i)
SetText(id, buff);
}
void GSDialog::ComboBoxInit(HWND hWnd, const GSSetting* settings, int count, uint32 selid, uint32 maxid)
void GSDialog::ComboBoxInit(UINT id, const GSSetting* settings, int count, uint32 selid, uint32 maxid)
{
HWND hWnd = GetDlgItem(m_hWnd, id);
SendMessage(hWnd, CB_RESETCONTENT, 0, 0);
for(int i = 0; i < count; i++)
{
if(settings[i].id <= maxid)
@ -136,13 +140,15 @@ void GSDialog::ComboBoxInit(HWND hWnd, const GSSetting* settings, int count, uin
str = str + " (" + settings[i].note + ")";
}
ComboBoxAppend(hWnd, str.c_str(), (LPARAM)settings[i].id, settings[i].id == selid);
ComboBoxAppend(id, str.c_str(), (LPARAM)settings[i].id, settings[i].id == selid);
}
}
}
int GSDialog::ComboBoxAppend(HWND hWnd, const char* str, LPARAM data, bool select)
int GSDialog::ComboBoxAppend(UINT id, const char* str, LPARAM data, bool select)
{
HWND hWnd = GetDlgItem(m_hWnd, id);
int item = (int)SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)str);
SendMessage(hWnd, CB_SETITEMDATA, item, (LPARAM)data);
@ -155,8 +161,10 @@ int GSDialog::ComboBoxAppend(HWND hWnd, const char* str, LPARAM data, bool selec
return item;
}
bool GSDialog::ComboBoxGetSelData(HWND hWnd, INT_PTR& data)
bool GSDialog::ComboBoxGetSelData(UINT id, INT_PTR& data)
{
HWND hWnd = GetDlgItem(m_hWnd, id);
int item = SendMessage(hWnd, CB_GETCURSEL, 0, 0);
if(item >= 0)

View File

@ -48,7 +48,7 @@ public:
void SetText(UINT id, const char* str);
void SetTextAsInt(UINT id, int i);
static void ComboBoxInit(HWND hWnd, const GSSetting* settings, int count, uint32 selid, uint32 maxid = ~0);
static int ComboBoxAppend(HWND hWnd, const char* str, LPARAM data = 0, bool select = false);
static bool ComboBoxGetSelData(HWND hWnd, INT_PTR& data);
void ComboBoxInit(UINT id, const GSSetting* settings, int count, uint32 selid, uint32 maxid = ~0);
int ComboBoxAppend(UINT id, const char* str, LPARAM data = 0, bool select = false);
bool ComboBoxGetSelData(UINT id, INT_PTR& data);
};

View File

@ -76,9 +76,7 @@ void GSSettingsDlg::OnInit()
memset(&mode, 0, sizeof(mode));
m_modes.push_back(mode);
HWND hWnd = GetDlgItem(m_hWnd, IDC_RESOLUTION);
ComboBoxAppend(hWnd, "Windowed", (LPARAM)&m_modes.back(), true);
ComboBoxAppend(IDC_RESOLUTION, "Windowed", (LPARAM)&m_modes.back(), true);
if(CComPtr<IDirect3D9> d3d = Direct3DCreate9(D3D_SDK_VERSION))
{
@ -96,7 +94,7 @@ void GSSettingsDlg::OnInit()
string str = format("%dx%d %dHz", mode.Width, mode.Height, mode.RefreshRate);
ComboBoxAppend(hWnd, str.c_str(), (LPARAM)&m_modes.back(), w == mode.Width && h == mode.Height && hz == mode.RefreshRate);
ComboBoxAppend(IDC_RESOLUTION, str.c_str(), (LPARAM)&m_modes.back(), w == mode.Width && h == mode.Height && hz == mode.RefreshRate);
}
}
}
@ -113,9 +111,9 @@ void GSSettingsDlg::OnInit()
renderers.push_back(g_renderers[i]);
}
ComboBoxInit(GetDlgItem(m_hWnd, IDC_RENDERER), &renderers[0], renderers.size(), theApp.GetConfig("Renderer", 0));
ComboBoxInit(GetDlgItem(m_hWnd, IDC_INTERLACE), g_interlace, countof(g_interlace), theApp.GetConfig("Interlace", 0));
ComboBoxInit(GetDlgItem(m_hWnd, IDC_ASPECTRATIO), g_aspectratio, countof(g_aspectratio), theApp.GetConfig("AspectRatio", 1));
ComboBoxInit(IDC_RENDERER, &renderers[0], renderers.size(), theApp.GetConfig("Renderer", 0));
ComboBoxInit(IDC_INTERLACE, g_interlace, countof(g_interlace), theApp.GetConfig("Interlace", 0));
ComboBoxInit(IDC_ASPECTRATIO, g_aspectratio, countof(g_aspectratio), theApp.GetConfig("AspectRatio", 1));
CheckDlgButton(m_hWnd, IDC_FILTER, theApp.GetConfig("filter", 1));
CheckDlgButton(m_hWnd, IDC_VSYNC, theApp.GetConfig("vsync", 0));
@ -151,7 +149,7 @@ bool GSSettingsDlg::OnCommand(HWND hWnd, UINT id, UINT code)
{
INT_PTR data;
if(ComboBoxGetSelData(GetDlgItem(m_hWnd, IDC_RESOLUTION), data))
if(ComboBoxGetSelData(IDC_RESOLUTION, data))
{
const D3DDISPLAYMODE* mode = (D3DDISPLAYMODE*)data;
@ -160,17 +158,17 @@ bool GSSettingsDlg::OnCommand(HWND hWnd, UINT id, UINT code)
theApp.SetConfig("ModeRefreshRate", (int)mode->RefreshRate);
}
if(ComboBoxGetSelData(GetDlgItem(m_hWnd, IDC_RENDERER), data))
if(ComboBoxGetSelData(IDC_RENDERER, data))
{
theApp.SetConfig("Renderer", (int)data);
}
if(ComboBoxGetSelData(GetDlgItem(m_hWnd, IDC_INTERLACE), data))
if(ComboBoxGetSelData(IDC_INTERLACE, data))
{
theApp.SetConfig("Interlace", (int)data);
}
if(ComboBoxGetSelData(GetDlgItem(m_hWnd, IDC_ASPECTRATIO), data))
if(ComboBoxGetSelData(IDC_ASPECTRATIO, data))
{
theApp.SetConfig("AspectRatio", (int)data);
}
@ -195,7 +193,7 @@ void GSSettingsDlg::UpdateControls()
{
INT_PTR i;
if(ComboBoxGetSelData(GetDlgItem(m_hWnd, IDC_RENDERER), i))
if(ComboBoxGetSelData(IDC_RENDERER, i))
{
bool dx9 = i >= 0 && i <= 2;
bool dx10 = i >= 3 && i <= 5;