From: Shamus Hammons Date: Thu, 3 Sep 2009 19:52:07 +0000 (+0000) Subject: Small refactoring to sprite draw code in anticipation of major refactoring X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=thunder;a=commitdiff_plain;h=d6a4e86c4d3e3a48254975400715ea985311a346 Small refactoring to sprite draw code in anticipation of major refactoring of sprite draw code. :-) --- diff --git a/src/screen.cpp b/src/screen.cpp index 0d65192..fef69a0 100755 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -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> 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) { diff --git a/src/screen.h b/src/screen.h index 832ec8a..f616de0 100755 --- a/src/screen.h +++ b/src/screen.h @@ -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__