//-------------------------------------
// Main title screen where you choose
// which version (1 or 2) of Lethal
// Enforcers you want to play
//-------------------------------------
int MainTitle (DoubleBuffer *db, Foreground *frgnd, u_long memptr)
{
   Background  *bkd;
   Character   *Chars[2];
   int         i, j = 255, k = 255, l = 255;
   int         dummy, sfx, vab;
   int         trigger = 0;
   int         counter = 1;
   int         LEVersion;
                                       
   //----------------------------------
   memptr = (u_long)((memptr + 3) & 0xFFFFFFFC);
   bkd = (Background *)memptr;          // Allocate space for background data
   memptr += sizeof (Background);

   memptr = (u_long)((memptr + 3) & 0xFFFFFFFC); // Load the background image
   bkd->Load ("\\BACKGRND\\MISCELLA\\MAINTITL.BKD", &memptr);
   bkd->SetLocation (0,0);

   //----------------------------------
   memptr = (u_long)((memptr + 3) & 0xFFFFFFFC);
   Chars[0] = (Character *)memptr;
   memptr += sizeof (Character);

   Chars[0]->Load ("\\SPRITES\\MAINTITL\\GAME.KRT", &memptr);
   Chars[1] = Chars[0]->Clone_Character (1, &memptr);
                                       
   Chars[0]->StartAction (0, 0);
   Chars[0]->Set_Location (85, 134);
   Chars[0]->SetDepth (3);
   Chars[1]->StartAction (1, 0);
   Chars[1]->Set_Location (235, 134);
   Chars[1]->SetDepth (3);

   frgnd->Credits = 0;
   frgnd->Plr1.Lifepnt = 1;
   frgnd->Plr2.Lifepnt = 1;

   //----------------------------------
   #ifdef TARGETCD
      #ifdef PLAY_CDXAS
         CDXACue = AudioLoadCueListFile ((u_char *)"\\CDXA\\LETHAL1.BIN;1");

         // Wait for the end of BIN file loading
         while (AudioWaveTableLoadStatus () == 0);

         if (AudioWaveTableLoadStatus () == -1)
         {
            FntPrint ("Unable to load music information.\n");
            db->Swap (1);
            db->Swap (1);
            while (1);
         }

         AudioPlayCue (SD_mainslct);
      #endif
   #endif

   //----------------------------------
   while (counter)
   {
      if (!trigger)
      {
         Control_Read (&trigger, frgnd, -1, &dummy);
         if (trigger)
         {
            PLAYER *player;
            if (trigger & 1)
               player = &frgnd->Plr1;
            else
               player = &frgnd->Plr2;

            if ((player->GunY > 96) && (player->GunY < 172))
            {
               if ((player->GunX > 34) && (player->GunX < 136))        // LE1
               {
                  bkd->BuildDestClut (2);
                  Chars[1]->BuildDestClut (2);
                  LEVersion = 0;
               }
               else if ((player->GunX > 184) && (player->GunX < 286))  // LE2
               {
                  bkd->BuildDestClut (2);
                  Chars[0]->BuildDestClut (2);
                  LEVersion = 1;
               }
               else
                  trigger = 0;
            }
            else
               trigger = 0;
         }
      }
         
      if (debug)
      {
         FntPrint ("j:%d  k:%d  l:%d\n", j, k, l);
      }

      if (trigger)                      // Darken some stuff if necessary
      {
         j = bkd->ChangeClut ();
         k = Chars[0]->ChangeClut (0);
         l = Chars[1]->ChangeClut (0);
         if ((!j) && (!k) && (!l))
            counter = 0;
      }

      bkd->Draw (db, 0);
      Chars[0]->DrawNextFrame (0,0, db, &sfx, &vab, &dummy);
      Chars[1]->DrawNextFrame (0,0, db, &sfx, &vab, &dummy);
      Draw_Gun_Cursor (frgnd, db, 1);

      db->Swap (debug);
   }

   Chars[0]->Clear ();
   Chars[1]->Clear ();
   bkd->Clear ();

   frgnd->Plr1.Lifepnt = 0;
   frgnd->Plr2.Lifepnt = 0;

   #ifdef TARGETCD
      #ifdef PLAY_CDXAS
         AudioUnloadCueList (CDXACue);
      #endif
   #endif

   return (LEVersion);
}
