--- np2/win9x/np2.cpp 2006/12/17 02:30:11 1.65 +++ np2/win9x/np2.cpp 2007/11/11 07:11:27 1.74 @@ -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 @@ -52,21 +56,19 @@ #endif static TCHAR szClassName[] = _T("NP2-MainWindow"); - HWND hWndMain; - HINSTANCE hInst; - HINSTANCE hPrev; + HWND g_hWndMain; + HINSTANCE g_hInstance; + HINSTANCE g_hPrevInst; +#if !defined(_WIN64) int mmxflag; +#endif UINT8 np2break = 0; // ver0.30 BOOL winui_en; NP2OSCFG np2oscfg = { -#if !defined(SUPPORT_PC9821) - OEMTEXT("Neko Project II"), -#else - OEMTEXT("Neko Project 21"), -#endif + OEMTEXT(PROJECTNAME) OEMTEXT(PROJECTSUBNAME), OEMTEXT("NP2"), - CW_USEDEFAULT, CW_USEDEFAULT, 1, 1, 0, 1, 0, 0, + CW_USEDEFAULT, CW_USEDEFAULT, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, KEY_UNKNOWN, 0, 0, 0, 0, {1, 2, 2, 1}, {5, 0, 0x3e, 19200, @@ -78,7 +80,7 @@ static TCHAR szClassName[] = _T("NP2-Ma {0, 0, 0x3e, 19200, OEMTEXT(""), OEMTEXT(""), OEMTEXT(""), OEMTEXT("")}, 0xffffff, 0xffbf6a, 0, 0, - 0, 1, 0, 9801, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + 0, 1, 0, 9801, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; OEMCHAR fddfolder[MAX_PATH]; OEMCHAR hddfolder[MAX_PATH]; @@ -94,10 +96,46 @@ 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) { @@ -120,7 +158,7 @@ WINLOCEX np2_winlocexallwin(HWND base) { HWND list[5]; cnt = 0; - list[cnt++] = hWndMain; + list[cnt++] = g_hWndMain; list[cnt++] = toolwin_gethwnd(); list[cnt++] = kdispwin_gethwnd(); list[cnt++] = skbdwin_gethwnd(); @@ -130,7 +168,7 @@ WINLOCEX np2_winlocexallwin(HWND base) { list[i] = NULL; } } - if (base != hWndMain) { // hWndMainのみ全体移動 + if (base != g_hWndMain) { // hWndMainのみ全体移動 base = NULL; } return(winlocex_create(base, list, cnt)); @@ -159,8 +197,8 @@ static void changescreen(UINT8 newmode) mdbgwin_destroy(); } else if (renewal & SCRNMODE_ROTATEMASK) { - wlex = np2_winlocexallwin(hWndMain); - winlocex_setholdwnd(wlex, hWndMain); + wlex = np2_winlocexallwin(g_hWndMain); + winlocex_setholdwnd(wlex, g_hWndMain); } soundmng_stop(); mousemng_disable(MOUSEPROC_WINUI); @@ -178,10 +216,10 @@ static void changescreen(UINT8 newmode) if (renewal & SCRNMODE_FULLSCREEN) { if (!scrnmng_isfullscreen()) { if (np2oscfg.toolwin) { - toolwin_create(); + toolwin_create(g_hInstance); } if (np2oscfg.keydisp) { - kdispwin_create(); + kdispwin_create(g_hInstance); } } } @@ -215,7 +253,7 @@ static void wincentering(HWND hWnd) { np2oscfg.winy = 0; } sysmng_update(SYS_UPDATEOSCFG); - MoveWindow(hWndMain, np2oscfg.winx, np2oscfg.winy, width, height, TRUE); + MoveWindow(g_hWndMain, np2oscfg.winx, np2oscfg.winy, width, height, TRUE); } void np2active_renewal(void) { // ver0.30 @@ -291,14 +329,14 @@ static int flagload(const OEMCHAR *ext, id = IDYES; ret = statsave_check(path, buf, NELEMENTS(buf)); if (ret & (~STATFLAG_DISKCHG)) { - MessageBox(hWndMain, _T("Couldn't restart"), title, + MessageBox(g_hWndMain, _T("Couldn't restart"), title, MB_OK | MB_ICONSTOP); id = IDNO; } else if ((!force) && (ret & STATFLAG_DISKCHG)) { OEMCHAR buf2[1024 + 256]; OEMSPRINTF(buf2, OEMTEXT("Conflict!\n\n%s\nContinue?"), buf); - id = MessageBox(hWndMain, buf2, title, + id = MessageBox(g_hWndMain, buf2, title, MB_YESNOCANCEL | MB_ICONQUESTION); } if (id == IDYES) { @@ -322,7 +360,7 @@ static void np2popup(HWND hWnd, LPARAM l HMENU hMenu; POINT pt; - mainmenu = (HMENU)GetWindowLong(hWnd, NP2GWL_HMENU); + mainmenu = (HMENU)GetWindowLongPtr(hWnd, NP2GWLP_HMENU); if (mainmenu == NULL) { return; } @@ -335,15 +373,18 @@ static void np2popup(HWND hWnd, LPARAM l DestroyMenu(hMenu); } -static void np2cmd(HWND hWnd, UINT16 cmd) { - - HINSTANCE hInst; +static void OnCommand(HWND hWnd, WPARAM wParam) +{ + HINSTANCE hInstance; UINT update; + UINT uID; BOOL b; - hInst = (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE); + hInstance = (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE); update = 0; - switch(cmd) { + uID = LOWORD(wParam); + switch(uID) + { case IDM_RESET: b = FALSE; if (!np2oscfg.comfirm) { @@ -368,7 +409,7 @@ static void np2cmd(HWND hWnd, UINT16 cmd case IDM_CONFIG: winuienter(); sstpmsg_config(); - DialogBox(hInst, MAKEINTRESOURCE(IDD_CONFIG), + DialogBox(hInstance, MAKEINTRESOURCE(IDD_CONFIG), hWnd, (DLGPROC)CfgDialogProc); if (!scrnmng_isfullscreen()) { UINT8 thick; @@ -755,6 +796,18 @@ static void np2cmd(HWND hWnd, UINT16 cmd update |= SYS_UPDATECFG; break; +#if defined(SUPPORT_PX) + case IDM_PX1: + xmenu_setsound(0x30); + update |= SYS_UPDATECFG; + break; + + case IDM_PX2: + xmenu_setsound(0x50); + update |= SYS_UPDATECFG; + break; +#endif // defined(SUPPORT_PX) + case IDM_JASTSOUND: xmenu_setjastsound(np2oscfg.jastsnd ^ 1); update |= SYS_UPDATEOSCFG; @@ -809,7 +862,7 @@ static void np2cmd(HWND hWnd, UINT16 cmd case IDM_MPUPC98: winuienter(); - DialogBox(hInst, MAKEINTRESOURCE(IDD_MPUPC98), + DialogBox(hInstance, MAKEINTRESOURCE(IDD_MPUPC98), hWnd, (DLGPROC)MidiDialogProc); winuileave(); break; @@ -857,7 +910,7 @@ static void np2cmd(HWND hWnd, UINT16 cmd case IDM_CALENDAR: winuienter(); - DialogBox(hInst, MAKEINTRESOURCE(IDD_CALENDAR), + DialogBox(hInstance, MAKEINTRESOURCE(IDD_CALENDAR), hWnd, (DLGPROC)ClndDialogProc); winuileave(); break; @@ -905,7 +958,7 @@ static void np2cmd(HWND hWnd, UINT16 cmd sstpmsg_about(); if (sstp_result() != SSTP_SENDING) { winuienter(); - DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUT), + DialogBox(hInstance, MAKEINTRESOURCE(IDD_ABOUT), hWnd, (DLGPROC)AboutDialogProc); winuileave(); } @@ -913,16 +966,16 @@ static void np2cmd(HWND hWnd, UINT16 cmd default: #if defined(SUPPORT_STATSAVE) - if ((cmd >= IDM_FLAGSAVE) && - (cmd < (IDM_FLAGSAVE + SUPPORT_STATSAVE))) { + if ((uID >= IDM_FLAGSAVE) && + (uID < (IDM_FLAGSAVE + SUPPORT_STATSAVE))) { OEMCHAR ext[4]; - OEMSPRINTF(ext, np2flagext, cmd - IDM_FLAGSAVE); + OEMSPRINTF(ext, np2flagext, uID - IDM_FLAGSAVE); flagsave(ext); } - else if ((cmd >= IDM_FLAGLOAD) && - (cmd < (IDM_FLAGLOAD + SUPPORT_STATSAVE))) { + else if ((uID >= IDM_FLAGLOAD) && + (uID < (IDM_FLAGLOAD + SUPPORT_STATSAVE))) { OEMCHAR ext[4]; - OEMSPRINTF(ext, np2flagext, cmd - IDM_FLAGLOAD); + OEMSPRINTF(ext, np2flagext, uID - IDM_FLAGLOAD); flagload(ext, OEMTEXT("Status Load"), TRUE); } #endif @@ -957,7 +1010,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT case IDM_TOOLWIN: sysmenu_settoolwin(np2oscfg.toolwin ^ 1); if (np2oscfg.toolwin) { - toolwin_create(); + toolwin_create(g_hInstance); } else { toolwin_destroy(); @@ -969,7 +1022,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT case IDM_KEYDISP: sysmenu_setkeydisp(np2oscfg.keydisp ^ 1); if (np2oscfg.keydisp) { - kdispwin_create(); + kdispwin_create(g_hInstance); } else { kdispwin_destroy(); @@ -978,12 +1031,12 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT #endif #if defined(SUPPORT_SOFTKBD) case IDM_SOFTKBD: - skbdwin_create(); + skbdwin_create(g_hInstance); break; #endif #if defined(CPUCORE_IA32) && defined(SUPPORT_MEMDBG32) case IDM_MEMDBG32: - mdbgwin_create(); + mdbgwin_create(g_hInstance); break; #endif case IDM_SCREENCENTER: @@ -1017,7 +1070,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT break; case IDM_DEBUGUTY: - viewer_open(); + viewer_open(g_hInstance); break; case IDM_SCRNMUL4: @@ -1027,9 +1080,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT case IDM_SCRNMUL12: case IDM_SCRNMUL16: if ((!scrnmng_isfullscreen()) && - !(GetWindowLong(hWndMain, GWL_STYLE) & WS_MINIMIZE)) { - sysmenu_setscrnmul(wParam - IDM_SCRNMUL); - scrnmng_setmultiple(wParam - IDM_SCRNMUL); + !(GetWindowLong(g_hWndMain, GWL_STYLE) & WS_MINIMIZE)) + { + sysmenu_setscrnmul((UINT8)(wParam - IDM_SCRNMUL)); + scrnmng_setmultiple((int)(wParam - IDM_SCRNMUL)); } break; @@ -1065,7 +1119,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT break; case WM_COMMAND: - np2cmd(hWnd, LOWORD(wParam)); + OnCommand(hWnd, wParam); break; case WM_ACTIVATE: @@ -1085,7 +1139,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT case WM_PAINT: hdc = BeginPaint(hWnd, &ps); if (np2opening) { - HINSTANCE hinst; + HINSTANCE hInstance; RECT rect; int width; int height; @@ -1093,11 +1147,11 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT BITMAP bmp; HDC hmdc; HBRUSH hbrush; - hinst = (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE); + hInstance = (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE); GetClientRect(hWnd, &rect); width = rect.right - rect.left; height = rect.bottom - rect.top; - hbmp = LoadBitmap(hinst, _T("NP2BMP")); + hbmp = LoadBitmap(hInstance, _T("NP2BMP")); GetObject(hbmp, sizeof(BITMAP), &bmp); hbrush = (HBRUSH)SelectObject(hdc, GetStockObject(BLACK_BRUSH)); @@ -1173,7 +1227,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT case WM_KEYDOWN: if (wParam == VK_F11) { - np2class_enablemenu(hWndMain, TRUE); + np2class_enablemenu(g_hWndMain, TRUE); return(DefWindowProc(hWnd, WM_SYSKEYDOWN, VK_F10, lParam)); } if ((wParam == VK_F12) && (!np2oscfg.F12COPY)) { @@ -1230,14 +1284,17 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT HTCAPTION, 0L)); } } +#if defined(SUPPORT_DCLOCK) else { POINT p; - if ((GetCursorPos(&p)) && (p.y >= 466)) { + if ((GetCursorPos(&p)) && + (scrnmng_isdispclockclick(&p))) { np2oscfg.clk_x++; sysmng_update(SYS_UPDATEOSCFG); dclock_reset(); } } +#endif return(DefWindowProc(hWnd, msg, wParam, lParam)); } break; @@ -1259,15 +1316,18 @@ 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) && - (np2oscfg.clk_x)) { + if ((GetCursorPos(&p)) && + (scrnmng_isdispclockclick(&p)) && + (np2oscfg.clk_x)) { np2oscfg.clk_fnt++; sysmng_update(SYS_UPDATEOSCFG); dclock_reset(); } } +#endif return(DefWindowProc(hWnd, msg, wParam, lParam)); } break; @@ -1381,7 +1441,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(); @@ -1406,8 +1468,7 @@ static void processwait(UINT cnt) { soundmng_sync(); } - -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInst, +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpszCmdLine, int nCmdShow) { WNDCLASS wc; MSG msg; @@ -1445,10 +1506,12 @@ int WINAPI WinMain(HINSTANCE hInstance, return(FALSE); } - hInst = hInstance; - hPrev = hPreInst; + g_hInstance = loadextinst(hInstance); + g_hPrevInst = hPrevInst; +#if !defined(_WIN64) mmxflag = (havemmx())?0:MMXFLAG_NOTSUPPORT; mmxflag += (np2oscfg.disablemmx)?MMXFLAG_DISABLE:0; +#endif TRACEINIT(); xrollkey = (np2oscfg.xrollkey == 0); @@ -1470,11 +1533,11 @@ int WINAPI WinMain(HINSTANCE hInstance, keystat_initialize(); np2class_initialize(hInstance); - if (!hPreInst) { + if (!hPrevInst) { wc.style = CS_BYTEALIGNCLIENT | CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; - wc.cbWndExtra = NP2GWL_SIZE; + wc.cbWndExtra = NP2GWLP_SIZE; wc.hInstance = hInstance; wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); wc.hCursor = LoadCursor(NULL, IDC_ARROW); @@ -1482,14 +1545,18 @@ int WINAPI WinMain(HINSTANCE hInstance, wc.lpszMenuName = MAKEINTRESOURCE(IDR_MAIN); wc.lpszClassName = szClassName; if (!RegisterClass(&wc)) { + unloadextinst(); + TRACETERM(); + dosio_term(); return(FALSE); } + + toolwin_initapp(hInstance); + kdispwin_initialize(hInstance); + skbdwin_initialize(hInstance); + mdbgwin_initialize(hInstance); + viewer_init(hInstance); } - toolwin_initapp(hInstance); - kdispwin_initialize(hPreInst); - skbdwin_initialize(hPreInst); - mdbgwin_initialize(hPreInst); - viewer_init(hPreInst); mousemng_initialize(); @@ -1500,7 +1567,7 @@ int WINAPI WinMain(HINSTANCE hInstance, hWnd = CreateWindowEx(0, szClassName, np2oscfg.titles, style, np2oscfg.winx, np2oscfg.winy, 640, 400, NULL, NULL, hInstance, NULL); - hWndMain = hWnd; + g_hWndMain = hWnd; scrnmng_initialize(); xmenu_setroltate(0); @@ -1562,6 +1629,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); } } @@ -1619,10 +1689,11 @@ int WINAPI WinMain(HINSTANCE hInstance, sstp_destruct(); soundmng_deinitialize(); scrnmng_destroy(); + unloadextinst(); TRACETERM(); dosio_term(); viewer_term(); - return(0); + return(FALSE); } } #endif @@ -1636,10 +1707,10 @@ int WINAPI WinMain(HINSTANCE hInstance, if (!(scrnmode & SCRNMODE_FULLSCREEN)) { if (np2oscfg.toolwin) { - toolwin_create(); + toolwin_create(hInstance); } if (np2oscfg.keydisp) { - kdispwin_create(); + kdispwin_create(hInstance); } } @@ -1661,7 +1732,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) { @@ -1680,7 +1753,9 @@ int WINAPI WinMain(HINSTANCE hInstance, joymng_sync(); mousemng_sync(); pccore_exec(framecnt == 0); +#if defined(SUPPORT_DCLOCK) dclock_callback(); +#endif framecnt++; } else { @@ -1693,7 +1768,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) { @@ -1769,12 +1846,14 @@ int WINAPI WinMain(HINSTANCE hInstance, } skbdwin_deinitialize(); + unloadextinst(); + TRACETERM(); _MEM_USED("report.txt"); dosio_term(); viewer_term(); // ver0.30 - return(msg.wParam); + return((int)msg.wParam); }