1
/***************************************************************************
3
M.A.M.E.UI - Multiple Arcade Machine Emulator with User Interface
4
Win32 Portions Copyright (C) 1997-2003 Michael Soderstrom and Chris Kirmse,
5
Copyright (C) 2003-2007 Chris Kirmse and the MAME32/MAMEUI team.
7
This file is part of MAMEUI, and may only be used, modified and
8
distributed under the terms of the MAME license, in "readme.txt".
9
By continuing to use, modify or distribute this file you indicate
10
that you have read the license and understand and accept it fully.
12
***************************************************************************/
14
/***************************************************************************
18
***************************************************************************/
20
// standard windows headers
21
#define WIN32_LEAN_AND_MEAN
32
// MAME/MAMEUI headers
34
#include "sound/samples.h"
43
/***************************************************************************
45
***************************************************************************/
47
/***************************************************************************
49
***************************************************************************/
51
/***************************************************************************
53
***************************************************************************/
54
static struct DriversInfo
68
BOOL supportsSaveState;
70
} *drivers_info = NULL;
73
/***************************************************************************
75
***************************************************************************/
80
void __cdecl ErrorMsg(const char* fmt, ...)
82
static FILE* pFile = NULL;
90
vsprintf(buf, fmt, va);
92
win_message_box_utf8(GetActiveWindow(), buf, MAMEUINAME, MB_OK | MB_ICONERROR);
94
strcpy(buf2, MAMEUINAME ": ");
98
WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), buf2, strlen(buf2), &dwWritten, NULL);
101
pFile = fopen("debug.txt", "wt");
105
fprintf(pFile, "%s", buf2);
112
void __cdecl dprintf(const char* fmt, ...)
119
_vsnprintf(buf,sizeof(buf),fmt,va);
121
win_output_debug_string_utf8(buf);
126
UINT GetDepth(HWND hWnd)
133
nBPP = GetDeviceCaps(hDC, BITSPIXEL) * GetDeviceCaps(hDC, PLANES);
135
ReleaseDC(hWnd, hDC);
141
* Return TRUE if comctl32.dll is version 4.71 or greater
142
* otherwise return FALSE.
144
LONG GetCommonControlVersion()
146
HMODULE hModule = GetModuleHandle(TEXT("comctl32"));
150
FARPROC lpfnICCE = GetProcAddress(hModule, "InitCommonControlsEx");
152
if (NULL != lpfnICCE)
154
FARPROC lpfnDLLI = GetProcAddress(hModule, "DllInstall");
156
if (NULL != lpfnDLLI)
158
/* comctl 4.71 or greater */
160
// see if we can find out exactly
162
DLLGETVERSIONPROC pDllGetVersion;
163
pDllGetVersion = (DLLGETVERSIONPROC)GetProcAddress(hModule, "DllGetVersion");
165
/* Because some DLLs might not implement this function, you
166
must test for it explicitly. Depending on the particular
167
DLL, the lack of a DllGetVersion function can be a useful
168
indicator of the version. */
175
ZeroMemory(&dvi, sizeof(dvi));
176
dvi.cbSize = sizeof(dvi);
178
hr = (*pDllGetVersion)(&dvi);
182
return PACKVERSION(dvi.dwMajorVersion, dvi.dwMinorVersion);
185
return PACKVERSION(4,71);
187
return PACKVERSION(4,7);
189
return PACKVERSION(4,0);
192
return PACKVERSION(0,0);
195
void DisplayTextFile(HWND hWnd, const char *cName)
201
tName = tstring_from_utf8(cName);
205
hErr = ShellExecute(hWnd, NULL, tName, NULL, NULL, SW_SHOWNORMAL);
215
msg = TEXT("The operating system is out of memory or resources.");
218
case ERROR_FILE_NOT_FOUND:
219
msg = TEXT("The specified file was not found.");
222
case SE_ERR_NOASSOC :
223
msg = TEXT("There is no application associated with the given filename extension.");
227
msg = TEXT("There was not enough memory to complete the operation.");
231
msg = TEXT("The specified path was not found.");
235
msg = TEXT("A sharing violation occurred.");
239
msg = TEXT("Unknown error.");
242
MessageBox(NULL, msg, tName, MB_OK);
247
char* MyStrStrI(const char* pFirst, const char* pSrch)
249
char* cp = (char*)pFirst;
258
while (*s1 && *s2 && !mame_strnicmp(s1, s2, 1))
269
char * ConvertToWindowsNewlines(const char *source)
271
static char buf[1024 * 1024];
290
/* Lop off path and extention from a source file name
291
* This assumes their is a pathname passed to the function
292
* like src\drivers\blah.c
294
const char * GetDriverFilename(int nIndex)
299
const char *s = driver_list::driver(nIndex).source_file;
303
ptmp = strrchr(s, '\\');
305
ptmp = strrchr(s, '/');
309
ptmp2 = strrchr(ptmp, '/');
322
BOOL isDriverVector(const machine_config *config)
324
const screen_device *screen = config->first_screen();
326
if (screen != NULL) {
327
// parse "vector.ini" for vector games
328
if (SCREEN_TYPE_VECTOR == screen->screen_type())
336
int numberOfScreens(const machine_config *config)
338
const screen_device *screen = config->first_screen();
340
for (; screen != NULL; screen = screen->next_screen()) {
348
int numberOfSpeakers(const machine_config *config)
350
return config->devicelist().count(SPEAKER);
353
static struct DriversInfo* GetDriversInfo(int driver_index)
355
if (drivers_info == NULL)
358
drivers_info = (DriversInfo*)malloc(sizeof(struct DriversInfo) * driver_list::total());
359
for (ndriver = 0; ndriver < driver_list::total(); ndriver++)
361
const game_driver *gamedrv = &driver_list::driver(ndriver);
362
struct DriversInfo *gameinfo = &drivers_info[ndriver];
363
const rom_entry *region, *rom;
364
machine_config config(*gamedrv, MameUIGlobal());
365
const rom_source *source;
368
gameinfo->isClone = (GetParentRomSetIndex(gamedrv) != -1);
369
gameinfo->isBroken = ((gamedrv->flags & GAME_NOT_WORKING) != 0);
370
gameinfo->supportsSaveState = ((gamedrv->flags & GAME_SUPPORTS_SAVE) != 0);
371
gameinfo->isHarddisk = FALSE;
372
gameinfo->isVertical = (gamedrv->flags & ORIENTATION_SWAP_XY) ? TRUE : FALSE;
373
for (source = rom_first_source(config); source != NULL; source = rom_next_source(*source))
375
for (region = rom_first_region(*source); region; region = rom_next_region(region))
377
if (ROMREGION_ISDISKDATA(region))
378
gameinfo->isHarddisk = TRUE;
381
gameinfo->hasOptionalBIOS = FALSE;
382
if (gamedrv->rom != NULL)
384
for (rom = gamedrv->rom; !ROMENTRY_ISEND(rom); rom++)
386
if (ROMENTRY_ISSYSTEM_BIOS(rom))
388
gameinfo->hasOptionalBIOS = TRUE;
394
num_speakers = numberOfSpeakers(&config);
396
gameinfo->isStereo = (num_speakers > 1);
397
gameinfo->screenCount = numberOfScreens(&config);
398
gameinfo->isVector = isDriverVector(&config); // ((drv.video_attributes & VIDEO_TYPE_VECTOR) != 0);
399
gameinfo->usesRoms = FALSE;
400
for (source = rom_first_source(config); source != NULL; source = rom_next_source(*source))
402
for (region = rom_first_region(*source); region; region = rom_next_region(region))
404
for (rom = rom_first_file(region); rom; rom = rom_next_file(rom))
406
gameinfo->usesRoms = TRUE;
411
gameinfo->usesSamples = FALSE;
414
const device_sound_interface *sound = NULL;
415
const char * const * samplenames = NULL;
416
for (bool gotone = config.devicelist().first(sound); gotone; gotone = sound->next(sound)) {
417
if (sound->device().type() == SAMPLES)
419
const samples_interface *intf = (const samples_interface *)sound->device().static_config();
420
samplenames = intf->samplenames;
422
if (samplenames != 0 && samplenames[0] != 0)
424
gameinfo->usesSamples = TRUE;
431
gameinfo->usesTrackball = FALSE;
432
gameinfo->usesLightGun = FALSE;
433
if (gamedrv->ipt != NULL)
435
input_port_config *port;
436
ioport_list portlist;
438
for (device_t *cfg = config.devicelist().first(); cfg != NULL; cfg = cfg->next())
440
if (cfg->input_ports()!=NULL) {
441
input_port_list_init(*cfg, portlist, errors);
445
for (port = portlist.first(); port != NULL; port = port->next())
447
input_field_config *field;
448
for (field = port->fieldlist().first(); field != NULL; field = field->next())
454
if (type == IPT_DIAL || type == IPT_PADDLE ||
455
type == IPT_TRACKBALL_X || type == IPT_TRACKBALL_Y ||
456
type == IPT_AD_STICK_X || type == IPT_AD_STICK_Y)
457
gameinfo->usesTrackball = TRUE;
458
if (type == IPT_LIGHTGUN_X || type == IPT_LIGHTGUN_Y)
459
gameinfo->usesLightGun = TRUE;
460
if (type == IPT_MOUSE_X || type == IPT_MOUSE_Y)
461
gameinfo->usesMouse = TRUE;
467
return &drivers_info[driver_index];
470
BOOL DriverIsClone(int driver_index)
472
return GetDriversInfo(driver_index)->isClone;
475
BOOL DriverIsBroken(int driver_index)
477
return GetDriversInfo(driver_index)->isBroken;
480
BOOL DriverIsHarddisk(int driver_index)
482
return GetDriversInfo(driver_index)->isHarddisk;
485
BOOL DriverIsBios(int driver_index)
488
if( !( (driver_list::driver(driver_index).flags & GAME_IS_BIOS_ROOT ) == 0) )
493
BOOL DriverIsMechanical(int driver_index)
495
BOOL bMechanical = FALSE;
496
if( !( (driver_list::driver(driver_index).flags & GAME_MECHANICAL ) == 0) )
501
BOOL DriverHasOptionalBIOS(int driver_index)
503
return GetDriversInfo(driver_index)->hasOptionalBIOS;
506
BOOL DriverIsStereo(int driver_index)
508
return GetDriversInfo(driver_index)->isStereo;
511
int DriverNumScreens(int driver_index)
513
return GetDriversInfo(driver_index)->screenCount;
516
BOOL DriverIsVector(int driver_index)
518
return GetDriversInfo(driver_index)->isVector;
521
BOOL DriverUsesRoms(int driver_index)
523
return GetDriversInfo(driver_index)->usesRoms;
526
BOOL DriverUsesSamples(int driver_index)
528
return GetDriversInfo(driver_index)->usesSamples;
531
BOOL DriverUsesTrackball(int driver_index)
533
return GetDriversInfo(driver_index)->usesTrackball;
536
BOOL DriverUsesLightGun(int driver_index)
538
return GetDriversInfo(driver_index)->usesLightGun;
541
BOOL DriverUsesMouse(int driver_index)
543
return GetDriversInfo(driver_index)->usesMouse;
546
BOOL DriverSupportsSaveState(int driver_index)
548
return GetDriversInfo(driver_index)->supportsSaveState;
551
BOOL DriverIsVertical(int driver_index) {
552
return GetDriversInfo(driver_index)->isVertical;
555
void FlushFileCaches(void)
557
zip_file_cache_clear();
560
BOOL StringIsSuffixedBy(const char *s, const char *suffix)
562
return (strlen(s) > strlen(suffix)) && (strcmp(s + strlen(s) - strlen(suffix), suffix) == 0);
565
/***************************************************************************
567
***************************************************************************/
569
BOOL SafeIsAppThemed(void)
571
BOOL bResult = FALSE;
573
BOOL (WINAPI *pfnIsAppThemed)(void);
575
hThemes = LoadLibrary(TEXT("uxtheme.dll"));
578
pfnIsAppThemed = (BOOL (WINAPI *)(void)) GetProcAddress(hThemes, "IsAppThemed");
579
if (pfnIsAppThemed != NULL)
580
bResult = pfnIsAppThemed();
581
FreeLibrary(hThemes);
588
void GetSystemErrorMessage(DWORD dwErrorId, TCHAR **tErrorMessage)
590
if( FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwErrorId, 0, (LPTSTR)tErrorMessage, 0, NULL) == 0 )
592
*tErrorMessage = (LPTSTR)LocalAlloc(LPTR, MAX_PATH * sizeof(TCHAR));
593
_tcscpy(*tErrorMessage, TEXT("Unknown Error"));
598
//============================================================
599
// win_extract_icon_utf8
600
//============================================================
602
HICON win_extract_icon_utf8(HINSTANCE inst, const char* exefilename, UINT iconindex)
605
TCHAR* t_exefilename = tstring_from_utf8(exefilename);
609
icon = ExtractIcon(inst, t_exefilename, iconindex);
611
osd_free(t_exefilename);
618
//============================================================
619
// win_tstring_strdup
620
//============================================================
622
TCHAR* win_tstring_strdup(LPCTSTR str)
627
cpy = (TCHAR*)osd_malloc((_tcslen(str) + 1) * sizeof(TCHAR));
634
//============================================================
635
// win_create_file_utf8
636
//============================================================
638
HANDLE win_create_file_utf8(const char* filename, DWORD desiredmode, DWORD sharemode,
639
LPSECURITY_ATTRIBUTES securityattributes, DWORD creationdisposition,
640
DWORD flagsandattributes, HANDLE templatehandle)
643
TCHAR* t_filename = tstring_from_utf8(filename);
647
result = CreateFile(t_filename, desiredmode, sharemode, securityattributes, creationdisposition,
648
flagsandattributes, templatehandle);
650
osd_free(t_filename);
655
//============================================================
656
// win_get_current_directory_utf8
657
//============================================================
659
DWORD win_get_current_directory_utf8(DWORD bufferlength, char* buffer)
662
TCHAR* t_buffer = NULL;
663
char* utf8_buffer = NULL;
665
if( bufferlength > 0 ) {
666
t_buffer = (TCHAR*)malloc((bufferlength * sizeof(TCHAR)) + 1);
671
result = GetCurrentDirectory(bufferlength, t_buffer);
673
if( bufferlength > 0 ) {
674
utf8_buffer = utf8_from_tstring(t_buffer);
681
strncpy(buffer, utf8_buffer, bufferlength);
684
osd_free(utf8_buffer);
692
//============================================================
693
// win_find_first_file_utf8
694
//============================================================
696
HANDLE win_find_first_file_utf8(const char* filename, LPWIN32_FIND_DATA findfiledata)
699
TCHAR* t_filename = tstring_from_utf8(filename);
703
result = FindFirstFile(t_filename, findfiledata);
705
osd_free(t_filename);