--- xmil/win9x/xmil.cpp 2004/08/04 17:09:25 1.6 +++ xmil/win9x/xmil.cpp 2004/08/19 09:50:23 1.23 @@ -10,25 +10,26 @@ #include "scrnmng.h" #include "soundmng.h" #include "sysmng.h" -#include "scrndraw.h" -#include "ddrawbmp.h" #include "winloc.h" #include "dclock.h" #include "winkbd.h" #include "menu.h" #include "ini.h" +#include "juliet.h" #include "extclass.h" #include "dialog.h" - #include "z80core.h" #include "pccore.h" #include "iocore.h" #include "timing.h" -#include "draw.h" -#include "fdd_ini.h" -#include "juliet.h" -#include "diskdrv.h" +#if defined(SUPPORT_RESUME) || defined(SUPPORT_STATSAVE) +#include "statsave.h" +#endif #include "debugsub.h" +#include "scrndraw.h" +#include "makescrn.h" +#include "diskdrv.h" +#include "fdd_ini.h" #include "x1f.h" @@ -36,8 +37,14 @@ static const OEMCHAR szClassName[] = OEM XMILOSCFG xmiloscfg = { CW_USEDEFAULT, CW_USEDEFAULT, - 1, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, +#if defined(SUPPORT_RESUME) + 0, +#endif +#if defined(SUPPORT_STATSAVE) + 1, +#endif 0, 0, 0xffffff, 0xffbf6a}; OEMCHAR szProgName[] = OEMTEXT("X millennium ¤Í¤³¤Á¤å¡Á¤ó"); @@ -48,8 +55,8 @@ static const OEMCHAR szClassName[] = OEM OEMCHAR fddfolder[MAX_PATH]; OEMCHAR bmpfilefolder[MAX_PATH]; -static BYTE xmilforeground = 0; - BYTE xmilopening = 1; +static BRESULT xmilstopemulate = FALSE; + UINT8 xmilopening = 1; static void wincentering(HWND hWnd) { @@ -93,9 +100,9 @@ static void winuileave(void) { static void dispbmp(HINSTANCE hinst, HDC hdc, const OEMCHAR *res, int x, int y) { - HBITMAP hbmp; - BITMAP bmp; - HDC hmdc; + HBITMAP hbmp; + BITMAP bmp; + HDC hmdc; hbmp = LoadBitmap(hinst, res); GetObject(hbmp, sizeof(bmp), &bmp); @@ -109,307 +116,411 @@ static void dispbmp(HINSTANCE hinst, HDC // ---- -LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { +#if defined(SUPPORT_RESUME) +static const OEMCHAR xmilresumeext[] = OEMTEXT(".sav"); +static const OEMCHAR str_resume[] = OEMTEXT("Resume"); +#endif +#if defined(SUPPORT_STATSAVE) +static const OEMCHAR xmilflagext[] = OEMTEXT(".sv%u"); +static const OEMCHAR str_statload[] = OEMTEXT("Status Load"); +#endif - PAINTSTRUCT ps; - RECT rc; - HDC hdc; - UINT updateflag; +#if defined(SUPPORT_RESUME) || defined(SUPPORT_STATSAVE) +static const OEMCHAR str_loaderr[] = OEMTEXT("Couldn't restart"); +static const OEMCHAR str_conflict[] = OEMTEXT("Conflict!\n\n%s\nContinue?"); + +static void getstatfilename(OEMCHAR *path, const OEMCHAR *ext, UINT size) { + + file_cpyname(path, modulefile, size); + file_cutext(path); + file_catname(path, ext, size); +} - switch (msg) { - case WM_CREATE: - extclass_wmcreate(hWnd); -#ifndef __GNUC__ - WINNLSEnableIME(hWnd, FALSE); +static int flagsave(const OEMCHAR *ext) { + + OEMCHAR path[MAX_PATH]; + int ret; + + getstatfilename(path, ext, NELEMENTS(path)); + soundmng_stop(); + ret = statsave_save(path); + if (ret) { + file_delete(path); + } + soundmng_play(); + return(ret); +} + +static void flagdelete(const OEMCHAR *ext) { + + OEMCHAR path[MAX_PATH]; + + getstatfilename(path, ext, NELEMENTS(path)); + file_delete(path); +} + +static int flagload(const OEMCHAR *ext, const OEMCHAR *title, BRESULT force) { + + int ret; + int id; + OEMCHAR path[MAX_PATH]; + OEMCHAR buf[1024]; + OEMCHAR buf2[1024 + 32]; + + getstatfilename(path, ext, NELEMENTS(path)); + winuienter(); + id = IDYES; + ret = statsave_check(path, buf, NELEMENTS(buf)); + if (ret & (~STATFLAG_DISKCHG)) { + MessageBox(hWndMain, str_loaderr, title, MB_OK | MB_ICONSTOP); + id = IDNO; + } + else if ((!force) && (ret & STATFLAG_DISKCHG)) { + OEMSPRINTF(buf2, str_conflict, buf); + id = MessageBox(hWndMain, buf2, title, + MB_YESNOCANCEL | MB_ICONQUESTION); + } + if (id == IDYES) { + statsave_load(path); +// toolwin_setfdd(0, fdd_diskname(0)); +// toolwin_setfdd(1, fdd_diskname(1)); + } + sysmng_workclockreset(); + sysmng_updatecaption(1); + winuileave(); + return(id); +} #endif + + +// ---- + +static void xmilcmd(HWND hWnd, UINT cmd) { + + UINT update; +#if defined(SUPPORT_STATSAVE) + OEMCHAR ext[16]; +#endif + + update = 0; + switch(cmd) { + case IDM_IPLRESET: + pccore_reset(); break; - case WM_SYSCOMMAND: - updateflag = 0; - switch(wParam) { - case IDM_SCREENCENTER: - if (!scrnmng_isfullscreen()) { - wincentering(hWnd); - } - break; + case IDM_NMIRESET: + Z80_NMI(); + break; - case IDM_SNAPENABLE: - sysmenu_setwinsnap(xmiloscfg.WINSNAP ^ 1); - updateflag = SYS_UPDATEOSCFG; - break; + case IDM_CONFIG: + winuienter(); + DialogBox(hInst, MAKEINTRESOURCE(IDD_CONFIG), + hWnd, (DLGPROC)CfgDialogProc); + winuileave(); + break; - case IDM_BACKGROUND: - sysmenu_setbackground(xmiloscfg.background ^ 1); - updateflag = SYS_UPDATEOSCFG; - break; + case IDM_NEWDISK: + winuienter(); + dialog_newdisk(hWnd); + winuileave(); + break; - case IDM_BGSOUND: - sysmenu_setbgsound(xmiloscfg.background ^ 2); - updateflag = SYS_UPDATEOSCFG; - break; + case IDM_EXIT: + SendMessage(hWnd, WM_CLOSE, 0, 0L); + break; - default: - return(DefWindowProc(hWnd, msg, wParam, lParam)); - } - sysmng_update(updateflag); + case IDM_FDD0OPEN: + winuienter(); + dialog_changefdd(hWnd, 0); + winuileave(); break; - case WM_COMMAND: - updateflag = 0; - switch(LOWORD(wParam)) { - case IDM_IPLRESET: -#if 1 - pccore_reset(); -#else - if ((!juliet_YM2151IsEnable()) && (changehz)) { - changehz = 0; - STREAM_TERM(); - STREAM_CREATE(); - } - if (reset_x1(xmilcfg.ROM_TYPE, - xmilcfg.SOUND_SW, xmilcfg.DIP_SW)) { - PostQuitMessage(0); - } -#endif - break; + case IDM_FDD0EJECT: + diskdrv_setfdd(0, NULL, 0); + break; - case IDM_NMIRESET: - Z80_NMI(); - break; + case IDM_FDD1OPEN: + winuienter(); + dialog_changefdd(hWnd, 1); + winuileave(); + break; - case IDM_CONFIG: - winuienter(); - DialogBox(hInst, MAKEINTRESOURCE(IDD_CONFIG), - hWnd, (DLGPROC)CfgDialogProc); - winuileave(); - break; + case IDM_FDD1EJECT: + diskdrv_setfdd(1, NULL, 0); + break; - case IDM_NEWDISK: - winuienter(); - dialog_newdisk(hWnd); - winuileave(); - break; + case IDM_FDD2OPEN: + winuienter(); + dialog_changefdd(hWnd, 2); + winuileave(); + break; - case IDM_EXIT: - SendMessage(hWnd, WM_CLOSE, 0, 0L); - break; + case IDM_FDD2EJECT: + diskdrv_setfdd(2, NULL, 0); + break; - case IDM_FDD0OPEN: - winuienter(); - dialog_changefdd(hWnd, 0); - winuileave(); - break; + case IDM_FDD3OPEN: + winuienter(); + dialog_changefdd(hWnd, 3); + winuileave(); + break; - case IDM_FDD0EJECT: - diskdrv_setfdd(0, NULL, 0); - break; + case IDM_FDD3EJECT: + diskdrv_setfdd(3, NULL, 0); + break; - case IDM_FDD1OPEN: - winuienter(); - dialog_changefdd(hWnd, 1); - winuileave(); - break; + case IDM_X1ROM: + menu_setiplrom(1); + update = SYS_UPDATECFG; + break; - case IDM_FDD1EJECT: - diskdrv_setfdd(1, NULL, 0); - break; + case IDM_TURBO: + menu_setiplrom(2); + update = SYS_UPDATECFG; + break; - case IDM_TURBOZ: - xmenu_setiplrom(3); - updateflag = SYS_UPDATECFG; - break; +#if defined(SUPPORT_TURBOZ) + case IDM_TURBOZ: + menu_setiplrom(3); + update = SYS_UPDATECFG; + break; +#endif - case IDM_TURBO: - xmenu_setiplrom(2); - updateflag = SYS_UPDATECFG; - break; + case IDM_BOOT2D: + menu_setbootmedia(0); + update = SYS_UPDATECFG; + break; - case IDM_X1ROM: - xmenu_setiplrom(1); - updateflag = SYS_UPDATECFG; - break; + case IDM_BOOT2HD: + menu_setbootmedia(DIPSW_BOOTMEDIA); + update = SYS_UPDATECFG; + break; - case IDM_BOOT2D: - xmenu_setbootmedia(0); - updateflag = SYS_UPDATECFG; - break; + case IDM_HIGHRES: + menu_setresolute(0); + update = SYS_UPDATECFG; + break; - case IDM_BOOT2HD: - xmenu_setbootmedia(DIPSW_BOOTMEDIA); - updateflag = SYS_UPDATECFG; - break; + case IDM_LOWRES: + menu_setresolute(DIPSW_RESOLUTE); + update = SYS_UPDATECFG; + break; - case IDM_HIGHRES: - xmenu_setresolute(0); - updateflag = SYS_UPDATECFG; - break; + case IDM_WINDOW: + scrnmng_changescreen(scrnmode & (~SCRNMODE_FULLSCREEN)); + break; - case IDM_LOWRES: - xmenu_setresolute(DIPSW_RESOLUTE); - updateflag = SYS_UPDATECFG; - break; + case IDM_FULLSCREEN: + scrnmng_changescreen(scrnmode | SCRNMODE_FULLSCREEN); + break; - case IDM_WINDOW: - scrnmng_changescreen(scrnmode & (~SCRNMODE_FULLSCREEN)); - break; + case IDM_DISPSYNC: + menu_setdispmode(xmilcfg.DISPSYNC ^ 1); + update = SYS_UPDATECFG; + break; - case IDM_FULLSCREEN: - scrnmng_changescreen(scrnmode | SCRNMODE_FULLSCREEN); - break; + case IDM_RASTER: + menu_setraster(xmilcfg.RASTER ^ 1); + if (xmilcfg.RASTER) { + scrnmng_changescreen(scrnmode | SCRNMODE_SYSHIGHCOLOR); + } + else { + scrnmng_changescreen(scrnmode & (~SCRNMODE_SYSHIGHCOLOR)); + } + update = SYS_UPDATECFG; + break; - case IDM_WIDTH80: - crtc.s.TXT_XL = 80; - crtc.s.GRP_XL = 640; - vrambank_patch(); - scrnallflash = 1; - break; + case IDM_NOWAIT: + menu_setwaitflg(xmiloscfg.NOWAIT ^ 1); + update = SYS_UPDATECFG; + break; - case IDM_WIDTH40: - crtc.s.TXT_XL = 40; - crtc.s.GRP_XL = 320; - vrambank_patch(); - scrnallflash = 1; - break; + case IDM_AUTOFPS: + menu_setframe(0); + update = SYS_UPDATECFG; + break; - case IDM_DISPSYNC: - xmenu_setdispmode(xmilcfg.DISPSYNC ^ 1); - break; + case IDM_60FPS: + menu_setframe(1); + update = SYS_UPDATECFG; + break; - case IDM_NOWAIT: - xmenu_setwaitflg(xmilcfg.NOWAIT ^ 1); - updateflag = SYS_UPDATECFG; - break; + case IDM_30FPS: + menu_setframe(2); + update = SYS_UPDATECFG; + break; - case IDM_RASTER: - xmenu_setframe(0); - updateflag = SYS_UPDATECFG; - break; + case IDM_20FPS: + menu_setframe(3); + update = SYS_UPDATECFG; + break; - case IDM_60FPS: - xmenu_setframe(1); - updateflag = SYS_UPDATECFG; - break; + case IDM_15FPS: + menu_setframe(4); + update = SYS_UPDATECFG; + break; - case IDM_30FPS: - xmenu_setframe(2); - updateflag = SYS_UPDATECFG; - break; + case IDM_KEY: + menu_setkey(0); + break; - case IDM_20FPS: - xmenu_setframe(3); - updateflag = SYS_UPDATECFG; - break; + case IDM_JOY1: + menu_setkey(1); + break; - case IDM_15FPS: - xmenu_setframe(4); - updateflag = SYS_UPDATECFG; - break; + case IDM_JOY2: + menu_setkey(2); + break; - case IDM_KEY: - xmenu_setkey(0); - break; + case IDM_FMBOARD: + menu_setsound(xmilcfg.SOUND_SW ^ 1); + update = SYS_UPDATECFG; + break; - case IDM_JOY1: - xmenu_setkey(1); - break; + case IDM_JOYSTICK: + menu_setjoystick(xmiloscfg.JOYSTICK ^ 1); + update = SYS_UPDATECFG; + break; - case IDM_JOY2: - xmenu_setkey(2); - break; + case IDM_MOUSE: + // mousemng_toggle(MOUSEPROC_SYSTEM); + menu_setmouse(xmilcfg.MOUSE_SW ^ 1); + update = SYS_UPDATECFG; + break; - case IDM_FMBOARD: - xmenu_setsound(xmilcfg.SOUND_SW ^ 1); - updateflag = SYS_UPDATECFG; - break; + case IDM_SEEKSND: + menu_setmotorflg(xmilcfg.MOTOR ^ 1); + update = SYS_UPDATECFG; + break; - case IDM_JOYSTICK: - xmenu_setjoystick(xmiloscfg.JOYSTICK ^ 1); - updateflag = SYS_UPDATECFG; - break; + case IDM_WIDTH40: + crtc_forcesetwidth(40); + break; - case IDM_MOUSE: - // mousemng_toggle(MOUSEPROC_SYSTEM); - xmenu_setmouse(xmilcfg.MOUSE_SW ^ 1); - updateflag = SYS_UPDATECFG; - break; + case IDM_WIDTH80: + crtc_forcesetwidth(80); + break; - case IDM_8MHZ: - xmenu_setcpuspeed(xmilcfg.CPU8MHz ^ 1); - updateflag = SYS_UPDATECFG; - break; + case IDM_Z80SAVE: + debugsub_status(); + break; - case IDM_SEEKSND: - xmenu_setmotorflg(xmilcfg.MOTOR ^ 1); - updateflag = SYS_UPDATECFG; - break; + case IDM_BMPSAVE: + winuienter(); + dialog_writebmp(hWnd); + winuileave(); + break; - case IDM_BMPSAVE: - winuienter(); - bmpsave(); - winuileave(); - break; + case IDM_OPMLOG: + winuienter(); + dialog_x1f(hWnd); + winuileave(); + break; - case IDM_OPMLOG: - winuienter(); - dialog_x1f(hWnd); - winuileave(); - break; + case IDM_DISPCLOCK: + menu_setdispclk(xmiloscfg.DISPCLK ^ 1); + update = SYS_UPDATECFG; + break; - case IDM_DISPCLOCK: - xmenu_setdispclk(xmiloscfg.DISPCLK ^ 1); - updateflag = SYS_UPDATECFG; - break; + case IDM_DISPFRAME: + menu_setdispclk(xmiloscfg.DISPCLK ^ 2); + update = SYS_UPDATECFG; + break; - case IDM_DISPFRAME: - xmenu_setdispclk(xmiloscfg.DISPCLK ^ 2); - updateflag = SYS_UPDATECFG; - break; + case IDM_JOYX: + menu_setbtnmode(xmilcfg.BTN_MODE ^ 1); + update = SYS_UPDATECFG; + break; - case IDM_SKIPLINE: - xmenu_setskipline(xmilcfg.SKIP_LINE ^ 1); - updateflag = SYS_UPDATECFG; - break; + case IDM_RAPID: + menu_setbtnrapid(xmilcfg.BTN_RAPID ^ 1); + update = SYS_UPDATECFG; + break; - case IDM_JOYX: - xmenu_setbtnmode(xmilcfg.BTN_MODE ^ 1); - updateflag = SYS_UPDATECFG; - break; + case IDM_ABOUT: + winuienter(); + DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUT), + hWnd, (DLGPROC)AboutDialogProc); + winuileave(); + break; + + default: +#if defined(SUPPORT_STATSAVE) + if ((cmd >= IDM_FLAGSAVE) && + (cmd < (IDM_FLAGSAVE + SUPPORT_STATSAVE))) { + OEMSPRINTF(ext, xmilflagext, cmd - IDM_FLAGSAVE); + flagsave(ext); + } + else if ((cmd >= IDM_FLAGLOAD) && + (cmd < (IDM_FLAGLOAD + SUPPORT_STATSAVE))) { + OEMSPRINTF(ext, xmilflagext, cmd - IDM_FLAGLOAD); + flagload(ext, str_statload, TRUE); + } +#endif + break; + } + sysmng_update(update); +} + +LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { + + PAINTSTRUCT ps; + RECT rc; + HDC hdc; + UINT updateflag; - case IDM_RAPID: - xmenu_setbtnrapid(xmilcfg.BTN_RAPID ^ 1); - updateflag = SYS_UPDATECFG; + switch (msg) { + case WM_CREATE: + extclass_wmcreate(hWnd); +#ifndef __GNUC__ + WINNLSEnableIME(hWnd, FALSE); +#endif + break; + + case WM_SYSCOMMAND: + updateflag = 0; + switch(wParam) { + case IDM_SCREENCENTER: + if (!scrnmng_isfullscreen()) { + wincentering(hWnd); + } break; - case IDM_HALFBMP: - winuienter(); - bmpsavehalf(); - winuileave(); + case IDM_SNAPENABLE: + sysmenu_setwinsnap(xmiloscfg.WINSNAP ^ 1); + updateflag = SYS_UPDATEOSCFG; break; - case IDM_Z80SAVE: - debugsub_status(); + case IDM_BACKGROUND: + sysmenu_setbackground(xmiloscfg.background ^ 1); + updateflag = SYS_UPDATEOSCFG; break; - case IDM_ABOUT: - winuienter(); - DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUT), - hWnd, (DLGPROC)AboutDialogProc); - winuileave(); + case IDM_BGSOUND: + sysmenu_setbgsound(xmiloscfg.background ^ 2); + updateflag = SYS_UPDATEOSCFG; break; + + default: + return(DefWindowProc(hWnd, msg, wParam, lParam)); } sysmng_update(updateflag); break; + case WM_COMMAND: + xmilcmd(hWnd, LOWORD(wParam)); + break; + case WM_ACTIVATE: if (LOWORD(wParam) != WA_INACTIVE) { - xmilforeground = 0; + xmilstopemulate = FALSE; scrnmng_update(); mousemng_enable(MOUSEPROC_BG); soundmng_enable(SNDPROC_MASTER); } else { - xmilforeground = 1; mousemng_disable(MOUSEPROC_BG); + xmilstopemulate = (xmiloscfg.background & 1)?TRUE:FALSE; if (xmiloscfg.background) { soundmng_disable(SNDPROC_MASTER); } @@ -498,7 +609,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT case WM_KEYDOWN: if (wParam == VK_F12) { mousemng_toggle(MOUSEPROC_SYSTEM); - // xmenu_setmouse(np2oscfg.MOUSE_SW ^ 1); + // menu_setmouse(np2oscfg.MOUSE_SW ^ 1); // sysmng_update(SYS_UPDATECFG); } else { @@ -578,7 +689,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT case WM_MBUTTONDOWN: mousemng_toggle(MOUSEPROC_SYSTEM); - // xmenu_setmouse(np2oscfg.MOUSE_SW ^ 1); + // menu_setmouse(np2oscfg.MOUSE_SW ^ 1); // sysmng_update(SYS_UPDATECFG); break; @@ -629,6 +740,47 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT // ---- +static UINT framecnt = 0; +static UINT waitcnt = 0; +static UINT framemax = 1; + +static void framereset(UINT cnt) { + + framecnt = 0; + scrnmng_dispclock(); +// kdispwin_draw((BYTE)cnt); +// skbdwin_process(); +// mdbgwin_process(); +// toolwin_draw((BYTE)cnt); +// viewer_allreload(FALSE); + if (xmiloscfg.DISPCLK & 3) { + if (sysmng_workclockrenewal()) { + sysmng_updatecaption(3); + } + } +} + +static void processwait(UINT cnt) { + + if (timing_getcount() >= cnt) { + timing_setcount(0); + framereset(cnt); + } + else { + Sleep(1); + } + soundmng_sync(); +} + +static void exec1frame(void) { + + joymng_sync(); + mousemng_sync(); + pccore_exec(framecnt == 0); + dclock_callback(); + framecnt++; +} + int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInst, LPSTR lpszCmdLine, int nCmdShow) { @@ -636,21 +788,25 @@ int WINAPI WinMain(HINSTANCE hInstance, WNDCLASS wc; MSG msg; + GetModuleFileName(NULL, modulefile, sizeof(modulefile)); + dosio_init(); + file_setcd(modulefile); + initload(); + hWnd = FindWindow(szClassName, NULL); if (hWnd != NULL) { ShowWindow(hWnd, SW_RESTORE); SetForegroundWindow(hWnd); + dosio_term(); return(FALSE); } - GetModuleFileName(NULL, modulefile, sizeof(modulefile)); - file_setcd(modulefile); - initload(); - hInst = hInstance; hPreI = hPreInst; TRACEINIT(); +// keystat_initialize(); + if (!hPreInst) { wc.style = CS_BYTEALIGNCLIENT | CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; @@ -679,31 +835,27 @@ int WINAPI WinMain(HINSTANCE hInstance, hWndMain = hWnd; scrnmng_initialize(); - sysmng_updatecaption(3); - - xmenu_setiplrom(xmilcfg.ROM_TYPE); - xmenu_setsound(xmilcfg.SOUND_SW); - xmenu_setskipline(xmilcfg.SKIP_LINE); - xmenu_setresolute(xmilcfg.DIP_SW); - xmenu_setbootmedia(xmilcfg.DIP_SW); - xmenu_setkey(0); - xmenu_setbtnrapid(xmilcfg.BTN_RAPID); - xmenu_setbtnmode(xmilcfg.BTN_MODE); - xmenu_setcpuspeed(xmilcfg.CPU8MHz); - xmenu_setwaitflg(xmilcfg.NOWAIT); - xmenu_setframe(xmilcfg.DRAW_SKIP); - xmenu_setmotorflg(xmilcfg.MOTOR); - xmenu_setz80save(xmiloscfg.Z80SAVE); - xmenu_setjoystick(xmiloscfg.JOYSTICK); - xmenu_setdispclk(xmiloscfg.DISPCLK); - xmenu_setdispmode(xmilcfg.DISPSYNC); - xmenu_setmouse(xmilcfg.MOUSE_SW); + menu_setiplrom(xmilcfg.ROM_TYPE); + menu_setbootmedia(xmilcfg.DIP_SW); + menu_setresolute(xmilcfg.DIP_SW); + menu_setdispmode(xmilcfg.DISPSYNC); + menu_setraster(xmilcfg.RASTER); + menu_setwaitflg(xmiloscfg.NOWAIT); + menu_setframe(xmiloscfg.DRAW_SKIP); + menu_setkey(0); + menu_setsound(xmilcfg.SOUND_SW); + menu_setjoystick(xmiloscfg.JOYSTICK); + menu_setmouse(xmilcfg.MOUSE_SW); + menu_setmotorflg(xmilcfg.MOTOR); + menu_setdispclk(xmiloscfg.DISPCLK); + menu_setbtnmode(xmilcfg.BTN_MODE); + menu_setbtnrapid(xmilcfg.BTN_RAPID); ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); sysmenu_initialize(); -// xmenu_initialize(); + menu_initialize(); DrawMenuBar(hWnd); sysmenu_setwinsnap(xmiloscfg.WINSNAP); @@ -712,6 +864,9 @@ int WINAPI WinMain(HINSTANCE hInstance, scrndraw_initialize(); scrnmode = 0; + if (xmilcfg.RASTER) { + scrnmode |= SCRNMODE_SYSHIGHCOLOR; + } if (scrnmng_create(scrnmode) != SUCCESS) { scrnmode ^= SCRNMODE_FULLSCREEN; if (scrnmng_create(scrnmode) != SUCCESS) { @@ -720,12 +875,10 @@ int WINAPI WinMain(HINSTANCE hInstance, return(FALSE); } } - joymng_initialize(); juliet_load(); juliet_prepare(); - - juliet2_reset(); +// juliet2_reset(); if (soundmng_initialize() == SUCCESS) { soundmng_pcmload(SOUND_PCMSEEK, OEMTEXT("fddseek.wav"), 0); soundmng_pcmload(SOUND_PCMSEEK1, OEMTEXT("fddseek1.wav"), 0); @@ -733,6 +886,9 @@ int WINAPI WinMain(HINSTANCE hInstance, soundmng_pcmvolume(SOUND_PCMSEEK1, xmilcfg.MOTORVOL); } + sysmng_initialize(); + joymng_initialize(); + pccore_initialize(); pccore_reset(); @@ -753,36 +909,72 @@ int WINAPI WinMain(HINSTANCE hInstance, xmilopening = 0; while(1) { - if (!(xmiloscfg.background & xmilforeground)) { + if (!xmilstopemulate) { if (PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE)) { if (!GetMessage(&msg, NULL, 0, 0)) { break; } - if ((msg.message != WM_SYSKEYDOWN) && - (msg.message != WM_SYSKEYUP)) { + if ((msg.hwnd != hWnd) || + ((msg.message != WM_SYSKEYDOWN) && + (msg.message != WM_SYSKEYUP))) { TranslateMessage(&msg); } DispatchMessage(&msg); } else { - if (xmiloscfg.DISPCLK) { - if (sysmng_workclockrenewal()) { - sysmng_updatecaption(2); + if (xmiloscfg.NOWAIT) { + exec1frame(); + if (xmiloscfg.DRAW_SKIP) { // nowait frame skip + if (framecnt >= xmiloscfg.DRAW_SKIP) { + processwait(0); + } + } + else { // nowait auto skip + if (timing_getcount()) { + processwait(0); + } + } + } + else if (xmiloscfg.DRAW_SKIP) { // frame skip + if (framecnt < xmiloscfg.DRAW_SKIP) { + exec1frame(); + } + else { + processwait(xmiloscfg.DRAW_SKIP); } } - if ((xmilcfg.NOWAIT) || (timing_getcount())) { - timing_setcount(0); - joymng_sync(); - mousemng_sync(); - juliet2_sync(25); - x1r_exec(); - x1f_sync(); + else { // auto skip + if (!waitcnt) { + UINT cnt; + exec1frame(); + cnt = timing_getcount(); + if (framecnt > cnt) { + waitcnt = framecnt; + if (framemax > 1) { + framemax--; + } + } + else if (framecnt >= framemax) { + if (framemax < 12) { + framemax++; + } + if (cnt >= 12) { + timing_reset(); + } + else { + timing_setcount(cnt - framecnt); + } + framereset(0); + } + } + else { + processwait(waitcnt); + waitcnt = framecnt; + } } - soundmng_sync(); - juliet2_exec(); } } - else { + else { // background sleep if (!GetMessage(&msg, NULL, 0, 0)) { break; }