DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/hardware/snd_pc98/cbus/cs4231io.c
00001 #include        "compiler.h"
00002 #include        "cpucore.h"
00003 #include        "pccore.h"
00004 #include        "iocore.h"
00005 #include        "cs4231io.h"
00006 #include        "sound.h"
00007 #include        "fmboard.h"
00008 
00009 
00010 static const UINT8 cs4231dma[] = {0xff,0x00,0x01,0x03,0xff,0xff,0xff,0xff};
00011 static const UINT8 cs4231irq[] = {0xff,0x03,0x06,0x0a,0x0c,0xff,0xff,0xff};
00012 
00013 
00014 static void IOOUTCALL csctrl_oc24(UINT port, REG8 dat) {
00015 
00016         cs4231.portctrl = dat;
00017         (void)port;
00018 }
00019 
00020 static void IOOUTCALL csctrl_oc2b(UINT port, REG8 dat) {
00021 
00022         UINT    num;
00023 
00024         if ((cs4231.portctrl & 0x28) == 0x20) {
00025                 num = cs4231.portctrl & 7;
00026                 if ((num == 0) || (num == 5)) {
00027                         cs4231.port[num] &= 0xff00;
00028                         cs4231.port[num] |= dat;
00029                 }
00030         }
00031         (void)port;
00032 }
00033 
00034 static void IOOUTCALL csctrl_oc2d(UINT port, REG8 dat) {
00035 
00036         UINT    num;
00037 
00038         if ((cs4231.portctrl & 0x2f) == 0x20) {
00039                 num = cs4231.portctrl & 7;
00040                 if ((num == 0) || (num == 5)) {
00041                         cs4231.port[num] &= 0x00ff;
00042                         cs4231.port[num] |= (dat << 8);
00043                 }
00044         }
00045         (void)port;
00046 }
00047 
00048 static REG8 IOINPCALL csctrl_ic24(UINT port) {
00049 
00050         (void)port;
00051         return(0x80 | cs4231.portctrl);
00052 }
00053 
00054 static REG8 IOINPCALL csctrl_ic2b(UINT port) {
00055 
00056         UINT    num;
00057 
00058         (void)port;
00059         num = cs4231.portctrl & 0x07;
00060         return((REG8)(cs4231.port[num] & 0xff));
00061 }
00062 
00063 static REG8 IOINPCALL csctrl_ic2d(UINT port) {
00064 
00065         UINT    num;
00066 
00067         (void)port;
00068         num = cs4231.portctrl & 0x07;
00069         return((REG8)(cs4231.port[num] >> 8));
00070 }
00071 
00072 
00073 // ----
00074 
00075 void cs4231io_reset(void) {
00076 
00077         cs4231.enable = 1;
00078         cs4231.adrs = 0x22;
00079         cs4231.dmairq = cs4231irq[(cs4231.adrs >> 3) & 7];
00080         cs4231.dmach = cs4231dma[cs4231.adrs & 7];
00081         if (cs4231.dmach != 0xff) {
00082                 dmac_attach(DMADEV_CS4231, cs4231.dmach);
00083         }
00084         cs4231.port[0] = 0x0f40;
00085         cs4231.port[1] = 0xa460;
00086         cs4231.port[2] = 0x0f48;
00087         cs4231.port[4] = 0x0188;
00088         cs4231.port[5] = 0x0f4a;
00089 
00090         TRACEOUT(("CS4231 - IRQ = %d", cs4231.dmairq));
00091         TRACEOUT(("CS4231 - DMA channel = %d", cs4231.dmach));
00092 }
00093 
00094 void cs4231io_bind(void) {
00095 
00096         sound_streamregist(&cs4231, (SOUNDCB)cs4231_getpcm);
00097         iocore_attachout(0xc24, csctrl_oc24);
00098         iocore_attachout(0xc2b, csctrl_oc2b);
00099         iocore_attachout(0xc2d, csctrl_oc2d);
00100         iocore_attachinp(0xc24, csctrl_ic24);
00101         iocore_attachinp(0xc2b, csctrl_ic2b);
00102         iocore_attachinp(0xc2d, csctrl_ic2d);
00103 }
00104 
00105 void IOOUTCALL cs4231io0_w8(UINT port, REG8 value) {
00106 
00107         switch(port - cs4231.port[0]) {
00108                 case 0x00:
00109                         cs4231.adrs = value;
00110                         cs4231.dmairq = cs4231irq[(value >> 3) & 7];
00111                         cs4231.dmach = cs4231dma[value & 7];
00112                         dmac_detach(DMADEV_CS4231);
00113                         if (cs4231.dmach != 0xff) {
00114                                 dmac_attach(DMADEV_CS4231, cs4231.dmach);
00115 #if 0
00116                                 if (cs4231.sdc_enable) {
00117                                         dmac.dmach[cs4231.dmach].ready = 1;
00118                                         dmac_check();
00119                                 }
00120 #endif
00121                         }
00122                         break;
00123 
00124                 case 0x04:
00125                         cs4231.index = value;
00126                         break;
00127 
00128                 case 0x05:
00129                         cs4231_control(cs4231.index & 0x1f, value);
00130                         break;
00131 
00132                 case 0x06:
00133                         cs4231.intflag = 0;
00134                         break;
00135 
00136                 case 0x07:
00137                         cs4231_datasend(value);
00138                         break;
00139         }
00140 }
00141 
00142 REG8 IOINPCALL cs4231io0_r8(UINT port) {
00143 
00144         switch(port - cs4231.port[0]) {
00145                 case 0x00:
00146                         return(cs4231.adrs);
00147 
00148                 case 0x03:
00149                         return(0x04);
00150 
00151                 case 0x04:
00152                         return(cs4231.index & 0x7f);
00153 
00154                 case 0x05:
00155                         return(*(((UINT8 *)(&cs4231.reg)) + (cs4231.index & 0x1f)));
00156 
00157                 case 0x06:
00158                         return(cs4231.intflag);
00159 
00160         }
00161         return(0);
00162 }
00163 
00164 void IOOUTCALL cs4231io5_w8(UINT port, REG8 value) {
00165 
00166         switch(port - cs4231.port[5]) {
00167                 case 0x00:
00168                         cs4231.extindex = value;
00169                         break;
00170         }
00171 }
00172 
00173 REG8 IOINPCALL cs4231io5_r8(UINT port) {
00174 
00175         switch(port - cs4231.port[5]) {
00176                 case 0x00:
00177                         return(cs4231.extindex);
00178 
00179                 case 0x01:
00180                         if (cs4231.extindex == 1) {
00181                                 return(0);                              // means opna int5
00182                         }
00183                         break;
00184         }
00185         return(0xff);
00186 }
00187