Fixed bug in OAM

This commit is contained in:
Selim Mustafaev 2023-09-30 15:31:30 +03:00
parent e2c33d36f7
commit 2e7b1bb480
3 changed files with 18 additions and 10 deletions

View File

@ -114,9 +114,9 @@ namespace nes {
}
}
Oam::PixelInfo Oam::getPixel() {
SpritePixelInfo Oam::getPixel() {
uint8_t pattern, palette, priority;
SpritePixelInfo pixel;
_firstVisibleSpriteBeingRendered = false;
for (size_t i = 0; i < _visibleSpriteCount; ++i) {
@ -125,17 +125,17 @@ namespace nes {
continue;
}
pattern = _spriteShifters[i].getValue(0);
palette = (_visibleSprites[i].attr & 0x03) + SPRITE_PALETTE_OFFSET;
priority = (_visibleSprites[i].attr & 0x20) == 0;
pixel.pattern = _spriteShifters[i].getValue(0);
pixel.palette = (_visibleSprites[i].attr & 0x03) + SPRITE_PALETTE_OFFSET;
pixel.priority = (_visibleSprites[i].attr & 0x20) == 0;
if(pattern > 0) {
if(pixel.pattern > 0) {
_firstVisibleSpriteBeingRendered = (i == 0);
break;
}
}
return std::make_tuple(pattern, palette, priority);
return pixel;
}
bool Oam::spriteZeroBeingRendered() const {

View File

@ -21,12 +21,17 @@ namespace nes {
uint8_t x = 0xFF;
};
struct SpritePixelInfo {
uint8_t pattern = 0;
uint8_t palette = 0;
uint8_t priority = 0;
};
class Oam {
public:
static constexpr size_t OAM_SIZE = 64;
static constexpr size_t MAX_SPRITES_PER_SCANLINE = 8;
static constexpr uint8_t SPRITE_PALETTE_OFFSET = 4;
using PixelInfo = std::tuple<uint8_t, uint8_t, uint8_t>;
public:
explicit Oam(Ppu* ppu);
@ -39,7 +44,7 @@ namespace nes {
bool detectVisibleSprites(int16_t scanline, bool bigSprite);
void loadShifters(int16_t scanline, bool bigSprite, bool patternSprite);
void updateShifters();
[[nodiscard]] PixelInfo getPixel();
[[nodiscard]] SpritePixelInfo getPixel();
[[nodiscard]] bool spriteZeroBeingRendered() const;
private:

View File

@ -114,7 +114,10 @@ namespace nes {
uint8_t priority = 0;
if(_mask.renderSprites) {
std::tie(fgPattern, fgPalette, priority) = _oam->getPixel();
auto fgPixel = _oam->getPixel();
fgPattern = fgPixel.pattern;
fgPalette = fgPixel.palette;
priority = fgPixel.priority;
}
uint8_t pattern = 0;