DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/hardware/snd_pc98/sound/fmboard.c
00001 #include    "np2glue.h"
00002 //#include      "compiler.h"
00003 //#include      "joymng.h"
00004 //#include      "soundmng.h"
00005 //#include      "pccore.h"
00006 //#include      "iocore.h"
00007 //#include      "cbuscore.h"
00008 //#include      "board14.h"
00009 #include        "board26k.h"
00010 #include        "board86.h"
00011 //#include      "boardx2.h"
00012 //#include      "board118.h"
00013 //#include      "boardspb.h"
00014 #if defined(SUPPORT_PX)
00015 //#include      "boardpx.h"
00016 #endif  // defined(SUPPORT_PX)
00017 //#include      "amd98.h"
00018 //#include      "pcm86io.h"
00019 //#include      "cs4231io.h"
00020 #include        "sound.h"
00021 #include        "fmboard.h"
00022 //#include      "beep.h"
00023 #include        "keydisp.h"
00024 //#include      "keystat.h"
00025 
00026 
00027         UINT32          usesound;
00028         OPN_T           opn;
00029         AMD98           amd98;
00030         MUSICGEN        musicgen;
00031 
00032         _TMS3631        tms3631;
00033         _FMTIMER        fmtimer;
00034         _OPNGEN         opngen;
00035         OPNCH           opnch[OPNCH_MAX];
00036         _PSGGEN         __psg[3];
00037         _RHYTHM         rhythm;
00038         _ADPCM          adpcm;
00039         _PCM86          pcm86;
00040 //      _CS4231         cs4231;
00041 
00042 #if defined(SUPPORT_PX)
00043         OPN_T           opn2;
00044         OPN_T           opn3;
00045         _RHYTHM         rhythm2;
00046         _RHYTHM         rhythm3;
00047         _ADPCM          adpcm2;
00048         _ADPCM          adpcm3;
00049 #endif  // defined(SUPPORT_PX)
00050 
00051 
00052 static void     (*extfn)(REG8 enable);
00053 
00054 
00055 // ----
00056 
00057 static  REG8    rapids = 0;
00058 
00059 REG8 fmboard_getjoy(PSGGEN psg) {
00060 
00061         REG8    ret;
00062 
00063         rapids ^= 0xf0;                                                                                 // ver0.28
00064         ret = 0xff;
00065         if (!(psg->reg.io2 & 0x40)) {
00066                 ret &= (joymng_getstat() | (rapids & 0x30));
00067                 if (np2cfg.KEY_MODE == 1) {
00068                         ret &= keystat_getjoy();
00069                 }
00070         }
00071         else {
00072                 if (np2cfg.KEY_MODE == 2) {
00073                         ret &= keystat_getjoy();
00074                 }
00075         }
00076         if (np2cfg.BTN_RAPID) {
00077                 ret |= rapids;
00078         }
00079 
00080         // rapidと非rapidを合成                                                         // ver0.28
00081         ret &= ((ret >> 2) | (~0x30));
00082 
00083         if (np2cfg.BTN_MODE) {
00084                 UINT8 bit1 = (ret & 0x20) >> 1;                                 // ver0.28
00085                 UINT8 bit2 = (ret & 0x10) << 1;
00086                 ret = (ret & (~0x30)) | bit1 | bit2;
00087         }
00088 
00089         // intr 反映して終わり                                                          // ver0.28
00090         ret &= 0x3f;
00091         ret |= fmtimer.intr;
00092         return(ret);
00093 }
00094 
00095 
00096 // ----
00097 
00098 void fmboard_extreg(void (*ext)(REG8 enable)) {
00099 
00100         extfn = ext;
00101 }
00102 
00103 void fmboard_extenable(REG8 enable) {
00104 
00105         if (extfn) {
00106                 (*extfn)(enable);
00107         }
00108 }
00109 
00110 
00111 
00112 // ----
00113 
00114 static void setfmregs(UINT8 *reg) {
00115 
00116         FillMemory(reg + 0x30, 0x60, 0xff);
00117         FillMemory(reg + 0x90, 0x20, 0x00);
00118         FillMemory(reg + 0xb0, 0x04, 0x00);
00119         FillMemory(reg + 0xb4, 0x04, 0xc0);
00120 }
00121 
00122 void fmboard_reset(const NP2CFG *pConfig, UINT32 type) {
00123 
00124         UINT8   cross;
00125 
00126         soundrom_reset();
00127 //      beep_reset();                                                                                           // ver0.27a
00128         cross = np2cfg.snd_x;                                                                           // ver0.30
00129 
00130         extfn = NULL;
00131         ZeroMemory(&opn, sizeof(opn));
00132         setfmregs(opn.reg + 0x000);
00133         setfmregs(opn.reg + 0x100);
00134         setfmregs(opn.reg + 0x200);
00135         setfmregs(opn.reg + 0x300);
00136         opn.reg[0xff] = 0x01;
00137         opn.channels = 3;
00138         opn.adpcmmask = (UINT8)~(0x1c);
00139 
00140 #if defined(SUPPORT_PX)
00141         ZeroMemory(&opn2, sizeof(opn2));
00142         setfmregs(opn2.reg + 0x000);
00143         setfmregs(opn2.reg + 0x100);
00144         setfmregs(opn2.reg + 0x200);
00145         setfmregs(opn2.reg + 0x300);
00146         opn2.reg[0xff] = 0x01;
00147         opn2.channels = 3;
00148         opn2.adpcmmask = (UINT8)~(0x1c);
00149 
00150         ZeroMemory(&opn3, sizeof(opn3));
00151         setfmregs(opn3.reg + 0x000);
00152         setfmregs(opn3.reg + 0x100);
00153         setfmregs(opn3.reg + 0x200);
00154         setfmregs(opn3.reg + 0x300);
00155         opn3.reg[0xff] = 0x01;
00156         opn3.channels = 3;
00157         opn3.adpcmmask = (UINT8)~(0x1c);
00158 #endif  // defined(SUPPORT_PX)
00159 
00160         ZeroMemory(&musicgen, sizeof(musicgen));
00161         ZeroMemory(&amd98, sizeof(amd98));
00162 
00163         tms3631_reset(&tms3631);
00164         opngen_reset();
00165         psggen_reset(&psg1);
00166         psggen_reset(&psg2);
00167         psggen_reset(&psg3);
00168         rhythm_reset(&rhythm);
00169 #if defined(SUPPORT_PX)
00170         rhythm_reset(&rhythm2);
00171         rhythm_reset(&rhythm3);
00172 #endif  // defined(SUPPORT_PX)
00173         adpcm_reset(&adpcm);
00174 #if defined(SUPPORT_PX)
00175         adpcm_reset(&adpcm2);
00176         adpcm_reset(&adpcm3);
00177 #endif  // defined(SUPPORT_PX)
00178         pcm86_reset();
00179 //      cs4231_reset();
00180 
00181         switch(type) {
00182                 case 0x01:
00183 //                      board14_reset(pConfig);
00184                         break;
00185 
00186                 case 0x02:
00187                         board26k_reset(pConfig);
00188                         break;
00189 
00190                 case 0x04:
00191                         board86_reset(pConfig);
00192                         break;
00193 
00194                 case 0x06:
00195 //                      boardx2_reset(pConfig);
00196                         break;
00197 
00198                 case 0x08:
00199 //                      board118_reset(pConfig);
00200                         break;
00201 
00202                 case 0x14:
00203                         board86_reset(pConfig);
00204                         break;
00205 
00206                 case 0x20:
00207 //                      boardspb_reset(pConfig);
00208                         cross ^= pConfig->spb_x;
00209                         break;
00210 
00211                 case 0x40:
00212 //                      boardspr_reset(pConfig);
00213                         cross ^= pConfig->spb_x;
00214                         break;
00215 
00216                 case 0x80:
00217 //                      amd98_reset(pConfig);
00218                         break;
00219 
00220 #if     defined(SUPPORT_PX)
00221                 case 0x30:
00222 //                      boardpx1_reset(pConfig);
00223                         break;
00224 
00225                 case 0x50:
00226 //                      boardpx2_reset(pConfig);
00227                         break;
00228 #endif  // defined(SUPPORT_PX)
00229 
00230                 default:
00231                         type = 0;
00232                         break;
00233         }
00234         usesound = type;
00235 //      soundmng_setreverse(cross);
00236         keydisp_setfmboard(type);
00237         opngen_setVR(pConfig->spb_vrc, pConfig->spb_vrl);
00238 }
00239 
00240 /* added by DOSBox-X */
00241 void fmboard_on_reset() {
00242     fmboard_reset(&np2cfg, usesound);
00243 }
00244 
00245 void fmboard_bind(void) {
00246 
00247         switch(usesound) {
00248                 case 0x01:
00249 //                      board14_bind();
00250                         break;
00251 
00252                 case 0x02:
00253                         board26k_bind();
00254                         break;
00255 
00256                 case 0x04:
00257                         board86_bind();
00258                         break;
00259 
00260                 case 0x06:
00261 //                      boardx2_bind();
00262                         break;
00263 
00264                 case 0x08:
00265 //                      board118_bind();
00266                         break;
00267 
00268                 case 0x14:
00269                         board86c_bind();
00270                         break;
00271 
00272                 case 0x20:
00273 //                      boardspb_bind();
00274                         break;
00275 
00276                 case 0x40:
00277 //                      boardspr_bind();
00278                         break;
00279 
00280                 case 0x80:
00281 //                      amd98_bind();
00282                         break;
00283 
00284 #if defined(SUPPORT_PX)
00285                 case 0x30:
00286 //                      boardpx1_bind();
00287                         break;
00288 
00289                 case 0x50:
00290 //                      boardpx2_bind();
00291                         break;
00292 #endif  // defined(SUPPORT_PX)
00293         }
00294 //      sound_streamregist(&beep, (SOUNDCB)beep_getpcm);
00295 }
00296 
00297 
00298 // ----
00299 
00300 void fmboard_fmrestore(REG8 chbase, UINT bank) {
00301 
00302         REG8    i;
00303 const UINT8     *reg;
00304 
00305         reg = opn.reg + (bank * 0x100);
00306         for (i=0x30; i<0xa0; i++) {
00307                 opngen_setreg(chbase, i, reg[i]);
00308         }
00309         for (i=0xb7; i>=0xa0; i--) {
00310                 opngen_setreg(chbase, i, reg[i]);
00311         }
00312         for (i=0; i<3; i++) {
00313                 opngen_keyon(chbase + i, opngen.keyreg[chbase + i]);
00314         }
00315 }
00316 
00317 void fmboard_rhyrestore(RHYTHM rhy, UINT bank) {
00318 
00319 const UINT8     *reg;
00320 
00321         reg = opn.reg + (bank * 0x100);
00322         rhythm_setreg(rhy, 0x11, reg[0x11]);
00323         rhythm_setreg(rhy, 0x18, reg[0x18]);
00324         rhythm_setreg(rhy, 0x19, reg[0x19]);
00325         rhythm_setreg(rhy, 0x1a, reg[0x1a]);
00326         rhythm_setreg(rhy, 0x1b, reg[0x1b]);
00327         rhythm_setreg(rhy, 0x1c, reg[0x1c]);
00328         rhythm_setreg(rhy, 0x1d, reg[0x1d]);
00329 }
00330 
00331 
00332 #if defined(SUPPORT_PX)
00333 void fmboard_fmrestore2(OPN_T* pOpn, REG8 chbase, UINT bank) {
00334 
00335         REG8    i;
00336 const UINT8     *reg;
00337 
00338         reg = pOpn->reg + (bank * 0x100);
00339         for (i=0x30; i<0xa0; i++) {
00340                 opngen_setreg(chbase, i, reg[i]);
00341         }
00342         for (i=0xb7; i>=0xa0; i--) {
00343                 opngen_setreg(chbase, i, reg[i]);
00344         }
00345         for (i=0; i<3; i++) {
00346                 opngen_keyon(chbase + i, opngen.keyreg[chbase + i]);
00347         }
00348 }
00349 
00350 void fmboard_rhyrestore2(OPN_T* pOpn, RHYTHM rhy, UINT bank) {
00351 
00352 const UINT8     *reg;
00353 
00354         reg = pOpn->reg + (bank * 0x100);
00355         rhythm_setreg(rhy, 0x11, reg[0x11]);
00356         rhythm_setreg(rhy, 0x18, reg[0x18]);
00357         rhythm_setreg(rhy, 0x19, reg[0x19]);
00358         rhythm_setreg(rhy, 0x1a, reg[0x1a]);
00359         rhythm_setreg(rhy, 0x1b, reg[0x1b]);
00360         rhythm_setreg(rhy, 0x1c, reg[0x1c]);
00361         rhythm_setreg(rhy, 0x1d, reg[0x1d]);
00362 }
00363 #endif  // defined(SUPPORT_PX)
00364