| 1 | #include "app.h"\r |
| 2 | #include "version.h"\r |
| 3 | #include <crtdbg.h>\r |
| 4 | #include <commdlg.h>\r |
| 5 | \r |
| 6 | char *romname=NULL;\r |
| 7 | HWND FrameWnd=NULL;\r |
| 8 | RECT FrameRectMy;\r |
| 9 | int lock_to_1_1 = 1;\r |
| 10 | \r |
| 11 | int MainWidth=720,MainHeight=480;\r |
| 12 | \r |
| 13 | static HMENU mdisplay = 0;\r |
| 14 | static unsigned char *rom_data = NULL;\r |
| 15 | \r |
| 16 | static void UpdateRect()\r |
| 17 | {\r |
| 18 | WINDOWINFO wi;\r |
| 19 | memset(&wi, 0, sizeof(wi));\r |
| 20 | wi.cbSize = sizeof(wi);\r |
| 21 | GetWindowInfo(FrameWnd, &wi);\r |
| 22 | FrameRectMy = wi.rcClient;\r |
| 23 | }\r |
| 24 | \r |
| 25 | static void LoadROM(const char *cmdpath)\r |
| 26 | {\r |
| 27 | static char rompath[MAX_PATH] = { 0, };\r |
| 28 | unsigned char *rom_data_new = NULL;\r |
| 29 | unsigned int rom_size = 0;\r |
| 30 | pm_file *rom = NULL;\r |
| 31 | int oldwait=LoopWait;\r |
| 32 | int i, ret;\r |
| 33 | \r |
| 34 | if (cmdpath) {\r |
| 35 | strcpy(rompath, cmdpath + (cmdpath[0] == '\"' ? 1 : 0));\r |
| 36 | if (rompath[strlen(rompath)-1] == '\"') rompath[strlen(rompath)-1] = 0;\r |
| 37 | if (strlen(rompath) > 4) rom = pm_open(rompath);\r |
| 38 | }\r |
| 39 | \r |
| 40 | if (!rom) {\r |
| 41 | OPENFILENAME of; ZeroMemory(&of, sizeof(OPENFILENAME));\r |
| 42 | of.lStructSize = sizeof(OPENFILENAME);\r |
| 43 | of.lpstrFilter = "ROMs\0*.smd;*.bin;*.gen;*.zip\0";\r |
| 44 | of.lpstrFile = rompath; rompath[0] = 0;\r |
| 45 | of.nMaxFile = MAX_PATH;\r |
| 46 | of.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;\r |
| 47 | of.hwndOwner = FrameWnd;\r |
| 48 | if (!GetOpenFileName(&of)) return;\r |
| 49 | rom = pm_open(rompath);\r |
| 50 | if (!rom) { error("failed to open ROM"); return; }\r |
| 51 | }\r |
| 52 | \r |
| 53 | ret=PicoCartLoad(rom, &rom_data_new, &rom_size);\r |
| 54 | pm_close(rom);\r |
| 55 | if (ret) {\r |
| 56 | error("failed to load ROM");\r |
| 57 | return;\r |
| 58 | }\r |
| 59 | \r |
| 60 | // halt the work thread..\r |
| 61 | // just a hack, should've used proper sync. primitives here, but who will use this emu anyway..\r |
| 62 | LoopWaiting=0;\r |
| 63 | LoopWait=1;\r |
| 64 | for (i = 0; LoopWaiting == 0 && i < 10; i++) Sleep(100);\r |
| 65 | \r |
| 66 | PicoCartInsert(rom_data_new, rom_size);\r |
| 67 | \r |
| 68 | if (rom_data) free(rom_data);\r |
| 69 | rom_data = rom_data_new;\r |
| 70 | romname = rompath;\r |
| 71 | LoopWait=0;\r |
| 72 | }\r |
| 73 | \r |
| 74 | static int rect_widths[4] = { 320, 256, 640, 512 };\r |
| 75 | static int rect_heights[4] = { 224, 224, 448, 448 };\r |
| 76 | \r |
| 77 | // Window proc for the frame window:\r |
| 78 | static LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)\r |
| 79 | {\r |
| 80 | int i;\r |
| 81 | switch (msg)\r |
| 82 | {\r |
| 83 | case WM_CLOSE: PostQuitMessage(0); return 0;\r |
| 84 | case WM_DESTROY: FrameWnd=NULL; break; // Blank handle\r |
| 85 | case WM_SIZE:\r |
| 86 | case WM_MOVE:\r |
| 87 | case WM_SIZING: UpdateRect(); break;\r |
| 88 | case WM_COMMAND:\r |
| 89 | switch (LOWORD(wparam))\r |
| 90 | {\r |
| 91 | case 1000: LoadROM(NULL); break;\r |
| 92 | case 1001: PostQuitMessage(0); return 0;\r |
| 93 | case 1100:\r |
| 94 | case 1101:\r |
| 95 | case 1102:\r |
| 96 | case 1103:\r |
| 97 | LoopWait=1; // another sync hack\r |
| 98 | for (i = 0; !LoopWaiting && i < 10; i++) Sleep(10);\r |
| 99 | FrameRectMy.right = FrameRectMy.left + rect_widths[wparam&3];\r |
| 100 | FrameRectMy.bottom = FrameRectMy.top + rect_heights[wparam&3];\r |
| 101 | AdjustWindowRect(&FrameRectMy, WS_OVERLAPPEDWINDOW, 1);\r |
| 102 | MoveWindow(hwnd, FrameRectMy.left, FrameRectMy.top,\r |
| 103 | FrameRectMy.right-FrameRectMy.left, FrameRectMy.bottom-FrameRectMy.top, 1);\r |
| 104 | UpdateRect();\r |
| 105 | if (HIWORD(wparam) == 0) { // locally sent\r |
| 106 | lock_to_1_1=0;\r |
| 107 | CheckMenuItem(mdisplay, 1104, MF_UNCHECKED);\r |
| 108 | }\r |
| 109 | if (rom_data != NULL) LoopWait=0;\r |
| 110 | return 0;\r |
| 111 | case 1104:\r |
| 112 | lock_to_1_1=!lock_to_1_1;\r |
| 113 | CheckMenuItem(mdisplay, 1104, lock_to_1_1 ? MF_CHECKED : MF_UNCHECKED);\r |
| 114 | return 0;\r |
| 115 | case 1200: break;\r |
| 116 | case 1300:\r |
| 117 | MessageBox(FrameWnd, "PicoDrive v" VERSION " (c) notaz, 2006-2008\n"\r |
| 118 | "SVP demo edition\n\n"\r |
| 119 | "Credits:\n"\r |
| 120 | "fDave: base code of PicoDrive, GenaDrive (the frontend)\n"\r |
| 121 | "Chui: Fame/C\n"\r |
| 122 | "NJ: CZ80\n"\r |
| 123 | "MAME devs: YM2612 and SN76496 cores\n"\r |
| 124 |