--- np2/wince/np2.cpp 2003/12/01 17:13:36 1.3 +++ np2/wince/np2.cpp 2005/02/11 21:17:23 1.21 @@ -29,26 +29,37 @@ #include "fddfile.h" #include "font.h" #include "timing.h" -#include "statsave.h" +#include "keystat.h" #include "vramhdl.h" #include "menubase.h" #include "sysmenu.h" -#if defined(SUPPORT_SOFTKBD) #include "softkbd.h" -#endif -static const TCHAR szAppCaption[] = STRLITERAL("Neko Project II"); -static const TCHAR szClassName[] = STRLITERAL("NP2-MainWindow"); +static const TCHAR szAppCaption[] = _T("Neko Project II"); +static const TCHAR szClassName[] = _T("NP2-MainWindow"); - NP2OSCFG np2oscfg = {0, 2, 0, 0}; + NP2OSCFG np2oscfg = {0, 0, 0, 0, +#if !defined(GX_DLL) + CW_USEDEFAULT, CW_USEDEFAULT, +#endif +#if defined(WIN32_PLATFORM_PSPC) + 0, 0, +#endif + 0}; HWND hWndMain; HINSTANCE hInst; HINSTANCE hPrev; - char modulefile[MAX_PATH]; + OEMCHAR modulefile[MAX_PATH]; + GXKeyList gx_keylist; + +enum { + SYSRUNNING_MAIN = 1, + SYSRUNNING_FORE = 2 +}; -static BOOL sysrunning; +static UINT sysrunning; static UINT framecnt; static UINT waitcnt; static UINT framemax = 1; @@ -56,7 +67,7 @@ static UINT framemax = 1; // ---- resume -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); @@ -64,12 +75,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)); ret = statsave_save(path); if (ret) { file_delete(path); @@ -77,31 +88,31 @@ 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]; - char buf2[1024 + 256]; + OEMCHAR path[MAX_PATH]; + OEMCHAR buf[1024]; + OEMCHAR buf2[1024 + 256]; - getstatfilename(path, ext, sizeof(path)); + getstatfilename(path, ext, NELEMENTS(path)); id = DID_YES; - ret = statsave_check(path, buf, sizeof(buf)); - if (ret & (~NP2FLAG_DISKCHG)) { + ret = statsave_check(path, buf, NELEMENTS(buf)); + if (ret & (~STATFLAG_DISKCHG)) { menumbox("Couldn't restart", title, MBOX_OK | MBOX_ICONSTOP); id = DID_NO; } - else if ((!force) && (ret & NP2FLAG_DISKCHG)) { - SPRINTF(buf2, "Conflict!\n\n%s\nContinue?", buf); + else if ((!force) && (ret & STATFLAG_DISKCHG)) { + OEMSPRINTF(buf2, "Conflict!\n\n%s\nContinue?", buf); id = menumbox(buf2, title, MBOX_YESNOCAN | MBOX_ICONQUESTION); } if (id == DID_YES) { @@ -164,7 +175,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT winkbd_keyup(wParam, lParam); break; -#if !defined(_WIN32_WCE) +#if 1 // !defined(_WIN32_WCE) case WM_SYSKEYDOWN: winkbd_keydown(wParam, lParam); break; @@ -187,7 +198,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT if (menuvram) { menubase_moving(LOWORD(lParam), HIWORD(lParam), 1); } - else { + else if (scrnmng_kbdpos(&lParam) == SUCCESS) { #if defined(SUPPORT_SOFTKBD) softkbd_down(LOWORD(lParam), HIWORD(lParam)); #endif @@ -197,25 +208,33 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT case WM_LBUTTONUP: if (scrnmng_mousepos(&lParam) == SUCCESS) { - #if defined(SUPPORT_SOFTKBD) softkbd_up(); +#endif if (menuvram) { menubase_moving(LOWORD(lParam), HIWORD(lParam), 2); } - else if ((LOWORD(lParam) < 32) && (HIWORD(lParam) >= 208)) { - sysmenu_menuopen(0, LOWORD(lParam), HIWORD(lParam)); - } -#else - if (menuvram) { - menubase_moving(LOWORD(lParam), HIWORD(lParam), 2); - } - else { + else if (scrnmng_ismenu(lParam)) { sysmenu_menuopen(0, LOWORD(lParam), HIWORD(lParam)); } + } + break; + +#if !defined(GX_DLL) + case WM_MOVE: +#if !defined(_WIN32_WCE) + if (!(GetWindowLong(hWnd, GWL_STYLE) & + (WS_MAXIMIZE | WS_MINIMIZE))) #endif + { + RECT rc; + GetWindowRect(hWnd, &rc); + np2oscfg.winx = rc.left; + np2oscfg.winy = rc.top; + sysmng_update(SYS_UPDATEOSCFG); } break; +#endif #if !defined(_WIN32_WCE) case WM_ENTERSIZEMOVE: @@ -240,13 +259,19 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT if (sysrunning) { if (LOWORD(wParam) != WA_INACTIVE) { GXResume(); +#if defined(GX_DLL) scrnmng_enable(TRUE); +#endif scrndraw_redraw(); soundmng_enable(SNDPROC_MAIN); + sysrunning |= SYSRUNNING_FORE; } else { + sysrunning &= ~SYSRUNNING_FORE; soundmng_disable(SNDPROC_MAIN); +#if defined(GX_DLL) scrnmng_enable(FALSE); +#endif GXSuspend(); } } @@ -273,45 +298,59 @@ static void processwait(UINT cnt) { timing_setcount(0); framereset(cnt); } +#if !defined(_WIN32_WCE) else { Sleep(1); } +#endif } // ---- -#if !defined(UNICODE) -#define GetModuleFileName_A(a, b, c) GetModuleFileName(a, b, c) -#else -static DWORD GetModuleFileName_A(HMODULE hModule, - LPSTR lpFileName, DWORD nSize) { +#if defined(UNICODE) && defined(OSLANG_SJIS) +static DWORD _GetModuleFileName(HMODULE hModule, + OEMCHAR *lpFileName, DWORD nSize) { - TCHAR *FileNameW; - DWORD len; + UINT16 ucs2[MAX_PATH]; - if (nSize) { - FileNameW = (TCHAR *)_MALLOC(nSize * sizeof(TCHAR), "ModuleFile"); - if (FileNameW) { - len = GetModuleFileName(hModule, FileNameW, nSize); - nSize = WideCharToMultiByte(CP_ACP, 0, FileNameW, -1, + GetModuleFileName(hModule, ucs2, NELEMENTS(ucs2)); + nSize = WideCharToMultiByte(CP_ACP, 0, ucs2, -1, lpFileName, nSize, NULL, NULL); - if (nSize) { - nSize--; - } - _MFREE(FileNameW); - } - else { - nSize = 0; - } + if (nSize) { + nSize--; + } + return(nSize); +} +#elif defined(OSLANG_UTF8) +static DWORD _GetModuleFileName(HMODULE hModule, + OEMCHAR *lpFileName, DWORD nSize) { + + UINT16 ucs2[MAX_PATH]; + + GetModuleFileName(hModule, ucs2, NELEMENTS(ucs2)); + nSize = ucscnv_ucs2toutf8(lpFileName, nSize, ucs2, (UINT)-1); + if (nSize) { + nSize--; } return(nSize); } +#else +#define _GetModuleFileName(a, b, c) GetModuleFileName(a, b, c) #endif -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInst, - LPTSTR lpszCmdLine, int nCmdShow) { +#if defined(_WIN32_WCE) +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInst, + LPWSTR lpszCmdLine, int nCmdShow) +#elif defined(UNICODE) +int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPreInst, + LPSTR lpszCmdLine, int nCmdShow) +#else +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInst, + LPSTR lpszCmdLine, int nCmdShow) +#endif +{ HWND hWnd; WNDCLASS np2; int id; @@ -329,7 +368,7 @@ int WINAPI WinMain(HINSTANCE hInstance, return(0); } - GetModuleFileName_A(NULL, modulefile, sizeof(modulefile)); + _GetModuleFileName(NULL, modulefile, NELEMENTS(modulefile)); dosio_init(); file_setcd(modulefile); initload(); @@ -341,7 +380,7 @@ int WINAPI WinMain(HINSTANCE hInstance, TRACEINIT(); inputmng_init(); - keystat_reset(); + keystat_initialize(); // if (!hPreInst) { np2.style = CS_HREDRAW | CS_VREDRAW; @@ -359,16 +398,17 @@ int WINAPI WinMain(HINSTANCE hInstance, } // } -#if !defined(WIN32_PLATFORM_PSPC) +#if !defined(GX_DLL) hWnd = CreateWindow(szClassName, szAppCaption, WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX, - 0, 0, FULLSCREEN_WIDTH, FULLSCREEN_HEIGHT, + np2oscfg.winx, np2oscfg.winy, + FULLSCREEN_WIDTH, FULLSCREEN_HEIGHT, NULL, NULL, hInstance, NULL); #else hWnd = CreateWindow(szClassName, szAppCaption, WS_VISIBLE, - 0, 0, + 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), NULL, NULL, hInstance, NULL); @@ -389,7 +429,7 @@ int WINAPI WinMain(HINSTANCE hInstance, } if (scrnmng_create(hWnd, FULLSCREEN_WIDTH, FULLSCREEN_HEIGHT) != SUCCESS) { - MessageBox(hWnd, STRLITERAL("Couldn't create DirectDraw Object"), + MessageBox(hWnd, _T("Couldn't create DirectDraw Object"), szAppCaption, MB_OK | MB_ICONSTOP); DestroyWindow(hWnd); goto np2main_err2; @@ -399,6 +439,11 @@ int WINAPI WinMain(HINSTANCE hInstance, DestroyWindow(hWnd); goto np2main_err3; } + gx_keylist = GXGetDefaultKeys(GX_NORMALKEYS); + scrnmng_keybinds(); +#if defined(WIN32_PLATFORM_PSPC) + winkbd_bindinit(); +#endif soundmng_initialize(); commng_initialize(); @@ -410,7 +455,12 @@ int WINAPI WinMain(HINSTANCE hInstance, pccore_reset(); scrndraw_redraw(); - sysrunning = TRUE; +#if defined(WIN32_PLATFORM_PSPC) + winkbd_bindcur(np2oscfg.bindcur); + winkbd_bindbtn(np2oscfg.bindbtn); +#endif + + sysrunning |= SYSRUNNING_MAIN | SYSRUNNING_FORE; if (np2oscfg.resume) { id = flagload(str_sav, str_resume, FALSE); @@ -425,7 +475,7 @@ int WINAPI WinMain(HINSTANCE hInstance, if (!GetMessage(&msg, NULL, 0, 0)) { break; } -#if !defined(_WIN32_WCE) +#if 1 // !defined(_WIN32_WCE) if ((msg.hwnd != hWnd) || ((msg.message != WM_SYSKEYDOWN) && (msg.message != WM_SYSKEYUP))) { @@ -436,7 +486,7 @@ int WINAPI WinMain(HINSTANCE hInstance, #endif DispatchMessage(&msg); } - else { + else if (sysrunning & SYSRUNNING_FORE) { if (np2oscfg.NOWAIT) { pccore_exec(framecnt == 0); if (np2oscfg.DRAW_SKIP) { // nowait frame skip @@ -492,6 +542,9 @@ int WINAPI WinMain(HINSTANCE hInstance, } } } + else { + Sleep(100); + } } soundmng_disable(SNDPROC_MAIN);