From 76e6cea7537c06acd6d1201779f210d263f629ae Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Thu, 13 Aug 2009 20:43:41 +0000 Subject: [PATCH] Some cleanup of the screen tile rendering. More to come. --- src/screen.cpp | 185 ++++++++++++++++++------------------------------ src/screen.h | 3 + src/thunder.cpp | 3 +- src/v6809.cpp | 37 ---------- 4 files changed, 72 insertions(+), 156 deletions(-) diff --git a/src/screen.cpp b/src/screen.cpp index b958582..0d65192 100755 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -27,6 +27,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); // Private global variables @@ -49,11 +50,17 @@ 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. + 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 @@ -68,28 +75,10 @@ void BlitChar(SDL_Surface * scr, uint8 * chr, uint8 * ram) 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); @@ -97,34 +86,10 @@ void BlitChar(SDL_Surface * scr, uint8 * chr, uint8 * ram) 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); @@ -135,31 +100,10 @@ void BlitChar(SDL_Surface * scr, uint8 * chr, uint8 * ram) 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... @@ -167,28 +111,7 @@ void BlitChar(SDL_Surface * scr, uint8 * chr, uint8 * ram) 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; } @@ -206,19 +129,14 @@ void BlitChar(SDL_Surface * scr, uint8 * chr, uint8 * ram) // 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++) @@ -233,30 +151,43 @@ void BlitChar(SDL_Surface * scr, uint8 * chr, uint8 * ram) 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... + } } // @@ -299,6 +230,23 @@ void Sprite(uint32 sprnum, uint16 x, uint16 y, uint8 flip, uint16 spr_id) 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; @@ -335,6 +283,7 @@ void Sprite(uint32 sprnum, uint16 x, uint16 y, uint8 flip, uint16 spr_id) { y += 16; sprnum += 3; } +#endif sprnum <<= 7; // 128 bytes per sprite diff --git a/src/screen.h b/src/screen.h index a4ba754..832ec8a 100755 --- a/src/screen.h +++ b/src/screen.h @@ -11,6 +11,9 @@ #include "SDL.h" #include "types.h" +#define VIRTUAL_SCREEN_WIDTH 288 +#define VIRTUAL_SCREEN_HEIGHT 224 + 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 diff --git a/src/thunder.cpp b/src/thunder.cpp index 8ee60f5..4fd1f32 100755 --- a/src/thunder.cpp +++ b/src/thunder.cpp @@ -1242,7 +1242,8 @@ WriteLog("--> CPU clock #1: %u\n", cpu1.clock); WriteLog("About to set up screen...\n"); // if (!SetVESA2()) running = false; // Set up screen // Set up screen (windowed) - screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE); //video_bpp, videoflags); +// screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE); //video_bpp, videoflags); + screen = SDL_SetVideoMode(VIRTUAL_SCREEN_WIDTH * 2, VIRTUAL_SCREEN_HEIGHT * 2, 8, SDL_SWSURFACE | SDL_DOUBLEBUF); if (screen == NULL) { cout << "Failed to initialize screen!" << endl; diff --git a/src/v6809.cpp b/src/v6809.cpp index 4874937..3dd47b5 100755 --- a/src/v6809.cpp +++ b/src/v6809.cpp @@ -3305,40 +3305,3 @@ if (disasm) #endif regs.cpuFlags &= ~line; } - -/* -Small problem: IRQ is not getting cleared! - - -820E: 9A 01 ORA $01 -V6809: IRQ line asserted! - CC=EF-I-Z-- A=00 B=00 DP=56 X=533C Y=53C0 S=57EE U=8215 PC=8210 -8210: A6 C6 LDA (A),U -V6809: IRQ line asserted! - CC=EF-I---- A=01 B=00 DP=56 X=533C Y=53C0 S=57EE U=8215 PC=8212 - -*** CONTEXT SWITCH *** - -818E: B7 80 00 STA $8000 -V6809: IRQ line asserted! - CC=EF-I---- A=02 B=00 DP=16 X=81AD Y=6224 S=03F2 U=89D7 PC=8191 -8191: B7 88 00 STA $8800 -WriteMem: CPU #2 Acknowledging IRQ... -V6809: Clearing line IRQ... -V6809: IRQ line asserted! - CC=EF-I---- A=02 B=00 DP=16 X=81AD Y=6224 S=03F2 U=89D7 PC=8194 -8194: 3B RTI -V6809: IRQ line asserted! - IRQ taken... - CC=EF-I-Z-- A=03 B=00 DP=16 X=1308 Y=6224 S=03F2 U=B0DC PC=8173 - -*** CONTEXT SWITCH *** - -8212: 97 1E STA $1E -V6809: IRQ line asserted! - CC=EF-I---- A=01 B=00 DP=56 X=533C Y=53C0 S=57EE U=8215 PC=8214 -8214: 39 RTS -V6809: IRQ line asserted! - - -*/ \ No newline at end of file -- 2.37.2