+#include <windows.h>\r
+#include <commdlg.h>\r
+#include <stdio.h>\r
+\r
+#include "../../pico/pico.h"\r
+#include "../common/readpng.h"\r
+#include "../common/config.h"\r
+#include "../common/lprintf.h"\r
+#include "../common/emu.h"\r
+#include "../common/menu.h"\r
+#include "../common/input.h"\r
+#include "../common/plat.h"\r
+#include "version.h"\r
+#include "direct.h"\r
+#include "in_vk.h"\r
+\r
+char *romname=NULL;\r
+HWND FrameWnd=NULL;\r
+RECT FrameRectMy;\r
+RECT EmuScreenRect = { 0, 0, 320, 224 };\r
+int lock_to_1_1 = 1;\r
+static HWND PicoSwWnd=NULL, PicoPadWnd=NULL;\r
+\r
+static HMENU mmain = 0, mdisplay = 0, mpicohw = 0;\r
+static HBITMAP ppad_bmp = 0;\r
+static HBITMAP ppage_bmps[7] = { 0, };\r
+static char rom_name[0x20*3+1];\r
+static int main_wnd_as_pad = 0;\r
+\r
+static HANDLE loop_enter_event, loop_end_event;\r
+\r
+void error(char *text)\r
+{\r
+ MessageBox(FrameWnd, text, "Error", 0);\r
+}\r
+\r
+static void UpdateRect(void)\r
+{\r
+ WINDOWINFO wi;\r
+ memset(&wi, 0, sizeof(wi));\r
+ wi.cbSize = sizeof(wi);\r
+ GetWindowInfo(FrameWnd, &wi);\r
+ FrameRectMy = wi.rcClient;\r
+}\r
+\r
+static int extract_rom_name(char *dest, const unsigned char *src, int len)\r
+{\r
+ char *p = dest, s_old = 0x20;\r
+ int i;\r
+\r
+ for (i = len - 1; i >= 0; i--)\r
+ {\r
+ if (src[i^1] != ' ') break;\r
+ }\r
+ len = i + 1;\r
+\r
+ for (i = 0; i < len; i++)\r
+ {\r
+ unsigned char s = src[i^1];\r
+ if (s == 0x20 && s_old == 0x20) continue;\r
+ else if (s >= 0x20 && s < 0x7f && s != '%')\r
+ {\r
+ *p++ = s;\r
+ }\r
+ else\r
+ {\r
+ sprintf(p, "%%%02x", s);\r
+ p += 3;\r
+ }\r
+ s_old = s;\r
+ }\r
+ *p = 0;\r
+\r
+ return p - dest;\r
+}\r
+\r
+static void check_name_alias(const char *afname)\r
+{\r
+ char buff[256], *var, *val;\r
+ FILE *f;\r
+ int ret;\r
+\r
+ f = fopen(afname, "r");\r
+ if (f == NULL) return;\r
+\r
+ while (1)\r
+ {\r
+ ret = config_get_var_val(f, buff, sizeof(buff), &var, &val);\r
+ if (ret == 0) break;\r
+ if (ret == -1) continue;\r
+\r
+ if (strcmp(rom_name, var) == 0) {\r
+ lprintf("rom aliased: \"%s\" -> \"%s\"\n", rom_name, val);\r
+ strncpy(rom_name, val, sizeof(rom_name));\r
+ break;\r
+ }\r
+ }\r
+ fclose(f);\r
+}\r
+\r
+static HBITMAP png2hb(const char *fname, int is_480)\r
+{\r
+ BITMAPINFOHEADER bih;\r
+ HBITMAP bmp;\r
+ void *bmem;\r
+ int ret;\r
+\r
+ bmem = calloc(1, is_480 ? 480*240*3 : 320*240*3);\r
+ if (bmem == NULL) return NULL;\r
+ ret = readpng(bmem, fname, is_480 ? READPNG_480_24 : READPNG_320_24);\r
+ if (ret != 0) {\r
+ free(bmem);\r
+ return NULL;\r
+ }\r
+\r
+ memset(&bih, 0, sizeof(bih));\r
+ bih.biSize = sizeof(bih);\r
+ bih.biWidth = is_480 ? 480 : 320;\r
+ bih.biHeight = -240;\r
+ bih.biPlanes = 1;\r
+ bih.biBitCount = 24;\r
+ bih.biCompression = BI_RGB;\r
+ bmp = CreateDIBitmap(GetDC(FrameWnd), &bih, CBM_INIT, bmem, (BITMAPINFO *)&bih, 0);\r
+ if (bmp == NULL)\r
+ lprintf("CreateDIBitmap failed with %i", GetLastError());\r
+\r
+ free(bmem);\r
+ return bmp;\r
+}\r
+\r
+static void PrepareForROM(void)\r
+{\r
+ unsigned char *rom_data = NULL;\r
+ int i, ret, show = PicoAHW & PAHW_PICO;\r
+ \r
+ PicoGetInternal(PI_ROM, (pint_ret_t *) &rom_data);\r
+ EnableMenuItem(mmain, 2, MF_BYPOSITION|(show ? MF_ENABLED : MF_GRAYED));\r
+ ShowWindow(PicoPadWnd, show ? SW_SHOWNA : SW_HIDE);\r
+ ShowWindow(PicoSwWnd, show ? SW_SHOWNA : SW_HIDE);\r
+ CheckMenuItem(mpicohw, 1210, show ? MF_CHECKED : MF_UNCHECKED);\r
+ CheckMenuItem(mpicohw, 1211, show ? MF_CHECKED : MF_UNCHECKED);\r
+ PostMessage(FrameWnd, WM_COMMAND, 1220 + PicoPicohw.page, 0);\r
+ DrawMenuBar(FrameWnd);\r
+ InvalidateRect(PicoSwWnd, NULL, 1);\r
+\r
+ PicoPicohw.pen_pos[0] =\r
+ PicoPicohw.pen_pos[1] = 0x8000;\r
+ in_vk_add_pl12 = 0;\r
+\r
+ ret = extract_rom_name(rom_name, rom_data + 0x150, 0x20);\r
+ if (ret == 0)\r
+ extract_rom_name(rom_name, rom_data + 0x130, 0x20);\r
+\r
+ if (show)\r
+ {\r
+ char path[MAX_PATH], *p;\r
+ GetModuleFileName(NULL, path, sizeof(path) - 32);\r
+ p = strrchr(path, '\\');\r
+ if (p == NULL) p = path;\r
+ else p++;\r
+ if (ppad_bmp == NULL) {\r
+ strcpy(p, "pico\\pad.png");\r
+ ppad_bmp = png2hb(path, 0);\r
+ }\r
+\r
+ strcpy(p, "pico\\alias.txt");\r
+ check_name_alias(path);\r
+\r
+ for (i = 0; i < 7; i++) {\r
+ if (ppage_bmps[i] != NULL) DeleteObject(ppage_bmps[i]);\r
+ sprintf(p, "pico\\%s_%i.png", rom_name, i);\r
+ ppage_bmps[i] = png2hb(path, 1);\r
+ }\r
+ // games usually don't have page 6, so just duplicate page 5.\r
+ if (ppage_bmps[6] == NULL && ppage_bmps[5] != NULL) {\r
+ sprintf(p, "pico\\%s_5.png", rom_name);\r
+ ppage_bmps[6] = png2hb(path, 1);\r
+ }\r
+ }\r
+}\r
+\r
+static void LoadROM(const char *cmdpath)\r
+{\r
+ char rompath[MAX_PATH];\r
+ int ret;\r
+\r
+ if (cmdpath != NULL && strlen(cmdpath)) {\r
+ strcpy(rompath, cmdpath + (cmdpath[0] == '\"' ? 1 : 0));\r
+ if (rompath[strlen(rompath)-1] == '\"')\r
+ rompath[strlen(rompath)-1] = 0;\r
+ }\r
+ else {\r
+ OPENFILENAME of; ZeroMemory(&of, sizeof(of));\r
+ rompath[sizeof(rompath) - 1] = 0;\r
+ strncpy(rompath, rom_fname_loaded, sizeof(rompath) - 1);\r
+ of.lStructSize = sizeof(of);\r
+ of.lpstrFilter = "ROMs, CD images\0*.smd;*.bin;*.gen;*.zip;*.32x;*.sms;*.iso;*.cso;*.cue\0"\r
+ "whatever\0*.*\0";\r
+ of.lpstrFile = rompath;\r
+ of.nMaxFile = MAX_PATH;\r
+ of.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;\r
+ of.hwndOwner = FrameWnd;\r
+ if (!GetOpenFileName(&of))\r
+ return;\r
+ }\r
+\r
+ if (engineState == PGS_Running) {\r
+ engineState = PGS_Paused;\r
+ WaitForSingleObject(loop_end_event, 5000);\r
+ }\r
+\r
+ ret = emu_reload_rom(rompath);\r
+ if (ret == 0) {\r
+ extern char menu_error_msg[]; // HACK..\r
+ error(menu_error_msg);\r
+ return;\r
+ }\r
+\r
+ PrepareForROM();\r
+ engineState = PGS_Running;\r
+ SetEvent(loop_enter_event);\r
+}\r
+\r
+static const int rect_widths[4] = { 320, 256, 640, 512 };\r
+static const int rect_heights[4] = { 224, 224, 448, 448 };\r
+\r
+// Window proc for the frame window:\r
+static LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)\r
+{\r
+ POINT pt;\r
+ RECT rc;\r
+ int i;\r
+ switch (msg)\r
+ {\r
+ case WM_CLOSE:\r
+ PostQuitMessage(0);\r
+ return 0;\r
+ case WM_DESTROY:\r
+ FrameWnd = NULL; // Blank the handle\r
+ break;\r
+ case WM_SIZE:\r
+ case WM_MOVE:\r
+ case WM_SIZING:\r
+ UpdateRect();\r
+ if (lock_to_1_1 && FrameRectMy.right - FrameRectMy.left != 0 &&\r
+ (FrameRectMy.right - FrameRectMy.left != EmuScreenRect.right - EmuScreenRect.left ||\r
+ FrameRectMy.bottom - FrameRectMy.top != EmuScreenRect.bottom - EmuScreenRect.top)) {\r
+ lock_to_1_1 = 0;\r
+ CheckMenuItem(mdisplay, 1104, MF_UNCHECKED);\r
+ }\r
+ break;\r
+ case WM_COMMAND:\r
+ switch (LOWORD(wparam))\r
+ {\r
+ case 1000:\r
+ LoadROM(NULL);\r
+ break;\r
+ case 1001:\r
+ emu_reset_game();\r
+ return 0;\r
+ case 1002:\r
+ PostQuitMessage(0);\r
+ return 0;\r
+ case 1100:\r
+ case 1101:\r
+ case 1102:\r
+ case 1103:\r
+// LoopWait=1; // another sync hack\r
+// for (i = 0; !LoopWaiting && i < 10; i++) Sleep(10);\r
+ FrameRectMy.right = FrameRectMy.left + rect_widths[wparam&3];\r
+ FrameRectMy.bottom = FrameRectMy.top + rect_heights[wparam&3];\r
+ AdjustWindowRect(&FrameRectMy, WS_OVERLAPPEDWINDOW, 1);\r
+ MoveWindow(hwnd, FrameRectMy.left, FrameRectMy.top,\r
+ FrameRectMy.right-FrameRectMy.left, FrameRectMy.bottom-FrameRectMy.top, 1);\r
+ UpdateRect();\r
+ lock_to_1_1 = 0;\r
+ CheckMenuItem(mdisplay, 1104, MF_UNCHECKED);\r
+// if (rom_loaded) LoopWait=0;\r
+ return 0;\r
+ case 1104:\r
+ lock_to_1_1 = !lock_to_1_1;\r
+ CheckMenuItem(mdisplay, 1104, lock_to_1_1 ? MF_CHECKED : MF_UNCHECKED);\r
+ /* FALLTHROUGH */\r
+ case 2000: // EmuScreenRect/FrameRectMy sync request\r
+ if (!lock_to_1_1)\r
+ return 0;\r
+ FrameRectMy.right = FrameRectMy.left + (EmuScreenRect.right - EmuScreenRect.left);\r
+ FrameRectMy.bottom = FrameRectMy.top + (EmuScreenRect.bottom - EmuScreenRect.top);\r
+ AdjustWindowRect(&FrameRectMy, WS_OVERLAPPEDWINDOW, 1);\r
+ MoveWindow(hwnd, FrameRectMy.left, FrameRectMy.top,\r
+ FrameRectMy.right-FrameRectMy.left, FrameRectMy.bottom-FrameRectMy.top, 1);\r
+ UpdateRect();\r
+ return 0;\r
+ case 1210:\r
+ case 1211:\r
+ i = IsWindowVisible((LOWORD(wparam)&1) ? PicoPadWnd : PicoSwWnd);\r
+ i = !i;\r
+ ShowWindow((LOWORD(wparam)&1) ? PicoPadWnd : PicoSwWnd, i ? SW_SHOWNA : SW_HIDE);\r
+ CheckMenuItem(mpicohw, LOWORD(wparam), i ? MF_CHECKED : MF_UNCHECKED);\r
+ return 0;\r
+ case 1212:\r
+ main_wnd_as_pad = !main_wnd_as_pad;\r
+ CheckMenuItem(mpicohw, 1212, main_wnd_as_pad ? MF_CHECKED : MF_UNCHECKED);\r
+ return 0;\r
+ case 1220:\r
+ case 1221:\r
+ case 1222:\r
+ case 1223:\r
+ case 1224:\r
+ case 1225:\r
+ case 1226:\r
+ PicoPicohw.page = LOWORD(wparam) % 10;\r
+ for (i = 0; i < 7; i++)\r
+ CheckMenuItem(mpicohw, 1220 + i, MF_UNCHECKED);\r
+ CheckMenuItem(mpicohw, 1220 + PicoPicohw.page, MF_CHECKED);\r
+ InvalidateRect(PicoSwWnd, NULL, 1);\r
+ return 0;\r
+ case 1300:\r
+ MessageBox(FrameWnd, plat_get_credits(), "About", 0);\r
+ return 0;\r
+ }\r
+ break;\r
+ case WM_TIMER:\r
+ GetCursorPos(&pt);\r
+ GetWindowRect(PicoSwWnd, &rc);\r
+ if (PtInRect(&rc, pt)) break;\r
+ GetWindowRect(PicoPadWnd, &rc);\r
+ if (PtInRect(&rc, pt)) break;\r
+ PicoPicohw.pen_pos[0] |= 0x8000;\r
+ PicoPicohw.pen_pos[1] |= 0x8000;\r
+ in_vk_add_pl12 = 0;\r
+ break;\r
+ case WM_LBUTTONDOWN: in_vk_add_pl12 |= 0x20; return 0;\r
+ case WM_LBUTTONUP: in_vk_add_pl12 &= ~0x20; return 0;\r
+ case WM_MOUSEMOVE:\r
+ if (!main_wnd_as_pad) break;\r
+ PicoPicohw.pen_pos[0] = 0x03c + (320 * LOWORD(lparam) / (FrameRectMy.right - FrameRectMy.left));\r
+ PicoPicohw.pen_pos[1] = 0x1fc + (232 * HIWORD(lparam) / (FrameRectMy.bottom - FrameRectMy.top));\r
+ SetTimer(FrameWnd, 100, 1000, NULL);\r
+ break;\r
+ case WM_KEYDOWN:\r
+ if (wparam == VK_TAB) {\r
+ emu_reset_game();\r
+ break;\r
+ }\r
+ if (wparam == VK_ESCAPE) {\r
+ LoadROM(NULL);\r
+ break;\r
+ }\r
+ in_vk_keydown(wparam);\r
+ break;\r
+ case WM_KEYUP:\r
+ in_vk_keyup(wparam);\r
+ break;\r
+ }\r
+\r
+ return DefWindowProc(hwnd,msg,wparam,lparam);\r
+}\r
+\r
+static LRESULT CALLBACK PicoSwWndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)\r
+{\r
+ PAINTSTRUCT ps;\r
+ HDC hdc, hdc2;\r
+\r
+ switch (msg)\r
+ {\r
+ case WM_DESTROY: PicoSwWnd=NULL; break;\r
+ case WM_LBUTTONDOWN: in_vk_add_pl12 |= 0x20; return 0;\r
+ case WM_LBUTTONUP: in_vk_add_pl12 &= ~0x20; return 0;\r
+ case WM_MOUSEMOVE:\r
+ if (HIWORD(lparam) < 0x20) break;\r
+ PicoPicohw.pen_pos[0] = 0x03c + LOWORD(lparam) * 2/3;\r
+ PicoPicohw.pen_pos[1] = 0x2f8 + HIWORD(lparam) - 0x20;\r
+ SetTimer(FrameWnd, 100, 1000, NULL);\r
+ break;\r
+ case WM_KEYDOWN: in_vk_keydown(wparam); break;\r
+ case WM_KEYUP: in_vk_keyup(wparam); break;\r
+ case WM_PAINT:\r
+ hdc = BeginPaint(hwnd, &ps);\r
+ if (ppage_bmps[PicoPicohw.page] == NULL)\r
+ {\r
+ SelectObject(hdc, GetStockObject(DEFAULT_GUI_FONT));\r
+ SetTextColor(hdc, RGB(255, 255, 255));\r
+ SetBkColor(hdc, RGB(0, 0, 0));\r
+ TextOut(hdc, 2, 2, "missing PNGs for", 16);\r
+ TextOut(hdc, 2, 18, rom_name, strlen(rom_name));\r
+ }\r
+ else\r
+ {\r
+ hdc2 = CreateCompatibleDC(GetDC(FrameWnd));\r
+ SelectObject(hdc2, ppage_bmps[PicoPicohw.page]);\r
+ BitBlt(hdc, 0, 0, 480, 240, hdc2, 0, 0, SRCCOPY);\r
+ DeleteDC(hdc2);\r
+ }\r
+ EndPaint(hwnd, &ps);\r
+ return 0;\r
+ case WM_CLOSE:\r
+ ShowWindow(hwnd, SW_HIDE);\r
+ CheckMenuItem(mpicohw, 1210, MF_UNCHECKED);\r
+ return 0;\r
+ }\r
+\r
+ return DefWindowProc(hwnd,msg,wparam,lparam);\r
+}\r
+\r
+static LRESULT CALLBACK PicoPadWndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)\r
+{\r
+ PAINTSTRUCT ps;\r
+ HDC hdc, hdc2;\r
+\r
+ switch (msg)\r
+ {\r
+ case WM_DESTROY: PicoPadWnd=NULL; break;\r
+ case WM_LBUTTONDOWN: in_vk_add_pl12 |= 0x20; return 0;\r
+ case WM_LBUTTONUP: in_vk_add_pl12 &= ~0x20; return 0;\r
+ case WM_MOUSEMOVE:\r
+ PicoPicohw.pen_pos[0] = 0x03c + LOWORD(lparam);\r
+ PicoPicohw.pen_pos[1] = 0x1fc + HIWORD(lparam);\r
+ SetTimer(FrameWnd, 100, 1000, NULL);\r
+ break;\r
+ case WM_KEYDOWN: in_vk_keydown(wparam); break;\r
+ case WM_KEYUP: in_vk_keyup(wparam); break;\r
+ case WM_PAINT:\r
+ if (ppad_bmp == NULL) break;\r
+ hdc = BeginPaint(hwnd, &ps);\r
+ hdc2 = CreateCompatibleDC(GetDC(FrameWnd));\r
+ SelectObject(hdc2, ppad_bmp);\r
+ BitBlt(hdc, 0, 0, 320, 240, hdc2, 0, 0, SRCCOPY);\r
+ EndPaint(hwnd, &ps);\r
+ DeleteDC(hdc2);\r
+ return 0;\r
+ case WM_CLOSE:\r
+ ShowWindow(hwnd, SW_HIDE);\r
+ CheckMenuItem(mpicohw, 1211, MF_UNCHECKED);\r
+ return 0;\r
+ }\r
+\r
+ return DefWindowProc(hwnd,msg,wparam,lparam);\r
+}\r
+\r
+\r
+static int FrameInit()\r
+{\r
+ WNDCLASS wc;\r
+ RECT rect={0,0,0,0};\r
+ HMENU mfile;\r
+ int style=0;\r
+ int left=0,top=0,width=0,height=0;\r
+\r
+ memset(&wc,0,sizeof(wc));\r
+\r
+ // Register the window class:\r
+ wc.lpfnWndProc=WndProc;\r
+ wc.hInstance=GetModuleHandle(NULL);\r
+ wc.hCursor=LoadCursor(NULL,IDC_ARROW);\r
+ wc.hbrBackground=CreateSolidBrush(0);\r
+ wc.lpszClassName="PicoMainFrame";\r
+ RegisterClass(&wc);\r
+\r
+ wc.lpszClassName="PicoSwWnd";\r
+ wc.lpfnWndProc=PicoSwWndProc;\r
+ RegisterClass(&wc);\r
+\r
+ wc.lpszClassName="PicoPadWnd";\r
+ wc.lpfnWndProc=PicoPadWndProc;\r
+ RegisterClass(&wc);\r
+\r
+ rect.right =320;\r
+ rect.bottom=224;\r
+\r
+ // Adjust size of windows based on borders:\r
+ style=WS_OVERLAPPEDWINDOW;\r
+ AdjustWindowRect(&rect,style,1);\r
+ width =rect.right-rect.left;\r
+ height=rect.bottom-rect.top;\r
+\r
+ // Place window in the centre of the screen:\r
+ SystemParametersInfo(SPI_GETWORKAREA,0,&rect,0);\r
+ left=rect.left+rect.right;\r
+ top=rect.top+rect.bottom;\r
+\r
+ left-=width; left>>=1;\r
+ top-=height; top>>=1;\r
+\r
+ // Create menu:\r
+ mfile = CreateMenu();\r
+ InsertMenu(mfile, -1, MF_BYPOSITION|MF_STRING, 1000, "&Load ROM");\r
+ InsertMenu(mfile, -1, MF_BYPOSITION|MF_STRING, 1001, "&Reset");\r
+ InsertMenu(mfile, -1, MF_BYPOSITION|MF_STRING, 1002, "E&xit");\r
+ mdisplay = CreateMenu();\r
+ InsertMenu(mdisplay, -1, MF_BYPOSITION|MF_STRING, 1100, "320x224");\r
+ InsertMenu(mdisplay, -1, MF_BYPOSITION|MF_STRING, 1101, "256x224");\r
+ InsertMenu(mdisplay, -1, MF_BYPOSITION|MF_STRING, 1102, "640x448");\r
+ InsertMenu(mdisplay, -1, MF_BYPOSITION|MF_STRING, 1103, "512x448");\r
+ InsertMenu(mdisplay, -1, MF_BYPOSITION|MF_STRING, 1104, "Lock to 1:1");\r
+ mpicohw = CreateMenu();\r
+ InsertMenu(mpicohw, -1, MF_BYPOSITION|MF_STRING, 1210, "Show &Storyware");\r
+ InsertMenu(mpicohw, -1, MF_BYPOSITION|MF_STRING, 1211, "Show &Drawing pad");\r
+ InsertMenu(mpicohw, -1, MF_BYPOSITION|MF_STRING, 1212, "&Main window as pad");\r
+ InsertMenu(mpicohw, -1, MF_BYPOSITION|MF_SEPARATOR, 0, NULL);\r
+ InsertMenu(mpicohw, -1, MF_BYPOSITION|MF_STRING, 1220, "Title page (&0)");\r
+ InsertMenu(mpicohw, -1, MF_BYPOSITION|MF_STRING, 1221, "Page &1");\r
+ InsertMenu(mpicohw, -1, MF_BYPOSITION|MF_STRING, 1222, "Page &2");\r
+ InsertMenu(mpicohw, -1, MF_BYPOSITION|MF_STRING, 1223, "Page &3");\r
+ InsertMenu(mpicohw, -1, MF_BYPOSITION|MF_STRING, 1224, "Page &4");\r
+ InsertMenu(mpicohw, -1, MF_BYPOSITION|MF_STRING, 1225, "Page &5");\r
+ InsertMenu(mpicohw, -1, MF_BYPOSITION|MF_STRING, 1226, "Page &6");\r
+ mmain = CreateMenu();\r
+ InsertMenu(mmain, -1, MF_BYPOSITION|MF_STRING|MF_POPUP, (UINT_PTR) mfile, "&File");\r
+ InsertMenu(mmain, -1, MF_BYPOSITION|MF_STRING|MF_POPUP, (UINT_PTR) mdisplay, "&Display");\r
+ InsertMenu(mmain, -1, MF_BYPOSITION|MF_STRING|MF_POPUP, (UINT_PTR) mpicohw, "&Pico");\r
+ EnableMenuItem(mmain, 2, MF_BYPOSITION|MF_GRAYED);\r
+// InsertMenu(mmain, -1, MF_BYPOSITION|MF_STRING|MF_POPUP, 1200, "&Config");\r
+ InsertMenu(mmain, -1, MF_BYPOSITION|MF_STRING, 1300, "&About");\r
+\r
+ // Create the window:\r
+ FrameWnd=CreateWindow("PicoMainFrame","PicoDrive " VERSION,style|WS_VISIBLE,\r
+ left,top,width,height,NULL,mmain,NULL,NULL);\r
+\r
+ CheckMenuItem(mdisplay, 1104, lock_to_1_1 ? MF_CHECKED : MF_UNCHECKED);\r
+ ShowWindow(FrameWnd, SW_NORMAL);\r
+ UpdateWindow(FrameWnd);\r
+ UpdateRect();\r
+\r
+ // create Pico windows\r
+ style = WS_OVERLAPPED|WS_CAPTION|WS_BORDER|WS_SYSMENU;\r
+ rect.left=rect.top=0;\r
+ rect.right =320;\r
+ rect.bottom=224;\r
+\r
+ AdjustWindowRect(&rect,style,1);\r
+ width =rect.right-rect.left;\r
+ height=rect.bottom-rect.top;\r
+\r
+ left += 326;\r
+ PicoSwWnd=CreateWindow("PicoSwWnd","Storyware",style,\r
+ left,top,width+160,height,FrameWnd,NULL,NULL,NULL);\r
+\r
+ top += 266;\r
+ PicoPadWnd=CreateWindow("PicoPadWnd","Drawing Pad",style,\r
+ left,top,width,height,FrameWnd,NULL,NULL,NULL);\r
+\r
+ return 0;\r
+}\r
+\r
+// --------------------\r
+\r
+static DWORD WINAPI work_thread(void *x)\r
+{\r
+ while (engineState != PGS_Quit) {\r
+ WaitForSingleObject(loop_enter_event, INFINITE);\r
+ if (engineState != PGS_Running)\r
+ continue;\r
+\r
+ printf("loop..\n");\r
+ emu_loop();\r
+ SetEvent(loop_end_event);\r
+ }\r
+\r
+ return 0;\r
+}\r
+\r
+// XXX: use main.c\r
+void xxinit(void)\r
+{\r
+ /* in_init() must go before config, config accesses in_ fwk */\r
+ in_init();\r
+ pemu_prep_defconfig();\r
+ emu_read_config(0, 0);\r
+ config_readlrom(PicoConfigFile);\r
+\r
+ plat_init();\r
+ in_probe();\r
+\r
+ emu_init();\r
+ menu_init();\r
+}\r
+\r
+\r
+int WINAPI WinMain(HINSTANCE p1, HINSTANCE p2, LPSTR cmdline, int p4)\r
+{\r
+ MSG msg;\r
+ DWORD tid = 0;\r
+ HANDLE thread;\r
+ int ret;\r
+\r
+ xxinit();\r
+ FrameInit();\r
+ ret = DirectInit();\r
+ if (ret)\r
+ goto end0;\r
+\r
+ loop_enter_event = CreateEvent(NULL, 0, 0, NULL);\r
+ if (loop_enter_event == NULL)\r
+ goto end0;\r
+\r
+ loop_end_event = CreateEvent(NULL, 0, 0, NULL);\r
+ if (loop_end_event == NULL)\r
+ goto end0;\r
+\r
+ thread = CreateThread(NULL, 0, work_thread, NULL, 0, &tid);\r
+ if (thread == NULL)\r
+ goto end0;\r
+\r
+ LoadROM(cmdline);\r
+\r
+ // Main window loop:\r
+ for (;;)\r
+ {\r
+ GetMessage(&msg,NULL,0,0);\r
+ if (msg.message==WM_QUIT) break;\r
+\r
+ TranslateMessage(&msg);\r
+ DispatchMessage(&msg);\r
+ }\r
+\r
+ // Signal thread to quit and wait for it to exit:\r
+ if (engineState == PGS_Running) {\r
+ engineState = PGS_Quit;\r
+ WaitForSingleObject(loop_end_event, 5000);\r
+ }\r
+ CloseHandle(thread); thread=NULL;\r
+\r
+ emu_write_config(0);\r
+ emu_finish();\r
+ //plat_finish();\r
+\r
+end0:\r
+ DirectExit();\r
+ DestroyWindow(FrameWnd);\r
+\r
+// _CrtDumpMemoryLeaks();\r
+ return 0;\r
+}\r
+\r