@@ -43,6 +43,13 @@ export class PixelFetcher {
43
43
44
44
static reset ( ) : void {
45
45
PixelFetcher . currentStatus = 0 ;
46
+
47
+ // Clear the pixel fifo memory
48
+ for ( let pixelIndex = 0 ; pixelIndex < 160 ; pixelIndex ++ ) {
49
+ for ( let byteIndex = 0 ; byteIndex < 11 ; byteIndex ++ ) {
50
+ storePixelFifoByteForPixelIndexIntoWasmBoyMemory ( pixelIndex , byteIndex , 0 ) ;
51
+ }
52
+ }
46
53
}
47
54
48
55
static startBgWindowFetch ( tileLine : i32 , tileIdInTileMapLocation : i32 ) : void {
@@ -53,10 +60,6 @@ export class PixelFetcher {
53
60
54
61
PixelFetcher . tileLine = tileLine ;
55
62
PixelFetcher . tileIdInTileMapLocation = tileIdInTileMapLocation ;
56
-
57
- // Debug: How often are we fetching?
58
- // 23 tiles per HBlank (Correct)
59
- // log(0x88, 0x01);
60
63
}
61
64
62
65
static isFetchingBgWindowTileLine ( tileLine : i32 , tileIdInTileMapLocation : i32 ) : boolean {
@@ -99,10 +102,6 @@ export class PixelFetcher {
99
102
100
103
// Idle and wait for next fetch to start
101
104
PixelFetcher . currentStatus = 0 ;
102
- } else {
103
- // DEBUG: How often are we stuck in the fetcher
104
- // DEBUG: Seems like we are always hitting this, like we aren't fetching new stuff?
105
- // log(0x55, PixelFetcher.currentStatus);
106
105
}
107
106
108
107
return ;
@@ -263,6 +262,15 @@ function _storeFetchIntoFifo(): void {
263
262
if ( PixelFetcher . isSprite ) {
264
263
// Need to mix the pixel on top of the old data
265
264
265
+ // Don't store anything if the Pixel Fifo is out of bounds
266
+ if ( PixelFifo . currentIndex >= 160 ) {
267
+ return ;
268
+ }
269
+
270
+ // Debug: Are we writing sprites?
271
+ // Yes we are, and what seems like correct scanlines
272
+ // log(0x99, Graphics.scanlineRegister);
273
+
266
274
// Get our data and type per pixel
267
275
let fifoTileDataByteZero = loadPixelFifoByteForPixelIndexFromWasmBoyMemory ( 0 , PixelFifo . currentIndex ) ;
268
276
let fifoTileDataByteOne = loadPixelFifoByteForPixelIndexFromWasmBoyMemory ( 1 , PixelFifo . currentIndex ) ;
@@ -305,18 +313,21 @@ function _storeFetchIntoFifo(): void {
305
313
306
314
// Replace the pixel data in the fifo with out sprite
307
315
if ( checkBitOnByte ( 1 , spritePaletteColorId ) ) {
308
- setBitOnByte ( i , fifoTileDataByteOne ) ;
316
+ fifoTileDataByteOne = setBitOnByte ( i , fifoTileDataByteOne ) ;
309
317
} else {
310
- resetBitOnByte ( i , fifoTileDataByteOne ) ;
318
+ fifoTileDataByteOne = resetBitOnByte ( i , fifoTileDataByteOne ) ;
311
319
}
312
320
if ( checkBitOnByte ( 0 , spritePaletteColorId ) ) {
313
- setBitOnByte ( i , fifoTileDataByteZero ) ;
321
+ fifoTileDataByteZero = setBitOnByte ( i , fifoTileDataByteZero ) ;
314
322
} else {
315
- resetBitOnByte ( i , fifoTileDataByteZero ) ;
323
+ fifoTileDataByteZero = resetBitOnByte ( i , fifoTileDataByteZero ) ;
316
324
}
317
325
318
326
// Set that we are a sprite
319
- setBitOnByte ( i , fifoTypePerPixel ) ;
327
+ fifoTypePerPixel = setBitOnByte ( i , fifoTypePerPixel ) ;
328
+
329
+ // Debug / TODO : Firgure our why sprites aren't shoing up...
330
+ log ( 0x87 , fifoTypePerPixel ) ;
320
331
321
332
// Write back to the fifo
322
333
storePixelFifoByteForPixelIndexIntoWasmBoyMemory ( 0 , PixelFifo . currentIndex , fifoTileDataByteZero ) ;
@@ -326,6 +337,12 @@ function _storeFetchIntoFifo(): void {
326
337
}
327
338
}
328
339
} else {
340
+ // Don't store anything if the Pixel Fifo is out of bounds
341
+ if ( PixelFifo . numberOfPixelsInFifo >= 160 ) {
342
+ PixelFifo . numberOfPixelsInFifo += 8 ;
343
+ return ;
344
+ }
345
+
329
346
// Simply add the tile pixels to the end of the fifo
330
347
storePixelFifoByteForPixelIndexIntoWasmBoyMemory ( 0 , PixelFifo . numberOfPixelsInFifo , PixelFetcher . tileDataByteZero ) ;
331
348
storePixelFifoByteForPixelIndexIntoWasmBoyMemory ( 1 , PixelFifo . numberOfPixelsInFifo , PixelFetcher . tileDataByteOne ) ;
0 commit comments