--- np2/win9x/np2.cpp 2005/03/20 23:48:02 1.62 +++ np2/win9x/np2.cpp 2006/12/24 00:52:29 1.67 @@ -8,7 +8,6 @@ #include "parts.h" #include "np2.h" #include "np2arg.h" -#include "cputype.h" #include "dosio.h" #include "extromio.h" #include "commng.h" @@ -23,7 +22,6 @@ #include "winloc.h" #include "sstp.h" #include "sstpmsg.h" -#include "dclock.h" #include "toolwin.h" #include "juliet.h" #include "np2class.h" @@ -45,6 +43,12 @@ #include "debugsub.h" #include "subwind.h" #include "viewer.h" +#if !defined(_WIN64) +#include "cputype.h" +#endif +#if defined(SUPPORT_DCLOCK) +#include "dclock.h" +#endif #ifdef BETA_RELEASE @@ -55,7 +59,9 @@ static TCHAR szClassName[] = _T("NP2-Ma HWND hWndMain; HINSTANCE hInst; HINSTANCE hPrev; +#if !defined(_WIN64) int mmxflag; +#endif UINT8 np2break = 0; // ver0.30 BOOL winui_en; @@ -94,11 +100,47 @@ static int np2quitmsg = 0; static HMENU hStat = NULL; static UINT8 scrnmode; static WINLOCEX smwlex; +static HMODULE resmod; static const OEMCHAR np2help[] = OEMTEXT("np2.chm"); static const OEMCHAR np2flagext[] = OEMTEXT("S%02d"); +static const OEMCHAR np2resext[] = OEMTEXT(".%u"); + + +// ---- + +static HINSTANCE loadextinst(HINSTANCE hInstance) { + + OEMCHAR path[MAX_PATH]; + OEMCHAR cpstr[16]; + HMODULE dll; + + file_cpyname(path, modulefile, NELEMENTS(path)); + file_cutext(path); + OEMSPRINTF(cpstr, np2resext, GetOEMCP()); + file_catname(path, cpstr, NELEMENTS(path)); + dll = LoadLibrary(path); + resmod = dll; + if (dll != NULL) { + hInstance = (HINSTANCE)dll; + } + return(hInstance); +} + +static void unloadextinst(void) { + + HMODULE dll; + + dll = resmod; + if (dll) { + resmod = 0; + FreeLibrary(dll); + } +} +// ---- + static void winuienter(void) { winui_en = TRUE; @@ -337,9 +379,11 @@ static void np2popup(HWND hWnd, LPARAM l static void np2cmd(HWND hWnd, UINT16 cmd) { - UINT update; - BOOL b; + HINSTANCE hInst; + UINT update; + BOOL b; + hInst = GetWindowInst(hWnd); update = 0; switch(cmd) { case IDM_RESET: @@ -443,25 +487,38 @@ static void np2cmd(HWND hWnd, UINT16 cmd toolwin_setfdd(3, NULL); break; - case IDM_SASI1OPEN: + case IDM_IDE0OPEN: winuienter(); dialog_changehdd(hWnd, 0x00); winuileave(); break; - case IDM_SASI1EJECT: + case IDM_IDE0EJECT: diskdrv_sethdd(0x00, NULL); break; - case IDM_SASI2OPEN: + case IDM_IDE1OPEN: winuienter(); dialog_changehdd(hWnd, 0x01); winuileave(); break; - case IDM_SASI2EJECT: + case IDM_IDE1EJECT: diskdrv_sethdd(0x01, NULL); break; + +#if defined(SUPPORT_IDEIO) + case IDM_IDE2OPEN: + winuienter(); + dialog_changehdd(hWnd, 0x02); + winuileave(); + break; + + case IDM_IDE2EJECT: + diskdrv_sethdd(0x02, NULL); + break; +#endif + #if defined(SUPPORT_SCSI) case IDM_SCSI0OPEN: winuienter(); @@ -503,6 +560,7 @@ static void np2cmd(HWND hWnd, UINT16 cmd diskdrv_sethdd(0x23, NULL); break; #endif + case IDM_WINDOW: changescreen(scrnmode & (~SCRNMODE_FULLSCREEN)); break; @@ -876,7 +934,7 @@ static void np2cmd(HWND hWnd, UINT16 cmd update |= SYS_UPDATECFG; break; - case IDM_I286SAVE: + case IDM_CPUSAVE: debugsub_status(); break; @@ -1077,7 +1135,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT BITMAP bmp; HDC hmdc; HBRUSH hbrush; - hinst = (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE); + hinst = GetWindowInst(hWnd); GetClientRect(hWnd, &rect); width = rect.right - rect.left; height = rect.bottom - rect.top; @@ -1214,6 +1272,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT HTCAPTION, 0L)); } } +#if defined(SUPPORT_DCLOCK) else { POINT p; if ((GetCursorPos(&p)) && (p.y >= 466)) { @@ -1222,6 +1281,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT dclock_reset(); } } +#endif return(DefWindowProc(hWnd, msg, wParam, lParam)); } break; @@ -1243,6 +1303,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT if (!scrnmng_isfullscreen()) { np2popup(hWnd, lParam); } +#if defined(SUPPORT_DCLOCK) else { POINT p; if ((GetCursorPos(&p)) && (p.y >= 466) && @@ -1252,6 +1313,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT dclock_reset(); } } +#endif return(DefWindowProc(hWnd, msg, wParam, lParam)); } break; @@ -1365,7 +1427,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT static void framereset(UINT cnt) { framecnt = 0; +#if defined(SUPPORT_DCLOCK) scrnmng_dispclock(); +#endif kdispwin_draw((UINT8)cnt); skbdwin_process(); mdbgwin_process(); @@ -1390,7 +1454,6 @@ static void processwait(UINT cnt) { soundmng_sync(); } - int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInst, LPSTR lpszCmdLine, int nCmdShow) { WNDCLASS wc; @@ -1429,10 +1492,12 @@ int WINAPI WinMain(HINSTANCE hInstance, return(FALSE); } - hInst = hInstance; + hInst = loadextinst(hInstance); hPrev = hPreInst; +#if !defined(_WIN64) mmxflag = (havemmx())?0:MMXFLAG_NOTSUPPORT; mmxflag += (np2oscfg.disablemmx)?MMXFLAG_DISABLE:0; +#endif TRACEINIT(); xrollkey = (np2oscfg.xrollkey == 0); @@ -1453,23 +1518,26 @@ int WINAPI WinMain(HINSTANCE hInstance, winkbd_setf12(np2oscfg.F12COPY); keystat_initialize(); - np2class_initialize(hInstance); + np2class_initialize(hInst); if (!hPreInst) { wc.style = CS_BYTEALIGNCLIENT | CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = NP2GWL_SIZE; - wc.hInstance = hInstance; - wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); + wc.hInstance = hInst; + wc.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1)); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH); wc.lpszMenuName = MAKEINTRESOURCE(IDR_MAIN); wc.lpszClassName = szClassName; if (!RegisterClass(&wc)) { + unloadextinst(); + TRACETERM(); + dosio_term(); return(FALSE); } } - toolwin_initapp(hInstance); + toolwin_initapp(hInst); kdispwin_initialize(hPreInst); skbdwin_initialize(hPreInst); mdbgwin_initialize(hPreInst); @@ -1483,7 +1551,7 @@ int WINAPI WinMain(HINSTANCE hInstance, } hWnd = CreateWindowEx(0, szClassName, np2oscfg.titles, style, np2oscfg.winx, np2oscfg.winy, 640, 400, - NULL, NULL, hInstance, NULL); + NULL, NULL, hInst, NULL); hWndMain = hWnd; scrnmng_initialize(); @@ -1546,6 +1614,9 @@ int WINAPI WinMain(HINSTANCE hInstance, MessageBox(hWnd, _T("Couldn't create DirectDraw Object"), np2oscfg.titles, MB_OK | MB_ICONSTOP); } + unloadextinst(); + TRACETERM(); + dosio_term(); return(FALSE); } } @@ -1603,10 +1674,11 @@ int WINAPI WinMain(HINSTANCE hInstance, sstp_destruct(); soundmng_deinitialize(); scrnmng_destroy(); + unloadextinst(); TRACETERM(); dosio_term(); viewer_term(); - return(0); + return(FALSE); } } #endif @@ -1645,7 +1717,9 @@ int WINAPI WinMain(HINSTANCE hInstance, joymng_sync(); mousemng_sync(); pccore_exec(framecnt == 0); +#if defined(SUPPORT_DCLOCK) dclock_callback(); +#endif if (np2oscfg.DRAW_SKIP) { // nowait frame skip framecnt++; if (framecnt >= np2oscfg.DRAW_SKIP) { @@ -1664,7 +1738,9 @@ int WINAPI WinMain(HINSTANCE hInstance, joymng_sync(); mousemng_sync(); pccore_exec(framecnt == 0); +#if defined(SUPPORT_DCLOCK) dclock_callback(); +#endif framecnt++; } else { @@ -1677,7 +1753,9 @@ int WINAPI WinMain(HINSTANCE hInstance, joymng_sync(); mousemng_sync(); pccore_exec(framecnt == 0); +#if defined(SUPPORT_DCLOCK) dclock_callback(); +#endif framecnt++; cnt = timing_getcount(); if (framecnt > cnt) { @@ -1753,6 +1831,8 @@ int WINAPI WinMain(HINSTANCE hInstance, } skbdwin_deinitialize(); + unloadextinst(); + TRACETERM(); _MEM_USED("report.txt"); dosio_term();