Advmame4x patch ported for ScummVM 1.0.0

All the inane chatter goes in here. If you're curious about whether we will support a game, post HERE not in General Discussion :)

Moderator: ScummVM Team

Post Reply
Tobis87
Posts: 23
Joined: Thu Feb 05, 2009 9:41 pm

Advmame4x patch ported for ScummVM 1.0.0

Post by Tobis87 »

Hi!

Here it is, the unofficial patch for big screens.

Code: Select all

diff -urN backends/platform/sdl/graphics.cpp backends/platform/sdl/graphics.cpp
--- backends/platform/sdl/graphics.cpp	2009-11-07 01:09:32.000000000 +0100
+++ backends/platform/sdl/graphics.cpp	2009-11-17 19:17:19.423331167 +0100
@@ -35,11 +35,13 @@
 	{"1x", "Normal (no scaling)", GFX_NORMAL},
 	{"2x", "2x", GFX_DOUBLESIZE},
 	{"3x", "3x", GFX_TRIPLESIZE},
+	{"4x", "4x", GFX_QUADSIZE},
 	{"2xsai", "2xSAI", GFX_2XSAI},
 	{"super2xsai", "Super2xSAI", GFX_SUPER2XSAI},
 	{"supereagle", "SuperEagle", GFX_SUPEREAGLE},
 	{"advmame2x", "AdvMAME2x", GFX_ADVMAME2X},
 	{"advmame3x", "AdvMAME3x", GFX_ADVMAME3X},
+	{"advmame4x", "AdvMAME4x", GFX_ADVMAME4X},
 #ifndef DISABLE_HQ_SCALERS
 	{"hq2x", "HQ2x", GFX_HQ2X},
 	{"hq3x", "HQ3x", GFX_HQ3X},
@@ -51,27 +53,29 @@
 
 // Table of relative scalers magnitudes
 // [definedScale - 1][scaleFactor - 1]
-static ScalerProc *scalersMagn[3][3] = {
+static ScalerProc *scalersMagn[4][4] = {
 #ifndef DISABLE_SCALERS
-	{ Normal1x, AdvMame2x, AdvMame3x },
-	{ Normal1x, Normal1x, Normal1o5x },
-	{ Normal1x, Normal1x, Normal1x }
+	{ Normal1x, AdvMame2x, AdvMame3x, AdvMame4x },
+	{ Normal1x, Normal1x, Normal1o5x, AdvMame2x },
+	{ Normal1x, Normal1x, Normal1x, Normal1x },
+	{ Normal1x, Normal1x, Normal1x, Normal1x }
 #else // remove dependencies on other scalers
-	{ Normal1x, Normal1x, Normal1x },
-	{ Normal1x, Normal1x, Normal1x },
-	{ Normal1x, Normal1x, Normal1x }
+	{ Normal1x, Normal1x, Normal1x, Normal1x },
+	{ Normal1x, Normal1x, Normal1x, Normal1x },
+	{ Normal1x, Normal1x, Normal1x, Normal1x },
+	{ Normal1x, Normal1x, Normal1x, Normal1x }
 #endif
 };
 
-static const int s_gfxModeSwitchTable[][4] = {
-		{ GFX_NORMAL, GFX_DOUBLESIZE, GFX_TRIPLESIZE, -1 },
-		{ GFX_NORMAL, GFX_ADVMAME2X, GFX_ADVMAME3X, -1 },
-		{ GFX_NORMAL, GFX_HQ2X, GFX_HQ3X, -1 },
-		{ GFX_NORMAL, GFX_2XSAI, -1, -1 },
-		{ GFX_NORMAL, GFX_SUPER2XSAI, -1, -1 },
-		{ GFX_NORMAL, GFX_SUPEREAGLE, -1, -1 },
-		{ GFX_NORMAL, GFX_TV2X, -1, -1 },
-		{ GFX_NORMAL, GFX_DOTMATRIX, -1, -1 }
+static const int s_gfxModeSwitchTable[][5] = {
+		{ GFX_NORMAL, GFX_DOUBLESIZE, GFX_TRIPLESIZE, GFX_QUADSIZE, -1 },
+		{ GFX_NORMAL, GFX_ADVMAME2X, GFX_ADVMAME3X, GFX_ADVMAME4X, -1 },
+		{ GFX_NORMAL, GFX_HQ2X, GFX_HQ3X, -1, -1 },
+		{ GFX_NORMAL, GFX_2XSAI, -1, -1, -1 },
+		{ GFX_NORMAL, GFX_SUPER2XSAI, -1, -1, -1 },
+		{ GFX_NORMAL, GFX_SUPEREAGLE, -1, -1, -1 },
+		{ GFX_NORMAL, GFX_TV2X, -1, -1, -1 },
+		{ GFX_NORMAL, GFX_DOTMATRIX, -1, -1, -1 },
 	};
 
 #ifndef DISABLE_SCALERS
@@ -213,7 +217,10 @@
 	case GFX_TRIPLESIZE:
 		newScaleFactor = 3;
 		break;
-
+	case GFX_QUADSIZE:
+		newScaleFactor = 4;
+		break;
+		
 	case GFX_2XSAI:
 		newScaleFactor = 2;
 		break;
@@ -229,6 +236,9 @@
 	case GFX_ADVMAME3X:
 		newScaleFactor = 3;
 		break;
+	case GFX_ADVMAME4X:
+		newScaleFactor = 4;
+		break;
 #ifndef DISABLE_HQ_SCALERS
 	case GFX_HQ2X:
 		newScaleFactor = 2;
@@ -277,7 +287,10 @@
 	case GFX_TRIPLESIZE:
 		newScalerProc = Normal3x;
 		break;
-
+	case GFX_QUADSIZE:
+		newScalerProc = Normal4x;
+		break;
+		
 	case GFX_2XSAI:
 		newScalerProc = _2xSaI;
 		break;
@@ -293,6 +306,9 @@
 	case GFX_ADVMAME3X:
 		newScalerProc = AdvMame3x;
 		break;
+	case GFX_ADVMAME4X:
+		newScalerProc = AdvMame4x;
+		break;
 #ifndef DISABLE_HQ_SCALERS
 	case GFX_HQ2X:
 		newScalerProc = HQ2x;
@@ -412,7 +428,9 @@
 	//
 
 	// Need some extra bytes around when using 2xSaI
-	_tmpscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.screenWidth + 3, _videoMode.screenHeight + 3,
+	_tmpscreen = SDL_CreateRGBSurface(SDL_SWSURFACE,
+						_videoMode.screenWidth + 2 * MAX_SCALER_REACH,
+						_videoMode.screenHeight + 2 * MAX_SCALER_REACH,
 						16,
 						_hwscreen->format->Rmask,
 						_hwscreen->format->Gmask,
@@ -444,7 +462,9 @@
 	_overlayFormat.bShift = _overlayscreen->format->Bshift;
 	_overlayFormat.aShift = _overlayscreen->format->Ashift;
 
-	_tmpscreen2 = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.overlayWidth + 3, _videoMode.overlayHeight + 3,
+	_tmpscreen2 = SDL_CreateRGBSurface(SDL_SWSURFACE,
+						_videoMode.overlayWidth + 2 * MAX_SCALER_REACH,
+						_videoMode.overlayHeight + 2 * MAX_SCALER_REACH,
 						16,
 						_hwscreen->format->Rmask,
 						_hwscreen->format->Gmask,
@@ -675,8 +695,8 @@
 
 		for (r = _dirtyRectList; r != lastRect; ++r) {
 			dst = *r;
-			dst.x++;	// Shift rect by one since 2xSai needs to access the data around
-			dst.y++;	// any pixel to scale it, and we want to avoid mem access crashes.
+ 			dst.x += MAX_SCALER_REACH;	// Shift rect by one since 2xSai needs to access the data around
+ 			dst.y += MAX_SCALER_REACH;	// any pixel to scale it, and we want to avoid mem access crashes.
 
 			if (SDL_BlitSurface(origSurf, r, srcSurf, &dst) != 0)
 				error("SDL_BlitSurface failed: %s", SDL_GetError());
@@ -706,7 +726,7 @@
 					dst_y = real2Aspect(dst_y);
 
 				assert(scalerProc != NULL);
-				scalerProc((byte *)srcSurf->pixels + (r->x * 2 + 2) + (r->y + 1) * srcPitch, srcPitch,
+				scalerProc((byte *)srcSurf->pixels + (r->x * 2 + 2 * MAX_SCALER_REACH) + (r->y + MAX_SCALER_REACH) * srcPitch, srcPitch,
 						   (byte *)_hwscreen->pixels + rx1 * 2 + dst_y * dstPitch, dstPitch, r->w, dst_h);
 			}
 
@@ -1331,8 +1351,8 @@
 
 		// Allocate bigger surface because AdvMame2x adds black pixel at [0,0]
 		_mouseOrigSurface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA,
-						_mouseCurState.w + 2,
-						_mouseCurState.h + 2,
+ 						_mouseCurState.w + 2 * MAX_SCALER_REACH,
+ 						_mouseCurState.h + 2 * MAX_SCALER_REACH,
 						16,
 						_hwscreen->format->Rmask,
 						_hwscreen->format->Gmask,
@@ -1368,16 +1388,16 @@
 	SDL_LockSurface(_mouseOrigSurface);
 
 	// Make whole surface transparent
-	for &#40;i = 0; i < h + 2; i++&#41; &#123;
+	for &#40;i = 0; i < h + 2 * MAX_SCALER_REACH; i++&#41; &#123;
 		dstPtr = &#40;byte *&#41;_mouseOrigSurface->pixels + _mouseOrigSurface->pitch * i;
-		for &#40;j = 0; j < w + 2; j++&#41; &#123;
+		for &#40;j = 0; j < w + 2 * MAX_SCALER_REACH; j++&#41; &#123;
 			*&#40;uint16 *&#41;dstPtr = kMouseColorKey;
 			dstPtr += 2;
 		&#125;
 	&#125;
 
 	// Draw from &#91;1,1&#93; since AdvMame2x adds artefact at 0,0
-	dstPtr = &#40;byte *&#41;_mouseOrigSurface->pixels + _mouseOrigSurface->pitch + 2;
+	dstPtr = &#40;byte *&#41;_mouseOrigSurface->pixels + &#40;_mouseOrigSurface->pitch + 2&#41; * MAX_SCALER_REACH;
 
 	SDL_Color *palette;
 
@@ -1479,12 +1499,12 @@
 	// the game. This only works well with the non-blurring scalers so we
 	// actually only use the 1x, 1.5x, 2x and AdvMame scalers.
 
-	if &#40;_cursorTargetScale == 1 && &#40;_videoMode.mode == GFX_DOUBLESIZE || _videoMode.mode == GFX_TRIPLESIZE&#41;&#41;
+	if &#40;_cursorTargetScale == 1 && &#40;_videoMode.mode == GFX_DOUBLESIZE || _videoMode.mode == GFX_TRIPLESIZE || _videoMode.mode == GFX_QUADSIZE&#41;&#41;
 		scalerProc = _scalerProc;
 	else
 		scalerProc = scalersMagn&#91;_cursorTargetScale - 1&#93;&#91;_videoMode.scaleFactor - 1&#93;;
 
-	scalerProc&#40;&#40;byte *&#41;_mouseOrigSurface->pixels + _mouseOrigSurface->pitch + 2,
+	scalerProc&#40;&#40;byte *&#41;_mouseOrigSurface->pixels + &#40;_mouseOrigSurface->pitch + 2&#41; * MAX_SCALER_REACH,
 		_mouseOrigSurface->pitch, &#40;byte *&#41;_mouseSurface->pixels, _mouseSurface->pitch,
 		_mouseCurState.w, _mouseCurState.h&#41;;
 
diff -urN backends/platform/sdl/sdl.h backends/platform/sdl/sdl.h
--- backends/platform/sdl/sdl.h	2009-11-07 01&#58;09&#58;32.000000000 +0100
+++ backends/platform/sdl/sdl.h	2009-11-17 19&#58;17&#58;19.423331167 +0100
@@ -59,15 +59,17 @@
 	GFX_NORMAL = 0,
 	GFX_DOUBLESIZE = 1,
 	GFX_TRIPLESIZE = 2,
-	GFX_2XSAI = 3,
-	GFX_SUPER2XSAI = 4,
-	GFX_SUPEREAGLE = 5,
-	GFX_ADVMAME2X = 6,
-	GFX_ADVMAME3X = 7,
-	GFX_HQ2X = 8,
-	GFX_HQ3X = 9,
-	GFX_TV2X = 10,
-	GFX_DOTMATRIX = 11
+	GFX_QUADSIZE = 3,
+	GFX_2XSAI = 4,
+	GFX_SUPER2XSAI = 5,
+	GFX_SUPEREAGLE = 6,
+	GFX_ADVMAME2X = 7,
+	GFX_ADVMAME3X = 8,
+	GFX_ADVMAME4X = 9,
+	GFX_HQ2X = 10,
+	GFX_HQ3X = 11,
+	GFX_TV2X = 12,
+	GFX_DOTMATRIX = 13
 &#125;;
 
 
@@ -297,7 +299,7 @@
 
 	enum &#123;
 		NUM_DIRTY_RECT = 100,
-		MAX_SCALING = 3
+		MAX_SCALING = 4
 	&#125;;
 
 	// Dirty rect management

diff -urN base/commandLine.cpp base/commandLine.cpp
--- base/commandLine.cpp	2009-11-07 01&#58;09&#58;23.000000000 +0100
+++ base/commandLine.cpp	2009-11-17 19&#58;17&#58;19.424331140 +0100
@@ -68,9 +68,9 @@
 	"  -x, --save-slot&#91;=NUM&#93;    Save game slot to load &#40;default&#58; autosave&#41;\n"
 	"  -f, --fullscreen         Force full-screen mode\n"
 	"  -F, --no-fullscreen      Force windowed mode\n"
-	"  -g, --gfx-mode=MODE      Select graphics scaler &#40;1x,2x,3x,2xsai,super2xsai,\n"
-	"                           supereagle,advmame2x,advmame3x,hq2x,hq3x,tv2x,\n"
-	"                           dotmatrix&#41;\n"
+	"  -g, --gfx-mode=MODE      Select graphics scaler &#40;1x,2x,3x,4x,2xsai,super2xsai,\n"
+	"                           supereagle,advmame2x,advmame3x,advmame4x,hq2x,hq3x,\n"
+	"                           tv2x,dotmatrix&#41;\n"
 	"  --gui-theme=THEME        Select GUI theme\n"
 	"  --themepath=PATH         Path to where GUI themes are stored\n"
 	"  --list-themes            Display list of all usable GUI themes\n"
diff -urN graphics/scaler/scalebit.cpp graphics/scaler/scalebit.cpp
--- graphics/scaler/scalebit.cpp	2009-11-07 01&#58;09&#58;21.000000000 +0100
+++ graphics/scaler/scalebit.cpp	2009-11-17 19&#58;17&#58;19.424331140 +0100
@@ -196,8 +196,6 @@
 	unsigned count;
 	unsigned char* mid&#91;6&#93;;
 
-	assert&#40;height >= 4&#41;;
-
 	count = height;
 
 	/* set the 6 buffer pointers */
@@ -208,11 +206,14 @@
 	mid&#91;4&#93; = mid&#91;3&#93; + mid_slice;
 	mid&#91;5&#93; = mid&#91;4&#93; + mid_slice;
 
+	stage_scale2x&#40;SCMID&#40;0&#41;, SCMID&#40;1&#41;, SCSRC&#40;0&#41; - pixel, SCSRC&#40;1&#41; - pixel, SCSRC&#40;2&#41; - pixel, pixel, width + 2&#41;;
+	stage_scale2x&#40;SCMID&#40;2&#41;, SCMID&#40;3&#41;, SCSRC&#40;1&#41; - pixel, SCSRC&#40;2&#41; - pixel, SCSRC&#40;3&#41; - pixel, pixel, width + 2&#41;;
+
 	while &#40;count&#41; &#123;
 		unsigned char* tmp;
 
-		stage_scale2x&#40;SCMID&#40;4&#41;, SCMID&#40;5&#41;, SCSRC&#40;2&#41;, SCSRC&#40;3&#41;, SCSRC&#40;4&#41;, pixel, width&#41;;
-		stage_scale4x&#40;SCDST&#40;0&#41;, SCDST&#40;1&#41;, SCDST&#40;2&#41;, SCDST&#40;3&#41;, SCMID&#40;1&#41;, SCMID&#40;2&#41;, SCMID&#40;3&#41;, SCMID&#40;4&#41;, pixel, width&#41;;
+		stage_scale2x&#40;SCMID&#40;4&#41;, SCMID&#40;5&#41;, SCSRC&#40;2&#41; - pixel, SCSRC&#40;3&#41; - pixel, SCSRC&#40;4&#41; - pixel, pixel, width + 2&#41;;
+		stage_scale4x&#40;SCDST&#40;0&#41;, SCDST&#40;1&#41;, SCDST&#40;2&#41;, SCDST&#40;3&#41;, SCMID&#40;1&#41; + 2 * pixel, SCMID&#40;2&#41; + 2 * pixel, SCMID&#40;3&#41; + 2 * pixel, SCMID&#40;4&#41; + 2 * pixel, pixel, width&#41;;
 
 		dst = SCDST&#40;4&#41;;
 		src = SCSRC&#40;1&#41;;
@@ -255,7 +256,7 @@
 	unsigned mid_slice;
 	void* mid;
 
-	mid_slice = 2 * pixel * width; /* required space for 1 row buffer */
+	mid_slice = 2 * pixel * &#40;width + 2&#41;; /* required space for 1 row buffer */
 
 	mid_slice = &#40;mid_slice + 0x7&#41; & ~0x7; /* align to 8 bytes */
 
diff -urN graphics/scaler.cpp graphics/scaler.cpp
--- graphics/scaler.cpp	2009-11-07 01&#58;09&#58;21.000000000 +0100
+++ graphics/scaler.cpp	2009-11-17 19&#58;17&#58;19.424331140 +0100
@@ -297,6 +297,41 @@
 	&#125;
 &#125;
 
+ void Normal4x&#40;const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch,
+ 							int width, int height&#41; &#123;
+ 	uint8 *r;
+ 	const uint32 dstPitch2 = dstPitch * 2;
+ 	const uint32 dstPitch3 = dstPitch * 3;
+ 	const uint32 dstPitch4 = dstPitch * 4;
+ 
+	assert&#40;IS_ALIGNED&#40;dstPtr, 2&#41;&#41;;
+ 	while &#40;height--&#41; &#123;
+ 		r = dstPtr;
+ 		for &#40;int i = 0; i < width; ++i, r += 8&#41; &#123;
+ 			uint16 color = *&#40;&#40;&#40;const uint16 *&#41;srcPtr&#41; + i&#41;;
+ 
+ 			*&#40;uint16 *&#41;&#40;r + 0&#41; = color;
+ 			*&#40;uint16 *&#41;&#40;r + 2&#41; = color;
+ 			*&#40;uint16 *&#41;&#40;r + 4&#41; = color;
+ 			*&#40;uint16 *&#41;&#40;r + 6&#41; = color;
+ 			*&#40;uint16 *&#41;&#40;r + 0 + dstPitch&#41; = color;
+ 			*&#40;uint16 *&#41;&#40;r + 2 + dstPitch&#41; = color;
+ 			*&#40;uint16 *&#41;&#40;r + 4 + dstPitch&#41; = color;
+ 			*&#40;uint16 *&#41;&#40;r + 6 + dstPitch&#41; = color;
+ 			*&#40;uint16 *&#41;&#40;r + 0 + dstPitch2&#41; = color;
+ 			*&#40;uint16 *&#41;&#40;r + 2 + dstPitch2&#41; = color;
+ 			*&#40;uint16 *&#41;&#40;r + 4 + dstPitch2&#41; = color;
+ 			*&#40;uint16 *&#41;&#40;r + 6 + dstPitch2&#41; = color;
+ 			*&#40;uint16 *&#41;&#40;r + 0 + dstPitch3&#41; = color;
+ 			*&#40;uint16 *&#41;&#40;r + 2 + dstPitch3&#41; = color;
+ 			*&#40;uint16 *&#41;&#40;r + 4 + dstPitch3&#41; = color;
+ 			*&#40;uint16 *&#41;&#40;r + 6 + dstPitch3&#41; = color;
+ 		&#125;
+ 		srcPtr += srcPitch;
+ 		dstPtr += dstPitch4;
+ 	&#125;
+ &#125;
+ 
 #define interpolate_1_1		interpolate16_1_1<Graphics&#58;&#58;ColorMasks<bitFormat> >
 #define interpolate_1_1_1_1	interpolate16_1_1_1_1<Graphics&#58;&#58;ColorMasks<bitFormat> >
 
@@ -355,6 +390,11 @@
 	scale&#40;3, dstPtr, dstPitch, srcPtr - srcPitch, srcPitch, 2, width, height&#41;;
 &#125;
 
+void AdvMame4x&#40;const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch,
+							 int width, int height&#41; &#123;
+	scale&#40;4, dstPtr, dstPitch, srcPtr - 2 * srcPitch, srcPitch, 2, width, height&#41;;
+&#125;
+
 template<int bitFormat>
 void TV2xTemplate&#40;const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch,
 					int width, int height&#41; &#123;
diff -urN graphics/scaler.h graphics/scaler.h
--- graphics/scaler.h	2009-11-07 01&#58;09&#58;21.000000000 +0100
+++ graphics/scaler.h	2009-11-17 19&#58;17&#58;19.424331140 +0100
@@ -43,12 +43,14 @@
 DECLARE_SCALER&#40;SuperEagle&#41;;
 DECLARE_SCALER&#40;AdvMame2x&#41;;
 DECLARE_SCALER&#40;AdvMame3x&#41;;
+DECLARE_SCALER&#40;AdvMame4x&#41;;
 DECLARE_SCALER&#40;Normal1x&#41;;
 DECLARE_SCALER&#40;Normal2x&#41;;
 #ifdef USE_ARM_SCALER_ASM
 DECLARE_SCALER&#40;Normal2xAspect&#41;;
 #endif
 DECLARE_SCALER&#40;Normal3x&#41;;
+DECLARE_SCALER&#40;Normal4x&#41;;
 DECLARE_SCALER&#40;Normal1o5x&#41;;
 DECLARE_SCALER&#40;TV2x&#41;;
 DECLARE_SCALER&#40;DotMatrix&#41;;
@@ -58,6 +60,8 @@
 DECLARE_SCALER&#40;HQ3x&#41;;
 #endif
 
+#define MAX_SCALER_REACH 2
+
 FORCEINLINE int real2Aspect&#40;int y&#41; &#123;
 	return y + &#40;y + 1&#41; / 5;
 &#125;
User avatar
ezekiel000
Posts: 443
Joined: Mon Aug 25, 2008 5:17 pm
Location: Surrey, England

Post by ezekiel000 »

Tobis87
Posts: 23
Joined: Thu Feb 05, 2009 9:41 pm

Post by Tobis87 »

The patch was already posted there a few years ago and it was rejected, because of the "scaler policy". It shouldn't go into trunk anyway, but instead everyone who is interested can use the patch. It is just the updated version which compiles with Release 1.0.0.
Tobis87
Posts: 23
Joined: Thu Feb 05, 2009 9:41 pm

Post by Tobis87 »

Updated against ScummVM 1.2.0;

Code: Select all

diff -urN scummvm-1.2.0/backends/platform/sdl/graphics.cpp scummvm-1.2.0/backends/platform/sdl/graphics.cpp
--- scummvm-1.2.0/backends/platform/sdl/graphics.cpp    2010-09-06 19&#58;28&#58;17.000000000 +0200
+++ scummvm-1.2.0/backends/platform/sdl/graphics.cpp    2010-10-16 18&#58;48&#58;36.402315325 +0200
@@ -41,11 +41,13 @@
 #ifdef USE_SCALERS
     &#123;"2x", "2x", GFX_DOUBLESIZE&#125;,
     &#123;"3x", "3x", GFX_TRIPLESIZE&#125;,
+    &#123;"4x", "4x", GFX_QUADSIZE&#125;,
     &#123;"2xsai", "2xSAI", GFX_2XSAI&#125;,
     &#123;"super2xsai", "Super2xSAI", GFX_SUPER2XSAI&#125;,
     &#123;"supereagle", "SuperEagle", GFX_SUPEREAGLE&#125;,
     &#123;"advmame2x", "AdvMAME2x", GFX_ADVMAME2X&#125;,
     &#123;"advmame3x", "AdvMAME3x", GFX_ADVMAME3X&#125;,
+    &#123;"advmame4x", "AdvMAME4x", GFX_ADVMAME4X&#125;,
 #ifdef USE_HQ_SCALERS
     &#123;"hq2x", "HQ2x", GFX_HQ2X&#125;,
     &#123;"hq3x", "HQ3x", GFX_HQ3X&#125;,
@@ -60,27 +62,29 @@
 
 // Table of relative scalers magnitudes
 // &#91;definedScale - 1&#93;&#91;scaleFactor - 1&#93;
-static ScalerProc *scalersMagn&#91;3&#93;&#91;3&#93; = &#123;
-#ifdef USE_SCALERS
-    &#123; Normal1x, AdvMame2x, AdvMame3x &#125;,
-    &#123; Normal1x, Normal1x, Normal1o5x &#125;,
-    &#123; Normal1x, Normal1x, Normal1x &#125;
+static ScalerProc *scalersMagn&#91;4&#93;&#91;4&#93; = &#123;
+#ifndef DISABLE_SCALERS
+    &#123; Normal1x, AdvMame2x, AdvMame3x, AdvMame4x &#125;,
+    &#123; Normal1x, Normal1x, Normal1o5x, AdvMame2x &#125;,
+    &#123; Normal1x, Normal1x, Normal1x, Normal1x &#125;,
+    &#123; Normal1x, Normal1x, Normal1x, Normal1x &#125;
 #else // remove dependencies on other scalers
-    &#123; Normal1x, Normal1x, Normal1x &#125;,
-    &#123; Normal1x, Normal1x, Normal1x &#125;,
-    &#123; Normal1x, Normal1x, Normal1x &#125;
+    &#123; Normal1x, Normal1x, Normal1x, Normal1x &#125;,
+    &#123; Normal1x, Normal1x, Normal1x, Normal1x &#125;,
+    &#123; Normal1x, Normal1x, Normal1x, Normal1x &#125;,
+    &#123; Normal1x, Normal1x, Normal1x, Normal1x &#125;
 #endif
 &#125;;
 
-static const int s_gfxModeSwitchTable&#91;&#93;&#91;4&#93; = &#123;
-        &#123; GFX_NORMAL, GFX_DOUBLESIZE, GFX_TRIPLESIZE, -1 &#125;,
-        &#123; GFX_NORMAL, GFX_ADVMAME2X, GFX_ADVMAME3X, -1 &#125;,
-        &#123; GFX_NORMAL, GFX_HQ2X, GFX_HQ3X, -1 &#125;,
-        &#123; GFX_NORMAL, GFX_2XSAI, -1, -1 &#125;,
-        &#123; GFX_NORMAL, GFX_SUPER2XSAI, -1, -1 &#125;,
-        &#123; GFX_NORMAL, GFX_SUPEREAGLE, -1, -1 &#125;,
-        &#123; GFX_NORMAL, GFX_TV2X, -1, -1 &#125;,
-        &#123; GFX_NORMAL, GFX_DOTMATRIX, -1, -1 &#125;
+static const int s_gfxModeSwitchTable&#91;&#93;&#91;5&#93; = &#123;
+        &#123; GFX_NORMAL, GFX_DOUBLESIZE, GFX_TRIPLESIZE, GFX_QUADSIZE, -1 &#125;,
+        &#123; GFX_NORMAL, GFX_ADVMAME2X, GFX_ADVMAME3X, GFX_ADVMAME4X, -1 &#125;,
+        &#123; GFX_NORMAL, GFX_HQ2X, GFX_HQ3X, -1, -1 &#125;,
+        &#123; GFX_NORMAL, GFX_2XSAI, -1, -1, -1 &#125;,
+        &#123; GFX_NORMAL, GFX_SUPER2XSAI, -1, -1, -1 &#125;,
+        &#123; GFX_NORMAL, GFX_SUPEREAGLE, -1, -1, -1 &#125;,
+        &#123; GFX_NORMAL, GFX_TV2X, -1, -1, -1 &#125;,
+        &#123; GFX_NORMAL, GFX_DOTMATRIX, -1, -1, -1 &#125;,
     &#125;;
 
 #ifdef USE_SCALERS
@@ -328,7 +332,10 @@
     case GFX_TRIPLESIZE&#58;
         newScaleFactor = 3;
         break;
-
+    case GFX_QUADSIZE&#58;
+        newScaleFactor = 4;
+        break;
+        
     case GFX_2XSAI&#58;
         newScaleFactor = 2;
         break;
@@ -344,6 +351,9 @@
     case GFX_ADVMAME3X&#58;
         newScaleFactor = 3;
         break;
+    case GFX_ADVMAME4X&#58;
+        newScaleFactor = 4;
+        break;
 #ifdef USE_HQ_SCALERS
     case GFX_HQ2X&#58;
         newScaleFactor = 2;
@@ -392,7 +402,10 @@
     case GFX_TRIPLESIZE&#58;
         newScalerProc = Normal3x;
         break;
-
+    case GFX_QUADSIZE&#58;
+        newScalerProc = Normal4x;
+        break;
+        
     case GFX_2XSAI&#58;
         newScalerProc = _2xSaI;
         break;
@@ -408,6 +421,9 @@
     case GFX_ADVMAME3X&#58;
         newScalerProc = AdvMame3x;
         break;
+    case GFX_ADVMAME4X&#58;
+        newScalerProc = AdvMame4x;
+        break;
 #ifdef USE_HQ_SCALERS
     case GFX_HQ2X&#58;
         newScalerProc = HQ2x;
@@ -607,7 +623,9 @@
     //
 
     // Need some extra bytes around when using 2xSaI
-    _tmpscreen = SDL_CreateRGBSurface&#40;SDL_SWSURFACE, _videoMode.screenWidth + 3, _videoMode.screenHeight + 3,
+    _tmpscreen = SDL_CreateRGBSurface&#40;SDL_SWSURFACE,
+                        _videoMode.screenWidth + 2 * MAX_SCALER_REACH,
+                        _videoMode.screenHeight + 2 * MAX_SCALER_REACH,
                         16,
                         _hwscreen->format->Rmask,
                         _hwscreen->format->Gmask,
@@ -639,7 +657,9 @@
     _overlayFormat.bShift = _overlayscreen->format->Bshift;
     _overlayFormat.aShift = _overlayscreen->format->Ashift;
 
-    _tmpscreen2 = SDL_CreateRGBSurface&#40;SDL_SWSURFACE, _videoMode.overlayWidth + 3, _videoMode.overlayHeight + 3,
+    _tmpscreen2 = SDL_CreateRGBSurface&#40;SDL_SWSURFACE,
+                        _videoMode.overlayWidth + 2 * MAX_SCALER_REACH,
+                        _videoMode.overlayHeight + 2 * MAX_SCALER_REACH,
                         16,
                         _hwscreen->format->Rmask,
                         _hwscreen->format->Gmask,
@@ -871,8 +891,8 @@
 
         for &#40;r = _dirtyRectList; r != lastRect; ++r&#41; &#123;
             dst = *r;
-            dst.x++;    // Shift rect by one since 2xSai needs to access the data around
-            dst.y++;    // any pixel to scale it, and we want to avoid mem access crashes.
+             dst.x += MAX_SCALER_REACH;    // Shift rect by one since 2xSai needs to access the data around
+             dst.y += MAX_SCALER_REACH;    // any pixel to scale it, and we want to avoid mem access crashes.
 
             if &#40;SDL_BlitSurface&#40;origSurf, r, srcSurf, &dst&#41; != 0&#41;
                 error&#40;"SDL_BlitSurface failed&#58; %s", SDL_GetError&#40;&#41;&#41;;
@@ -902,7 +922,7 @@
                     dst_y = real2Aspect&#40;dst_y&#41;;
 
                 assert&#40;scalerProc != NULL&#41;;
-                scalerProc&#40;&#40;byte *&#41;srcSurf->pixels + &#40;r->x * 2 + 2&#41; + &#40;r->y + 1&#41; * srcPitch, srcPitch,
+                scalerProc&#40;&#40;byte *&#41;srcSurf->pixels + &#40;r->x * 2 + 2 * MAX_SCALER_REACH&#41; + &#40;r->y + MAX_SCALER_REACH&#41; * srcPitch, srcPitch,
                            &#40;byte *&#41;_hwscreen->pixels + rx1 * 2 + dst_y * dstPitch, dstPitch, r->w, dst_h&#41;;
             &#125;
 
@@ -1453,8 +1473,8 @@
 
         // Allocate bigger surface because AdvMame2x adds black pixel at &#91;0,0&#93;
         _mouseOrigSurface = SDL_CreateRGBSurface&#40;SDL_SWSURFACE | SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA,
-                        _mouseCurState.w + 2,
-                        _mouseCurState.h + 2,
+                         _mouseCurState.w + 2 * MAX_SCALER_REACH,
+                         _mouseCurState.h + 2 * MAX_SCALER_REACH,
                         16,
                         _hwscreen->format->Rmask,
                         _hwscreen->format->Gmask,
@@ -1499,16 +1519,16 @@
     SDL_LockSurface&#40;_mouseOrigSurface&#41;;
 
     // Make whole surface transparent
-    for &#40;i = 0; i < h + 2; i++&#41; &#123;
+    for &#40;i = 0; i < h + 2 * MAX_SCALER_REACH; i++&#41; &#123;
         dstPtr = &#40;byte *&#41;_mouseOrigSurface->pixels + _mouseOrigSurface->pitch * i;
-        for &#40;j = 0; j < w + 2; j++&#41; &#123;
+        for &#40;j = 0; j < w + 2 * MAX_SCALER_REACH; j++&#41; &#123;
             *&#40;uint16 *&#41;dstPtr = kMouseColorKey;
             dstPtr += 2;
         &#125;
     &#125;
 
     // Draw from &#91;1,1&#93; since AdvMame2x adds artefact at 0,0
-    dstPtr = &#40;byte *&#41;_mouseOrigSurface->pixels + _mouseOrigSurface->pitch + 2;
+    dstPtr = &#40;byte *&#41;_mouseOrigSurface->pixels + &#40;_mouseOrigSurface->pitch + 2&#41; * MAX_SCALER_REACH;
 
     SDL_Color *palette;
 
@@ -1629,12 +1649,12 @@
     // the game. This only works well with the non-blurring scalers so we
     // actually only use the 1x, 1.5x, 2x and AdvMame scalers.
 
-    if &#40;_cursorTargetScale == 1 && &#40;_videoMode.mode == GFX_DOUBLESIZE || _videoMode.mode == GFX_TRIPLESIZE&#41;&#41;
+    if &#40;_cursorTargetScale == 1 && &#40;_videoMode.mode == GFX_DOUBLESIZE || _videoMode.mode == GFX_TRIPLESIZE || _videoMode.mode == GFX_QUADSIZE&#41;&#41;
         scalerProc = _scalerProc;
     else
         scalerProc = scalersMagn&#91;_cursorTargetScale - 1&#93;&#91;_videoMode.scaleFactor - 1&#93;;
 
-    scalerProc&#40;&#40;byte *&#41;_mouseOrigSurface->pixels + _mouseOrigSurface->pitch + 2,
+    scalerProc&#40;&#40;byte *&#41;_mouseOrigSurface->pixels + &#40;_mouseOrigSurface->pitch + 2&#41; * MAX_SCALER_REACH,
         _mouseOrigSurface->pitch, &#40;byte *&#41;_mouseSurface->pixels, _mouseSurface->pitch,
         _mouseCurState.w, _mouseCurState.h&#41;;
 
diff -urN scummvm-1.2.0/backends/platform/sdl/sdl.h scummvm-1.2.0/backends/platform/sdl/sdl.h
--- scummvm-1.2.0/backends/platform/sdl/sdl.h    2010-07-13 01&#58;18&#58;44.000000000 +0200
+++ scummvm-1.2.0/backends/platform/sdl/sdl.h    2010-10-16 18&#58;48&#58;36.402315325 +0200
@@ -59,15 +59,17 @@
     GFX_NORMAL = 0,
     GFX_DOUBLESIZE = 1,
     GFX_TRIPLESIZE = 2,
-    GFX_2XSAI = 3,
-    GFX_SUPER2XSAI = 4,
-    GFX_SUPEREAGLE = 5,
-    GFX_ADVMAME2X = 6,
-    GFX_ADVMAME3X = 7,
-    GFX_HQ2X = 8,
-    GFX_HQ3X = 9,
-    GFX_TV2X = 10,
-    GFX_DOTMATRIX = 11
+    GFX_QUADSIZE = 3,
+    GFX_2XSAI = 4,
+    GFX_SUPER2XSAI = 5,
+    GFX_SUPEREAGLE = 6,
+    GFX_ADVMAME2X = 7,
+    GFX_ADVMAME3X = 8,
+    GFX_ADVMAME4X = 9,
+    GFX_HQ2X = 10,
+    GFX_HQ3X = 11,
+    GFX_TV2X = 12,
+    GFX_DOTMATRIX = 13
 &#125;;
 
 class AspectRatio &#123;
@@ -350,7 +352,7 @@
 
     enum &#123;
         NUM_DIRTY_RECT = 100,
-        MAX_SCALING = 3
+        MAX_SCALING = 4
     &#125;;
 
     // Dirty rect management
diff -urN scummvm-1.2.0/base/commandLine.cpp scummvm-1.2.0/base/commandLine.cpp
--- scummvm-1.2.0/base/commandLine.cpp    2010-10-05 00&#58;42&#58;28.000000000 +0200
+++ scummvm-1.2.0/base/commandLine.cpp    2010-10-16 18&#58;48&#58;36.402315325 +0200
@@ -66,9 +66,9 @@
     "  -x, --save-slot&#91;=NUM&#93;    Save game slot to load &#40;default&#58; autosave&#41;\n"
     "  -f, --fullscreen         Force full-screen mode\n"
     "  -F, --no-fullscreen      Force windowed mode\n"
-    "  -g, --gfx-mode=MODE      Select graphics scaler &#40;1x,2x,3x,2xsai,super2xsai,\n"
-    "                           supereagle,advmame2x,advmame3x,hq2x,hq3x,tv2x,\n"
-    "                           dotmatrix&#41;\n"
+    "  -g, --gfx-mode=MODE      Select graphics scaler &#40;1x,2x,3x,4x,2xsai,super2xsai,\n"
+    "                           supereagle,advmame2x,advmame3x,advmame4x,hq2x,hq3x,\n"
+    "                           tv2x,dotmatrix&#41;\n"
     "  --gui-theme=THEME        Select GUI theme\n"
     "  --themepath=PATH         Path to where GUI themes are stored\n"
     "  --list-themes            Display list of all usable GUI themes\n"
diff -urN scummvm-1.2.0/graphics/scaler/scalebit.cpp scummvm-1.2.0/graphics/scaler/scalebit.cpp
--- scummvm-1.2.0/graphics/scaler/scalebit.cpp    2009-07-30 11&#58;36&#58;50.000000000 +0200
+++ scummvm-1.2.0/graphics/scaler/scalebit.cpp    2010-10-16 18&#58;48&#58;36.403315298 +0200
@@ -196,8 +196,6 @@
     unsigned count;
     unsigned char* mid&#91;6&#93;;
 
-    assert&#40;height >= 4&#41;;
-
     count = height;
 
     /* set the 6 buffer pointers */
@@ -208,11 +206,14 @@
     mid&#91;4&#93; = mid&#91;3&#93; + mid_slice;
     mid&#91;5&#93; = mid&#91;4&#93; + mid_slice;
 
+    stage_scale2x&#40;SCMID&#40;0&#41;, SCMID&#40;1&#41;, SCSRC&#40;0&#41; - pixel, SCSRC&#40;1&#41; - pixel, SCSRC&#40;2&#41; - pixel, pixel, width + 2&#41;;
+    stage_scale2x&#40;SCMID&#40;2&#41;, SCMID&#40;3&#41;, SCSRC&#40;1&#41; - pixel, SCSRC&#40;2&#41; - pixel, SCSRC&#40;3&#41; - pixel, pixel, width + 2&#41;;
+
     while &#40;count&#41; &#123;
         unsigned char* tmp;
 
-        stage_scale2x&#40;SCMID&#40;4&#41;, SCMID&#40;5&#41;, SCSRC&#40;2&#41;, SCSRC&#40;3&#41;, SCSRC&#40;4&#41;, pixel, width&#41;;
-        stage_scale4x&#40;SCDST&#40;0&#41;, SCDST&#40;1&#41;, SCDST&#40;2&#41;, SCDST&#40;3&#41;, SCMID&#40;1&#41;, SCMID&#40;2&#41;, SCMID&#40;3&#41;, SCMID&#40;4&#41;, pixel, width&#41;;
+        stage_scale2x&#40;SCMID&#40;4&#41;, SCMID&#40;5&#41;, SCSRC&#40;2&#41; - pixel, SCSRC&#40;3&#41; - pixel, SCSRC&#40;4&#41; - pixel, pixel, width + 2&#41;;
+        stage_scale4x&#40;SCDST&#40;0&#41;, SCDST&#40;1&#41;, SCDST&#40;2&#41;, SCDST&#40;3&#41;, SCMID&#40;1&#41; + 2 * pixel, SCMID&#40;2&#41; + 2 * pixel, SCMID&#40;3&#41; + 2 * pixel, SCMID&#40;4&#41; + 2 * pixel, pixel, width&#41;;
 
         dst = SCDST&#40;4&#41;;
         src = SCSRC&#40;1&#41;;
@@ -255,7 +256,7 @@
     unsigned mid_slice;
     void* mid;
 
-    mid_slice = 2 * pixel * width; /* required space for 1 row buffer */
+    mid_slice = 2 * pixel * &#40;width + 2&#41;; /* required space for 1 row buffer */
 
     mid_slice = &#40;mid_slice + 0x7&#41; & ~0x7; /* align to 8 bytes */
 
diff -urN scummvm-1.2.0/graphics/scaler.cpp scummvm-1.2.0/graphics/scaler.cpp
--- scummvm-1.2.0/graphics/scaler.cpp    2010-05-09 13&#58;00&#58;17.000000000 +0200
+++ scummvm-1.2.0/graphics/scaler.cpp    2010-10-16 18&#58;48&#58;36.403315298 +0200
@@ -253,6 +253,41 @@
     &#125;
 &#125;
 
+void Normal4x&#40;const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch,
+                            int width, int height&#41; &#123;
+    uint8 *r;
+    const uint32 dstPitch2 = dstPitch * 2;
+    const uint32 dstPitch3 = dstPitch * 3;
+    const uint32 dstPitch4 = dstPitch * 4;
+
+    assert&#40;IS_ALIGNED&#40;dstPtr, 2&#41;&#41;;
+    while &#40;height--&#41; &#123;
+        r = dstPtr;
+        for &#40;int i = 0; i < width; ++i, r += 8&#41; &#123;
+            uint16 color = *&#40;&#40;&#40;const uint16 *&#41;srcPtr&#41; + i&#41;;
+
+            *&#40;uint16 *&#41;&#40;r + 0&#41; = color;
+            *&#40;uint16 *&#41;&#40;r + 2&#41; = color;
+            *&#40;uint16 *&#41;&#40;r + 4&#41; = color;
+            *&#40;uint16 *&#41;&#40;r + 6&#41; = color;
+            *&#40;uint16 *&#41;&#40;r + 0 + dstPitch&#41; = color;
+            *&#40;uint16 *&#41;&#40;r + 2 + dstPitch&#41; = color;
+            *&#40;uint16 *&#41;&#40;r + 4 + dstPitch&#41; = color;
+            *&#40;uint16 *&#41;&#40;r + 6 + dstPitch&#41; = color;
+            *&#40;uint16 *&#41;&#40;r + 0 + dstPitch2&#41; = color;
+            *&#40;uint16 *&#41;&#40;r + 2 + dstPitch2&#41; = color;
+            *&#40;uint16 *&#41;&#40;r + 4 + dstPitch2&#41; = color;
+            *&#40;uint16 *&#41;&#40;r + 6 + dstPitch2&#41; = color;
+            *&#40;uint16 *&#41;&#40;r + 0 + dstPitch3&#41; = color;
+            *&#40;uint16 *&#41;&#40;r + 2 + dstPitch3&#41; = color;
+            *&#40;uint16 *&#41;&#40;r + 4 + dstPitch3&#41; = color;
+            *&#40;uint16 *&#41;&#40;r + 6 + dstPitch3&#41; = color;
+        &#125;
+        srcPtr += srcPitch;
+        dstPtr += dstPitch4;
+    &#125;
+&#125;
+
 #define interpolate_1_1        interpolate16_1_1<ColorMask>
 #define interpolate_1_1_1_1    interpolate16_1_1_1_1<ColorMask>
 
@@ -317,6 +352,11 @@
     scale&#40;3, dstPtr, dstPitch, srcPtr - srcPitch, srcPitch, 2, width, height&#41;;
 &#125;
 
+void AdvMame4x&#40;const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch,
+                             int width, int height&#41; &#123;
+    scale&#40;4, dstPtr, dstPitch, srcPtr - 2 * srcPitch, srcPitch, 2, width, height&#41;;
+&#125;
+
 template<typename ColorMask>
 void TV2xTemplate&#40;const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch,
                     int width, int height&#41; &#123;
diff -urN scummvm-1.2.0/graphics/scaler.h scummvm-1.2.0/graphics/scaler.h
--- scummvm-1.2.0/graphics/scaler.h    2010-06-15 14&#58;33&#58;20.000000000 +0200
+++ scummvm-1.2.0/graphics/scaler.h    2010-10-16 18&#58;48&#58;36.403315298 +0200
@@ -45,6 +45,7 @@
 
 DECLARE_SCALER&#40;Normal2x&#41;;
 DECLARE_SCALER&#40;Normal3x&#41;;
+DECLARE_SCALER&#40;Normal4x&#41;;
 DECLARE_SCALER&#40;Normal1o5x&#41;;
 
 DECLARE_SCALER&#40;_2xSaI&#41;;
@@ -53,6 +54,7 @@
 
 DECLARE_SCALER&#40;AdvMame2x&#41;;
 DECLARE_SCALER&#40;AdvMame3x&#41;;
+DECLARE_SCALER&#40;AdvMame4x&#41;;
 
 DECLARE_SCALER&#40;TV2x&#41;;
 DECLARE_SCALER&#40;DotMatrix&#41;;
@@ -62,6 +64,8 @@
 DECLARE_SCALER&#40;HQ3x&#41;;
 #endif
 
+#define MAX_SCALER_REACH 2
+
 #endif // #ifdef USE_SCALERS
 
 // creates a 160x100 thumbnail for 320x200 games
Post Reply