KSSBrawl_

HandleNoiseMusic

Oct 24th, 2021 (edited)
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.09 KB | None | 0 0
  1. static void
  2. HandleNoiseMusic()
  3. {
  4.     u8 a, y, x;
  5.  
  6.     // The underground and castle music do not use the noise channel. This bitmask is used
  7.     // to check if either of these are the active music
  8.     u8 const NO_NOISE_DATA_MASK = MUSIC_Underground | MUSIC_Castle;
  9.  
  10.     if ( !( AreaMusicBuffer & (u8)~NO_NOISE_DATA_MASK ) )
  11.         return;
  12.    
  13.     if ( --Noise_BeatLenCounter == 0 )
  14.     {
  15.         for ( ; ; )
  16.         {
  17.             y = MusicOffset_Noise++;
  18.             a = MusicData[y];
  19.  
  20.             if ( a != 0 ) // If not end of noise data
  21.                 break;
  22.  
  23.             MusicOffset_Noise = NoiseDataLoopbackOfs;
  24.         }
  25.  
  26.         x = a;
  27.         Noise_BeatLenCounter = AlternateLengthHandler( a );
  28.         a &= 0b00111110;
  29.  
  30.         // Hihat
  31.         if ( a == 0x30 )
  32.         {
  33.             a = 0x1c;
  34.             x = 0x03;
  35.             y = 0x58;
  36.         }
  37.         // Kick
  38.         else if ( a == 0x20 )
  39.         {
  40.             a = 0x1c;
  41.             x = 0x0c;
  42.             y = 0x18;
  43.         }
  44.         // Snare
  45.         else if ( a & 0x10 )
  46.         {
  47.             a = 0x1c;
  48.             x = 0x03;
  49.             y = 0x18;
  50.         }
  51.         // Rest (X and Y are not written to since the value in A will silence the channel)
  52.         else
  53.             a = 0x10;
  54.  
  55.         write_apu_reg( NOIVOL, a );
  56.         write_apu_reg( NOIFREQ, x );
  57.         write_apu_reg( NOILEN, y );
  58.     }
  59. }
Add Comment
Please, Sign In to add comment