@@ -193,11 +193,10 @@ function _storeFetchIntoFifo(): void {
193
193
194
194
// Get the location of where we will be mixing
195
195
// Which is the first 8 pixels in the fifo
196
- let pixelFifoIndex = PixelPipeline . pixelFifoIndex * 4 ;
196
+ let pixelFifoIndex = PixelPipeline . pixelFifoIndex * 11 ;
197
197
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 ) ;
201
200
202
201
// Go one by one for the 8 pixels in the current fifo
203
202
for ( let i = 0 ; i < 8 ; i ++ ) {
@@ -227,9 +226,10 @@ function _storeFetchIntoFifo(): void {
227
226
continue ;
228
227
}
229
228
230
- // Load the data for the pixel
229
+ // Load the data & attributes for the pixel
231
230
let fifoTileDataByteZero = eightBitLoadFromGBMemory ( PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_LOCATION + pixelFifoIndex + 0 ) ;
232
231
let fifoTileDataByteOne = eightBitLoadFromGBMemory ( PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_LOCATION + pixelFifoIndex + 1 ) ;
232
+ let fifoTileAttributes = eightBitLoadFromGBMemory ( PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_LOCATION + pixelFifoIndex + 3 + i ) ;
233
233
234
234
// Get the Palette Color Ids of the pixel in the Fifo
235
235
let fifoPaletteColorId = 0 ;
@@ -243,14 +243,14 @@ function _storeFetchIntoFifo(): void {
243
243
}
244
244
245
245
// 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.
247
247
// There are multiple cases where we NEED to draw a sprite pixel over a Background
248
248
// 1. The LCDC Bit 0 - BG/Window Display/Priority is cleared, thus BG priority is ignored
249
249
// 2. The Sprite Priority bit is NOT set. If it is, we can only draw over BG color id 0.
250
250
// 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.
251
251
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 ;
254
254
255
255
if ( shouldShowRelativeToLcdcPriority || ( shouldShowRelativeToOamPriority && shouldShowRelativeToBgPriority ) ) {
256
256
// Mix the pixel!
@@ -267,32 +267,28 @@ function _storeFetchIntoFifo(): void {
267
267
resetBitOnByte ( i , fifoTileDataByteZero ) ;
268
268
}
269
269
270
- // Note: Don't need to worry about priority,
271
- // since sprite can't draw over sprites
272
-
273
270
// Set that we are a sprite
274
271
setBitOnByte ( i , typePerPixel ) ;
275
272
276
273
// Write back to the fifo
277
274
eightBitStoreIntoGBMemory ( PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_LOCATION + pixelFifoIndex , fifoTileDataByteZero ) ;
278
275
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 ) ;
280
278
}
281
279
}
282
280
} else {
283
281
// 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 ;
288
286
eightBitStoreIntoGBMemory ( PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_LOCATION + pixelFifoIndex , PixelFetcher . tileDataByteZero ) ;
289
287
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 ) ;
293
291
}
294
- eightBitStoreIntoGBMemory ( PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_LOCATION + pixelFifoIndex + 2 , tilePriority ) ;
295
- eightBitStoreIntoGBMemory ( PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_LOCATION + pixelFifoIndex + 3 , 0 ) ;
296
292
PixelPipeline . numberOfPixelsInFifo += 8 ;
297
293
}
298
294
}
0 commit comments