From: Toni Wilen Date: Sat, 28 May 2016 11:34:36 +0000 (+0300) Subject: Logitech LCD API update. X-Git-Tag: 3300~17 X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=92c1338d5dca7c97fb169eac74d607c6dcaac139;p=francis%2Fwinuae.git Logitech LCD API update. --- diff --git a/od-win32/lcd.cpp b/od-win32/lcd.cpp index 36a82ac6..37a1b426 100644 --- a/od-win32/lcd.cpp +++ b/od-win32/lcd.cpp @@ -8,94 +8,109 @@ #include "gui.h" #include "lcd.h" -#include +#include extern HINSTANCE hInst; static int inited; -static lgLcdConnectContext cctx; -static lgLcdDeviceDescEx desc; -static int device; -static lgLcdBitmapHeader *lbh; static uae_u8 *bitmap, *origbitmap; static uae_u8 *numbers; -static int numbers_width = 7, numbers_height = 10; -static int old_pri; +static int bm_width = LOGI_LCD_MONO_WIDTH; +static int bm_height = LOGI_LCD_MONO_HEIGHT; +static const int numbers_width = 7, numbers_height = 10; +static HMODULE lcdlib; + +extern unsigned long timeframes; + +// Do it this way because stupid LogitechLCDLib.lib LogiLcdInit() refuses to link. + +typedef bool(__cdecl *LOGILCDINIT)(wchar_t*, int); +static LOGILCDINIT pLogiLcdInit; +typedef bool(__cdecl *LOGILCDISCONNECTED)(int); +static LOGILCDISCONNECTED pLogiLcdIsConnected; +typedef bool(__cdecl *LOGILCDSHUTDOWN)(void); +static LOGILCDSHUTDOWN pLogiLcdShutdown; +typedef bool(__cdecl *LOGILCDUPDATE)(void); +static LOGILCDUPDATE pLogiLcdUpdate; +typedef bool(__cdecl *LOGILCDMONOSETBACKGROUND)(BYTE[]); +static LOGILCDMONOSETBACKGROUND pLogiLcdMonoSetBackground; + +#define LOGITECH_LCD_DLL _T("SOFTWARE\\Classes\\CLSID\\{d0e790a5-01a7-49ae-ae0b-e986bdd0c21b}\\ServerBinary") void lcd_close (void) { - lgLcdDeInit (); - xfree (lbh); - lbh = NULL; + if (!lcdlib) + return; + pLogiLcdShutdown(); + xfree(bitmap); bitmap = NULL; + xfree(origbitmap); + origbitmap = NULL; inited = 0; + FreeLibrary(lcdlib); + lcdlib = NULL; } static int lcd_init (void) { - DWORD ret; - lgLcdOpenContext octx; HBITMAP bmp; BITMAP binfo; HDC dc; - int x, y; + TCHAR path[MAX_DPATH]; + DWORD ret; + DWORD type = REG_SZ; + DWORD size = sizeof(path) / sizeof(TCHAR); + HKEY key; - old_pri = 0; - ret = lgLcdInit (); - if (ret != ERROR_SUCCESS) { - if (ret == RPC_S_SERVER_UNAVAILABLE || ret == ERROR_OLD_WIN_VERSION) { - write_log (_T("LCD: Logitech LCD system not detected\n")); - return 0; - } - write_log (_T("LCD: lgLcdInit() returned %d\n"), ret); - return 0; - } - memset (&cctx, 0, sizeof (cctx)); - cctx.appFriendlyName = _T("WinUAE"); - cctx.isPersistent = TRUE; - cctx.isAutostartable = FALSE; - ret = lgLcdConnect (&cctx); - if (ret != ERROR_SUCCESS) { - write_log (_T("LCD: lgLcdConnect() returned %d\n"), ret); - lcd_close (); - return 0; - } - ret = lgLcdEnumerateEx (cctx.connection, 0, &desc); - if (ret != ERROR_SUCCESS) { - write_log (_T("LCD: lgLcdEnumerateEx() returned %d\n"), ret); - lcd_close (); + lcdlib = NULL; + ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, LOGITECH_LCD_DLL, 0, KEY_READ, &key); + if (ret != ERROR_SUCCESS) return 0; + if (RegQueryValueEx(key, NULL, 0, &type, (LPBYTE)path, &size) == ERROR_SUCCESS) { + lcdlib = LoadLibrary(path); } - lbh = (lgLcdBitmapHeader*)xcalloc (uae_u8, sizeof (lgLcdBitmapHeader) + desc.Width * (desc.Height + 20)); - lbh->Format = LGLCD_BMP_FORMAT_160x43x1; - bitmap = (uae_u8*)lbh + sizeof (lgLcdBitmapHeader); - origbitmap = xcalloc (uae_u8, desc.Width * desc.Height); - memset (&octx, 0, sizeof (octx)); - octx.connection = cctx.connection; - octx.index = 0; - ret = lgLcdOpen (&octx); - if (ret != ERROR_SUCCESS) { - write_log (_T("LCD: lgLcdOpen() returned %d\n"), ret); - lcd_close (); + RegCloseKey(key); + if (!lcdlib) return 0; - } - device = octx.device; + + pLogiLcdInit = (LOGILCDINIT)GetProcAddress(lcdlib, "LogiLcdInit"); + pLogiLcdIsConnected = (LOGILCDISCONNECTED)GetProcAddress(lcdlib, "LogiLcdIsConnected"); + pLogiLcdShutdown = (LOGILCDSHUTDOWN)GetProcAddress(lcdlib, "LogiLcdShutdown"); + pLogiLcdUpdate = (LOGILCDUPDATE)GetProcAddress(lcdlib, "LogiLcdUpdate"); + pLogiLcdMonoSetBackground = (LOGILCDMONOSETBACKGROUND)GetProcAddress(lcdlib, "LogiLcdMonoSetBackground"); + if (!pLogiLcdInit || !pLogiLcdIsConnected || !pLogiLcdShutdown || !pLogiLcdUpdate || !pLogiLcdMonoSetBackground) + goto err; + + if (!pLogiLcdInit(_T("WinUAE"), LOGI_LCD_TYPE_MONO)) + goto err; bmp = LoadBitmap (hInst, MAKEINTRESOURCE(IDB_LCD160X43)); dc = CreateCompatibleDC (NULL); SelectObject (dc, bmp); GetObject (bmp, sizeof (binfo), &binfo); - for (y = 0; y < binfo.bmHeight; y++) { - for (x = 0; x < binfo.bmWidth; x++) { + + bitmap = xcalloc(uae_u8, binfo.bmWidth * binfo.bmHeight); + origbitmap = xcalloc(uae_u8, binfo.bmWidth * binfo.bmHeight); + + for (int y = 0; y < binfo.bmHeight; y++) { + for (int x = 0; x < binfo.bmWidth; x++) { bitmap[y * binfo.bmWidth + x] = GetPixel (dc, x, y) == 0 ? 0xff : 0; } } - numbers = bitmap + desc.Width * desc.Height; - memcpy (origbitmap, bitmap, desc.Width * desc.Height); + numbers = bitmap + bm_width * bm_height; + memcpy (origbitmap, bitmap, bm_width * bm_height); DeleteDC (dc); - write_log (_T("LCD: '%s' enabled\n"), desc.deviceDisplayName); + write_log (_T("LCD enabled\n")); return 1; + +err: + write_log(_T("LCD: Logitech LCD failed to initialize\n")); + if (lcdlib) { + FreeLibrary(lcdlib); + lcdlib = NULL; + } + return 0; } static void dorect (int *crd, int inv) @@ -104,10 +119,10 @@ static void dorect (int *crd, int inv) int x = crd[0], y = crd[1], w = crd[2], h = crd[3]; for (yy = y; yy < y + h; yy++) { for (xx = x; xx < x + w; xx++) { - uae_u8 b = origbitmap[yy * desc.Width + xx]; + uae_u8 b = origbitmap[yy * bm_width + xx]; if (inv) b = b == 0 ? 0xff : 0; - bitmap[yy * desc.Width + xx] = b; + bitmap[yy * bm_width + xx] = b; } } } @@ -124,8 +139,8 @@ static void putnumber (int x, int y, int n, int inv) n = 10; for (yy = 0; yy < numbers_height; yy++) { for (xx = 0; xx < numbers_width; xx++) { - dst = bitmap + (yy + y) * desc.Width + (xx + x); - src = numbers + n * numbers_width + yy * desc.Width + xx; + dst = bitmap + (yy + y) * bm_width + (xx + x); + src = numbers + n * numbers_width + yy * bm_width + xx; *dst = 0; if (*src == 0) *dst = 0xff; @@ -149,23 +164,19 @@ static int coords[] = { void lcd_priority (int priority) { - if (!inited) - return; - if (old_pri == priority) - return; - if (lgLcdSetAsLCDForegroundApp (device, priority ? LGLCD_LCD_FOREGROUND_APP_YES : LGLCD_LCD_FOREGROUND_APP_NO) == ERROR_SUCCESS) - old_pri = priority; } void lcd_update (int led, int on) { + bool c; int track, x, y; + static unsigned long otimeframes; if (!inited) return; if (led < 0) { - lgLcdUpdateBitmap (device, lbh, LGLCD_PRIORITY_IDLE_NO_SHOW); + c = pLogiLcdUpdate(); return; } if (on < 0) @@ -195,7 +206,12 @@ void lcd_update (int led, int on) x = 98; putnumbers (x, y, gui_data.idle <= 999 ? gui_data.idle / 10 : 99, 0); } - lgLcdUpdateBitmap (device, lbh, LGLCD_ASYNC_UPDATE (LGLCD_PRIORITY_NORMAL + 1)); + + if (otimeframes != timeframes) { + c = pLogiLcdMonoSetBackground(bitmap); + c = pLogiLcdUpdate(); + otimeframes = timeframes; + } } int lcd_open (void)