]> 4ch.mooo.com Git - 16.git/blobdiff - src/lib/16_snd.c
seriously i want sound!!! bakapee!
[16.git] / src / lib / 16_snd.c
index 5ade6445f2b89e83d4ec8fa12a3963f211b844ff..47cab348332462fb8a4a85e326c22b1888540818 100644 (file)
 
 #include "src/lib/16_snd.h"
 
-void opl2out(word data, word reg)
+void opl2out(word reg, word data)
 {\r
        __asm
        {\r
                mov     ax,reg\r
-               mov     dx,word ptr [OPLPORT]\r
+               mov     dx,word ptr [ADLIB_FM_ADDRESS]\r
                or      ah,ah\r
                jz      @@1\r
                add     dx,2\r
@@ -46,12 +46,12 @@ void opl2out(word data, word reg)
        }
 }\r
 \r
-void opl3out(word data, word reg)
+void opl3out(word reg, word data)
 {\r
        __asm
        {\r
                mov     ax,reg\r
-               mov     dx,word ptr [OPLPORT]\r
+               mov     dx,word ptr [ADLIB_FM_ADDRESS]\r
                or      ah,ah\r
                jz      @@1\r
                add     dx,2\r
@@ -71,7 +71,7 @@ void opl3exp(word data)
        __asm
        {\r
                mov     ax,data\r
-               mov     dx,word ptr [OPLPORT]\r
+               mov     dx,word ptr [ADLIB_FM_ADDRESS]\r
                add     dx,2\r
                out     dx,al\r
                mov     cx,6\r
@@ -84,4 +84,112 @@ void opl3exp(word data)
 @@2:    in      al,dx\r
                loop    @@2
        }\r
-}
\ No newline at end of file
+}
+
+/* Function: FMResest *******************************************************\r
+*\r
+*     Description:        quick and dirty sound card reset (zeros all\r
+*                         registers).\r
+*\r
+*/\r
+void FMReset(void/*int percusiveMode*/)
+{\r
+       int i;\r
+\r
+       /* zero all registers */\r
+       for(i = MIN_REGISTER; i < MAX_REGISTER+1; i++) opl2out(i, 0);\r
+\r
+       /* allow FM chips to control the waveform of each operator */\r
+       opl2out(0x01, 0x20);\r
+\r
+       /* set rhythm enabled (6 melodic voices, 5 percussive) */\r
+       opl2out(0xBD, 0x20);\r
+\r
+       //FMSetPercusiveMode(percusiveMode);\r
+} /* End of FMReset */
+
+/* Function: FMKeyOff *******************************************************\r
+*\r
+*     Parameters:        voice - which voice to turn off.\r
+*\r
+*     Description:        turns off the specified voice.\r
+*\r
+*/\r
+void FMKeyOff(int voice)
+{\r
+       int regNum;\r
+\r
+       /* turn voice off */\r
+       regNum = 0xB0 + voice % 11;//NUMVOICE;\r
+       opl2out(regNum, 0x0E);\r
+} /* End of FMKeyOff */\r
+\r
+/* Function: FMKeyOn *******************************************************\r
+*\r
+*     Parameters:        voice - which voice to turn on.\r
+*                         freq - its frequency (note).\r
+*                         octave - its octave.\r
+*\r
+*     Description:        turns on a voice of specfied frequency and\r
+*                         octave.\r
+*\r
+*/\r
+void FMKeyOn(int voice, int freq, int octave)
+{\r
+       int regNum, tmp;\r
+\r
+       regNum = 0xA0 + voice % 11;//NUMVOICE;\r
+       opl2out(regNum, freq & 0xff);\r
+       regNum = 0xB0 + voice % 11;//NUMVOICE;\r
+       tmp = (freq >> 8) | (octave << 2) | 0x20;
+       opl2out(regNum, tmp);\r
+} /* End of FMKeyOn */
+
+/* Function: FMSetVoice *****************************************************\r
+*\r
+*     Parameters:        voiceNum - which voice to set.\r
+*                         ins - instrument to set voice.\r
+*\r
+*     Description:        sets the instrument of a voice.\r
+*\r
+*/\r
+void FMSetVoice(int voiceNum, FMInstrument *ins){\r
+       int opCellNum, cellOffset;\r
+\r
+       voiceNum %= 11;//NUMVOICE;\r
+       cellOffset = voiceNum % 3 + ((voiceNum / 3) << 3);\r
+\r
+       /* set sound characteristic */\r
+       opCellNum = 0x20 + (char)cellOffset;\r
+       opl2out(opCellNum, ins->SoundCharacteristic[0]);\r
+       opCellNum += 3;\r
+       opl2out(opCellNum, ins->SoundCharacteristic[1]);\r
+\r
+       /* set level/output */\r
+       opCellNum = 0x40 + (char)cellOffset;\r
+       opl2out(opCellNum, ins->Level[0]);\r
+       opCellNum += 3;\r
+       opl2out(opCellNum, ins->Level[1]);\r
+\r
+       /* set Attack/Decay */\r
+       opCellNum = 0x60 + (char)cellOffset;\r
+       opl2out(opCellNum, ins->AttackDecay[0]);\r
+       opCellNum += 3;\r
+       opl2out(opCellNum, ins->AttackDecay[1]);\r
+\r
+       /* set Sustain/Release */\r
+       opCellNum = 0x80 + (char)cellOffset;\r
+       opl2out(opCellNum, ins->SustainRelease[0]);\r
+       opCellNum += 3;\r
+       opl2out(opCellNum, ins->SustainRelease[1]);\r
+\r
+       /* set Wave Select */\r
+       opCellNum = 0xE0 + (char)cellOffset;\r
+       opl2out(opCellNum, ins->WaveSelect[0]);\r
+       opCellNum += 3;\r
+       opl2out(opCellNum, ins->WaveSelect[1]);\r
+\r
+       /* set Feedback/Selectivity */\r
+       opCellNum = (byte)0xC0 + (byte)voiceNum;\r
+       opl2out(opCellNum, ins->Feedback);\r
+} /* End of FMSetVoice */