--- np2/win9x/np2.cpp 2003/10/16 17:58:56 1.1 +++ np2/win9x/np2.cpp 2003/10/31 04:11:40 1.20 @@ -1,10 +1,14 @@ #include "compiler.h" #include +#ifndef __GNUC__ #include +#endif #include "resource.h" #include "strres.h" +#include "parts.h" #include "np2.h" #include "np2arg.h" +#include "cputype.h" #include "dosio.h" #include "extromio.h" #include "commng.h" @@ -16,18 +20,21 @@ #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 "toolwin.h" +#ifdef USE_ROMEO +#include "juliet.h" +#endif +#include "np2class.h" +#include "dialog.h" #include "memory.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,14 +42,11 @@ #include "s98.h" #include "diskdrv.h" #include "fddfile.h" - -#ifdef USE_ROMEO -#include "juliet.h" -#endif - +#include "timing.h" +#include "statsave.h" +#include "debugsub.h" #include "keydisp.h" #include "viewer.h" -#include "statsave.h" #ifdef BETA_RELEASE @@ -51,13 +55,11 @@ #define STATSAVEMAX 10 -static char np2help[] = "np2.hlp"; -static char np2resume[] = "sav"; - static char szClassName[] = "NP2-MainWindow"; HWND hWndMain; HINSTANCE hInst; HINSTANCE hPrev; + int mmxflag; NP2OSCFG np2oscfg = { "Neko Project II", "NP2", @@ -69,12 +71,11 @@ static char szClassName[] = "NP2-MainWi {0, 0, 0x3e, 19200, "", "", "", ""}, // ver0.34 {0, 0, 0x3e, 19200, "", "", "", ""}, // ver0.34 0xffffff, 0xffbf6a, 0, 0, - 0, 1, 0, 9801, 0, 0, 0, 0}; // ver0.34 + 0, 1, 0, 9801, 0, 0, 0, 0, 0, 0}; // ver0.38 char fddfolder[MAX_PATH]; char hddfolder[MAX_PATH]; char bmpfilefolder[MAX_PATH]; - char mimpideffile[MAX_PATH]; char modulefile[MAX_PATH]; static UINT framecnt = 0; @@ -85,31 +86,26 @@ static BYTE np2stopemulate = 0; static int np2opening = 1; static int np2quitmsg = 0; HMENU hStat = NULL; +static BYTE scrnmode; + WINLOC wl; +static const char np2help[] = "np2.hlp"; +static const char np2resume[] = "sav"; -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 BYTE scrnmode; +static void winuienter(void) { + + soundmng_disable(SNDPROC_MAIN); + scrnmng_topwinui(); +} + +static void winuileave(void) { + + scrnmng_clearwinui(); + soundmng_enable(SNDPROC_MAIN); +} static void changescreen(BYTE newmode) { @@ -125,6 +121,12 @@ static void changescreen(BYTE newmode) { renewal |= (change & SCRNMODE_ROTATEMASK); } if (renewal) { + if (renewal & SCRNMODE_FULLSCREEN) { + toolwin_close(); + } + else if (renewal & SCRNMODE_ROTATEMASK) { + toolwin_movingstart(); + } soundmng_stop(); mouse_running(MOUSE_STOP); keydisp_destroy(); @@ -139,6 +141,13 @@ static void changescreen(BYTE newmode) { } } scrndraw_redraw(); + if ((renewal & SCRNMODE_FULLSCREEN) && + (!scrnmng_isfullscreen()) && (np2oscfg.toolwin)) { + toolwin_open(); + } + else if (renewal & SCRNMODE_ROTATEMASK) { + toolwin_movingend(); + } mouse_running(MOUSE_CONT); soundmng_play(); } @@ -172,7 +181,7 @@ void np2active_renewal(void) { / if (np2break & (~NP2BREAK_MAIN)) { np2stopemulate = 2; - soundmng_disable(); + soundmng_disable(SNDPROC_MASTER); } else if (np2break & NP2BREAK_MAIN) { if (np2oscfg.background & 1) { @@ -182,15 +191,15 @@ void np2active_renewal(void) { / np2stopemulate = 0; } if (np2oscfg.background) { - soundmng_disable(); + soundmng_disable(SNDPROC_MASTER); } else { - soundmng_enable(); + soundmng_enable(SNDPROC_MASTER); } } else { np2stopemulate = 0; - soundmng_enable(); + soundmng_enable(SNDPROC_MASTER); } } @@ -217,6 +226,14 @@ static int flagsave(const char *ext) { return(ret); } +static void flagdelete(const char *ext) { + + char path[MAX_PATH]; + + getstatfilename(path, ext, sizeof(path)); + file_delete(path); +} + static int flagload(const char *ext, const char *title, BOOL force) { int ret; @@ -225,8 +242,7 @@ static int flagload(const char *ext, con char buf[1024]; getstatfilename(path, ext, sizeof(path)); - soundmng_stop(); - scrnmng_topwinui(); + winuienter(); id = IDYES; ret = statsave_check(path, buf, sizeof(buf)); if (ret & (~NP2FLAG_DISKCHG)) { @@ -241,29 +257,18 @@ static int flagload(const char *ext, con } if (id == IDYES) { statsave_load(path); + toolwin_setfdd(0, fdd_diskname(0)); + toolwin_setfdd(1, fdd_diskname(1)); } sysmng_workclockreset(); sysmng_updatecaption(1); - scrnmng_clearwinui(); - soundmng_play(); + winuileave(); return(id); } // ---- proc -static void winuienter(void) { - - soundmng_stop(); - scrnmng_topwinui(); -} - -static void winuileave(void) { - - scrnmng_clearwinui(); - soundmng_play(); -} - LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; @@ -275,34 +280,48 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT switch (msg) { case WM_CREATE: sstp_construct(hWnd); +#ifndef __GNUC__ WINNLSEnableIME(hWnd, FALSE); -// DragAcceptFiles(hWnd, TRUE); +#endif break; case WM_SYSCOMMAND: update = 0; switch(wParam) { - case IDM_SCREENCENTER: // ver0.26 + case IDM_TOOLWIN: + xmenu_settoolwin(np2oscfg.toolwin ^ 1); + if (np2oscfg.toolwin) { + toolwin_open(); + } + else { + toolwin_close(); + } + update |= SYS_UPDATEOSCFG; + break; + + case IDM_SCREENCENTER: if ((!scrnmng_isfullscreen()) && (!(GetWindowLong(hWnd, GWL_STYLE) & (WS_MAXIMIZE | WS_MINIMIZE)))) { + toolwin_movingstart(); wincentering(hWnd); + toolwin_movingend(); } break; case IDM_SNAPENABLE: xmenu_setwinsnap(np2oscfg.WINSNAP ^ 1); - update |= SYS_UPDATECFG; + update |= SYS_UPDATEOSCFG; break; case IDM_BACKGROUND: xmenu_setbackground(np2oscfg.background ^ 1); - update |= SYS_UPDATECFG; + update |= SYS_UPDATEOSCFG; break; case IDM_BGSOUND: xmenu_setbgsound(np2oscfg.background ^ 2); - update |= SYS_UPDATECFG; + update |= SYS_UPDATEOSCFG; break; case IDM_KEYDISP: @@ -323,13 +342,11 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT case IDM_SCRNMUL10: case IDM_SCRNMUL12: case IDM_SCRNMUL16: -#if 0 - if ((SCREENMODE & SCMD_WINDOWED) && + if ((!scrnmng_isfullscreen()) && !(GetWindowLong(hWndMain, GWL_STYLE) & WS_MINIMIZE)) { xmenu_setscrnmul(wParam - IDM_SCRNMUL); - ddraws_setmul(wParam - IDM_SCRNMUL); + scrnmng_setmultiple(wParam - IDM_SCRNMUL); } -#endif break; default: @@ -393,6 +410,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT case IDM_FDD1EJECT: diskdrv_setfdd(0, NULL, 0); + toolwin_setfdd(0, NULL); break; case IDM_FDD2OPEN: @@ -403,6 +421,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT case IDM_FDD2EJECT: diskdrv_setfdd(1, NULL, 0); + toolwin_setfdd(1, NULL); break; case IDM_SASI1OPEN: @@ -534,19 +553,31 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT case IDM_F12MOUSE: xmenu_setf12copy(0); - keystat_resetcopyhelp(); + winkbd_resetf12(); update |= SYS_UPDATECFG; break; case IDM_F12COPY: xmenu_setf12copy(1); - keystat_resetcopyhelp(); + winkbd_resetf12(); update |= SYS_UPDATECFG; break; case IDM_F12STOP: xmenu_setf12copy(2); - keystat_resetcopyhelp(); + winkbd_resetf12(); + update |= SYS_UPDATECFG; + break; + + case IDM_F12EQU: + xmenu_setf12copy(3); + winkbd_resetf12(); + update |= SYS_UPDATECFG; + break; + + case IDM_F12COMMA: + xmenu_setf12copy(4); + winkbd_resetf12(); update |= SYS_UPDATECFG; break; @@ -810,6 +841,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT if (LOWORD(wParam) != WA_INACTIVE) { np2break &= ~NP2BREAK_MAIN; scrnmng_update(); + keystat_allrelease(); mouse_running(MOUSE_CONT_M); } else { @@ -822,34 +854,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, - 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, + HINSTANCE hinst; + RECT rect; + int width; + int height; + HBITMAP hbmp; + BITMAP bmp; + HDC hmdc; + HBRUSH hbrush; + hinst = (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE); + GetClientRect(hWnd, &rect); + width = rect.right - rect.left; + height = rect.bottom - rect.top; + hbmp = LoadBitmap(hinst, "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); -#endif + DeleteDC(hmdc); + DeleteObject(hbmp); } else { // scrnmng_update(); @@ -863,13 +892,20 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT break; case WM_MOVE: - if ((!scrnmng_isfullscreen()) && - (!(GetWindowLong(hWndMain, GWL_STYLE) & - (WS_MAXIMIZE | WS_MINIMIZE)))) { - GetWindowRect(hWnd, &rc); - np2oscfg.winx = rc.left; - np2oscfg.winy = rc.top; - sysmng_update(SYS_UPDATEOSCFG); + if (!scrnmng_isfullscreen()) { + if (!(GetWindowLong(hWnd, GWL_STYLE) & + (WS_MAXIMIZE | WS_MINIMIZE))) { + GetWindowRect(hWnd, &rc); + np2oscfg.winx = rc.left; + np2oscfg.winy = rc.top; + sysmng_update(SYS_UPDATEOSCFG); + } + if (GetWindowLong(hWnd, GWL_STYLE) & WS_MINIMIZE) { + toolwin_close(); + } + else if (np2oscfg.toolwin) { + toolwin_open(); + } } break; @@ -885,24 +921,27 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT break; case WM_ENTERSIZEMOVE: - soundmng_stop(); + soundmng_disable(SNDPROC_MAIN); mouse_running(MOUSE_STOP); - winloc_movingstart(); + winloc_movingstart(&wl); + toolwin_movingstart(); break; case WM_EXITSIZEMOVE: + toolwin_movingend(); mouse_running(MOUSE_CONT); - soundmng_play(); + soundmng_enable(SNDPROC_MAIN); break; case WM_MOVING: if (np2oscfg.WINSNAP) { - winloc_movingproc((RECT *)lParam); + winloc_movingproc(&wl, (RECT *)lParam); } break; case WM_KEYDOWN: if (wParam == VK_F11) { + scrnmng_enablemenubar(); return(DefWindowProc(hWnd, WM_SYSKEYDOWN, VK_F10, lParam)); } if ((wParam == VK_F12) && (!np2oscfg.F12COPY)) { @@ -911,15 +950,16 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT 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,17 +974,26 @@ 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; + POINT p; if ((GetCursorPos(&p)) && (p.y >= 466)) { np2oscfg.clk_x++; sysmng_update(SYS_UPDATEOSCFG); @@ -954,6 +1003,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT return(DefWindowProc(hWnd, msg, wParam, lParam)); } break; + case WM_LBUTTONUP: if (!mouse_btn(MOUSE_LEFTUP)) { return(DefWindowProc(hWnd, msg, wParam, lParam)); @@ -1071,17 +1121,18 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT } -static void processwait(WORD cnt) { +static void processwait(UINT cnt) { if (timing_getcount() >= cnt) { timing_setcount(0); framecnt = 0; scrnmng_dispclock(); - keydisp_draw(np2oscfg.DRAW_SKIP); + keydisp_draw((BYTE)cnt); + toolwin_draw((BYTE)cnt); viewer_allreload(FALSE); - if (np2oscfg.DISPCLK & 2) { + if (np2oscfg.DISPCLK & 3) { if (sysmng_workclockrenewal()) { - sysmng_updatecaption(2); + sysmng_updatecaption(3); } } } @@ -1097,7 +1148,7 @@ int WINAPI WinMain(HINSTANCE hInstance, MSG msg; HMENU hMenu; HWND hwndorg; - int i; + UINT i; #ifdef OPENING_WAIT UINT32 tick; #endif @@ -1105,12 +1156,11 @@ int WINAPI WinMain(HINSTANCE hInstance, GetModuleFileName(NULL, modulefile, sizeof(modulefile)); dosio_init(); file_setcd(modulefile); - np2arg_analize(lpszCmdLine); // タイミング修正 // ver0.29 + np2arg_analize(lpszCmdLine); initload(); + toolwin_readini(); - srand((unsigned)time(NULL)); - -// np2arg_analize(lpszCmdLine); + rand_setseed((unsigned)time(NULL)); CopyMemory(szClassName, np2oscfg.winid, 3); @@ -1124,6 +1174,8 @@ int WINAPI WinMain(HINSTANCE hInstance, hInst = hInstance; hPrev = hPreInst; + mmxflag = (havemmx())?0:MMXFLAG_NOTSUPPORT; + mmxflag += (np2oscfg.disablemmx)?MMXFLAG_DISABLE:0; TRACEINIT(); if (np2oscfg.KEYBOARD >= KEY_TYPEMAX) { // ver0.28 @@ -1140,6 +1192,7 @@ int WINAPI WinMain(HINSTANCE hInstance, } keystat_reset(); + np2class_initialize(hInstance); if (!hPreInst) { np2.style = CS_BYTEALIGNCLIENT | CS_HREDRAW | CS_VREDRAW; np2.lpfnWndProc = WndProc; @@ -1148,17 +1201,18 @@ int WINAPI WinMain(HINSTANCE hInstance, np2.hInstance = hInstance; np2.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); np2.hCursor = LoadCursor(NULL, IDC_ARROW); - np2.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); + np2.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH); np2.lpszMenuName = MAKEINTRESOURCE(IDM_MAIN); np2.lpszClassName = szClassName; if (!RegisterClass(&np2)) { return(FALSE); } } + toolwin_initapp(hInstance); keydisp_initialize(hPreInst); viewer_init(hPreInst); // ver0.30 - hWndMain = CreateWindowEx(0, szClassName, np2oscfg.titles, + hWndMain = CreateWindow(szClassName, np2oscfg.titles, WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX, np2oscfg.winx, np2oscfg.winy, 640, 400, @@ -1209,24 +1263,7 @@ int WINAPI WinMain(HINSTANCE hInstance, } InsertMenu(hMenu, 1, MF_BYPOSITION | MF_POPUP, (UINT)hStat, "S&tat"); } - - hMenu = GetSystemMenu(hWndMain, FALSE); // ver0.26 - for (i=0; i<(sizeof(smenu_item)/sizeof(SYSMENU_ITEM)); i++) { - if (smenu_item[i].str) { - InsertMenu(hMenu, i, MF_BYPOSITION | MF_STRING, - smenu_item[i].id, smenu_item[i].str); - } - else { - InsertMenu(hMenu, i, MF_BYPOSITION | MF_SEPARATOR, 0, NULL); - } - } - - if (np2oscfg.I286SAVE) { - InsertMenu(hMenu, 5, MF_BYPOSITION | MF_STRING, IDM_MEMORYDUMP, - "&Memory Dump"); - InsertMenu(hMenu, 6, MF_BYPOSITION | MF_STRING, IDM_DEBUGUTY, - "&Debug Utility"); - } + sysmenu_init(); DrawMenuBar(hWndMain); // ver0.30 @@ -1234,11 +1271,16 @@ int WINAPI WinMain(HINSTANCE hInstance, EnableMenuItem(GetMenu(hWndMain), IDM_HELP, MF_GRAYED); } + xmenu_settoolwin(np2oscfg.toolwin); xmenu_setwinsnap(np2oscfg.WINSNAP); xmenu_setbackground(np2oscfg.background); xmenu_setbgsound(np2oscfg.background); xmenu_setscrnmul(8); // ver0.26 + if (np2oscfg.toolwin) { + toolwin_open(); + } + scrnmode = 0; if (np2arg.fullscreen) { scrnmode |= SCRNMODE_FULLSCREEN; @@ -1369,22 +1411,30 @@ int WINAPI WinMain(HINSTANCE hInstance, } else { // auto skip if (!waitcnt) { + UINT cnt; joy_flash(); mouse_callback(); pccore_exec(framecnt == 0); dclock_callback(); 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); + } + processwait(0); } } else { @@ -1403,6 +1453,7 @@ int WINAPI WinMain(HINSTANCE hInstance, DispatchMessage(&msg); } } + toolwin_close(); pccore_cfgupdate(); @@ -1413,7 +1464,7 @@ int WINAPI WinMain(HINSTANCE hInstance, flagsave(np2resume); } else { -// DeleteFile(file_getcd(np2resume)); + flagdelete(np2resume); } #ifdef USE_ROMEO @@ -1432,6 +1483,7 @@ int WINAPI WinMain(HINSTANCE hInstance, if (sys_updates & (SYS_UPDATECFG | SYS_UPDATEOSCFG)) { initsave(); + toolwin_writeini(); } TRACETERM();