6#ifndef SPRITECONVERTER_HH
7#define SPRITECONVERTER_HH
34 std::span<const Pixel, 16> pal)
35 : spriteChecker(spriteChecker_)
45 transparency = enabled;
69 if (
int before = minX - x; before > 0) {
77 if (
int after = maxX - x; after < 32) {
83 auto mask = narrow_cast<int>(0x8000'0000);
84 pattern &= (mask >> (after - 1));
96 void drawMode1(
int absLine,
int minX,
int maxX, std::span<Pixel> pixelPtr)
const
99 auto visibleSprites = spriteChecker.
getSprites(absLine);
102 if (visibleSprites.empty())
return;
107 Pixel colIndex = si.colorAttrib & 0x0F;
111 if (colIndex == 0 && transparency)
continue;
112 Pixel color = palette[colIndex];
116 if (!
clipPattern(x, pattern, minX, maxX))
continue;
118 Pixel* p = &pixelPtr[x];
121 if (pattern & 0x8000'0000) {
141 template<
unsigned MODE>
142 void drawMode2(
int absLine,
int minX,
int maxX, std::span<Pixel> pixelPtr)
const
145 auto visibleSprites = spriteChecker.
getSprites(absLine);
148 if (visibleSprites.empty())
return;
149 std::span visibleSpritesWithSentinel{visibleSprites.data(),
150 visibleSprites.size() +1};
156 if ((visibleSprites[first].colorAttrib & 0x40) == 0) [[likely]] {
160 }
while (first <
int(visibleSprites.size()));
161 for (
int i = narrow<int>(visibleSprites.size() - 1); i >= first; --i) {
166 if (!
clipPattern(x, pattern, minX, maxX))
continue;
168 if (c == 0 && transparency)
continue;
170 if (pattern & 0x8000'0000) {
173 for (
int j = i + 1; ; ++j) {
175 visibleSpritesWithSentinel[j];
177 unsigned shift2 = x - info2.
x;
179 ((info2.
pattern << shift2) & 0x8000'0000)) {
184 Pixel pixL = palette[color >> 2];
185 Pixel pixR = palette[color & 3];
186 pixelPtr[x * 2 + 0] = pixL;
187 pixelPtr[x * 2 + 1] = pixR;
189 Pixel pix = palette[color];
191 pixelPtr[x * 2 + 0] = pix;
192 pixelPtr[x * 2 + 1] = pix;
209 std::span<const Pixel, 16> palette;
Represents a VDP display mode.
static constexpr uint8_t GRAPHIC5
static constexpr uint8_t GRAPHIC6
uint32_t SpritePattern
Bitmap of length 32 describing a sprite pattern.
std::span< const SpriteInfo > getSprites(int line) const
Get sprites for a display line.
Utility class for converting VRAM contents to host pixels.
static bool clipPattern(int &x, SpriteChecker::SpritePattern &pattern, int minX, int maxX)
SpriteConverter(SpriteChecker &spriteChecker_, std::span< const Pixel, 16 > pal)
Constructor.
void drawMode1(int absLine, int minX, int maxX, std::span< Pixel > pixelPtr) const
Draw sprites in sprite mode 1.
void setTransparency(bool enabled)
Update the transparency setting.
void drawMode2(int absLine, int minX, int maxX, std::span< Pixel > pixelPtr) const
Draw sprites in sprite mode 2.
void setDisplayMode(DisplayMode newMode)
Notify SpriteConverter of a display mode change.
void setPalette(std::span< const Pixel, 16 > newPalette)
Set palette to use for converting sprites.
This file implemented 3 utility functions:
constexpr auto reverse(Range &&range)
Contains all the information to draw a line of a sprite.
SpritePattern pattern
Pattern of this sprite line, corrected for magnification.
byte colorAttrib
Bit 3..0 are index in palette.
int16_t x
X-coordinate of sprite, corrected for early clock.