--- np2/io/iocore.c 2003/12/26 22:24:06 1.4 +++ np2/io/iocore.c 2007/11/03 00:00:20 1.23 @@ -5,6 +5,7 @@ #include "cbuscore.h" #include "sound.h" #include "fmboard.h" +#include "ideio.h" #include "cs4231io.h" #include "iocore16.tbl" @@ -16,13 +17,14 @@ _DMAC dmac; _EGC egc; _EPSONIO epsonio; - _EXTMEM extmem; + _EMSIO emsio; _FDC fdc; _GDC gdc; _GDCS gdcs; _GRCG grcg; - _KEYB keyb; + _KEYBRD keybrd; _MOUSEIF mouseif; + _NECIO necio; _NMIIO nmiio; _NP2SYSP np2sysp; _PIC pic; @@ -31,6 +33,10 @@ _SYSPORT sysport; _UPD4990 uPD4990; +#if defined(SUPPORT_PC9821) + _PCIDEV pcidev; +#endif + // ---- @@ -49,6 +55,7 @@ typedef struct { typedef struct { IOFUNC base[256]; + UINT busclock; LISTARRAY iotbl; } _IOCORE, *IOCORE; @@ -60,24 +67,45 @@ static UINT8 ioterminate[0x100]; static void IOOUTCALL defout8(UINT port, REG8 dat) { - if ((port & 0xfff0) == cs4231.port) { - cs4231io_w8(port, dat); +#if !defined(DISABLE_SOUND) + UINT tmp; + + tmp = port - cs4231.port[0]; + if (tmp < 8) { + cs4231io0_w8(port, dat); return; } + tmp = port - cs4231.port[5]; + if (tmp < 2) { + cs4231io5_w8(port, dat); + return; + } +#endif if ((port & 0xf0ff) == 0x801e) { dipsw_w8(port, dat); return; } +// TRACEOUT(("defout8 - %x %x %.4x %.4x", port, dat, CPU_CS, CPU_IP)); } static REG8 IOINPCALL definp8(UINT port) { - if ((port & 0xfff0) == cs4231.port) { - return(cs4231io_r8(port)); +#if !defined(DISABLE_SOUND) + UINT tmp; + + tmp = port - cs4231.port[0]; + if (tmp < 8) { + return(cs4231io0_r8(port)); + } + tmp = port - cs4231.port[5]; + if (tmp < 2) { + return(cs4231io5_r8(port)); } +#endif if ((port & 0xf0ff) == 0x801e) { return(dipsw_r8(port)); } +// TRACEOUT(("definp8 - %x %.4x %.4x", port, CPU_CS, CPU_IP)); return(0xff); } @@ -230,7 +258,7 @@ void iocore_attachsysinpex(UINT port, UI // ---- -static BOOL makesndiofunc(UINT port) { +static BRESULT makesndiofunc(UINT port) { IOFUNC tbl[2]; UINT num; @@ -260,9 +288,9 @@ static BOOL makesndiofunc(UINT port) { return(SUCCESS); } -BOOL iocore_attachsndout(UINT port, IOOUT func) { +BRESULT iocore_attachsndout(UINT port, IOOUT func) { - BOOL r; + BRESULT r; UINT num; r = makesndiofunc(port); @@ -276,9 +304,9 @@ BOOL iocore_attachsndout(UINT port, IOOU return(r); } -BOOL iocore_attachsndinp(UINT port, IOINP func) { +BRESULT iocore_attachsndinp(UINT port, IOINP func) { - BOOL r; + BRESULT r; UINT num; r = makesndiofunc(port); @@ -311,7 +339,7 @@ static IOFUNC getextiofunc(UINT port) { return(iof); } -BOOL iocore_attachout(UINT port, IOOUT func) { +BRESULT iocore_attachout(UINT port, IOOUT func) { IOFUNC iof; @@ -325,7 +353,7 @@ BOOL iocore_attachout(UINT port, IOOUT f } } -BOOL iocore_attachinp(UINT port, IOINP func) { +BRESULT iocore_attachinp(UINT port, IOINP func) { IOFUNC iof; @@ -350,7 +378,7 @@ const UINT8 *p; ZeroMemory(&iocore, sizeof(iocore)); ZeroMemory(ioterminate, sizeof(ioterminate)); - for (i=0; i<(sizeof(termtbl)/sizeof(TERMTBL)); i++) { + for (i=0; iiotbl = NULL; } -BOOL iocore_build(void) { +BRESULT iocore_build(void) { IOCORE ioc; IOFUNC cmn; @@ -413,7 +441,8 @@ icbld_err: // ---- -static const IOCBFN resetfn[] = { +static const FNIORESET resetfn[] = +{ // PC-9801 System... cgrom_reset, crtc_reset, dmac_reset, gdc_reset, fdc_reset, @@ -425,10 +454,15 @@ static const IOCBFN resetfn[] = { itimer_reset, mouseif_reset, // extend - artic_reset, egc_reset, - extmem_reset, np2sysp_reset}; + artic_reset, egc_reset, np2sysp_reset, + necio_reset, epsonio_reset, emsio_reset, +#if defined(SUPPORT_PC9821) + pcidev_reset, +#endif +}; -static const IOCBFN bindfn[] = { +static const FNIOBIND bindfn[] = +{ // PC-9801 System... cgrom_bind, cpuio_bind, crtc_bind, dmac_bind, gdc_bind, fdc_bind, @@ -440,55 +474,49 @@ static const IOCBFN bindfn[] = { itimer_bind, mouseif_bind, // extend - itf_bind, artic_bind, egc_bind, - extmem_bind, np2sysp_bind}; - + artic_bind, egc_bind, np2sysp_bind, + necio_bind, epsonio_bind, emsio_bind, +#if defined(SUPPORT_PC9821) + pcidev_bind, +#endif +}; -void iocore_cb(const IOCBFN *cbfn, UINT count) { - while(count--) { - (*cbfn)(); - cbfn++; +void iocore_cbreset(const FNIORESET *pfn, UINT uCount, const NP2CFG *pConfig) +{ + while(uCount--) + { + (*pfn)(pConfig); + pfn++; } } -void iocore_reset(void) { - - iocore_cb(resetfn, sizeof(resetfn)/sizeof(IOCBFN)); -} - -void iocore_bind(void) { - - iocore_cb(bindfn, sizeof(bindfn)/sizeof(IOCBFN)); +void iocore_cbbind(const FNIOBIND *pfn, UINT uCount) +{ + while(uCount--) + { + (*pfn)(); + pfn++; + } } -#if !defined(TRACE) - -void IOOUTCALL iocore_out8(UINT port, REG8 dat) { - - IOFUNC iof; - - iof = iocore.base[(port >> 8) & 0xff]; - iof->ioout[port & 0xff](port, dat); +void iocore_reset(const NP2CFG *pConfig) +{ + iocore_cbreset(resetfn, NELEMENTS(resetfn), pConfig); } -REG8 IOINPCALL iocore_inp8(UINT port) { - - IOFUNC iof; - - iof = iocore.base[(port >> 8) & 0xff]; - return(iof->ioinp[port & 0xff](port)); +void iocore_bind(void) +{ + iocore.busclock = pccore.multiple; + iocore_cbbind(bindfn, NELEMENTS(bindfn)); } -#else - void IOOUTCALL iocore_out8(UINT port, REG8 dat) { IOFUNC iof; - if (dat & (~0xff)) { - TRACEOUT(("iocore_out8 - %x %x", port, dat)); - } +// TRACEOUT(("iocore_out8(%.2x, %.2x)", port, dat)); + CPU_REMCLOCK -= iocore.busclock; iof = iocore.base[(port >> 8) & 0xff]; iof->ioout[port & 0xff](port, dat); } @@ -498,21 +526,25 @@ REG8 IOINPCALL iocore_inp8(UINT port) { IOFUNC iof; REG8 ret; + CPU_REMCLOCK -= iocore.busclock; iof = iocore.base[(port >> 8) & 0xff]; ret = iof->ioinp[port & 0xff](port); - - if (ret & (~0xff)) { - TRACEOUT(("iocore_inp8 - %x %x", port, ret)); - } +// TRACEOUT(("iocore_inp8(%.2x) -> %.2x", port, ret)); return(ret); } -#endif - void IOOUTCALL iocore_out16(UINT port, REG16 dat) { IOFUNC iof; +// TRACEOUT(("iocore_out16(%.4x, %.4x)", port, dat)); + CPU_REMCLOCK -= iocore.busclock; +#if defined(SUPPORT_IDEIO) + if (port == 0x0640) { + ideio_w16(port, dat); + return; + } +#endif if ((port & 0xfff1) == 0x04a0) { egc_w16(port, dat); return; @@ -543,6 +575,12 @@ REG16 IOINPCALL iocore_inp16(UINT port) IOFUNC iof; REG8 ret; + CPU_REMCLOCK -= iocore.busclock; +#if defined(SUPPORT_IDEIO) + if (port == 0x0640) { + return(ideio_r16(port)); + } +#endif if ((port & 0xfffc) == 0x005c) { return(artic_r16(port)); } @@ -576,14 +614,27 @@ REG16 IOINPCALL iocore_inp16(UINT port) void IOOUTCALL iocore_out32(UINT port, UINT32 dat) { + CPU_REMCLOCK -= iocore.busclock; +#if defined(SUPPORT_PC9821) + if ((port & 0xfffb) == 0x0cf8) { + pcidev_w32(port, dat); + return; + } +#endif iocore_out16(port, (UINT16)dat); iocore_out16(port+2, (UINT16)(dat >> 16)); } UINT32 IOINPCALL iocore_inp32(UINT port) { - REG16 ret; + UINT32 ret; + CPU_REMCLOCK -= iocore.busclock; +#if defined(SUPPORT_PC9821) + if ((port & 0xfffb) == 0x0cf8) { + return(pcidev_r32(port)); + } +#endif ret = iocore_inp16(port); return(ret + (iocore_inp16(port+2) << 16)); }