]> Shamusworld >> Repos - thunder/blobdiff - src/screen.cpp
Code cleanup.
[thunder] / src / screen.cpp
index fd35a1376a4425dde8aeaf19d82ad9f87e3f0702..5f92f223afeffc00cabb3d0023c932e4b8032e6e 100644 (file)
@@ -5,14 +5,14 @@
 // Now with VESA2 support!
 // Also, support routines for video hardware emulation are included
 //
-// by James L. Hammons
+// by James Hammons
 //
 // (C) 2003 Underground Software
 //
-// JLH = James L. Hammons <jlhamm@acm.org>
+// JLH = James Hammons <jlhamm@acm.org>
 //
 // Who  When        What
-// ---  ----------  ------------------------------------------------------------
+// ---  ----------  -----------------------------------------------------------
 // JLH  03/12/2003  Ported this steaming pile of crap from VESA to SDL
 //
 
 
 // Private function prototypes
 
-void DrawSprites(uint8 priority);
+void DrawSprites(uint8_t priority);
 int FindPCXName(void);
-static void DrawChar(uint8 * chr, uint8 * ram, uint8 sx, uint8 sy, uint16 scp, uint32 baseAddr, uint32 scrollOffset, bool transparent = true);
-void Sprite(uint32 sprnum, uint16 x, uint16 y, uint8 flip, uint8 horiz_bl, uint8 vert_bl);
+static void DrawChar(uint8_t * chr, uint8_t * ram, uint8_t sx, uint8_t sy, uint16_t scp, uint32_t baseAddr, uint32_t scrollOffset, bool transparent = true);
+void Sprite(uint32_t sprnum, uint16_t x, uint16_t y, uint8_t flip, uint8_t horiz_bl, uint8_t vert_bl);
 
 // Private global variables
 
-uint8 my_scr[0x14000];                                                                 // Screen buffer...
-uint8 palette[768];                                                                            // Screen palette
-uint8 ccolor[256][8];                                                                  // Character colors
-uint8 scolor[128][16];                                                                 // Sprite colors
-bool charbase;                                                                                 // Character base pointer...
-uint8 hScrollOffset;                                                                   // Horizontal scroll offset
-uint8 vScrollOffset;                                                                   // Vertical scroll offset
-uint8 spr_color_index;                                                                 // Sprite color index
-uint32 hoffsets[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };               // Scroll offsets...
-uint32 voffsets[8] = { 0, 320, 640, 960, 1280, 1600, 1920, 2240 };
+uint8_t my_scr[0x14000];                       // Screen buffer...
+uint8_t palette[768];                          // Screen palette
+uint8_t ccolor[256][8];                                // Character colors
+uint8_t scolor[128][16];                       // Sprite colors
+bool charbase;                                         // Character base pointer...
+uint8_t hScrollOffset;                         // Horizontal scroll offset
+uint8_t vScrollOffset;                         // Vertical scroll offset
+uint8_t spr_color_index;                       // Sprite color index
+uint32_t hoffsets[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };// Scroll offsets...
+uint32_t voffsets[8] = { 0, 320, 640, 960, 1280, 1600, 1920, 2240 };
+
+extern bool show_text;                         // Whether or not to show text
+extern bool show_scr;                          // Whether or not to show screen
 
-extern bool show_text;                                                                 // Whether or not to show text
-extern bool show_scr;                                                                  // Whether or not to show screen
 
 //
 // Render the NAMCO screen
 //
-void BlitChar(SDL_Surface * scr, uint8 * chr, uint8 * ram)
+void BlitChar(SDL_Surface * scr, uint8_t * chr, uint8_t * ram)
 {
        // Screen structure:
        // Screen is 288 x 224 pixels, with character and independent sprites. Tiles are 36 x 28.
@@ -59,16 +60,16 @@ void BlitChar(SDL_Surface * scr, uint8 * chr, uint8 * ram)
 
        if (show_scr)
        {
-               uint32 sc_base = ((ram[0x9000] << 8) | ram[0x9001]) + 4;        // Adjust hscroll val
+               uint32_t sc_base = ((ram[0x9000] << 8) | ram[0x9001]) + 4;      // Adjust hscroll val
                hScrollOffset = sc_base & 0x07;                                 // Horiz. fine scroll offset
                sc_base = (sc_base & 0xFFF8) >> 2;                              // Skip odds..
-               uint8 vsc_base = ((ram[0x9002] + 1) & 0xF8) >> 3;// Vertical scroll addr adjust
+               uint8_t vsc_base = ((ram[0x9002] + 1) & 0xF8) >> 3;// Vertical scroll addr adjust
                vScrollOffset = ((ram[0x9002] + 1) & 0x07);             // Vertical fine scroll amount
 
-               uint32 scp0 = 0x0180 | ((sc_base + 0x04) & 0x7F);       /*0x0188;*/
-               uint32 scp1 = 0x1180 | ((sc_base + 0x04) & 0x7F);       /*0x1188;*/
-               uint32 scp2 = 0x2180 | ((sc_base + 0x04) & 0x7F);       /*0x2188;*/
-               uint32 scp3 = 0x3208;
+               uint32_t scp0 = 0x0180 | ((sc_base + 0x04) & 0x7F);     /*0x0188;*/
+               uint32_t scp1 = 0x1180 | ((sc_base + 0x04) & 0x7F);     /*0x1188;*/
+               uint32_t scp2 = 0x2180 | ((sc_base + 0x04) & 0x7F);     /*0x2188;*/
+               uint32_t scp3 = 0x3208;
 
                scp0 += vsc_base * 0x80;
                scp0 &= 0x0FFF;                                                                 // Set vertical scroll addr
@@ -78,9 +79,9 @@ void BlitChar(SDL_Surface * scr, uint8 * chr, uint8 * ram)
                scp2 = 0x2000 | (scp2 & 0x0FFF);                                // Set vertical scroll addr
 
                // Layer 0 (bottom layer)
-               for(uint8 sy=0; sy<29; sy++)
+               for(uint8_t sy=0; sy<29; sy++)
                {
-                       for(uint8 sx=0; sx<37; sx++)
+                       for(uint8_t sx=0; sx<37; sx++)
                                DrawChar(chr, ram, sx, sy, scp0, (charbase ? 0x20000 : 0x00000), 0, false);
 
                        scp0 += 0x80;
@@ -90,9 +91,9 @@ void BlitChar(SDL_Surface * scr, uint8 * chr, uint8 * ram)
                DrawSprites(0x40);                                                              // Draw sprites at lowest layer...
 
                // Layer 1
-               for(uint8 sy=0; sy<29; sy++)
+               for(uint8_t sy=0; sy<29; sy++)
                {
-                       for(uint8 sx=0; sx<37; sx++)
+                       for(uint8_t sx=0; sx<37; sx++)
                                DrawChar(chr, ram, sx, sy, scp1, (charbase ? 0x30000 : 0x10000), 0);
 
                        scp1 += 0x80;
@@ -102,9 +103,9 @@ void BlitChar(SDL_Surface * scr, uint8 * chr, uint8 * ram)
                DrawSprites(0x80);                                                              // Draw sprites under layer #2...
 
                // Layer 2
-               for(uint8 sy=0; sy<29; sy++)
+               for(uint8_t sy=0; sy<29; sy++)
                {
-                       for(uint8 sx=0; sx<37; sx++)
+                       for(uint8_t sx=0; sx<37; sx++)
                                DrawChar(chr, ram, sx, sy, scp2, 0x40000, 0);
 
                        scp2 += 0x80;
@@ -114,9 +115,9 @@ void BlitChar(SDL_Surface * scr, uint8 * chr, uint8 * ram)
                DrawSprites(0xC0);                                                              // Draw highest priority sprites...
 
                // Layer 3 (top layer)
-               for(uint8 sy=0; sy<28; sy++)
+               for(uint8_t sy=0; sy<28; sy++)
                {
-                       for(uint8 sx=0; sx<36; sx++)
+                       for(uint8_t sx=0; sx<36; sx++)
                                DrawChar(chr, ram, sx, sy, scp3, 0x50000, hScrollOffset + voffsets[vScrollOffset]);
 
                        scp3 += 0x80;
@@ -138,10 +139,10 @@ void BlitChar(SDL_Surface * scr, uint8 * chr, uint8 * ram)
        // Rolling Thunder screen size is 288 x 224. Virtual is this, real may not be...
 
        // Doubled pixel blit (should be faster now!)
-       uint8 * pMem = (uint8 *)scr->pixels;
-       uint32 src = (uint32)(hoffsets[hScrollOffset] + voffsets[vScrollOffset]),
+       uint8_t * pMem = (uint8_t *)scr->pixels;
+       uint32_t src = (uint32_t)(hoffsets[hScrollOffset] + voffsets[vScrollOffset]),
                dst1 = 0, dst2 = scr->pitch;
-       uint32 srcAdd = 320 - VIRTUAL_SCREEN_WIDTH, dstAdd = (scr->pitch * 2) - (VIRTUAL_SCREEN_WIDTH * 2);
+       uint32_t srcAdd = 320 - VIRTUAL_SCREEN_WIDTH, dstAdd = (scr->pitch * 2) - (VIRTUAL_SCREEN_WIDTH * 2);
 
        for(int i=0; i<VIRTUAL_SCREEN_HEIGHT; i++)
        {
@@ -161,18 +162,19 @@ void BlitChar(SDL_Surface * scr, uint8 * chr, uint8 * ram)
        SDL_UpdateRect(scr, 0, 0, 0, 0);
 }
 
+
 //
 // Draw character on screen
 //
-static inline void DrawChar(uint8 * chr, uint8 * ram, uint8 sx, uint8 sy, uint16 scp, uint32 baseAddr, uint32 scrollOffset, bool transparent/*= true*/)
+static inline void DrawChar(uint8_t * chr, uint8_t * ram, uint8_t sx, uint8_t sy, uint16_t scp, uint32_t baseAddr, uint32_t scrollOffset, bool transparent/*= true*/)
 {
-       uint8 scp_lo = (scp + (sx << 1)) & 0x7F;// Let LO byte wrap only...
-       uint16 sp2 = (scp & 0xFF80) | scp_lo;
-       uint8 tile  = ram[sp2++];
-       uint8 index = ram[sp2] & 0x03;
-       uint8 color = ram[sp2];
-       uint32 chind = baseAddr + (((index << 8) + tile) * 64);
-       uint32 sc_addr = (sx * 8) + (sy * 2560) + scrollOffset; // Start addr in my_scr[]
+       uint8_t scp_lo = (scp + (sx << 1)) & 0x7F;// Let LO byte wrap only...
+       uint16_t sp2 = (scp & 0xFF80) | scp_lo;
+       uint8_t tile  = ram[sp2++];
+       uint8_t index = ram[sp2] & 0x03;
+       uint8_t color = ram[sp2];
+       uint32_t chind = baseAddr + (((index << 8) + tile) * 64);
+       uint32_t sc_addr = (sx * 8) + (sy * 2560) + scrollOffset;       // Start addr in my_scr[]
 
        for(int y=0; y<8; y++)
        {
@@ -194,10 +196,11 @@ static inline void DrawChar(uint8 * chr, uint8 * ram, uint8 sx, uint8 sy, uint16
        }
 }
 
+
 //
 // Draw sprites at priority level (new code)
 //
-void DrawSprites(uint8 priority)
+void DrawSprites(uint8_t priority)
 {
        // Sprite blocks:
        //
@@ -210,21 +213,21 @@ void DrawSprites(uint8 priority)
        // 8       Top two bits are sprite priority, bits 4 & 2 are sprite offset hi bit, vert. expand
        // 9       Sprite Y position (192 - value)
 
-       extern uint8 gram1[];                                                   // Game RAM space
+       extern uint8_t gram1[];                                                 // Game RAM space
 
-       for(uint16 i=0x5800; i<0x6000; i+=0x10)
+       for(uint16_t i=0x5800; i<0x6000; i+=0x10)
        {
                if ((gram1[i + 8] & 0xC0) == priority)          // Check for correct layer...
                {
                        spr_color_index = gram1[i + 6] >> 1;    // Set color...
-                       uint16 x = ((gram1[i + 6] & 0x01) << 8) | gram1[i + 7];
+                       uint16_t x = ((gram1[i + 6] & 0x01) << 8) | gram1[i + 7];
 
                        if (x > 512 - 32)
                                x -= 512;                                                       // Handle neg x values
 
-                       uint16 y = 192 - gram1[i + 9];
-                       uint8 flip = gram1[i + 4] & 0x20;               // Horizontal flip
-                       uint32 spr_num = ((gram1[i + 4] & 0x07) << 9) | ((gram1[i + 5] & 0x7F) << 2)
+                       uint16_t y = 192 - gram1[i + 9];
+                       uint8_t flip = gram1[i + 4] & 0x20;             // Horizontal flip
+                       uint32_t spr_num = ((gram1[i + 4] & 0x07) << 9) | ((gram1[i + 5] & 0x7F) << 2)
                                | ((gram1[i + 4] & 0x10) >> 4) | ((gram1[i + 8] & 0x10) >> 3);
 
                        // Draw sprite...
@@ -233,13 +236,14 @@ void DrawSprites(uint8 priority)
        }
 }
 
+
 //
 // Sprite handler
 //
-void Sprite(uint32 sprnum, uint16 x, uint16 y, uint8 flip, uint8 horiz_bl, uint8 vert_bl)
+void Sprite(uint32_t sprnum, uint16_t x, uint16_t y, uint8_t flip, uint8_t horiz_bl, uint8_t vert_bl)
 {
-       extern uint8 spr_rom[];
-       uint32 sc_addr;
+       extern uint8_t spr_rom[];
+       uint32_t sc_addr;
 
        x += hScrollOffset;                                                     // Adjust x-coord
        y += vScrollOffset;                                                     // Adjust y-coord
@@ -251,12 +255,12 @@ void Sprite(uint32 sprnum, uint16 x, uint16 y, uint8 flip, uint8 horiz_bl, uint8
 
        if (!flip)
        {
-               for(uint16 sy=0; sy<16; sy++)
+               for(uint16_t sy=0; sy<16; sy++)
                {
-                       for(uint16 sx=0; sx<16; sx+=2)
+                       for(uint16_t sx=0; sx<16; sx+=2)
                        {
-                               uint8 b1 = spr_rom[sprnum] >> 4, b2 = spr_rom[sprnum++] & 0x0F;
-                               uint16 spy = y + sy, spx = x + sx;      // Need to optimize this clipping!
+                               uint8_t b1 = spr_rom[sprnum] >> 4, b2 = spr_rom[sprnum++] & 0x0F;
+                               uint16_t spy = y + sy, spx = x + sx;    // Need to optimize this clipping!
 
                                if (spy > 223 || spx > 299)
                                        sc_addr = 0x13FFE;
@@ -275,12 +279,12 @@ void Sprite(uint32 sprnum, uint16 x, uint16 y, uint8 flip, uint8 horiz_bl, uint8
 
                if (horiz_bl)
                {
-                       for(uint16 sy=0; sy<16; sy++)
+                       for(uint16_t sy=0; sy<16; sy++)
                        {
-                               for(uint16 sx=16; sx<32; sx+=2)
+                               for(uint16_t sx=16; sx<32; sx+=2)
                                {
-                                       uint8 b1 = spr_rom[sprnum] >> 4, b2 = spr_rom[sprnum++] & 0x0F;
-                                       uint16 spy = y + sy, spx = x + sx;
+                                       uint8_t b1 = spr_rom[sprnum] >> 4, b2 = spr_rom[sprnum++] & 0x0F;
+                                       uint16_t spy = y + sy, spx = x + sx;
 
                                        if (spy > 223 || spx > 299)
                                                sc_addr = 0x13FFE;
@@ -304,12 +308,12 @@ void Sprite(uint32 sprnum, uint16 x, uint16 y, uint8 flip, uint8 horiz_bl, uint8
                {
                        y += 16;                                                                        // Do next row...
 
-                       for(uint16 sy=0; sy<16; sy++)
+                       for(uint16_t sy=0; sy<16; sy++)
                        {
-                               for(uint16 sx=0; sx<16; sx+=2)
+                               for(uint16_t sx=0; sx<16; sx+=2)
                                {
-                                       uint8 b1 = spr_rom[sprnum] >> 4, b2 = spr_rom[sprnum++] & 0x0F;
-                                       uint16 spy = y + sy, spx = x + sx;
+                                       uint8_t b1 = spr_rom[sprnum] >> 4, b2 = spr_rom[sprnum++] & 0x0F;
+                                       uint16_t spy = y + sy, spx = x + sx;
 
                                        if (spy > 223 || spx > 299)
                                                sc_addr = 0x13FFE;
@@ -328,12 +332,12 @@ void Sprite(uint32 sprnum, uint16 x, uint16 y, uint8 flip, uint8 horiz_bl, uint8
 
                        if (horiz_bl)
                        {
-                               for(uint16 sy=0; sy<16; sy++)
+                               for(uint16_t sy=0; sy<16; sy++)
                                {
-                                       for(uint16 sx=16; sx<32; sx+=2)
+                                       for(uint16_t sx=16; sx<32; sx+=2)
                                        {
-                                               uint8 b1 = spr_rom[sprnum] >> 4, b2 = spr_rom[sprnum++] & 0x0F;
-                                               uint16 spy = y + sy, spx = x + sx;
+                                               uint8_t b1 = spr_rom[sprnum] >> 4, b2 = spr_rom[sprnum++] & 0x0F;
+                                               uint16_t spy = y + sy, spx = x + sx;
 
                                                if (spy > 223 || spx > 299)
                                                        sc_addr = 0x13FFE;
@@ -354,88 +358,109 @@ void Sprite(uint32 sprnum, uint16 x, uint16 y, uint8 flip, uint8 horiz_bl, uint8
        }
        else    // Flip
        {
-    if (horiz_bl)
-    {
-      for(uint16 sy=0; sy<16; sy++)
-      {
-        for(uint16 sx=30; sx!=14; sx-=2)
-        {
-          uint8 b1 = spr_rom[sprnum]>>4, b2 = spr_rom[sprnum++]&0x0F;
-        uint16 spy = y+sy, spx = x+sx;
-        if ((spy>223) || (spx>299))
-          sc_addr = 0x13FFE;
-        else
-          sc_addr = spx+spy*320;
-          if (b2 != 15)
-            my_scr[sc_addr] = scolor[spr_color_index][b2]; // Store it
-          sc_addr++;
-          if (b1 != 15)
-            my_scr[sc_addr] = scolor[spr_color_index][b1]; // Store it
-        }
-      }
-    }
-    for(uint16 sy=0; sy<16; sy++)
-    {
-      for(uint16 sx=14; sx!=0xFFFE; sx-=2)
-      {
-        uint8 b1 = spr_rom[sprnum]>>4, b2 = spr_rom[sprnum++]&0x0F;
-        uint16 spy = y+sy, spx = x+sx;
-        if ((spy>223) || (spx>299))
-          sc_addr = 0x13FFE;
-        else
-          sc_addr = spx+spy*320;
-        if (b2 != 15)
-          my_scr[sc_addr] = scolor[spr_color_index][b2]; // Store it
-        sc_addr++;
-        if (b1 != 15)
-          my_scr[sc_addr] = scolor[spr_color_index][b1]; // Store it
-      }
-    }
-    if (!horiz_bl)  sprnum += 128;  // If single, skip sprite...
-    if (vert_bl)
-    {
-      y += 16;      // Adjust Y coord...
-      if (horiz_bl)
-      {
-        for(uint16 sy=0; sy<16; sy++)
-        {
-          for(uint16 sx=30; sx!=14; sx-=2)
-          {
-            uint8 b1 = spr_rom[sprnum]>>4, b2 = spr_rom[sprnum++]&0x0F;
-        uint16 spy = y+sy, spx = x+sx;
-        if ((spy>223) || (spx>299))
-          sc_addr = 0x13FFE;
-        else
-          sc_addr = spx+spy*320;
-            if (b2 != 15)
-              my_scr[sc_addr] = scolor[spr_color_index][b2]; // Store it
-            sc_addr++;
-            if (b1 != 15)
-               my_scr[sc_addr] = scolor[spr_color_index][b1]; // Store it
-          }
-        }
-      }
-      for(uint16 sy=0; sy<16; sy++)
-      {
-        for(uint16 sx=14; sx!=0xFFFE; sx-=2)
-        {
-          uint8 b1 = spr_rom[sprnum]>>4, b2 = spr_rom[sprnum++]&0x0F;
-        uint16 spy = y+sy, spx = x+sx;
-        if ((spy>223) || (spx>299))
-          sc_addr = 0x13FFE;
-        else
-          sc_addr = spx+spy*320;
-          if (b2 != 15)
-            my_scr[sc_addr] = scolor[spr_color_index][b2]; // Store it
-          sc_addr++;
-          if (b1 != 15)
-            my_scr[sc_addr] = scolor[spr_color_index][b1]; // Store it
-        }
-      }
-    }
-  }
+               if (horiz_bl)
+               {
+                       for(uint16_t sy=0; sy<16; sy++)
+                       {
+                               for(uint16_t sx=30; sx!=14; sx-=2)
+                               {
+                                       uint8_t b1 = spr_rom[sprnum] >> 4, b2 = spr_rom[sprnum++] & 0x0F;
+                                       uint16_t spy = y + sy, spx = x + sx;
+
+                                       if ((spy > 223) || (spx > 299))
+                                               sc_addr = 0x13FFE;
+                                       else
+                                               sc_addr = spx + spy * 320;
+
+                                       if (b2 != 15)
+                                               my_scr[sc_addr] = scolor[spr_color_index][b2]; // Store it
+
+                                       sc_addr++;
+
+                                       if (b1 != 15)
+                                               my_scr[sc_addr] = scolor[spr_color_index][b1]; // Store it
+                               }
+                       }
+               }
+
+               for(uint16_t sy=0; sy<16; sy++)
+               {
+                       for(uint16_t sx=14; sx!=0xFFFE; sx-=2)
+                       {
+                               uint8_t b1 = spr_rom[sprnum] >> 4, b2 = spr_rom[sprnum++] & 0x0F;
+                               uint16_t spy = y + sy, spx = x + sx;
+
+                               if ((spy > 223) || (spx > 299))
+                                       sc_addr = 0x13FFE;
+                               else
+                                       sc_addr = spx+spy*320;
+
+                               if (b2 != 15)
+                                       my_scr[sc_addr] = scolor[spr_color_index][b2]; // Store it
+
+                               sc_addr++;
+
+                               if (b1 != 15)
+                                       my_scr[sc_addr] = scolor[spr_color_index][b1]; // Store it
+                       }
+               }
+
+               if (!horiz_bl)  sprnum += 128;  // If single, skip sprite...
+
+               if (vert_bl)
+               {
+                       y += 16;      // Adjust Y coord...
+
+                       if (horiz_bl)
+                       {
+                               for(uint16_t sy=0; sy<16; sy++)
+                               {
+                                       for(uint16_t sx=30; sx!=14; sx-=2)
+                                       {
+                                               uint8_t b1 = spr_rom[sprnum] >> 4, b2 = spr_rom[sprnum++] & 0x0F;
+                                               uint16_t spy = y + sy, spx = x + sx;
+
+                                               if ((spy > 223) || (spx > 299))
+                                                       sc_addr = 0x13FFE;
+                                               else
+                                                       sc_addr = spx + spy * 320;
+
+                                               if (b2 != 15)
+                                                       my_scr[sc_addr] = scolor[spr_color_index][b2]; // Store it
+
+                                               sc_addr++;
+
+                                               if (b1 != 15)
+                                                       my_scr[sc_addr] = scolor[spr_color_index][b1]; // Store it
+                                       }
+                               }
+                       }
+                       for(uint16_t sy=0; sy<16; sy++)
+                       {
+                               for(uint16_t sx=14; sx!=0xFFFE; sx-=2)
+                               {
+                                       uint8_t b1 = spr_rom[sprnum] >> 4, b2 = spr_rom[sprnum++] & 0x0F;
+                                       uint16_t spy = y + sy, spx = x + sx;
+
+                                       if ((spy > 223) || (spx > 299))
+                                               sc_addr = 0x13FFE;
+                                       else
+                                               sc_addr = spx + spy * 320;
+
+                                       if (b2 != 15)
+                                               my_scr[sc_addr] = scolor[spr_color_index][b2]; // Store it
+
+                                       sc_addr++;
+
+                                       if (b1 != 15)
+                                               my_scr[sc_addr] = scolor[spr_color_index][b1]; // Store it
+                               }
+                       }
+               }
+       }
 }
 
+
 int FindPCXName()
 {
        static int pcxNum = -1;                                                         // This needs to go elsewhere... (or does it?)
@@ -457,6 +482,7 @@ int FindPCXName()
        return -1;
 }
 
+
 void SnapPCX(SDL_Surface * scr)
 {
        char filename[30];
@@ -466,8 +492,9 @@ void SnapPCX(SDL_Surface * scr)
        int YMax = 223;
        int bytesPerLine = 320;
 
+       // Return if failed...
        if ((i = FindPCXName()) < 0)
-               return;               // failed...
+               return;
 
        sprintf(filename, "thnd%04i.pcx", i);
 
@@ -480,46 +507,68 @@ void SnapPCX(SDL_Surface * scr)
        fputc(0x5, fw); // version 5
        fputc(0x1, fw); // RLE encoding
        fputc(0x8, fw); // bits per pixel
-       fputc(0, fw);  fputc(0, fw);  fputc(0, fw);  fputc(0, fw); // XMin=0,YMin=0
-       fputc(XMax&0xFF, fw);  fputc(XMax>>8, fw);
-       fputc(YMax&0xFF, fw);  fputc(YMax>>8, fw);
-       fputc(0, fw);  fputc(0, fw);  fputc(0, fw);  fputc(0,fw); // unknown DPI
-       for (i=0; i<48; i++)  fputc(0, fw);                 // EGA color palette
+       fputc(0, fw);
+       fputc(0, fw);
+       fputc(0, fw);
+       fputc(0, fw); // XMin=0,YMin=0
+       fputc(XMax & 0xFF, fw);
+       fputc(XMax >> 8, fw);
+       fputc(YMax & 0xFF, fw);
+       fputc(YMax >> 8, fw);
+       fputc(0, fw);
+       fputc(0, fw);
+       fputc(0, fw);
+       fputc(0,fw); // unknown DPI
+
+       for (i=0; i<48; i++)
+               fputc(0, fw);                 // EGA color palette
+
        fputc(0, fw); // reserved
        fputc(1, fw); // number of bit planes
-       fputc(bytesPerLine&0xFF, fw);  fputc(bytesPerLine>>8, fw);
-       fputc(1, fw);  fputc(0, fw); // palette info - unused
-       fputc((XMax+1)&0xFF, fw);  fputc((XMax+1)>>8, fw);
-       fputc((YMax+1)&0xFF, fw);  fputc((YMax+1)>>8, fw); // screen resolution
-       for (i=0; i<54; i++)  fputc(0, fw); // unused
+       fputc(bytesPerLine & 0xFF, fw);
+       fputc(bytesPerLine >> 8, fw);
+       fputc(1, fw);
+       fputc(0, fw); // palette info - unused
+       fputc((XMax + 1) & 0xFF, fw);
+       fputc((XMax + 1) >> 8, fw);
+       fputc((YMax + 1) & 0xFF, fw);
+       fputc((YMax + 1) >> 8, fw); // screen resolution
+
+       for (i=0; i<54; i++)
+               fputc(0, fw); // unused
 
        // Instead of using the screen, we should use our internal buffer...
        SDL_LockSurface(scr);
 
-       uint32 mem = scr->pitch * 8; // Skip first line... WAS:320*8;
+       uint32_t mem = scr->pitch * 8; // Skip first line... WAS:320*8;
+
        for (line=0; line<=YMax; line++)
        {
                int count;
                int last;
                int xpos;
-               uint8 * pMem = (uint8 *)scr->pixels;
+               uint8_t * pMem = (uint8_t *)scr->pixels;
 
                xpos = 0;
+
                while (xpos < bytesPerLine)
                {
                        last = pMem[mem++];
                        xpos++;
                        count = 1;
+
                        while (pMem[mem] == last && xpos < bytesPerLine && count < 63)
                        {
                                mem++;  count++;  xpos++;
                        }
 
-                       if (count > 1 || (last&0xC0) == 0xC0)
+                       if (count > 1 || (last & 0xC0) == 0xC0)
                        {
-                               fputc(0xC0 | (count & 0x3F), fw);  fputc(last & 0xFF, fw);
+                               fputc(0xC0 | (count & 0x3F), fw);
+                               fputc(last & 0xFF, fw);
                        }
-                       else fputc(last & 0xFF, fw);
+                       else
+                               fputc(last & 0xFF, fw);
                }
                mem += (scr->pitch - 320);  // Handle non-standard line lengths...
        }
@@ -527,10 +576,11 @@ void SnapPCX(SDL_Surface * scr)
        SDL_UnlockSurface(scr);
 
        // Write the palette
-
        fputc(0x0C, fw);
+
        for (i=0; i<768; i++)
                fputc(palette[i], fw);
 
        fclose(fw);    // success!
 }
+