[Scummvm-cvs-logs] scummvm master -> 4372bd830608f8617fc005713f4ab75774b32462

dreammaster dreammaster at scummvm.org
Sun Mar 17 16:31:26 CET 2013


This automated email contains information about 22 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
317bd9ebd0 HOPKINS: Beginnings of implementing dirty rect support
54924de6cb HOPKINS: Home-screen now displaying correctly with dirty rects
c3bab0aecb HOPKINS: Cleaned up the addDirtyRect method
d738802bc1 HOPKINS: Converted dirty rects to use Common::Array
7c862d586e HOPKINS: Preparatory work for a refresh rect list
95aca78bcd HOPKINS: Renamed dirty rect methods
9d8eb97840 HOPKINS: Hooked up display code for refresh rects
77eb6f74eb HOPKINS: Fix to not display dirty rects that are off-screen
7a7b2b35e2 HOPKINS: Added a debugger command to frame dirty rects
f93275b310 HOPKINS: Removed usage of g_system->lockScreen
188f7efd05 HOPKINS: Fix display of screen images using screen fade in
83480c5784 HOPKINS: Fix transition between initial version display to intro animation
55c024494d HOPKINS: Fix problem with scrolling not working properly
3d06a93be1 HOPKINS: Merged dirty/refresh rect rect adding into a single method
2d83249ac2 HOPKINS: Clean up main game quit checks
e50a7be7de HOPKINS: Further fix for dirty area display in-game
f49fb723da HOPKINS: Added a more comprehensive rects merge code
408345ebab HOPKINS: Further cleaned up dirty rect display
3a48420c90 HOPKINS: Dirty rect fix for Breakout game
d10f81372b HOPKINS: Endian fix for playing Breakout game
39ffd06839 HOPKINS: Bugfix for refreshing Breakout lives when one is lost
4372bd8306 Merge branch 'hopkins_dirtyRects'


Commit: 317bd9ebd088ed1e0329d14d9571015e31cc8de6
    https://github.com/scummvm/scummvm/commit/317bd9ebd088ed1e0329d14d9571015e31cc8de6
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2013-02-24T19:03:38-08:00

Commit Message:
HOPKINS: Beginnings of implementing dirty rect support

Changed paths:
    engines/hopkins/anim.cpp
    engines/hopkins/graphics.cpp
    engines/hopkins/graphics.h
    engines/hopkins/script.cpp



diff --git a/engines/hopkins/anim.cpp b/engines/hopkins/anim.cpp
index fa6dd1c..bc0075b 100644
--- a/engines/hopkins/anim.cpp
+++ b/engines/hopkins/anim.cpp
@@ -79,7 +79,7 @@ void AnimationManager::playAnim(const Common::String &filename, uint32 rate1, ui
 	f.read(screenP, nbytes);
 
 	if (_clearAnimationFl) {
-		_vm->_graphicsManager.lockScreen();
+		_vm->_graphicsManager.lockScreen(true);
 		_vm->_graphicsManager.clearScreen();
 		_vm->_graphicsManager.unlockScreen();
 	}
@@ -94,7 +94,7 @@ void AnimationManager::playAnim(const Common::String &filename, uint32 rate1, ui
 		_vm->_graphicsManager.setPaletteVGA256(_vm->_graphicsManager._palette);
 	} else {
 		_vm->_graphicsManager.setPaletteVGA256(_vm->_graphicsManager._palette);
-		_vm->_graphicsManager.lockScreen();
+		_vm->_graphicsManager.lockScreen(true);
 		if (hasScreenCopy)
 			_vm->_graphicsManager.m_scroll16A(screenCopy, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
 		else
@@ -145,7 +145,7 @@ void AnimationManager::playAnim(const Common::String &filename, uint32 rate1, ui
 
 			if (!_vm->_eventsManager._escKeyFl) {
 				_vm->_eventsManager._rateCounter = 0;
-				_vm->_graphicsManager.lockScreen();
+				_vm->_graphicsManager.lockScreen(true);
 				if (hasScreenCopy) {
 					if (*screenP != kByteStop) {
 						_vm->_graphicsManager.copyWinscanVbe3(screenP, screenCopy);
@@ -260,7 +260,7 @@ void AnimationManager::playAnim2(const Common::String &filename, uint32 rate1, u
 		oldScrollPosX = _vm->_graphicsManager._scrollPosX;
 		_vm->_graphicsManager.SCANLINE(SCREEN_WIDTH);
 		_vm->_graphicsManager.scrollScreen(0);
-		_vm->_graphicsManager.lockScreen();
+		_vm->_graphicsManager.lockScreen(true);
 		_vm->_graphicsManager.clearScreen();
 		_vm->_graphicsManager.unlockScreen();
 		_vm->_graphicsManager._maxX = SCREEN_WIDTH;
@@ -275,7 +275,7 @@ void AnimationManager::playAnim2(const Common::String &filename, uint32 rate1, u
 			_vm->_graphicsManager.setPaletteVGA256(_vm->_graphicsManager._palette);
 		} else {
 			_vm->_graphicsManager.setPaletteVGA256(_vm->_graphicsManager._palette);
-			_vm->_graphicsManager.lockScreen();
+			_vm->_graphicsManager.lockScreen(true);
 			if (hasScreenCopy)
 				_vm->_graphicsManager.m_scroll16A(screenCopy, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
 			else
@@ -319,7 +319,7 @@ void AnimationManager::playAnim2(const Common::String &filename, uint32 rate1, u
 			}
 
 			_vm->_eventsManager._rateCounter = 0;
-			_vm->_graphicsManager.lockScreen();
+			_vm->_graphicsManager.lockScreen(true);
 			if (*screenP != kByteStop) {
 				if (hasScreenCopy) {
 					_vm->_graphicsManager.copyWinscanVbe3(screenP, screenCopy);
@@ -382,7 +382,7 @@ void AnimationManager::playAnim2(const Common::String &filename, uint32 rate1, u
 
 	memcpy(_vm->_graphicsManager._palette, _vm->_graphicsManager._oldPalette, 769);
 	_vm->_graphicsManager.clearPalette();
-	_vm->_graphicsManager.lockScreen();
+	_vm->_graphicsManager.lockScreen(true);
 	_vm->_graphicsManager.clearScreen();
 	_vm->_graphicsManager.unlockScreen();
 	_vm->_graphicsManager._scrollPosX = oldScrollPosX;
@@ -390,12 +390,12 @@ void AnimationManager::playAnim2(const Common::String &filename, uint32 rate1, u
 	if (_vm->_graphicsManager._largeScreenFl) {
 		_vm->_graphicsManager.SCANLINE(2 * SCREEN_WIDTH);
 		_vm->_graphicsManager._maxX = 2 * SCREEN_WIDTH;
-		_vm->_graphicsManager.lockScreen();
+		_vm->_graphicsManager.lockScreen(true);
 		_vm->_graphicsManager.m_scroll16(_vm->_graphicsManager._vesaBuffer, _vm->_eventsManager._startPos.x, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
 	} else {
 		_vm->_graphicsManager.SCANLINE(SCREEN_WIDTH);
 		_vm->_graphicsManager._maxX = SCREEN_WIDTH;
-		_vm->_graphicsManager.lockScreen();
+		_vm->_graphicsManager.lockScreen(true);
 		_vm->_graphicsManager.clearScreen();
 		_vm->_graphicsManager.m_scroll16(_vm->_graphicsManager._vesaBuffer, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
 	}
@@ -642,7 +642,7 @@ void AnimationManager::playSequence(const Common::String &file, uint32 rate1, ui
 		}
 		_vm->_graphicsManager.setPaletteVGA256(_vm->_graphicsManager._palette);
 	} else {
-		_vm->_graphicsManager.lockScreen();
+		_vm->_graphicsManager.lockScreen(true);
 		if (hasScreenCopy)
 			_vm->_graphicsManager.m_scroll16A(screenCopy, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
 		else
@@ -718,7 +718,7 @@ void AnimationManager::playSequence(const Common::String &file, uint32 rate1, ui
 				break;
 
 			_vm->_eventsManager._rateCounter = 0;
-			_vm->_graphicsManager.lockScreen();
+			_vm->_graphicsManager.lockScreen(true);
 			if (hasScreenCopy) {
 				if (*screenP != kByteStop) {
 					_vm->_graphicsManager.copyWinscanVbe(screenP, screenCopy);
@@ -801,7 +801,7 @@ void AnimationManager::playSequence2(const Common::String &file, uint32 rate1, u
 			}
 			_vm->_graphicsManager.setPaletteVGA256(_vm->_graphicsManager._palette);
 		} else {
-			_vm->_graphicsManager.lockScreen();
+			_vm->_graphicsManager.lockScreen(true);
 			_vm->_graphicsManager.setPaletteVGA256(_vm->_graphicsManager._palette);
 			if (multiScreenFl)
 				_vm->_graphicsManager.m_scroll16A(screenCopy, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
@@ -844,7 +844,7 @@ void AnimationManager::playSequence2(const Common::String &file, uint32 rate1, u
 			}
 
 			_vm->_eventsManager._rateCounter = 0;
-			_vm->_graphicsManager.lockScreen();
+			_vm->_graphicsManager.lockScreen(true);
 			if (multiScreenFl) {
 				if (*screenP != kByteStop) {
 					_vm->_graphicsManager.copyWinscanVbe(screenP, screenCopy);
diff --git a/engines/hopkins/graphics.cpp b/engines/hopkins/graphics.cpp
index b299082..a339f97 100644
--- a/engines/hopkins/graphics.cpp
+++ b/engines/hopkins/graphics.cpp
@@ -47,7 +47,11 @@ GraphicsManager::GraphicsManager() {
 	_scrollPosX = 0;
 	_largeScreenFl = false;
 	_oldScrollPosX = 0;
-	NBBLOC = 0;
+	_dirtyRectCount = 0;
+	_vesaScreen = NULL;
+	_vesaBuffer = NULL;
+	_screenBuffer = NULL;
+	_isPhysicalPtr = false;
 
 	_lineNbr2 = 0;
 	Agr_x = Agr_y = 0;
@@ -73,14 +77,15 @@ GraphicsManager::GraphicsManager() {
 	Common::fill(&_palette[0], &_palette[PALETTE_EXT_BLOCK_SIZE], 0);
 	Common::fill(&_oldPalette[0], &_oldPalette[PALETTE_EXT_BLOCK_SIZE], 0);
 
-	for (int i = 0; i < 250; ++i)
-		Common::fill((byte *)&BLOC[i], (byte *)&BLOC[i] + sizeof(BlocItem), 0);
+	for (int i = 0; i < DIRTY_RECTS_SIZE; ++i)
+		Common::fill((byte *)&_dirtyRects[i], (byte *)&_dirtyRects[i] + sizeof(BlocItem), 0);
 
 }
 
 GraphicsManager::~GraphicsManager() {
 	_vm->_globals.freeMemory(_vesaScreen);
 	_vm->_globals.freeMemory(_vesaBuffer);
+	_vm->_globals.freeMemory(_screenBuffer);
 }
 
 void GraphicsManager::setParent(HopkinsEngine *vm) {
@@ -107,14 +112,13 @@ void GraphicsManager::setGraphicalMode(int width, int height) {
 		// Init surfaces
 		_vesaScreen = _vm->_globals.allocMemory(SCREEN_WIDTH * 2 * SCREEN_HEIGHT);
 		_vesaBuffer = _vm->_globals.allocMemory(SCREEN_WIDTH * 2 * SCREEN_HEIGHT);
+		_screenBuffer = _vm->_globals.allocMemory(SCREEN_WIDTH * 2 * SCREEN_HEIGHT);
 
 		_videoPtr = NULL;
 		_screenWidth = width;
 		_screenHeight = height;
 
-		// Clear the screen pitch. This will be set on the first lockScreen call
-		WinScan = 0;
-
+		WinScan = width * 2;
 		PAL_PIXELS = SD_PIXELS;
 		_lineNbr = width;
 
@@ -127,12 +131,19 @@ void GraphicsManager::setGraphicalMode(int width, int height) {
 /**
  * (try to) Lock Screen
  */
-void GraphicsManager::lockScreen() {
+void GraphicsManager::lockScreen(bool shouldUsePhysicalScreen) {
 	if (!_skipVideoLockFl) {
 		if (_lockCounter++ == 0) {
-			_videoPtr = g_system->lockScreen();
-			if (WinScan == 0)
-				WinScan = _videoPtr->pitch;
+			if (shouldUsePhysicalScreen) {
+				Graphics::Surface *s = g_system->lockScreen();
+				_videoPtr = (byte *)s->pixels;
+				WinScan = s->pitch;
+			} else {
+				_videoPtr = _screenBuffer;
+				WinScan = _width * 2;
+			}
+
+			_isPhysicalPtr = shouldUsePhysicalScreen;
 		}
 	}		
 }
@@ -143,7 +154,9 @@ void GraphicsManager::lockScreen() {
 void GraphicsManager::unlockScreen() {
 	assert(_videoPtr);
 	if (--_lockCounter == 0) {
-		g_system->unlockScreen();
+		if (_isPhysicalPtr)
+			g_system->unlockScreen();
+
 		_videoPtr = NULL;
 	}
 }
@@ -153,7 +166,7 @@ void GraphicsManager::unlockScreen() {
  */
 void GraphicsManager::clearScreen() {
 	assert(_videoPtr);
-	_videoPtr->fillRect(Common::Rect(0, 0, _screenWidth, _screenHeight), 0);
+	Common::fill(_videoPtr, _videoPtr + WinScan * _screenHeight, 0);
 }
 
 /**
@@ -395,14 +408,10 @@ void GraphicsManager::loadPCX320(byte *surface, const Common::String &file, byte
 }
 
 // Clear Palette
-// CHECKME: Some versions of the game don't include it, some contains nothing more than 
-// than a loop doing nothing, some others just map the last value. While debugging, it
-// seems that this function is called once the palette is already cleared, so it would be useless
-// This code could most likely be removed.
 void GraphicsManager::clearPalette() {
-	uint16 col0 = mapRGB(0, 0, 0);
-	for (int i = 0; i < 512; i += 2)
-		WRITE_LE_UINT16(&SD_PIXELS[i], col0);
+	// As weird as it sounds, this is what the original Linux executable does, 
+	// and not a full array clear.
+	SD_PIXELS[0] = 0;
 }
 
 void GraphicsManager::SCANLINE(int pitch) {
@@ -417,7 +426,7 @@ void GraphicsManager::m_scroll16(const byte *surface, int xs, int ys, int width,
 
 	assert(_videoPtr);
 	const byte *srcP = xs + _lineNbr2 * ys + surface;
-	byte *destP = (byte *)_videoPtr->pixels + destX * 2 + WinScan * destY;
+	byte *destP = (byte *)_videoPtr + destX * 2 + WinScan * destY;
 
 	for (int yp = 0; yp < height; ++yp) {
 		// Copy over the line, using the source pixels as lookups into the pixels palette
@@ -436,6 +445,7 @@ void GraphicsManager::m_scroll16(const byte *surface, int xs, int ys, int width,
 	}
 
 	unlockScreen();
+	addVesaSegment(xs, ys, xs + width, ys + height);
 }
 
 // TODO: See if PAL_PIXELS can be converted to a uint16 array
@@ -448,7 +458,7 @@ void GraphicsManager::m_scroll16A(const byte *surface, int xs, int ys, int width
 
 	assert(_videoPtr);
 	const byte *srcP = xs + _lineNbr2 * ys + surface;
-	byte *destP = (byte *)_videoPtr->pixels + destX + destX + WinScan * destY;
+	byte *destP = (byte *)_videoPtr + destX + destX + WinScan * destY;
 	int yNext = height;
 	Agr_x = 0;
 	Agr_y = 0;
@@ -494,6 +504,8 @@ void GraphicsManager::m_scroll16A(const byte *surface, int xs, int ys, int width
 		srcP = _lineNbr2 + srcCopyP;
 		yNext = yCtr - 1;
 	} while (yCtr != 1);
+
+	addVesaSegment(xs, ys, xs + width, ys + width);
 }
 
 void GraphicsManager::Copy_Vga16(const byte *surface, int xp, int yp, int width, int height, int destX, int destY) {
@@ -506,7 +518,7 @@ void GraphicsManager::Copy_Vga16(const byte *surface, int xp, int yp, int width,
 
 	assert(_videoPtr);
 	const byte *srcP = surface + xp + 320 * yp;
-	byte *destP = (byte *)_videoPtr->pixels + 30 * WinScan + destX + destX + destX + destX + WinScan * 2 * destY;
+	byte *destP = (byte *)_videoPtr + 30 * WinScan + destX + destX + destX + destX + WinScan * 2 * destY;
 	int yCount = height;
 	int xCount = width;
 
@@ -531,6 +543,8 @@ void GraphicsManager::Copy_Vga16(const byte *surface, int xp, int yp, int width,
 		srcP = loopSrcP + 320;
 		yCount = yCtr - 1;
 	} while (yCtr != 1);
+
+	addVesaSegment(xp, yp, xp + width, yp + width);
 }
 
 /** 
@@ -816,7 +830,7 @@ void GraphicsManager::copyVideoVbe16(const byte *srcData) {
 			if (srcByte == 211) {
 				int pixelCount = srcP[1];
 				int pixelIndex = srcP[2];
-				byte *destP = (byte *)_videoPtr->pixels + destOffset * 2;
+				byte *destP = (byte *)_videoPtr + destOffset * 2;
 				destOffset += pixelCount;
 
 				while (pixelCount--) {
@@ -829,7 +843,7 @@ void GraphicsManager::copyVideoVbe16(const byte *srcData) {
 			} else {
 				int pixelCount = srcByte - 211;
 				int pixelIndex = srcP[1];
-				byte *destP = (byte *)_videoPtr->pixels + destOffset * 2;
+				byte *destP = (byte *)_videoPtr + destOffset * 2;
 				destOffset += pixelCount;
 
 				while (pixelCount--) {
@@ -841,7 +855,7 @@ void GraphicsManager::copyVideoVbe16(const byte *srcData) {
 				srcP += 2;
 			}
 		} else {
-			byte *destP = (byte *)_videoPtr->pixels + destOffset * 2;
+			byte *destP = (byte *)_videoPtr + destOffset * 2;
 			destP[0] = PAL_PIXELS[2 * srcByte];
 			destP[1] = PAL_PIXELS[(2 * srcByte) + 1];
 			++srcP;
@@ -875,7 +889,7 @@ void GraphicsManager::copyVideoVbe16a(const byte *srcData) {
 			}
 		}
 
-		WRITE_LE_UINT16((byte *)_videoPtr->pixels + destOffset * 2, READ_LE_UINT16(PAL_PIXELS + 2 * srcByte));
+		WRITE_LE_UINT16((byte *)_videoPtr + destOffset * 2, READ_LE_UINT16(PAL_PIXELS + 2 * srcByte));
 		++srcP;
 		++destOffset;
 	}
@@ -1080,10 +1094,10 @@ void GraphicsManager::displayAllBob() {
 }
 
 void GraphicsManager::resetVesaSegment() {
-	for (int idx = 0; idx <= NBBLOC; idx++)
-		BLOC[idx]._activeFl = false;
+	for (int idx = 0; idx <= _dirtyRectCount; idx++)
+		_dirtyRects[idx]._activeFl = false;
 
-	NBBLOC = 0;
+	_dirtyRectCount = 0;
 }
 
 // Add VESA Segment
@@ -1099,15 +1113,15 @@ void GraphicsManager::addVesaSegment(int x1, int y1, int x2, int y2) {
 	if (y1 < _minY)
 		y1 = _minY;
 
-	for (int blocIndex = 0; blocIndex <= NBBLOC; blocIndex++) {
-		BlocItem &bloc = BLOC[blocIndex];
+	for (int blocIndex = 0; blocIndex <= _dirtyRectCount; blocIndex++) {
+		BlocItem &bloc = _dirtyRects[blocIndex];
 		if (bloc._activeFl && tempX >= bloc._x1 && x2 <= bloc._x2 && y1 >= bloc._y1 && y2 <= bloc._y2)
 			addFlag = false;
 	};
 
 	if (addFlag) {
-		assert(NBBLOC < 250);
-		BlocItem &bloc = BLOC[++NBBLOC];
+		assert(_dirtyRectCount < DIRTY_RECTS_SIZE);
+		BlocItem &bloc = _dirtyRects[++_dirtyRectCount];
 
 		bloc._activeFl = true;
 		bloc._x1 = tempX;
@@ -1119,13 +1133,13 @@ void GraphicsManager::addVesaSegment(int x1, int y1, int x2, int y2) {
 
 // Display VESA Segment
 void GraphicsManager::displayVesaSegment() {
-	if (NBBLOC == 0)
+	if (_dirtyRectCount == 0)
 		return;
 
 	lockScreen();
 
-	for (int idx = 1; idx <= NBBLOC; ++idx) {
-		BlocItem &bloc = BLOC[idx];
+	for (int idx = 1; idx <= _dirtyRectCount; ++idx) {
+		BlocItem &bloc = _dirtyRects[idx];
 		Common::Rect &dstRect = dstrect[idx - 1];
 		if (!bloc._activeFl)
 			continue;
@@ -1154,11 +1168,15 @@ void GraphicsManager::displayVesaSegment() {
 			unlockScreen();
 		}
 
-		BLOC[idx]._activeFl = false;
+		byte *srcP = _videoPtr + WinScan * dstRect.top + (dstRect.left * 2);
+		g_system->copyRectToScreen(srcP, WinScan, dstRect.left, dstRect.top, 
+			dstRect.width(), dstRect.height());
+
+		_dirtyRects[idx]._activeFl = false;
 	}
 
-	NBBLOC = 0;
 	unlockScreen();
+	_dirtyRectCount = 0;	
 }
 
 void GraphicsManager::AFFICHE_SPEEDVGA(const byte *objectData, int xp, int yp, int idx, bool addSegment) {
@@ -1184,7 +1202,7 @@ void GraphicsManager::copy16bFromSurfaceScaleX2(const byte *surface) {
 
 	assert(_videoPtr);
 	const byte *curSurface = surface;
-	byte *destPtr = 30 * WinScan + (byte *)_videoPtr->pixels;
+	byte *destPtr = 30 * WinScan + (byte *)_videoPtr;
 	for (int y = 200; y; y--) {
 		byte *oldDestPtr = destPtr;
 		for (int x = 320; x; x--) {
diff --git a/engines/hopkins/graphics.h b/engines/hopkins/graphics.h
index 6dc8ec6..c0d14f0 100644
--- a/engines/hopkins/graphics.h
+++ b/engines/hopkins/graphics.h
@@ -31,6 +31,7 @@
 
 namespace Hopkins {
 
+#define DIRTY_RECTS_SIZE 250
 #define PALETTE_SIZE 256
 #define PALETTE_BLOCK_SIZE (PALETTE_SIZE * 3)
 #define PALETTE_EXT_BLOCK_SIZE 800
@@ -63,7 +64,8 @@ private:
 	bool _initGraphicsFl;
 	int _screenWidth;
 	int _screenHeight;
-	Graphics::Surface *_videoPtr;
+	byte *_videoPtr;
+	bool _isPhysicalPtr;
 	int _width;
 	int _posXClipped, _posYClipped;
 	bool _clipFl;
@@ -94,6 +96,7 @@ public:
 	byte _oldPalette[PALETTE_EXT_BLOCK_SIZE];
 	byte *_vesaScreen;
 	byte *_vesaBuffer;
+	byte *_screenBuffer;
 	int _scrollOffset;
 	int _scrollPosX;
 	bool _largeScreenFl;
@@ -108,8 +111,8 @@ public:
 	bool _skipVideoLockFl;
 	int _fadeDefaultSpeed;
 
-	int NBBLOC;
-	BlocItem BLOC[250];
+	int _dirtyRectCount;
+	BlocItem _dirtyRects[DIRTY_RECTS_SIZE];
 	int WinScan;
 	byte *PAL_PIXELS;
 	bool MANU_SCROLL;
@@ -119,7 +122,7 @@ public:
 	~GraphicsManager();
 
 	void setParent(HopkinsEngine *vm);
-	void lockScreen();
+	void lockScreen(bool shouldUsePhysicalScreen = false);
 	void unlockScreen();
 	void clearPalette();
 	void clearScreen();
diff --git a/engines/hopkins/script.cpp b/engines/hopkins/script.cpp
index 09555bd..993bd2b 100644
--- a/engines/hopkins/script.cpp
+++ b/engines/hopkins/script.cpp
@@ -2337,7 +2337,7 @@ int ScriptManager::handleOpcode(byte *dataP) {
 				memcpy(_vm->_graphicsManager._oldPalette, _vm->_graphicsManager._palette, 769);
 				_vm->_animationManager.playAnim2("PLAN.ANM", 50, 10, 800);
 			}
-			_vm->_graphicsManager.NBBLOC = 0;
+			_vm->_graphicsManager._dirtyRectCount = 0;
 			break;
 
 		case 608:


Commit: 54924de6cbd07e8b8cb2eb91067a0d31d08b55c8
    https://github.com/scummvm/scummvm/commit/54924de6cbd07e8b8cb2eb91067a0d31d08b55c8
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2013-02-25T19:00:36-08:00

Commit Message:
HOPKINS: Home-screen now displaying correctly with dirty rects

Changed paths:
    engines/hopkins/computer.cpp
    engines/hopkins/dialogs.cpp
    engines/hopkins/events.cpp
    engines/hopkins/font.cpp
    engines/hopkins/graphics.cpp
    engines/hopkins/graphics.h
    engines/hopkins/objects.cpp



diff --git a/engines/hopkins/computer.cpp b/engines/hopkins/computer.cpp
index 2e91115..37f1dd2 100644
--- a/engines/hopkins/computer.cpp
+++ b/engines/hopkins/computer.cpp
@@ -426,13 +426,13 @@ void ComputerManager::displayMessage(int xp, int yp, int textIdx) {
 			x1 -= _vm->_fontManager._fontFixedWidth;
 			x2 = x1 + 2 * _vm->_fontManager._fontFixedWidth;
 			_vm->_graphicsManager.Copy_Mem(_vm->_graphicsManager._vesaScreen, x1, yp, 3 * _vm->_fontManager._fontFixedWidth, 12, _vm->_graphicsManager._vesaBuffer, x1, yp);
-			_vm->_graphicsManager.addVesaSegment(x1, yp, x2, yp + 12);
+			_vm->_graphicsManager.addDirtyRect(x1, yp, x2, yp + 12);
 			_vm->_fontManager.displayTextVesa(x1, yp, "_", 252);
 		}
 		if (mappedChar != '*') {
 			char newChar = mappedChar;
 			_vm->_graphicsManager.Copy_Mem(_vm->_graphicsManager._vesaScreen, x1, yp, _vm->_fontManager._fontFixedWidth, 12, _vm->_graphicsManager._vesaBuffer, x1, yp);
-			_vm->_graphicsManager.addVesaSegment(x1, yp, _vm->_fontManager._fontFixedWidth + x1, yp + 12);
+			_vm->_graphicsManager.addDirtyRect(x1, yp, _vm->_fontManager._fontFixedWidth + x1, yp + 12);
 			_inputBuf[textIndex] = newChar;
 
 			Common::String charString = Common::String::format("%c_", newChar);
@@ -444,7 +444,7 @@ void ComputerManager::displayMessage(int xp, int yp, int textIdx) {
 	} while (textIndex != textIdx && curChar != 13);
 
 	_vm->_graphicsManager.Copy_Mem(_vm->_graphicsManager._vesaScreen, x1, yp, _vm->_fontManager._fontFixedWidth, 12, _vm->_graphicsManager._vesaBuffer, x1, yp);
-	_vm->_graphicsManager.addVesaSegment(x1, yp, _vm->_fontManager._fontFixedWidth + x1, yp + 12);
+	_vm->_graphicsManager.addDirtyRect(x1, yp, _vm->_fontManager._fontFixedWidth + x1, yp + 12);
 
 	_vm->_eventsManager.VBL();
 	_inputBuf[textIndex] = 0;
diff --git a/engines/hopkins/dialogs.cpp b/engines/hopkins/dialogs.cpp
index 6102c86..f45e586 100644
--- a/engines/hopkins/dialogs.cpp
+++ b/engines/hopkins/dialogs.cpp
@@ -300,7 +300,7 @@ void DialogsManager::showOptionsDialog() {
 
 	_vm->_graphicsManager.copySurface(_vm->_graphicsManager._vesaScreen, _vm->_graphicsManager._scrollOffset + 164,
 		107, 335, 215, _vm->_graphicsManager._vesaBuffer, _vm->_graphicsManager._scrollOffset + 164, 107);
-	_vm->_graphicsManager.addVesaSegment(_vm->_graphicsManager._scrollOffset + 164, 107,
+	_vm->_graphicsManager.addDirtyRect(_vm->_graphicsManager._scrollOffset + 164, 107,
 		_vm->_graphicsManager._scrollOffset + 498, 320);
 
 	_vm->_globals._optionDialogSpr = _vm->_globals.freeMemory(_vm->_globals._optionDialogSpr);
@@ -451,7 +451,7 @@ void DialogsManager::showInventory() {
 	if (_inventDisplayedFl) {
 		_inventDisplayedFl = false;
 		_vm->_graphicsManager.copySurface(_vm->_graphicsManager._vesaScreen, _inventX, 114, _inventWidth, _inventHeight, _vm->_graphicsManager._vesaBuffer, _inventX, 114);
-		_vm->_graphicsManager.addVesaSegment(_inventX, 114, _inventX + _inventWidth, _inventWidth + 114);
+		_vm->_graphicsManager.addDirtyRect(_inventX, 114, _inventX + _inventWidth, _inventWidth + 114);
 		_vm->_objectsManager.BOBTOUS = true;
 	}
 
@@ -483,7 +483,7 @@ void DialogsManager::inventAnim() {
 	if (_vm->_objectsManager._eraseVisibleCounter && !_vm->_objectsManager._visibleFl) {
 		_vm->_graphicsManager.copySurface(_vm->_graphicsManager._vesaScreen, _vm->_objectsManager._oldInventoryPosX, 27, 48, 38,
 			_vm->_graphicsManager._vesaBuffer, _vm->_objectsManager._oldInventoryPosX, 27);
-		_vm->_graphicsManager.addVesaSegment(_vm->_objectsManager._oldInventoryPosX, 27, _vm->_objectsManager._oldInventoryPosX + 48, 65);
+		_vm->_graphicsManager.addDirtyRect(_vm->_objectsManager._oldInventoryPosX, 27, _vm->_objectsManager._oldInventoryPosX + 48, 65);
 		--_vm->_objectsManager._eraseVisibleCounter;
 	}
 
@@ -493,10 +493,10 @@ void DialogsManager::inventAnim() {
 		_vm->_graphicsManager.copySurface(_vm->_graphicsManager._vesaScreen, _vm->_objectsManager._oldInventoryPosX, 27, 48, 38,
 			_vm->_graphicsManager._vesaBuffer, _vm->_objectsManager._oldInventoryPosX, 27);
 
-		_vm->_graphicsManager.addVesaSegment(_vm->_objectsManager._oldInventoryPosX, 27, _vm->_objectsManager._oldInventoryPosX + 48, 65);
+		_vm->_graphicsManager.addDirtyRect(_vm->_objectsManager._oldInventoryPosX, 27, _vm->_objectsManager._oldInventoryPosX + 48, 65);
 		int newOffset = _vm->_graphicsManager._scrollOffset + 2;
 		_vm->_graphicsManager.Sprite_Vesa(_vm->_graphicsManager._vesaBuffer, _inventoryIcons, newOffset + 300, 327, 0);
-		_vm->_graphicsManager.addVesaSegment(newOffset, 27, newOffset + 45, 62);
+		_vm->_graphicsManager.addDirtyRect(newOffset, 27, newOffset + 45, 62);
 		_vm->_objectsManager._oldInventoryPosX = newOffset;
 	}
 
@@ -505,17 +505,17 @@ void DialogsManager::inventAnim() {
 			_vm->_graphicsManager.Affiche_Perfect(_vm->_graphicsManager._vesaBuffer, _vm->_objectsManager._headSprites, 832, 325, 0, 0, 0, false);
 		if (_vm->_globals._saveData->_data[svField355] == 1)
 			_vm->_graphicsManager.Affiche_Perfect(_vm->_graphicsManager._vesaBuffer, _vm->_objectsManager._headSprites, 866, 325, 1, 0, 0, false);
-		_vm->_graphicsManager.addVesaSegment(532, 25, 560, 60);
-		_vm->_graphicsManager.addVesaSegment(566, 25, 594, 60);
+		_vm->_graphicsManager.addDirtyRect(532, 25, 560, 60);
+		_vm->_graphicsManager.addDirtyRect(566, 25, 594, 60);
 	}
 	if (_vm->_globals._saveData->_data[svField356] == 1) {
 		_vm->_graphicsManager.Affiche_Perfect(_vm->_graphicsManager._vesaBuffer, _vm->_objectsManager._headSprites, 832, 325, 0, 0, 0, false);
-		_vm->_graphicsManager.addVesaSegment(532, 25, 560, 60);
+		_vm->_graphicsManager.addDirtyRect(532, 25, 560, 60);
 	}
 
 	if (_vm->_globals._saveData->_data[svField354] == 1) {
 		_vm->_graphicsManager.Affiche_Perfect(_vm->_graphicsManager._vesaBuffer, _vm->_objectsManager._headSprites, 832, 325, 0, 0, 0, false);
-		_vm->_graphicsManager.addVesaSegment(532, 25, 560, 60);
+		_vm->_graphicsManager.addDirtyRect(532, 25, 560, 60);
 	}
 }
 
@@ -574,7 +574,7 @@ void DialogsManager::showLoadGame() {
 	} while (!_vm->shouldQuit() && (!slotNumber || _vm->_eventsManager.getMouseButton() != 1));
 	_vm->_objectsManager._saveLoadFl = false;
 	_vm->_graphicsManager.copySurface(_vm->_graphicsManager._vesaScreen, _vm->_eventsManager._startPos.x + 183, 60, 274, 353, _vm->_graphicsManager._vesaBuffer, _vm->_eventsManager._startPos.x + 183, 60);
-	_vm->_graphicsManager.addVesaSegment(_vm->_eventsManager._startPos.x + 183, 60, 457, 413);
+	_vm->_graphicsManager.addDirtyRect(_vm->_eventsManager._startPos.x + 183, 60, 457, 413);
 	_vm->_objectsManager.BOBTOUS = true;
 	_vm->_objectsManager._saveLoadSprite = _vm->_globals.freeMemory(_vm->_objectsManager._saveLoadSprite);
 	_vm->_objectsManager._saveLoadSprite2 = _vm->_globals.freeMemory(_vm->_objectsManager._saveLoadSprite2);
@@ -603,7 +603,7 @@ void DialogsManager::showSaveGame() {
 
 	_vm->_objectsManager._saveLoadFl = false;
 	_vm->_graphicsManager.copySurface(_vm->_graphicsManager._vesaScreen, _vm->_eventsManager._startPos.x + 183, 60, 274, 353, _vm->_graphicsManager._vesaBuffer, _vm->_eventsManager._startPos.x + 183, 60);
-	_vm->_graphicsManager.addVesaSegment(_vm->_eventsManager._startPos.x + 183, 60, _vm->_eventsManager._startPos.x + 457, 413);
+	_vm->_graphicsManager.addDirtyRect(_vm->_eventsManager._startPos.x + 183, 60, _vm->_eventsManager._startPos.x + 457, 413);
 	_vm->_objectsManager.BOBTOUS = true;
 	_vm->_objectsManager._saveLoadSprite = _vm->_globals.freeMemory(_vm->_objectsManager._saveLoadSprite);
 	_vm->_objectsManager._saveLoadSprite2 = _vm->_globals.freeMemory(_vm->_objectsManager._saveLoadSprite2);
diff --git a/engines/hopkins/events.cpp b/engines/hopkins/events.cpp
index d13f545..3a6d31a 100644
--- a/engines/hopkins/events.cpp
+++ b/engines/hopkins/events.cpp
@@ -411,7 +411,7 @@ void EventsManager::VBL() {
 		}
 	} else if (yp < _vm->_graphicsManager._maxY && xp < _vm->_graphicsManager._maxX && width > 1 && height > 1) {
 		_vm->_eventsManager.updateCursor();
-		_vm->_graphicsManager.addVesaSegment(xp, yp, right, bottom);
+		_vm->_graphicsManager.addDirtyRect(xp, yp, right, bottom);
 	}
 
 	_vm->_globals._speed = 2;
diff --git a/engines/hopkins/font.cpp b/engines/hopkins/font.cpp
index 89d197b..62ce7f2 100644
--- a/engines/hopkins/font.cpp
+++ b/engines/hopkins/font.cpp
@@ -166,7 +166,7 @@ void FontManager::box(int idx, int messageId, const Common::String &filename, in
 				yp,
 				_text[idx]._width,
 				_text[idx]._height);
-			_vm->_graphicsManager.addVesaSegment(xp, yp, xp + width, yp + height);
+			_vm->_graphicsManager.addDirtyRect(xp, yp, xp + width, yp + height);
 		}
 	} else {
 		int lineCount = 0;
@@ -405,7 +405,7 @@ void FontManager::displayTextVesa(int xp, int yp, const Common::String &message,
 		}
 	}
 
-	_vm->_graphicsManager.addVesaSegment(xp, yp, currentX, yp + 12);
+	_vm->_graphicsManager.addDirtyRect(xp, yp, currentX, yp + 12);
 }
 
 /**
@@ -463,7 +463,7 @@ void FontManager::renderTextDisplay(int xp, int yp, const Common::String &msg, i
 
 			int charStartPosX = charEndPosX;
 			charEndPosX += charWidth;
-			_vm->_graphicsManager.addVesaSegment(charStartPosX, yp, charEndPosX, yp + 12);
+			_vm->_graphicsManager.addDirtyRect(charStartPosX, yp, charEndPosX, yp + 12);
 			if (_vm->_eventsManager._escKeyFl) {
 				_vm->_globals.iRegul = 1;
 				_vm->_eventsManager.VBL();
diff --git a/engines/hopkins/graphics.cpp b/engines/hopkins/graphics.cpp
index a339f97..3133232 100644
--- a/engines/hopkins/graphics.cpp
+++ b/engines/hopkins/graphics.cpp
@@ -118,7 +118,7 @@ void GraphicsManager::setGraphicalMode(int width, int height) {
 		_screenWidth = width;
 		_screenHeight = height;
 
-		WinScan = width * 2;
+		WinScan = SCREEN_WIDTH * 2;
 		PAL_PIXELS = SD_PIXELS;
 		_lineNbr = width;
 
@@ -140,7 +140,7 @@ void GraphicsManager::lockScreen(bool shouldUsePhysicalScreen) {
 				WinScan = s->pitch;
 			} else {
 				_videoPtr = _screenBuffer;
-				WinScan = _width * 2;
+				WinScan = SCREEN_WIDTH * 2;
 			}
 
 			_isPhysicalPtr = shouldUsePhysicalScreen;
@@ -203,6 +203,7 @@ void GraphicsManager::loadVgaImage(const Common::String &file) {
  */
 void GraphicsManager::loadScreen(const Common::String &file) {
 	Common::File f;
+	assert(!_videoPtr || !_isPhysicalPtr);
 
 	bool flag = true;
 	if (_vm->_fileManager.searchCat(file, 6) == g_PTRNUL) {
@@ -242,7 +243,7 @@ void GraphicsManager::loadScreen(const Common::String &file) {
 		}
 	}
 
-	memcpy(_vesaBuffer, _vesaScreen, SCREEN_WIDTH * 2 * SCREEN_HEIGHT);
+	memcpy(_vesaBuffer, _vesaScreen, SCREEN_WIDTH * 2 * SCREEN_HEIGHT);	
 }
 
 void GraphicsManager::initColorTable(int minIndex, int maxIndex, byte *palette) {
@@ -445,7 +446,7 @@ void GraphicsManager::m_scroll16(const byte *surface, int xs, int ys, int width,
 	}
 
 	unlockScreen();
-	addVesaSegment(xs, ys, xs + width, ys + height);
+	addDirtyRect(xs, ys, xs + width, ys + height);
 }
 
 // TODO: See if PAL_PIXELS can be converted to a uint16 array
@@ -505,7 +506,7 @@ void GraphicsManager::m_scroll16A(const byte *surface, int xs, int ys, int width
 		yNext = yCtr - 1;
 	} while (yCtr != 1);
 
-	addVesaSegment(xs, ys, xs + width, ys + width);
+	addDirtyRect(xs, ys, xs + width, ys + width);
 }
 
 void GraphicsManager::Copy_Vga16(const byte *surface, int xp, int yp, int width, int height, int destX, int destY) {
@@ -544,7 +545,7 @@ void GraphicsManager::Copy_Vga16(const byte *surface, int xp, int yp, int width,
 		yCount = yCtr - 1;
 	} while (yCtr != 1);
 
-	addVesaSegment(xp, yp, xp + width, yp + width);
+	addDirtyRect(xp, yp, xp + width, yp + width);
 }
 
 /** 
@@ -1101,7 +1102,7 @@ void GraphicsManager::resetVesaSegment() {
 }
 
 // Add VESA Segment
-void GraphicsManager::addVesaSegment(int x1, int y1, int x2, int y2) {
+void GraphicsManager::addDirtyRect(int x1, int y1, int x2, int y2) {
 	int tempX = x1;
 	bool addFlag = true;
 	if (x2 > _maxX)
@@ -1190,7 +1191,7 @@ void GraphicsManager::AFFICHE_SPEEDVGA(const byte *objectData, int xp, int yp, i
 		Sprite_Vesa(_vesaScreen, objectData, xp + 300, yp + 300, idx);
 	}
 	if (addSegment)
-		addVesaSegment(xp, yp, xp + width, yp + height);
+		addDirtyRect(xp, yp, xp + width, yp + height);
 }
 
 /**
@@ -1609,7 +1610,7 @@ void GraphicsManager::fastDisplay(const byte *spriteData, int xp, int yp, int sp
 		Sprite_Vesa(_vesaScreen, spriteData, xp + 300, yp + 300, spriteIndex);
 	}
 	if (addSegment)
-		addVesaSegment(xp, yp, xp + width, yp + height);
+		addDirtyRect(xp, yp, xp + width, yp + height);
 }
 
 void GraphicsManager::copySurface(const byte *surface, int x1, int y1, int width, int height, byte *destSurface, int destX, int destY) {
@@ -1635,7 +1636,7 @@ void GraphicsManager::copySurface(const byte *surface, int x1, int y1, int width
 	if (croppedWidth > 0 && croppedHeight > 0) {
 		int height2 = croppedHeight;
 		Copy_Mem(surface, left, top, croppedWidth, croppedHeight, destSurface, destX, destY);
-		addVesaSegment(left, top, left + croppedWidth, top + height2);
+		addDirtyRect(left, top, left + croppedWidth, top + height2);
 	}
 }
 
diff --git a/engines/hopkins/graphics.h b/engines/hopkins/graphics.h
index c0d14f0..0db51a0 100644
--- a/engines/hopkins/graphics.h
+++ b/engines/hopkins/graphics.h
@@ -126,7 +126,7 @@ public:
 	void unlockScreen();
 	void clearPalette();
 	void clearScreen();
-	void addVesaSegment(int x1, int y1, int x2, int y2);
+	void addDirtyRect(int x1, int y1, int x2, int y2);
 	void copySurface(const byte *surface, int x1, int y1, int width, int height, byte *destSurface, int destX, int destY);
 	void loadImage(const Common::String &file);
 	void loadVgaImage(const Common::String &file);
diff --git a/engines/hopkins/objects.cpp b/engines/hopkins/objects.cpp
index b37dac2..20d14af 100644
--- a/engines/hopkins/objects.cpp
+++ b/engines/hopkins/objects.cpp
@@ -414,7 +414,7 @@ void ObjectsManager::displaySprite() {
 			_vm->_graphicsManager.Sprite_Vesa(_vm->_graphicsManager._vesaBuffer, _vm->_dialogsManager._inventBuf2, _oldBorderPos.x + 300, _oldBorderPos.y + 300, _oldBorderSpriteIndex + 1);
 		if (_borderPos.x && _borderPos.y)
 			_vm->_graphicsManager.Sprite_Vesa(_vm->_graphicsManager._vesaBuffer, _vm->_dialogsManager._inventBuf2, _borderPos.x + 300, _borderPos.y + 300, _borderSpriteIndex);
-		_vm->_graphicsManager.addVesaSegment(_vm->_dialogsManager._inventX, _vm->_dialogsManager._inventY, _vm->_dialogsManager._inventX + _vm->_dialogsManager._inventWidth, _vm->_dialogsManager._inventY + _vm->_dialogsManager._inventHeight);
+		_vm->_graphicsManager.addDirtyRect(_vm->_dialogsManager._inventX, _vm->_dialogsManager._inventY, _vm->_dialogsManager._inventX + _vm->_dialogsManager._inventWidth, _vm->_dialogsManager._inventY + _vm->_dialogsManager._inventHeight);
 	}
 
 	if (_saveLoadFl) {
@@ -422,7 +422,7 @@ void ObjectsManager::displaySprite() {
 		if (_saveLoadX && _saveLoadY)
 			_vm->_graphicsManager.Sprite_Vesa(_vm->_graphicsManager._vesaBuffer, _saveLoadSprite2, _saveLoadX + _vm->_eventsManager._startPos.x + 300, _saveLoadY + 300, 0);
 
-		_vm->_graphicsManager.addVesaSegment(_vm->_eventsManager._startPos.x + 183, 60, _vm->_eventsManager._startPos.x + 457, 413);
+		_vm->_graphicsManager.addDirtyRect(_vm->_eventsManager._startPos.x + 183, 60, _vm->_eventsManager._startPos.x + 457, 413);
 	}
 
 	// If the Options dialog is activated, draw the elements
@@ -443,7 +443,7 @@ void ObjectsManager::displaySprite() {
 			_vm->_eventsManager._startPos.x + 600, 522, _vm->_globals._menuDisplayType);
 		_vm->_graphicsManager.Sprite_Vesa(_vm->_graphicsManager._vesaBuffer, _vm->_globals._optionDialogSpr,
 			_vm->_eventsManager._startPos.x + 611, 502, _vm->_globals._menuScrollSpeed);
-		_vm->_graphicsManager.addVesaSegment(_vm->_eventsManager._startPos.x + 164, 107, _vm->_eventsManager._startPos.x + 498, 320);
+		_vm->_graphicsManager.addDirtyRect(_vm->_eventsManager._startPos.x + 164, 107, _vm->_eventsManager._startPos.x + 498, 320);
 	}
 
 	// Loop to draw any on-screen text
@@ -565,7 +565,7 @@ void ObjectsManager::setBobInfo(int idx) {
 		_vm->_globals.Liste2[idx]._visibleFl = false;
 
 	if (_vm->_globals.Liste2[idx]._visibleFl)
-		_vm->_graphicsManager.addVesaSegment(
+		_vm->_graphicsManager.addDirtyRect(
              _vm->_globals.Liste2[idx]._posX,
              _vm->_globals.Liste2[idx]._posY,
              _vm->_globals.Liste2[idx]._posX + _vm->_globals.Liste2[idx]._width,
@@ -808,7 +808,7 @@ void ObjectsManager::DEF_SPRITE(int idx) {
 		list->_visibleFl = false;
 
 	if (list->_visibleFl)
-		_vm->_graphicsManager.addVesaSegment( list->_posX, list->_posY, list->_posX + list->_width, list->_posY + list->_height);
+		_vm->_graphicsManager.addDirtyRect( list->_posX, list->_posY, list->_posX + list->_width, list->_posY + list->_height);
 }
 
 void ObjectsManager::displayHiding(int idx) {
@@ -816,7 +816,7 @@ void ObjectsManager::displayHiding(int idx) {
 
 	_vm->_graphicsManager.Sprite_Vesa(_vm->_graphicsManager._vesaBuffer, _vm->_globals._hidingItemData[1], 
 		hid->_x + 300, hid->_y + 300, hid->_spriteIndex);
-	_vm->_graphicsManager.addVesaSegment(hid->_x, hid->_y, hid->_x + hid->_width, hid->_y + hid->_height);
+	_vm->_graphicsManager.addDirtyRect(hid->_x, hid->_y, hid->_x + hid->_width, hid->_y + hid->_height);
 }
 
 // Compute Sprite
@@ -1085,7 +1085,7 @@ void ObjectsManager::displayVBob() {
 			_vm->_graphicsManager.restoreSurfaceRect(_vm->_graphicsManager._vesaBuffer, vbob->_surface,
 				vbob->_xp, vbob->_yp, width, height);
 
-			_vm->_graphicsManager.addVesaSegment(vbob->_xp, vbob->_yp, vbob->_xp + width, height + vbob->_yp);
+			_vm->_graphicsManager.addDirtyRect(vbob->_xp, vbob->_yp, vbob->_xp + width, height + vbob->_yp);
 			vbob->_surface = _vm->_globals.freeMemory(vbob->_surface);
 
 			vbob->field4 = 0;
@@ -1109,7 +1109,7 @@ void ObjectsManager::displayVBob() {
 			_vm->_graphicsManager.restoreSurfaceRect(_vm->_graphicsManager._vesaBuffer, vbob->_surface,
 				vbob->_oldX, vbob->_oldY, width, height);
 
-			_vm->_graphicsManager.addVesaSegment(vbob->_oldX, vbob->_oldY, vbob->_oldX + width, vbob->_oldY + height);
+			_vm->_graphicsManager.addDirtyRect(vbob->_oldX, vbob->_oldY, vbob->_oldX + width, vbob->_oldY + height);
 
 			vbob->field4 = 1;
 			vbob->_oldSpriteData = vbob->_spriteData;
@@ -1148,7 +1148,7 @@ void ObjectsManager::displayVBob() {
 					vbob->_xp + 300, vbob->_yp + 300, vbob->_frameIndex);
 			}
 
-			_vm->_graphicsManager.addVesaSegment(vbob->_xp, vbob->_yp , vbob->_xp + width, vbob->_yp + height);
+			_vm->_graphicsManager.addDirtyRect(vbob->_xp, vbob->_yp , vbob->_xp + width, vbob->_yp + height);
 			vbob->field4 = 2;
 		}
 	}
@@ -2095,7 +2095,7 @@ void ObjectsManager::changeCharacterHead(PlayerCharacter oldCharacter, PlayerCha
 
 	_changeHeadFl = true;
 	_vm->_graphicsManager.copySurface(_vm->_graphicsManager._vesaScreen, 532, 25, 65, 40, _vm->_graphicsManager._vesaBuffer, 532, 25);
-	_vm->_graphicsManager.addVesaSegment(532, 25, 597, 65);
+	_vm->_graphicsManager.addDirtyRect(532, 25, 597, 65);
 	_vm->_globals._checkDistanceFl = true;
 	_vm->_linesManager._route = (RouteItem *)g_PTRNUL;
 


Commit: c3bab0aecbb00f55493a0816c217d33dc9359793
    https://github.com/scummvm/scummvm/commit/c3bab0aecbb00f55493a0816c217d33dc9359793
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2013-03-02T07:53:11-08:00

Commit Message:
HOPKINS: Cleaned up the addDirtyRect method

Changed paths:
    engines/hopkins/graphics.cpp



diff --git a/engines/hopkins/graphics.cpp b/engines/hopkins/graphics.cpp
index 3133232..ea65ad7 100644
--- a/engines/hopkins/graphics.cpp
+++ b/engines/hopkins/graphics.cpp
@@ -1103,29 +1103,25 @@ void GraphicsManager::resetVesaSegment() {
 
 // Add VESA Segment
 void GraphicsManager::addDirtyRect(int x1, int y1, int x2, int y2) {
-	int tempX = x1;
 	bool addFlag = true;
-	if (x2 > _maxX)
-		x2 = _maxX;
-	if (y2 > _maxY)
-		y2 = _maxY;
-	if (x1 < _minX)
-		tempX = _minX;
-	if (y1 < _minY)
-		y1 = _minY;
+
+	x1 = CLIP(x1, _minX, _maxX);
+	y1 = CLIP(y1, _minY, _maxY);
+	x2 = CLIP(x2, _minX, _maxX);
+	y2 = CLIP(y2, _minY, _maxY);
 
 	for (int blocIndex = 0; blocIndex <= _dirtyRectCount; blocIndex++) {
 		BlocItem &bloc = _dirtyRects[blocIndex];
-		if (bloc._activeFl && tempX >= bloc._x1 && x2 <= bloc._x2 && y1 >= bloc._y1 && y2 <= bloc._y2)
+		if (bloc._activeFl && x1 >= bloc._x1 && x2 <= bloc._x2 && y1 >= bloc._y1 && y2 <= bloc._y2)
 			addFlag = false;
 	};
 
-	if (addFlag) {
+	if (addFlag && (x2 > x1) && (y2 > y1)) {
 		assert(_dirtyRectCount < DIRTY_RECTS_SIZE);
 		BlocItem &bloc = _dirtyRects[++_dirtyRectCount];
 
 		bloc._activeFl = true;
-		bloc._x1 = tempX;
+		bloc._x1 = x1;
 		bloc._x2 = x2;
 		bloc._y1 = y1;
 		bloc._y2 = y2;


Commit: d738802bc1d1441fee8bce3881cd5233044305d6
    https://github.com/scummvm/scummvm/commit/d738802bc1d1441fee8bce3881cd5233044305d6
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2013-03-02T14:30:42-08:00

Commit Message:
HOPKINS: Converted dirty rects to use Common::Array

Changed paths:
    engines/hopkins/graphics.cpp
    engines/hopkins/graphics.h
    engines/hopkins/script.cpp



diff --git a/engines/hopkins/graphics.cpp b/engines/hopkins/graphics.cpp
index ea65ad7..c998a3b 100644
--- a/engines/hopkins/graphics.cpp
+++ b/engines/hopkins/graphics.cpp
@@ -47,7 +47,6 @@ GraphicsManager::GraphicsManager() {
 	_scrollPosX = 0;
 	_largeScreenFl = false;
 	_oldScrollPosX = 0;
-	_dirtyRectCount = 0;
 	_vesaScreen = NULL;
 	_vesaBuffer = NULL;
 	_screenBuffer = NULL;
@@ -76,10 +75,6 @@ GraphicsManager::GraphicsManager() {
 	Common::fill(&_colorTable[0], &_colorTable[PALETTE_EXT_BLOCK_SIZE], 0);
 	Common::fill(&_palette[0], &_palette[PALETTE_EXT_BLOCK_SIZE], 0);
 	Common::fill(&_oldPalette[0], &_oldPalette[PALETTE_EXT_BLOCK_SIZE], 0);
-
-	for (int i = 0; i < DIRTY_RECTS_SIZE; ++i)
-		Common::fill((byte *)&_dirtyRects[i], (byte *)&_dirtyRects[i] + sizeof(BlocItem), 0);
-
 }
 
 GraphicsManager::~GraphicsManager() {
@@ -1095,72 +1090,62 @@ void GraphicsManager::displayAllBob() {
 }
 
 void GraphicsManager::resetVesaSegment() {
-	for (int idx = 0; idx <= _dirtyRectCount; idx++)
-		_dirtyRects[idx]._activeFl = false;
-
-	_dirtyRectCount = 0;
+	_dirtyRects.clear();
 }
 
 // Add VESA Segment
 void GraphicsManager::addDirtyRect(int x1, int y1, int x2, int y2) {
-	bool addFlag = true;
-
 	x1 = CLIP(x1, _minX, _maxX);
 	y1 = CLIP(y1, _minY, _maxY);
 	x2 = CLIP(x2, _minX, _maxX);
 	y2 = CLIP(y2, _minY, _maxY);
 
-	for (int blocIndex = 0; blocIndex <= _dirtyRectCount; blocIndex++) {
-		BlocItem &bloc = _dirtyRects[blocIndex];
-		if (bloc._activeFl && x1 >= bloc._x1 && x2 <= bloc._x2 && y1 >= bloc._y1 && y2 <= bloc._y2)
-			addFlag = false;
-	};
-
-	if (addFlag && (x2 > x1) && (y2 > y1)) {
-		assert(_dirtyRectCount < DIRTY_RECTS_SIZE);
-		BlocItem &bloc = _dirtyRects[++_dirtyRectCount];
-
-		bloc._activeFl = true;
-		bloc._x1 = x1;
-		bloc._x2 = x2;
-		bloc._y1 = y1;
-		bloc._y2 = y2;
+	Common::Rect newRect(x1, y1, x2, y2);
+	if (!newRect.isValidRect())
+		return;
+
+	// Don't bother adding the rect if it's contained within another existing one
+	for (uint rectIndex = 0; rectIndex < _dirtyRects.size(); ++rectIndex) {
+		const Common::Rect &r = _dirtyRects[rectIndex];
+		if (r.contains(newRect))
+			return;
 	}
+
+	assert(_dirtyRects.size() < DIRTY_RECTS_SIZE);
+	_dirtyRects.push_back(newRect);
 }
 
 // Display VESA Segment
 void GraphicsManager::displayVesaSegment() {
-	if (_dirtyRectCount == 0)
+	if (_dirtyRects.size() == 0)
 		return;
 
 	lockScreen();
 
-	for (int idx = 1; idx <= _dirtyRectCount; ++idx) {
-		BlocItem &bloc = _dirtyRects[idx];
-		Common::Rect &dstRect = dstrect[idx - 1];
-		if (!bloc._activeFl)
-			continue;
+	for (uint idx = 0; idx < _dirtyRects.size(); ++idx) {
+		Common::Rect &r = _dirtyRects[idx];
+		Common::Rect &dstRect = dstrect[idx];
 
 		if (_vm->_eventsManager._breakoutFl) {
-			Copy_Vga16(_vesaBuffer, bloc._x1, bloc._y1, bloc._x2 - bloc._x1, bloc._y2 - bloc._y1, bloc._x1, bloc._y1);
-			dstRect.left = bloc._x1 * 2;
-			dstRect.top = bloc._y1 * 2 + 30;
-			dstRect.setWidth((bloc._x2 - bloc._x1) * 2);
-			dstRect.setHeight((bloc._y2 - bloc._y1) * 2);
-		} else if (bloc._x2 > _vm->_eventsManager._startPos.x && bloc._x1 < _vm->_eventsManager._startPos.x + SCREEN_WIDTH) {
-			if (bloc._x1 < _vm->_eventsManager._startPos.x)
-				bloc._x1 = _vm->_eventsManager._startPos.x;
-			if (bloc._x2 > _vm->_eventsManager._startPos.x + SCREEN_WIDTH)
-				bloc._x2 = _vm->_eventsManager._startPos.x + SCREEN_WIDTH;
+			Copy_Vga16(_vesaBuffer, r.left, r.top, r.right - r.left, r.bottom - r.top, r.left, r.top);
+			dstRect.left = r.left * 2;
+			dstRect.top = r.top * 2 + 30;
+			dstRect.setWidth((r.right - r.left) * 2);
+			dstRect.setHeight((r.bottom - r.top) * 2);
+		} else if (r.right > _vm->_eventsManager._startPos.x && r.left < _vm->_eventsManager._startPos.x + SCREEN_WIDTH) {
+			if (r.left < _vm->_eventsManager._startPos.x)
+				r.left = _vm->_eventsManager._startPos.x;
+			if (r.right > _vm->_eventsManager._startPos.x + SCREEN_WIDTH)
+				r.right = _vm->_eventsManager._startPos.x + SCREEN_WIDTH;
 
 			// WORKAROUND: Original didn't lock the screen for access
 			lockScreen();
-			m_scroll16(_vesaBuffer, bloc._x1, bloc._y1, bloc._x2 - bloc._x1, bloc._y2 - bloc._y1, bloc._x1 - _vm->_eventsManager._startPos.x, bloc._y1);
+			m_scroll16(_vesaBuffer, r.left, r.top, r.right - r.left, r.bottom - r.top, r.left - _vm->_eventsManager._startPos.x, r.top);
 
-			dstRect.left = bloc._x1 - _vm->_eventsManager._startPos.x;
-			dstRect.top = bloc._y1;
-			dstRect.setWidth(bloc._x2 - bloc._x1);
-			dstRect.setHeight(bloc._y2 - bloc._y1);
+			dstRect.left = r.left - _vm->_eventsManager._startPos.x;
+			dstRect.top = r.top;
+			dstRect.setWidth(r.right - r.left);
+			dstRect.setHeight(r.bottom - r.top);
 
 			unlockScreen();
 		}
@@ -1168,12 +1153,10 @@ void GraphicsManager::displayVesaSegment() {
 		byte *srcP = _videoPtr + WinScan * dstRect.top + (dstRect.left * 2);
 		g_system->copyRectToScreen(srcP, WinScan, dstRect.left, dstRect.top, 
 			dstRect.width(), dstRect.height());
-
-		_dirtyRects[idx]._activeFl = false;
 	}
 
 	unlockScreen();
-	_dirtyRectCount = 0;	
+	resetVesaSegment();
 }
 
 void GraphicsManager::AFFICHE_SPEEDVGA(const byte *objectData, int xp, int yp, int idx, bool addSegment) {
diff --git a/engines/hopkins/graphics.h b/engines/hopkins/graphics.h
index 0db51a0..72fd87c 100644
--- a/engines/hopkins/graphics.h
+++ b/engines/hopkins/graphics.h
@@ -24,6 +24,7 @@
 #define HOPKINS_GRAPHICS_H
 
 #include "common/scummsys.h"
+#include "common/array.h"
 #include "common/endian.h"
 #include "common/rect.h"
 #include "common/str.h"
@@ -46,14 +47,6 @@ struct RGB8 {
 	byte b;
 };
 
-struct BlocItem {
-	uint16 _activeFl;
-	int _x1;
-	int _y1;
-	int _x2;
-	int _y2;
-};
-
 class HopkinsEngine;
 
 class GraphicsManager {
@@ -111,8 +104,7 @@ public:
 	bool _skipVideoLockFl;
 	int _fadeDefaultSpeed;
 
-	int _dirtyRectCount;
-	BlocItem _dirtyRects[DIRTY_RECTS_SIZE];
+	Common::Array<Common::Rect> _dirtyRects;
 	int WinScan;
 	byte *PAL_PIXELS;
 	bool MANU_SCROLL;
diff --git a/engines/hopkins/script.cpp b/engines/hopkins/script.cpp
index 993bd2b..55cbe00 100644
--- a/engines/hopkins/script.cpp
+++ b/engines/hopkins/script.cpp
@@ -2337,7 +2337,7 @@ int ScriptManager::handleOpcode(byte *dataP) {
 				memcpy(_vm->_graphicsManager._oldPalette, _vm->_graphicsManager._palette, 769);
 				_vm->_animationManager.playAnim2("PLAN.ANM", 50, 10, 800);
 			}
-			_vm->_graphicsManager._dirtyRectCount = 0;
+			_vm->_graphicsManager.resetVesaSegment();
 			break;
 
 		case 608:


Commit: 7c862d586ede81d759eafae831f8fd54684d92bd
    https://github.com/scummvm/scummvm/commit/7c862d586ede81d759eafae831f8fd54684d92bd
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2013-03-02T15:56:14-08:00

Commit Message:
HOPKINS: Preparatory work for a refresh rect list

Changed paths:
    engines/hopkins/events.cpp
    engines/hopkins/graphics.cpp
    engines/hopkins/graphics.h



diff --git a/engines/hopkins/events.cpp b/engines/hopkins/events.cpp
index 3a6d31a..519bd64 100644
--- a/engines/hopkins/events.cpp
+++ b/engines/hopkins/events.cpp
@@ -222,7 +222,7 @@ void EventsManager::checkForNextFrameCounter() {
 	if ((milli - _priorFrameTime) >= GAME_FRAME_TIME) {
 		++_gameCounter;
 		_priorFrameTime = milli;
-		g_system->updateScreen();
+		_vm->_graphicsManager.DD_VBL();
 
 		// Signal the ScummVM debugger
 		_vm->_debugger.onFrame();
@@ -465,7 +465,9 @@ void EventsManager::VBL() {
 			_vm->_graphicsManager.lockScreen();
 			_vm->_graphicsManager.m_scroll16(_vm->_graphicsManager._vesaBuffer, _vm->_graphicsManager._scrollPosX, 20, SCREEN_WIDTH, 440, 0, 20);
 			_vm->_graphicsManager.unlockScreen();
-			_vm->_graphicsManager.dstrect[0] = Common::Rect(0, 20, SCREEN_WIDTH, 460);
+			
+			_vm->_graphicsManager.resetRefreshRects();
+			_vm->_graphicsManager.addRefreshRect(Common::Rect(0, 20, SCREEN_WIDTH, 460));
 
 			_vm->_graphicsManager.resetVesaSegment();
 
diff --git a/engines/hopkins/graphics.cpp b/engines/hopkins/graphics.cpp
index c998a3b..4fe9c4e 100644
--- a/engines/hopkins/graphics.cpp
+++ b/engines/hopkins/graphics.cpp
@@ -612,7 +612,7 @@ void GraphicsManager::fadeOut(const byte *palette, int step, const byte *surface
 
 	setPaletteVGA256(palData);
 	m_scroll16(surface, _vm->_eventsManager._startPos.x, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
-	return DD_VBL();
+	DD_VBL();
 }
 
 /** 
@@ -735,7 +735,10 @@ uint16 GraphicsManager::mapRGB(byte r, byte g, byte b) {
 }
 
 void GraphicsManager::DD_VBL() {
-	// TODO: Is this okay here?
+	// Display any aras of the screen that need refreshing
+	displayRefreshRects();
+
+	// Update the screen
 	g_system->updateScreen();
 }
 
@@ -1093,7 +1096,11 @@ void GraphicsManager::resetVesaSegment() {
 	_dirtyRects.clear();
 }
 
-// Add VESA Segment
+void GraphicsManager::resetRefreshRects() {
+	_refreshRects.clear();
+}
+
+// Add a game area dirty rectangle
 void GraphicsManager::addDirtyRect(int x1, int y1, int x2, int y2) {
 	x1 = CLIP(x1, _minX, _maxX);
 	y1 = CLIP(y1, _minY, _maxY);
@@ -1115,7 +1122,19 @@ void GraphicsManager::addDirtyRect(int x1, int y1, int x2, int y2) {
 	_dirtyRects.push_back(newRect);
 }
 
-// Display VESA Segment
+// Add a refresh rect
+void GraphicsManager::addRefreshRect(const Common::Rect &r) {
+	// Ensure that an existing dest rectangle doesn't already contain the new one
+	for (uint idx = 0; idx < _refreshRects.size(); ++idx) {
+		if (_refreshRects[idx].contains(r))
+			return;
+	}
+
+	assert(_refreshRects.size() < DIRTY_RECTS_SIZE);
+	_refreshRects.push_back(r);
+}
+
+// Draw any game dirty rects onto the screen intermediate surface
 void GraphicsManager::displayVesaSegment() {
 	if (_dirtyRects.size() == 0)
 		return;
@@ -1124,7 +1143,7 @@ void GraphicsManager::displayVesaSegment() {
 
 	for (uint idx = 0; idx < _dirtyRects.size(); ++idx) {
 		Common::Rect &r = _dirtyRects[idx];
-		Common::Rect &dstRect = dstrect[idx];
+		Common::Rect dstRect;
 
 		if (_vm->_eventsManager._breakoutFl) {
 			Copy_Vga16(_vesaBuffer, r.left, r.top, r.right - r.left, r.bottom - r.top, r.left, r.top);
@@ -1159,6 +1178,19 @@ void GraphicsManager::displayVesaSegment() {
 	resetVesaSegment();
 }
 
+void GraphicsManager::displayRefreshRects() {
+	if (_refreshRects.size() == 0)
+		return;
+/*
+	for (uint idx = 0; idx < _refreshRects.size(); ++idx) {
+		const Common::Rect &r = _refreshRects[idx];
+
+		g_system->copyRectToScreen(_screenBuffer, WinScan,)
+	}
+*/
+	resetRefreshRects();
+}
+
 void GraphicsManager::AFFICHE_SPEEDVGA(const byte *objectData, int xp, int yp, int idx, bool addSegment) {
 	int width = _vm->_objectsManager.getWidth(objectData, idx);
 	int height = _vm->_objectsManager.getHeight(objectData, idx);
diff --git a/engines/hopkins/graphics.h b/engines/hopkins/graphics.h
index 72fd87c..367b0a2 100644
--- a/engines/hopkins/graphics.h
+++ b/engines/hopkins/graphics.h
@@ -99,12 +99,18 @@ public:
 	int _minX, _minY;
 	int _maxX, _maxY;
 	bool _noFadingFl;
-	Common::Rect dstrect[50];
 	int _scrollStatus;
 	bool _skipVideoLockFl;
 	int _fadeDefaultSpeed;
 
+	/**
+	 * The _dirtyRects list contains paletted game areas that need to be redrawn. 
+	 * The _dstrect array is the list of areas of the screen that ScummVM needs to be redrawn.
+	 * Some areas, such as the animation managers, skip the _dirtyRects and use _dstrec directly.
+	 */
 	Common::Array<Common::Rect> _dirtyRects;
+	Common::Array<Common::Rect> _refreshRects;
+
 	int WinScan;
 	byte *PAL_PIXELS;
 	bool MANU_SCROLL;
@@ -118,7 +124,12 @@ public:
 	void unlockScreen();
 	void clearPalette();
 	void clearScreen();
+	void resetVesaSegment();
+	void resetRefreshRects();
 	void addDirtyRect(int x1, int y1, int x2, int y2);
+	void addRefreshRect(const Common::Rect &r);
+	void displayVesaSegment();
+	void displayRefreshRects();
 	void copySurface(const byte *surface, int x1, int y1, int width, int height, byte *destSurface, int destX, int destY);
 	void loadImage(const Common::String &file);
 	void loadVgaImage(const Common::String &file);
@@ -131,8 +142,6 @@ public:
 	void fadeOutLong();
 	void fadeOutShort();
 	void fastDisplay(const byte *spriteData, int xp, int yp, int spriteIndex, bool addSegment = true);
-	void displayVesaSegment();
-	void resetVesaSegment();
 	void copyWinscanVbe3(const byte *srcData, byte *destSurface);
 	void copyWinscanVbe(const byte *srcP, byte *destP);
 	void copyVideoVbe16(const byte *srcData);


Commit: 95aca78bcdc42a2765220c2fbd990539168b15b5
    https://github.com/scummvm/scummvm/commit/95aca78bcdc42a2765220c2fbd990539168b15b5
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2013-03-02T17:40:03-08:00

Commit Message:
HOPKINS: Renamed dirty rect methods

Changed paths:
    engines/hopkins/computer.cpp
    engines/hopkins/events.cpp
    engines/hopkins/graphics.cpp
    engines/hopkins/graphics.h
    engines/hopkins/hopkins.cpp
    engines/hopkins/objects.cpp
    engines/hopkins/script.cpp



diff --git a/engines/hopkins/computer.cpp b/engines/hopkins/computer.cpp
index 37f1dd2..b1f71cd 100644
--- a/engines/hopkins/computer.cpp
+++ b/engines/hopkins/computer.cpp
@@ -127,7 +127,7 @@ void ComputerManager::setTextPosition(int yp, int xp) {
  */
 void ComputerManager::showComputer(ComputerEnum mode) {
 	_vm->_eventsManager._escKeyFl = false;
-	_vm->_graphicsManager.resetVesaSegment();
+	_vm->_graphicsManager.resetDirtyRects();
 	setVideoMode();
 	setTextColor(4);
 	setTextPosition(2, 4);
@@ -287,7 +287,7 @@ void ComputerManager::showComputer(ComputerEnum mode) {
 	else // Free access or Samantha
 		_vm->_globals._exitId = 14;
 
-	_vm->_graphicsManager.resetVesaSegment();
+	_vm->_graphicsManager.resetDirtyRects();
 }
 
 static const char _englishText[] = 
@@ -557,9 +557,9 @@ void ComputerManager::displayGamesSubMenu() {
 	loadHiscore();
 	setModeVGA256();
 	newLevel();
-	_vm->_graphicsManager.resetVesaSegment();
+	_vm->_graphicsManager.resetDirtyRects();
 	playBreakout();
-	_vm->_graphicsManager.resetVesaSegment();
+	_vm->_graphicsManager.resetDirtyRects();
 	_breakoutSpr = _vm->_globals.freeMemory(_breakoutSpr);
 	_breakoutLevel = (int16 *)_vm->_globals.freeMemory((byte *)_breakoutLevel);
 	_vm->_objectsManager._sprite[0]._spriteData = oldSpriteData;
@@ -726,7 +726,7 @@ void ComputerManager::playBreakout() {
 			_ballPosition = Common::Point(_padPositionX + 14, 187);
 			_vm->_objectsManager.setSpriteY(1, 187);
 			_vm->_objectsManager.setSpriteX(1, _ballPosition.x);
-			_vm->_graphicsManager.resetVesaSegment();
+			_vm->_graphicsManager.resetDirtyRects();
 			_vm->_eventsManager.VBL();
 			_vm->_graphicsManager.fadeInBreakout();
 
@@ -801,7 +801,7 @@ void ComputerManager::playBreakout() {
  * @return		The selected button index: 1 = Game, 2 = Quit
  */
 int ComputerManager::displayHiscores() {
-	_vm->_graphicsManager.resetVesaSegment();
+	_vm->_graphicsManager.resetDirtyRects();
 	loadHiscore();
 	_vm->_graphicsManager.loadVgaImage("HISCORE.PCX");
 	byte *ptr = _vm->_fileManager.loadFile("ALPHA.SPR");
@@ -827,7 +827,7 @@ int ComputerManager::displayHiscores() {
 	}
 
 	_vm->_graphicsManager.fadeInBreakout();
-	_vm->_graphicsManager.resetVesaSegment();
+	_vm->_graphicsManager.resetDirtyRects();
 	int buttonIndex = 0;
 	do {
 		_vm->_eventsManager.refreshEvents();
diff --git a/engines/hopkins/events.cpp b/engines/hopkins/events.cpp
index 519bd64..b64f0cd 100644
--- a/engines/hopkins/events.cpp
+++ b/engines/hopkins/events.cpp
@@ -446,7 +446,7 @@ void EventsManager::VBL() {
 	_vm->_globals._speed = 2;
 	_rateCounter = 0;
 	if (!_vm->_graphicsManager._largeScreenFl || _vm->_graphicsManager._scrollStatus == 1) {
-		_vm->_graphicsManager.displayVesaSegment();
+		_vm->_graphicsManager.displayDirtyRects();
 	} else {
 		if (_vm->_graphicsManager._scrollStatus != 2) {
 			if (getMouseX() > _vm->_graphicsManager._scrollPosX + 620)
@@ -459,7 +459,7 @@ void EventsManager::VBL() {
 		if (_vm->_graphicsManager._scrollPosX > SCREEN_WIDTH)
 			_vm->_graphicsManager._scrollPosX = SCREEN_WIDTH;
 		if (_vm->_graphicsManager._oldScrollPosX == _vm->_graphicsManager._scrollPosX) {
-			_vm->_graphicsManager.displayVesaSegment();
+			_vm->_graphicsManager.displayDirtyRects();
 		} else {
 			_vm->_fontManager.hideText(9);
 			_vm->_graphicsManager.lockScreen();
@@ -469,7 +469,7 @@ void EventsManager::VBL() {
 			_vm->_graphicsManager.resetRefreshRects();
 			_vm->_graphicsManager.addRefreshRect(Common::Rect(0, 20, SCREEN_WIDTH, 460));
 
-			_vm->_graphicsManager.resetVesaSegment();
+			_vm->_graphicsManager.resetDirtyRects();
 
 			_startPos.x = _vm->_graphicsManager._scrollPosX;
 			_vm->_graphicsManager._scrollOffset = _vm->_graphicsManager._scrollPosX;
diff --git a/engines/hopkins/graphics.cpp b/engines/hopkins/graphics.cpp
index 4fe9c4e..75280c4 100644
--- a/engines/hopkins/graphics.cpp
+++ b/engines/hopkins/graphics.cpp
@@ -1092,7 +1092,7 @@ void GraphicsManager::displayAllBob() {
 	}
 }
 
-void GraphicsManager::resetVesaSegment() {
+void GraphicsManager::resetDirtyRects() {
 	_dirtyRects.clear();
 }
 
@@ -1135,7 +1135,7 @@ void GraphicsManager::addRefreshRect(const Common::Rect &r) {
 }
 
 // Draw any game dirty rects onto the screen intermediate surface
-void GraphicsManager::displayVesaSegment() {
+void GraphicsManager::displayDirtyRects() {
 	if (_dirtyRects.size() == 0)
 		return;
 
@@ -1175,7 +1175,7 @@ void GraphicsManager::displayVesaSegment() {
 	}
 
 	unlockScreen();
-	resetVesaSegment();
+	resetDirtyRects();
 }
 
 void GraphicsManager::displayRefreshRects() {
diff --git a/engines/hopkins/graphics.h b/engines/hopkins/graphics.h
index 367b0a2..bdd8fee 100644
--- a/engines/hopkins/graphics.h
+++ b/engines/hopkins/graphics.h
@@ -124,11 +124,11 @@ public:
 	void unlockScreen();
 	void clearPalette();
 	void clearScreen();
-	void resetVesaSegment();
+	void resetDirtyRects();
 	void resetRefreshRects();
 	void addDirtyRect(int x1, int y1, int x2, int y2);
 	void addRefreshRect(const Common::Rect &r);
-	void displayVesaSegment();
+	void displayDirtyRects();
 	void displayRefreshRects();
 	void copySurface(const byte *surface, int x1, int y1, int width, int height, byte *destSurface, int destX, int destY);
 	void loadImage(const Common::String &file);
diff --git a/engines/hopkins/hopkins.cpp b/engines/hopkins/hopkins.cpp
index 3d4d152..5e55c28 100644
--- a/engines/hopkins/hopkins.cpp
+++ b/engines/hopkins/hopkins.cpp
@@ -343,7 +343,7 @@ bool HopkinsEngine::runWin95Demo() {
 			memset(_graphicsManager._vesaBuffer, 0, 307200);
 			memset(_graphicsManager._vesaScreen, 0, 307200);
 			_graphicsManager.clearPalette();
-			_graphicsManager.resetVesaSegment();
+			_graphicsManager.resetDirtyRects();
 			break;
 
 		case 114:
@@ -661,7 +661,7 @@ bool HopkinsEngine::runLinuxDemo() {
 			memset(_graphicsManager._vesaBuffer, 0, 307200);
 			memset(_graphicsManager._vesaScreen, 0, 307200);
 			_graphicsManager.clearPalette();
-			_graphicsManager.resetVesaSegment();
+			_graphicsManager.resetDirtyRects();
 			break;
 
 		case 114:
@@ -1434,7 +1434,7 @@ bool HopkinsEngine::runFull() {
 			memset(_graphicsManager._vesaBuffer, 0, 307200);
 			memset(_graphicsManager._vesaScreen, 0, 307200);
 			_graphicsManager.clearPalette();
-			_graphicsManager.resetVesaSegment();
+			_graphicsManager.resetDirtyRects();
 			break;
 
 		case 114:
@@ -1905,7 +1905,7 @@ void HopkinsEngine::restoreSystem() {
 
 void HopkinsEngine::endLinuxDemo() {
 	_globals._linuxEndDemoFl = true;
-	_graphicsManager.resetVesaSegment();
+	_graphicsManager.resetDirtyRects();
 	_objectsManager._forestFl = false;
 	_eventsManager._breakoutFl = false;
 	_globals._disableInventFl = true;
diff --git a/engines/hopkins/objects.cpp b/engines/hopkins/objects.cpp
index 20d14af..26c0d1c 100644
--- a/engines/hopkins/objects.cpp
+++ b/engines/hopkins/objects.cpp
@@ -2082,7 +2082,7 @@ void ObjectsManager::clearScreen() {
 	_changeVerbFl = false;
 	_vm->_linesManager._route = (RouteItem *)g_PTRNUL;
 	_vm->_globals._oldDirection = DIR_NONE;
-	_vm->_graphicsManager.resetVesaSegment();
+	_vm->_graphicsManager.resetDirtyRects();
 }
 
 /**
diff --git a/engines/hopkins/script.cpp b/engines/hopkins/script.cpp
index 55cbe00..c9413c1 100644
--- a/engines/hopkins/script.cpp
+++ b/engines/hopkins/script.cpp
@@ -2337,7 +2337,7 @@ int ScriptManager::handleOpcode(byte *dataP) {
 				memcpy(_vm->_graphicsManager._oldPalette, _vm->_graphicsManager._palette, 769);
 				_vm->_animationManager.playAnim2("PLAN.ANM", 50, 10, 800);
 			}
-			_vm->_graphicsManager.resetVesaSegment();
+			_vm->_graphicsManager.resetDirtyRects();
 			break;
 
 		case 608:


Commit: 9d8eb97840072ee2c55dabdaf07c05b4db086eea
    https://github.com/scummvm/scummvm/commit/9d8eb97840072ee2c55dabdaf07c05b4db086eea
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2013-03-02T17:57:42-08:00

Commit Message:
HOPKINS: Hooked up display code for refresh rects

Changed paths:
    engines/hopkins/graphics.cpp



diff --git a/engines/hopkins/graphics.cpp b/engines/hopkins/graphics.cpp
index 75280c4..c7b6904 100644
--- a/engines/hopkins/graphics.cpp
+++ b/engines/hopkins/graphics.cpp
@@ -162,6 +162,8 @@ void GraphicsManager::unlockScreen() {
 void GraphicsManager::clearScreen() {
 	assert(_videoPtr);
 	Common::fill(_videoPtr, _videoPtr + WinScan * _screenHeight, 0);
+	if (!_isPhysicalPtr)
+		addRefreshRect(Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
 }
 
 /**
@@ -1179,15 +1181,14 @@ void GraphicsManager::displayDirtyRects() {
 }
 
 void GraphicsManager::displayRefreshRects() {
-	if (_refreshRects.size() == 0)
-		return;
-/*
+	// Loop through copying over any  specified rects to the screen
 	for (uint idx = 0; idx < _refreshRects.size(); ++idx) {
 		const Common::Rect &r = _refreshRects[idx];
 
-		g_system->copyRectToScreen(_screenBuffer, WinScan,)
+		byte *srcP = _screenBuffer + WinScan * r.top + (r.left * 2);
+		g_system->copyRectToScreen(srcP, WinScan, r.left, r.top, r.width(), r.height());
 	}
-*/
+
 	resetRefreshRects();
 }
 


Commit: 77eb6f74eb17deda5e629457ca4ec144782fddfe
    https://github.com/scummvm/scummvm/commit/77eb6f74eb17deda5e629457ca4ec144782fddfe
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2013-03-02T18:47:03-08:00

Commit Message:
HOPKINS: Fix to not display dirty rects that are off-screen

Changed paths:
    engines/hopkins/graphics.cpp



diff --git a/engines/hopkins/graphics.cpp b/engines/hopkins/graphics.cpp
index c7b6904..0c06ef7 100644
--- a/engines/hopkins/graphics.cpp
+++ b/engines/hopkins/graphics.cpp
@@ -1171,9 +1171,12 @@ void GraphicsManager::displayDirtyRects() {
 			unlockScreen();
 		}
 
-		byte *srcP = _videoPtr + WinScan * dstRect.top + (dstRect.left * 2);
-		g_system->copyRectToScreen(srcP, WinScan, dstRect.left, dstRect.top, 
-			dstRect.width(), dstRect.height());
+		// If it's a valid rect, then copy it over
+		if (dstRect.isValidRect() && dstRect.width() > 0 && dstRect.height() > 0) {
+			byte *srcP = _videoPtr + WinScan * dstRect.top + (dstRect.left * 2);
+			g_system->copyRectToScreen(srcP, WinScan, dstRect.left, dstRect.top, 
+				dstRect.width(), dstRect.height());
+		}
 	}
 
 	unlockScreen();


Commit: 7a7b2b35e2be1e6526d8aeea2576e8c9231aa73c
    https://github.com/scummvm/scummvm/commit/7a7b2b35e2be1e6526d8aeea2576e8c9231aa73c
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2013-03-02T19:36:38-08:00

Commit Message:
HOPKINS: Added a debugger command to frame dirty rects

Changed paths:
    engines/hopkins/debugger.cpp
    engines/hopkins/debugger.h
    engines/hopkins/graphics.cpp
    engines/hopkins/graphics.h



diff --git a/engines/hopkins/debugger.cpp b/engines/hopkins/debugger.cpp
index 0abfd1f..07a0c92 100644
--- a/engines/hopkins/debugger.cpp
+++ b/engines/hopkins/debugger.cpp
@@ -30,10 +30,23 @@ namespace Hopkins {
 
 Debugger::Debugger() : GUI::Debugger() {
 	DCmd_Register("continue", WRAP_METHOD(Debugger, Cmd_Exit));
+	DCmd_Register("rects", WRAP_METHOD(Debugger, cmd_DirtyRects));
 }
 
 void Debugger::setParent(HopkinsEngine *vm) {
 	_vm = vm;
 }
 
+// Turns dirty rects on or off
+bool Debugger::cmd_DirtyRects(int argc, const char **argv) {
+	if (argc != 2) {
+		DebugPrintf("%s: [on | off]\n", argv[0]);
+		return true;
+	} else {
+		_vm->_graphicsManager._showDirtyRects = !strcmp(argv[1], "on");
+		return false;
+	}
+}
+
+
 } // End of namespace Hopkins
diff --git a/engines/hopkins/debugger.h b/engines/hopkins/debugger.h
index aabc95c..1ce018b 100644
--- a/engines/hopkins/debugger.h
+++ b/engines/hopkins/debugger.h
@@ -38,6 +38,8 @@ public:
 	Debugger();
 	virtual ~Debugger() {}
 	void setParent(HopkinsEngine *vm);
+
+	bool cmd_DirtyRects(int argc, const char **argv);
 };
 
 } // End of namespace Hopkins
diff --git a/engines/hopkins/graphics.cpp b/engines/hopkins/graphics.cpp
index 0c06ef7..540c18f 100644
--- a/engines/hopkins/graphics.cpp
+++ b/engines/hopkins/graphics.cpp
@@ -51,6 +51,7 @@ GraphicsManager::GraphicsManager() {
 	_vesaBuffer = NULL;
 	_screenBuffer = NULL;
 	_isPhysicalPtr = false;
+	_showDirtyRects = false;
 
 	_lineNbr2 = 0;
 	Agr_x = Agr_y = 0;
@@ -1142,6 +1143,13 @@ void GraphicsManager::displayDirtyRects() {
 		return;
 
 	lockScreen();
+	
+	// Refresh the entire screen 
+	Graphics::Surface *screenSurface = NULL;
+	if (_showDirtyRects) {
+		screenSurface = g_system->lockScreen();
+		g_system->copyRectToScreen(_screenBuffer, WinScan, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
+	}
 
 	for (uint idx = 0; idx < _dirtyRects.size(); ++idx) {
 		Common::Rect &r = _dirtyRects[idx];
@@ -1176,10 +1184,16 @@ void GraphicsManager::displayDirtyRects() {
 			byte *srcP = _videoPtr + WinScan * dstRect.top + (dstRect.left * 2);
 			g_system->copyRectToScreen(srcP, WinScan, dstRect.left, dstRect.top, 
 				dstRect.width(), dstRect.height());
+
+			if (_showDirtyRects)
+				screenSurface->frameRect(dstRect, 0xffffff);
 		}
 	}
 
 	unlockScreen();
+	if (_showDirtyRects)
+		g_system->unlockScreen();
+
 	resetDirtyRects();
 }
 
diff --git a/engines/hopkins/graphics.h b/engines/hopkins/graphics.h
index bdd8fee..54e4156 100644
--- a/engines/hopkins/graphics.h
+++ b/engines/hopkins/graphics.h
@@ -110,6 +110,7 @@ public:
 	 */
 	Common::Array<Common::Rect> _dirtyRects;
 	Common::Array<Common::Rect> _refreshRects;
+	bool _showDirtyRects;
 
 	int WinScan;
 	byte *PAL_PIXELS;


Commit: f93275b3109943a76bd75163d5f4e5bc2cee982c
    https://github.com/scummvm/scummvm/commit/f93275b3109943a76bd75163d5f4e5bc2cee982c
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2013-03-05T06:42:06-08:00

Commit Message:
HOPKINS: Removed usage of g_system->lockScreen

Changed paths:
    engines/hopkins/anim.cpp
    engines/hopkins/graphics.cpp
    engines/hopkins/graphics.h



diff --git a/engines/hopkins/anim.cpp b/engines/hopkins/anim.cpp
index bc0075b..0818067 100644
--- a/engines/hopkins/anim.cpp
+++ b/engines/hopkins/anim.cpp
@@ -79,7 +79,7 @@ void AnimationManager::playAnim(const Common::String &filename, uint32 rate1, ui
 	f.read(screenP, nbytes);
 
 	if (_clearAnimationFl) {
-		_vm->_graphicsManager.lockScreen(true);
+		_vm->_graphicsManager.lockScreen();
 		_vm->_graphicsManager.clearScreen();
 		_vm->_graphicsManager.unlockScreen();
 	}
@@ -94,12 +94,14 @@ void AnimationManager::playAnim(const Common::String &filename, uint32 rate1, ui
 		_vm->_graphicsManager.setPaletteVGA256(_vm->_graphicsManager._palette);
 	} else {
 		_vm->_graphicsManager.setPaletteVGA256(_vm->_graphicsManager._palette);
-		_vm->_graphicsManager.lockScreen(true);
+		_vm->_graphicsManager.lockScreen();
 		if (hasScreenCopy)
 			_vm->_graphicsManager.m_scroll16A(screenCopy, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
 		else
 			_vm->_graphicsManager.m_scroll16(screenP, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
 		_vm->_graphicsManager.unlockScreen();
+		_vm->_graphicsManager.addRefreshRect(Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
+
 		_vm->_graphicsManager.DD_VBL();
 	}
 	_vm->_eventsManager._rateCounter = 0;
@@ -145,7 +147,7 @@ void AnimationManager::playAnim(const Common::String &filename, uint32 rate1, ui
 
 			if (!_vm->_eventsManager._escKeyFl) {
 				_vm->_eventsManager._rateCounter = 0;
-				_vm->_graphicsManager.lockScreen(true);
+				_vm->_graphicsManager.lockScreen();
 				if (hasScreenCopy) {
 					if (*screenP != kByteStop) {
 						_vm->_graphicsManager.copyWinscanVbe3(screenP, screenCopy);
@@ -155,6 +157,8 @@ void AnimationManager::playAnim(const Common::String &filename, uint32 rate1, ui
 					_vm->_graphicsManager.copyVideoVbe16(screenP);
 				}
 				_vm->_graphicsManager.unlockScreen();
+				_vm->_graphicsManager.addRefreshRect(Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
+
 				_vm->_graphicsManager.DD_VBL();
 				_vm->_soundManager.checkSoundEnd();
 			}
@@ -260,9 +264,10 @@ void AnimationManager::playAnim2(const Common::String &filename, uint32 rate1, u
 		oldScrollPosX = _vm->_graphicsManager._scrollPosX;
 		_vm->_graphicsManager.SCANLINE(SCREEN_WIDTH);
 		_vm->_graphicsManager.scrollScreen(0);
-		_vm->_graphicsManager.lockScreen(true);
+		_vm->_graphicsManager.lockScreen();
 		_vm->_graphicsManager.clearScreen();
 		_vm->_graphicsManager.unlockScreen();
+
 		_vm->_graphicsManager._maxX = SCREEN_WIDTH;
 		if (_vm->_graphicsManager.WinScan / 2 > SCREEN_WIDTH) {
 			hasScreenCopy = true;
@@ -275,12 +280,14 @@ void AnimationManager::playAnim2(const Common::String &filename, uint32 rate1, u
 			_vm->_graphicsManager.setPaletteVGA256(_vm->_graphicsManager._palette);
 		} else {
 			_vm->_graphicsManager.setPaletteVGA256(_vm->_graphicsManager._palette);
-			_vm->_graphicsManager.lockScreen(true);
+			_vm->_graphicsManager.lockScreen();
 			if (hasScreenCopy)
 				_vm->_graphicsManager.m_scroll16A(screenCopy, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
 			else
 				_vm->_graphicsManager.m_scroll16(screenP, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
+
 			_vm->_graphicsManager.unlockScreen();
+			_vm->_graphicsManager.addRefreshRect(Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
 			_vm->_graphicsManager.DD_VBL();
 		}
 		_vm->_eventsManager._rateCounter = 0;
@@ -319,7 +326,7 @@ void AnimationManager::playAnim2(const Common::String &filename, uint32 rate1, u
 			}
 
 			_vm->_eventsManager._rateCounter = 0;
-			_vm->_graphicsManager.lockScreen(true);
+			_vm->_graphicsManager.lockScreen();
 			if (*screenP != kByteStop) {
 				if (hasScreenCopy) {
 					_vm->_graphicsManager.copyWinscanVbe3(screenP, screenCopy);
@@ -329,6 +336,7 @@ void AnimationManager::playAnim2(const Common::String &filename, uint32 rate1, u
 				}
 			}
 			_vm->_graphicsManager.unlockScreen();
+			_vm->_graphicsManager.addRefreshRect(Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
 			_vm->_graphicsManager.DD_VBL();
 			_vm->_soundManager.checkSoundEnd();
 		}
@@ -382,24 +390,27 @@ void AnimationManager::playAnim2(const Common::String &filename, uint32 rate1, u
 
 	memcpy(_vm->_graphicsManager._palette, _vm->_graphicsManager._oldPalette, 769);
 	_vm->_graphicsManager.clearPalette();
-	_vm->_graphicsManager.lockScreen(true);
+	_vm->_graphicsManager.lockScreen();
 	_vm->_graphicsManager.clearScreen();
 	_vm->_graphicsManager.unlockScreen();
+
 	_vm->_graphicsManager._scrollPosX = oldScrollPosX;
 	_vm->_graphicsManager.scrollScreen(oldScrollPosX);
 	if (_vm->_graphicsManager._largeScreenFl) {
 		_vm->_graphicsManager.SCANLINE(2 * SCREEN_WIDTH);
 		_vm->_graphicsManager._maxX = 2 * SCREEN_WIDTH;
-		_vm->_graphicsManager.lockScreen(true);
+		_vm->_graphicsManager.lockScreen();
 		_vm->_graphicsManager.m_scroll16(_vm->_graphicsManager._vesaBuffer, _vm->_eventsManager._startPos.x, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
 	} else {
 		_vm->_graphicsManager.SCANLINE(SCREEN_WIDTH);
 		_vm->_graphicsManager._maxX = SCREEN_WIDTH;
-		_vm->_graphicsManager.lockScreen(true);
+		_vm->_graphicsManager.lockScreen();
 		_vm->_graphicsManager.clearScreen();
 		_vm->_graphicsManager.m_scroll16(_vm->_graphicsManager._vesaBuffer, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
 	}
 	_vm->_graphicsManager.unlockScreen();
+	_vm->_graphicsManager.addRefreshRect(Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
+
 	_vm->_graphicsManager.fadeInShort();
 	_vm->_graphicsManager.DD_VBL();
 
@@ -642,12 +653,14 @@ void AnimationManager::playSequence(const Common::String &file, uint32 rate1, ui
 		}
 		_vm->_graphicsManager.setPaletteVGA256(_vm->_graphicsManager._palette);
 	} else {
-		_vm->_graphicsManager.lockScreen(true);
+		_vm->_graphicsManager.lockScreen();
 		if (hasScreenCopy)
 			_vm->_graphicsManager.m_scroll16A(screenCopy, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
 		else
 			_vm->_graphicsManager.m_scroll16(screenP, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
 		_vm->_graphicsManager.unlockScreen();
+		_vm->_graphicsManager.addRefreshRect(Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
+
 		_vm->_graphicsManager.DD_VBL();
 	}
 	bool skipFl = false;
@@ -718,7 +731,7 @@ void AnimationManager::playSequence(const Common::String &file, uint32 rate1, ui
 				break;
 
 			_vm->_eventsManager._rateCounter = 0;
-			_vm->_graphicsManager.lockScreen(true);
+			_vm->_graphicsManager.lockScreen();
 			if (hasScreenCopy) {
 				if (*screenP != kByteStop) {
 					_vm->_graphicsManager.copyWinscanVbe(screenP, screenCopy);
@@ -728,6 +741,8 @@ void AnimationManager::playSequence(const Common::String &file, uint32 rate1, ui
 				_vm->_graphicsManager.copyVideoVbe16a(screenP);
 			}
 			_vm->_graphicsManager.unlockScreen();
+			_vm->_graphicsManager.addRefreshRect(Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
+
 			_vm->_graphicsManager.DD_VBL();
 			_vm->_soundManager.checkSoundEnd();
 		}
@@ -801,13 +816,15 @@ void AnimationManager::playSequence2(const Common::String &file, uint32 rate1, u
 			}
 			_vm->_graphicsManager.setPaletteVGA256(_vm->_graphicsManager._palette);
 		} else {
-			_vm->_graphicsManager.lockScreen(true);
+			_vm->_graphicsManager.lockScreen();
 			_vm->_graphicsManager.setPaletteVGA256(_vm->_graphicsManager._palette);
 			if (multiScreenFl)
 				_vm->_graphicsManager.m_scroll16A(screenCopy, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
 			else
 				_vm->_graphicsManager.m_scroll16(screenP, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
 			_vm->_graphicsManager.unlockScreen();
+			_vm->_graphicsManager.addRefreshRect(Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
+
 			_vm->_graphicsManager.DD_VBL();
 		}
 		_vm->_eventsManager._rateCounter = 0;
@@ -844,7 +861,7 @@ void AnimationManager::playSequence2(const Common::String &file, uint32 rate1, u
 			}
 
 			_vm->_eventsManager._rateCounter = 0;
-			_vm->_graphicsManager.lockScreen(true);
+			_vm->_graphicsManager.lockScreen();
 			if (multiScreenFl) {
 				if (*screenP != kByteStop) {
 					_vm->_graphicsManager.copyWinscanVbe(screenP, screenCopy);
@@ -854,6 +871,8 @@ void AnimationManager::playSequence2(const Common::String &file, uint32 rate1, u
 				_vm->_graphicsManager.copyVideoVbe16a(screenP);
 			}
 			_vm->_graphicsManager.unlockScreen();
+			_vm->_graphicsManager.addRefreshRect(Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
+			
 			_vm->_graphicsManager.DD_VBL();
 			_vm->_soundManager.checkSoundEnd();
 		}
diff --git a/engines/hopkins/graphics.cpp b/engines/hopkins/graphics.cpp
index 540c18f..ecefe4c 100644
--- a/engines/hopkins/graphics.cpp
+++ b/engines/hopkins/graphics.cpp
@@ -50,7 +50,6 @@ GraphicsManager::GraphicsManager() {
 	_vesaScreen = NULL;
 	_vesaBuffer = NULL;
 	_screenBuffer = NULL;
-	_isPhysicalPtr = false;
 	_showDirtyRects = false;
 
 	_lineNbr2 = 0;
@@ -127,19 +126,11 @@ void GraphicsManager::setGraphicalMode(int width, int height) {
 /**
  * (try to) Lock Screen
  */
-void GraphicsManager::lockScreen(bool shouldUsePhysicalScreen) {
+void GraphicsManager::lockScreen() {
 	if (!_skipVideoLockFl) {
 		if (_lockCounter++ == 0) {
-			if (shouldUsePhysicalScreen) {
-				Graphics::Surface *s = g_system->lockScreen();
-				_videoPtr = (byte *)s->pixels;
-				WinScan = s->pitch;
-			} else {
-				_videoPtr = _screenBuffer;
-				WinScan = SCREEN_WIDTH * 2;
-			}
-
-			_isPhysicalPtr = shouldUsePhysicalScreen;
+			_videoPtr = _screenBuffer;
+			WinScan = SCREEN_WIDTH * 2;
 		}
 	}		
 }
@@ -150,9 +141,6 @@ void GraphicsManager::lockScreen(bool shouldUsePhysicalScreen) {
 void GraphicsManager::unlockScreen() {
 	assert(_videoPtr);
 	if (--_lockCounter == 0) {
-		if (_isPhysicalPtr)
-			g_system->unlockScreen();
-
 		_videoPtr = NULL;
 	}
 }
@@ -163,8 +151,8 @@ void GraphicsManager::unlockScreen() {
 void GraphicsManager::clearScreen() {
 	assert(_videoPtr);
 	Common::fill(_videoPtr, _videoPtr + WinScan * _screenHeight, 0);
-	if (!_isPhysicalPtr)
-		addRefreshRect(Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
+
+	addRefreshRect(Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
 }
 
 /**
@@ -201,7 +189,7 @@ void GraphicsManager::loadVgaImage(const Common::String &file) {
  */
 void GraphicsManager::loadScreen(const Common::String &file) {
 	Common::File f;
-	assert(!_videoPtr || !_isPhysicalPtr);
+	assert(!_videoPtr);
 
 	bool flag = true;
 	if (_vm->_fileManager.searchCat(file, 6) == g_PTRNUL) {
@@ -1198,14 +1186,25 @@ void GraphicsManager::displayDirtyRects() {
 }
 
 void GraphicsManager::displayRefreshRects() {
+	Graphics::Surface *screenSurface = NULL;
+	if (_showDirtyRects) {
+		screenSurface = g_system->lockScreen();
+		g_system->copyRectToScreen(_screenBuffer, WinScan, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
+	}
 	// Loop through copying over any  specified rects to the screen
 	for (uint idx = 0; idx < _refreshRects.size(); ++idx) {
 		const Common::Rect &r = _refreshRects[idx];
 
 		byte *srcP = _screenBuffer + WinScan * r.top + (r.left * 2);
 		g_system->copyRectToScreen(srcP, WinScan, r.left, r.top, r.width(), r.height());
+
+		if (_showDirtyRects)
+			screenSurface->frameRect(r, 0xffffff);
 	}
 
+	if (_showDirtyRects)
+		g_system->unlockScreen();
+
 	resetRefreshRects();
 }
 
diff --git a/engines/hopkins/graphics.h b/engines/hopkins/graphics.h
index 54e4156..bbc3b87 100644
--- a/engines/hopkins/graphics.h
+++ b/engines/hopkins/graphics.h
@@ -58,7 +58,6 @@ private:
 	int _screenWidth;
 	int _screenHeight;
 	byte *_videoPtr;
-	bool _isPhysicalPtr;
 	int _width;
 	int _posXClipped, _posYClipped;
 	bool _clipFl;
@@ -121,7 +120,7 @@ public:
 	~GraphicsManager();
 
 	void setParent(HopkinsEngine *vm);
-	void lockScreen(bool shouldUsePhysicalScreen = false);
+	void lockScreen();
 	void unlockScreen();
 	void clearPalette();
 	void clearScreen();


Commit: 188f7efd0584c975e9e5d2ae38752c7217083cb0
    https://github.com/scummvm/scummvm/commit/188f7efd0584c975e9e5d2ae38752c7217083cb0
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2013-03-05T17:58:43-08:00

Commit Message:
HOPKINS: Fix display of screen images using screen fade in

Changed paths:
    engines/hopkins/graphics.cpp



diff --git a/engines/hopkins/graphics.cpp b/engines/hopkins/graphics.cpp
index ecefe4c..d4e1a25 100644
--- a/engines/hopkins/graphics.cpp
+++ b/engines/hopkins/graphics.cpp
@@ -727,6 +727,7 @@ uint16 GraphicsManager::mapRGB(byte r, byte g, byte b) {
 
 void GraphicsManager::DD_VBL() {
 	// Display any aras of the screen that need refreshing
+	displayDirtyRects();
 	displayRefreshRects();
 
 	// Update the screen


Commit: 83480c5784dd4193fa6b5dd3bb2f7a75ac67715d
    https://github.com/scummvm/scummvm/commit/83480c5784dd4193fa6b5dd3bb2f7a75ac67715d
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2013-03-06T06:46:05-08:00

Commit Message:
HOPKINS: Fix transition between initial version display to intro animation

Changed paths:
    engines/hopkins/graphics.cpp
    engines/hopkins/graphics.h
    engines/hopkins/hopkins.cpp



diff --git a/engines/hopkins/graphics.cpp b/engines/hopkins/graphics.cpp
index d4e1a25..f311693 100644
--- a/engines/hopkins/graphics.cpp
+++ b/engines/hopkins/graphics.cpp
@@ -150,11 +150,18 @@ void GraphicsManager::unlockScreen() {
  */
 void GraphicsManager::clearScreen() {
 	assert(_videoPtr);
-	Common::fill(_videoPtr, _videoPtr + WinScan * _screenHeight, 0);
 
+	Common::fill(_screenBuffer, _screenBuffer + WinScan * _screenHeight, 0);
 	addRefreshRect(Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
 }
 
+void GraphicsManager::clearVesaScreen() {
+	warning("clearVesa");
+	Common::fill(_vesaScreen, _vesaScreen + WinScan * _screenHeight, 0);
+	Common::fill(_vesaBuffer, _vesaBuffer + WinScan * _screenHeight, 0);
+	addDirtyRect(Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
+}
+
 /**
  * Load Image
  */
diff --git a/engines/hopkins/graphics.h b/engines/hopkins/graphics.h
index bbc3b87..33edc6f 100644
--- a/engines/hopkins/graphics.h
+++ b/engines/hopkins/graphics.h
@@ -124,9 +124,11 @@ public:
 	void unlockScreen();
 	void clearPalette();
 	void clearScreen();
+	void clearVesaScreen();
 	void resetDirtyRects();
 	void resetRefreshRects();
 	void addDirtyRect(int x1, int y1, int x2, int y2);
+	void addDirtyRect(const Common::Rect &r) { addDirtyRect(r.left, r.top, r.right, r.bottom); }
 	void addRefreshRect(const Common::Rect &r);
 	void displayDirtyRects();
 	void displayRefreshRects();
diff --git a/engines/hopkins/hopkins.cpp b/engines/hopkins/hopkins.cpp
index 5e55c28..ff82d41 100644
--- a/engines/hopkins/hopkins.cpp
+++ b/engines/hopkins/hopkins.cpp
@@ -757,6 +757,7 @@ bool HopkinsEngine::runFull() {
 		_graphicsManager.fadeInLong();
 		_eventsManager.delay(500);
 		_graphicsManager.fadeOutLong();
+		_graphicsManager.clearVesaScreen();
 	} else {
 		// This piece of code, though named "display_version" in the original, 
 		// displays a "loading please wait" screen.
@@ -764,6 +765,8 @@ bool HopkinsEngine::runFull() {
 		_graphicsManager.fadeInLong();
 		_eventsManager.delay(500);
 		_graphicsManager.fadeOutLong();
+		_graphicsManager.clearVesaScreen();
+
 		_globals.iRegul = 1;
 	}
 


Commit: 55c024494d80b343fc23d8e534153fd9c873f040
    https://github.com/scummvm/scummvm/commit/55c024494d80b343fc23d8e534153fd9c873f040
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2013-03-09T06:44:46-08:00

Commit Message:
HOPKINS: Fix problem with scrolling not working properly

Changed paths:
    engines/hopkins/anim.cpp
    engines/hopkins/events.cpp
    engines/hopkins/graphics.cpp
    engines/hopkins/graphics.h



diff --git a/engines/hopkins/anim.cpp b/engines/hopkins/anim.cpp
index 0818067..89672e8 100644
--- a/engines/hopkins/anim.cpp
+++ b/engines/hopkins/anim.cpp
@@ -100,7 +100,7 @@ void AnimationManager::playAnim(const Common::String &filename, uint32 rate1, ui
 		else
 			_vm->_graphicsManager.m_scroll16(screenP, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
 		_vm->_graphicsManager.unlockScreen();
-		_vm->_graphicsManager.addRefreshRect(Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
+		_vm->_graphicsManager.addRefreshRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
 
 		_vm->_graphicsManager.DD_VBL();
 	}
@@ -157,7 +157,7 @@ void AnimationManager::playAnim(const Common::String &filename, uint32 rate1, ui
 					_vm->_graphicsManager.copyVideoVbe16(screenP);
 				}
 				_vm->_graphicsManager.unlockScreen();
-				_vm->_graphicsManager.addRefreshRect(Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
+				_vm->_graphicsManager.addRefreshRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
 
 				_vm->_graphicsManager.DD_VBL();
 				_vm->_soundManager.checkSoundEnd();
@@ -287,7 +287,7 @@ void AnimationManager::playAnim2(const Common::String &filename, uint32 rate1, u
 				_vm->_graphicsManager.m_scroll16(screenP, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
 
 			_vm->_graphicsManager.unlockScreen();
-			_vm->_graphicsManager.addRefreshRect(Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
+			_vm->_graphicsManager.addRefreshRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
 			_vm->_graphicsManager.DD_VBL();
 		}
 		_vm->_eventsManager._rateCounter = 0;
@@ -336,7 +336,7 @@ void AnimationManager::playAnim2(const Common::String &filename, uint32 rate1, u
 				}
 			}
 			_vm->_graphicsManager.unlockScreen();
-			_vm->_graphicsManager.addRefreshRect(Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
+			_vm->_graphicsManager.addRefreshRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
 			_vm->_graphicsManager.DD_VBL();
 			_vm->_soundManager.checkSoundEnd();
 		}
@@ -409,7 +409,7 @@ void AnimationManager::playAnim2(const Common::String &filename, uint32 rate1, u
 		_vm->_graphicsManager.m_scroll16(_vm->_graphicsManager._vesaBuffer, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
 	}
 	_vm->_graphicsManager.unlockScreen();
-	_vm->_graphicsManager.addRefreshRect(Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
+	_vm->_graphicsManager.addRefreshRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
 
 	_vm->_graphicsManager.fadeInShort();
 	_vm->_graphicsManager.DD_VBL();
@@ -659,7 +659,7 @@ void AnimationManager::playSequence(const Common::String &file, uint32 rate1, ui
 		else
 			_vm->_graphicsManager.m_scroll16(screenP, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
 		_vm->_graphicsManager.unlockScreen();
-		_vm->_graphicsManager.addRefreshRect(Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
+		_vm->_graphicsManager.addRefreshRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
 
 		_vm->_graphicsManager.DD_VBL();
 	}
@@ -741,7 +741,7 @@ void AnimationManager::playSequence(const Common::String &file, uint32 rate1, ui
 				_vm->_graphicsManager.copyVideoVbe16a(screenP);
 			}
 			_vm->_graphicsManager.unlockScreen();
-			_vm->_graphicsManager.addRefreshRect(Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
+			_vm->_graphicsManager.addRefreshRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
 
 			_vm->_graphicsManager.DD_VBL();
 			_vm->_soundManager.checkSoundEnd();
@@ -823,7 +823,7 @@ void AnimationManager::playSequence2(const Common::String &file, uint32 rate1, u
 			else
 				_vm->_graphicsManager.m_scroll16(screenP, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
 			_vm->_graphicsManager.unlockScreen();
-			_vm->_graphicsManager.addRefreshRect(Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
+			_vm->_graphicsManager.addRefreshRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
 
 			_vm->_graphicsManager.DD_VBL();
 		}
@@ -871,7 +871,7 @@ void AnimationManager::playSequence2(const Common::String &file, uint32 rate1, u
 				_vm->_graphicsManager.copyVideoVbe16a(screenP);
 			}
 			_vm->_graphicsManager.unlockScreen();
-			_vm->_graphicsManager.addRefreshRect(Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
+			_vm->_graphicsManager.addRefreshRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
 			
 			_vm->_graphicsManager.DD_VBL();
 			_vm->_soundManager.checkSoundEnd();
diff --git a/engines/hopkins/events.cpp b/engines/hopkins/events.cpp
index b64f0cd..09a19a2 100644
--- a/engines/hopkins/events.cpp
+++ b/engines/hopkins/events.cpp
@@ -467,7 +467,7 @@ void EventsManager::VBL() {
 			_vm->_graphicsManager.unlockScreen();
 			
 			_vm->_graphicsManager.resetRefreshRects();
-			_vm->_graphicsManager.addRefreshRect(Common::Rect(0, 20, SCREEN_WIDTH, 460));
+			_vm->_graphicsManager.addRefreshRect(0, 20, SCREEN_WIDTH, SCREEN_HEIGHT - 20);
 
 			_vm->_graphicsManager.resetDirtyRects();
 
diff --git a/engines/hopkins/graphics.cpp b/engines/hopkins/graphics.cpp
index f311693..b5c0660 100644
--- a/engines/hopkins/graphics.cpp
+++ b/engines/hopkins/graphics.cpp
@@ -152,11 +152,10 @@ void GraphicsManager::clearScreen() {
 	assert(_videoPtr);
 
 	Common::fill(_screenBuffer, _screenBuffer + WinScan * _screenHeight, 0);
-	addRefreshRect(Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
+	addRefreshRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
 }
 
 void GraphicsManager::clearVesaScreen() {
-	warning("clearVesa");
 	Common::fill(_vesaScreen, _vesaScreen + WinScan * _screenHeight, 0);
 	Common::fill(_vesaBuffer, _vesaBuffer + WinScan * _screenHeight, 0);
 	addDirtyRect(Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
@@ -439,7 +438,7 @@ void GraphicsManager::m_scroll16(const byte *surface, int xs, int ys, int width,
 	}
 
 	unlockScreen();
-	addDirtyRect(xs, ys, xs + width, ys + height);
+	addRefreshRect(xs, ys, xs + width, ys + height);
 }
 
 // TODO: See if PAL_PIXELS can be converted to a uint16 array
@@ -499,7 +498,7 @@ void GraphicsManager::m_scroll16A(const byte *surface, int xs, int ys, int width
 		yNext = yCtr - 1;
 	} while (yCtr != 1);
 
-	addDirtyRect(xs, ys, xs + width, ys + width);
+	addRefreshRect(xs, ys, xs + width, ys + width);
 }
 
 void GraphicsManager::Copy_Vga16(const byte *surface, int xp, int yp, int width, int height, int destX, int destY) {
@@ -538,7 +537,7 @@ void GraphicsManager::Copy_Vga16(const byte *surface, int xp, int yp, int width,
 		yCount = yCtr - 1;
 	} while (yCtr != 1);
 
-	addDirtyRect(xp, yp, xp + width, yp + width);
+	addRefreshRect(xp, yp, xp + width, yp + width);
 }
 
 /** 
@@ -1122,15 +1121,18 @@ void GraphicsManager::addDirtyRect(int x1, int y1, int x2, int y2) {
 }
 
 // Add a refresh rect
-void GraphicsManager::addRefreshRect(const Common::Rect &r) {
-	// Ensure that an existing dest rectangle doesn't already contain the new one
-	for (uint idx = 0; idx < _refreshRects.size(); ++idx) {
-		if (_refreshRects[idx].contains(r))
-			return;
-	}
+void GraphicsManager::addRefreshRect(int x1, int y1, int x2, int y2) {
+	x1 = MAX(x1, 0);
+	y1 = MAX(y1, 0);
+	x2 = MIN(x2, SCREEN_WIDTH);
+	y2 = MIN(y2, SCREEN_HEIGHT);
 
-	assert(_refreshRects.size() < DIRTY_RECTS_SIZE);
-	_refreshRects.push_back(r);
+	if ((x2 > x1) && (y2 > y1)) {
+		Common::Rect r(x1, y1, x2, y2);
+
+		assert(_refreshRects.size() < DIRTY_RECTS_SIZE);
+		_refreshRects.push_back(r);
+	}
 }
 
 // Draw any game dirty rects onto the screen intermediate surface
diff --git a/engines/hopkins/graphics.h b/engines/hopkins/graphics.h
index 33edc6f..3739bbf 100644
--- a/engines/hopkins/graphics.h
+++ b/engines/hopkins/graphics.h
@@ -129,7 +129,7 @@ public:
 	void resetRefreshRects();
 	void addDirtyRect(int x1, int y1, int x2, int y2);
 	void addDirtyRect(const Common::Rect &r) { addDirtyRect(r.left, r.top, r.right, r.bottom); }
-	void addRefreshRect(const Common::Rect &r);
+	void addRefreshRect(int x1, int y1, int x2, int y2);
 	void displayDirtyRects();
 	void displayRefreshRects();
 	void copySurface(const byte *surface, int x1, int y1, int width, int height, byte *destSurface, int destX, int destY);


Commit: 3d06a93be163d9cc99d5c06036408e3020d5e76e
    https://github.com/scummvm/scummvm/commit/3d06a93be163d9cc99d5c06036408e3020d5e76e
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2013-03-09T19:04:41-08:00

Commit Message:
HOPKINS: Merged dirty/refresh rect rect adding into a single method

Changed paths:
    engines/hopkins/graphics.cpp
    engines/hopkins/graphics.h



diff --git a/engines/hopkins/graphics.cpp b/engines/hopkins/graphics.cpp
index b5c0660..af142ac 100644
--- a/engines/hopkins/graphics.cpp
+++ b/engines/hopkins/graphics.cpp
@@ -1105,19 +1105,8 @@ void GraphicsManager::addDirtyRect(int x1, int y1, int x2, int y2) {
 	x2 = CLIP(x2, _minX, _maxX);
 	y2 = CLIP(y2, _minY, _maxY);
 
-	Common::Rect newRect(x1, y1, x2, y2);
-	if (!newRect.isValidRect())
-		return;
-
-	// Don't bother adding the rect if it's contained within another existing one
-	for (uint rectIndex = 0; rectIndex < _dirtyRects.size(); ++rectIndex) {
-		const Common::Rect &r = _dirtyRects[rectIndex];
-		if (r.contains(newRect))
-			return;
-	}
-
-	assert(_dirtyRects.size() < DIRTY_RECTS_SIZE);
-	_dirtyRects.push_back(newRect);
+	if ((x2 > x1) && (y2 > y1))	
+		addRectToArray(_dirtyRects, Common::Rect(x1, y1, x2, y2));
 }
 
 // Add a refresh rect
@@ -1127,12 +1116,25 @@ void GraphicsManager::addRefreshRect(int x1, int y1, int x2, int y2) {
 	x2 = MIN(x2, SCREEN_WIDTH);
 	y2 = MIN(y2, SCREEN_HEIGHT);
 
-	if ((x2 > x1) && (y2 > y1)) {
-		Common::Rect r(x1, y1, x2, y2);
+	if ((x2 > x1) && (y2 > y1))
+		addRectToArray(_refreshRects, Common::Rect(x1, y1, x2, y2));
+}
 
-		assert(_refreshRects.size() < DIRTY_RECTS_SIZE);
-		_refreshRects.push_back(r);
+void GraphicsManager::addRectToArray(Common::Array<Common::Rect> &rects, const Common::Rect &newRect) {
+	// Scan for an intersection with existing rects
+	for (uint rectIndex = 0; rectIndex < rects.size(); ++rectIndex) {
+		Common::Rect &r = rects[rectIndex];
+		
+		if (r.intersects(newRect)) {
+			// Rect either intersects or is completely inside existing one, so extend existing one as necessary
+			r.extend(newRect);
+			return;
+		}
 	}
+
+	// Ensure that the rect list doesn't get too big, and add the new one in
+	assert(_refreshRects.size() < DIRTY_RECTS_SIZE);
+	rects.push_back(newRect);
 }
 
 // Draw any game dirty rects onto the screen intermediate surface
diff --git a/engines/hopkins/graphics.h b/engines/hopkins/graphics.h
index 3739bbf..45bc202 100644
--- a/engines/hopkins/graphics.h
+++ b/engines/hopkins/graphics.h
@@ -130,6 +130,7 @@ public:
 	void addDirtyRect(int x1, int y1, int x2, int y2);
 	void addDirtyRect(const Common::Rect &r) { addDirtyRect(r.left, r.top, r.right, r.bottom); }
 	void addRefreshRect(int x1, int y1, int x2, int y2);
+	void addRectToArray(Common::Array<Common::Rect> &rects, const Common::Rect &newRect);
 	void displayDirtyRects();
 	void displayRefreshRects();
 	void copySurface(const byte *surface, int x1, int y1, int width, int height, byte *destSurface, int destX, int destY);


Commit: 2d83249ac2105ff9ce803becd4bb6f1688de3df8
    https://github.com/scummvm/scummvm/commit/2d83249ac2105ff9ce803becd4bb6f1688de3df8
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2013-03-10T17:25:05-07:00

Commit Message:
HOPKINS: Clean up main game quit checks

Changed paths:
    engines/hopkins/hopkins.cpp



diff --git a/engines/hopkins/hopkins.cpp b/engines/hopkins/hopkins.cpp
index ff82d41..ce4f0f5 100644
--- a/engines/hopkins/hopkins.cpp
+++ b/engines/hopkins/hopkins.cpp
@@ -172,7 +172,7 @@ bool HopkinsEngine::runWin95Demo() {
 			}
 		}
 
-		if (g_system->getEventManager()->shouldQuit())
+		if (shouldQuit())
 			return false;
 
 		switch (_globals._exitId) {
@@ -452,14 +452,14 @@ bool HopkinsEngine::runLinuxDemo() {
 		if (!_globals._exitId) {
 			_globals._exitId = _menuManager.menu();
 			if (_globals._exitId == -1) {
-				if (!g_system->getEventManager()->shouldQuit())
+				if (!shouldQuit())
 					endLinuxDemo();
 				_globals.PERSO = _globals.freeMemory(_globals.PERSO);
 				restoreSystem();
 			}
 		}
 
-		if (g_system->getEventManager()->shouldQuit())
+		if (shouldQuit())
 			return false;
 
 		switch (_globals._exitId) {
@@ -790,8 +790,11 @@ bool HopkinsEngine::runFull() {
 		_graphicsManager.fadeOutLong();
 	}
 
-	if (!_eventsManager._escKeyFl)
+	if (!_eventsManager._escKeyFl) {
 		playIntro();
+		if (shouldQuit())
+			return false;
+	}
 	if (getPlatform() != Common::kPlatformLinux) {
 		_graphicsManager.fadeOutShort();
 		_graphicsManager.loadImage("H2");
@@ -819,7 +822,7 @@ bool HopkinsEngine::runFull() {
 			}
 		}
 
-		if (g_system->getEventManager()->shouldQuit())
+		if (shouldQuit())
 			return false;
 
 		switch (_globals._exitId) {
@@ -1927,7 +1930,7 @@ void HopkinsEngine::endLinuxDemo() {
 
 		if (_eventsManager.getMouseButton() == 1)
 			mouseClicked = true;
-	} while (!mouseClicked && !g_system->getEventManager()->shouldQuit());
+	} while (!mouseClicked && !shouldQuit());
 
 	// Original tried to open a web browser link here. Since ScummVM doesn't support
 	// that, it's being skipped in favor of simply exiting
@@ -2520,7 +2523,7 @@ void HopkinsEngine::displayCredits() {
 		_globals._creditsEndX = -1;
 		_globals._creditsStartY = -1;
 		_globals._creditsEndY = -1;
-	} while ((_eventsManager.getMouseButton() != 1) && (!g_system->getEventManager()->shouldQuit()));
+	} while ((_eventsManager.getMouseButton() != 1) && (!shouldQuit()));
 	_graphicsManager.fadeOutLong();
 	_globals.iRegul = 1;
 	_eventsManager._mouseFl = true;
@@ -2816,7 +2819,7 @@ void HopkinsEngine::handleOceanMaze(int16 curExitId, Common::String backgroundFi
 		_linesManager.checkZone();
 		setSubmarineSprites();
 		_eventsManager.VBL();
-		if (_globals._exitId || g_system->getEventManager()->shouldQuit())
+		if (_globals._exitId || shouldQuit())
 			break;
 	}
 


Commit: e50a7be7defca39b89941a7bade023db87e6bf01
    https://github.com/scummvm/scummvm/commit/e50a7be7defca39b89941a7bade023db87e6bf01
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2013-03-10T19:09:29-07:00

Commit Message:
HOPKINS: Further fix for dirty area display in-game

Changed paths:
    engines/hopkins/graphics.cpp



diff --git a/engines/hopkins/graphics.cpp b/engines/hopkins/graphics.cpp
index af142ac..bad6760 100644
--- a/engines/hopkins/graphics.cpp
+++ b/engines/hopkins/graphics.cpp
@@ -438,7 +438,7 @@ void GraphicsManager::m_scroll16(const byte *surface, int xs, int ys, int width,
 	}
 
 	unlockScreen();
-	addRefreshRect(xs, ys, xs + width, ys + height);
+	addRefreshRect(destX, destY, destX + width, destY + height);
 }
 
 // TODO: See if PAL_PIXELS can be converted to a uint16 array
@@ -498,7 +498,7 @@ void GraphicsManager::m_scroll16A(const byte *surface, int xs, int ys, int width
 		yNext = yCtr - 1;
 	} while (yCtr != 1);
 
-	addRefreshRect(xs, ys, xs + width, ys + width);
+	addRefreshRect(destX, destY, destX + width, destY + width);
 }
 
 void GraphicsManager::Copy_Vga16(const byte *surface, int xp, int yp, int width, int height, int destX, int destY) {
@@ -537,7 +537,7 @@ void GraphicsManager::Copy_Vga16(const byte *surface, int xp, int yp, int width,
 		yCount = yCtr - 1;
 	} while (yCtr != 1);
 
-	addRefreshRect(xp, yp, xp + width, yp + width);
+	addRefreshRect(destX, destY, destX + width, destY + width);
 }
 
 /** 


Commit: f49fb723dafff9e8b9f213cff785e580c671a3a8
    https://github.com/scummvm/scummvm/commit/f49fb723dafff9e8b9f213cff785e580c671a3a8
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2013-03-10T19:15:12-07:00

Commit Message:
HOPKINS: Added a more comprehensive rects merge code

Changed paths:
    engines/hopkins/graphics.cpp



diff --git a/engines/hopkins/graphics.cpp b/engines/hopkins/graphics.cpp
index bad6760..3265718 100644
--- a/engines/hopkins/graphics.cpp
+++ b/engines/hopkins/graphics.cpp
@@ -1122,19 +1122,39 @@ void GraphicsManager::addRefreshRect(int x1, int y1, int x2, int y2) {
 
 void GraphicsManager::addRectToArray(Common::Array<Common::Rect> &rects, const Common::Rect &newRect) {
 	// Scan for an intersection with existing rects
-	for (uint rectIndex = 0; rectIndex < rects.size(); ++rectIndex) {
+	uint rectIndex;
+	for (rectIndex = 0; rectIndex < rects.size(); ++rectIndex) {
 		Common::Rect &r = rects[rectIndex];
 		
 		if (r.intersects(newRect)) {
 			// Rect either intersects or is completely inside existing one, so extend existing one as necessary
 			r.extend(newRect);
-			return;
+			break;
 		}
 	}
+	if (rectIndex == rects.size()) {
+		// Rect not intersecting any existing one, so add it in
+		assert(rects.size() < DIRTY_RECTS_SIZE);
+		rects.push_back(newRect);
+	}
+
+	// Take care of merging the existing rect list. This is done as a separate check even if
+	// a previous extending above has been done, since the merging of the new rect above may
+	// result in further rects now able to be merged
+
+	for (int srcIndex = rects.size() - 1; srcIndex > 0; --srcIndex) {
+		const Common::Rect &srcRect = rects[srcIndex];
 
-	// Ensure that the rect list doesn't get too big, and add the new one in
-	assert(_refreshRects.size() < DIRTY_RECTS_SIZE);
-	rects.push_back(newRect);
+		// Loop through all the other rects to see if it intersects them
+		for (int destIndex = srcIndex - 1; destIndex >= 0; --destIndex) {
+			if (rects[destIndex].intersects(srcRect)) {
+				// Found an intersection, so extend the found one, and delete the original
+				rects[destIndex].extend(srcRect);
+				rects.remove_at(srcIndex);
+				break;
+			}
+		}
+	}
 }
 
 // Draw any game dirty rects onto the screen intermediate surface


Commit: 408345ebabe803f239e85d32a0627f5ca5c7b46b
    https://github.com/scummvm/scummvm/commit/408345ebabe803f239e85d32a0627f5ca5c7b46b
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2013-03-12T18:43:48-07:00

Commit Message:
HOPKINS: Further cleaned up dirty rect display

Changed paths:
    engines/hopkins/graphics.cpp



diff --git a/engines/hopkins/graphics.cpp b/engines/hopkins/graphics.cpp
index 3265718..4041363 100644
--- a/engines/hopkins/graphics.cpp
+++ b/engines/hopkins/graphics.cpp
@@ -185,6 +185,7 @@ void GraphicsManager::loadVgaImage(const Common::String &file) {
 
 	lockScreen();
 	copy16bFromSurfaceScaleX2(_vesaBuffer);
+	addRefreshRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
 	unlockScreen();
 
 	fadeInBreakout();
@@ -1165,12 +1166,6 @@ void GraphicsManager::displayDirtyRects() {
 	lockScreen();
 	
 	// Refresh the entire screen 
-	Graphics::Surface *screenSurface = NULL;
-	if (_showDirtyRects) {
-		screenSurface = g_system->lockScreen();
-		g_system->copyRectToScreen(_screenBuffer, WinScan, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
-	}
-
 	for (uint idx = 0; idx < _dirtyRects.size(); ++idx) {
 		Common::Rect &r = _dirtyRects[idx];
 		Common::Rect dstRect;
@@ -1199,21 +1194,12 @@ void GraphicsManager::displayDirtyRects() {
 			unlockScreen();
 		}
 
-		// If it's a valid rect, then copy it over
-		if (dstRect.isValidRect() && dstRect.width() > 0 && dstRect.height() > 0) {
-			byte *srcP = _videoPtr + WinScan * dstRect.top + (dstRect.left * 2);
-			g_system->copyRectToScreen(srcP, WinScan, dstRect.left, dstRect.top, 
-				dstRect.width(), dstRect.height());
-
-			if (_showDirtyRects)
-				screenSurface->frameRect(dstRect, 0xffffff);
-		}
+		// If it's a valid rect, then add it to the list of areas to refresh on the screen
+		if (dstRect.isValidRect() && dstRect.width() > 0 && dstRect.height() > 0)
+			addRectToArray(_refreshRects, dstRect);
 	}
 
 	unlockScreen();
-	if (_showDirtyRects)
-		g_system->unlockScreen();
-
 	resetDirtyRects();
 }
 


Commit: 3a48420c90605eecbd820c61468bbc508f7d50e2
    https://github.com/scummvm/scummvm/commit/3a48420c90605eecbd820c61468bbc508f7d50e2
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2013-03-12T18:44:36-07:00

Commit Message:
HOPKINS: Dirty rect fix for Breakout game

Changed paths:
    engines/hopkins/computer.cpp



diff --git a/engines/hopkins/computer.cpp b/engines/hopkins/computer.cpp
index b1f71cd..2a882a9 100644
--- a/engines/hopkins/computer.cpp
+++ b/engines/hopkins/computer.cpp
@@ -556,8 +556,10 @@ void ComputerManager::displayGamesSubMenu() {
 	_breakoutSpr = _vm->_fileManager.loadFile("CASSE.SPR");
 	loadHiscore();
 	setModeVGA256();
+
 	newLevel();
-	_vm->_graphicsManager.resetDirtyRects();
+	_vm->_graphicsManager.DD_VBL();
+
 	playBreakout();
 	_vm->_graphicsManager.resetDirtyRects();
 	_breakoutSpr = _vm->_globals.freeMemory(_breakoutSpr);
@@ -642,12 +644,15 @@ void ComputerManager::newLevel() {
 
 	_breakoutLevel = (int16 *)_vm->_fileManager.loadFile(file);
 	displayBricks();
+
 	_vm->_objectsManager.addStaticSprite(_breakoutSpr, Common::Point(150, 192), 0, 13, 0, false, 0, 0);
 	_vm->_objectsManager.addStaticSprite(_breakoutSpr, Common::Point(164, 187), 1, 14, 0, false, 0, 0);
+
 	_ballPosition = Common::Point(164, 187);
 	_padPositionX = 150;
 	_vm->_objectsManager.animateSprite(0);
 	_vm->_objectsManager.animateSprite(1);
+ 
 	_vm->_eventsManager.mouseOn();
 	_vm->_soundManager.playSample(3, 5);
 }


Commit: d10f81372bafe4af7ed94162570e1c55be3ae4e1
    https://github.com/scummvm/scummvm/commit/d10f81372bafe4af7ed94162570e1c55be3ae4e1
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2013-03-12T20:03:18-07:00

Commit Message:
HOPKINS: Endian fix for playing Breakout game

Changed paths:
    engines/hopkins/computer.cpp



diff --git a/engines/hopkins/computer.cpp b/engines/hopkins/computer.cpp
index 2a882a9..7b88121 100644
--- a/engines/hopkins/computer.cpp
+++ b/engines/hopkins/computer.cpp
@@ -669,11 +669,11 @@ void ComputerManager::displayBricks() {
 	int cellTop;
 	int cellType;
 	for (int levelIdx = 0; ; levelIdx += 6) {
-		cellLeft = level[levelIdx];
+		cellLeft = (int16)FROM_LE_16(level[levelIdx]);
 		if (cellLeft == -1)
 			break;
-		cellTop = level[levelIdx + 1];
-		cellType = level[levelIdx + 4];
+		cellTop = FROM_LE_16(level[levelIdx + 1]);
+		cellType = FROM_LE_16(level[levelIdx + 4]);
 
 		if (cellType <= 6)
 			++_breakoutBrickNbr;
@@ -701,8 +701,6 @@ void ComputerManager::displayBricks() {
 			_vm->_graphicsManager.AFFICHE_SPEEDVGA(_breakoutSpr, cellLeft, cellTop, 23);
 			break;
 		}
-
-		levelIdx += 6;
 	}
 
 	displayScore();


Commit: 39ffd06839531cb9a2e81e9c89b820b6332327d8
    https://github.com/scummvm/scummvm/commit/39ffd06839531cb9a2e81e9c89b820b6332327d8
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2013-03-13T19:58:48-07:00

Commit Message:
HOPKINS: Bugfix for refreshing Breakout lives when one is lost

Changed paths:
    engines/hopkins/computer.cpp
    engines/hopkins/graphics.cpp
    engines/hopkins/graphics.h



diff --git a/engines/hopkins/computer.cpp b/engines/hopkins/computer.cpp
index 7b88121..4872f91 100644
--- a/engines/hopkins/computer.cpp
+++ b/engines/hopkins/computer.cpp
@@ -715,6 +715,8 @@ void ComputerManager::displayLives() {
 
 	for (int i = 0, xp = 10; i < _breakoutLives - 1; i++, xp += 7)
 		_vm->_graphicsManager.AFFICHE_SPEEDVGA(_breakoutSpr, xp, 10, 14);
+
+	_vm->_graphicsManager.DD_VBL();
 }
 
 /**
@@ -766,7 +768,7 @@ void ComputerManager::playBreakout() {
 			} while (!_vm->shouldQuit() && !lastBreakoutEvent);
 			if (lastBreakoutEvent != 1)
 				break;
-			_vm->_graphicsManager.fateOutBreakout();
+
 			--_breakoutLives;
 
 			if (_breakoutLives) {
@@ -774,6 +776,8 @@ void ComputerManager::playBreakout() {
 				if (_breakoutLives)
 					continue;
 			}
+
+			_vm->_graphicsManager.fadeOutBreakout();
 			_vm->_eventsManager.mouseOn();
 			_vm->_objectsManager.removeSprite(0);
 			_vm->_objectsManager.removeSprite(1);
@@ -794,7 +798,7 @@ void ComputerManager::playBreakout() {
 		}
 		if (lastBreakoutEvent != 2)
 			return;
-		_vm->_graphicsManager.fateOutBreakout();
+		_vm->_graphicsManager.fadeOutBreakout();
 		newLevel();
 	}
 }
@@ -846,7 +850,7 @@ int ComputerManager::displayHiscores() {
 	} while (!buttonIndex && !_vm->shouldQuit());
 
 	_vm->_eventsManager.mouseOff();
-	_vm->_graphicsManager.fateOutBreakout();
+	_vm->_graphicsManager.fadeOutBreakout();
 	_vm->_globals.freeMemory(ptr);
 	return buttonIndex;
 }
@@ -889,7 +893,7 @@ void ComputerManager::getScoreName() {
 	for (int i = scoreLen, scorePos = 8; i >= 0; i--) {
 		_score[5]._score.setChar(score[i], scorePos--);
 	}
-	_vm->_graphicsManager.fateOutBreakout();
+	_vm->_graphicsManager.fadeOutBreakout();
 	_vm->_globals.freeMemory(ptr);
 	saveScore();
 }
diff --git a/engines/hopkins/graphics.cpp b/engines/hopkins/graphics.cpp
index 4041363..798b350 100644
--- a/engines/hopkins/graphics.cpp
+++ b/engines/hopkins/graphics.cpp
@@ -675,7 +675,7 @@ void GraphicsManager::fadeInBreakout() {
 /** 
  * Fade out used by for the breakout mini-game
  */
-void GraphicsManager::fateOutBreakout() {
+void GraphicsManager::fadeOutBreakout() {
 	byte palette[PALETTE_EXT_BLOCK_SIZE];
 
 	memset(palette, 0, PALETTE_EXT_BLOCK_SIZE);
diff --git a/engines/hopkins/graphics.h b/engines/hopkins/graphics.h
index 45bc202..cdf9962 100644
--- a/engines/hopkins/graphics.h
+++ b/engines/hopkins/graphics.h
@@ -141,7 +141,7 @@ public:
 	void fadeInDefaultLength(const byte *surface);
 	void fadeInShort();
 	void fadeOutDefaultLength(const byte *surface);
-	void fateOutBreakout();
+	void fadeOutBreakout();
 	void fadeOutLong();
 	void fadeOutShort();
 	void fastDisplay(const byte *spriteData, int xp, int yp, int spriteIndex, bool addSegment = true);


Commit: 4372bd830608f8617fc005713f4ab75774b32462
    https://github.com/scummvm/scummvm/commit/4372bd830608f8617fc005713f4ab75774b32462
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2013-03-17T08:29:00-07:00

Commit Message:
Merge branch 'hopkins_dirtyRects'

Conflicts:
	engines/hopkins/anim.cpp
	engines/hopkins/computer.cpp
	engines/hopkins/dialogs.cpp
	engines/hopkins/graphics.cpp
	engines/hopkins/hopkins.cpp

Changed paths:
    engines/hopkins/anim.cpp
    engines/hopkins/computer.cpp
    engines/hopkins/debugger.cpp
    engines/hopkins/debugger.h
    engines/hopkins/dialogs.cpp
    engines/hopkins/events.cpp
    engines/hopkins/font.cpp
    engines/hopkins/graphics.cpp
    engines/hopkins/graphics.h
    engines/hopkins/hopkins.cpp
    engines/hopkins/objects.cpp
    engines/hopkins/script.cpp



diff --cc engines/hopkins/anim.cpp
index 7b3c186,89672e8..ac15139
--- a/engines/hopkins/anim.cpp
+++ b/engines/hopkins/anim.cpp
@@@ -100,7 -100,9 +100,9 @@@ void AnimationManager::playAnim(const C
  		else
  			_vm->_graphicsManager.m_scroll16(screenP, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
  		_vm->_graphicsManager.unlockScreen();
 -		_vm->_graphicsManager.addRefreshRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
+ 
 -		_vm->_graphicsManager.DD_VBL();
++		_vm->_graphicsManager.addRefreshRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
 +		_vm->_graphicsManager.updateScreen();
  	}
  	_vm->_eventsManager._rateCounter = 0;
  	_vm->_eventsManager._escKeyFl = false;
@@@ -155,7 -157,9 +157,9 @@@
  					_vm->_graphicsManager.copyVideoVbe16(screenP);
  				}
  				_vm->_graphicsManager.unlockScreen();
 -				_vm->_graphicsManager.addRefreshRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
+ 
 -				_vm->_graphicsManager.DD_VBL();
++				_vm->_graphicsManager.addRefreshRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
 +				_vm->_graphicsManager.updateScreen();
  				_vm->_soundManager.checkSoundEnd();
  			}
  		}
@@@ -280,8 -285,10 +285,11 @@@ void AnimationManager::playAnim2(const 
  				_vm->_graphicsManager.m_scroll16A(screenCopy, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
  			else
  				_vm->_graphicsManager.m_scroll16(screenP, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
+ 
  			_vm->_graphicsManager.unlockScreen();
++
+ 			_vm->_graphicsManager.addRefreshRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
 -			_vm->_graphicsManager.DD_VBL();
 +			_vm->_graphicsManager.updateScreen();
  		}
  		_vm->_eventsManager._rateCounter = 0;
  		_vm->_eventsManager._escKeyFl = false;
@@@ -329,7 -336,8 +337,9 @@@
  				}
  			}
  			_vm->_graphicsManager.unlockScreen();
++
+ 			_vm->_graphicsManager.addRefreshRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
 -			_vm->_graphicsManager.DD_VBL();
 +			_vm->_graphicsManager.updateScreen();
  			_vm->_soundManager.checkSoundEnd();
  		}
  
@@@ -400,8 -409,10 +411,10 @@@
  		_vm->_graphicsManager.m_scroll16(_vm->_graphicsManager._vesaBuffer, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
  	}
  	_vm->_graphicsManager.unlockScreen();
+ 	_vm->_graphicsManager.addRefreshRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
+ 
  	_vm->_graphicsManager.fadeInShort();
 -	_vm->_graphicsManager.DD_VBL();
 +	_vm->_graphicsManager.updateScreen();
  
  	_vm->_eventsManager.mouseOn();
  }
@@@ -648,7 -659,9 +661,9 @@@ void AnimationManager::playSequence(con
  		else
  			_vm->_graphicsManager.m_scroll16(screenP, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
  		_vm->_graphicsManager.unlockScreen();
 -		_vm->_graphicsManager.addRefreshRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
+ 
 -		_vm->_graphicsManager.DD_VBL();
++		_vm->_graphicsManager.addRefreshRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
 +		_vm->_graphicsManager.updateScreen();
  	}
  	bool skipFl = false;
  	if (_vm->getIsDemo()) {
@@@ -728,7 -741,9 +743,9 @@@
  				_vm->_graphicsManager.copyVideoVbe16a(screenP);
  			}
  			_vm->_graphicsManager.unlockScreen();
 -			_vm->_graphicsManager.addRefreshRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
+ 
 -			_vm->_graphicsManager.DD_VBL();
++			_vm->_graphicsManager.addRefreshRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
 +			_vm->_graphicsManager.updateScreen();
  			_vm->_soundManager.checkSoundEnd();
  		}
  	}
@@@ -808,7 -823,9 +825,9 @@@ void AnimationManager::playSequence2(co
  			else
  				_vm->_graphicsManager.m_scroll16(screenP, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
  			_vm->_graphicsManager.unlockScreen();
 -			_vm->_graphicsManager.addRefreshRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
+ 
 -			_vm->_graphicsManager.DD_VBL();
++			_vm->_graphicsManager.addRefreshRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
 +			_vm->_graphicsManager.updateScreen();
  		}
  		_vm->_eventsManager._rateCounter = 0;
  		_vm->_eventsManager._escKeyFl = false;
@@@ -854,7 -871,9 +873,9 @@@
  				_vm->_graphicsManager.copyVideoVbe16a(screenP);
  			}
  			_vm->_graphicsManager.unlockScreen();
++
+ 			_vm->_graphicsManager.addRefreshRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
 -			
 -			_vm->_graphicsManager.DD_VBL();
 +			_vm->_graphicsManager.updateScreen();
  			_vm->_soundManager.checkSoundEnd();
  		}
  	}
diff --cc engines/hopkins/computer.cpp
index 82cd17a,4872f91..4e9ed83
--- a/engines/hopkins/computer.cpp
+++ b/engines/hopkins/computer.cpp
@@@ -444,9 -444,9 +444,9 @@@ void ComputerManager::displayMessage(in
  	} while (textIndex != textIdx && curChar != 13);
  
  	_vm->_graphicsManager.Copy_Mem(_vm->_graphicsManager._vesaScreen, x1, yp, _vm->_fontManager._fontFixedWidth, 12, _vm->_graphicsManager._vesaBuffer, x1, yp);
- 	_vm->_graphicsManager.addVesaSegment(x1, yp, _vm->_fontManager._fontFixedWidth + x1, yp + 12);
+ 	_vm->_graphicsManager.addDirtyRect(x1, yp, _vm->_fontManager._fontFixedWidth + x1, yp + 12);
  
 -	_vm->_eventsManager.VBL();
 +	_vm->_eventsManager.refreshScreenAndEvents();
  	_inputBuf[textIndex] = 0;
  	_vm->_eventsManager._mouseFl = oldMouseFlag;
  }
@@@ -726,8 -731,8 +731,9 @@@ void ComputerManager::playBreakout() 
  			_ballPosition = Common::Point(_padPositionX + 14, 187);
  			_vm->_objectsManager.setSpriteY(1, 187);
  			_vm->_objectsManager.setSpriteX(1, _ballPosition.x);
- 			_vm->_graphicsManager.resetVesaSegment();
++
+ 			_vm->_graphicsManager.resetDirtyRects();
 -			_vm->_eventsManager.VBL();
 +			_vm->_eventsManager.refreshScreenAndEvents();
  			_vm->_graphicsManager.fadeInBreakout();
  
  			// Wait for mouse press to start playing
diff --cc engines/hopkins/dialogs.cpp
index ad3e547,f45e586..9056101
--- a/engines/hopkins/dialogs.cpp
+++ b/engines/hopkins/dialogs.cpp
@@@ -298,13 -295,13 +298,12 @@@ void DialogsManager::showOptionsDialog(
  			break;
  		}
  
 -		_vm->_eventsManager.VBL();
 +		_vm->_eventsManager.refreshScreenAndEvents();
  	} while (!doneFlag);
  
 -	_vm->_graphicsManager.copySurface(_vm->_graphicsManager._vesaScreen, _vm->_graphicsManager._scrollOffset + 164,
 -		107, 335, 215, _vm->_graphicsManager._vesaBuffer, _vm->_graphicsManager._scrollOffset + 164, 107);
 -	_vm->_graphicsManager.addDirtyRect(_vm->_graphicsManager._scrollOffset + 164, 107,
 -		_vm->_graphicsManager._scrollOffset + 498, 320);
 +	_vm->_graphicsManager.copySurface(_vm->_graphicsManager._vesaScreen, scrollOffset + 164,
 +		107, 335, 215, _vm->_graphicsManager._vesaBuffer, scrollOffset + 164, 107);
- 	_vm->_graphicsManager.addVesaSegment(scrollOffset + 164, 107,
- 		scrollOffset + 498, 320);
++	_vm->_graphicsManager.addDirtyRect(scrollOffset + 164, 107, scrollOffset + 498, 320);
  
  	_vm->_globals._optionDialogSpr = _vm->_globals.freeMemory(_vm->_globals._optionDialogSpr);
  	_vm->_globals._optionDialogFl = false;
diff --cc engines/hopkins/font.cpp
index d0f7325,62ce7f2..864da4f
--- a/engines/hopkins/font.cpp
+++ b/engines/hopkins/font.cpp
@@@ -479,13 -463,13 +479,13 @@@ void FontManager::renderTextDisplay(in
  
  			int charStartPosX = charEndPosX;
  			charEndPosX += charWidth;
- 			_vm->_graphicsManager.addVesaSegment(charStartPosX, yp, charEndPosX, yp + 12);
+ 			_vm->_graphicsManager.addDirtyRect(charStartPosX, yp, charEndPosX, yp + 12);
  			if (_vm->_eventsManager._escKeyFl) {
  				_vm->_globals.iRegul = 1;
 -				_vm->_eventsManager.VBL();
 +				_vm->_eventsManager.refreshScreenAndEvents();
  			} else {
  				_vm->_globals.iRegul = 4;
 -				_vm->_eventsManager.VBL();
 +				_vm->_eventsManager.refreshScreenAndEvents();
  				_vm->_globals.iRegul = 1;
  			}
  		}
diff --cc engines/hopkins/graphics.cpp
index 9f4c910,798b350..09fe2f1
--- a/engines/hopkins/graphics.cpp
+++ b/engines/hopkins/graphics.cpp
@@@ -191,9 -196,10 +196,10 @@@ void GraphicsManager::loadVgaImage(cons
   */
  void GraphicsManager::loadScreen(const Common::String &file) {
  	Common::File f;
+ 	assert(!_videoPtr);
  
  	bool flag = true;
 -	if (_vm->_fileManager.searchCat(file, 6) == g_PTRNUL) {
 +	if (_vm->_fileManager.searchCat(file, RES_PIC) == g_PTRNUL) {
  		if (!f.open(file))
  			error("loadScreen - %s", file.c_str());
  
@@@ -396,17 -402,13 +402,13 @@@ void GraphicsManager::loadPCX320(byte *
  }
  
  // Clear Palette
- // CHECKME: Some versions of the game don't include it, some contains nothing more than 
- // than a loop doing nothing, some others just map the last value. While debugging, it
- // seems that this function is called once the palette is already cleared, so it would be useless
- // This code could most likely be removed.
  void GraphicsManager::clearPalette() {
- 	uint16 col0 = mapRGB(0, 0, 0);
- 	for (int i = 0; i < 512; i += 2)
- 		WRITE_LE_UINT16(&SD_PIXELS[i], col0);
+ 	// As weird as it sounds, this is what the original Linux executable does, 
+ 	// and not a full array clear.
+ 	SD_PIXELS[0] = 0;
  }
  
 -void GraphicsManager::SCANLINE(int pitch) {
 +void GraphicsManager::setScreenWidth(int pitch) {
  	_lineNbr = _lineNbr2 = pitch;
  }
  
@@@ -603,7 -610,7 +610,8 @@@ void GraphicsManager::fadeOut(const byt
  
  	setPaletteVGA256(palData);
  	m_scroll16(surface, _vm->_eventsManager._startPos.x, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
- 	return updateScreen();
 -	DD_VBL();
++
++	updateScreen();
  }
  
  /** 
@@@ -725,8 -732,12 +733,13 @@@ uint16 GraphicsManager::mapRGB(byte r, 
  			| (b >> format.bLoss) << format.bShift;
  }
  
 -void GraphicsManager::DD_VBL() {
 +void GraphicsManager::updateScreen() {
 +	// TODO: Is this okay here?
+ 	// Display any aras of the screen that need refreshing
+ 	displayDirtyRects();
+ 	displayRefreshRects();
+ 
+ 	// Update the screen
  	g_system->updateScreen();
  }
  
diff --cc engines/hopkins/hopkins.cpp
index 55062a1,ce4f0f5..2821746
--- a/engines/hopkins/hopkins.cpp
+++ b/engines/hopkins/hopkins.cpp
@@@ -2800,8 -2818,8 +2806,9 @@@ void HopkinsEngine::handleOceanMaze(int
  			handleOceanMouseEvents();
  		_linesManager.checkZone();
  		setSubmarineSprites();
 -		_eventsManager.VBL();
++
 +		_eventsManager.refreshScreenAndEvents();
- 		if (_globals._exitId || g_system->getEventManager()->shouldQuit())
+ 		if (_globals._exitId || shouldQuit())
  			break;
  	}
  






More information about the Scummvm-git-logs mailing list