DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/hardware/snd_pc98/sound/tms3631c.c
00001 #include    "np2glue.h"
00002 //#include      "compiler.h"
00003 #include        "sound.h"
00004 #include        "tms3631.h"
00005 
00006 
00007         TMS3631CFG      tms3631cfg;
00008 
00009 static const UINT16 tms3631_freqtbl[] = {
00010                         0,      0x051B, 0x0569, 0x05BB, 0x0613, 0x066F, 0x06D1,
00011                                 0x0739, 0x07A7, 0x081B, 0x0897, 0x091A, 0x09A4, 0,0,0,
00012                         0,      0x0A37, 0x0AD3, 0x0B77, 0x0C26, 0x0CDF, 0x0DA3,
00013                                 0x0E72, 0x0F4E, 0x1037, 0x112E, 0x1234, 0x1349, 0,0,0,
00014                         0,      0x146E, 0x15A6, 0x16EF, 0x184C, 0x19BE, 0x1B46,
00015                                 0x1CE5, 0x1E9D, 0x206F, 0x225D, 0x2468, 0x2692, 0,0,0,
00016                         0,      0x28DD, 0x2B4C, 0x2DDF, 0x3099, 0x337D, 0x368D,
00017                                 0x39CB, 0x3D3B, 0x40DF, 0x44BA, 0x48D1, 0x4D25, 0x51BB, 0,0};
00018 
00019 
00020 void tms3631_initialize(UINT rate) {
00021 
00022         UINT    sft;
00023 
00024         ZeroMemory(&tms3631cfg, sizeof(tms3631cfg));
00025         sft = 0;
00026         if (rate == 11025) {
00027                 sft = 0;
00028         }
00029         else if (rate == 22050) {
00030                 sft = 1;
00031         }
00032         else if (rate == 44100) {
00033                 sft = 2;
00034         }
00035         tms3631cfg.ratesft = sft;
00036 }
00037 
00038 void tms3631_setvol(const UINT8 *vol) {
00039 
00040         UINT    i;
00041         UINT    j;
00042         SINT32  data;
00043 
00044         tms3631cfg.left = (vol[0] & 15) << 5;
00045         tms3631cfg.right = (vol[1] & 15) << 5;
00046         vol += 2;
00047         for (i=0; i<16; i++) {
00048                 data = 0;
00049                 for (j=0; j<4; j++) {
00050                         data += (vol[j] & 15) * ((i & (1 << j))?1:-1);
00051                 }
00052                 tms3631cfg.feet[i] = data << 5;
00053         }
00054 }
00055 
00056 
00057 // ----
00058 
00059 void tms3631_reset(TMS3631 tms) {
00060 
00061         ZeroMemory(tms, sizeof(_TMS3631));
00062 }
00063 
00064 void tms3631_setkey(TMS3631 tms, REG8 ch, REG8 key) {
00065 
00066         tms->ch[ch & 7].freq = tms3631_freqtbl[key & 0x3f] >> tms3631cfg.ratesft;
00067 }
00068 
00069 void tms3631_setenable(TMS3631 tms, REG8 enable) {
00070 
00071         tms->enable = enable;
00072 }
00073