--- xmil/win9x/xmil.cpp 2004/08/04 15:18:26 1.5 +++ xmil/win9x/xmil.cpp 2004/08/08 06:59:22 1.11 @@ -10,26 +10,25 @@ #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 "x1_io.h" -#include "x1_crtc.h" +#include "iocore.h" #include "timing.h" -#include "draw.h" -#include "fdd_ini.h" -#include "juliet.h" -#include "diskdrv.h" +#include "keystat.h" #include "debugsub.h" +#include "scrndraw.h" +#include "makescrn.h" +#include "diskdrv.h" +#include "fdd_ini.h" #include "x1f.h" @@ -37,7 +36,7 @@ static const OEMCHAR szClassName[] = OEM XMILOSCFG xmiloscfg = { CW_USEDEFAULT, CW_USEDEFAULT, - 1, 0, 0, + 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0xffffff, 0xffbf6a}; @@ -49,8 +48,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) { @@ -259,29 +258,35 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT break; case IDM_WIDTH80: - crtc.TXT_XL = 80; - crtc.GRP_XL = 640; + crtc.s.TXT_XL = 80; + crtc.s.GRP_XL = 640; vrambank_patch(); scrnallflash = 1; break; case IDM_WIDTH40: - crtc.TXT_XL = 40; - crtc.GRP_XL = 320; + crtc.s.TXT_XL = 40; + crtc.s.GRP_XL = 320; vrambank_patch(); scrnallflash = 1; break; case IDM_DISPSYNC: xmenu_setdispmode(xmilcfg.DISPSYNC ^ 1); + updateflag = SYS_UPDATECFG; break; +// case IDM_RASTER: +// menu_setraster(xmilcfg.RASTER ^ 1); +// updateflag = SYS_UPDATECFG; +// break; + case IDM_NOWAIT: - xmenu_setwaitflg(xmilcfg.NOWAIT ^ 1); + xmenu_setwaitflg(xmiloscfg.NOWAIT ^ 1); updateflag = SYS_UPDATECFG; break; - case IDM_RASTER: + case IDM_AUTOFPS: xmenu_setframe(0); updateflag = SYS_UPDATECFG; break; @@ -403,14 +408,14 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT 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); } @@ -630,6 +635,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) { @@ -637,21 +683,27 @@ int WINAPI WinMain(HINSTANCE hInstance, WNDCLASS wc; MSG msg; + GetModuleFileName(NULL, modulefile, sizeof(modulefile)); + dosio_init(); + file_setcd(modulefile); + initload(); + +// rand_setseed((unsigned)time(NULL)); + 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; @@ -680,25 +732,24 @@ 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_setresolute(xmilcfg.DIP_SW); + xmenu_setdispmode(xmilcfg.DISPSYNC); +// xmenu_setraster(xmilcfg.RASTER); + xmenu_setwaitflg(xmiloscfg.NOWAIT); + xmenu_setframe(xmiloscfg.DRAW_SKIP); xmenu_setkey(0); - xmenu_setbtnrapid(xmilcfg.BTN_RAPID); - xmenu_setbtnmode(xmilcfg.BTN_MODE); + xmenu_setsound(xmilcfg.SOUND_SW); + xmenu_setjoystick(xmiloscfg.JOYSTICK); + xmenu_setmouse(xmilcfg.MOUSE_SW); 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); + xmenu_setskipline(xmilcfg.SKIP_LINE); + xmenu_setbtnmode(xmilcfg.BTN_MODE); + xmenu_setbtnrapid(xmilcfg.BTN_RAPID); + xmenu_setz80save(xmiloscfg.Z80SAVE); ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); @@ -721,12 +772,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); @@ -734,6 +783,9 @@ int WINAPI WinMain(HINSTANCE hInstance, soundmng_pcmvolume(SOUND_PCMSEEK1, xmilcfg.MOTORVOL); } + sysmng_initialize(); + joymng_initialize(); + pccore_initialize(); pccore_reset(); @@ -754,36 +806,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); + } } } - if ((xmilcfg.NOWAIT) || (timing_getcount())) { - timing_setcount(0); - joymng_sync(); - mousemng_sync(); - juliet2_sync(25); - x1r_exec(); - x1f_sync(); + else if (xmiloscfg.DRAW_SKIP) { // frame skip + if (framecnt < xmiloscfg.DRAW_SKIP) { + exec1frame(); + } + else { + processwait(xmiloscfg.DRAW_SKIP); + } + } + 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; }