--- np2/win9x/np2.cpp 2003/10/16 17:58:56 1.1.1.1 +++ np2/win9x/np2.cpp 2007/01/08 01:16:59 1.69 @@ -1,8 +1,11 @@ #include "compiler.h" #include +#ifndef __GNUC__ #include +#endif #include "resource.h" #include "strres.h" +#include "parts.h" #include "np2.h" #include "np2arg.h" #include "dosio.h" @@ -16,18 +19,18 @@ #include "winkbd.h" #include "ini.h" #include "menu.h" -#include "dialog.h" #include "winloc.h" #include "sstp.h" #include "sstpmsg.h" -#include "dclock.h" -#include "memory.h" +#include "toolwin.h" +#include "juliet.h" +#include "np2class.h" +#include "dialog.h" +#include "cpucore.h" #include "pccore.h" #include "iocore.h" #include "pc9861k.h" #include "mpu98ii.h" -#include "timing.h" -#include "debugsub.h" #include "bios.h" #include "scrndraw.h" #include "sound.h" @@ -35,89 +38,151 @@ #include "s98.h" #include "diskdrv.h" #include "fddfile.h" - -#ifdef USE_ROMEO -#include "juliet.h" -#endif - -#include "keydisp.h" +#include "timing.h" +#include "keystat.h" +#include "debugsub.h" +#include "subwind.h" #include "viewer.h" -#include "statsave.h" +#if !defined(_WIN64) +#include "cputype.h" +#endif +#if defined(SUPPORT_DCLOCK) +#include "dclock.h" +#endif #ifdef BETA_RELEASE #define OPENING_WAIT 1500 #endif -#define STATSAVEMAX 10 - -static char np2help[] = "np2.hlp"; -static char np2resume[] = "sav"; - -static char szClassName[] = "NP2-MainWindow"; +static TCHAR szClassName[] = _T("NP2-MainWindow"); HWND hWndMain; HINSTANCE hInst; HINSTANCE hPrev; +#if !defined(_WIN64) + int mmxflag; +#endif + UINT8 np2break = 0; // ver0.30 + BOOL winui_en; NP2OSCFG np2oscfg = { - "Neko Project II", "NP2", - CW_USEDEFAULT, CW_USEDEFAULT, 1, 1, 0, 1, 0, 2, + OEMTEXT(PROJECTNAME) OEMTEXT(PROJECTSUBNAME), + OEMTEXT("NP2"), + 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, "", "", "", ""}, // ver0.34 - {0, 0, 0x3e, 19200, "", "", "", ""}, // ver0.34 - {0, 0, 0x3e, 19200, "", "", "", ""}, // ver0.34 - {0, 0, 0x3e, 19200, "", "", "", ""}, // ver0.34 + {5, 0, 0x3e, 19200, + OEMTEXT(""), OEMTEXT(""), OEMTEXT(""), OEMTEXT("")}, + {0, 0, 0x3e, 19200, + OEMTEXT(""), OEMTEXT(""), OEMTEXT(""), OEMTEXT("")}, + {0, 0, 0x3e, 19200, + OEMTEXT(""), OEMTEXT(""), OEMTEXT(""), OEMTEXT("")}, + {0, 0, 0x3e, 19200, + OEMTEXT(""), OEMTEXT(""), OEMTEXT(""), OEMTEXT("")}, 0xffffff, 0xffbf6a, 0, 0, - 0, 1, 0, 9801, 0, 0, 0, 0}; // ver0.34 + 0, 1, 0, 9801, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - char fddfolder[MAX_PATH]; - char hddfolder[MAX_PATH]; - char bmpfilefolder[MAX_PATH]; - char mimpideffile[MAX_PATH]; - char modulefile[MAX_PATH]; - -static UINT framecnt = 0; -static UINT waitcnt = 0; -static UINT framemax = 1; - BYTE np2break = 0; // ver0.30 -static BYTE np2stopemulate = 0; -static int np2opening = 1; -static int np2quitmsg = 0; - HMENU hStat = NULL; + OEMCHAR fddfolder[MAX_PATH]; + OEMCHAR hddfolder[MAX_PATH]; + OEMCHAR bmpfilefolder[MAX_PATH]; + OEMCHAR modulefile[MAX_PATH]; + +static UINT framecnt = 0; +static UINT waitcnt = 0; +static UINT framemax = 1; +static UINT8 np2stopemulate = 0; +static int np2opening = 1; +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); + } +} -typedef struct { -const char *str; - int id; -} SYSMENU_ITEM; -static SYSMENU_ITEM smenu_item[] = { - {"&Centering", IDM_SCREENCENTER}, - {"&Window Snap", IDM_SNAPENABLE}, - {"&Background", IDM_BACKGROUND}, - {"Background &Sound", IDM_BGSOUND}, - {"&Key display", IDM_KEYDISP}, - {NULL, 0}, - {" 320x200", IDM_SCRNMUL4}, - {" 480x300", IDM_SCRNMUL6}, - {" 640x400", IDM_SCRNMUL8}, - {" 800x500", IDM_SCRNMUL10}, - {" 960x600", IDM_SCRNMUL12}, - {"1280x800", IDM_SCRNMUL16}, - {NULL, 0}, - }; +// ---- + +static void winuienter(void) { + + winui_en = TRUE; + soundmng_disable(SNDPROC_MAIN); + scrnmng_topwinui(); +} + +static void winuileave(void) { + + scrnmng_clearwinui(); + soundmng_enable(SNDPROC_MAIN); + winui_en = FALSE; +} +WINLOCEX np2_winlocexallwin(HWND base) { -static BYTE scrnmode; + UINT i; + UINT cnt; + HWND list[5]; + + cnt = 0; + list[cnt++] = hWndMain; + list[cnt++] = toolwin_gethwnd(); + list[cnt++] = kdispwin_gethwnd(); + list[cnt++] = skbdwin_gethwnd(); + list[cnt++] = mdbgwin_gethwnd(); + for (i=0; i= IDM_FLAGSAVE) && + (cmd < (IDM_FLAGSAVE + SUPPORT_STATSAVE))) { + OEMCHAR ext[4]; + OEMSPRINTF(ext, np2flagext, cmd - IDM_FLAGSAVE); + flagsave(ext); + } + else if ((cmd >= IDM_FLAGLOAD) && + (cmd < (IDM_FLAGLOAD + SUPPORT_STATSAVE))) { + OEMCHAR ext[4]; + OEMSPRINTF(ext, np2flagext, cmd - IDM_FLAGLOAD); + flagload(ext, OEMTEXT("Status Load"), TRUE); + } +#endif + break; + } + sysmng_update(update); +} - case IDM_MPUPC98: - winuienter(); - DialogBox(hInst, MAKEINTRESOURCE(IDD_MPUPC98), - hWnd, (DLGPROC)MidiDialogProc); - winuileave(); - break; +LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { - case IDM_MIDIPANIC: // ver0.29 - rs232c_midipanic(); - mpu98ii_midipanic(); - pc9861k_midipanic(); - break; + PAINTSTRUCT ps; + RECT rc; + HDC hdc; + BOOL b; + UINT update; + HWND subwin; + WINLOCEX wlex; - case IDM_BMPSAVE: - winuienter(); - dialog_writebmp(hWnd); - winuileave(); - break; + switch (msg) { + case WM_CREATE: + np2class_wmcreate(hWnd); + np2class_windowtype(hWnd, np2oscfg.wintype); + sstp_construct(hWnd); +#ifndef __GNUC__ + WINNLSEnableIME(hWnd, FALSE); +#endif + break; - case IDM_S98LOGGING: - winuienter(); - dialog_s98(hWnd); - winuileave(); + case WM_SYSCOMMAND: + update = 0; + switch(wParam) { + case IDM_TOOLWIN: + sysmenu_settoolwin(np2oscfg.toolwin ^ 1); + if (np2oscfg.toolwin) { + toolwin_create(); + } + else { + toolwin_destroy(); + } + update |= SYS_UPDATEOSCFG; break; - case IDM_DISPCLOCK: - xmenu_setdispclk(np2oscfg.DISPCLK ^ 1); - update |= SYS_UPDATECFG; +#if defined(SUPPORT_KEYDISP) + case IDM_KEYDISP: + sysmenu_setkeydisp(np2oscfg.keydisp ^ 1); + if (np2oscfg.keydisp) { + kdispwin_create(); + } + else { + kdispwin_destroy(); + } break; - - case IDM_DISPFRAME: - xmenu_setdispclk(np2oscfg.DISPCLK ^ 2); - update |= SYS_UPDATECFG; +#endif +#if defined(SUPPORT_SOFTKBD) + case IDM_SOFTKBD: + skbdwin_create(); break; - - case IDM_CALENDAR: - winuienter(); - DialogBox(hInst, MAKEINTRESOURCE(IDD_CALENDAR), - hWnd, (DLGPROC)ClndDialogProc); - winuileave(); +#endif +#if defined(CPUCORE_IA32) && defined(SUPPORT_MEMDBG32) + case IDM_MEMDBG32: + mdbgwin_create(); break; - - case IDM_ALTENTER: - xmenu_setshortcut(np2oscfg.shortcut ^ 1); - update |= SYS_UPDATECFG; +#endif + case IDM_SCREENCENTER: + if ((!scrnmng_isfullscreen()) && + (!(GetWindowLong(hWnd, GWL_STYLE) & + (WS_MAXIMIZE | WS_MINIMIZE)))) { + wlex = np2_winlocexallwin(hWnd); + wincentering(hWnd); + winlocex_move(wlex); + winlocex_destroy(wlex); + } break; - case IDM_ALTF4: - xmenu_setshortcut(np2oscfg.shortcut ^ 2); - update |= SYS_UPDATECFG; + case IDM_SNAPENABLE: + sysmenu_setwinsnap(np2oscfg.WINSNAP ^ 1); + update |= SYS_UPDATEOSCFG; break; - case IDM_JOYX: - xmenu_setbtnmode(np2cfg.BTN_MODE ^ 1); - update |= SYS_UPDATECFG; + case IDM_BACKGROUND: + sysmenu_setbackground(np2oscfg.background ^ 1); + update |= SYS_UPDATEOSCFG; break; - case IDM_RAPID: - xmenu_setbtnrapid(np2cfg.BTN_RAPID ^ 1); - update |= SYS_UPDATECFG; + case IDM_BGSOUND: + sysmenu_setbgsound(np2oscfg.background ^ 2); + update |= SYS_UPDATEOSCFG; break; - case IDM_MSRAPID: - xmenu_setmsrapid(np2cfg.MOUSERAPID ^ 1); - update |= SYS_UPDATECFG; + case IDM_MEMORYDUMP: + debugsub_memorydump(); break; - case IDM_SSTP: - xmenu_setsstp(np2oscfg.sstp ^ 1); - update |= SYS_UPDATECFG; + case IDM_DEBUGUTY: + viewer_open(); break; - case IDM_I286SAVE: - debugsub_status(); + case IDM_SCRNMUL4: + case IDM_SCRNMUL6: + case IDM_SCRNMUL8: + case IDM_SCRNMUL10: + 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); + } break; - case IDM_HELP: - ShellExecute(hWnd, NULL, file_getcd(np2help), - NULL, NULL, SW_SHOWNORMAL); - break; + case SC_MINIMIZE: + wlex = np2_winlocexallwin(hWnd); + winlocex_close(wlex); + winlocex_destroy(wlex); + return(DefWindowProc(hWnd, msg, wParam, lParam)); - case IDM_ABOUT: - sstpmsg_about(); - if (sstp_result() != SSTP_SENDING) { - winuienter(); - DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUT), - hWnd, (DLGPROC)AboutDialogProc); - winuileave(); + case SC_RESTORE: + subwin = toolwin_gethwnd(); + if (subwin) { + ShowWindow(subwin, SW_SHOWNOACTIVATE); + } + subwin = kdispwin_gethwnd(); + if (subwin) { + ShowWindow(subwin, SW_SHOWNOACTIVATE); + } + subwin = skbdwin_gethwnd(); + if (subwin) { + ShowWindow(subwin, SW_SHOWNOACTIVATE); + } + subwin = mdbgwin_gethwnd(); + if (subwin) { + ShowWindow(subwin, SW_SHOWNOACTIVATE); } - break; + return(DefWindowProc(hWnd, msg, wParam, lParam)); default: - if ((LOWORD(wParam) >= IDM_FLAGSAVE) && - (LOWORD(wParam) < IDM_FLAGSAVE + STATSAVEMAX)) { - char ext[4]; - wsprintf(ext, "S%02d", - (LOWORD(wParam) - IDM_FLAGSAVE) % 100); - flagsave(ext); - } - if ((LOWORD(wParam) >= IDM_FLAGLOAD) && - (LOWORD(wParam) < IDM_FLAGLOAD + STATSAVEMAX)) { - char ext[4]; - wsprintf(ext, "S%02d", - (LOWORD(wParam) - IDM_FLAGLOAD) % 100); - flagload(ext, "Status Load", TRUE); - } - break; + return(DefWindowProc(hWnd, msg, wParam, lParam)); } sysmng_update(update); break; + case WM_COMMAND: + np2cmd(hWnd, LOWORD(wParam)); + break; + case WM_ACTIVATE: if (LOWORD(wParam) != WA_INACTIVE) { np2break &= ~NP2BREAK_MAIN; scrnmng_update(); - mouse_running(MOUSE_CONT_M); + keystat_allrelease(); + mousemng_enable(MOUSEPROC_BG); } else { np2break |= NP2BREAK_MAIN; - mouse_running(MOUSE_STOP_M); + mousemng_disable(MOUSEPROC_BG); } np2active_renewal(); break; @@ -822,34 +1123,31 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT case WM_PAINT: hdc = BeginPaint(hWnd, &ps); if (np2opening) { - - HDC hmdc; - HBITMAP hbmp; - BITMAP bmp; - HINSTANCE hinst; - int sx = 640 + np2oscfg.paddingx; - int sy = 400 + np2oscfg.paddingy; - - hinst = (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE); -#if 1 - hbmp = LoadBitmap(hinst, "NP2BMP"); - GetObject(hbmp, sizeof(BITMAP), &bmp); - hmdc = CreateCompatibleDC(hdc); - SelectObject(hmdc, hbmp); - BitBlt(hdc, (sx - 252) / 2, (sy - 28) / 2, + HINSTANCE hinst; + RECT rect; + int width; + int height; + HBITMAP hbmp; + BITMAP bmp; + HDC hmdc; + HBRUSH hbrush; + hinst = GetWindowInst(hWnd); + GetClientRect(hWnd, &rect); + width = rect.right - rect.left; + height = rect.bottom - rect.top; + hbmp = LoadBitmap(hinst, _T("NP2BMP")); + GetObject(hbmp, sizeof(BITMAP), &bmp); + hbrush = (HBRUSH)SelectObject(hdc, + GetStockObject(BLACK_BRUSH)); + PatBlt(hdc, 0, 0, width, height, PATCOPY); + SelectObject(hdc, hbrush); + hmdc = CreateCompatibleDC(hdc); + SelectObject(hmdc, hbmp); + BitBlt(hdc, (width - bmp.bmWidth) / 2, + (height - bmp.bmHeight) / 2, bmp.bmWidth, bmp.bmHeight, hmdc, 0, 0, SRCCOPY); - DeleteDC(hmdc); - DeleteObject(hbmp); -#else - hbmp = LoadBitmap(hinst, "NP2EXT"); - GetObject(hbmp, sizeof(BITMAP), &bmp); - hmdc = CreateCompatibleDC(hdc); - SelectObject(hmdc, hbmp); - BitBlt(hdc, (sx - 160) / 2, (sy - 140) / 2, - bmp.bmWidth, bmp.bmHeight, hmdc, 0, 0, SRCCOPY); - DeleteDC(hmdc); - DeleteObject(hbmp); -#endif + DeleteDC(hmdc); + DeleteObject(hbmp); } else { // scrnmng_update(); @@ -864,7 +1162,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT case WM_MOVE: if ((!scrnmng_isfullscreen()) && - (!(GetWindowLong(hWndMain, GWL_STYLE) & + (!(GetWindowLong(hWnd, GWL_STYLE) & (WS_MAXIMIZE | WS_MINIMIZE)))) { GetWindowRect(hWnd, &rc); np2oscfg.winx = rc.left; @@ -885,41 +1183,53 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT break; case WM_ENTERSIZEMOVE: - soundmng_stop(); - mouse_running(MOUSE_STOP); - winloc_movingstart(); - break; - - case WM_EXITSIZEMOVE: - mouse_running(MOUSE_CONT); - soundmng_play(); + soundmng_disable(SNDPROC_MAIN); + mousemng_disable(MOUSEPROC_WINUI); + winlocex_destroy(smwlex); + smwlex = np2_winlocexallwin(hWnd); + scrnmng_entersizing(); break; case WM_MOVING: if (np2oscfg.WINSNAP) { - winloc_movingproc((RECT *)lParam); + winlocex_moving(smwlex, (RECT *)lParam); } break; + case WM_SIZING: + scrnmng_sizing((UINT)wParam, (RECT *)lParam); + break; + + case WM_EXITSIZEMOVE: + scrnmng_exitsizing(); + winlocex_move(smwlex); + winlocex_destroy(smwlex); + smwlex = NULL; + mousemng_enable(MOUSEPROC_WINUI); + soundmng_enable(SNDPROC_MAIN); + break; + case WM_KEYDOWN: if (wParam == VK_F11) { + np2class_enablemenu(hWndMain, TRUE); return(DefWindowProc(hWnd, WM_SYSKEYDOWN, VK_F10, lParam)); } if ((wParam == VK_F12) && (!np2oscfg.F12COPY)) { - mouse_running(MOUSE_XOR); + mousemng_toggle(MOUSEPROC_SYSTEM); xmenu_setmouse(np2oscfg.MOUSE_SW ^ 1); sysmng_update(SYS_UPDATECFG); } else { - winkeydown106(wParam, lParam); + winkbd_keydown(wParam, lParam); } break; + case WM_KEYUP: if (wParam == VK_F11) { return(DefWindowProc(hWnd, WM_SYSKEYUP, VK_F10, lParam)); } if ((wParam != VK_F12) || (np2oscfg.F12COPY)) { - winkeyup106(wParam, lParam); + winkbd_keyup(wParam, lParam); } break; @@ -934,59 +1244,99 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT break; } } - winkeydown106(wParam, lParam); + winkbd_keydown(wParam, lParam); break; case WM_SYSKEYUP: - winkeyup106(wParam, lParam); + winkbd_keyup(wParam, lParam); + break; + + case WM_MOUSEMOVE: + if (scrnmng_isfullscreen()) { + POINT p; + if (GetCursorPos(&p)) { + scrnmng_fullscrnmenu(p.y); + } + } break; case WM_LBUTTONDOWN: - if (!mouse_btn(MOUSE_LEFTDOWN)) { - if (scrnmng_isfullscreen()) { - POINT p; - if ((GetCursorPos(&p)) && (p.y >= 466)) { + if (!mousemng_buttonevent(MOUSEMNG_LEFTDOWN)) { + if (!scrnmng_isfullscreen()) { + if (np2oscfg.wintype == 2) { + return(SendMessage(hWnd, WM_NCLBUTTONDOWN, + HTCAPTION, 0L)); + } + } +#if defined(SUPPORT_DCLOCK) + else { + POINT p; + if ((GetCursorPos(&p)) && + (scrnmng_isdispclockclick(&p))) { np2oscfg.clk_x++; sysmng_update(SYS_UPDATEOSCFG); dclock_reset(); } } +#endif return(DefWindowProc(hWnd, msg, wParam, lParam)); } break; + case WM_LBUTTONUP: - if (!mouse_btn(MOUSE_LEFTUP)) { + if (!mousemng_buttonevent(MOUSEMNG_LEFTUP)) { return(DefWindowProc(hWnd, msg, wParam, lParam)); } break; - case WM_MBUTTONDOWN: // ver0.26 - mouse_running(MOUSE_XOR); + case WM_MBUTTONDOWN: + mousemng_toggle(MOUSEPROC_SYSTEM); xmenu_setmouse(np2oscfg.MOUSE_SW ^ 1); sysmng_update(SYS_UPDATECFG); break; case WM_RBUTTONDOWN: - if (!mouse_btn(MOUSE_RIGHTDOWN)) { - if (scrnmng_isfullscreen()) { - POINT p; - if ((GetCursorPos(&p)) && (p.y >= 466) && - (np2oscfg.clk_x)) { + if (!mousemng_buttonevent(MOUSEMNG_RIGHTDOWN)) { + if (!scrnmng_isfullscreen()) { + np2popup(hWnd, lParam); + } +#if defined(SUPPORT_DCLOCK) + else { + POINT p; + 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; case WM_RBUTTONUP: - if (!mouse_btn(MOUSE_RIGHTUP)) { + if (!mousemng_buttonevent(MOUSEMNG_RIGHTUP)) { return(DefWindowProc(hWnd, msg, wParam, lParam)); } break; + case WM_LBUTTONDBLCLK: + if (!scrnmng_isfullscreen()) { + np2oscfg.wintype++; + if (np2oscfg.wintype >= 3) { + np2oscfg.wintype = 0; + } + wlex = np2_winlocexallwin(hWnd); + winlocex_setholdwnd(wlex, hWnd); + np2class_windowtype(hWnd, np2oscfg.wintype); + winlocex_move(wlex); + winlocex_destroy(wlex); + sysmng_update(SYS_UPDATEOSCFG); + } + break; + case WM_CLOSE: b = FALSE; if (!np2oscfg.comfirm) { @@ -994,14 +1344,13 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT } else if (sstpconfirm_exit()) { winuienter(); - if (MessageBox(hWnd, "Sure?", "Exit", + if (MessageBox(hWnd, _T("Sure?"), _T("Exit"), MB_ICONQUESTION | MB_YESNO) == IDYES) { b = TRUE; } winuileave(); } if (b) { - keydisp_destroy(); viewer_allclose(); DestroyWindow(hWnd); } @@ -1009,6 +1358,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT case WM_DESTROY: DestroyMenu(hStat); + np2class_wmdestroy(hWnd); PostQuitMessage(0); break; @@ -1025,6 +1375,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT break; case NP2CMD_RESET: + juliet_YMF288Reset(); pccore_cfgupdate(); pccore_reset(); break; @@ -1071,65 +1422,88 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT } -static void processwait(WORD cnt) { +static void framereset(UINT cnt) { + + framecnt = 0; +#if defined(SUPPORT_DCLOCK) + scrnmng_dispclock(); +#endif + kdispwin_draw((UINT8)cnt); + skbdwin_process(); + mdbgwin_process(); + toolwin_draw((UINT8)cnt); + viewer_allreload(FALSE); + if (np2oscfg.DISPCLK & 3) { + if (sysmng_workclockrenewal()) { + sysmng_updatecaption(3); + } + } +} + +static void processwait(UINT cnt) { if (timing_getcount() >= cnt) { timing_setcount(0); - framecnt = 0; - scrnmng_dispclock(); - keydisp_draw(np2oscfg.DRAW_SKIP); - viewer_allreload(FALSE); - if (np2oscfg.DISPCLK & 2) { - if (sysmng_workclockrenewal()) { - sysmng_updatecaption(2); - } - } + framereset(cnt); } else { Sleep(1); } + soundmng_sync(); } - int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInst, LPSTR lpszCmdLine, int nCmdShow) { - WNDCLASS np2; + WNDCLASS wc; MSG msg; - HMENU hMenu; - HWND hwndorg; - int i; + HWND hWnd; + UINT i; + DWORD style; #ifdef OPENING_WAIT UINT32 tick; #endif + BOOL xrollkey; - GetModuleFileName(NULL, modulefile, sizeof(modulefile)); + _MEM_INIT(); + + GetModuleFileName(NULL, modulefile, NELEMENTS(modulefile)); dosio_init(); file_setcd(modulefile); - np2arg_analize(lpszCmdLine); // タイミング修正 // ver0.29 + np2arg_analize(); initload(); + toolwin_readini(); + kdispwin_readini(); + skbdwin_readini(); + mdbgwin_readini(); + + rand_setseed((unsigned)time(NULL)); + + szClassName[0] = (TCHAR)np2oscfg.winid[0]; + szClassName[1] = (TCHAR)np2oscfg.winid[1]; + szClassName[2] = (TCHAR)np2oscfg.winid[2]; - srand((unsigned)time(NULL)); - -// np2arg_analize(lpszCmdLine); - - CopyMemory(szClassName, np2oscfg.winid, 3); - - if ((hwndorg = FindWindow(szClassName, NULL)) != NULL) { + if ((hWnd = FindWindow(szClassName, NULL)) != NULL) { sstpmsg_running(); - ShowWindow(hwndorg, SW_RESTORE); - SetForegroundWindow(hwndorg); + ShowWindow(hWnd, SW_RESTORE); + SetForegroundWindow(hWnd); dosio_term(); 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(); - if (np2oscfg.KEYBOARD >= KEY_TYPEMAX) { // ver0.28 + xrollkey = (np2oscfg.xrollkey == 0); + if (np2oscfg.KEYBOARD >= KEY_TYPEMAX) { int keytype = GetKeyboardType(1); if ((keytype & 0xff00) == 0x0d00) { np2oscfg.KEYBOARD = KEY_PC98; + xrollkey = !xrollkey; } else if (!keytype) { np2oscfg.KEYBOARD = KEY_KEY101; @@ -1138,106 +1512,91 @@ int WINAPI WinMain(HINSTANCE hInstance, np2oscfg.KEYBOARD = KEY_KEY106; } } - keystat_reset(); + winkbd_roll(xrollkey); + winkbd_setf12(np2oscfg.F12COPY); + keystat_initialize(); + np2class_initialize(hInst); if (!hPreInst) { - np2.style = CS_BYTEALIGNCLIENT | CS_HREDRAW | CS_VREDRAW; - np2.lpfnWndProc = WndProc; - np2.cbClsExtra = 0; - np2.cbWndExtra = 0; - np2.hInstance = hInstance; - np2.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); - np2.hCursor = LoadCursor(NULL, IDC_ARROW); - np2.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); - np2.lpszMenuName = MAKEINTRESOURCE(IDM_MAIN); - np2.lpszClassName = szClassName; - if (!RegisterClass(&np2)) { + wc.style = CS_BYTEALIGNCLIENT | CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; + wc.lpfnWndProc = WndProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = NP2GWL_SIZE; + 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); } } - keydisp_initialize(hPreInst); - viewer_init(hPreInst); // ver0.30 - - hWndMain = CreateWindowEx(0, szClassName, np2oscfg.titles, - WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION | - WS_MINIMIZEBOX, + toolwin_initapp(hInst); + kdispwin_initialize(hPreInst); + skbdwin_initialize(hPreInst); + mdbgwin_initialize(hPreInst); + viewer_init(hPreInst); + + mousemng_initialize(); + + style = WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX; + if (np2oscfg.thickframe) { + style |= WS_THICKFRAME; + } + 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(); - xmenu_setsound(np2cfg.SOUND_SW); - xmenu_setbeepvol(np2cfg.BEEP_VOL); - xmenu_setkey(0); - xmenu_setbtnrapid(np2cfg.BTN_RAPID); - xmenu_setbtnmode(np2cfg.BTN_MODE); - xmenu_setmsrapid(np2cfg.MOUSERAPID); + xmenu_setroltate(0); + xmenu_setdispmode(np2cfg.DISPSYNC); + xmenu_setraster(np2cfg.RASTER); xmenu_setwaitflg(np2oscfg.NOWAIT); xmenu_setframe(np2oscfg.DRAW_SKIP); - xmenu_setdispmode(np2cfg.DISPSYNC); - xmenu_setdispclk(np2oscfg.DISPCLK); - xmenu_seti286save(np2oscfg.I286SAVE); - xmenu_setmotorflg(np2cfg.MOTOR); - xmenu_setroltate(0); + + xmenu_setkey(0); xmenu_setxshift(0); xmenu_setf12copy(np2oscfg.F12COPY); + xmenu_setbeepvol(np2cfg.BEEP_VOL); + xmenu_setsound(np2cfg.SOUND_SW); + xmenu_setjastsound(np2oscfg.jastsnd); + xmenu_setmotorflg(np2cfg.MOTOR); xmenu_setextmem(np2cfg.EXTMEM); - xmenu_setraster(np2cfg.RASTER); - xmenu_setshortcut(np2oscfg.shortcut); // ver0.30 - xmenu_setsstp(np2oscfg.sstp); xmenu_setmouse(np2oscfg.MOUSE_SW); - ShowWindow(hWndMain, nCmdShow); - UpdateWindow(hWndMain); + xmenu_setshortcut(np2oscfg.shortcut); + xmenu_setdispclk(np2oscfg.DISPCLK); + xmenu_setbtnmode(np2cfg.BTN_MODE); + xmenu_setbtnrapid(np2cfg.BTN_RAPID); + xmenu_setmsrapid(np2cfg.MOUSERAPID); + xmenu_setsstp(np2oscfg.sstp); + + ShowWindow(hWnd, nCmdShow); + UpdateWindow(hWnd); #ifdef OPENING_WAIT tick = GetTickCount(); #endif - // めにゅー追加 - if (np2oscfg.statsave) { - char buf[16]; - hMenu = GetMenu(hWndMain); - hStat = CreatePopupMenu(); - for (i=0; i= np2oscfg.DRAW_SKIP) { @@ -1357,10 +1733,12 @@ int WINAPI WinMain(HINSTANCE hInstance, } else if (np2oscfg.DRAW_SKIP) { // frame skip if (framecnt < np2oscfg.DRAW_SKIP) { - joy_flash(); - mouse_callback(); + joymng_sync(); + mousemng_sync(); pccore_exec(framecnt == 0); +#if defined(SUPPORT_DCLOCK) dclock_callback(); +#endif framecnt++; } else { @@ -1369,22 +1747,32 @@ int WINAPI WinMain(HINSTANCE hInstance, } else { // auto skip if (!waitcnt) { - joy_flash(); - mouse_callback(); + UINT cnt; + joymng_sync(); + mousemng_sync(); pccore_exec(framecnt == 0); +#if defined(SUPPORT_DCLOCK) dclock_callback(); +#endif framecnt++; - if (timing_getcount() < framecnt) { + cnt = timing_getcount(); + if (framecnt > cnt) { waitcnt = framecnt; if (framemax > 1) { framemax--; } } else if (framecnt >= framemax) { - waitcnt = framecnt; if (framemax < 12) { framemax++; } + if (cnt >= 12) { + timing_reset(); + } + else { + timing_setcount(cnt - framecnt); + } + framereset(0); } } else { @@ -1403,41 +1791,51 @@ int WINAPI WinMain(HINSTANCE hInstance, DispatchMessage(&msg); } } + toolwin_destroy(); + kdispwin_destroy(); + skbdwin_destroy(); + mdbgwin_destroy(); pccore_cfgupdate(); - mouse_running(MOUSE_OFF); + mousemng_disable(MOUSEPROC_WINUI); S98_trash(); +#if defined(SUPPORT_RESUME) if (np2oscfg.resume) { - flagsave(np2resume); + flagsave(str_sav); } else { -// DeleteFile(file_getcd(np2resume)); + flagdelete(str_sav); } +#endif -#ifdef USE_ROMEO juliet_YMF288Reset(); -#endif pccore_term(); sstp_destruct(); -#ifdef USE_ROMEO - juliet_unload(); -#endif + juliet_deinitialize(); soundmng_deinitialize(); scrnmng_destroy(); if (sys_updates & (SYS_UPDATECFG | SYS_UPDATEOSCFG)) { initsave(); + toolwin_writeini(); + kdispwin_writeini(); + skbdwin_writeini(); + mdbgwin_writeini(); } + skbdwin_deinitialize(); + + unloadextinst(); TRACETERM(); + _MEM_USED("report.txt"); dosio_term(); - viewer_term(); // ver0.30 + viewer_term(); // ver0.30 return(msg.wParam); }