--- np2/cbus/board14.c 2003/10/16 17:58:00 1.1.1.1 +++ np2/cbus/board14.c 2011/01/15 18:04:43 1.9 @@ -7,27 +7,55 @@ #include "fmboard.h" -// ---- intr +// どうも 8253C-2は 4MHz/16らすい? +// とりあえず 1996800/8を入力してみる... (ver0.71) + + +// ---- 8253C-2 + +UINT board14_pitcount(void) { + + SINT32 clk; + + clk = nevent_getremain(NEVENT_MUSICGEN); + if (clk >= 0) { + clk /= pccore.multiple; + clk /= 8; + if (!(pccore.cpumode & CPUMODE_8MHZ)) { + clk = clk * 13 / 16; + } + return(clk); + } + return(0); +} + -static void setmusicgenevent(BOOL absolute) { +// ---- intr - SINT32 cnt; +static void setmusicgenevent(UINT32 cnt, BOOL absolute) { - if (pit.value[3].w > 8) { // 根拠なし - cnt = pc.multiple * pit.value[3].w; + if (cnt > 4) { // 根拠なし + cnt *= pccore.multiple; } else { - cnt = pc.multiple << 16; + cnt = pccore.multiple << 16; + } + if (!(pccore.cpumode & CPUMODE_8MHZ)) { + cnt = cnt * 16 / 13; // cnt * 2457600 / 1996800 } + cnt *= 8; nevent_set(NEVENT_MUSICGEN, cnt, musicgenint, absolute); } void musicgenint(NEVENTITEM item) { + PITCH pitch; + if (item->flag & NEVENT_SETEVENT) { - if ((pit.mode[3] & 0x0c) == 0x04) { + pitch = pit.ch + 3; + if ((pitch->ctrl & 0x0c) == 0x04) { // レートジェネレータ - setmusicgenevent(NEVENT_RELATIVE); + setmusicgenevent(pitch->value, NEVENT_RELATIVE); } } pic_setirq(0x0c); @@ -37,19 +65,19 @@ void musicgenint(NEVENTITEM item) { // ---- I/O -static void IOOUTCALL musicgen_o088(UINT port, BYTE dat) { +static void IOOUTCALL musicgen_o088(UINT port, REG8 dat) { musicgen.porta = dat; (void)port; } -static void IOOUTCALL musicgen_o08a(UINT port, BYTE dat) { +static void IOOUTCALL musicgen_o08a(UINT port, REG8 dat) { musicgen.portb = dat; (void)port; } -static void IOOUTCALL musicgen_o08c(UINT port, BYTE dat) { +static void IOOUTCALL musicgen_o08c(UINT port, REG8 dat) { if (dat & 0x80) { if (!(musicgen.portc & 0x80)) { @@ -60,7 +88,7 @@ static void IOOUTCALL musicgen_o08c(UINT musicgen.sync = 0; sound_sync(); musicgen.key[musicgen.ch] = dat; - tms3631_setkey(&tms3631, (BYTE)musicgen.ch, dat); + tms3631_setkey(&tms3631, (REG8)musicgen.ch, dat); } else if ((!(dat & 0x40)) && (musicgen.portc & 0x40)) { musicgen.sync = 1; @@ -71,7 +99,7 @@ static void IOOUTCALL musicgen_o08c(UINT (void)port; } -static void IOOUTCALL musicgen_o188(UINT port, BYTE dat) { +static void IOOUTCALL musicgen_o188(UINT port, REG8 dat) { sound_sync(); musicgen.mask = dat; @@ -79,59 +107,67 @@ static void IOOUTCALL musicgen_o188(UINT (void)port; } -static void IOOUTCALL musicgen_o18c(UINT port, BYTE dat) { +static void IOOUTCALL musicgen_o18c(UINT port, REG8 dat) { + + PITCH pitch; - itimer_setcount(3, dat); - setmusicgenevent(NEVENT_ABSOLUTE); + pitch = pit.ch + 3; + if (!pit_setcount(pitch, dat)) { + setmusicgenevent(pitch->value, NEVENT_ABSOLUTE); + } (void)port; } -static void IOOUTCALL musicgen_o18e(UINT port, BYTE dat) { +static void IOOUTCALL musicgen_o18e(UINT port, REG8 dat) { - itimer_setflag(3, dat); + pit_setflag(pit.ch + 3, dat); (void)port; } -static BYTE IOINPCALL musicgen_i088(UINT port) { +static REG8 IOINPCALL musicgen_i088(UINT port) { (void)port; return(musicgen.porta); } -static BYTE IOINPCALL musicgen_i08a(UINT port) { +static REG8 IOINPCALL musicgen_i08a(UINT port) { (void)port; return(musicgen.portb); } -static BYTE IOINPCALL musicgen_i08c(UINT port) { +static REG8 IOINPCALL musicgen_i08c(UINT port) { (void)port; return(musicgen.portc); } -static BYTE IOINPCALL musicgen_i08e(UINT port) { +static REG8 IOINPCALL musicgen_i08e(UINT port) { (void)port; return(0x08); } -static BYTE IOINPCALL musicgen_i188(UINT port) { +static REG8 IOINPCALL musicgen_i188(UINT port) { (void)port; return(musicgen.mask); } -static BYTE IOINPCALL musicgen_i18c(UINT port) { +static REG8 IOINPCALL musicgen_i18c(UINT port) { (void)port; - return(itimer_getcount(3)); + return(pit_getstat(pit.ch + 3)); } -static BYTE IOINPCALL musicgen_i18e(UINT port) { +static REG8 IOINPCALL musicgen_i18e(UINT port) { (void)port; +#if 1 + return(0x80); // INT-5 +#else return(0x40); // INT-5 +#endif } @@ -150,10 +186,12 @@ static const IOINP musicgen_i1[4] = { musicgen_i188, musicgen_i188, musicgen_i18c, musicgen_i18e}; -void board14_reset(void) { +void board14_reset(const NP2CFG *pConfig) { ZeroMemory(&musicgen, sizeof(musicgen)); - soundrom_load(0xcc000, "14"); + soundrom_load(0xcc000, OEMTEXT("14")); + + (void)pConfig; } void board14_bind(void) { @@ -165,10 +203,10 @@ void board14_bind(void) { void board14_allkeymake(void) { - int i; + REG8 i; for (i=0; i<8; i++) { - tms3631_setkey(&tms3631, (BYTE)i, musicgen.key[i]); + tms3631_setkey(&tms3631, i, musicgen.key[i]); } }