X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fscreen.cpp;h=fd35a1376a4425dde8aeaf19d82ad9f87e3f0702;hb=a82cb4de3c1820fe8a9a8185e55eef94a9f4b079;hp=0d65192a578673e33797be722f303cc526f6ba9d;hpb=76e6cea7537c06acd6d1201779f210d263f629ae;p=thunder diff --git a/src/screen.cpp b/src/screen.cpp index 0d65192..fd35a13 100755 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -28,6 +28,7 @@ void DrawSprites(uint8 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); // Private global variables @@ -36,10 +37,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 @@ -50,70 +51,75 @@ extern bool show_scr; // Whether or not to show screen // void BlitChar(SDL_Surface * scr, uint8 * chr, uint8 * ram) { -// Screen structure: -// Screen is 288 x 224 pixels, with character and independent sprites. Tiles are 36 x 28. -// There are four tile planes, three of them affected by the h/vscroll values, the last -// one is a static display (also has highest priority). Screens are 128 bytes wide by -// 32 bytes high. + // Screen structure: + // Screen is 288 x 224 pixels, with character and independent sprites. Tiles are 36 x 28. + // There are four tile planes, three of them affected by the h/vscroll values, the last + // one is a static display (also has highest priority). Screens are 128 bytes wide by + // 32 bytes high. if (show_scr) { - int sx, sy; uint32 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 vScrollOffset = ((ram[0x9002] + 1) & 0x07); // Vertical fine scroll amount - uint32 scp1 = 0x0180 | ((sc_base + 0x04) & 0x7F); /*0x0188;*/ - uint32 scp2 = 0x1180 | ((sc_base + 0x04) & 0x7F); /*0x1188;*/ - uint32 scp3 = 0x2180 | ((sc_base + 0x04) & 0x7F); /*0x2188;*/ - uint32 scp = 0x3208; + + 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; + + scp0 += vsc_base * 0x80; + scp0 &= 0x0FFF; // Set vertical scroll addr scp1 += vsc_base * 0x80; - scp1 &= 0x0FFF; // Set vertical scroll addr + scp1 = 0x1000 | (scp1 & 0x0FFF); // Set vertical scroll addr scp2 += vsc_base * 0x80; - scp2 = 0x1000 | (scp2 & 0x0FFF); // Set vertical scroll addr - scp3 += vsc_base * 0x80; - scp3 = 0x2000 | (scp3 & 0x0FFF); // Set vertical scroll addr + scp2 = 0x2000 | (scp2 & 0x0FFF); // Set vertical scroll addr - for(sy=0; sy<29; sy++) + // Layer 0 (bottom layer) + for(uint8 sy=0; sy<29; sy++) { - for(sx=0; sx<37; sx++) - DrawChar(chr, ram, sx, sy, scp1, (charbase ? 0x20000 : 0x00000), 0, false); + for(uint8 sx=0; sx<37; sx++) + DrawChar(chr, ram, sx, sy, scp0, (charbase ? 0x20000 : 0x00000), 0, false); - scp1 += 0x80; - scp1 = 0x0000 | (scp1 & 0x0FFF); + scp0 += 0x80; + scp0 = 0x0000 | (scp0 & 0x0FFF); } DrawSprites(0x40); // Draw sprites at lowest layer... - for(sy=0; sy<29; sy++) + // Layer 1 + for(uint8 sy=0; sy<29; sy++) { - for(sx=0; sx<37; sx++) - DrawChar(chr, ram, sx, sy, scp2, (charbase ? 0x30000 : 0x10000), 0); + for(uint8 sx=0; sx<37; sx++) + DrawChar(chr, ram, sx, sy, scp1, (charbase ? 0x30000 : 0x10000), 0); - scp2 += 0x80; - scp2 = 0x1000 | (scp2 & 0x0FFF); + scp1 += 0x80; + scp1 = 0x1000 | (scp1 & 0x0FFF); } DrawSprites(0x80); // Draw sprites under layer #2... - for(sy=0; sy<29; sy++) + // Layer 2 + for(uint8 sy=0; sy<29; sy++) { - for(sx=0; sx<37; sx++) - DrawChar(chr, ram, sx, sy, scp3, 0x40000, 0); + for(uint8 sx=0; sx<37; sx++) + DrawChar(chr, ram, sx, sy, scp2, 0x40000, 0); - scp3 += 0x80; - scp3 = 0x2000 | (scp3 & 0x0FFF); + scp2 += 0x80; + scp2 = 0x2000 | (scp2 & 0x0FFF); } DrawSprites(0xC0); // Draw highest priority sprites... - for(sy=0; sy<28; sy++) + // Layer 3 (top layer) + for(uint8 sy=0; sy<28; sy++) { - for(sx=0; sx<36; sx++) - DrawChar(chr, ram, sx, sy, scp, 0x50000, hScrollOffset + voffsets[vScrollOffset]); + for(uint8 sx=0; sx<36; sx++) + DrawChar(chr, ram, sx, sy, scp3, 0x50000, hScrollOffset + voffsets[vScrollOffset]); - scp += 0x80; + scp3 += 0x80; } } @@ -132,16 +138,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 - uint32 spr_num = ((gram1[i + 4] & 0x07) << 9) | ((gram1[i + 5] & 0x7F) << 2); + uint8 flip = gram1[i + 4] & 0x20; // Horizontal flip + uint32 spr_num = ((gram1[i + 4] & 0x07) << 9) | ((gram1[i + 5] & 0x7F) << 2) + | ((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, gram1[i + 8] & 0x04); } } } @@ -220,72 +236,18 @@ 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, uint8 horiz_bl, uint8 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) {