diff options
Diffstat (limited to 'docs/release/src/osd/winui/mui_util.cpp')
-rw-r--r-- | docs/release/src/osd/winui/mui_util.cpp | 369 |
1 files changed, 234 insertions, 135 deletions
diff --git a/docs/release/src/osd/winui/mui_util.cpp b/docs/release/src/osd/winui/mui_util.cpp index abb45522b1b..4ea23955d08 100644 --- a/docs/release/src/osd/winui/mui_util.cpp +++ b/docs/release/src/osd/winui/mui_util.cpp @@ -4,7 +4,7 @@ /*************************************************************************** - mui_util.c + mui_util.cpp ***************************************************************************/ @@ -13,7 +13,6 @@ #include <shellapi.h> // standard C headers -#include <stdio.h> #include <tchar.h> // MAME/MAMEUI headers @@ -23,7 +22,6 @@ #include "unzip.h" #include "sound/samples.h" #include "winutf8.h" -#include "strconv.h" #include "winui.h" #include "mui_util.h" #include "mui_opts.h" @@ -31,7 +29,6 @@ #include "machine/ram.h" #include <shlwapi.h> -#include <vector> /*************************************************************************** function prototypes @@ -63,7 +60,8 @@ struct DriversInfo bool hasRam; }; -static std::vector<DriversInfo> drivers_info; +static std::vector<DriversInfo> drivers_info; +static bool bFirst = true; enum @@ -91,11 +89,11 @@ enum */ void __cdecl ErrorMsg(const char* fmt, ...) { - static FILE* pFile = NULL; - DWORD dwWritten; - char buf[5000]; - char buf2[5000]; - va_list va; + static FILE* pFile = NULL; + DWORD dwWritten; + char buf[5000]; + char buf2[5000]; + va_list va; va_start(va, fmt); @@ -123,7 +121,7 @@ void __cdecl ErrorMsg(const char* fmt, ...) void __cdecl dprintf(const char* fmt, ...) { - char buf[5000]; + char buf[5000]; va_list va; va_start(va, fmt); @@ -135,10 +133,96 @@ void __cdecl dprintf(const char* fmt, ...) va_end(va); } +//============================================================ +// winui_message_box_utf8 +//============================================================ + +int winui_message_box_utf8(HWND hWnd, const char *text, const char *caption, UINT type) +{ + int result = IDCANCEL; + wchar_t *t_text = ui_wstring_from_utf8(text); + wchar_t *t_caption = ui_wstring_from_utf8(caption); + + if (!t_text) + return result; + + if (!t_caption) + { + free(t_text); + return result; + } + + result = MessageBox(hWnd, t_text, t_caption, type); + free(t_text); + free(t_caption); + return result; +} + +void ErrorMessageBox(const char *fmt, ...) +{ + char buf[1024]; + va_list ptr; + + va_start(ptr, fmt); + vsnprintf(buf, ARRAY_LENGTH(buf), fmt, ptr); + winui_message_box_utf8(GetMainWindow(), buf, MAMEUINAME, MB_ICONERROR | MB_OK); + va_end(ptr); +} + +void ShellExecuteCommon(HWND hWnd, const char *cName) +{ + wchar_t *tName = ui_wstring_from_utf8(cName); + + if(!tName) + return; + + HINSTANCE hErr = ShellExecute(hWnd, NULL, tName, NULL, NULL, SW_SHOWNORMAL); + + if ((uintptr_t)hErr > 32) + { + free(tName); + return; + } + + const char *msg = NULL; + switch((uintptr_t)hErr) + { + case 0: + msg = "The Operating System is out of memory or resources."; + break; + + case ERROR_FILE_NOT_FOUND: + msg = "The specified file was not found."; + break; + + case SE_ERR_NOASSOC : + msg = "There is no application associated with the given filename extension."; + break; + + case SE_ERR_OOM : + msg = "There was not enough memory to complete the operation."; + break; + + case SE_ERR_PNF : + msg = "The specified path was not found."; + break; + + case SE_ERR_SHARE : + msg = "A sharing violation occurred."; + break; + + default: + msg = "Unknown error."; + } + + ErrorMessageBox("%s\r\nPath: '%s'", msg, cName); + free(tName); +} + UINT GetDepth(HWND hWnd) { - UINT nBPP; - HDC hDC; + UINT nBPP; + HDC hDC; hDC = GetDC(hWnd); @@ -150,8 +234,8 @@ UINT GetDepth(HWND hWnd) } /* - * Return TRUE if comctl32.dll is version 4.71 or greater - * otherwise return FALSE. + * Return true if comctl32.dll is version 4.71 or greater + * otherwise return false. */ LONG GetCommonControlVersion() { @@ -206,21 +290,18 @@ LONG GetCommonControlVersion() void DisplayTextFile(HWND hWnd, const char *cName) { - HINSTANCE hErr; - LPCTSTR msg = 0; - LPTSTR tName; - - tName = ui_wstring_from_utf8(cName); + LPTSTR tName = ui_wstring_from_utf8(cName); if( !tName ) return; - hErr = ShellExecute(hWnd, NULL, tName, NULL, NULL, SW_SHOWNORMAL); + HINSTANCE hErr = ShellExecute(hWnd, NULL, tName, NULL, NULL, SW_SHOWNORMAL); if ((uintptr_t)hErr > 32) { free(tName); return; } + LPCTSTR msg = 0; switch((uintptr_t)hErr) { case 0: @@ -303,10 +384,10 @@ char * ConvertToWindowsNewlines(const char *source) * This assumes their is a pathname passed to the function * like src\drivers\blah.c */ -const char * GetDriverFilename(int nIndex) +const char * GetDriverFilename(uint32_t nIndex) { static char tmp[40]; - std::string driver = core_filename_extract_base(driver_list::driver(nIndex).source_file); + std::string driver = core_filename_extract_base(driver_list::driver(nIndex).type.source()); strcpy(tmp, driver.c_str()); return tmp; } @@ -316,11 +397,10 @@ BOOL isDriverVector(const machine_config *config) const screen_device *screen = config->first_screen(); if (screen) - { if (SCREEN_TYPE_VECTOR == screen->screen_type()) - return TRUE; - } - return FALSE; + return true; + + return false; } int numberOfScreens(const machine_config *config) @@ -337,26 +417,47 @@ int numberOfSpeakers(const machine_config *config) static void SetDriversInfo(void) { - int ndriver; - int cache = -1; - int total = driver_list::total(); + uint32_t cache; + uint32_t total = driver_list::total(); struct DriversInfo *gameinfo = NULL; - for (ndriver = 0; ndriver < total; ndriver++) + for (uint32_t ndriver = 0; ndriver < total; ndriver++) { gameinfo = &drivers_info[ndriver]; - cache = (gameinfo->screenCount & DRIVER_CACHE_SCREEN); - if (gameinfo->isClone) cache += DRIVER_CACHE_CLONE; - if (gameinfo->isHarddisk) cache += DRIVER_CACHE_HARDDISK; - if (gameinfo->hasOptionalBIOS) cache += DRIVER_CACHE_BIOS; - if (gameinfo->isStereo) cache += DRIVER_CACHE_STEREO; - if (gameinfo->isVector) cache += DRIVER_CACHE_VECTOR; - if (gameinfo->usesRoms) cache += DRIVER_CACHE_ROMS; - if (gameinfo->usesSamples) cache += DRIVER_CACHE_SAMPLES; - if (gameinfo->usesTrackball) cache += DRIVER_CACHE_TRACKBALL; - if (gameinfo->usesLightGun) cache += DRIVER_CACHE_LIGHTGUN; - if (gameinfo->usesMouse) cache += DRIVER_CACHE_MOUSE; - if (gameinfo->hasRam) cache += DRIVER_CACHE_RAM; + cache = gameinfo->screenCount & DRIVER_CACHE_SCREEN; + + if (gameinfo->isClone) + cache += DRIVER_CACHE_CLONE; + + if (gameinfo->isHarddisk) + cache += DRIVER_CACHE_HARDDISK; + + if (gameinfo->hasOptionalBIOS) + cache += DRIVER_CACHE_BIOS; + + if (gameinfo->isStereo) + cache += DRIVER_CACHE_STEREO; + + if (gameinfo->isVector) + cache += DRIVER_CACHE_VECTOR; + + if (gameinfo->usesRoms) + cache += DRIVER_CACHE_ROMS; + + if (gameinfo->usesSamples) + cache += DRIVER_CACHE_SAMPLES; + + if (gameinfo->usesTrackball) + cache += DRIVER_CACHE_TRACKBALL; + + if (gameinfo->usesLightGun) + cache += DRIVER_CACHE_LIGHTGUN; + + if (gameinfo->usesMouse) + cache += DRIVER_CACHE_MOUSE; + + if (gameinfo->hasRam) + cache += DRIVER_CACHE_RAM; SetDriverCache(ndriver, cache); } @@ -364,24 +465,27 @@ static void SetDriversInfo(void) static void InitDriversInfo(void) { - int ndriver; + printf("InitDriversInfo: A\n");fflush(stdout); int num_speakers; - int total = driver_list::total(); + uint32_t total = driver_list::total(); const game_driver *gamedrv = NULL; struct DriversInfo *gameinfo = NULL; const rom_entry *region, *rom; - for (ndriver = 0; ndriver < total; ndriver++) + for (uint32_t ndriver = 0; ndriver < total; ndriver++) { + uint32_t cache = GetDriverCacheLower(ndriver); gamedrv = &driver_list::driver(ndriver); gameinfo = &drivers_info[ndriver]; machine_config config(*gamedrv, MameUIGlobal()); - gameinfo->isClone = (GetParentRomSetIndex(gamedrv) != -1); - gameinfo->isBroken = (gamedrv->flags & (MACHINE_NOT_WORKING | MACHINE_UNEMULATED_PROTECTION | MACHINE_MECHANICAL)) ? true : false; - gameinfo->supportsSaveState = ((gamedrv->flags & MACHINE_SUPPORTS_SAVE) != 0); - gameinfo->isHarddisk = FALSE; - gameinfo->isVertical = (gamedrv->flags & ORIENTATION_SWAP_XY) ? TRUE : FALSE; + bool const have_parent(strcmp(gamedrv->parent, "0")); + auto const parent_idx(have_parent ? driver_list::find(gamedrv->parent) : -1); + gameinfo->isClone = ( !have_parent || (0 > parent_idx) || BIT(GetDriverCacheLower(parent_idx),9)) ? false : true; + gameinfo->isBroken = (cache & 0x4040) ? true : false; // (MACHINE_NOT_WORKING | MACHINE_MECHANICAL) + gameinfo->supportsSaveState = BIT(cache, 7) ^ 1; //MACHINE_SUPPORTS_SAVE + gameinfo->isHarddisk = false; + gameinfo->isVertical = BIT(cache, 2); //ORIENTATION_SWAP_XY ram_device_iterator iter1(config.root_device()); gameinfo->hasRam = (iter1.first() ); @@ -389,15 +493,15 @@ static void InitDriversInfo(void) for (device_t &device : device_iterator(config.root_device())) for (region = rom_first_region(device); region; region = rom_next_region(region)) if (ROMREGION_ISDISKDATA(region)) - gameinfo->isHarddisk = TRUE; + gameinfo->isHarddisk = true; - gameinfo->hasOptionalBIOS = FALSE; + gameinfo->hasOptionalBIOS = false; if (gamedrv->rom) { auto rom_entries = rom_build_entries(gamedrv->rom); for (rom = rom_entries.data(); !ROMENTRY_ISEND(rom); rom++) if (ROMENTRY_ISSYSTEM_BIOS(rom)) - gameinfo->hasOptionalBIOS = TRUE; + gameinfo->hasOptionalBIOS = true; } num_speakers = numberOfSpeakers(&config); @@ -405,20 +509,19 @@ static void InitDriversInfo(void) gameinfo->isStereo = (num_speakers > 1); gameinfo->screenCount = numberOfScreens(&config); gameinfo->isVector = isDriverVector(&config); // ((drv.video_attributes & VIDEO_TYPE_VECTOR) != 0); - gameinfo->usesRoms = FALSE; + gameinfo->usesRoms = false; for (device_t &device : device_iterator(config.root_device())) for (region = rom_first_region(device); region; region = rom_next_region(region)) for (rom = rom_first_file(region); rom; rom = rom_next_file(rom)) - gameinfo->usesRoms = TRUE; - - gameinfo->usesSamples = FALSE; + gameinfo->usesRoms = true; samples_device_iterator iter(config.root_device()); - if (iter.first()) - gameinfo->usesSamples = TRUE; + gameinfo->usesSamples = iter.count() ? true : false; + + gameinfo->usesTrackball = false; + gameinfo->usesLightGun = false; + gameinfo->usesMouse = false; - gameinfo->usesTrackball = FALSE; - gameinfo->usesLightGun = FALSE; if (gamedrv->ipt) { ioport_list portlist; @@ -435,171 +538,166 @@ static void InitDriversInfo(void) type = field.type(); if (type == IPT_END) break; - if (type == IPT_DIAL || type == IPT_PADDLE || - type == IPT_TRACKBALL_X || type == IPT_TRACKBALL_Y || - type == IPT_AD_STICK_X || type == IPT_AD_STICK_Y) - gameinfo->usesTrackball = TRUE; + if (type == IPT_DIAL || type == IPT_PADDLE || type == IPT_TRACKBALL_X || type == IPT_TRACKBALL_Y || type == IPT_AD_STICK_X || type == IPT_AD_STICK_Y) + gameinfo->usesTrackball = true; if (type == IPT_LIGHTGUN_X || type == IPT_LIGHTGUN_Y) - gameinfo->usesLightGun = TRUE; + gameinfo->usesLightGun = true; if (type == IPT_MOUSE_X || type == IPT_MOUSE_Y) - gameinfo->usesMouse = TRUE; + gameinfo->usesMouse = true; } } } } SetDriversInfo(); + printf("InitDriversInfo: Finished\n");fflush(stdout); } static int InitDriversCache(void) { - int cache = -1; - int total = driver_list::total(); - const game_driver *gamedrv = NULL; - struct DriversInfo *gameinfo = NULL; - int ndriver; - + printf("InitDriversCache: A\n");fflush(stdout); if (RequiredDriverCache()) { + printf("InitDriversCache: B\n");fflush(stdout); InitDriversInfo(); return 0; } - for (ndriver = 0; ndriver < total; ndriver++) + printf("InitDriversCache: C\n");fflush(stdout); + uint32_t cache_lower, cache_upper; + uint32_t total = driver_list::total(); + struct DriversInfo *gameinfo = NULL; + + printf("InitDriversCache: D\n");fflush(stdout); + for (uint32_t ndriver = 0; ndriver < total; ndriver++) { - gamedrv = &driver_list::driver(ndriver); gameinfo = &drivers_info[ndriver]; - cache = GetDriverCache(ndriver); - - if (cache == -1) - { - InitDriversInfo(); - break; - } - - gameinfo->isBroken = (gamedrv->flags & (MACHINE_NOT_WORKING | MACHINE_UNEMULATED_PROTECTION | MACHINE_MECHANICAL)) ? true : false; - gameinfo->supportsSaveState = ((gamedrv->flags & MACHINE_SUPPORTS_SAVE) != 0); - gameinfo->isVertical = (gamedrv->flags & ORIENTATION_SWAP_XY) ? TRUE : FALSE; - gameinfo->screenCount = cache & DRIVER_CACHE_SCREEN; - gameinfo->isClone = ((cache & DRIVER_CACHE_CLONE) != 0); - gameinfo->isHarddisk = ((cache & DRIVER_CACHE_HARDDISK) != 0); - gameinfo->hasOptionalBIOS = ((cache & DRIVER_CACHE_BIOS) != 0); - gameinfo->isStereo = ((cache & DRIVER_CACHE_STEREO) != 0); - gameinfo->isVector = ((cache & DRIVER_CACHE_VECTOR) != 0); - gameinfo->usesRoms = ((cache & DRIVER_CACHE_ROMS) != 0); - gameinfo->usesSamples = ((cache & DRIVER_CACHE_SAMPLES) != 0); - gameinfo->usesTrackball = ((cache & DRIVER_CACHE_TRACKBALL) != 0); - gameinfo->usesLightGun = ((cache & DRIVER_CACHE_LIGHTGUN) != 0); - gameinfo->usesMouse = ((cache & DRIVER_CACHE_MOUSE) != 0); - gameinfo->hasRam = ((cache & DRIVER_CACHE_RAM) != 0); + cache_lower = GetDriverCacheLower(ndriver); + cache_upper = GetDriverCacheUpper(ndriver); + + gameinfo->isBroken = (cache_lower & 0x4040) ? true : false; //MACHINE_NOT_WORKING | MACHINE_MECHANICAL + gameinfo->supportsSaveState = BIT(cache_lower, 7) ? false : true; //MACHINE_SUPPORTS_SAVE + gameinfo->isVertical = BIT(cache_lower, 2) ? true : false; //ORIENTATION_XY + gameinfo->screenCount = cache_upper & DRIVER_CACHE_SCREEN; + gameinfo->isClone = ((cache_upper & DRIVER_CACHE_CLONE) != 0); + gameinfo->isHarddisk = ((cache_upper & DRIVER_CACHE_HARDDISK) != 0); + gameinfo->hasOptionalBIOS = ((cache_upper & DRIVER_CACHE_BIOS) != 0); + gameinfo->isStereo = ((cache_upper & DRIVER_CACHE_STEREO) != 0); + gameinfo->isVector = ((cache_upper & DRIVER_CACHE_VECTOR) != 0); + gameinfo->usesRoms = ((cache_upper & DRIVER_CACHE_ROMS) != 0); + gameinfo->usesSamples = ((cache_upper & DRIVER_CACHE_SAMPLES) != 0); + gameinfo->usesTrackball = ((cache_upper & DRIVER_CACHE_TRACKBALL) != 0); + gameinfo->usesLightGun = ((cache_upper & DRIVER_CACHE_LIGHTGUN) != 0); + gameinfo->usesMouse = ((cache_upper & DRIVER_CACHE_MOUSE) != 0); + gameinfo->hasRam = ((cache_upper & DRIVER_CACHE_RAM) != 0); } + printf("InitDriversCache: Finished\n");fflush(stdout); return 0; } -static struct DriversInfo* GetDriversInfo(int driver_index) +static struct DriversInfo* GetDriversInfo(uint32_t driver_index) { - static bool bFirst = true; - if (bFirst) { bFirst = false; drivers_info.clear(); - drivers_info.reserve(driver_list::total()); - + drivers_info.resize(driver_list::total()); + std::fill(drivers_info.begin(), drivers_info.end(), DriversInfo{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); + printf("DriversInfo: B\n");fflush(stdout); InitDriversCache(); } return &drivers_info[driver_index]; } -BOOL DriverIsClone(int driver_index) +BOOL DriverIsClone(uint32_t driver_index) { return GetDriversInfo(driver_index)->isClone; } -BOOL DriverIsBroken(int driver_index) +BOOL DriverIsBroken(uint32_t driver_index) { return GetDriversInfo(driver_index)->isBroken; } -BOOL DriverIsHarddisk(int driver_index) +BOOL DriverIsHarddisk(uint32_t driver_index) { return GetDriversInfo(driver_index)->isHarddisk; } -BOOL DriverIsBios(int driver_index) +BOOL DriverIsBios(uint32_t driver_index) { - return ( driver_list::driver(driver_index).flags & MACHINE_IS_BIOS_ROOT ) ? TRUE : FALSE; + return BIT(GetDriverCacheLower(driver_index), 9); } -BOOL DriverIsMechanical(int driver_index) +BOOL DriverIsMechanical(uint32_t driver_index) { - return ( driver_list::driver(driver_index).flags & MACHINE_MECHANICAL ) ? TRUE : FALSE; + return BIT(GetDriverCacheLower(driver_index), 14); } -BOOL DriverIsArcade(int driver_index) +BOOL DriverIsArcade(uint32_t driver_index) { - return ( driver_list::driver(driver_index).flags & MACHINE_TYPE_ARCADE ) ? TRUE : FALSE; + return ((GetDriverCacheLower(driver_index) & 3) == 0) ? true: false; //TYPE_ARCADE } -BOOL DriverHasOptionalBIOS(int driver_index) +BOOL DriverHasOptionalBIOS(uint32_t driver_index) { return GetDriversInfo(driver_index)->hasOptionalBIOS; } -BOOL DriverIsStereo(int driver_index) +BOOL DriverIsStereo(uint32_t driver_index) { return GetDriversInfo(driver_index)->isStereo; } -int DriverNumScreens(int driver_index) +int DriverNumScreens(uint32_t driver_index) { return GetDriversInfo(driver_index)->screenCount; } -BOOL DriverIsVector(int driver_index) +BOOL DriverIsVector(uint32_t driver_index) { return GetDriversInfo(driver_index)->isVector; } -BOOL DriverUsesRoms(int driver_index) +BOOL DriverUsesRoms(uint32_t driver_index) { return GetDriversInfo(driver_index)->usesRoms; } -BOOL DriverUsesSamples(int driver_index) +BOOL DriverUsesSamples(uint32_t driver_index) { return GetDriversInfo(driver_index)->usesSamples; } -BOOL DriverUsesTrackball(int driver_index) +BOOL DriverUsesTrackball(uint32_t driver_index) { return GetDriversInfo(driver_index)->usesTrackball; } -BOOL DriverUsesLightGun(int driver_index) +BOOL DriverUsesLightGun(uint32_t driver_index) { return GetDriversInfo(driver_index)->usesLightGun; } -BOOL DriverUsesMouse(int driver_index) +BOOL DriverUsesMouse(uint32_t driver_index) { return GetDriversInfo(driver_index)->usesMouse; } -BOOL DriverSupportsSaveState(int driver_index) +BOOL DriverSupportsSaveState(uint32_t driver_index) { return GetDriversInfo(driver_index)->supportsSaveState; } -BOOL DriverIsVertical(int driver_index) +BOOL DriverIsVertical(uint32_t driver_index) { return GetDriversInfo(driver_index)->isVertical; } -BOOL DriverHasRam(int driver_index) +BOOL DriverHasRam(uint32_t driver_index) { return GetDriversInfo(driver_index)->hasRam; } @@ -620,11 +718,10 @@ BOOL StringIsSuffixedBy(const char *s, const char *suffix) BOOL SafeIsAppThemed(void) { - BOOL bResult = FALSE; - HMODULE hThemes; + BOOL bResult = false; BOOL (WINAPI *pfnIsAppThemed)(void); - hThemes = LoadLibrary(TEXT("uxtheme.dll")); + HMODULE hThemes = LoadLibrary(TEXT("uxtheme.dll")); if (hThemes) { pfnIsAppThemed = (BOOL (WINAPI *)(void)) GetProcAddress(hThemes, "IsAppThemed"); @@ -687,9 +784,8 @@ TCHAR* win_tstring_strdup(LPCTSTR str) // win_create_file_utf8 //============================================================ -HANDLE win_create_file_utf8(const char* filename, DWORD desiredmode, DWORD sharemode, - LPSECURITY_ATTRIBUTES securityattributes, DWORD creationdisposition, - DWORD flagsandattributes, HANDLE templatehandle) +HANDLE win_create_file_utf8(const char* filename, DWORD desiredmode, DWORD sharemode, LPSECURITY_ATTRIBUTES securityattributes, + DWORD creationdisposition, DWORD flagsandattributes, HANDLE templatehandle) { HANDLE result = 0; TCHAR* t_filename = ui_wstring_from_utf8(filename); @@ -711,9 +807,9 @@ DWORD win_get_current_directory_utf8(DWORD bufferlength, char* buffer) { DWORD result = 0; TCHAR* t_buffer = NULL; - char* utf8_buffer = NULL; - if( bufferlength > 0 ) { + if( bufferlength > 0 ) + { t_buffer = (TCHAR*)malloc((bufferlength * sizeof(TCHAR)) + 1); if( !t_buffer ) return result; @@ -721,9 +817,12 @@ DWORD win_get_current_directory_utf8(DWORD bufferlength, char* buffer) result = GetCurrentDirectory(bufferlength, t_buffer); - if( bufferlength > 0 ) { + char* utf8_buffer = NULL; + if( bufferlength > 0 ) + { utf8_buffer = ui_utf8_from_wstring(t_buffer); - if( !utf8_buffer ) { + if( !utf8_buffer ) + { free(t_buffer); return result; } |