diff --git a/src/win32/Direct3D.cpp b/src/win32/Direct3D.cpp index 115e6e65..be3dd016 100644 --- a/src/win32/Direct3D.cpp +++ b/src/win32/Direct3D.cpp @@ -353,25 +353,43 @@ void Direct3DDisplay::render() DXTRACE_ERR_MSGBOX( _T("Can not lock texture"), hr ); return; } else { - if( !theApp.filterFunction ) { - copyImage( - pix, - lr.pBits, - (systemColorDepth == 32) ? theApp.sizeX - : theApp.sizeX + 1, // TODO: workaround results in one pixel black border at right side - theApp.sizeY, - lr.Pitch, - systemColorDepth - ); - } else { - u32 pitch = theApp.filterWidth * (systemColorDepth>>3) + 4; - theApp.filterFunction( pix + pitch, + unsigned short pitch = theApp.sizeX * ( systemColorDepth >> 3 ) + 4; + if( theApp.filterFunction ) { + // pixel filter enabled + theApp.filterFunction( + pix + pitch, pitch, (u8*)theApp.delta, (u8*)lr.pBits, lr.Pitch, - theApp.filterWidth, - theApp.filterHeight); + theApp.sizeX, + theApp.sizeY + ); + } else { + // pixel filter disabled + switch( systemColorDepth ) + { + case 32: + cpyImg32( + (unsigned char *)lr.pBits, + lr.Pitch, + pix + pitch, + pitch, + theApp.sizeX, + theApp.sizeY + ); + break; + case 16: + cpyImg16( + (unsigned char *)lr.pBits, + lr.Pitch, + pix + pitch, + pitch, + theApp.sizeX, + theApp.sizeY + ); + break; + } } emulatedImage->UnlockRect( 0 ); } diff --git a/src/win32/DirectDraw.cpp b/src/win32/DirectDraw.cpp index 3789d4e8..d97f351d 100644 --- a/src/win32/DirectDraw.cpp +++ b/src/win32/DirectDraw.cpp @@ -569,7 +569,7 @@ void DirectDrawDisplay::render() if(hret == DD_OK) { hret = ddsOffscreen->Restore(); - if(hret == DD_OK) { + if(hret == DD_OK) { hret = ddsOffscreen->Lock(NULL, &ddsDesc, DDLOCK_WRITEONLY| @@ -580,46 +580,49 @@ void DirectDrawDisplay::render() NULL); } - } + } } if(hret == DD_OK) { - if(theApp.filterFunction) { - if(systemColorDepth == 16) - (*theApp.filterFunction)(pix+theApp.filterWidth*2+4, - theApp.filterWidth*2+4, - (u8*)theApp.delta, - (u8*)ddsDesc.lpSurface, - ddsDesc.lPitch, - theApp.filterWidth, - theApp.filterHeight); - else - (*theApp.filterFunction)(pix+theApp.filterWidth*4+4, - theApp.filterWidth*4+4, - (u8*)theApp.delta, - (u8*)ddsDesc.lpSurface, - ddsDesc.lPitch, - theApp.filterWidth, - theApp.filterHeight); - - } else { - int copyX = 240; - int copyY = 160; - - if(theApp.cartridgeType == 1) { - if(gbBorderOn) { - copyX = 256; - copyY = 224; - } else { - copyX = 160; - copyY = 144; - } - } - if( systemColorDepth == 16 ) { - copyX++; // TODO: workaround results in one pixel black border at right side + unsigned short pitch = theApp.sizeX * ( systemColorDepth >> 3 ) + 4; + if( theApp.filterFunction ) { + // pixel filter enabled + theApp.filterFunction( + pix + pitch, + pitch, + (u8*)theApp.delta, + (u8*)ddsDesc.lpSurface, + ddsDesc.lPitch, + theApp.sizeX, + theApp.sizeY + ); + } else { + // pixel filter disabled + switch( systemColorDepth ) + { + case 32: + cpyImg32( + (unsigned char *)ddsDesc.lpSurface, + ddsDesc.lPitch, + pix + pitch, + pitch, + theApp.sizeX, + theApp.sizeY + ); + break; + case 16: + cpyImg16( + (unsigned char *)ddsDesc.lpSurface, + ddsDesc.lPitch, + pix + pitch, + pitch, + theApp.sizeX, + theApp.sizeY + ); + break; + } } - copyImage( pix, ddsDesc.lpSurface, copyX, copyY, ddsDesc.lPitch, systemColorDepth ); - } + if(theApp.showSpeed && (theApp.videoOption > VIDEO_4X || theApp.skin != NULL)) { char buffer[30]; if(theApp.showSpeed == 1) diff --git a/src/win32/Display.h b/src/win32/Display.h index f0b353f4..894623c0 100644 --- a/src/win32/Display.h +++ b/src/win32/Display.h @@ -19,6 +19,8 @@ #pragma once +#include + enum DISPLAY_TYPE { DIRECT_DRAW = 0, DIRECT_3D = 1, @@ -43,46 +45,27 @@ class IDisplay { virtual int selectFullScreenMode(GUID **) = 0; }; -inline void copyImage( void *source, void *destination, unsigned int width, unsigned int height, unsigned int destinationPitch, unsigned int colorDepth ) +inline void cpyImg32( unsigned char *dst, unsigned int dstPitch, unsigned char *src, unsigned int srcPitch, unsigned short width, unsigned short height ) { // fast, iterative C version - register unsigned int lineSize; - register unsigned char *src, *dst; - switch(colorDepth) - { - case 16: - lineSize = width<<1; - src = ((unsigned char*)source) + lineSize + 4; - dst = (unsigned char*)destination; - do { - MoveMemory( dst, src, lineSize ); - src+=lineSize; - dst+=lineSize; - src += 2; - dst += (destinationPitch - lineSize); - } while ( --height); - break; - case 32: - lineSize = width<<2; - src = ((unsigned char*)source) + lineSize + 4; - dst = (unsigned char*)destination; - do { - MoveMemory( dst, src, lineSize ); - src+=lineSize; - dst+=lineSize; - src += 4; - dst += (destinationPitch - lineSize); - } while ( --height); - break; - } + // copies an width*height array of visible pixels from src to dst + // srcPitch and dstPitch are the number of garbage bytes after a scanline + register unsigned short lineSize = width<<2; - // compact but slow C version - //unsigned int nBytesPerPixel = colorDepth>>3; - //unsigned int i, x, y, srcPitch = (width+1) * nBytesPerPixel; - //unsigned char * src = ((unsigned char*)source)+srcPitch; - //unsigned char * dst = (unsigned char*)destination; - //for (y=0;y