Skip to content

Commit 745308e

Browse files
committed
Made some sprite fixes
1 parent ce4a4db commit 745308e

File tree

4 files changed

+56
-10
lines changed

4 files changed

+56
-10
lines changed

core/graphics/pixelPipeline/pixelFetcher.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,6 @@ function _storeFetchIntoFifo(): void {
267267
return;
268268
}
269269

270-
// Debug: Are we writing sprites?
271-
// Yes we are, and what seems like correct scanlines
272-
// log(0x99, Graphics.scanlineRegister);
273-
274270
// Get our data and type per pixel
275271
let fifoTileDataByteZero = loadPixelFifoByteForPixelIndexFromWasmBoyMemory(0, PixelFifo.currentIndex);
276272
let fifoTileDataByteOne = loadPixelFifoByteForPixelIndexFromWasmBoyMemory(1, PixelFifo.currentIndex);
@@ -288,7 +284,7 @@ function _storeFetchIntoFifo(): void {
288284

289285
// Palette ColorId zero (last two bits of pallette) of a sprite are always transparent
290286
// http://gbdev.gg8.se/wiki/articles/Video_Display
291-
if (spritePaletteColorId !== 0) {
287+
if (spritePaletteColorId === 0) {
292288
continue;
293289
}
294290

@@ -329,6 +325,13 @@ function _storeFetchIntoFifo(): void {
329325
// Debug / TODO : Firgure our why sprites aren't shoing up...
330326
// fifoTypePerPixel is correct, maybe is is the data bytes?
331327
// log(0x87, fifoTypePerPixel);
328+
// log(0x89, spritePaletteColorId);
329+
// log(0x90, fifoTileDataByteZero);
330+
// log(0x91, fifoTileDataByteOne);
331+
332+
// Debug: Are we writing sprites?
333+
// Yes we are, and what seems like correct scanlines
334+
// log(0x99, Graphics.scanlineRegister);
332335

333336
// Write back to the fifo
334337
storePixelFifoByteForPixelIndexIntoWasmBoyMemory(0, PixelFifo.currentIndex, fifoTileDataByteZero);

core/graphics/pixelPipeline/pixelFifo.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export class PixelFifo {
1111
// Status of the Fetcher
1212
// 0: Idling
1313
// 1: Pushing Pixels
14+
// 2: Idling because fetching sprite
1415
static currentStatus: i32 = 0;
1516

1617
// Number of pixels in our fifo
@@ -25,7 +26,20 @@ export class PixelFifo {
2526
PixelFifo.numberOfPixelsInFifo = 0;
2627
}
2728

29+
static startSpriteIdle(): void {
30+
PixelFifo.currentStatus = 2;
31+
}
32+
33+
static stopSpriteIdle(): void {
34+
PixelFifo.currentStatus = 0;
35+
}
36+
2837
static step(): void {
38+
// Check if we are waiting for a sprite fetch
39+
if (PixelFifo.currentStatus === 2) {
40+
return;
41+
}
42+
2943
// Check if we can continue idling
3044
// Pixel Fifo won't push out pixels if there is <= 8 pixels in the fifo
3145
let pixelsRemainingInFifo = PixelFifo.numberOfPixelsInFifo - PixelFifo.currentIndex;

core/graphics/pixelPipeline/pixelPipeline.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ export class PixelPipeline {
3939
cpuCycles = cpuCycles >> (<i32>Cpu.GBCDoubleSpeed);
4040

4141
for (let pixelPipelineCyclesStepped: i32 = 0; pixelPipelineCyclesStepped < cpuCycles; pixelPipelineCyclesStepped++) {
42+
// Debug:
43+
// The problem with sprites is that we are still pushing pixels, while we are trying to fetch sprites.
44+
// We need to do checks, and then proceed down a certain path
45+
4246
// Push our a pixel
4347
PixelFifo.step();
4448

@@ -47,17 +51,25 @@ export class PixelPipeline {
4751
/*
4852
if (_tryToFetchSprite()) {
4953
// We are fetching a sprite!
50-
} else if (_tryToFetchWindow()) {
51-
// We are fetching window!
54+
PixelFifo.startSpriteIdle();
5255
} else {
53-
_tryToFetchBackground();
56+
57+
PixelFifo.stopSpriteIdle();
58+
59+
if (_tryToFetchWindow()) {
60+
// We are fetching window!
61+
} else {
62+
_tryToFetchBackground();
63+
}
5464
}
5565
*/
5666

5767
// DEBUG: Just do sprites and BG
5868
if (_tryToFetchSprite()) {
5969
// We are fetching a sprite!
70+
PixelFifo.startSpriteIdle();
6071
} else {
72+
PixelFifo.stopSpriteIdle();
6173
_tryToFetchBackground();
6274
}
6375

@@ -121,13 +133,28 @@ function _tryToFetchSprite(): boolean {
121133
// NOTE: Y Position was handled by the OAM Search,
122134
// and sprites are not affected by scroll Y
123135
// So we know the sprite is on this scanline
124-
if (PixelFifo.currentIndex >= spriteXPosition && PixelFifo.currentIndex < spriteXPosition + 8) {
136+
// Also, we only want to check for the start of the sprite, not it's entire width
137+
// since the entire 8 x pixels of the tile are fetched at once
138+
if (PixelFifo.currentIndex === spriteXPosition) {
125139
// We need to fetch this sprite!
126140

141+
// Debug: also need to fix tile line in the fetcher!!!
142+
// getting off train
143+
144+
// Get which line of the 8x8 or 8x16 tile.
145+
// Need to sub tract 16 from the total because of the tile height, to get the line
146+
// Debug, may need to put the sprite height here in stead of 16.
147+
let spriteTileLine = Graphics.scanlineRegister - spriteYPosition - 16;
148+
127149
// Check if we are already fetching the sprite,
128150
// If not, start fetching it
129-
let spriteTileLine = Graphics.scanlineRegister - spriteYPosition;
130151
if (!PixelFetcher.isFetchingSpriteTileLine(spriteTileLine, spriteIndex)) {
152+
// Debug: We are fetching this sprite
153+
// But which line and things?
154+
let spriteHeight: i32 = Lcd.tallSpriteSize ? 16 : 8;
155+
log(Graphics.scanlineRegister, spriteYPosition);
156+
log(0x01, spriteHeight);
157+
131158
// Just reset everything, and start fetching the sprite
132159
PixelFetcher.startSpriteFetch(spriteTileLine, spriteIndex);
133160
}

core/graphics/sprites.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ export class Sprites {
4646
// Y is offset by 16. An off-screen value (for example, Y=0 or Y>=160) hides the sprite.
4747
spriteYPosition -= 16;
4848

49+
// DEBUG: Tile line is wrong, both here and the fetcher.
50+
4951
// Find if the sprite is visible
5052
// spriteXPosition > -8 because:
5153
// X is minus 8 pixels, and since sprites can only be 8 pixels wide, it would be not visible.

0 commit comments

Comments
 (0)