int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { MSG uMsg; memset(&uMsg,0,sizeof(uMsg)); winClass.lpszClassName = "MY_WINDOWS_CLASS"; winClass.cbSize = sizeof(WNDCLASSEX); winClass.style = CS_HREDRAW | CS_VREDRAW; winClass.lpfnWndProc = WndProc; winClass.hInstance = hInstance; winClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); winClass.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); winClass.hCursor = LoadCursor(NULL, IDC_ARROW); winClass.lpszMenuName = MAKEINTRESOURCE(IDC_CV); winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); winClass.cbClsExtra = 0; winClass.cbWndExtra = 0; OpenConsole(); if( !RegisterClassEx(&winClass) ) return E_FAIL; GetINIPath(); LoadSettings(); pcejin.aspectRatio = GetPrivateProfileInt("Video", "aspectratio", 0, IniName); pcejin.windowSize = GetPrivateProfileInt("Video", "pcejin.windowSize", 1, IniName); WndX = GetPrivateProfileInt("Main", "WndX", 0, IniName); WndY = GetPrivateProfileInt("Main", "WndY", 0, IniName); g_hWnd = CreateWindowEx( NULL, "MY_WINDOWS_CLASS", pcejin.versionName.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE, WndX, WndY, 256, 232, NULL, NULL, hInstance, NULL ); if( g_hWnd == NULL ) return E_FAIL; ScaleScreen(pcejin.windowSize); soundInit(); LoadIniSettings(); InitSpeedThrottle(); RecentROMs.SetGUI_hWnd(g_hWnd); RecentROMs.SetID(RECENTROM_START); RecentROMs.SetMenuID(ID_FILE_RECENTROM); RecentROMs.SetType("ROM"); RecentROMs.MakeRecentMenu(hInstance); RecentROMs.GetRecentItemsFromIni(IniName, "General"); RecentMovies.SetGUI_hWnd(g_hWnd); RecentMovies.SetID(RECENTMOVIE_START); RecentMovies.SetMenuID(ID_MOVIE_RECENT); RecentMovies.SetType("Movie"); RecentMovies.MakeRecentMenu(hInstance); RecentMovies.GetRecentItemsFromIni(IniName, "General"); RecentLua.SetGUI_hWnd(g_hWnd); RecentLua.SetID(RECENTLUA_START); RecentLua.SetMenuID(ID_LUA_RECENT); RecentLua.SetType("Lua"); RecentLua.MakeRecentMenu(hInstance); RecentLua.GetRecentItemsFromIni(IniName, "General"); DirectDrawInit(); InitCustomControls(); InitCustomKeys(&CustomKeys); LoadHotkeyConfig(); LoadInputConfig(); DragAcceptFiles(g_hWnd, true); extern void Agg_init(); Agg_init(); if (osd) {delete osd; osd =NULL; } osd = new OSDCLASS(-1); di_init(); DWORD wmTimerRes; TIMECAPS tc; if (timeGetDevCaps(&tc, sizeof(TIMECAPS))== TIMERR_NOERROR) { wmTimerRes = std::min(std::max(tc.wPeriodMin, (UINT)1), tc.wPeriodMax); timeBeginPeriod (wmTimerRes); } else { wmTimerRes = 5; timeBeginPeriod (wmTimerRes); } if (KeyInDelayMSec == 0) { DWORD dwKeyboardDelay; SystemParametersInfo(SPI_GETKEYBOARDDELAY, 0, &dwKeyboardDelay, 0); KeyInDelayMSec = 250 * (dwKeyboardDelay + 1); } if (KeyInRepeatMSec == 0) { DWORD dwKeyboardSpeed; SystemParametersInfo(SPI_GETKEYBOARDSPEED, 0, &dwKeyboardSpeed, 0); KeyInRepeatMSec = (int)(1000.0/(((30.0-2.5)/31.0)*dwKeyboardSpeed+2.5)); } if (KeyInRepeatMSec < (int)wmTimerRes) KeyInRepeatMSec = (int)wmTimerRes; if (KeyInDelayMSec < KeyInRepeatMSec) KeyInDelayMSec = KeyInRepeatMSec; hKeyInputTimer = timeSetEvent (KeyInRepeatMSec, 0, KeyInputTimer, 0, TIME_PERIODIC); ShowWindow( g_hWnd, nCmdShow ); UpdateWindow( g_hWnd ); initialize(); if (lpCmdLine[0])ParseCmdLine(lpCmdLine, g_hWnd); if (RecentROMs.GetAutoLoad() && (!skipAutoLoadROM)) { ALoad(RecentROMs.GetRecentItem(0).c_str()); } //Intentionally does not prompt for a game if no game specified, user should be forced to autoload roms as well, for this to work properly if (RecentMovies.GetAutoLoad() && (!skipAutoLoadMovie)) { LoadMovie(RecentMovies.GetRecentItem(0).c_str(), 1, false, false); } if (RecentLua.GetAutoLoad() && (!skipAutoLoadLua)) { char temp [1024]; strcpy(temp, RecentLua.GetRecentItem(0).c_str()); HWND hDlg = CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_LUA), g_hWnd, (DLGPROC) LuaScriptProc); SendDlgItemMessage(hDlg,IDC_EDIT_LUAPATH,WM_SETTEXT,0,(LPARAM)temp); } while( uMsg.message != WM_QUIT ) { if( PeekMessage( &uMsg, NULL, 0, 0, PM_REMOVE ) ) { TranslateMessage( &uMsg ); DispatchMessage( &uMsg ); } else { emulate(); render(); } if(!pcejin.started) Sleep(1); } // shutDown(); timeEndPeriod (wmTimerRes); CloseAllToolWindows(); UnregisterClass( "MY_WINDOWS_CLASS", winClass.hInstance ); return uMsg.wParam; }
LRESULT CALLBACK WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; HWND hDlg; switch(Message) { case WM_KEYDOWN: if(wParam != VK_PAUSE) break; // case WM_SYSKEYDOWN: case WM_CUSTKEYDOWN: { int modifiers = GetModifiers(wParam); if(!HandleKeyMessage(wParam,lParam, modifiers)) return 0; break; } case WM_KEYUP: if(wParam != VK_PAUSE) break; case WM_SYSKEYUP: case WM_CUSTKEYUP: { int modifiers = GetModifiers(wParam); HandleKeyUp(wParam, lParam, modifiers); } break; case WM_SIZE: switch(wParam) { case SIZE_MINIMIZED: break; case SIZE_MAXIMIZED: pcejin.maximized = true; break; case SIZE_RESTORED: pcejin.maximized = false; break; default: break; } return 0; case WM_MOVE: RECT rect; GetWindowRect(hWnd,&rect); WndX = rect.left; WndY = rect.top; return 0; case WM_DROPFILES: { char filename[MAX_PATH] = ""; DragQueryFile((HDROP)wParam,0,filename,MAX_PATH); DragFinish((HDROP)wParam); std::string fileDropped = filename; //------------------------------------------------------- //Check if mcm file, if so auto-convert and play //------------------------------------------------------- if (!(fileDropped.find(".mcm") == std::string::npos) && (fileDropped.find(".mcm") == fileDropped.length()-4)) { if (!pcejin.romLoaded) //If no ROM is loaded, prompt for one { soundDriver->pause(); LoadGame(); pcejin.tempUnPause(); } if (pcejin.romLoaded && !(fileDropped.find(".mcm") == std::string::npos)) LoadMCM(fileDropped.c_str(), true); } //------------------------------------------------------- //Check if Movie file //------------------------------------------------------- else if (!(fileDropped.find(".mc2") == std::string::npos) && (fileDropped.find(".mc2") == fileDropped.length()-4)) { if (!pcejin.romLoaded) //If no ROM is loaded, prompt for one { soundDriver->pause(); LoadGame(); pcejin.tempUnPause(); } if (pcejin.romLoaded && !(fileDropped.find(".mc2") == std::string::npos)) { LoadMovie(fileDropped.c_str(), 1, false, false); RecentMovies.UpdateRecentItems(fileDropped); } } //------------------------------------------------------- //Check if Savestate file //------------------------------------------------------- else if (!(fileDropped.find(".nc") == std::string::npos)) { if (fileDropped.find(".nc") == fileDropped.length()-4) { if ((fileDropped[fileDropped.length()-1] >= '0' && fileDropped[fileDropped.length()-1] <= '9')) { MDFNSS_Load(filename, NULL); UpdateToolWindows(); } } } //------------------------------------------------------- //Check if Lua script file //------------------------------------------------------- else if (!(fileDropped.find(".lua") == std::string::npos) && (fileDropped.find(".lua") == fileDropped.length()-4)) //ROM is already loaded and .dsm in filename { if(LuaScriptHWnds.size() < 16) { char temp [1024]; strcpy(temp, fileDropped.c_str()); HWND IsScriptFileOpen(const char* Path); RecentLua.UpdateRecentItems(fileDropped); if(!IsScriptFileOpen(temp)) { HWND hDlg = CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_LUA), hWnd, (DLGPROC) LuaScriptProc); SendDlgItemMessage(hDlg,IDC_EDIT_LUAPATH,WM_SETTEXT,0,(LPARAM)temp); } } } //------------------------------------------------------- //Check if watchlist file //------------------------------------------------------- else if (!(fileDropped.find(".wch") == std::string::npos) && (fileDropped.find(".wch") == fileDropped.length()-4)) //ROM is already loaded and .dsm in filename { if(!RamWatchHWnd) { RamWatchHWnd = CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_RAMWATCH), hWnd, (DLGPROC) RamWatchProc); } else SetForegroundWindow(RamWatchHWnd); Load_Watches(true, fileDropped.c_str()); } //------------------------------------------------------- //Else load it as a ROM //------------------------------------------------------- else { ALoad(fileDropped.c_str()); } } return 0; case WM_ENTERMENULOOP: soundDriver->pause(); EnableMenuItem(GetMenu(hWnd), IDM_RECORD_MOVIE, MF_BYCOMMAND | (movieMode == MOVIEMODE_INACTIVE && pcejin.romLoaded) ? MF_ENABLED : MF_GRAYED); EnableMenuItem(GetMenu(hWnd), IDM_PLAY_MOVIE, MF_BYCOMMAND | (movieMode == MOVIEMODE_INACTIVE && pcejin.romLoaded) ? MF_ENABLED : MF_GRAYED); EnableMenuItem(GetMenu(hWnd), IDM_STOPMOVIE, MF_BYCOMMAND | (movieMode != MOVIEMODE_INACTIVE) ? MF_ENABLED : MF_GRAYED); EnableMenuItem(GetMenu(hWnd), IDM_RESTARTMOVIE, MF_BYCOMMAND | (movieMode != MOVIEMODE_INACTIVE) ? MF_ENABLED : MF_GRAYED); EnableMenuItem(GetMenu(hWnd), IDM_FILE_STOPAVI, MF_BYCOMMAND | (DRV_AviIsRecording()) ? MF_ENABLED : MF_GRAYED); EnableMenuItem(GetMenu(hWnd), IDM_FILE_RECORDAVI, MF_BYCOMMAND | (!DRV_AviIsRecording()) ? MF_ENABLED : MF_GRAYED); //Window Size checkMenu(IDC_WINDOW1X, ((pcejin.windowSize==1))); checkMenu(IDC_WINDOW2X, ((pcejin.windowSize==2))); checkMenu(IDC_WINDOW3X, ((pcejin.windowSize==3))); checkMenu(IDC_WINDOW4X, ((pcejin.windowSize==4))); checkMenu(IDC_ASPECT, ((pcejin.aspectRatio))); checkMenu(ID_VIEW_FRAMECOUNTER,Hud.FrameCounterDisplay); checkMenu(ID_VIEW_DISPLAYINPUT,Hud.ShowInputDisplay); checkMenu(ID_VIEW_DISPLAYSTATESLOTS,Hud.DisplayStateSlots); checkMenu(ID_VIEW_DISPLAYLAG,Hud.ShowLagFrameCounter); checkMenu(IDM_MUTE,soundDriver->userMute); break; case WM_EXITMENULOOP: pcejin.tempUnPause(); break; case WM_CLOSE: { SaveIniSettings(); PostQuitMessage(0); } case WM_DESTROY: { PostQuitMessage(0); } // HANDLE_MSG(hWnd, WM_DESTROY, OnDestroy); // HANDLE_MSG(hWnd, WM_PAINT, OnPaint); // HANDLE_MSG(hwnd, WM_COMMAND, OnCommand); case WM_COMMAND: //Recent ROMs if(wParam >= RECENTROM_START && wParam <= RECENTROM_START + RecentROMs.MAX_RECENT_ITEMS - 1) { ALoad(RecentROMs.GetRecentItem(wParam - RECENTROM_START).c_str()); break; } else if (wParam == RecentROMs.GetClearID()) { RecentROMs.ClearRecentItems(); break; } else if (wParam == RecentROMs.GetAutoloadID()) { RecentROMs.FlipAutoLoad(); break; } //Recent Movies if(wParam >= RECENTMOVIE_START && wParam <= RECENTMOVIE_START + RecentMovies.MAX_RECENT_ITEMS - 1) { strcpy(Tmp_Str, RecentMovies.GetRecentItem(wParam - RECENTMOVIE_START).c_str()); RecentMovies.UpdateRecentItems(Tmp_Str); //WIN32_StartMovieReplay(Str_Tmp); break; } else if (wParam == RecentMovies.GetClearID()) { RecentMovies.ClearRecentItems(); break; } else if (wParam == RecentMovies.GetAutoloadID()) { RecentMovies.FlipAutoLoad(); break; } //Recent Lua if(wParam >= RECENTLUA_START && wParam <= RECENTLUA_START + RecentLua.MAX_RECENT_ITEMS - 1) { if(LuaScriptHWnds.size() < 16) { char temp [1024]; strcpy(temp, RecentLua.GetRecentItem(wParam - RECENTLUA_START).c_str()); HWND IsScriptFileOpen(const char* Path); RecentLua.UpdateRecentItems(temp); if(!IsScriptFileOpen(temp)) { HWND hDlg = CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_LUA), hWnd, (DLGPROC) LuaScriptProc); SendDlgItemMessage(hDlg,IDC_EDIT_LUAPATH,WM_SETTEXT,0,(LPARAM)temp); } } break; } else if (wParam == RecentLua.GetClearID()) { RecentLua.ClearRecentItems(); break; } else if (wParam == RecentLua.GetAutoloadID()) { RecentLua.FlipAutoLoad(); break; } wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDC_WINDOW1X: pcejin.windowSize=1; ScaleScreen(pcejin.windowSize); break; case IDC_WINDOW2X: pcejin.windowSize=2; ScaleScreen(pcejin.windowSize); break; case IDC_WINDOW3X: pcejin.windowSize=3; ScaleScreen(pcejin.windowSize); break; case IDC_WINDOW4X: pcejin.windowSize=4; ScaleScreen(pcejin.windowSize); break; case IDC_ASPECT: pcejin.aspectRatio ^= 1; ScaleScreen(pcejin.windowSize); break; case IDM_EXIT: SaveIniSettings(); PostQuitMessage(0); break; case IDM_RESET: PCE_Power(); break; case IDM_OPEN_ROM: soundDriver->pause(); LoadGame(); pcejin.tempUnPause(); break; case IDM_RECORD_MOVIE: soundDriver->pause(); MovieRecordTo(); pcejin.tempUnPause(); return 0; case IDM_PLAY_MOVIE: soundDriver->pause(); Replay_LoadMovie(); pcejin.tempUnPause(); return 0; case IDM_INPUT_CONFIG: soundDriver->pause(); DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_INPUTCONFIG), hWnd, DlgInputConfig); pcejin.tempUnPause(); // RunInputConfig(); break; case IDM_HOTKEY_CONFIG: { soundDriver->pause(); DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_KEYCUSTOM), hWnd, DlgHotkeyConfig); pcejin.tempUnPause(); } break; case IDM_BIOS_CONFIG: soundDriver->pause(); DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_BIOS), hWnd, (DLGPROC) BiosSettingsDlgProc); // DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_KEYCUSTOM), hWnd, BiosSettingsDlgProc); pcejin.tempUnPause(); break; case ID_VIEW_FRAMECOUNTER: Hud.FrameCounterDisplay ^= true; WritePrivateProfileBool("Display", "FrameCounter", Hud.FrameCounterDisplay, IniName); return 0; case ID_VIEW_DISPLAYINPUT: Hud.ShowInputDisplay ^= true; WritePrivateProfileBool("Display", "Display Input", Hud.ShowInputDisplay, IniName); osd->clear(); return 0; case ID_VIEW_DISPLAYSTATESLOTS: Hud.DisplayStateSlots ^= true; WritePrivateProfileBool("Display", "Display State Slots", Hud.DisplayStateSlots, IniName); osd->clear(); return 0; case ID_VIEW_DISPLAYLAG: Hud.ShowLagFrameCounter ^= true; WritePrivateProfileBool("Display", "Display Lag Counter", Hud.ShowLagFrameCounter, IniName); osd->clear(); return 0; case IDC_NEW_LUA_SCRIPT: if(LuaScriptHWnds.size() < 16) { CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_LUA), g_hWnd, (DLGPROC) LuaScriptProc); } break; case IDM_CONVERT_MCM: ConvertMCM(hWnd); break; case IDM_MUTE: soundDriver->doUserMute(); break; case IDM_STOPMOVIE: StopMovie(); return 0; break; case IDM_RESTARTMOVIE: PCE_Power(); ResetFrameCount(); movieMode = MOVIEMODE_PLAY; movie_readonly = true; return 0; break; case ID_RAM_SEARCH: if(!RamSearchHWnd) { InitRamSearch(); RamSearchHWnd = CreateDialog(winClass.hInstance, MAKEINTRESOURCE(IDD_RAMSEARCH), hWnd, (DLGPROC) RamSearchProc); } else SetForegroundWindow(RamSearchHWnd); break; case ID_RAM_WATCH: if(!RamWatchHWnd) { RamWatchHWnd = CreateDialog(winClass.hInstance, MAKEINTRESOURCE(IDD_RAMWATCH), hWnd, (DLGPROC) RamWatchProc); } else SetForegroundWindow(RamWatchHWnd); return 0; case IDM_MEMORY: if (!RegWndClass("MemView_ViewBox", MemView_ViewBoxProc, 0, sizeof(CMemView*))) return 0; OpenToolWindow(new CMemView()); return 0; case IDM_ABOUT: soundDriver->pause(); DialogBox(winClass.hInstance, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); pcejin.tempUnPause(); break; case IDM_FILE_RECORDAVI: soundDriver->pause(); RecordAvi(); pcejin.tempUnPause(); break; case IDM_FILE_STOPAVI: StopAvi(); break; } break; } return DefWindowProc(hWnd, Message, wParam, lParam); }