mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-02-23 22:52:34 +01:00
byuu says: Changelog: - nall: `#undef OUT` on Windows platform - GBA: add missing CPU prefetch state to serialization (this was breaking serialization in games using ROM prefetch) - GBA: reset all PPU data in the power() function (some things were missing before, causing issues on reset) - GBA: restored horizontal mosaic emulation to the new pixel-based renderer - GBA: fixed tilemap background horizontal flipping (Legend of Spyro - warning screen) - GBA: fixed d8 bits of scroll registers (ATV - Thunder Ridge Racers - menu screen) - SFC: DRAM refresh ticks the ALU MUL/DIV registers five steps forward [reported by kevtris] - SFC: merged dmaCounter and autoJoypadCounter into new shared clockCounter - left stub for old dmaCounter so that I can do some traces to ensure the new code's 100% identical GBA save states would have been broken since whenever I emulated ROM prefetch. I guess not many people are using the GBA core ...
70 lines
2.4 KiB
C++
70 lines
2.4 KiB
C++
auto PPU::Screen::run(uint x, uint y) -> uint15 {
|
|
if(ppu.blank()) return 0x7fff;
|
|
|
|
//determine active window
|
|
uint1 active[6] = {true, true, true, true, true, true}; //enable all layers if no windows are enabled
|
|
if(ppu.window0.io.enable || ppu.window1.io.enable || ppu.window2.io.enable) {
|
|
memory::copy(&active, &ppu.window3.io.active, sizeof(active));
|
|
if(ppu.window2.io.enable && ppu.window2.output) memory::copy(&active, &ppu.window2.io.active, sizeof(active));
|
|
if(ppu.window1.io.enable && ppu.window1.output) memory::copy(&active, &ppu.window1.io.active, sizeof(active));
|
|
if(ppu.window0.io.enable && ppu.window0.output) memory::copy(&active, &ppu.window0.io.active, sizeof(active));
|
|
}
|
|
|
|
//priority sorting: find topmost two pixels
|
|
Pixel layers[6] = {
|
|
ppu.objects.mosaic,
|
|
ppu.bg0.mosaic,
|
|
ppu.bg1.mosaic,
|
|
ppu.bg2.mosaic,
|
|
ppu.bg3.mosaic,
|
|
{true, 3, ppu.pram[0]},
|
|
};
|
|
|
|
uint aboveLayer = 5, belowLayer = 5;
|
|
for(int priority = 3; priority >= 0; priority--) {
|
|
for(int layer = 5; layer >= 0; layer--) {
|
|
if(layers[layer].enable && layers[layer].priority == priority && active[layer]) {
|
|
belowLayer = aboveLayer;
|
|
aboveLayer = layer;
|
|
}
|
|
}
|
|
}
|
|
|
|
auto above = layers[aboveLayer];
|
|
auto below = layers[belowLayer];
|
|
auto eva = min(16u, (uint)io.blendEVA);
|
|
auto evb = min(16u, (uint)io.blendEVB);
|
|
auto evy = min(16u, (uint)io.blendEVY);
|
|
uint15 color = above.color;
|
|
|
|
//color blending
|
|
if(active[SFX]) {
|
|
if(above.translucent && io.blendBelow[belowLayer]) {
|
|
color = blend(above.color, eva, below.color, evb);
|
|
} else if(io.blendMode == 1 && io.blendAbove[aboveLayer] && io.blendBelow[belowLayer]) {
|
|
color = blend(above.color, eva, below.color, evb);
|
|
} else if(io.blendMode == 2 && io.blendAbove[aboveLayer]) {
|
|
color = blend(above.color, 16 - evy, 0x7fff, evy);
|
|
} else if(io.blendMode == 3 && io.blendAbove[aboveLayer]) {
|
|
color = blend(above.color, 16 - evy, 0x0000, evy);
|
|
}
|
|
}
|
|
|
|
return color;
|
|
}
|
|
|
|
auto PPU::Screen::blend(uint15 above, uint eva, uint15 below, uint evb) -> uint15 {
|
|
uint5 ar = above >> 0, ag = above >> 5, ab = above >> 10;
|
|
uint5 br = below >> 0, bg = below >> 5, bb = below >> 10;
|
|
|
|
uint r = (ar * eva + br * evb) >> 4;
|
|
uint g = (ag * eva + bg * evb) >> 4;
|
|
uint b = (ab * eva + bb * evb) >> 4;
|
|
|
|
return min(31u, r) << 0 | min(31u, g) << 5 | min(31u, b) << 10;
|
|
}
|
|
|
|
auto PPU::Screen::power() -> void {
|
|
memory::fill(&io, sizeof(IO));
|
|
}
|