--- np2/cbus/ideio.c 2005/03/05 11:58:02 1.11 +++ np2/cbus/ideio.c 2005/04/06 17:44:09 1.14 @@ -1,10 +1,5 @@ #include "compiler.h" -#ifdef TRACEOUT -#undef TRACEOUT -#endif -#define TRACEOUT(s) trace_fmt s - // winでidentifyまでは取得に行くんだけどな…ってAnex86も同じか #if defined(SUPPORT_IDEIO) @@ -16,6 +11,7 @@ #include "ideio.h" #include "atapicmd.h" #include "sxsi.h" +#include "sound.h" #include "idebios.res" @@ -56,7 +52,7 @@ static const char model[] = "QUANTUM FIR static const char cdrom_serial[] = "1.0 "; static const char cdrom_firm[] = " "; -static const char cdrom_model[] = "NP2 VIRTUAL CD-ROM DRIVE "; +static const char cdrom_model[] = "NEC CD-ROM DRIVE "; static BRESULT setidentify(IDEDRV drv) { @@ -924,6 +920,75 @@ REG16 IOINPCALL ideio_r16(UINT port) { // ---- +#if 1 +static BRESULT SOUNDCALL playdevaudio(IDEDRV drv, SINT32 *pcm, UINT count) { + + SXSIDEV sxsi; + UINT r; +const UINT8 *ptr; + SINT sampl; + SINT sampr; + + sxsi = sxsi_getptr(drv->sxsidrv); + if ((sxsi == NULL) || (sxsi->devtype != SXSIDEV_CDROM) || + (!(sxsi->flag & SXSIFLAG_READY))) { + drv->daflag = 0x14; + return(FAILURE); + } + while(count) { + r = min(count, drv->dabufrem); + if (r) { + count -= r; + ptr = drv->dabuf + 2352 - (drv->dabufrem * 4); + drv->dabufrem -= r; + do { + sampl = ((SINT8)ptr[1] << 8) + ptr[0]; + sampr = ((SINT8)ptr[3] << 8) + ptr[2]; + pcm[0] += sampl; + pcm[1] += sampr; + ptr += 4; + pcm += 2; + } while(--r); + } + if (count == 0) { + break; + } + if (drv->dalength == 0) { + drv->daflag = 0x13; + return(FAILURE); + } + if (sxsicd_readraw(sxsi, drv->dacurpos, drv->dabuf) != SUCCESS) { + drv->daflag = 0x14; + return(FAILURE); + } + drv->dalength--; + drv->dacurpos++; + drv->dabufrem = sizeof(drv->dabuf) / 4; + } + return(SUCCESS); +} + +static void SOUNDCALL playaudio(void *hdl, SINT32 *pcm, UINT count) { + + UINT bit; + IDEDRV drv; + + bit = ideio.daplaying; + if (!bit) { + return; + } + if (bit & 4) { + drv = ideio.dev[1].drv + 0; + if (playdevaudio(drv, pcm, count) != SUCCESS) { + bit = bit & (~4); + } + } + ideio.daplaying = bit; +} +#endif + +// ---- + static void devinit(IDEDRV drv, REG8 sxsidrv) { SXSIDEV sxsi; @@ -946,8 +1011,9 @@ static void devinit(IDEDRV drv, REG8 sxs drv->error = 0; drv->media = IDEIO_MEDIA_EJECTABLE; if (sxsi->flag & SXSIFLAG_READY) { - drv->media |= (IDEIO_MEDIA_CHANGED | IDEIO_MEDIA_LOADED); + drv->media |= (IDEIO_MEDIA_CHANGED|IDEIO_MEDIA_LOADED); } + drv->daflag = 0x15; } else { drv->status = IDESTAT_ERR; @@ -974,6 +1040,9 @@ void ideio_reset(void) { void ideio_bind(void) { if (pccore.hddif & PCHDD_IDE) { +#if 1 + sound_streamregist(NULL, (SOUNDCB)playaudio); +#endif iocore_attachout(0x0430, ideio_o430); iocore_attachout(0x0432, ideio_o430); iocore_attachinp(0x0430, ideio_i430); @@ -1002,20 +1071,39 @@ void ideio_bind(void) { void ideio_notify(REG8 sxsidrv, UINT action) { + SXSIDEV sxsi; IDEDRV drv; + REG8 i; - if ((sxsidrv >= 0) && (sxsidrv < 4)) { - drv = ideio.dev[sxsidrv >> 1].drv + (sxsidrv & 1); - switch(action) { - case 1: - drv->media |= (IDEIO_MEDIA_CHANGED | IDEIO_MEDIA_LOADED); - break; + sxsi = sxsi_getptr(sxsidrv); + if ((sxsi == NULL) + || (!(sxsi->flag & SXSIFLAG_READY)) + || (sxsi->devtype != SXSIDEV_CDROM)) { + return; + } - case 0: - drv->media &= ~IDEIO_MEDIA_LOADED; - break; + for (i=0; i<4; i++) { + drv = ideio.dev[i >> 1].drv + (i & 1); + if ((drv != NULL) && (drv->sxsidrv == sxsidrv)) { + goto do_notify; } } + return; + +do_notify: + switch(action) { + case 1: + drv->media |= (IDEIO_MEDIA_CHANGED|IDEIO_MEDIA_LOADED); + if (sxsi->mediatype & SXSIMEDIA_DATA) + drv->media |= IDEIO_MEDIA_DATA; + if (sxsi->mediatype & SXSIMEDIA_AUDIO) + drv->media |= IDEIO_MEDIA_AUDIO; + break; + + case 0: + drv->media &= ~(IDEIO_MEDIA_LOADED|IDEIO_MEDIA_COMBINE); + break; + } } #endif /* SUPPORT_IDEIO */