Hi, I'm trying to get my NES emulator to work, but I found big problem. In Duck Hunt, everything seems all right until the duck flies out. When it hides behind the tree on the left or the bushes on the right, it's weirdly clipped. Also, when the dog laughs out loud on me for having missed the duck, the grass behind which he is is NOT transparent (as it should be). See the screenshot:
I'm using per scanline engine (I know it's less accurate than per pixel engine, but just right now, I need at least some of the mapper 0 games working and I can switch to per pixel engine later).
Here's what do I do during drawing a scanline:
1. Draw any pixels of the background tiles being on the current scanline (non-transparent and transparent). I keep a flag of which pixel is transparent and which is not.
2. Draw non-transparant sprite pixels on the current scanline (from sprite 0 to sprite 63):
a) If the sprite is in the foreground, i simply draw it's pixels
b) If the sprite is in the background, i draw all it's pixels where BG is transparent
Anytime I draw a sprite pixel, I set appropriate flag that background is no longer transparent there.
Here's the code:
Can anyone tell me what do I do wrong? I want to implement scrolling in my emulator, but no sooner than the sprites are drawn correctly.
Thanks.
I'm using per scanline engine (I know it's less accurate than per pixel engine, but just right now, I need at least some of the mapper 0 games working and I can switch to per pixel engine later).
Here's what do I do during drawing a scanline:
1. Draw any pixels of the background tiles being on the current scanline (non-transparent and transparent). I keep a flag of which pixel is transparent and which is not.
2. Draw non-transparant sprite pixels on the current scanline (from sprite 0 to sprite 63):
a) If the sprite is in the foreground, i simply draw it's pixels
b) If the sprite is in the background, i draw all it's pixels where BG is transparent
Anytime I draw a sprite pixel, I set appropriate flag that background is no longer transparent there.
Here's the code:
Code:
if ((colorAddressOffset & 0x0003) && ((!(ppu.sprRAM[k+2] & 0x20)) || (transparencyMap[ppu.sprRAM[k + 3] + j]))) { // Not transparent
colorIndex = ppu.readMemory(0x3f10 + colorAddressOffset);
SDL_LockSurface(ppu.scanline);
putPixel(ppu.scanline, ppu.sprRAM[k + 3] + j, 0, SDL_MapRGB(ppu.scanline->format, NES_PALETTE[colorIndex].r, NES_PALETTE[colorIndex].g, NES_PALETTE[colorIndex].b));
SDL_UnlockSurface(ppu.scanline);
transparencyMap[ppu.sprRAM[k + 3] + j] = false;
}
colorIndex = ppu.readMemory(0x3f10 + colorAddressOffset);
SDL_LockSurface(ppu.scanline);
putPixel(ppu.scanline, ppu.sprRAM[k + 3] + j, 0, SDL_MapRGB(ppu.scanline->format, NES_PALETTE[colorIndex].r, NES_PALETTE[colorIndex].g, NES_PALETTE[colorIndex].b));
SDL_UnlockSurface(ppu.scanline);
transparencyMap[ppu.sprRAM[k + 3] + j] = false;
}
Can anyone tell me what do I do wrong? I want to implement scrolling in my emulator, but no sooner than the sprites are drawn correctly.
Thanks.