Commits

spencercw  committed ce3a257

Implement the window x position handling.

  • Participants
  • Parent commits 2c1fe71

Comments (0)

Files changed (2)

File gb_emulator/gb_memory.cpp

 		ioPorts[ptr] |= val & 0x78;
 		break;
 
+	// Current draw line
+	case LCDC_Y:
+		ioPorts[ptr] = 0;
+		break;
+
 	// DMA transfer
 	case DMA:
 		// The maximum start address is 0xf100

File gb_emulator/gb_video.cpp

 	}
 	else if (type == DRAW_WINDOW)
 	{
-		line = (gb_.mem_.ioPorts[LCDC_Y] - gb_.mem_.ioPorts[WY]) % 256;
+		line = gb_.mem_.ioPorts[LCDC_Y] - gb_.mem_.ioPorts[WY];
 		tileMap  = &gb_.mem_.vram[(gb_.mem_.ioPorts[LCDC] & LCDC_WNDW_TILE_MAP) ? 0x1c00 : 0x1800];
 		tileAttr = &gb_.mem_.vram[(gb_.mem_.ioPorts[LCDC] & LCDC_WNDW_TILE_MAP) ? 0x3c00 : 0x3800];
 	}
 			// Calculate x coordinate
 			int x = 8 * i + (hFlip ? 7 - j : j);
 			if (type == DRAW_BACKGROUND)
+			{
 				x -= gb_.mem_.ioPorts[SCX];
-			x = (x % 256 + 256) % 256;
-			if (x >= 160)
+				x = (x % 256 + 256) % 256;
+			}
+			else if (type == DRAW_WINDOW)
+			{
+				x += gb_.mem_.ioPorts[WX];
+				x -= 7;
+			}
+			
+			if (x < 0 || x >= 160)
 				continue;
 
 			// Mark the pixel as drawn. A value of 2 in the priority map indicates the background