Clean-up & documented: CopySource()

Clean-up: UpdateHiResCell()
This commit is contained in:
mpohoreski 2011-01-06 17:10:23 +00:00
parent 6a65821ec3
commit a44367e7ea

View File

@ -134,13 +134,13 @@ enum Color_Palette_Index_e
//#define SRCOFFS_DHIRES (SRCOFFS_HIRES + 512) //#define SRCOFFS_DHIRES (SRCOFFS_HIRES + 512)
//#define SRCOFFS_TOTAL (SRCOFFS_DHIRES + 2560) //#define SRCOFFS_TOTAL (SRCOFFS_DHIRES + 2560)
const int SRCOFFS_40COL = 0; const int SRCOFFS_40COL = 0; // 0
const int SRCOFFS_IIPLUS = (SRCOFFS_40COL + 256); const int SRCOFFS_IIPLUS = (SRCOFFS_40COL + 256); // 256
const int SRCOFFS_80COL = (SRCOFFS_IIPLUS + 256); const int SRCOFFS_80COL = (SRCOFFS_IIPLUS + 256); // 512
const int SRCOFFS_LORES = (SRCOFFS_80COL + 128); const int SRCOFFS_LORES = (SRCOFFS_80COL + 128); // 640
const int SRCOFFS_HIRES = (SRCOFFS_LORES + 16); const int SRCOFFS_HIRES = (SRCOFFS_LORES + 16); // 656
const int SRCOFFS_DHIRES = (SRCOFFS_HIRES + 512); const int SRCOFFS_DHIRES = (SRCOFFS_HIRES + 512); // 1168
const int SRCOFFS_TOTAL = (SRCOFFS_DHIRES + 2560); const int SRCOFFS_TOTAL = (SRCOFFS_DHIRES + 2560); // 3278
#define SW_80COL (g_bVideoMode & VF_80COL) #define SW_80COL (g_bVideoMode & VF_80COL)
#define SW_DHIRES (g_bVideoMode & VF_DHIRES) #define SW_DHIRES (g_bVideoMode & VF_DHIRES)
@ -182,7 +182,7 @@ static HDC g_hDeviceDC;
LPBYTE g_pFramebufferbits = NULL; // last drawn frame LPBYTE g_pFramebufferbits = NULL; // last drawn frame
static LPBITMAPINFO g_pFramebufferinfo = NULL; static LPBITMAPINFO g_pFramebufferinfo = NULL;
static LPBYTE frameoffsettable[FRAMEBUFFER_H]; // array of pointers to start of each scanline static LPBYTE g_aFrameBufferOffset[FRAMEBUFFER_H]; // array of pointers to start of each scanline
static LPBYTE g_pHiresBank1; static LPBYTE g_pHiresBank1;
static LPBYTE g_pHiresBank0; static LPBYTE g_pHiresBank0;
HBITMAP g_hLogoBitmap; HBITMAP g_hLogoBitmap;
@ -209,7 +209,7 @@ static WORD colormixmap[6][6][6];
bool g_VideoForceFullRedraw = 1; bool g_VideoForceFullRedraw = 1;
static LPBYTE framebufferaddr = (LPBYTE)0; static LPBYTE framebufferaddr = (LPBYTE)0;
static LONG framebufferpitch = 0; static LONG g_nFrameBufferPitch = 0;
BOOL graphicsmode = 0; BOOL graphicsmode = 0;
static BOOL hasrefreshed = 0; static BOOL hasrefreshed = 0;
static DWORD lastpageflip = 0; static DWORD lastpageflip = 0;
@ -257,43 +257,54 @@ void Video_MakeScreenShot( FILE *pFile );
int GetMonochromeIndex(); int GetMonochromeIndex();
//=========================================================================== /** Our BitClit() / VRAM_Copy()
void __stdcall CopySource (int destx, int desty, @param dx Dst X
int xsize, int ysize, @param dy Dst Y
int sourcex, int sourcey) @param w Width (same for src & dst)
@param h Height (same for src & dst)
@param sx Src X
@param sy Src Y
// =========================================================================== */
void CopySource (int dx, int dy, int w, int h, int sx, int sy )
{ {
LPBYTE currdestptr = frameoffsettable [desty] +destx; LPBYTE pDst = g_aFrameBufferOffset[ dy ] + dx;
LPBYTE currsourceptr = g_aSourceStartofLine[sourcey]+sourcex; LPBYTE pSrc = g_aSourceStartofLine[ sy ] + sx;
int bytesleft; int nBytes;
while (ysize--)
{ while (h--)
bytesleft = xsize;
while (bytesleft & 3)
{ {
--bytesleft; nBytes = w;
*(currdestptr+bytesleft) = *(currsourceptr+bytesleft);
} // If not multiple of 3 bytes, copy first 3 bytes, so the next copy is 4-byte aligned.
while (bytesleft) while (nBytes & 3)
{ {
bytesleft -= 4; --nBytes;
*(LPDWORD)(currdestptr+bytesleft) = *(LPDWORD)(currsourceptr+bytesleft); *(pDst+nBytes) = *(pSrc+nBytes);
} }
currdestptr -= framebufferpitch;
currsourceptr -= SRCOFFS_TOTAL; // Copy 4 bytes at a time
} while (nBytes)
{
nBytes -= 4;
*(LPDWORD)(pDst+nBytes) = *(LPDWORD)(pSrc+nBytes);
}
pDst -= g_nFrameBufferPitch;
pSrc -= SRCOFFS_TOTAL;
}
} }
//=========================================================================== //===========================================================================
void CreateFrameOffsetTable (LPBYTE addr, LONG pitch) { void CreateFrameOffsetTable (LPBYTE addr, LONG pitch) {
if (framebufferaddr == addr && if (framebufferaddr == addr &&
framebufferpitch == pitch) g_nFrameBufferPitch == pitch)
return; return;
framebufferaddr = addr; framebufferaddr = addr;
framebufferpitch = pitch; g_nFrameBufferPitch = pitch;
// CREATE THE OFFSET TABLE FOR EACH SCAN LINE IN THE FRAME BUFFER // CREATE THE OFFSET TABLE FOR EACH SCAN LINE IN THE FRAME BUFFER
for (int y = 0; y < FRAMEBUFFER_H; y++) for (int y = 0; y < FRAMEBUFFER_H; y++)
frameoffsettable[y] = framebufferaddr + framebufferpitch*((FRAMEBUFFER_H-1)-y); g_aFrameBufferOffset[y] = framebufferaddr + g_nFrameBufferPitch*((FRAMEBUFFER_H-1)-y);
} }
//=========================================================================== //===========================================================================
@ -1400,7 +1411,7 @@ void __stdcall MixColorsVertical(int matx, int maty) { // For tv emulation g_nAp
void __stdcall CopyMixedSource (int x, int y, int sourcex, int sourcey) { // For tv emulation g_nAppMode void __stdcall CopyMixedSource (int x, int y, int sourcex, int sourcey) { // For tv emulation g_nAppMode
LPBYTE currsourceptr = g_aSourceStartofLine[sourcey]+sourcex; LPBYTE currsourceptr = g_aSourceStartofLine[sourcey]+sourcex;
LPBYTE currdestptr = frameoffsettable[y<<1] + (x<<1); LPBYTE currdestptr = g_aFrameBufferOffset[y<<1] + (x<<1);
LPBYTE currptr; LPBYTE currptr;
int matx = x; int matx = x;
@ -1425,11 +1436,11 @@ void __stdcall CopyMixedSource (int x, int y, int sourcex, int sourcey) { // For
// transfer up to 6 mixed (half-)pixels of current column to framebuffer // transfer up to 6 mixed (half-)pixels of current column to framebuffer
currptr = currdestptr+bufxoffset; currptr = currdestptr+bufxoffset;
if (hgrlinesabove) if (hgrlinesabove)
currptr += framebufferpitch << 1; currptr += g_nFrameBufferPitch << 1;
for (i = istart; for (i = istart;
i <= iend; i <= iend;
currptr -= framebufferpitch, i++) { currptr -= g_nFrameBufferPitch, i++) {
*currptr = *(currptr+1) = colormixbuffer[i]; *currptr = *(currptr+1) = colormixbuffer[i];
} }
} }
@ -1441,32 +1452,45 @@ bool UpdateHiResCell (int x, int y, int xpixel, int ypixel, int offset)
{ {
bool bDirty = false; bool bDirty = false;
int yoffset = 0; int yoffset = 0;
while (yoffset < 0x2000) { while (yoffset < 0x2000)
BYTE byteval1 = (x > 0) ? *(g_pHiresBank0+offset+yoffset-1) : 0; {
BYTE byteval2 = *(g_pHiresBank0+offset+yoffset); #if 0 // TRACE_VIDEO
BYTE byteval3 = (x < 39) ? *(g_pHiresBank0+offset+yoffset+1) : 0; static char sText[ 256 ];
if ((byteval2 != *(vidlastmem+offset+yoffset+0x2000)) || sprintf(sText, "x: %3d y: %3d xpix: %3d ypix: %3d offset: %04X \n"
((x > 0) && ((byteval1 & 0x60) != (*(vidlastmem+offset+yoffset+0x1FFF) & 0x60))) || , x, y, xpixel, ypixel, offset, yoffset
((x < 39) && ((byteval3 & 0x03) != (*(vidlastmem+offset+yoffset+0x2001) & 0x03))) || );
g_VideoForceFullRedraw) { OutputDebugString("sText");
#endif
BYTE byteval1 = (x > 0) ? *(g_pHiresBank0+offset+yoffset-1) : 0;
BYTE byteval2 = *(g_pHiresBank0+offset+yoffset);
BYTE byteval3 = (x < 39) ? *(g_pHiresBank0+offset+yoffset+1) : 0;
if ((byteval2 != *(vidlastmem+offset+yoffset+0x2000)) ||
((x > 0) && ((byteval1 & 0x60) != (*(vidlastmem+offset+yoffset+0x1FFF) & 0x60))) ||
((x < 39) && ((byteval3 & 0x03) != (*(vidlastmem+offset+yoffset+0x2001) & 0x03))) ||
g_VideoForceFullRedraw)
{
#define COLOFFS (((byteval1 & 0x60) << 2) | \ #define COLOFFS (((byteval1 & 0x60) << 2) | \
((byteval3 & 0x03) << 5)) ((byteval3 & 0x03) << 5))
if (g_eVideoType == VT_COLOR_TVEMU) if (g_eVideoType == VT_COLOR_TVEMU)
{ {
CopyMixedSource(xpixel >> 1, (ypixel+(yoffset >> 9)) >> 1, CopyMixedSource(
SRCOFFS_HIRES+COLOFFS+((x & 1) << 4),(((int)byteval2) << 1)); xpixel >> 1, (ypixel+(yoffset >> 9)) >> 1,
} SRCOFFS_HIRES+COLOFFS+((x & 1) << 4), (((int)byteval2) << 1)
else );
{ }
CopySource(xpixel,ypixel+(yoffset >> 9), else
14,2, {
SRCOFFS_HIRES+COLOFFS+((x & 1) << 4),(((int)byteval2) << 1)); CopySource(
} xpixel, ypixel+(yoffset >> 9),
14, 2, // 2x upscale: 280x192 -> 560x384
SRCOFFS_HIRES+COLOFFS+((x & 1) << 4), (((int)byteval2) << 1)
);
}
#undef COLOFFS #undef COLOFFS
bDirty = true; bDirty = true;
} }
yoffset += 0x400; yoffset += 0x400;
} }
return bDirty; return bDirty;
} }
@ -2179,7 +2203,7 @@ void _Video_RedrawScreen( VideoUpdateFuncPtr_t pfUpdate, bool bMixed )
for( int y = 1; y < FRAMEBUFFER_H; y += 2 ) for( int y = 1; y < FRAMEBUFFER_H; y += 2 )
{ {
unsigned char *pSrc = pSrc = frameoffsettable[y]; unsigned char *pSrc = pSrc = g_aFrameBufferOffset[y];
for( int x = 0; x < FRAMEBUFFER_W; x++ ) for( int x = 0; x < FRAMEBUFFER_W; x++ )
{ {
*pSrc++ = 0; *pSrc++ = 0;