| version 1.32, 2004/08/14 12:16:17 | version 1.38, 2008/06/02 20:07:30 | 
| Line 1 | Line 1 | 
 |  |  | 
 |  | /* #define      SINGLESTEPONLY */ | 
 |  | /* #define      IPTRACE                 (1 << 14) */ | 
 |  | /* #define      NEVENT_COUNTER */ | 
 |  | /* #define      PCCOUNTER */ | 
 |  | /* #define      IOCOUNTER */ | 
 |  | /* #define      CTCCOUNTER */ | 
 |  |  | 
 | #include        "compiler.h" | #include        "compiler.h" | 
 |  | #if defined(TRACE) && IPTRACE | 
 | #include        "dosio.h" | #include        "dosio.h" | 
 |  | #endif | 
 |  | #if defined(SUPPORT_TURBOZ) | 
 | #include        "scrnmng.h" | #include        "scrnmng.h" | 
 |  | #endif | 
 |  | #if !defined(DISABLE_SOUND) | 
 | #include        "soundmng.h" | #include        "soundmng.h" | 
 |  | #endif | 
 | #include        "sysmng.h" | #include        "sysmng.h" | 
 | #include        "timemng.h" | #include        "timemng.h" | 
 | #include        "xmilver.h" | #include        "xmilver.h" | 
| Line 19 | Line 33 | 
 | #include        "sndctrl.h" | #include        "sndctrl.h" | 
 | #include        "font.h" | #include        "font.h" | 
 | #include        "fddfile.h" | #include        "fddfile.h" | 
 | #include        "defrom.res" |  | 
 |  |  | 
 |  |  | 
 | const OEMCHAR xmilversion[] = OEMTEXT(XMILVER_CORE); | const OEMCHAR xmilversion[] = OEMTEXT(XMILVER_CORE); | 
 |  |  | 
 | XMILCFG         xmilcfg = { 2, 1, 0x03, | XMILCFG         xmilcfg = { 2, 1, 0x03, | 
 | 1, 0, 0, 0, | 1, 0, 0, 0, | 
| 22050, 500, 0, 0, 80, | #if !defined(DISABLE_SOUND) | 
|  | 22050, 500, | 
|  | #if defined(SUPPORT_TURBOZ) || defined(SUPPORT_OPM) | 
|  | 0, 64, | 
|  | #endif | 
|  | 64, 0, 80, | 
|  | #endif | 
 | 0, 0, 0, 0}; | 0, 0, 0, 0}; | 
 |  |  | 
 | PCCORE          pccore; | PCCORE          pccore; | 
 | CORESTAT        corestat; | CORESTAT        corestat; | 
 | UINT8           mMAIN[0x10000]; |  | 
 | UINT8           mBIOS[0x8000]; |  | 
 | #if defined(SUPPORT_BANKMEM) |  | 
 | UINT8           mBANK[16][0x8000]; |  | 
 | #endif |  | 
 | UINT8           *RAM0r; |  | 
 | UINT8           *RAM0w; |  | 
 |  |  | 
 |  |  | 
| // ---- | /* ---- */ | 
|  |  | 
| static void ipl_load(void) { |  | 
|  |  | 
| FILEH   hdl; |  | 
|  |  | 
| ZeroMemory(mBIOS, sizeof(mBIOS)); |  | 
| CopyMemory(mBIOS, DEFROM, sizeof(DEFROM)); |  | 
|  |  | 
| if (pccore.ROM_TYPE >= 2) { |  | 
| if ((hdl = file_open_c(OEMTEXT("IPLROM.X1T"))) != FILEH_INVALID) { |  | 
| file_read(hdl, mBIOS, 0x8000); |  | 
| file_close(hdl); |  | 
| } |  | 
| } |  | 
| else if (pccore.ROM_TYPE == 1) { |  | 
| if ((hdl = file_open_c(OEMTEXT("IPLROM.X1"))) != FILEH_INVALID) { |  | 
| file_read(hdl, mBIOS, 0x8000); |  | 
| file_close(hdl); |  | 
| } |  | 
| } |  | 
| } |  | 
|  |  | 
|  |  | 
| // ---- |  | 
 |  |  | 
 | void pccore_initialize(void) { | void pccore_initialize(void) { | 
 |  |  | 
 |  | Z80_INITIALIZE(); | 
 | fddfile_initialize(); | fddfile_initialize(); | 
 | sndctrl_initialize(); | sndctrl_initialize(); | 
 | makescrn_initialize(); | makescrn_initialize(); | 
| Line 89  void pccore_deinitialize(void) { | Line 78  void pccore_deinitialize(void) { | 
 | fddfile_eject(3); | fddfile_eject(3); | 
 | } | } | 
 |  |  | 
 |  | #if 0 | 
 |  | void neitem_dummy(UINT id) { | 
 |  |  | 
 |  | nevent_repeat(id); | 
 |  | } | 
 |  | #endif | 
 |  |  | 
 | void pccore_reset(void) { | void pccore_reset(void) { | 
 |  |  | 
 |  | #if !defined(DISABLE_SOUND) | 
 | soundmng_stop(); | soundmng_stop(); | 
 | if (corestat.soundrenewal) { | if (corestat.soundrenewal) { | 
 | corestat.soundrenewal = 0; | corestat.soundrenewal = 0; | 
 | sndctrl_deinitialize(); | sndctrl_deinitialize(); | 
 | sndctrl_initialize(); | sndctrl_initialize(); | 
 | } | } | 
 |  | #endif | 
 |  |  | 
 |  | #if !defined(FIX_Z80A) | 
 | pccore.baseclock = 2000000; | pccore.baseclock = 2000000; | 
 | pccore.multiple = 2; | pccore.multiple = 2; | 
 | pccore.realclock = pccore.baseclock * pccore.multiple; | pccore.realclock = pccore.baseclock * pccore.multiple; | 
 |  | #endif | 
 |  |  | 
 | pccore.ROM_TYPE = xmilcfg.ROM_TYPE; | pccore.ROM_TYPE = xmilcfg.ROM_TYPE; | 
| pccore.SOUND_SW = xmilcfg.SOUND_SW; | #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; | pccore.DIP_SW = xmilcfg.DIP_SW; | 
 |  |  | 
| // スクリーンモードの変更... | /* スクリーンモードの変更... */ | 
|  | #if defined(SUPPORT_TURBOZ) | 
 | if (pccore.ROM_TYPE >= 3) { | if (pccore.ROM_TYPE >= 3) { | 
 | if (scrnmng_setcolormode(TRUE) != SUCCESS) { | if (scrnmng_setcolormode(TRUE) != SUCCESS) { | 
 | pccore.ROM_TYPE = 2; | pccore.ROM_TYPE = 2; | 
| Line 115  void pccore_reset(void) { | Line 123  void pccore_reset(void) { | 
 | else { | else { | 
 | scrnmng_setcolormode(FALSE); | scrnmng_setcolormode(FALSE); | 
 | } | } | 
 |  | #endif | 
 |  |  | 
 | sysmng_cpureset(); | sysmng_cpureset(); | 
 |  |  | 
| Line 126  void pccore_reset(void) { | Line 135  void pccore_reset(void) { | 
 | ievent_reset(); | ievent_reset(); | 
 | calendar_reset(); | calendar_reset(); | 
 | iocore_reset(); | iocore_reset(); | 
|  | /*      nevent_set(15, 4000000 / (60 * 50), neitem_dummy, NEVENT_RELATIVE); */ | 
| ipl_load(); |  | 
|  |  | 
| RAM0r = mBIOS; |  | 
| RAM0w = mMAIN; |  | 
 |  |  | 
 | pal_reset(); | pal_reset(); | 
 | makescrn_reset(); | makescrn_reset(); | 
 | timing_reset(); | timing_reset(); | 
 |  |  | 
 |  | #if !defined(DISABLE_SOUND) | 
 | soundmng_play(); | soundmng_play(); | 
 |  | #endif | 
 | } | } | 
 |  |  | 
 |  |  | 
| // ---- | /* ---- */ | 
|  |  | 
| // #define      IPTRACE                 (1 << 14) |  | 
 |  |  | 
 | #if defined(TRACE) && IPTRACE | #if defined(TRACE) && IPTRACE | 
 | static  UINT    trpos = 0; | static  UINT    trpos = 0; | 
| Line 174  void iptrace_out(void) { | Line 179  void iptrace_out(void) { | 
 | #endif | #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) { | void neitem_disp(UINT id) { | 
 |  |  | 
 | corestat.vsync = 1; | corestat.vsync = 1; | 
| Line 188  void neitem_vsync(UINT id) { | Line 231  void neitem_vsync(UINT id) { | 
 | corestat.vsync = 2; | corestat.vsync = 2; | 
 | (void)id; | (void)id; | 
 | } | } | 
 |  | #endif | 
 |  |  | 
 |  |  | 
| // ---- | /* ---- */ | 
 |  |  | 
| #define SINGLESTEPONLY | #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) { | void pccore_exec(BRESULT draw) { | 
 |  |  | 
 | SINT32  frameclock; | SINT32  frameclock; | 
 |  | #if defined(MAINFRAMES_OLD) | 
 | SINT32  dispclock; | SINT32  dispclock; | 
 |  | #endif | 
 |  | #if defined(TRACE) && defined(NEVENT_COUNTER) | 
 |  | UINT    ncounter = 0; | 
 |  | #endif | 
 |  |  | 
 | corestat.drawframe = draw; | corestat.drawframe = draw; | 
 |  | pal_eventclear(); | 
 |  | #if !defined(DISABLE_SOUND) | 
 | soundmng_sync(); | soundmng_sync(); | 
 |  | #endif | 
 |  |  | 
| timing_setrate(crtc.e.frameclock); | frameclock = crtc.e.frameclock; | 
| frameclock = crtc.e.frameclock * pccore.multiple / 2; | if (corestat.framebaseclock != frameclock) { | 
| dispclock = min(frameclock, crtc.e.dispclock); | corestat.framebaseclock = frameclock; | 
| corestat.dispclock = dispclock; | timing_setrate(frameclock); | 
| corestat.syncclock = frameclock - dispclock; | } | 
 | corestat.vsync = 0; | 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); | nevent_set(NEVENT_FRAMES, dispclock, neitem_disp, NEVENT_RELATIVE); | 
 |  | #endif | 
 |  |  | 
 | do { | do { | 
 |  | #if defined(TRACE) && defined(NEVENT_COUNTER) | 
 |  | ncounter++; | 
 |  | #endif | 
 | #if !defined(SINGLESTEPONLY) | #if !defined(SINGLESTEPONLY) | 
 | if (CPU_REMCLOCK > 0) { | if (CPU_REMCLOCK > 0) { | 
 | Z80_EXECUTE(); | Z80_EXECUTE(); | 
 | } | } | 
 | #else | #else | 
 | while(CPU_REMCLOCK > 0) { | while(CPU_REMCLOCK > 0) { | 
| //      TRACEOUT(("%.4x", Z80_PC)); | /* TRACEOUT(("%.4x", Z80_PC)); */ | 
 | #if defined(TRACE) && IPTRACE | #if defined(TRACE) && IPTRACE | 
 | treip[trpos & (IPTRACE - 1)] = Z80_PC; | treip[trpos & (IPTRACE - 1)] = Z80_PC; | 
 | trpos++; | trpos++; | 
| Line 231  void pccore_exec(BRESULT draw) { | Line 312  void pccore_exec(BRESULT draw) { | 
 | scrnupdate(); | scrnupdate(); | 
 | sound_sync(); | sound_sync(); | 
 | fdc_callback(); | 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)); | 
 |  | } | 
 |  | 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)); | 
 |  | } | 
 |  | } | 
 |  | #endif | 
 | } | } | 
 |  |  |