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