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 
00043         tms3631cfg.left = (vol[0] & 15) << 5;
00044         tms3631cfg.right = (vol[1] & 15) << 5;
00045         vol += 2;
00046         for (i=0; i<16; i++) {
00047                 SINT32 data = 0;
00048                 for (j=0; j<4; j++) {
00049                         data += (vol[j] & 15) * ((i & (1 << j))?1:-1);
00050                 }
00051                 tms3631cfg.feet[i] = data << 5;
00052         }
00053 }
00054 
00055 
00056 // ----
00057 
00058 void tms3631_reset(TMS3631 tms) {
00059 
00060         ZeroMemory(tms, sizeof(_TMS3631));
00061 }
00062 
00063 void tms3631_setkey(TMS3631 tms, REG8 ch, REG8 key) {
00064 
00065         tms->ch[ch & 7].freq = tms3631_freqtbl[key & 0x3f] >> tms3631cfg.ratesft;
00066 }
00067 
00068 void tms3631_setenable(TMS3631 tms, REG8 enable) {
00069 
00070         tms->enable = enable;
00071 }
00072