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);
// Private global variables
//
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.
+
if (show_scr)
{
int sx, sy;
uint32 sc_base = ((ram[0x9000] << 8) | ram[0x9001]) + 4; // Adjust hscroll val
- hScrollOffset = sc_base & 0x07; // Horiz. scroll offset
+ 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
scp3 += vsc_base * 0x80;
scp3 = 0x2000 | (scp3 & 0x0FFF); // Set vertical scroll addr
- uint32 chBaseOffset = (charbase ? 0x20000 : 0x00000);
-
for(sy=0; sy<29; sy++)
{
for(sx=0; sx<37; sx++)
- {
- uint8 scp_lo = (scp1 + (sx << 1)) & 0x7F;// Let LO byte wrap only...
- uint16 sp2 = (scp1 & 0xFF80) | scp_lo;
- uint8 tile = ram[sp2++];
- uint8 index = ram[sp2] & 0x03;
- uint8 color = ram[sp2];
- uint32 chind = chBaseOffset + (((index << 8) + tile) * 64);
- uint32 sc_addr = (sx * 8) + (sy * 2560); // Start addr in my_scr[]
-
- for(int y=0; y<8; y++)
- {
- for(int x=0; x<8; x++)
- my_scr[sc_addr++] = ccolor[color][chr[chind++]];
-
- sc_addr += 312; // Do next line...
- }
- }
+ DrawChar(chr, ram, sx, sy, scp1, (charbase ? 0x20000 : 0x00000), 0, false);
scp1 += 0x80;
scp1 = 0x0000 | (scp1 & 0x0FFF);
DrawSprites(0x40); // Draw sprites at lowest layer...
- chBaseOffset = (charbase ? 0x30000 : 0x10000);
-
for(sy=0; sy<29; sy++)
{
for(sx=0; sx<37; sx++)
- {
- uint8 scp_lo = (scp2 + (sx << 1)) & 0x7F; // Let LO byte wrap only...
- uint16 sp2 = (scp2 & 0xFF80) | scp_lo;
- uint8 tile = ram[sp2++];
- uint8 index = ram[sp2] & 0x03;
- uint8 color = ram[sp2];
- uint32 chind = chBaseOffset + (((index << 8) + tile) * 64);
- uint32 sc_addr = (sx * 8) + (sy * 2560); // Start addr in my_scr[]
-
- for(int y=0; y<8; y++)
- {
- for(int x=0; x<8; x++)
- {
- if (chr[chind] != 7)
- my_scr[sc_addr] = ccolor[color][chr[chind]];
-
- sc_addr++;
- chind++;
- }
-
- sc_addr += 312; // Do next line...
- }
- }
+ DrawChar(chr, ram, sx, sy, scp2, (charbase ? 0x30000 : 0x10000), 0);
scp2 += 0x80;
scp2 = 0x1000 | (scp2 & 0x0FFF);
for(sy=0; sy<29; sy++)
{
for(sx=0; sx<37; sx++)
- {
- uint8 scp_lo = (scp3 + (sx << 1)) & 0x7F; // Let LO byte wrap only...
- uint16 sp2 = (scp3 & 0xFF80) | scp_lo;
- uint8 tile = ram[sp2++];
- uint8 index = ram[sp2] & 0x03;
- uint8 color = ram[sp2];
- uint32 chind = 0x40000 + (((index << 8) + tile) * 64);
- uint32 sc_addr = (sx * 8) + (sy * 2560); // Start addr in my_scr[]
-
- for(int y=0; y<8; y++)
- {
- for(int x=0; x<8; x++)
- {
- if (chr[chind] != 7)
- my_scr[sc_addr] = ccolor[color][chr[chind]];
-
- sc_addr++;
- chind++;
- }
-
- sc_addr += 312; // Do next line...
- }
- }
+ DrawChar(chr, ram, sx, sy, scp3, 0x40000, 0);
- scp3 += 0x80; scp3 = 0x2000|(scp3&0x0FFF);
+ scp3 += 0x80;
+ scp3 = 0x2000 | (scp3 & 0x0FFF);
}
DrawSprites(0xC0); // Draw highest priority sprites...
for(sy=0; sy<28; sy++)
{
for(sx=0; sx<36; sx++)
- {
- uint16 sp2 = scp + (sx << 1);
- uint8 tile = ram[sp2++];
- uint8 index = ram[sp2] & 0x03;
- uint8 color = ram[sp2];
- uint32 chind = 0x50000 + (((index << 8) + tile) * 64);
- uint32 sc_addr = (sx * 8) + (sy * 2560) + hScrollOffset + voffsets[vScrollOffset]; // Start addr in my_scr[]
-
- for(int y=0; y<8; y++)
- {
- for(int x=0; x<8; x++)
- {
- if (chr[chind] != 7)
- my_scr[sc_addr] = ccolor[color][chr[chind]];
-
- sc_addr++;
- chind++;
- }
-
- sc_addr += 312; // Do next line of char...
- }
- }
+ DrawChar(chr, ram, sx, sy, scp, 0x50000, hScrollOffset + voffsets[vScrollOffset]);
scp += 0x80;
}
// exit(2);
}
- // Screen size is 288 x 224
-
- // Fast blit
-/* for(int i=0; i<224; i++)
- {
- memcpy((char *)scr->pixels + scr->pitch * i,
- my_scr + (uint32)(offsets[hScrollOffset]+voffsets[vScrollOffset]) + i * 320, 320);
- }//*/
+ // 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 + ((scr->pitch * 8 + 16) * 2);
+ uint8 * pMem = (uint8 *)scr->pixels;
uint32 src = (uint32)(offsets[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);
for(int i=0; i<224; i++)
src += srcAdd;
dst1 += dstAdd;
dst2 += dstAdd;
- }//*/
+ }
- // Scanlined pixel blit
-/* uint8 * pMem = (uint8 *)scr->pixels + ((scr->pitch * 8 + 16) * 2);
- uint32 src = (uint32)(offsets[hScrollOffset] + voffsets[vScrollOffset]),
- dst1 = 0, dst2 = scr->pitch;
- uint32 srcAdd = 320 - 288, dstAdd = (scr->pitch * 2) - (288 * 2);
+ SDL_UnlockSurface(scr);
+ SDL_UpdateRect(scr, 0, 0, 0, 0);
+}
- for(int i=0; i<224; i++)
+//
+// 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*/)
+{
+ 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[]
+
+ for(int y=0; y<8; y++)
{
- for (int j=0; j<288; j++)
+ for(int x=0; x<8; x++)
{
- pMem[dst1] = pMem[dst1 + 1] = pMem[dst2] = my_scr[src++];
- dst1 += 2;
- dst2 += 2;
- }
+ if (transparent)
+ {
+ if (chr[chind] != 7)
+ my_scr[sc_addr] = ccolor[color][chr[chind]];
+ }
+ else
+ my_scr[sc_addr] = ccolor[color][chr[chind]];
- src += srcAdd;
- dst1 += dstAdd;
- dst2 += dstAdd;
- }//*/
+ sc_addr++;
+ chind++;
+ }
- SDL_UnlockSurface(scr);
- SDL_UpdateRect(scr, 0, 0, 0, 0);
+ sc_addr += 312; // Do next line of char...
+ }
}
//
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
+
+#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;
{
y += 16; sprnum += 3;
}
+#endif
sprnum <<= 7; // 128 bytes per sprite