--- xmil/pccore.c 2004/08/04 15:18:25 1.6 +++ xmil/pccore.c 2004/08/11 13:53:53 1.21 @@ -4,55 +4,47 @@ #include "soundmng.h" #include "sysmng.h" #include "timemng.h" +#include "xmilver.h" #include "z80core.h" #include "pccore.h" #include "iocore.h" -#include "x1_io.h" -#include "x1_crtc.h" -#include "draw.h" +#include "nevent.h" +#include "ievent.h" +#include "timing.h" +#include "calendar.h" +#include "keystat.h" +#include "palettes.h" +#include "makescrn.h" #include "sound.h" #include "sndctrl.h" -#include "menu.h" #include "font.h" -#include "juliet.h" -#include "xmilver.h" #include "fddfile.h" -#include "calendar.h" -#include "timing.h" #include "defrom.res" -#include "keystat.h" const OEMCHAR xmilversion[] = OEMTEXT(XMILVER_CORE); - XMILCFG xmilcfg = { 0, 0, 1, 0, 1, 2, 0, 1, - 22050, 1000, 0, 80, - 0, 0, - 0, 0, - 0, 0, 0, - 1, - 1, 0}; + XMILCFG xmilcfg = { 2, 0, 1, + 1, 0, 0, 0, + 22050, 500, 0, 0, 80, + 0, 0, 0, 0}; - PCCORE pccore = {250, 0, 1, 1, 0}; + PCCORE pccore; + CORESTAT corestat; BYTE mMAIN[0x10000]; BYTE mBIOS[0x8000]; - BYTE mBANK[16][0x8000]; - WORD v_cnt; - int s_cnt; - +#if defined(SUPPORT_BANKMEM) + UINT8 mBANK[16][0x8000]; +#endif BYTE *RAM0r; BYTE *RAM0w; - BYTE lastmem; - DWORD h_cntbase; - BRESULT soundrenewal; - /*********************************************************************** IPL-ROM LOAD ***********************************************************************/ -void ipl_load(void) { +static void ipl_load(void) { FILEH hdl; @@ -75,23 +67,15 @@ void ipl_load(void) { /*********************************************************************** - FONT-ROM LOAD -***********************************************************************/ - -void fnt_load(void) { - - font_load(NULL, TRUE); -} - - -/*********************************************************************** 初期化 ***********************************************************************/ -BYTE reset_x1(BYTE ROM_TYPE, BYTE SOUND_SW, BYTE DIP_SW) { +static BRESULT reset_x1(BYTE ROM_TYPE, BYTE SOUND_SW, BYTE DIP_SW) { + + pccore.baseclock = 2000000; + pccore.multiple = 2; + pccore.realclock = pccore.baseclock * pccore.multiple; - pccore.HSYNC_CLK = 250; - pccore.ROM_SW = 1; pccore.ROM_TYPE = ROM_TYPE; pccore.SOUND_SW = SOUND_SW; pccore.DIP_SW = DIP_SW; @@ -105,34 +89,35 @@ BYTE reset_x1(BYTE ROM_TYPE, BYTE SOUND_ else { scrnmng_setcolormode(FALSE); } + sound_changeclock(); - textdrawproc_renewal(); ipl_load(); Z80_RESET(); + iocore_reset(); - lastmem = 0x78; RAM0r = mBIOS; RAM0w = mMAIN; - h_cntbase = 0; sysmng_cpureset(); calendar_initialize(); - subcpu_reset(); - ppi_reset(); - init_crtc(); - cgrom_reset(); cmt_reset(); + crtc_reset(); ctc_reset(); dmac_reset(); fdc_reset(); + memio_reset(); pcg_reset(); + ppi_reset(); sio_reset(); sndboard_reset(); + subcpu_reset(); vramio_reset(); + pal_reset(); + makescrn_reset(); timing_reset(); return(SUCCESS); } @@ -143,49 +128,45 @@ BYTE reset_x1(BYTE ROM_TYPE, BYTE SOUND_ 実行/終了 ***********************************************************************/ -static BYTE keyintcnt = 0; -static BYTE flame = 0; -static BYTE inttiming = 0; - void pccore_initialize(void) { + fddfile_initialize(); sndctrl_initialize(); + makescrn_initialize(); - init_draw(); - fnt_load(); + font_load(NULL, TRUE); + crtc_initialize(); pcg_initialize(); ppi_initialize(); +} - reset_x1(xmilcfg.ROM_TYPE, xmilcfg.SOUND_SW, xmilcfg.DIP_SW); +void pccore_deinitialize(void) { -// keystat_initialize(); -// keystat_reset(); + sndctrl_deinitialize(); + + fddfile_eject(0); + fddfile_eject(1); + fddfile_eject(2); + fddfile_eject(3); } void pccore_reset(void) { soundmng_stop(); - if (soundrenewal) { - soundrenewal = 0; + if (corestat.soundrenewal) { + corestat.soundrenewal = 0; sndctrl_deinitialize(); sndctrl_initialize(); } + sound_reset(); + + nevent_allreset(); + ievent_reset(); reset_x1(xmilcfg.ROM_TYPE, xmilcfg.SOUND_SW, xmilcfg.DIP_SW); soundmng_play(); } -void pccore_deinitialize(void) { - - sndctrl_deinitialize(); - -// keyboard_term(); - - fdd_eject(0); - fdd_eject(1); - fdd_eject(2); - fdd_eject(3); -} // ---- @@ -222,71 +203,94 @@ void iptrace_out(void) { #endif +#if 0 +void nvitem_raster(UINT id) { -void x1r_exec(void) { - -extern BYTE disp_flashscreen; - - v_cnt = 0; - s_cnt = 0; - xmilcfg.DISPSYNC &= 1; - inttiming = xmilcfg.CPU8MHz & 1; -// TRACEOUT(("*sync")); - - while(s_cnt < 266) { - while(h_cnt < pccore.HSYNC_CLK) { -#if defined(TRACE) -// TRACEOUT(("%.4x", Z80_PC)); -// if (Z80_PC == 0x8198) { -// TRACEOUT(("---->sound")); -// } -// if (Z80_PC == 0x8188) { -// TRACEOUT(("-- poll sound")); -// } -#endif -#if IPTRACE - treip[trpos & (IPTRACE - 1)] = Z80_PC; - trpos++; -#endif - Z80_EXECUTE(); - z80dmap(); + nevent_repeat(id); + sound_makesample(pcmbufsize[v_cnt]); +// x1_ctc_int(); + if (!((++keyintcnt) & 15)) { + x1_sub_int(); + if (xmilcfg.MOUSE_SW) { + sio_int(); } - h_cnt -= pccore.HSYNC_CLK; - h_cntbase += pccore.HSYNC_CLK; - inttiming ^= 2; - if (inttiming != 3) { - if (xmilcfg.SOUNDPLY) { - sound_makesample(pcmbufsize[s_cnt]); - juliet2_exec(); - } - s_cnt++; - x1_ctc_int(); - if (!((++keyintcnt) & 15)) { - x1_sub_int(); - if (xmilcfg.MOUSE_SW) { - sio_int(); - } - } - } - v_cnt++; - if (crtc.CRT_YL == v_cnt) { -// TRACEOUT(("--->sync")); - pcg.r.vsync = 1; - if (xmilcfg.DISPSYNC == 1) { - xmilcfg.DISPSYNC |= 0x80; - scrnupdate(); - } + } + v_cnt++; + if (crtc.s.CRT_YL == v_cnt) { + pcg.r.vsync = 1; + if (xmilcfg.DISPSYNC & 1) { + scrnupdate(); } } - if (++flame >= 60) { - flame = 0; - calendar_inc(); +} +#endif + +UINT pccore_getraster(UINT *h) { + + SINT32 work; + UINT vl; + + work = nevent_getwork(NEVENT_FRAMES); + vl = work / 250; + if (h) { + *h = work - (vl * 250); } - if (!xmilcfg.SOUNDPLY) { - sound_makesample(framesoundcnt); + if (corestat.vsync) { + vl += corestat.vl; } - if (!(xmilcfg.DISPSYNC & 0x80)) { + return(vl); +} + +void nvitem_vdisp(UINT id) { + + corestat.vsync = 1; + pcg.r.vsync = 1; + if (xmilcfg.DISPSYNC & 1) { scrnupdate(); } + nevent_set(NEVENT_FRAMES, (corestat.tl - corestat.vl) * 250, + nvitem_vsync, NEVENT_RELATIVE); +} + +void nvitem_vsync(UINT id) { + + corestat.vsync = 2; +} + + +// #define SINGLESTEPONLY + +void pccore_exec(BRESULT draw) { + + corestat.drawframe = draw; + soundmng_sync(); + + corestat.tl = 266 * pccore.multiple / 2; + corestat.vl = min(corestat.tl, crtc.s.CRT_YL); + corestat.vsync = 0; + nevent_set(NEVENT_FRAMES, corestat.vl * 250, + nvitem_vdisp, NEVENT_RELATIVE); + do { +#if !defined(SINGLESTEPONLY) + if (CPU_REMCLOCK > 0) { + Z80_EXECUTE(); + } +#else + while(CPU_REMCLOCK > 0) { + TRACEOUT(("%.4x", Z80_PC)); +#if defined(TRACE) && IPTRACE + treip[trpos & (IPTRACE - 1)] = Z80_PC; + trpos++; +#endif + Z80_STEP(); + } +#endif + nevent_progress(); + ievent_progress(); + } while(corestat.vsync < 2); + + scrnupdate(); + calendar_inc(); + sound_sync(); }