--- xmil/pccore.c 2004/08/02 13:38:46 1.3 +++ xmil/pccore.c 2008/06/02 20:07:30 1.38 @@ -1,106 +1,120 @@ + +/* #define SINGLESTEPONLY */ +/* #define IPTRACE (1 << 14) */ +/* #define NEVENT_COUNTER */ +/* #define PCCOUNTER */ +/* #define IOCOUNTER */ +/* #define CTCCOUNTER */ + #include "compiler.h" +#if defined(TRACE) && IPTRACE #include "dosio.h" +#endif +#if defined(SUPPORT_TURBOZ) #include "scrnmng.h" +#endif +#if !defined(DISABLE_SOUND) #include "soundmng.h" +#endif #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 "x1_vram.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}; - - PCCORE pccore = {250, 0, 1, 1, 0}; - BYTE mMAIN[0x10000]; - BYTE mBIOS[0x8000]; - BYTE mBANK[16][0x8000]; -// BYTE KNJ_FNT[0x4bc00]; - BYTE GRP_RAM[0x20000]; - BYTE TXT_RAM[0x01800]; - WORD v_cnt; - int s_cnt; - - BYTE *RAM0r; - BYTE *RAM0w; - BYTE lastmem; - DWORD h_cntbase; - BRESULT soundrenewal; + XMILCFG xmilcfg = { 2, 1, 0x03, + 1, 0, 0, 0, +#if !defined(DISABLE_SOUND) + 22050, 500, +#if defined(SUPPORT_TURBOZ) || defined(SUPPORT_OPM) + 0, 64, +#endif + 64, 0, 80, +#endif + 0, 0, 0, 0}; + PCCORE pccore; + CORESTAT corestat; -/*********************************************************************** - IPL-ROM LOAD -***********************************************************************/ - -void ipl_load(void) { - - FILEH hdl; - - ZeroMemory(mBIOS, sizeof(mBIOS)); - memcpy(mBIOS, DEFROM, sizeof(DEFROM)); - - if (pccore.ROM_TYPE >= 2) { - if ((hdl = file_open_c("IPLROM.X1T")) != FILEH_INVALID) { - file_read(hdl, mBIOS, 0x8000); - file_close(hdl); - } - } - else if (pccore.ROM_TYPE == 1) { - if ((hdl = file_open_c("IPLROM.X1")) != FILEH_INVALID) { - file_read(hdl, mBIOS, 0x8000); - file_close(hdl); - } - } +/* ---- */ + +void pccore_initialize(void) { + + Z80_INITIALIZE(); + fddfile_initialize(); + sndctrl_initialize(); + makescrn_initialize(); + + font_load(NULL, TRUE); + + crtc_initialize(); + pcg_initialize(); + ppi_initialize(); } +void pccore_deinitialize(void) { -/*********************************************************************** - FONT-ROM LOAD -***********************************************************************/ + sndctrl_deinitialize(); -void fnt_load(void) { + fddfile_eject(0); + fddfile_eject(1); + fddfile_eject(2); + fddfile_eject(3); +} - font_load(NULL, TRUE); +#if 0 +void neitem_dummy(UINT id) { + + nevent_repeat(id); } +#endif + +void pccore_reset(void) { + +#if !defined(DISABLE_SOUND) + soundmng_stop(); + if (corestat.soundrenewal) { + corestat.soundrenewal = 0; + sndctrl_deinitialize(); + sndctrl_initialize(); + } +#endif +#if !defined(FIX_Z80A) + pccore.baseclock = 2000000; + pccore.multiple = 2; + pccore.realclock = pccore.baseclock * pccore.multiple; +#endif -/*********************************************************************** - 初期化 -***********************************************************************/ - -BYTE reset_x1(BYTE ROM_TYPE, BYTE SOUND_SW, BYTE DIP_SW) { - - pccore.HSYNC_CLK = 250; - pccore.ROM_SW = 1; - pccore.ROM_TYPE = ROM_TYPE; - pccore.SOUND_SW = SOUND_SW; - pccore.DIP_SW = DIP_SW; + pccore.ROM_TYPE = xmilcfg.ROM_TYPE; +#if defined(SUPPORT_TURBOZ) || defined(SUPPORT_OPM) + if (xmilcfg.ROM_TYPE >= 3) { + pccore.SOUND_SW = 1; /* 無条件で搭載 */ + } + else { + pccore.SOUND_SW = xmilcfg.SOUND_SW; + } +#endif + pccore.DIP_SW = xmilcfg.DIP_SW; - // スクリーンモードの変更... + /* スクリーンモードの変更... */ +#if defined(SUPPORT_TURBOZ) if (pccore.ROM_TYPE >= 3) { if (scrnmng_setcolormode(TRUE) != SUCCESS) { pccore.ROM_TYPE = 2; @@ -109,92 +123,31 @@ BYTE reset_x1(BYTE ROM_TYPE, BYTE SOUND_ else { scrnmng_setcolormode(FALSE); } +#endif - textdrawproc_renewal(); - ipl_load(); - - Z80_RESET(); - - lastmem = 0x78; - RAM0r = mBIOS; - RAM0w = mMAIN; - h_cntbase = 0; sysmng_cpureset(); - calendar_initialize(); + sound_changeclock(); + sound_reset(); - subcpu_reset(); - ppi_reset(); - init_crtc(); - init_vram(); - - cgrom_reset(); - cmt_reset(); - ctc_reset(); - dmac_reset(); - fdc_reset(); - pcg_reset(); - sio_reset(); - sndboard_reset(); + Z80_RESET(); + nevent_allreset(); + ievent_reset(); + calendar_reset(); + iocore_reset(); +/* nevent_set(15, 4000000 / (60 * 50), neitem_dummy, NEVENT_RELATIVE); */ + pal_reset(); + makescrn_reset(); timing_reset(); - return(SUCCESS); -} - - - -/*********************************************************************** - 実行/終了 -***********************************************************************/ - -static BYTE keyintcnt = 0; -static BYTE flame = 0; -static BYTE inttiming = 0; - -void pccore_initialize(void) { - - sndctrl_initialize(); - - init_draw(); - fnt_load(); - - pcg_initialize(); - ppi_initialize(); - reset_x1(xmilcfg.ROM_TYPE, xmilcfg.SOUND_SW, xmilcfg.DIP_SW); - -// keystat_initialize(); -// keystat_reset(); -} - -void pccore_reset(void) { - - soundmng_stop(); - if (soundrenewal) { - soundrenewal = 0; - sndctrl_deinitialize(); - sndctrl_initialize(); - } - reset_x1(xmilcfg.ROM_TYPE, xmilcfg.SOUND_SW, xmilcfg.DIP_SW); +#if !defined(DISABLE_SOUND) soundmng_play(); +#endif } -void pccore_deinitialize(void) { - - sndctrl_deinitialize(); - -// keyboard_term(); - - fdd_eject(0); - fdd_eject(1); - fdd_eject(2); - fdd_eject(3); -} - - -// ---- -// #define IPTRACE (1 << 14) +/* ---- */ #if defined(TRACE) && IPTRACE static UINT trpos = 0; @@ -226,71 +179,183 @@ void iptrace_out(void) { #endif +#if !defined(MAINFRAMES_OLD) +void neitem_mainframes(UINT id) { + + SINT32 clock; + REG8 ppib; + SINT32 next; + + clock = CPU_CLOCKCOUNT - iocore.e.framestartclock; + ppib = iocore.s.ppib & (~0x84); + do { + next = iocore.e.dispclock; + if (clock < next) { + ppib |= 0x80; + break; + } + next = iocore.e.dispclock; + if (clock < next) { + if (xmilcfg.DISPSYNC & 1) { + scrnupdate(); + } + break; + } + next = iocore.e.vsyncend; + if (clock < next) { + ppib |= 0x04; + break; + } + next = corestat.framebaseclock; + if (clock >= next) { + corestat.vsync = 2; + return; + } + } while(0); + iocore.s.ppib = ppib; + nevent_set(NEVENT_FRAMES, + next - clock, neitem_mainframes, NEVENT_ABSOLUTE); +} +#else +void neitem_disp(UINT id) { + + corestat.vsync = 1; + if (xmilcfg.DISPSYNC & 1) { + scrnupdate(); + } + nevent_set(id, corestat.syncclock, neitem_vsync, NEVENT_RELATIVE); +} + +void neitem_vsync(UINT id) { + + corestat.vsync = 2; + (void)id; +} +#endif + + +/* ---- */ + +#if defined(TRACE) && defined(IOCOUNTER) +static UINT iocounter = 0; + UINT icounter[0x2008]; + UINT ocounter[0x2008]; +#endif +#if defined(TRACE) && defined(CTCCOUNTER) + UINT ctccnt; +#endif +#if defined(TRACE) && defined(PCCOUNTER) + UINT pccnt; + UINT pccnt2; + UINT pccnt3; + UINT lastpc; +#endif + +void pccore_exec(BRESULT draw) { + + SINT32 frameclock; +#if defined(MAINFRAMES_OLD) + SINT32 dispclock; +#endif +#if defined(TRACE) && defined(NEVENT_COUNTER) + UINT ncounter = 0; +#endif -void x1r_exec(void) { + corestat.drawframe = draw; + pal_eventclear(); +#if !defined(DISABLE_SOUND) + soundmng_sync(); +#endif -extern BYTE disp_flashscreen; + frameclock = crtc.e.frameclock; + if (corestat.framebaseclock != frameclock) { + corestat.framebaseclock = frameclock; + timing_setrate(frameclock); + } + corestat.vsync = 0; + + iocore.e.framestartclock = CPU_CLOCKCOUNT; + +#if !defined(MAINFRAMES_OLD) + neitem_mainframes(NEVENT_FRAMES); +#else +#if !defined(FIX_Z80A) + frameclock = frameclock * pccore.multiple / 2; +#endif + dispclock = min(frameclock, iocore.e.dispclock); + corestat.syncclock = frameclock - dispclock; + nevent_set(NEVENT_FRAMES, dispclock, neitem_disp, NEVENT_RELATIVE); +#endif - 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")); -// } + do { +#if defined(TRACE) && defined(NEVENT_COUNTER) + ncounter++; #endif -#if IPTRACE +#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_EXECUTE(); - z80dmap(); + Z80_STEP(); } - 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(); +#endif + nevent_progress(); + ievent_progress(); + } while(corestat.vsync < 2); + + scrnupdate(); + sound_sync(); + fdc_callback(); + +#if defined(TRACE) && defined(NEVENT_COUNTER) + TRACEOUT(("loop = %d", ncounter)); +#endif +#if defined(TRACE) && defined(CTCCOUNTER) + TRACEOUT(("ctc = %d", ctccnt)); + ctccnt = 0; +#endif +#if defined(TRACE) && defined(PCCOUNTER) + TRACEOUT(("pccnt = %d %d %d", pccnt, pccnt2, pccnt3)); + pccnt = 0; + pccnt2 = 0; + pccnt3 = 0; +#endif +#if defined(TRACE) && defined(IOCOUNTER) + iocounter++; + if (iocounter >= 60) { + UINT i, j, cnt, pos; + iocounter = 0; + for (i=0; i<10; i++) { + cnt = 0; + pos = 0; + for (j=0; j<0x2004; j++) { + if (cnt < ocounter[j]) { + cnt = ocounter[j]; + pos = j; } } + ocounter[pos] = 0; + TRACEOUT(("o%2d - %.4x %8dtimes", i, pos, cnt)); } - v_cnt++; - if (crtc.CRT_YL == v_cnt) { -// TRACEOUT(("--->sync")); - pcg.r.vsync = 1; - if (xmilcfg.DISPSYNC == 1) { - xmilcfg.DISPSYNC |= 0x80; - scrnupdate(); + for (i=0; i<10; i++) { + cnt = 0; + pos = 0; + for (j=0; j<0x2004; j++) { + if (cnt < icounter[j]) { + cnt = icounter[j]; + pos = j; + } } + icounter[pos] = 0; + TRACEOUT(("i%2d - %.4x %8dtimes", i, pos, cnt)); } } - if (++flame >= 60) { - flame = 0; - calendar_inc(); - } - if (!xmilcfg.SOUNDPLY) { - sound_makesample(framesoundcnt); - } - if (!(xmilcfg.DISPSYNC & 0x80)) { - scrnupdate(); - } +#endif }