Skip to content

Commit 043b6fe

Browse files
committed
Fixed up pixel fetcher relative to fifo
1 parent 757fa4d commit 043b6fe

File tree

3 files changed

+19
-22
lines changed

3 files changed

+19
-22
lines changed

core/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const OAM_VISIBLE_SPRITES_LOCATION: i32 = BG_PRIORITY_MAP_LOCATION + BG_P
4040
export const OAM_VISIBLE_SPRITES_SIZE: i32 = 0x0b;
4141

4242
export const PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_LOCATION: i32 = OAM_VISIBLE_SPRITES_LOCATION + OAM_VISIBLE_SPRITES_SIZE;
43-
export const PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_SIZE: i32 = 0x50;
43+
export const PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_SIZE: i32 = 0xdc;
4444

4545
export const FRAME_LOCATION: i32 = PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_LOCATION + PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_SIZE;
4646
export const FRAME_SIZE: i32 = 0x016c00;

core/graphics/pixelPipeline/pixelFetcher.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,10 @@ function _storeFetchIntoFifo(): void {
193193

194194
// Get the location of where we will be mixing
195195
// Which is the first 8 pixels in the fifo
196-
let pixelFifoIndex = PixelPipeline.pixelFifoIndex * 4;
196+
let pixelFifoIndex = PixelPipeline.pixelFifoIndex * 11;
197197

198-
// Get our priority per pixel, and type per pixel
199-
let priorityPerPixel = eightBitLoadFromGBMemory(PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_LOCATION + pixelFifoIndex + 2);
200-
let typePerPixel = eightBitLoadFromGBMemory(PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_LOCATION + pixelFifoIndex + 3);
198+
// Get our type per pixel
199+
let typePerPixel = eightBitLoadFromGBMemory(PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_LOCATION + pixelFifoIndex + 2);
201200

202201
// Go one by one for the 8 pixels in the current fifo
203202
for (let i = 0; i < 8; i++) {
@@ -227,9 +226,10 @@ function _storeFetchIntoFifo(): void {
227226
continue;
228227
}
229228

230-
// Load the data for the pixel
229+
// Load the data & attributes for the pixel
231230
let fifoTileDataByteZero = eightBitLoadFromGBMemory(PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_LOCATION + pixelFifoIndex + 0);
232231
let fifoTileDataByteOne = eightBitLoadFromGBMemory(PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_LOCATION + pixelFifoIndex + 1);
232+
let fifoTileAttributes = eightBitLoadFromGBMemory(PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_LOCATION + pixelFifoIndex + 3 + i);
233233

234234
// Get the Palette Color Ids of the pixel in the Fifo
235235
let fifoPaletteColorId = 0;
@@ -243,14 +243,14 @@ function _storeFetchIntoFifo(): void {
243243
}
244244

245245
// NOTE:
246-
// We are trying to draw a sprite pixel over a BG/Window pixel
246+
// We are trying to draw a sprite pixel over a BG/Window pixel.
247247
// There are multiple cases where we NEED to draw a sprite pixel over a Background
248248
// 1. The LCDC Bit 0 - BG/Window Display/Priority is cleared, thus BG priority is ignored
249249
// 2. The Sprite Priority bit is NOT set. If it is, we can only draw over BG color id 0.
250250
// 3. (CGB Only) The BG Priority bit is NOT set. If it is, If it is, we can only draw over BG color id 0.
251251
let shouldShowRelativeToLcdcPriority = Cpu.GBCEnabled && !Lcd.bgDisplayEnabled;
252-
let shouldShowRelativeToOamPriority = !checkBitOnByte(6, PixelFetcher.tileAttributes) || fifoPaletteColorId === 0;
253-
let shouldShowRelativeToBgPriority = !checkBitOnByte(i, priorityPerPixel) || fifoPaletteColorId === 0;
252+
let shouldShowRelativeToOamPriority = !checkBitOnByte(7, PixelFetcher.tileAttributes) || fifoPaletteColorId === 0;
253+
let shouldShowRelativeToBgPriority = !checkBitOnByte(7, fifoTileAttributes) || fifoPaletteColorId === 0;
254254

255255
if (shouldShowRelativeToLcdcPriority || (shouldShowRelativeToOamPriority && shouldShowRelativeToBgPriority)) {
256256
// Mix the pixel!
@@ -267,32 +267,28 @@ function _storeFetchIntoFifo(): void {
267267
resetBitOnByte(i, fifoTileDataByteZero);
268268
}
269269

270-
// Note: Don't need to worry about priority,
271-
// since sprite can't draw over sprites
272-
273270
// Set that we are a sprite
274271
setBitOnByte(i, typePerPixel);
275272

276273
// Write back to the fifo
277274
eightBitStoreIntoGBMemory(PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_LOCATION + pixelFifoIndex, fifoTileDataByteZero);
278275
eightBitStoreIntoGBMemory(PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_LOCATION + pixelFifoIndex + 1, fifoTileDataByteOne);
279-
eightBitStoreIntoGBMemory(PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_LOCATION + pixelFifoIndex + 3, typePerPixel);
276+
eightBitStoreIntoGBMemory(PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_LOCATION + pixelFifoIndex + 2, typePerPixel);
277+
eightBitStoreIntoGBMemory(PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_LOCATION + pixelFifoIndex + 3 + i, PixelFetcher.tileAttributes);
280278
}
281279
}
282280
} else {
283281
// Simply add the pixels to the end of the fifo
284-
// * 4, because Fifo has the 2 data tile bytes, and for WasmBoy Specifically,
285-
// A third byte representing the priority for each pixel (0 = no priority bit, 1 = priority bit)
286-
// and a 4th byte representing the type of pixel (0 = BG/Window, 1 = Sprite)
287-
let pixelFifoIndex = PixelPipeline.numberOfPixelsInFifo * 4;
282+
// * 11, because Fifo has the 2 data tile bytes, and for WasmBoy Specifically,
283+
// A 3rd byte representing the type of pixel (0 = BG/Window, 1 = Sprite)
284+
// Bytes 4-11 represent the attributes for that tile's pixel
285+
let pixelFifoIndex = PixelPipeline.numberOfPixelsInFifo * 11;
288286
eightBitStoreIntoGBMemory(PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_LOCATION + pixelFifoIndex, PixelFetcher.tileDataByteZero);
289287
eightBitStoreIntoGBMemory(PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_LOCATION + pixelFifoIndex + 1, PixelFetcher.tileDataByteOne);
290-
let tilePriority = 0;
291-
if (checkBitOnByte(7, PixelFetcher.tileAttributes)) {
292-
tilePriority = 0xff;
288+
eightBitStoreIntoGBMemory(PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_LOCATION + pixelFifoIndex + 2, 0);
289+
for (let i = 0; i < 8; i++) {
290+
eightBitStoreIntoGBMemory(PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_LOCATION + pixelFifoIndex + 3 + i, PixelFetcher.tileAttributes);
293291
}
294-
eightBitStoreIntoGBMemory(PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_LOCATION + pixelFifoIndex + 2, tilePriority);
295-
eightBitStoreIntoGBMemory(PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_LOCATION + pixelFifoIndex + 3, 0);
296292
PixelPipeline.numberOfPixelsInFifo += 8;
297293
}
298294
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Class responsible for pushing our pixels with their respective palettes

0 commit comments

Comments
 (0)