--- np2/win9x/np2.cpp 2004/06/14 13:35:40 1.55 +++ np2/win9x/np2.cpp 2007/01/08 08:52:21 1.71 @@ -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,56 +43,100 @@ #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 #define OPENING_WAIT 1500 #endif -static char szClassName[] = "NP2-MainWindow"; +static TCHAR szClassName[] = _T("NP2-MainWindow"); HWND hWndMain; HINSTANCE hInst; HINSTANCE hPrev; +#if !defined(_WIN64) int mmxflag; - BYTE np2break = 0; // ver0.30 +#endif + UINT8 np2break = 0; // ver0.30 BOOL winui_en; NP2OSCFG np2oscfg = { -#if !defined(SUPPORT_PC9821) - "Neko Project II", -#else - "Neko Project 21", -#endif - "NP2", - CW_USEDEFAULT, CW_USEDEFAULT, 1, 1, 0, 1, 0, 0, + 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, 0, 0, 0, 0, 0, 0, 0}; + 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 modulefile[MAX_PATH]; + 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 BYTE np2stopemulate = 0; +static UINT8 np2stopemulate = 0; static int np2opening = 1; static int np2quitmsg = 0; static HMENU hStat = NULL; -static BYTE scrnmode; +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) { -static const char np2help[] = "np2.chm"; -static const char np2flagext[] = "S%02d"; + 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; @@ -132,10 +174,10 @@ WINLOCEX np2_winlocexallwin(HWND base) { return(winlocex_create(base, list, cnt)); } -static void changescreen(BYTE newmode) { +static void changescreen(UINT8 newmode) { - BYTE change; - BYTE renewal; + UINT8 change; + UINT8 renewal; WINLOCEX wlex; change = scrnmode ^ newmode; @@ -244,7 +286,7 @@ void np2active_renewal(void) { // ---- resume and statsave #if defined(SUPPORT_RESUME) || defined(SUPPORT_STATSAVE) -static void getstatfilename(char *path, const char *ext, int size) { +static void getstatfilename(OEMCHAR *path, const OEMCHAR *ext, int size) { file_cpyname(path, modulefile, size); file_cutext(path); @@ -252,12 +294,12 @@ static void getstatfilename(char *path, file_catname(path, ext, size); } -static int flagsave(const char *ext) { +static int flagsave(const OEMCHAR *ext) { int ret; - char path[MAX_PATH]; + OEMCHAR path[MAX_PATH]; - getstatfilename(path, ext, sizeof(path)); + getstatfilename(path, ext, NELEMENTS(path)); soundmng_stop(); ret = statsave_save(path); if (ret) { @@ -267,32 +309,33 @@ static int flagsave(const char *ext) { return(ret); } -static void flagdelete(const char *ext) { +static void flagdelete(const OEMCHAR *ext) { - char path[MAX_PATH]; + OEMCHAR path[MAX_PATH]; - getstatfilename(path, ext, sizeof(path)); + getstatfilename(path, ext, NELEMENTS(path)); file_delete(path); } -static int flagload(const char *ext, const char *title, BOOL force) { +static int flagload(const OEMCHAR *ext, const OEMCHAR *title, BOOL force) { int ret; int id; - char path[MAX_PATH]; - char buf[1024]; + OEMCHAR path[MAX_PATH]; + OEMCHAR buf[1024]; - getstatfilename(path, ext, sizeof(path)); + getstatfilename(path, ext, NELEMENTS(path)); winuienter(); id = IDYES; - ret = statsave_check(path, buf, sizeof(buf)); + ret = statsave_check(path, buf, NELEMENTS(buf)); if (ret & (~STATFLAG_DISKCHG)) { - MessageBox(hWndMain, "Couldn't restart", title, MB_OK | MB_ICONSTOP); + MessageBox(hWndMain, _T("Couldn't restart"), title, + MB_OK | MB_ICONSTOP); id = IDNO; } else if ((!force) && (ret & STATFLAG_DISKCHG)) { - char buf2[1024 + 256]; - wsprintf(buf2, "Conflict!\n\n%s\nContinue?", buf); + OEMCHAR buf2[1024 + 256]; + OEMSPRINTF(buf2, OEMTEXT("Conflict!\n\n%s\nContinue?"), buf); id = MessageBox(hWndMain, buf2, title, MB_YESNOCANCEL | MB_ICONQUESTION); } @@ -317,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; } @@ -332,9 +375,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 = (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE); update = 0; switch(cmd) { case IDM_RESET: @@ -344,7 +389,7 @@ static void np2cmd(HWND hWnd, UINT16 cmd } else if (sstpconfirm_reset()) { winuienter(); - if (MessageBox(hWnd, "Sure?", "Reset", + if (MessageBox(hWnd, OEMTEXT("Sure?"), OEMTEXT("Reset"), MB_ICONQUESTION | MB_YESNO) == IDYES) { b = TRUE; } @@ -361,10 +406,10 @@ static void np2cmd(HWND hWnd, UINT16 cmd case IDM_CONFIG: winuienter(); sstpmsg_config(); - DialogBox(hInst, MAKEINTRESOURCE(IDD_CONFIG), + DialogBox(hinst, MAKEINTRESOURCE(IDD_CONFIG), hWnd, (DLGPROC)CfgDialogProc); if (!scrnmng_isfullscreen()) { - BYTE thick; + UINT8 thick; thick = (GetWindowLong(hWnd, GWL_STYLE) & WS_THICKFRAME)?1:0; if (thick != np2oscfg.thickframe) { WINLOCEX wlex; @@ -438,25 +483,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(); @@ -498,6 +556,7 @@ static void np2cmd(HWND hWnd, UINT16 cmd diskdrv_sethdd(0x23, NULL); break; #endif + case IDM_WINDOW: changescreen(scrnmode & (~SCRNMODE_FULLSCREEN)); break; @@ -788,7 +847,7 @@ static void np2cmd(HWND hWnd, UINT16 cmd case IDM_MPUPC98: winuienter(); - DialogBox(hInst, MAKEINTRESOURCE(IDD_MPUPC98), + DialogBox(hinst, MAKEINTRESOURCE(IDD_MPUPC98), hWnd, (DLGPROC)MidiDialogProc); winuileave(); break; @@ -836,7 +895,7 @@ static void np2cmd(HWND hWnd, UINT16 cmd case IDM_CALENDAR: winuienter(); - DialogBox(hInst, MAKEINTRESOURCE(IDD_CALENDAR), + DialogBox(hinst, MAKEINTRESOURCE(IDD_CALENDAR), hWnd, (DLGPROC)ClndDialogProc); winuileave(); break; @@ -871,7 +930,7 @@ static void np2cmd(HWND hWnd, UINT16 cmd update |= SYS_UPDATECFG; break; - case IDM_I286SAVE: + case IDM_CPUSAVE: debugsub_status(); break; @@ -884,7 +943,7 @@ static void np2cmd(HWND hWnd, UINT16 cmd sstpmsg_about(); if (sstp_result() != SSTP_SENDING) { winuienter(); - DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUT), + DialogBox(hinst, MAKEINTRESOURCE(IDD_ABOUT), hWnd, (DLGPROC)AboutDialogProc); winuileave(); } @@ -894,15 +953,15 @@ static void np2cmd(HWND hWnd, UINT16 cmd #if defined(SUPPORT_STATSAVE) if ((cmd >= IDM_FLAGSAVE) && (cmd < (IDM_FLAGSAVE + SUPPORT_STATSAVE))) { - char ext[4]; - SPRINTF(ext, np2flagext, cmd - IDM_FLAGSAVE); + OEMCHAR ext[4]; + OEMSPRINTF(ext, np2flagext, cmd - IDM_FLAGSAVE); flagsave(ext); } else if ((cmd >= IDM_FLAGLOAD) && (cmd < (IDM_FLAGLOAD + SUPPORT_STATSAVE))) { - char ext[4]; - SPRINTF(ext, np2flagext, cmd - IDM_FLAGLOAD); - flagload(ext, "Status Load", TRUE); + OEMCHAR ext[4]; + OEMSPRINTF(ext, np2flagext, cmd - IDM_FLAGLOAD); + flagload(ext, OEMTEXT("Status Load"), TRUE); } #endif break; @@ -1007,8 +1066,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT case IDM_SCRNMUL16: if ((!scrnmng_isfullscreen()) && !(GetWindowLong(hWndMain, GWL_STYLE) & WS_MINIMIZE)) { - sysmenu_setscrnmul(wParam - IDM_SCRNMUL); - scrnmng_setmultiple(wParam - IDM_SCRNMUL); + sysmenu_setscrnmul((UINT8)(wParam - IDM_SCRNMUL)); + scrnmng_setmultiple((int)(wParam - IDM_SCRNMUL)); } break; @@ -1072,11 +1131,11 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT BITMAP bmp; HDC hmdc; HBRUSH hbrush; - hinst = (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE); + hinst = (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE); GetClientRect(hWnd, &rect); width = rect.right - rect.left; height = rect.bottom - rect.top; - hbmp = LoadBitmap(hinst, "NP2BMP"); + hbmp = LoadBitmap(hinst, _T("NP2BMP")); GetObject(hbmp, sizeof(BITMAP), &bmp); hbrush = (HBRUSH)SelectObject(hdc, GetStockObject(BLACK_BRUSH)); @@ -1209,14 +1268,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; @@ -1238,15 +1300,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; @@ -1279,7 +1344,7 @@ 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; } @@ -1360,11 +1425,13 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT static void framereset(UINT cnt) { framecnt = 0; +#if defined(SUPPORT_DCLOCK) scrnmng_dispclock(); - kdispwin_draw((BYTE)cnt); +#endif + kdispwin_draw((UINT8)cnt); skbdwin_process(); mdbgwin_process(); - toolwin_draw((BYTE)cnt); + toolwin_draw((UINT8)cnt); viewer_allreload(FALSE); if (np2oscfg.DISPCLK & 3) { if (sysmng_workclockrenewal()) { @@ -1385,7 +1452,6 @@ static void processwait(UINT cnt) { soundmng_sync(); } - int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInst, LPSTR lpszCmdLine, int nCmdShow) { WNDCLASS wc; @@ -1400,10 +1466,10 @@ int WINAPI WinMain(HINSTANCE hInstance, _MEM_INIT(); - GetModuleFileName(NULL, modulefile, sizeof(modulefile)); + GetModuleFileName(NULL, modulefile, NELEMENTS(modulefile)); dosio_init(); file_setcd(modulefile); - np2arg_analize(lpszCmdLine); + np2arg_analize(); initload(); toolwin_readini(); kdispwin_readini(); @@ -1412,7 +1478,9 @@ int WINAPI WinMain(HINSTANCE hInstance, rand_setseed((unsigned)time(NULL)); - CopyMemory(szClassName, np2oscfg.winid, 3); + szClassName[0] = (TCHAR)np2oscfg.winid[0]; + szClassName[1] = (TCHAR)np2oscfg.winid[1]; + szClassName[2] = (TCHAR)np2oscfg.winid[2]; if ((hWnd = FindWindow(szClassName, NULL)) != NULL) { sstpmsg_running(); @@ -1422,10 +1490,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); @@ -1446,23 +1516,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.cbWndExtra = NP2GWLP_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); } } - toolwin_initapp(hInstance); + toolwin_initapp(hInst); kdispwin_initialize(hPreInst); skbdwin_initialize(hPreInst); mdbgwin_initialize(hPreInst); @@ -1476,7 +1549,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(); @@ -1536,16 +1609,19 @@ int WINAPI WinMain(HINSTANCE hInstance, scrnmode ^= SCRNMODE_FULLSCREEN; if (scrnmng_create(scrnmode) != SUCCESS) { if (sstpmsg_dxerror()) { - MessageBox(hWnd, "Couldn't create DirectDraw Object", + MessageBox(hWnd, _T("Couldn't create DirectDraw Object"), np2oscfg.titles, MB_OK | MB_ICONSTOP); } + unloadextinst(); + TRACETERM(); + dosio_term(); return(FALSE); } } if (soundmng_initialize() == SUCCESS) { - soundmng_pcmload(SOUND_PCMSEEK, "SEEKWAV", EXTROMIO_RES); - soundmng_pcmload(SOUND_PCMSEEK1, "SEEK1WAV", EXTROMIO_RES); + soundmng_pcmload(SOUND_PCMSEEK, OEMTEXT("SEEKWAV"), EXTROMIO_RES); + soundmng_pcmload(SOUND_PCMSEEK1, OEMTEXT("SEEK1WAV"), EXTROMIO_RES); soundmng_pcmvolume(SOUND_PCMSEEK, np2cfg.MOTORVOL); soundmng_pcmvolume(SOUND_PCMSEEK1, np2cfg.MOTORVOL); } @@ -1584,7 +1660,9 @@ int WINAPI WinMain(HINSTANCE hInstance, id = flagload(str_sav, str_resume, FALSE); if (id == IDYES) { - for (i=0; i<4; i++) np2arg.disk[i] = NULL; + for (i=0; i<4; i++) { + np2arg.disk[i] = NULL; + } } else if (id == IDCANCEL) { DestroyWindow(hWnd); @@ -1594,10 +1672,11 @@ int WINAPI WinMain(HINSTANCE hInstance, sstp_destruct(); soundmng_deinitialize(); scrnmng_destroy(); + unloadextinst(); TRACETERM(); dosio_term(); viewer_term(); - return(0); + return(FALSE); } } #endif @@ -1605,8 +1684,7 @@ int WINAPI WinMain(HINSTANCE hInstance, // リセットしてから… コマンドラインのディスク挿入。 for (i=0; i<4; i++) { if (np2arg.disk[i]) { - milstr_ncpy(diskdrv_fname[i], np2arg.disk[i], MAX_PATH); - diskdrv_delay[i] = 1; + diskdrv_readyfdd((REG8)i, np2arg.disk[i], 0); } } @@ -1637,7 +1715,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) { @@ -1656,7 +1736,9 @@ int WINAPI WinMain(HINSTANCE hInstance, joymng_sync(); mousemng_sync(); pccore_exec(framecnt == 0); +#if defined(SUPPORT_DCLOCK) dclock_callback(); +#endif framecnt++; } else { @@ -1669,7 +1751,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) { @@ -1745,12 +1829,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); }