From 97e94452aea736cc685df68906bebb1248eb9c9a Mon Sep 17 00:00:00 2001 From: timothy lamb Date: Mon, 11 Apr 2016 02:36:54 -0700 Subject: [PATCH] Adding back in changes that were lost when posting original source to Git. Version 1.3.0 to 1.3.3 --- Source/mGB.h | 6 +- Source/mGBASMSynthFunctions.s | 317 ++++++++++++++----------------- Source/mGBSynthCommonFunctions.c | 268 -------------------------- Source/mGBSynthPitchFunctions.c | 71 ++++--- 4 files changed, 183 insertions(+), 479 deletions(-) diff --git a/Source/mGB.h b/Source/mGB.h index 47e7ce8..862a509 100644 --- a/Source/mGB.h +++ b/Source/mGB.h @@ -50,7 +50,7 @@ void asmPlayNotePu1(); #define SPRITE_ARRL_START 27 #define SPRITE_PUFREQ_LOW 1 -const UWORD freq[72] = { +UWORD freq[72] = { 44, 156, 262, 363, 457, 547, 631, 710, 786, 854, 923, 986, 1046, 1102, 1155, 1205, 1253, 1297, 1339, 1379, 1417, 1452, 1486, 1517, 1546, 1575, 1602, 1627, 1650, 1673, 1694, 1714, 1732, 1750, 1767, 1783, @@ -61,7 +61,7 @@ const UWORD freq[72] = { UBYTE noteStatus[8]; -const UBYTE noiFreq[72] = { +UBYTE noiFreq[72] = { 0x94,0x87,0x86,0x85,0x84,0x77,0x76,0x75,0x74,0x67,0x66,0x65, 0x64,0x57,0x56,0x55,0x54,0x47,0x46,0x45,0x44,0x37,0x36,0x35, 0x34,0x27,0x26,0x25,0x24,0x17,0x16,0x15,0x14,0x07,0x06,0x00, @@ -413,7 +413,7 @@ const unsigned char versionnumber[10] = 32,81, 2,81, 4,81, - 1, + 4, 0,0,0 }; diff --git a/Source/mGBASMSynthFunctions.s b/Source/mGBASMSynthFunctions.s index 0c73463..bd7720d 100644 --- a/Source/mGBASMSynthFunctions.s +++ b/Source/mGBASMSynthFunctions.s @@ -9,7 +9,7 @@ push bc ld A,(hl) cp #0x80 jr nz, _asmUpdatePu1PbWheel$ - + ld hl, #_pbWheelActive + 0 ld A,(hl) bit 0,A @@ -36,25 +36,17 @@ pop bc ret _asmUpdatePu1PbWheelSet$:: ld (hl), A - - ld A,#0x00 - push af - inc sp - - ld A,#0x01 ;pu1currentnote - push af - inc sp - - ld A,#0x00 ;pu1 - push af - inc sp - - ld A, #0x01 + + ld A, #0x01 ld hl, #_pbWheelActive + 0 ld (hl), A - - call _setPitchBendFrequencyOffset - lda sp,3(sp) + + ld A, #0x00 + push af + inc sp + call _setPitchBendFrequencyOffset + inc sp +pop bc ret _asmUpdatePu1PbWheelReset$:: @@ -63,25 +55,25 @@ _asmUpdatePu1PbWheelReset$:: ld A, #0x80 ld hl, #_pbWheelInLast + 0 ld (hl), A - + ld hl, #_noteStatus + 1 ld A,(hl) ld B,A - + ld A,#<_freq add A,B add A,B ld E,A ld A,#>_freq ld D,A - + ld A,(DE) ld (#0xFF13),A ld hl, #_currentFreqData + 0 ld (hl+), A - + inc DE - + ld A,(DE) ld (hl), A ld (#0xFF14),A @@ -103,7 +95,7 @@ push bc ld A,(hl) cp #0x80 jr nz, _asmUpdatePu2PbWheel$ - + ld hl, #_pbWheelActive + 1 ld A,(hl) bit 0,A @@ -130,25 +122,17 @@ pop bc ret _asmUpdatePu2PbWheelSet$:: ld (hl), A - - ld A,#0x02 - push af - inc sp - - ld A,#0x03 ;pu2currentnote - push af - inc sp - - ld A,#0x01 ;pu2 - push af - inc sp - + ld A, #0x01 ld hl, #_pbWheelActive + 1 ld (hl), A - - call _setPitchBendFrequencyOffset - lda sp,3(sp) + + ld A, #0x01 + push af + inc sp + call _setPitchBendFrequencyOffset + inc sp +pop bc ret _asmUpdatePu2PbWheelReset$:: @@ -157,11 +141,11 @@ _asmUpdatePu2PbWheelReset$:: ld A, #0x80 ld hl, #_pbWheelInLast + 1 ld (hl), A - + ld hl, #_noteStatus + 3 ld A,(hl) ld B,A - + ld A,#<_freq add A,B @@ -169,14 +153,14 @@ _asmUpdatePu2PbWheelReset$:: ld E,A ld A,#>_freq ld D,A - + ld A,(DE) ld (#0xFF18),A ld hl, #_currentFreqData + 2 ld (hl+), A - + inc DE - + ld A,(DE) ld (hl), A ld (#0xFF19),A @@ -199,18 +183,18 @@ push bc ld hl, #_wavDataOffset cp (hl) jr nz, _asmUpdateWavData$ - - + + ld hl, #_pbWheelIn + 2 ld A,(hl) cp #0x80 jr nz, _asmUpdateWavPbWheel$ - + ld hl, #_pbWheelActive + 2 ld A,(hl) bit 0,A jr nz, _asmUpdateWavPbWheelReset$ - + pop bc ret @@ -229,7 +213,7 @@ _asmUpdateWavData$:: inc sp call _asmLoadWav lda sp,1(sp) - + ld A, #0x80 ld hl, #_pbWheelInLast + 2 ld (hl), A @@ -247,25 +231,17 @@ pop bc ret _asmUpdateWavPbWheelSet$:: ld (hl), A - - ld A,#0x04 - push af - inc sp - - ld A,#0x05 ;Wavcurrentnote - push af - inc sp - - ld A,#0x02 ;pu1 - push af - inc sp - + ld A, #0x01 ld hl, #_pbWheelActive + 2 ld (hl), A - - call _setPitchBendFrequencyOffset - lda sp,3(sp) + + ld A, #0x02 + push af + inc sp + call _setPitchBendFrequencyOffset + inc sp +pop bc ret _asmUpdateWavPbWheelReset$:: @@ -274,41 +250,40 @@ _asmUpdateWavPbWheelReset$:: ld A, #0x80 ld hl, #_pbWheelInLast + 2 ld (hl), A - + ld hl, #_noteStatus + 5 ld A,(hl) ld B,A - + ld A,#<_freq add A,B add A,B ld E,A ld A,#>_freq ld D,A - + ld A,(DE) - + ld hl, #_wavCurrentFreq ld (hl), A ld hl, #_currentFreqData + 4 ld (hl), A ld C,A - ld A,#0x00 - ld (#0xFF1E),A + ;ld A,#0x00 + ;ld (#0xFF1E),A ld A,C ld (#0xFF1D),A - + inc DE ld A,(DE) - + inc hl ld (hl), A - + ld hl, #_wavCurrentFreq + 1 ld (hl), A - - or #0x80 - + + and #0x7F ld (#0xFF1E),A pop bc ret @@ -323,7 +298,7 @@ push bc ld A,(hl) cp #0x80 jr nz, _asmUpdateNoiPbWheel$ - + ld hl, #_pbWheelActive + 3 ld A,(hl) bit 0,A @@ -343,25 +318,13 @@ pop bc ret _asmUpdateNoiPbWheelSet$:: ld (hl), A - - ld A,#0x06 - push af - inc sp - - ld A,#0x07 ;pu1currentnote - push af - inc sp - - ld A,#0x03 ;pu1 - push af - inc sp - + ld A, #0x01 ld hl, #_pbWheelActive + 3 ld (hl), A - - call _setPitchBendFrequencyOffset - lda sp,3(sp) + + call _setPitchBendFrequencyOffsetNoise +pop bc ret _asmUpdateNoiPbWheelReset$:: @@ -370,26 +333,26 @@ _asmUpdateNoiPbWheelReset$:: ld A, #0x80 ld hl, #_pbWheelInLast + 3 ld (hl), A - + ld hl, #_noteStatus + 3 ld A,(hl) ld B,A - + ld A,#<_noiFreq add A,B ld E,A ld A,#>_noiFreq ld D,A - + ld A,(DE) ld (#0xFF22),A ld hl, #_currentFreqData + 6 ld (hl), A - + ld A,#0xFF ld (#0xFF20),A - ld A,#0x80 - ld (#0xFF23),A + ;ld A,#0x80 + ;ld (#0xFF23),A pop bc ret @@ -408,26 +371,26 @@ _asmPlayNotePu1:: SUB #0x24 ld hl, #_pu1Oct add (hl) - + ld B, A ld hl, #_valueByte ld A,(hl) ld C, A - + cp #0x00 jr nz,_asmPlayNotePu1OnSet$ jr _asmPlayNotePu1Off$ _asmPlayNotePu1OnSet$:: ld A, (#0xFF12) - cp #0x00 + cp #0x00 jr z,_asmPlayNotePu1OnSetOn$ jr _asmPlayNotePu1OnSetOff$ _asmPlayNotePu1OnSetOn$:: ld A, #0x80 ld hl, #_pu1Trig ld (hl),A - + ld hl, #_pu1Vel ld A,C ld (hl),A @@ -436,10 +399,10 @@ _asmPlayNotePu1OnSetOn$:: ld hl, #_pu1Env OR (hl) ld (#0xFF12),A - + jr _asmPlayNotePu1On$ _asmPlayNotePu1OnSetOff$:: - + ld hl, #_pu1Vel ld A,(hl) cp C @@ -448,11 +411,11 @@ _asmPlayNotePu1OnSetOff$:: ld A, (hl) bit 0, A jr nz,_asmPlayNotePu1OnSetOn$ - + ld A, #0x00 ld hl, #_pu1Trig ld (hl),A - + jr _asmPlayNotePu1On$ pop bc ret @@ -461,37 +424,37 @@ ret _asmPlayNotePu1On$:: ld hl, #_noteStatus + 1 ld (hl),B - + ld A,#<_freq add A,B add A,B ld E,A ld A,#>_freq ld D,A - + ld A,(DE) ld (#0xFF13),A ld hl, #_currentFreqData + 0 ld (hl+), A - + inc DE - + ld A,(DE) ld (hl), A - + ld hl, #_pu1Trig ld C,(hl) or C ld (#0xFF14),A - + ld A,#0x00 ld hl,#_vibratoPosition + 0 ld (hl),A - + ld A,#0x80 ld hl,#_pbWheelInLast + 0 ld (hl),A - + ld hl,#_pbRange + 0 ld C,(hl) ld A,B @@ -501,11 +464,11 @@ _asmPlayNotePu1On$:: ld A,B add C ld (hl),A - + ld A,#0x01 ld hl, #_noteStatus + 0 ld (hl),A - + ld A,#0x00 ld hl, #_pu1NoteOffTrigger ld (hl),A @@ -517,20 +480,20 @@ _asmPlayNotePu1Off$:: ld A,(hl) cp B jr nz,_asmPlayNoteOffPu1Return$ - + ld hl, #_noteStatus + 0 ld A,#0x00 ld (hl), A - + ld hl, #_pu1Sus ld A,(hl) bit 0, A jr nz,_asmPlayNoteOffPu1Return$ - + ld A,#0x01 ld hl, #_pu1NoteOffTrigger ld (hl),A - + ;ld A,#0x00 ;ld (#0xFF12),A pop bc @@ -550,12 +513,12 @@ _asmPlayNotePu2$:: SUB #0x24 ld hl, #_pu2Oct add (hl) - + ld B, A ld hl, #_valueByte ld A,(hl) ld C, A - + cp #0x00 jr nz,_asmPlayNotePu2OnSet$ jr _asmPlayNotePu2Off$ @@ -569,7 +532,7 @@ _asmPlayNotePu2OnSetOn$:: ld A, #0x80 ld hl, #_pu2Trig ld (hl),A - + ld hl, #_pu2Vel ld A,C ld (hl),A @@ -578,9 +541,9 @@ _asmPlayNotePu2OnSetOn$:: ld hl, #_pu2Env OR (hl) ld (#0xFF17),A - + jr _asmPlayNotePu2On$ -_asmPlayNotePu2OnSetOff$:: +_asmPlayNotePu2OnSetOff$:: ld hl, #_pu2Vel ld A,(hl) cp C @@ -589,11 +552,11 @@ _asmPlayNotePu2OnSetOff$:: ld A, (hl) bit 0, A jr nz,_asmPlayNotePu2OnSetOn$ - + ld A, #0x00 ld hl, #_pu2Trig ld (hl),A - + jr _asmPlayNotePu2On$ pop bc ret @@ -601,36 +564,36 @@ ret _asmPlayNotePu2On$:: ld hl, #_noteStatus + 3 ld (hl),B - + ld A,#<_freq add A,B add A,B ld E,A ld A,#>_freq ld D,A - + ld A,(DE) ld (#0xFF18),A ld hl, #_currentFreqData + 2 ld (hl+), A - + inc DE - + ld A,(DE) ld (hl), A ld hl, #_pu2Trig ld C,(hl) or C ld (#0xFF19),A - + ld A,#0x00 ld hl,#_vibratoPosition + 1 ld (hl),A - + ld A,#0x80 ld hl,#_pbWheelInLast + 1 ld (hl),A - + ld hl,#_pbRange + 1 ld C,(hl) ld A,B @@ -640,11 +603,11 @@ _asmPlayNotePu2On$:: ld A,B add C ld (hl),A - + ld A,#0x01 ld hl, #_noteStatus + 2 ld (hl),A - + ld A,#0x00 ld hl, #_pu2NoteOffTrigger ld (hl),A @@ -656,20 +619,20 @@ _asmPlayNotePu2Off$:: ld A,(hl) cp B jp nz,_popReturn$ - + ld hl, #_noteStatus + 2 ld A,#0x00 ld (hl), A - + ld hl, #_pu2Sus ld A,(hl) bit 0, A jp nz,_popReturn$ - + ld A,#0x01 ld hl, #_pu2NoteOffTrigger ld (hl),A - + ;ld A,#0x00 ;ld (#0xFF17),A pop bc @@ -691,7 +654,7 @@ _asmPlayNoteWav$:: ld hl, #_valueByte ld A,(hl) ld C, A - + cp #0x00 jr nz,_asmPlayNoteWavOn$ jp _asmPlayNoteWavOff$ @@ -731,9 +694,9 @@ _asmPlayNoteWavSet$:: ld E,A ld A,#>_freq ld D,A - + ld A,(DE) - + ld hl, #_wavCurrentFreq ld (hl), A ld hl, #_currentFreqData + 4 @@ -743,22 +706,22 @@ _asmPlayNoteWavSet$:: ld (#0xFF1E),A ld A,C ld (#0xFF1D),A - + inc DE ld A,(DE) - + inc hl ld (hl), A - + ld hl, #_wavCurrentFreq + 1 ld (hl), A - + ld (#0xFF1E),A - + ld A,#0x00 ld hl,#_vibratoPosition + 2 ld (hl),A - + ld A,#0x00 ld hl,#_wavStepCounter ld (hl),A @@ -767,11 +730,11 @@ _asmPlayNoteWavSet$:: ld (hl),A ld hl,#_counterWavStart ld (hl),A - + ld A,#0x80 ld hl,#_pbWheelInLast + 2 ld (hl),A - + ld hl,#_pbRange + 2 ld C,(hl) ld A,B @@ -781,13 +744,13 @@ _asmPlayNoteWavSet$:: ld A,B add C ld (hl),A - + ld A,#0x01 ld hl, #_noteStatus + 4 ld (hl),A ld hl,#_cueWavSweep ld (hl),A - + ld A,#0x00 ld hl, #_wavNoteOffTrigger ld (hl),A @@ -801,21 +764,21 @@ _asmPlayNoteWavOff$:: ld A,(hl) cp B jp nz,_popReturn$ - - + + ld hl, #_noteStatus + 4 ld A,#0x00 ld (hl), A - + ld hl, #_wavSus ld A,(hl) bit 0, A jp nz,_popReturn$ - + ld A,#0x01 ld hl, #_wavNoteOffTrigger ld (hl),A - + ;ld A,#0x00 ;ld (#0xFF1C),A pop bc @@ -836,7 +799,7 @@ _asmPlayNoteNoi$:: ld hl, #_valueByte ld A,(hl) ld C, A - + cp #0x00 jr nz,_asmPlayNoteNoiOn$ jr _asmPlayNoteNoiOff$ @@ -846,38 +809,38 @@ ret _asmPlayNoteNoiOn$:: ld hl, #_noteStatus + 7 ld (hl),B - + ld hl, #_noiEnv ld A,C RLCA AND #0xF0 OR (hl) ld (#0xFF21),A - + ld A,#<_noiFreq add A,B ld E,A ld A,#>_noiFreq ld D,A - + ld A,(DE) ld (#0xFF22),A ld hl, #_currentFreqData + 6 ld (hl), A - + ld A,#0xFF ld (#0xFF20),A ld A,#0x80 ld (#0xFF23),A - + ld A,#0x00 ld hl,#_vibratoPosition + 3 ld (hl),A - + ld A,#0x80 ld hl,#_pbWheelInLast + 3 ld (hl),A - + ld A,#0x01 ld hl, #_noteStatus + 6 ld (hl),A @@ -889,16 +852,16 @@ _asmPlayNoteNoiOff$:: ld A,(hl) cp B jp nz,_popReturn$ - + ld hl, #_noteStatus + 6 ld A,#0x00 ld (hl), A - + ld hl, #_pu2Sus ld A,(hl) bit 0, A jp nz,_popReturn$ - + ld A,#0x00 ld (#0xFF21),A pop bc @@ -921,7 +884,7 @@ _asmPlayNotePoly$:: ld hl, #_valueByte ld A,(hl) ld C, A - + cp #0x00 jr nz,_asmPlayNotePolyOn$ jr _asmPlayNotePolyOff$ @@ -932,7 +895,7 @@ _asmPlayNotePolyOff$:: ld A,(hl) cp B call z,_asmPlayNotePolyPu1Off$; - + ld hl, #_addressByte ld A,(hl) ld B, A @@ -940,7 +903,7 @@ _asmPlayNotePolyOff$:: ld A,(hl) cp B call z,_asmPlayNotePolyPu2Off$; - + ld hl, #_addressByte ld A,(hl) ld B, A @@ -984,7 +947,7 @@ _asmPlayNotePolyCon$:: jr z,_asmPlayNotePolyPu1$ cp #0x01 jr z,_asmPlayNotePolyPu2$ - + ld hl,#_polyNoteState + 2 ld (hl),B jp _asmPlayNoteWav$; @@ -994,7 +957,7 @@ _asmPlayNotePolyPu1$:: ld hl,#_polyNoteState + 0 ld (hl),B jp _asmPlayNotePu1; - + pop bc ret _asmPlayNotePolyPu2$:: diff --git a/Source/mGBSynthCommonFunctions.c b/Source/mGBSynthCommonFunctions.c index b006945..4eb322a 100644 --- a/Source/mGBSynthCommonFunctions.c +++ b/Source/mGBSynthCommonFunctions.c @@ -1,274 +1,6 @@ UBYTE wavStepCounter; -/* -void updatePu1() -{ - if(pbWheelIn[PU1] != PBWHEEL_CENTER) { - pbWheelActive[PU1] = 0x01U; - - if(pbWheelIn[PU1] != pbWheelInLast[PU1]) { - pbWheelInLast[PU1] = pbWheelIn[PU1]; - setPitchBendFrequencyOffset(PU1,PU1_CURRENT_NOTE,0U); - } - } else if(pbWheelActive[PU1]) { - pbWheelActive[PU1] = 0x00U; - pbWheelInLast[PU1] = PBWHEEL_CENTER; - NR14_REG = freq[noteStatus[PU1_CURRENT_NOTE]] >> 8U; - NR13_REG = freq[noteStatus[PU1_CURRENT_NOTE]]; - } -// if(vibratoDepth[PU1]) updateVibratoPosition(PU1); -} -void updatePu2() -{ - if(pbWheelIn[PU2] != PBWHEEL_CENTER) { - pbWheelActive[PU2] = 1U; - if(pbWheelIn[PU2] != pbWheelInLast[PU2]) { - pbWheelInLast[PU2] = pbWheelIn[PU2]; - setPitchBendFrequencyOffset(PU2,PU2_CURRENT_NOTE,2U); - } - } else if(pbWheelActive[PU2]) { - pbWheelActive[PU2] = 0U; - pbWheelInLast[PU2] = PBWHEEL_CENTER; - NR24_REG = freq[noteStatus[PU2_CURRENT_NOTE]] >> 8U; - NR23_REG = freq[noteStatus[PU2_CURRENT_NOTE]]; - } -// if(vibratoDepth[PU2]) updateVibratoPosition(PU2); -} - -void updateWav() -{ - if(pbWheelIn[WAV] != PBWHEEL_CENTER) { - pbWheelActive[WAV] = 1U; - if(pbWheelIn[WAV] != pbWheelInLast[WAV]) { - pbWheelInLast[WAV] = pbWheelIn[WAV]; - setPitchBendFrequencyOffset(WAV,WAV_CURRENT_NOTE,4U); - } - } else if(pbWheelActive[WAV]) { - pbWheelActive[WAV] = 0U; - pbWheelInLast[WAV] = PBWHEEL_CENTER; - NR34_REG = freq[noteStatus[WAV_CURRENT_NOTE]] >> 8U; - NR33_REG = freq[noteStatus[WAV_CURRENT_NOTE]]; - wavCurrentFreq = freq[noteStatus[WAV_CURRENT_NOTE]]; - } - - if(wavShapeLast != wavDataOffset) { - asmLoadWav(wavDataOffset); - pbWheelInLast[WAV] = PBWHEEL_CENTER; - } -} - -void updateNoi() -{ - if(pbWheelIn[NOI] != PBWHEEL_CENTER) { - systemIdle = 0; - pbWheelActive[NOI] = 1U; - if(pbWheelIn[NOI] != pbWheelInLast[NOI]) { - pbWheelInLast[NOI] = pbWheelIn[NOI]; - setPitchBendFrequencyOffset(NOI,NOI_CURRENT_NOTE,6U); - } - } else if(pbWheelActive[NOI]) { - pbWheelActive[NOI] = 0U; - pbWheelInLast[NOI] = PBWHEEL_CENTER; - NR43_REG = noiFreq[noteStatus[NOI_CURRENT_NOTE]]; - } -// if(vibratoDepth[NOI]) updateVibratoPosition(NOI); -} - - -void playNotePu1() -{ - x = noteStatus[PU1_CURRENT_NOTE]; - note = addressByte; - envelope = valueByte; - note -=36U; - if(envelope) { - noteStatus[PU1_CURRENT_NOTE]=note; - - if(pu1Oct<0){ - if(note > (pu1Oct*-1)) note = note + pu1Oct; - } else { - note = note + pu1Oct; - } - if(pu1Oct!=0) while(note>71) note -=12; - - NR12_REG = ((envelope << 1U) & 0xF0U) + pu1Env; //Take a value from 0 to 127 and make it 0 to 255, and add in the envelope - NR14_REG = 0x80+(freq[note]>>8U); - NR13_REG = freq[note]; - currentFreqData[PU1] = freq[note]; - vibratoPosition[PU1]=0; - - pbNoteRange[0] = note - pbRange[0]; - pbNoteRange[1] = note + pbRange[0]; - - noteStatus[PU1_CURRENT_STATUS]=1U; - //noteStatus[PU1_CURRENT_ENV]=noteStatus[PU1_OLD_ENV]=envelope; - pbWheelInLast[PU1] = PBWHEEL_CENTER; - - } else if(x == note) { - noteStatus[PU1_CURRENT_STATUS]=0U; // <<< - if (!pu1Sus) { - NR12_REG = 0x00U; - } - } -} - -void playNotePu2() -{ - x = noteStatus[PU2_CURRENT_NOTE]; - note = addressByte; - envelope = valueByte; - note -=36U; - if(envelope) { - if(pu2Oct<0){ - if(note > (pu2Oct*-1)) note = note + pu2Oct; - } else { - note = note + pu2Oct; - } - if(pu2Oct!=0) while(note>71) note -=12; - NR22_REG = ((envelope << 1U) & 0xF0U) + pu2Env; //Take a value from 0 to 127 and make it 0 to 255, and add in the envelope - NR24_REG = 0x80+(freq[note]>>8U); - //NR24_REG = trig + (freq[note]>>8U); - NR23_REG = (freq[note]); - currentFreqData[PU2] = freq[note]; - vibratoPosition[PU2]=0; - - pbNoteRange[2] = note - pbRange[1]; - pbNoteRange[3] = note + pbRange[1]; - - noteStatus[PU2_CURRENT_STATUS]=1U; - noteStatus[PU2_CURRENT_NOTE]=note; - //noteStatus[PU2_OLD_ENV] = noteStatus[PU2_CURRENT_ENV] = envelope; - pbWheelInLast[PU2] = PBWHEEL_CENTER; - - } else if (x == note) { - noteStatus[PU2_CURRENT_STATUS]=0U; - if(!pu2Sus) { - NR22_REG = 0x00U; - } - } -} - - -void playNoteWav() -{ - x = noteStatus[WAV_CURRENT_NOTE]; - note = addressByte; - envelope = valueByte; - note -=24U; - if(envelope) { - if(wavOct<0){ - if(note > (wavOct*-1)) note = note + wavOct; - } else { - note = note + wavOct; - } - - if(wavOct!=0) while(note>71) note -=12; - - noteStatus[WAV_OLD_ENV] = envelope; - envelope = (envelope>>5U); - vibratoPosition[WAV]=0; - - switch(envelope) { - case 0: - envelope = 0x00U; - break; - case 1: - envelope = 0x60U; - break; - case 2: - envelope = 0x40U; - break; - default: - envelope = 0x20U; - } - - NR32_REG = envelope; - NR34_REG = 0x07U&(freq[note]>>8U); - NR33_REG = (freq[note]); - pbNoteRange[4] = note - pbRange[2]; - pbNoteRange[5] = note + pbRange[2]; - noteStatus[WAV_CURRENT_STATUS]=1U; - noteStatus[WAV_CURRENT_NOTE]=note; - noteStatus[WAV_CURRENT_ENV] =envelope; - pbWheelInLast[WAV] = PBWHEEL_CENTER; - - wavCurrentFreq = freq[note]; - wavOriginalFreq = freq[note]; - currentFreqData[WAV] = freq[note]; - wavStepCounter = 0; - counterWav=0U; - counterWavStart=0U; - cueWavSweep=1U; - - } else if (x == note) { - noteStatus[WAV_CURRENT_STATUS]=0U; - if(!wavSus) { - NR32_REG = 0x00U; - } - } -} - -void playNoteNoi() -{ - note = addressByte; - envelope = valueByte; - note-=24U; - note = note + noiOct; - if(envelope) { - NR42_REG = ((envelope << 1) & 0xF0U) + noiEnv; //Take a value from 0 to 127 and make it 0 to 255, and add in the envelope - NR43_REG = (noiFreq[note]); - NR41_REG = 0xFFU; //sound length - NR44_REG = 0x80U; - currentFreqData[NOI] = noiFreq[note]; - - vibratoPosition[NOI]=0; - - noteStatus[NOI_CURRENT_STATUS]=1; - noteStatus[NOI_CURRENT_NOTE]=note; - // noteStatus[NOI_CURRENT_ENV] = noteStatus[NOI_OLD_ENV] = envelope; - pbWheelInLast[NOI] = PBWHEEL_CENTER; - - } else if (noteStatus[NOI_CURRENT_NOTE] == note) { - //stop current note - noteStatus[NOI_CURRENT_STATUS] = 0U; - if(!noiSus) NR42_REG = 0x00U; - } -} - - -void playNotePoly() -{ - if(valueByte) { - polyVoiceSelect++; - if(polyVoiceSelect==0x03U)polyVoiceSelect=0x00U; - switch(polyVoiceSelect) { - case 0U: - polyNoteState[PU1] = addressByte; - //playNotePu1(); - break; - case 1U: - polyNoteState[PU2] = addressByte; - //playNotePu2(); - break; - case 2U: - polyNoteState[WAV] = addressByte; - //playNoteWav(); - break; - } - } else { - if(addressByte == (polyNoteState[PU1]-pu1Oct)) { - //playNotePu1(); - } - if (addressByte == (polyNoteState[PU2]-pu2Oct)) { - //playNotePu2(); - } - if (addressByte == (polyNoteState[WAV]-wavOct)) { - //playNoteWav(); - } - } -} -*/ void setOutputSwitch() { NR51_REG = outputSwitch[0]+outputSwitch[1]+outputSwitch[2]+outputSwitch[3]; diff --git a/Source/mGBSynthPitchFunctions.c b/Source/mGBSynthPitchFunctions.c index 75a8f8d..59ec0d6 100644 --- a/Source/mGBSynthPitchFunctions.c +++ b/Source/mGBSynthPitchFunctions.c @@ -1,47 +1,56 @@ -void setPitchBendFrequencyOffset(UBYTE synth,UBYTE synth_pitch,UBYTE synth_note_range) +void setPitchBendFrequencyOffset(UBYTE synth) { - systemIdle = 0; - if(synth != NOI) { - if(pbWheelIn[synth] & PBWHEEL_CENTER) { - currentFreq = pbWheelIn[synth] - PBWHEEL_CENTER; - currentFreq++; - currentFreq = (currentFreq<<4) / PBWHEEL_CENTER; - currentFreq = (freq[pbNoteRange[synth_note_range+1]] - freq[noteStatus[synth_pitch]]) * currentFreq; - currentFreq = freq[noteStatus[synth_pitch]] + (currentFreq>>4); - } else { - currentFreq = PBWHEEL_CENTER - pbWheelIn[synth]; - currentFreq = (currentFreq<<4) / PBWHEEL_CENTER; - currentFreq = (freq[noteStatus[synth_pitch]] - freq[pbNoteRange[synth_note_range]]) * currentFreq; - currentFreq = freq[noteStatus[synth_pitch]] - (currentFreq>>4); - } - - if(synth == PU1) { + UWORD freqRange; + UWORD f = freq[noteStatus[(synth<<1)+0x01]]; + systemIdle = 0; + if(pbWheelIn[synth] & 0x80) { + freqRange = freq[pbNoteRange[(synth<<1)+0x01]]; + currentFreq = (UWORD) (pbWheelIn[synth] - 0x7F); + currentFreq <<= 6; + currentFreq /= 128; + currentFreq = currentFreq * (freqRange - f); + currentFreq = f + (currentFreq>>6); + } else { + freqRange = freq[pbNoteRange[synth<<1]]; + currentFreq = (UWORD) (0x80 - pbWheelIn[synth]); + currentFreq <<= 6; + currentFreq /= 128; + currentFreq = currentFreq * (f - freqRange); + currentFreq = f - (currentFreq>>6); + } + switch(synth) { + case PU1: NR14_REG = (currentFreq>>8U); NR13_REG = currentFreq; currentFreqData[PU1] = currentFreq; - } else if (synth == PU2) { + break; + case PU2: NR24_REG = (currentFreq>>8U); NR23_REG = currentFreq; currentFreqData[PU2] = currentFreq; - } else if (synth == WAV) { + break; + default: NR34_REG = (currentFreq>>8U); NR33_REG = currentFreq; wavCurrentFreq = currentFreq; currentFreqData[WAV] = currentFreq; - } - } else { - if(pbWheelIn[NOI] > PBWHEEL_CENTER) { - noteStatus[NOI_CURRENT_NOTE] = noteStatus[NOI_CURRENT_NOTE]; - currentFreq = noiFreq[noteStatus[NOI_CURRENT_NOTE] + ((pbWheelIn[NOI] - PBWHEEL_CENTER) >>3)]; - } else { - noteStatus[NOI_CURRENT_NOTE] = noteStatus[NOI_CURRENT_NOTE]; - currentFreq = noiFreq[noteStatus[NOI_CURRENT_NOTE] - ((PBWHEEL_CENTER - pbWheelIn[NOI]) >>3)]; - } - NR43_REG = currentFreq; - currentFreqData[NOI] = currentFreq; } } +void setPitchBendFrequencyOffsetNoise() +{ + systemIdle = 0; + if(pbWheelIn[NOI] & 0x80) { + noteStatus[NOI_CURRENT_NOTE] = noteStatus[NOI_CURRENT_NOTE]; + currentFreq = noiFreq[noteStatus[NOI_CURRENT_NOTE] + ((pbWheelIn[NOI] - 0x80) >>3)]; + } else { + noteStatus[NOI_CURRENT_NOTE] = noteStatus[NOI_CURRENT_NOTE]; + currentFreq = noiFreq[noteStatus[NOI_CURRENT_NOTE] - ((0x80 - pbWheelIn[NOI]) >>3)]; + } + NR43_REG = currentFreq; + currentFreqData[NOI] = currentFreq; +} + void addVibrato(UBYTE synth){ if(vibratoDepth[synth]) { currentFreq = currentFreqData[synth] + vibratoPosition[synth]; @@ -78,7 +87,7 @@ void updateVibratoPosition(UBYTE synth) } } addVibrato(synth); - + } vibratoTimer[synth]++; }