Skip to content

Commit 2cfa7dc

Browse files
committed
Falling asleep :(
1 parent b58f8e6 commit 2cfa7dc

File tree

4 files changed

+37
-17
lines changed

4 files changed

+37
-17
lines changed

core/constants.ts

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

4242
export const PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_LOCATION: i32 = OAM_VISIBLE_SPRITES_LOCATION + OAM_VISIBLE_SPRITES_SIZE;
43+
// 0xdc = 220. (Number of tiles in viewport * 11) = 220.
4344
export const PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_SIZE: i32 = 0xdc;
4445

4546
export const FRAME_LOCATION: i32 = PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_LOCATION + PIXEL_PIPELINE_ENTIRE_SCANLINE_FIFO_SIZE;

core/graphics/pixelPipeline/pixelFetcher.ts

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ export class PixelFetcher {
4343

4444
static reset(): void {
4545
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+
}
4653
}
4754

4855
static startBgWindowFetch(tileLine: i32, tileIdInTileMapLocation: i32): void {
@@ -53,10 +60,6 @@ export class PixelFetcher {
5360

5461
PixelFetcher.tileLine = tileLine;
5562
PixelFetcher.tileIdInTileMapLocation = tileIdInTileMapLocation;
56-
57-
// Debug: How often are we fetching?
58-
// 23 tiles per HBlank (Correct)
59-
// log(0x88, 0x01);
6063
}
6164

6265
static isFetchingBgWindowTileLine(tileLine: i32, tileIdInTileMapLocation: i32): boolean {
@@ -99,10 +102,6 @@ export class PixelFetcher {
99102

100103
// Idle and wait for next fetch to start
101104
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);
106105
}
107106

108107
return;
@@ -263,6 +262,15 @@ function _storeFetchIntoFifo(): void {
263262
if (PixelFetcher.isSprite) {
264263
// Need to mix the pixel on top of the old data
265264

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+
266274
// Get our data and type per pixel
267275
let fifoTileDataByteZero = loadPixelFifoByteForPixelIndexFromWasmBoyMemory(0, PixelFifo.currentIndex);
268276
let fifoTileDataByteOne = loadPixelFifoByteForPixelIndexFromWasmBoyMemory(1, PixelFifo.currentIndex);
@@ -305,18 +313,21 @@ function _storeFetchIntoFifo(): void {
305313

306314
// Replace the pixel data in the fifo with out sprite
307315
if (checkBitOnByte(1, spritePaletteColorId)) {
308-
setBitOnByte(i, fifoTileDataByteOne);
316+
fifoTileDataByteOne = setBitOnByte(i, fifoTileDataByteOne);
309317
} else {
310-
resetBitOnByte(i, fifoTileDataByteOne);
318+
fifoTileDataByteOne = resetBitOnByte(i, fifoTileDataByteOne);
311319
}
312320
if (checkBitOnByte(0, spritePaletteColorId)) {
313-
setBitOnByte(i, fifoTileDataByteZero);
321+
fifoTileDataByteZero = setBitOnByte(i, fifoTileDataByteZero);
314322
} else {
315-
resetBitOnByte(i, fifoTileDataByteZero);
323+
fifoTileDataByteZero = resetBitOnByte(i, fifoTileDataByteZero);
316324
}
317325

318326
// 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);
320331

321332
// Write back to the fifo
322333
storePixelFifoByteForPixelIndexIntoWasmBoyMemory(0, PixelFifo.currentIndex, fifoTileDataByteZero);
@@ -326,6 +337,12 @@ function _storeFetchIntoFifo(): void {
326337
}
327338
}
328339
} 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+
329346
// Simply add the tile pixels to the end of the fifo
330347
storePixelFifoByteForPixelIndexIntoWasmBoyMemory(0, PixelFifo.numberOfPixelsInFifo, PixelFetcher.tileDataByteZero);
331348
storePixelFifoByteForPixelIndexIntoWasmBoyMemory(1, PixelFifo.numberOfPixelsInFifo, PixelFetcher.tileDataByteOne);

core/graphics/pixelPipeline/pixelFifo.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ export class PixelFifo {
3030
// Pixel Fifo won't push out pixels if there is <= 8 pixels in the fifo
3131
let pixelsRemainingInFifo = PixelFifo.numberOfPixelsInFifo - PixelFifo.currentIndex;
3232
if (pixelsRemainingInFifo <= 8) {
33-
// DEBUG: How often are we stuck in the fifo
34-
// log(0x40, 0x00);
3533
PixelFifo.currentStatus = 0;
3634
return;
3735
}

core/graphics/pixelPipeline/pixelPipeline.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ export class PixelPipeline {
5454
}
5555
*/
5656

57-
// DEBUG: Try just fetching background
58-
_tryToFetchBackground();
57+
// DEBUG: Just do sprites and BG
58+
if (_tryToFetchSprite()) {
59+
// We are fetching a sprite!
60+
} else {
61+
_tryToFetchBackground();
62+
}
5963

6064
// Step our fetcher (2 times as slow as fifo)
6165
if (PixelPipeline.cycles !== 0) {

0 commit comments

Comments
 (0)