diff src/adplug/core/rat.cxx @ 955:4709ce4e209e trunk

[svn] Run indent -ts4 -nut -bli0 -cdw on this messy lot. Upstream is not consistent with whitespace anyway, no loss there.
author chainsaw
date Sat, 14 Apr 2007 15:23:50 -0700
parents 3da1b8942b8b
children
line wrap: on
line diff
--- a/src/adplug/core/rat.cxx	Sat Apr 14 08:48:41 2007 -0700
+++ b/src/adplug/core/rat.cxx	Sat Apr 14 15:23:50 2007 -0700
@@ -32,33 +32,36 @@
 #include "rat.h"
 #include "debug.h"
 
-const unsigned char CxadratPlayer::rat_adlib_bases[18] =
-{
+const unsigned char
+  CxadratPlayer::rat_adlib_bases[18] = {
   0x00, 0x01, 0x02, 0x08, 0x09, 0x0A, 0x10, 0x11, 0x12,
   0x03, 0x04, 0x05, 0x0B, 0x0C, 0x0D, 0x13, 0x14, 0x15
 };
 
-const unsigned short CxadratPlayer::rat_notes[16] =
-{
-  0x157, 0x16B, 0x181, 0x198, 0x1B0, 0x1CA, 0x1E5, 0x202, 0x220, 0x241, 0x263, 0x287,
-  0x000, 0x000, 0x000, 0x000 // by riven
+const unsigned short
+  CxadratPlayer::rat_notes[16] = {
+  0x157, 0x16B, 0x181, 0x198, 0x1B0, 0x1CA, 0x1E5, 0x202, 0x220, 0x241, 0x263,
+    0x287,
+  0x000, 0x000, 0x000, 0x000    // by riven
 };
 
-CPlayer *CxadratPlayer::factory(Copl *newopl)
+CPlayer *
+CxadratPlayer::factory (Copl * newopl)
 {
-  return new CxadratPlayer(newopl);
+  return new CxadratPlayer (newopl);
 }
 
-bool CxadratPlayer::xadplayer_load()
+bool
+CxadratPlayer::xadplayer_load ()
 {
-  if(xad.fmt != RAT)
+  if (xad.fmt != RAT)
     return false;
 
   // load header
-  memcpy(&rat.hdr, &tune[0], sizeof(rat_header));
+  memcpy (&rat.hdr, &tune[0], sizeof (rat_header));
 
   // is 'RAT'-signed ?
-  if (strncmp(rat.hdr.id,"RAT",3))
+  if (strncmp (rat.hdr.id, "RAT", 3))
     return false;
 
   // is version 1.0 ?
@@ -69,25 +72,26 @@
   rat.order = &tune[0x40];
 
   // load instruments
-  rat.inst = (rat_instrument *)&tune[0x140];
+  rat.inst = (rat_instrument *) & tune[0x140];
 
   // load pattern data
   unsigned short patseg = (rat.hdr.patseg[1] << 8) + rat.hdr.patseg[0];
   unsigned char *event_ptr = &tune[patseg << 4];
 
-  for(int i=0;i<rat.hdr.numpat;i++)
-    for(int j=0;j<64;j++)
-      for(int k=0;k<rat.hdr.numchan;k++)
+  for (int i = 0; i < rat.hdr.numpat; i++)
+    for (int j = 0; j < 64; j++)
+      for (int k = 0; k < rat.hdr.numchan; k++)
       {
-        memcpy(&rat.tracks[i][j][k], event_ptr, sizeof(rat_event));
+        memcpy (&rat.tracks[i][j][k], event_ptr, sizeof (rat_event));
 
-        event_ptr += sizeof(rat_event);
+        event_ptr += sizeof (rat_event);
       }
 
   return true;
 }
 
-void CxadratPlayer::xadplayer_rewind(int subsong)
+void
+CxadratPlayer::xadplayer_rewind (int subsong)
 {
   int i;
 
@@ -98,41 +102,44 @@
   plr.speed = rat.hdr.speed;
 
   // clear channel data
-  memset(&rat.channel, 0, sizeof(rat.channel[0])*9);
+  memset (&rat.channel, 0, sizeof (rat.channel[0]) * 9);
 
   // init OPL
-  opl_write(0x01, 0x20);
-  opl_write(0x08, 0x00);
-  opl_write(0xBD, 0x00);
+  opl_write (0x01, 0x20);
+  opl_write (0x08, 0x00);
+  opl_write (0xBD, 0x00);
 
   // set default frequencies
-  for(i=0;i<9;i++)
+  for (i = 0; i < 9; i++)
   {
-    opl_write(0xA0+i, 0x00);
-    opl_write(0xA3+i, 0x00);
-    opl_write(0xB0+i, 0x00);
-    opl_write(0xB3+i, 0x00);
+    opl_write (0xA0 + i, 0x00);
+    opl_write (0xA3 + i, 0x00);
+    opl_write (0xB0 + i, 0x00);
+    opl_write (0xB3 + i, 0x00);
   }
 
   // set default volumes
-  for(i=0;i<0x1F;i++)
-    opl_write(0x40+i, 0x3F);
+  for (i = 0; i < 0x1F; i++)
+    opl_write (0x40 + i, 0x3F);
 }
 
-void CxadratPlayer::xadplayer_update()
+void
+CxadratPlayer::xadplayer_update ()
 {
   int i;
 
   rat_event event;
 
   // process events
-  for(i=0;i<rat.hdr.numchan;i++)
+  for (i = 0; i < rat.hdr.numchan; i++)
   {
-    memcpy(&event,&rat.tracks[rat.order[rat.order_pos]][rat.pattern_pos][i],sizeof(rat_event));
+    memcpy (&event, &rat.tracks[rat.order[rat.order_pos]][rat.pattern_pos][i],
+            sizeof (rat_event));
 #ifdef DEBUG
-   AdPlug_LogWrite("order %02X, pattern %02X, row %02X, channel %02X, event %02X %02X %02X %02X %02X:\n",
-	         rat.order_pos, rat.order[rat.order_pos], rat.pattern_pos, i, event.note, event.instrument, event.volume, event.fx, event.fxp
-           );
+    AdPlug_LogWrite
+      ("order %02X, pattern %02X, row %02X, channel %02X, event %02X %02X %02X %02X %02X:\n",
+       rat.order_pos, rat.order[rat.order_pos], rat.pattern_pos, i,
+       event.note, event.instrument, event.volume, event.fx, event.fxp);
 #endif
 
     // is instrument ?
@@ -150,8 +157,8 @@
     if (event.note != 0xFF)
     {
       // mute channel
-      opl_write(0xB0+i, 0x00);
-      opl_write(0xA0+i, 0x00);
+      opl_write (0xB0 + i, 0x00);
+      opl_write (0xA0 + i, 0x00);
 
       // if note != 0xFE then play
       if (event.note != 0xFE)
@@ -159,34 +166,39 @@
         unsigned char ins = rat.channel[i].instrument;
 
         // synthesis/feedback
-        opl_write(0xC0+i, rat.inst[ins].connect);
+        opl_write (0xC0 + i, rat.inst[ins].connect);
 
         // controls
-		opl_write(0x20+rat_adlib_bases[i], rat.inst[ins].mod_ctrl);
-        opl_write(0x20+rat_adlib_bases[i+9], rat.inst[ins].car_ctrl);
+        opl_write (0x20 + rat_adlib_bases[i], rat.inst[ins].mod_ctrl);
+        opl_write (0x20 + rat_adlib_bases[i + 9], rat.inst[ins].car_ctrl);
 
         // volumes
-		opl_write(0x40+rat_adlib_bases[i], __rat_calc_volume(rat.inst[ins].mod_volume,rat.channel[i].volume,rat.volume));
-        opl_write(0x40+rat_adlib_bases[i+9], __rat_calc_volume(rat.inst[ins].car_volume,rat.channel[i].volume,rat.volume));
+        opl_write (0x40 + rat_adlib_bases[i],
+                   __rat_calc_volume (rat.inst[ins].mod_volume,
+                                      rat.channel[i].volume, rat.volume));
+        opl_write (0x40 + rat_adlib_bases[i + 9],
+                   __rat_calc_volume (rat.inst[ins].car_volume,
+                                      rat.channel[i].volume, rat.volume));
 
         // attack/decay
-		opl_write(0x60+rat_adlib_bases[i], rat.inst[ins].mod_AD);
-        opl_write(0x60+rat_adlib_bases[i+9], rat.inst[ins].car_AD);
+        opl_write (0x60 + rat_adlib_bases[i], rat.inst[ins].mod_AD);
+        opl_write (0x60 + rat_adlib_bases[i + 9], rat.inst[ins].car_AD);
 
         // sustain/release
-		opl_write(0x80+rat_adlib_bases[i], rat.inst[ins].mod_SR);
-        opl_write(0x80+rat_adlib_bases[i+9], rat.inst[ins].car_SR);
+        opl_write (0x80 + rat_adlib_bases[i], rat.inst[ins].mod_SR);
+        opl_write (0x80 + rat_adlib_bases[i + 9], rat.inst[ins].car_SR);
 
         // waveforms
-		opl_write(0xE0+rat_adlib_bases[i], rat.inst[ins].mod_wave);
-        opl_write(0xE0+rat_adlib_bases[i+9], rat.inst[ins].car_wave);
+        opl_write (0xE0 + rat_adlib_bases[i], rat.inst[ins].mod_wave);
+        opl_write (0xE0 + rat_adlib_bases[i + 9], rat.inst[ins].car_wave);
 
         // octave/frequency
-	unsigned short insfreq = (rat.inst[ins].freq[1] << 8) + rat.inst[ins].freq[0];
+        unsigned short insfreq =
+          (rat.inst[ins].freq[1] << 8) + rat.inst[ins].freq[0];
         unsigned short freq = insfreq * rat_notes[event.note & 0x0F] / 0x20AB;
 
-        opl_write(0xA0+i, freq & 0xFF);
-        opl_write(0xB0+i, (freq >> 8) | ((event.note & 0xF0) >> 2) | 0x20);
+        opl_write (0xA0 + i, freq & 0xFF);
+        opl_write (0xB0 + i, (freq >> 8) | ((event.note & 0xF0) >> 2) | 0x20);
       }
     }
 
@@ -202,30 +214,30 @@
   rat.pattern_pos++;
 
   // process effects
-  for(i=0;i<rat.hdr.numchan;i++)
+  for (i = 0; i < rat.hdr.numchan; i++)
   {
     unsigned char old_order_pos = rat.order_pos;
 
     switch (rat.channel[i].fx)
     {
-      case 0x01: // 0x01: Set Speed
-        plr.speed = rat.channel[i].fxp;
-        break;
-      case 0x02: // 0x02: Position Jump
-        if (rat.channel[i].fxp < rat.hdr.order_end)
-          rat.order_pos = rat.channel[i].fxp;
-        else
-          rat.order_pos = 0;
+    case 0x01:                 // 0x01: Set Speed
+      plr.speed = rat.channel[i].fxp;
+      break;
+    case 0x02:                 // 0x02: Position Jump
+      if (rat.channel[i].fxp < rat.hdr.order_end)
+        rat.order_pos = rat.channel[i].fxp;
+      else
+        rat.order_pos = 0;
 
-        // jumpback ?
-        if (rat.order_pos <= old_order_pos)
-          plr.looping = 1;
+      // jumpback ?
+      if (rat.order_pos <= old_order_pos)
+        plr.looping = 1;
 
-        rat.pattern_pos = 0;
-        break;
-      case 0x03: // 0x03: Pattern Break (?)
-        rat.pattern_pos = 0x40;
-        break;
+      rat.pattern_pos = 0;
+      break;
+    case 0x03:                 // 0x03: Pattern Break (?)
+      rat.pattern_pos = 0x40;
+      break;
     }
 
     rat.channel[i].fx = 0;
@@ -248,45 +260,50 @@
   }
 }
 
-float CxadratPlayer::xadplayer_getrefresh()
+float
+CxadratPlayer::xadplayer_getrefresh ()
 {
   return 60.0f;
 }
 
-std::string CxadratPlayer::xadplayer_gettype()
+std::string CxadratPlayer::xadplayer_gettype ()
 {
-  return (std::string("xad: rat player"));
+  return (std::string ("xad: rat player"));
 }
 
-std::string CxadratPlayer::xadplayer_gettitle()
+std::string CxadratPlayer::xadplayer_gettitle ()
 {
-  return (std::string(rat.hdr.title,32));
+  return (std::string (rat.hdr.title, 32));
 }
 
-unsigned int CxadratPlayer::xadplayer_getinstruments()
+unsigned int
+CxadratPlayer::xadplayer_getinstruments ()
 {
   return rat.hdr.numinst;
 }
 
 /* -------- Internal Functions ---------------------------- */
 
-unsigned char CxadratPlayer::__rat_calc_volume(unsigned char ivol, unsigned char cvol, unsigned char gvol)
+unsigned char
+CxadratPlayer::__rat_calc_volume (unsigned char ivol, unsigned char cvol,
+                                  unsigned char gvol)
 {
 #ifdef DEBUG
-   AdPlug_LogWrite("volumes: instrument %02X, channel %02X, global %02X:\n", ivol, cvol, gvol);
+  AdPlug_LogWrite ("volumes: instrument %02X, channel %02X, global %02X:\n",
+                   ivol, cvol, gvol);
 #endif
   unsigned short vol;
 
-  vol   =  ivol;
-  vol  &=  0x3F;
-  vol  ^=  0x3F;
-  vol  *=  cvol;
-  vol >>=  6;
-  vol  *=  gvol;
-  vol >>=  6;
-  vol  ^=  0x3F;
+  vol = ivol;
+  vol &= 0x3F;
+  vol ^= 0x3F;
+  vol *= cvol;
+  vol >>= 6;
+  vol *= gvol;
+  vol >>= 6;
+  vol ^= 0x3F;
 
-  vol  |=  ivol & 0xC0;
+  vol |= ivol & 0xC0;
 
   return vol;
 }