]> Shamusworld >> Repos - thunder/commitdiff
Small refactoring to sprite draw code in anticipation of major refactoring
authorShamus Hammons <jlhamm@acm.org>
Thu, 3 Sep 2009 19:52:07 +0000 (19:52 +0000)
committerShamus Hammons <jlhamm@acm.org>
Thu, 3 Sep 2009 19:52:07 +0000 (19:52 +0000)
of sprite draw code. :-)

src/screen.cpp
src/screen.h

index 0d65192a578673e33797be722f303cc526f6ba9d..fef69a0a7a1653e77e273d60d8534bb8ee3b2f7a 100755 (executable)
@@ -36,10 +36,10 @@ 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 hScrollOffset;                                                                   // Horizontal scroll offset
+uint8 vScrollOffset;                                                                   // Vertical scroll offset
 uint8 spr_color_index;                                                                 // Sprite color index
-uint32 offsets[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };                        // Scroll offsets...
+uint32 hoffsets[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };               // Scroll offsets...
 uint32 voffsets[8] = { 0, 320, 640, 960, 1280, 1600, 1920, 2240 };
 
 extern bool show_text;                                                                 // Whether or not to show text
@@ -132,16 +132,14 @@ 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 + ((scr->pitch * 8 + 16) * 2);
        uint8 * pMem = (uint8 *)scr->pixels;
-       uint32 src = (uint32)(offsets[hScrollOffset] + voffsets[vScrollOffset]),
+       uint32 src = (uint32)(hoffsets[hScrollOffset] + voffsets[vScrollOffset]),
                dst1 = 0, dst2 = scr->pitch;
-//     uint32 srcAdd = 320 - 288, dstAdd = (scr->pitch * 2) - (288 * 2);
-       uint32 srcAdd = 320 - 288, dstAdd = (scr->pitch * 2) - (288 * 2);
+       uint32 srcAdd = 320 - VIRTUAL_SCREEN_WIDTH, dstAdd = (scr->pitch * 2) - (VIRTUAL_SCREEN_WIDTH * 2);
 
-       for(int i=0; i<224; i++)
+       for(int i=0; i<VIRTUAL_SCREEN_HEIGHT; i++)
        {
-               for (int j=0; j<288; j++)
+               for (int j=0; j<VIRTUAL_SCREEN_WIDTH; j++)
                {
                        pMem[dst1] = pMem[dst1 + 1] = pMem[dst2] = pMem[dst2 + 1] = my_scr[src++];
                        dst1 += 2;
@@ -195,24 +193,36 @@ static inline void DrawChar(uint8 * chr, uint8 * ram, uint8 sx, uint8 sy, uint16
 //
 void DrawSprites(uint8 priority)
 {
-       extern uint8 gram1[];                                                           // Game RAM space
+       // Sprite blocks:
+       //
+       // Offset  Note
+       // ------  -----------------------------------------------------------------------------------
+       // 4       h.fb .nnn (f = horz. flip, h = horz. expand, b = sprite offset lo bit, nnn = upper bits of sprite #)
+       // 5       Lower 7 bits of sprite #
+       // 6       Sprite color index (top 7 bits only), bottom bit is bit 8 of X position
+       // 7       Sprite X position (bits 0-7)
+       // 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
 
        for(uint16 i=0x5800; i<0x6000; i+=0x10)
        {
-               if ((gram1[i + 8] & 0xC0) == priority)                  // Check for correct layer...
+               if ((gram1[i + 8] & 0xC0) == priority)          // Check for correct layer...
                {
-                       spr_color_index = gram1[i + 6] >> 1;            // Set color...
+                       spr_color_index = gram1[i + 6] >> 1;    // Set color...
                        uint16 x = ((gram1[i + 6] & 0x01) << 8) | gram1[i + 7];
 
                        if (x > 512 - 32)
-                               x -= 512;                                                               // Handle neg x values
+                               x -= 512;                                                       // Handle neg x values
 
                        uint16 y = 192 - gram1[i + 9];
-                       uint16 hdr = (gram1[i + 4] & 0x90) << 8 | (gram1[i + 8] & 0x14);
-                       uint8 flip = gram1[i + 4] & 0x20;                       // Horizontal flip
+                       uint8 flip = gram1[i + 4] & 0x20;               // Horizontal flip
                        uint32 spr_num = ((gram1[i + 4] & 0x07) << 9) | ((gram1[i + 5] & 0x7F) << 2);
+                       spr_num += ((gram1[i + 4] & 0x10) >> 4) + ((gram1[i + 8] & 0x10) >> 3);
 
-                       Sprite(spr_num, x, y, flip, hdr);                       // Draw sprite...
+                       // Draw sprite...
+                       Sprite(spr_num, x, y, flip, (gram1[i + 4] & 0x80 ? true : false), (gram1[i + 8] & 0x04 ? true : false));
                }
        }
 }
@@ -220,72 +230,19 @@ void DrawSprites(uint8 priority)
 //
 // Sprite handler
 //
-void Sprite(uint32 sprnum, uint16 x, uint16 y, uint8 flip, uint16 spr_id)
+//void Sprite(uint32 sprnum, uint16 x, uint16 y, uint8 flip, uint16 spr_id)
+void Sprite(uint32 sprnum, uint16 x, uint16 y, uint8 flip, bool horiz_bl, bool vert_bl)
 {
        extern uint8 spr_rom[];
-       // To show or not to show a 16x16 block in the 4x4 grid...
-       bool horiz_bl = false, vert_bl = false;
        uint32 sc_addr;
 
-       x += hScrollOffset;                                                                     // Adjust x-coord
-       y += vScrollOffset;                                                                     // Adjust y-coord
+       x += hScrollOffset;                                                     // Adjust x-coord
+       y += vScrollOffset;                                                     // Adjust y-coord
 
-//     8421 8421 8421 8421
-//     1xxx xxxx xxxx xxxx   horiz_bl?
-//     xxxx xxxx xxxx x1xx   vert_bl?
-//     xxxx xxxx xxxx x0xx   y + 16?
-//     xxxB xxxx xxxA xxxx   spr# (AB) to start
+       sprnum <<= 7;                                                           // 128 bytes per sprite
 
-#if 1
-       if (spr_id & 0x8000)
-               horiz_bl = true;
-
-       if (spr_id & 0x0004)
-               vert_bl = true;
-       else
-               y += 16;
-
-       sprnum += ((spr_id & 0x1000) >> 12) + ((spr_id & 0x0010) >> 3);
-#else
-       if (spr_id == 0x8004)
-       {
-               horiz_bl = true;  vert_bl = true;
-       }
-       if (spr_id == 0x8000)
-       {
-               horiz_bl = true;  y += 16;
-       }
-       if (spr_id == 0x8010)
-       {
-               horiz_bl = true;  y += 16;  sprnum += 2;
-       }
-       if (spr_id == 0x0004)
-       {
-               vert_bl = true;
-       }
-       if (spr_id == 0x1004)
-       {
-               vert_bl = true;  sprnum++;
-       }
-       if (spr_id == 0x0000)
-       {
+       if (!vert_bl)
                y += 16;
-       }
-       if (spr_id == 0x1000)
-       {
-               y += 16;  sprnum++;
-       }
-       if (spr_id == 0x0010)
-       {
-               y += 16;  sprnum += 2;
-       }
-       if (spr_id == 0x1010)
-       {
-               y += 16;  sprnum += 3;
-       }
-#endif
-
-       sprnum <<= 7;                                                                   // 128 bytes per sprite
 
        if (!flip)
        {
index 832ec8a8a1b87b68897cc5d17616ee0fdf00b599..f616de012d6d1f7a364dda8bc42fabbd043d54e2 100755 (executable)
@@ -16,6 +16,7 @@
 
 void SnapPCX(SDL_Surface *);          // Take a PCX snapshot
 void BlitChar(SDL_Surface *, uint8 *, uint8 *); // Show NAMCO screen
-void Sprite(uint32, uint16, uint16, uint8, uint16); // Show sprite on the screen
+//void Sprite(uint32, uint16, uint16, uint8, uint16); // Show sprite on the screen
+void Sprite(uint32 sprnum, uint16 x, uint16 y, uint8 flip, bool horiz_bl, bool vert_bl);
 
 #endif // __SCREEN_H__