| version 1.1, 2003/11/24 11:46:54 | version 1.23, 2005/03/24 04:40:33 | 
| Line 5 | Line 5 | 
 | #endif | #endif | 
 | #include        "resource.h" | #include        "resource.h" | 
 | #include        "strres.h" | #include        "strres.h" | 
 |  | #if defined(UNICODE) && defined(OSLANG_UTF8) | 
 |  | #include        "codecnv.h" | 
 |  | #endif | 
 | #include        "np2.h" | #include        "np2.h" | 
 | #include        "dosio.h" | #include        "dosio.h" | 
 | #include        "commng.h" | #include        "commng.h" | 
| Line 29 | Line 32 | 
 | #include        "fddfile.h" | #include        "fddfile.h" | 
 | #include        "font.h" | #include        "font.h" | 
 | #include        "timing.h" | #include        "timing.h" | 
| #include        "statsave.h" | #include        "keystat.h" | 
 | #include        "vramhdl.h" | #include        "vramhdl.h" | 
 | #include        "menubase.h" | #include        "menubase.h" | 
 | #include        "sysmenu.h" | #include        "sysmenu.h" | 
 |  | #include        "softkbd.h" | 
 |  |  | 
 |  |  | 
| static const TCHAR szAppCaption[] = STRLITERAL("Neko Project II"); | static const TCHAR szAppCaption[] = _T("Neko Project II"); | 
| static const TCHAR szClassName[] = STRLITERAL("NP2-MainWindow"); | 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; | HWND            hWndMain; | 
 | HINSTANCE       hInst; | HINSTANCE       hInst; | 
 | HINSTANCE       hPrev; | 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            framecnt; | 
 | static  UINT            waitcnt; | static  UINT            waitcnt; | 
 | static  UINT            framemax = 1; | static  UINT            framemax = 1; | 
| Line 53  static UINT  framemax = 1; | Line 70  static UINT  framemax = 1; | 
 |  |  | 
 | // ---- resume | // ---- 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_cpyname(path, modulefile, size); | 
 | file_cutext(path); | file_cutext(path); | 
| Line 61  static void getstatfilename(char *path, | Line 78  static void getstatfilename(char *path, | 
 | file_catname(path, ext, size); | file_catname(path, ext, size); | 
 | } | } | 
 |  |  | 
| static int flagsave(const char *ext) { | static int flagsave(const OEMCHAR *ext) { | 
 |  |  | 
 | int             ret; | int             ret; | 
| char    path[MAX_PATH]; | OEMCHAR path[MAX_PATH]; | 
 |  |  | 
| getstatfilename(path, ext, sizeof(path)); | getstatfilename(path, ext, NELEMENTS(path)); | 
 | ret = statsave_save(path); | ret = statsave_save(path); | 
 | if (ret) { | if (ret) { | 
 | file_delete(path); | file_delete(path); | 
| Line 74  static int flagsave(const char *ext) { | Line 91  static int flagsave(const char *ext) { | 
 | return(ret); | 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); | 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             ret; | 
 | int             id; | int             id; | 
| char    path[MAX_PATH]; | OEMCHAR path[MAX_PATH]; | 
| char    buf[1024]; | OEMCHAR buf[1024]; | 
| char    buf2[1024 + 256]; | OEMCHAR buf2[1024 + 256]; | 
 |  |  | 
| getstatfilename(path, ext, sizeof(path)); | getstatfilename(path, ext, NELEMENTS(path)); | 
 | id = DID_YES; | id = DID_YES; | 
| ret = statsave_check(path, buf, sizeof(buf)); | ret = statsave_check(path, buf, NELEMENTS(buf)); | 
| if (ret & (~NP2FLAG_DISKCHG)) { | if (ret & (~STATFLAG_DISKCHG)) { | 
| menumbox("Couldn't restart", title, MBOX_OK | MBOX_ICONSTOP); | menumbox(OEMTEXT("Couldn't restart"), title, MBOX_OK | MBOX_ICONSTOP); | 
 | id = DID_NO; | id = DID_NO; | 
 | } | } | 
| else if ((!force) && (ret & NP2FLAG_DISKCHG)) { | else if ((!force) && (ret & STATFLAG_DISKCHG)) { | 
| SPRINTF(buf2, "Conflict!\n\n%s\nContinue?", buf); | OEMSPRINTF(buf2, OEMTEXT("Conflict!\n\n%s\nContinue?"), buf); | 
 | id = menumbox(buf2, title, MBOX_YESNOCAN | MBOX_ICONQUESTION); | id = menumbox(buf2, title, MBOX_YESNOCAN | MBOX_ICONQUESTION); | 
 | } | } | 
 | if (id == DID_YES) { | if (id == DID_YES) { | 
| Line 135  LRESULT CALLBACK WndProc(HWND hWnd, UINT | Line 152  LRESULT CALLBACK WndProc(HWND hWnd, UINT | 
 | EndPaint(hWnd, &ps); | EndPaint(hWnd, &ps); | 
 | break; | break; | 
 |  |  | 
 |  | #if defined(WIN32_PLATFORM_PSPC) | 
 |  | case WM_ERASEBKGND: | 
 |  | if (sysrunning) { | 
 |  | scrndraw_redraw(); | 
 |  | } | 
 |  | break; | 
 |  | #endif | 
 |  |  | 
 | case WM_KEYDOWN: | case WM_KEYDOWN: | 
 | if (wParam == VK_F11) { | if (wParam == VK_F11) { | 
 | if (menuvram == NULL) { | if (menuvram == NULL) { | 
| Line 153  LRESULT CALLBACK WndProc(HWND hWnd, UINT | Line 178  LRESULT CALLBACK WndProc(HWND hWnd, UINT | 
 | winkbd_keyup(wParam, lParam); | winkbd_keyup(wParam, lParam); | 
 | break; | break; | 
 |  |  | 
| #if !defined(_WIN32_WCE) | #if 1 // !defined(_WIN32_WCE) | 
 | case WM_SYSKEYDOWN: | case WM_SYSKEYDOWN: | 
 | winkbd_keydown(wParam, lParam); | winkbd_keydown(wParam, lParam); | 
 | break; | break; | 
| Line 165  LRESULT CALLBACK WndProc(HWND hWnd, UINT | Line 190  LRESULT CALLBACK WndProc(HWND hWnd, UINT | 
 |  |  | 
 | case WM_MOUSEMOVE: | case WM_MOUSEMOVE: | 
 | if (scrnmng_mousepos(&lParam) == SUCCESS) { | if (scrnmng_mousepos(&lParam) == SUCCESS) { | 
| if (menuvram == NULL) { | if (menuvram) { | 
| } |  | 
| else { |  | 
 | menubase_moving(LOWORD(lParam), HIWORD(lParam), 0); | menubase_moving(LOWORD(lParam), HIWORD(lParam), 0); | 
 | } | } | 
 | } | } | 
| Line 175  LRESULT CALLBACK WndProc(HWND hWnd, UINT | Line 198  LRESULT CALLBACK WndProc(HWND hWnd, UINT | 
 |  |  | 
 | case WM_LBUTTONDOWN: | case WM_LBUTTONDOWN: | 
 | if (scrnmng_mousepos(&lParam) == SUCCESS) { | if (scrnmng_mousepos(&lParam) == SUCCESS) { | 
| if (menuvram == NULL) { | if (menuvram) { | 
| } |  | 
| else { |  | 
 | menubase_moving(LOWORD(lParam), HIWORD(lParam), 1); | menubase_moving(LOWORD(lParam), HIWORD(lParam), 1); | 
 | } | } | 
 |  | else if (scrnmng_kbdpos(&lParam) == SUCCESS) { | 
 |  | #if defined(SUPPORT_SOFTKBD) | 
 |  | softkbd_down(LOWORD(lParam), HIWORD(lParam)); | 
 |  | #endif | 
 |  | } | 
 | } | } | 
 | break; | break; | 
 |  |  | 
 | case WM_LBUTTONUP: | case WM_LBUTTONUP: | 
 | if (scrnmng_mousepos(&lParam) == SUCCESS) { | if (scrnmng_mousepos(&lParam) == SUCCESS) { | 
| if (menuvram == NULL) { | #if defined(SUPPORT_SOFTKBD) | 
| sysmenu_menuopen(0, LOWORD(lParam), HIWORD(lParam)); | softkbd_up(); | 
| } | #endif | 
| else { | if (menuvram) { | 
 | menubase_moving(LOWORD(lParam), HIWORD(lParam), 2); | menubase_moving(LOWORD(lParam), HIWORD(lParam), 2); | 
 | } | } | 
 |  | 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; | break; | 
 |  | #endif | 
 |  |  | 
 | #if !defined(_WIN32_WCE) | #if !defined(_WIN32_WCE) | 
 | case WM_ENTERSIZEMOVE: | case WM_ENTERSIZEMOVE: | 
| Line 217  LRESULT CALLBACK WndProc(HWND hWnd, UINT | Line 262  LRESULT CALLBACK WndProc(HWND hWnd, UINT | 
 | if (sysrunning) { | if (sysrunning) { | 
 | if (LOWORD(wParam) != WA_INACTIVE) { | if (LOWORD(wParam) != WA_INACTIVE) { | 
 | GXResume(); | GXResume(); | 
 |  | #if defined(GX_DLL) | 
 | scrnmng_enable(TRUE); | scrnmng_enable(TRUE); | 
 |  | #endif | 
 | scrndraw_redraw(); | scrndraw_redraw(); | 
 | soundmng_enable(SNDPROC_MAIN); | soundmng_enable(SNDPROC_MAIN); | 
 |  | sysrunning |= SYSRUNNING_FORE; | 
 | } | } | 
 | else { | else { | 
 |  | sysrunning &= ~SYSRUNNING_FORE; | 
 | soundmng_disable(SNDPROC_MAIN); | soundmng_disable(SNDPROC_MAIN); | 
 |  | #if defined(GX_DLL) | 
 | scrnmng_enable(FALSE); | scrnmng_enable(FALSE); | 
 |  | #endif | 
 | GXSuspend(); | GXSuspend(); | 
 | } | } | 
 | } | } | 
| Line 250  static void processwait(UINT cnt) { | Line 301  static void processwait(UINT cnt) { | 
 | timing_setcount(0); | timing_setcount(0); | 
 | framereset(cnt); | framereset(cnt); | 
 | } | } | 
 |  | #if !defined(_WIN32_WCE) | 
 | else { | else { | 
 | Sleep(1); | Sleep(1); | 
 | } | } | 
 |  | #endif | 
 | } | } | 
 |  |  | 
 |  |  | 
 | // ---- | // ---- | 
 |  |  | 
| #if !defined(UNICODE) | #if defined(UNICODE) && defined(OSLANG_SJIS) | 
| #define GetModuleFileName_A(a, b, c)    GetModuleFileName(a, b, c) | static DWORD _GetModuleFileName(HMODULE hModule, | 
| #else | OEMCHAR *lpFileName, DWORD nSize) { | 
| static DWORD GetModuleFileName_A(HMODULE hModule, |  | 
| LPSTR lpFileName, DWORD nSize) { |  | 
 |  |  | 
| TCHAR   *FileNameW; | UINT16  ucs2[MAX_PATH]; | 
| DWORD   len; |  | 
 |  |  | 
| if (nSize) { | GetModuleFileName(hModule, ucs2, NELEMENTS(ucs2)); | 
| FileNameW = (TCHAR *)_MALLOC(nSize * sizeof(TCHAR), "ModuleFile"); | nSize = WideCharToMultiByte(CP_ACP, 0, ucs2, -1, | 
| if (FileNameW) { |  | 
| len = GetModuleFileName(hModule, FileNameW, nSize); |  | 
| nSize = WideCharToMultiByte(CP_ACP, 0, FileNameW, -1, |  | 
 | lpFileName, nSize, NULL, NULL); | lpFileName, nSize, NULL, NULL); | 
| if (nSize) { | if (nSize) { | 
| nSize--; | nSize--; | 
| } |  | 
| _MFREE(FileNameW); |  | 
| } |  | 
| else { |  | 
| nSize = 0; |  | 
| } |  | 
 | } | } | 
 | return(nSize); | return(nSize); | 
 | } | } | 
 |  | #elif defined(UNICODE) && defined(OSLANG_UTF8) | 
 |  | static DWORD _GetModuleFileName(HMODULE hModule, | 
 |  | OEMCHAR *lpFileName, DWORD nSize) { | 
 |  |  | 
 |  | UINT16  ucs2[MAX_PATH]; | 
 |  |  | 
 |  | GetModuleFileName(hModule, ucs2, NELEMENTS(ucs2)); | 
 |  | nSize = codecnv_ucs2toutf8(lpFileName, nSize, ucs2, (UINT)-1); | 
 |  | if (nSize) { | 
 |  | nSize--; | 
 |  | } | 
 |  | return(nSize); | 
 |  | } | 
 |  | #else | 
 |  | #define _GetModuleFileName(a, b, c)             GetModuleFileName(a, b, c) | 
 | #endif | #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; | HWND            hWnd; | 
 | WNDCLASS        np2; | WNDCLASS        np2; | 
 | int                     id; | int                     id; | 
| Line 306  int WINAPI WinMain(HINSTANCE hInstance, | Line 371  int WINAPI WinMain(HINSTANCE hInstance, | 
 | return(0); | return(0); | 
 | } | } | 
 |  |  | 
| GetModuleFileName_A(NULL, modulefile, sizeof(modulefile)); | _GetModuleFileName(NULL, modulefile, NELEMENTS(modulefile)); | 
 | dosio_init(); | dosio_init(); | 
 | file_setcd(modulefile); | file_setcd(modulefile); | 
 | initload(); | initload(); | 
| Line 318  int WINAPI WinMain(HINSTANCE hInstance, | Line 383  int WINAPI WinMain(HINSTANCE hInstance, | 
 | TRACEINIT(); | TRACEINIT(); | 
 |  |  | 
 | inputmng_init(); | inputmng_init(); | 
| keystat_reset(); | keystat_initialize(); | 
 |  |  | 
 | //      if (!hPreInst) { | //      if (!hPreInst) { | 
 | np2.style = CS_HREDRAW | CS_VREDRAW; | np2.style = CS_HREDRAW | CS_VREDRAW; | 
| Line 336  int WINAPI WinMain(HINSTANCE hInstance, | Line 401  int WINAPI WinMain(HINSTANCE hInstance, | 
 | } | } | 
 | //      } | //      } | 
 |  |  | 
| #if !defined(WIN32_PLATFORM_PSPC) | #if !defined(GX_DLL) | 
 | hWnd = CreateWindow(szClassName, szAppCaption, | hWnd = CreateWindow(szClassName, szAppCaption, | 
 | WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION | | WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION | | 
 | WS_MINIMIZEBOX, | WS_MINIMIZEBOX, | 
| 0, 0, FULLSCREEN_WIDTH, FULLSCREEN_HEIGHT, | np2oscfg.winx, np2oscfg.winy, | 
|  | FULLSCREEN_WIDTH, FULLSCREEN_HEIGHT, | 
 | NULL, NULL, hInstance, NULL); | NULL, NULL, hInstance, NULL); | 
 | #else | #else | 
 | hWnd = CreateWindow(szClassName, szAppCaption, | hWnd = CreateWindow(szClassName, szAppCaption, | 
 | WS_VISIBLE, | WS_VISIBLE, | 
| 0, 0, | 0, 0, | 
 | GetSystemMetrics(SM_CXSCREEN), | GetSystemMetrics(SM_CXSCREEN), | 
 | GetSystemMetrics(SM_CYSCREEN), | GetSystemMetrics(SM_CYSCREEN), | 
 | NULL, NULL, hInstance, NULL); | NULL, NULL, hInstance, NULL); | 
| Line 366  int WINAPI WinMain(HINSTANCE hInstance, | Line 432  int WINAPI WinMain(HINSTANCE hInstance, | 
 | } | } | 
 | if (scrnmng_create(hWnd, FULLSCREEN_WIDTH, FULLSCREEN_HEIGHT) | if (scrnmng_create(hWnd, FULLSCREEN_WIDTH, FULLSCREEN_HEIGHT) | 
 | != SUCCESS) { | != SUCCESS) { | 
| MessageBox(hWnd, STRLITERAL("Couldn't create DirectDraw Object"), | MessageBox(hWnd, _T("Couldn't create DirectDraw Object"), | 
 | szAppCaption, MB_OK | MB_ICONSTOP); | szAppCaption, MB_OK | MB_ICONSTOP); | 
 | DestroyWindow(hWnd); | DestroyWindow(hWnd); | 
 | goto np2main_err2; | goto np2main_err2; | 
| Line 376  int WINAPI WinMain(HINSTANCE hInstance, | Line 442  int WINAPI WinMain(HINSTANCE hInstance, | 
 | DestroyWindow(hWnd); | DestroyWindow(hWnd); | 
 | goto np2main_err3; | goto np2main_err3; | 
 | } | } | 
 |  | gx_keylist = GXGetDefaultKeys(GX_NORMALKEYS); | 
 |  | scrnmng_keybinds(); | 
 |  | #if defined(WIN32_PLATFORM_PSPC) | 
 |  | winkbd_bindinit(); | 
 |  | #endif | 
 |  |  | 
 | soundmng_initialize(); | soundmng_initialize(); | 
 | commng_initialize(); | commng_initialize(); | 
| Line 387  int WINAPI WinMain(HINSTANCE hInstance, | Line 458  int WINAPI WinMain(HINSTANCE hInstance, | 
 | pccore_reset(); | pccore_reset(); | 
 | scrndraw_redraw(); | 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) { | if (np2oscfg.resume) { | 
 | id = flagload(str_sav, str_resume, FALSE); | id = flagload(str_sav, str_resume, FALSE); | 
| Line 402  int WINAPI WinMain(HINSTANCE hInstance, | Line 478  int WINAPI WinMain(HINSTANCE hInstance, | 
 | if (!GetMessage(&msg, NULL, 0, 0)) { | if (!GetMessage(&msg, NULL, 0, 0)) { | 
 | break; | break; | 
 | } | } | 
| #if !defined(_WIN32_WCE) | #if 1 // !defined(_WIN32_WCE) | 
 | if ((msg.hwnd != hWnd) || | if ((msg.hwnd != hWnd) || | 
 | ((msg.message != WM_SYSKEYDOWN) && | ((msg.message != WM_SYSKEYDOWN) && | 
 | (msg.message != WM_SYSKEYUP))) { | (msg.message != WM_SYSKEYUP))) { | 
| Line 413  int WINAPI WinMain(HINSTANCE hInstance, | Line 489  int WINAPI WinMain(HINSTANCE hInstance, | 
 | #endif | #endif | 
 | DispatchMessage(&msg); | DispatchMessage(&msg); | 
 | } | } | 
| else { | else if (sysrunning & SYSRUNNING_FORE) { | 
 | if (np2oscfg.NOWAIT) { | if (np2oscfg.NOWAIT) { | 
 | pccore_exec(framecnt == 0); | pccore_exec(framecnt == 0); | 
 | if (np2oscfg.DRAW_SKIP) {                       // nowait frame skip | if (np2oscfg.DRAW_SKIP) {                       // nowait frame skip | 
| Line 469  int WINAPI WinMain(HINSTANCE hInstance, | Line 545  int WINAPI WinMain(HINSTANCE hInstance, | 
 | } | } | 
 | } | } | 
 | } | } | 
 |  | else { | 
 |  | Sleep(100); | 
 |  | } | 
 | } | } | 
 |  |  | 
 | soundmng_disable(SNDPROC_MAIN); | soundmng_disable(SNDPROC_MAIN); |