Commits

spencercw committed b32ec56

Implement vertical flip of background tiles.

Comments (0)

Files changed (1)

gb_emulator/gb_video.cpp

 		// Handle background attributes
 		uint8_t *tile, *palette = NULL;
 		bool hFlip = false;
+		bool vFlip = false;
 		if (gb_.gbc_)
 		{
 			// Palette select
 			else
 				tile = &tileData[tileIndex * 16];
 
-			// Flip horizontally
+			// Flip horizontally/vertically
 			if (attr & 0x20)
 				hFlip = true;
+			if (attr & 0x40)
+				vFlip = true;
 		}
 		else
 			tile = &tileData[tileIndex * 16];
-		uint16_t tileLine = *reinterpret_cast<uint16_t *>(&tile[line % 8 * 2]);
+		uint16_t tileLine;
+		{
+			unsigned offset = vFlip ?
+				(7 - (line % 8)) * 2 :
+				(line % 8) * 2;
+			tileLine = *reinterpret_cast<uint16_t *>(&tile[offset]);
+		}
 
 		// Iterate over each pixel in the line
 		for (int j = 0; j != 8; ++j)