Update to v095r05 release.
byuu says:
Changelog:
- GBA: lots of emulation improvements
- PPU PRAM is 16-bits wide
- DMA masks &~1/Half, &~3/Word
- VRAM OBJ 8-bit writes are ignored
- OAM 8-bit writes are ignored
- BGnCNT unused bits are writable*
- BG(0,1)CNT can't set the d13
- BLDALPHA is readable (fixes Donkey Kong Country, etc)
- SNES: lots of code cleanups
- sfc/chip => sfc/coprocessor
- UI: save most recent controller selection
GBA test scores: 1552/1552, 37/38, 1020/1260
(* forgot to add the value to the read function, so endrift's I/O tests
for them will fail. Fixed locally.)
Note: SNES is the only system with multiple controller/expansion port
options, and as such is the only one with a "None" option. Because it's
shared by the controller and expansion port, it ends up sorted first in
the list. This means that on your first run, you'll need to go to Super
Famicom->Controller Port 1 and select "Gamepad", otherwise input won't
work.
Also note that changing the expansion port device requires loading a new
cart. Unlike controllers, you aren't meant to hotplug expansion port
devices.
2015-11-12 10:15:03 +00:00
|
|
|
auto PPU::Screen::scanline() -> void {
|
2016-06-14 10:51:54 +00:00
|
|
|
lineA = ppu.output + ppu.vcounter() * 1024;
|
|
|
|
lineB = lineA + (ppu.display.interlace ? 0 : 512);
|
|
|
|
if(ppu.display.interlace && ppu.field()) lineA += 512, lineB += 512;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2013-01-23 08:28:35 +00:00
|
|
|
//the first hires pixel of each scanline is transparent
|
|
|
|
//note: exact value initializations are not confirmed on hardware
|
2016-06-14 10:51:54 +00:00
|
|
|
math.above.color = paletteColor(0);
|
|
|
|
math.below.color = math.above.color;
|
2011-04-27 08:57:31 +00:00
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
math.above.colorEnable = !(ppu.window.r.col.aboveMask & 1);
|
|
|
|
math.below.colorEnable = !(ppu.window.r.col.belowMask & 1) && r.back.colorEnable;
|
2013-01-23 08:28:35 +00:00
|
|
|
|
|
|
|
math.transparent = true;
|
2016-06-14 10:51:54 +00:00
|
|
|
math.blendMode = false;
|
|
|
|
math.colorHalve = r.colorHalve && !r.blendMode && math.above.colorEnable;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
Update to v095r05 release.
byuu says:
Changelog:
- GBA: lots of emulation improvements
- PPU PRAM is 16-bits wide
- DMA masks &~1/Half, &~3/Word
- VRAM OBJ 8-bit writes are ignored
- OAM 8-bit writes are ignored
- BGnCNT unused bits are writable*
- BG(0,1)CNT can't set the d13
- BLDALPHA is readable (fixes Donkey Kong Country, etc)
- SNES: lots of code cleanups
- sfc/chip => sfc/coprocessor
- UI: save most recent controller selection
GBA test scores: 1552/1552, 37/38, 1020/1260
(* forgot to add the value to the read function, so endrift's I/O tests
for them will fail. Fixed locally.)
Note: SNES is the only system with multiple controller/expansion port
options, and as such is the only one with a "None" option. Because it's
shared by the controller and expansion port, it ends up sorted first in
the list. This means that on your first run, you'll need to go to Super
Famicom->Controller Port 1 and select "Gamepad", otherwise input won't
work.
Also note that changing the expansion port device requires loading a new
cart. Unlike controllers, you aren't meant to hotplug expansion port
devices.
2015-11-12 10:15:03 +00:00
|
|
|
auto PPU::Screen::run() -> void {
|
2016-06-14 10:51:54 +00:00
|
|
|
if(ppu.vcounter() == 0) return;
|
2011-04-30 13:12:15 +00:00
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
bool hires = ppu.r.pseudoHires || ppu.r.bgMode == 5 || ppu.r.bgMode == 6;
|
|
|
|
auto belowColor = below(hires);
|
|
|
|
auto aboveColor = above();
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
*lineA++ = *lineB++ = ppu.r.displayBrightness << 15 | (hires ? belowColor : aboveColor);
|
|
|
|
*lineA++ = *lineB++ = ppu.r.displayBrightness << 15 | (aboveColor);
|
2013-01-23 08:28:35 +00:00
|
|
|
}
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
auto PPU::Screen::below(bool hires) -> uint16 {
|
|
|
|
if(ppu.r.displayDisable || (!ppu.r.overscan && ppu.vcounter() >= 225)) return 0;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
Update to v095r05 release.
byuu says:
Changelog:
- GBA: lots of emulation improvements
- PPU PRAM is 16-bits wide
- DMA masks &~1/Half, &~3/Word
- VRAM OBJ 8-bit writes are ignored
- OAM 8-bit writes are ignored
- BGnCNT unused bits are writable*
- BG(0,1)CNT can't set the d13
- BLDALPHA is readable (fixes Donkey Kong Country, etc)
- SNES: lots of code cleanups
- sfc/chip => sfc/coprocessor
- UI: save most recent controller selection
GBA test scores: 1552/1552, 37/38, 1020/1260
(* forgot to add the value to the read function, so endrift's I/O tests
for them will fail. Fixed locally.)
Note: SNES is the only system with multiple controller/expansion port
options, and as such is the only one with a "None" option. Because it's
shared by the controller and expansion port, it ends up sorted first in
the list. This means that on your first run, you'll need to go to Super
Famicom->Controller Port 1 and select "Gamepad", otherwise input won't
work.
Also note that changing the expansion port device requires loading a new
cart. Unlike controllers, you aren't meant to hotplug expansion port
devices.
2015-11-12 10:15:03 +00:00
|
|
|
uint priority = 0;
|
2016-06-14 10:51:54 +00:00
|
|
|
if(ppu.bg1.output.below.priority) {
|
|
|
|
priority = ppu.bg1.output.below.priority;
|
|
|
|
if(r.directColor && (ppu.r.bgMode == 3 || ppu.r.bgMode == 4 || ppu.r.bgMode == 7)) {
|
|
|
|
math.below.color = directColor(ppu.bg1.output.below.palette, ppu.bg1.output.below.tile);
|
2010-08-09 13:28:56 +00:00
|
|
|
} else {
|
2016-06-14 10:51:54 +00:00
|
|
|
math.below.color = paletteColor(ppu.bg1.output.below.palette);
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-14 10:51:54 +00:00
|
|
|
if(ppu.bg2.output.below.priority > priority) {
|
|
|
|
priority = ppu.bg2.output.below.priority;
|
|
|
|
math.below.color = paletteColor(ppu.bg2.output.below.palette);
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
2016-06-14 10:51:54 +00:00
|
|
|
if(ppu.bg3.output.below.priority > priority) {
|
|
|
|
priority = ppu.bg3.output.below.priority;
|
|
|
|
math.below.color = paletteColor(ppu.bg3.output.below.palette);
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
2016-06-14 10:51:54 +00:00
|
|
|
if(ppu.bg4.output.below.priority > priority) {
|
|
|
|
priority = ppu.bg4.output.below.priority;
|
|
|
|
math.below.color = paletteColor(ppu.bg4.output.below.palette);
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
2016-06-15 11:32:17 +00:00
|
|
|
if(ppu.obj.output.below.priority > priority) {
|
|
|
|
priority = ppu.obj.output.below.priority;
|
|
|
|
math.below.color = paletteColor(ppu.obj.output.below.palette);
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
2016-06-14 10:51:54 +00:00
|
|
|
if(math.transparent = (priority == 0)) math.below.color = paletteColor(0);
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2013-01-23 08:28:35 +00:00
|
|
|
if(!hires) return 0;
|
2016-06-28 10:43:47 +00:00
|
|
|
if(!math.below.colorEnable) return math.above.colorEnable ? math.below.color : (uint15)0;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
return blend(
|
2016-06-28 10:43:47 +00:00
|
|
|
math.above.colorEnable ? math.below.color : (uint15)0,
|
2016-06-14 10:51:54 +00:00
|
|
|
math.blendMode ? math.above.color : fixedColor()
|
2013-01-23 08:28:35 +00:00
|
|
|
);
|
|
|
|
}
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
auto PPU::Screen::above() -> uint16 {
|
|
|
|
if(ppu.r.displayDisable || (!ppu.r.overscan && ppu.vcounter() >= 225)) return 0;
|
2013-01-23 08:28:35 +00:00
|
|
|
|
Update to v095r05 release.
byuu says:
Changelog:
- GBA: lots of emulation improvements
- PPU PRAM is 16-bits wide
- DMA masks &~1/Half, &~3/Word
- VRAM OBJ 8-bit writes are ignored
- OAM 8-bit writes are ignored
- BGnCNT unused bits are writable*
- BG(0,1)CNT can't set the d13
- BLDALPHA is readable (fixes Donkey Kong Country, etc)
- SNES: lots of code cleanups
- sfc/chip => sfc/coprocessor
- UI: save most recent controller selection
GBA test scores: 1552/1552, 37/38, 1020/1260
(* forgot to add the value to the read function, so endrift's I/O tests
for them will fail. Fixed locally.)
Note: SNES is the only system with multiple controller/expansion port
options, and as such is the only one with a "None" option. Because it's
shared by the controller and expansion port, it ends up sorted first in
the list. This means that on your first run, you'll need to go to Super
Famicom->Controller Port 1 and select "Gamepad", otherwise input won't
work.
Also note that changing the expansion port device requires loading a new
cart. Unlike controllers, you aren't meant to hotplug expansion port
devices.
2015-11-12 10:15:03 +00:00
|
|
|
uint priority = 0;
|
2016-06-14 10:51:54 +00:00
|
|
|
if(ppu.bg1.output.above.priority) {
|
|
|
|
priority = ppu.bg1.output.above.priority;
|
|
|
|
if(r.directColor && (ppu.r.bgMode == 3 || ppu.r.bgMode == 4 || ppu.r.bgMode == 7)) {
|
|
|
|
math.above.color = directColor(ppu.bg1.output.above.palette, ppu.bg1.output.above.tile);
|
2010-08-09 13:28:56 +00:00
|
|
|
} else {
|
2016-06-14 10:51:54 +00:00
|
|
|
math.above.color = paletteColor(ppu.bg1.output.above.palette);
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
2016-06-14 10:51:54 +00:00
|
|
|
math.below.colorEnable = r.bg1.colorEnable;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
2016-06-14 10:51:54 +00:00
|
|
|
if(ppu.bg2.output.above.priority > priority) {
|
|
|
|
priority = ppu.bg2.output.above.priority;
|
|
|
|
math.above.color = paletteColor(ppu.bg2.output.above.palette);
|
|
|
|
math.below.colorEnable = r.bg2.colorEnable;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
2016-06-14 10:51:54 +00:00
|
|
|
if(ppu.bg3.output.above.priority > priority) {
|
|
|
|
priority = ppu.bg3.output.above.priority;
|
|
|
|
math.above.color = paletteColor(ppu.bg3.output.above.palette);
|
|
|
|
math.below.colorEnable = r.bg3.colorEnable;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
2016-06-14 10:51:54 +00:00
|
|
|
if(ppu.bg4.output.above.priority > priority) {
|
|
|
|
priority = ppu.bg4.output.above.priority;
|
|
|
|
math.above.color = paletteColor(ppu.bg4.output.above.palette);
|
|
|
|
math.below.colorEnable = r.bg4.colorEnable;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
2016-06-15 11:32:17 +00:00
|
|
|
if(ppu.obj.output.above.priority > priority) {
|
|
|
|
priority = ppu.obj.output.above.priority;
|
|
|
|
math.above.color = paletteColor(ppu.obj.output.above.palette);
|
|
|
|
math.below.colorEnable = r.obj.colorEnable && ppu.obj.output.above.palette >= 192;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
2013-01-23 08:28:35 +00:00
|
|
|
if(priority == 0) {
|
2016-06-14 10:51:54 +00:00
|
|
|
math.above.color = paletteColor(0);
|
|
|
|
math.below.colorEnable = r.back.colorEnable;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
if(!ppu.window.output.below.colorEnable) math.below.colorEnable = false;
|
|
|
|
math.above.colorEnable = ppu.window.output.above.colorEnable;
|
2016-06-28 10:43:47 +00:00
|
|
|
if(!math.below.colorEnable) return math.above.colorEnable ? math.above.color : (uint15)0;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
if(r.blendMode && math.transparent) {
|
|
|
|
math.blendMode = false;
|
|
|
|
math.colorHalve = false;
|
2010-08-09 13:28:56 +00:00
|
|
|
} else {
|
2016-06-14 10:51:54 +00:00
|
|
|
math.blendMode = r.blendMode;
|
|
|
|
math.colorHalve = r.colorHalve && math.above.colorEnable;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
return blend(
|
2016-06-28 10:43:47 +00:00
|
|
|
math.above.colorEnable ? math.above.color : (uint15)0,
|
2016-06-14 10:51:54 +00:00
|
|
|
math.blendMode ? math.below.color : fixedColor()
|
2013-01-23 08:28:35 +00:00
|
|
|
);
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2016-06-28 10:43:47 +00:00
|
|
|
auto PPU::Screen::blend(uint x, uint y) const -> uint15 {
|
2016-06-14 10:51:54 +00:00
|
|
|
if(!r.colorMode) {
|
|
|
|
if(!math.colorHalve) {
|
Update to v095r05 release.
byuu says:
Changelog:
- GBA: lots of emulation improvements
- PPU PRAM is 16-bits wide
- DMA masks &~1/Half, &~3/Word
- VRAM OBJ 8-bit writes are ignored
- OAM 8-bit writes are ignored
- BGnCNT unused bits are writable*
- BG(0,1)CNT can't set the d13
- BLDALPHA is readable (fixes Donkey Kong Country, etc)
- SNES: lots of code cleanups
- sfc/chip => sfc/coprocessor
- UI: save most recent controller selection
GBA test scores: 1552/1552, 37/38, 1020/1260
(* forgot to add the value to the read function, so endrift's I/O tests
for them will fail. Fixed locally.)
Note: SNES is the only system with multiple controller/expansion port
options, and as such is the only one with a "None" option. Because it's
shared by the controller and expansion port, it ends up sorted first in
the list. This means that on your first run, you'll need to go to Super
Famicom->Controller Port 1 and select "Gamepad", otherwise input won't
work.
Also note that changing the expansion port device requires loading a new
cart. Unlike controllers, you aren't meant to hotplug expansion port
devices.
2015-11-12 10:15:03 +00:00
|
|
|
uint sum = x + y;
|
|
|
|
uint carry = (sum - ((x ^ y) & 0x0421)) & 0x8420;
|
2010-08-09 13:28:56 +00:00
|
|
|
return (sum - carry) | (carry - (carry >> 5));
|
|
|
|
} else {
|
|
|
|
return (x + y - ((x ^ y) & 0x0421)) >> 1;
|
|
|
|
}
|
|
|
|
} else {
|
Update to v095r05 release.
byuu says:
Changelog:
- GBA: lots of emulation improvements
- PPU PRAM is 16-bits wide
- DMA masks &~1/Half, &~3/Word
- VRAM OBJ 8-bit writes are ignored
- OAM 8-bit writes are ignored
- BGnCNT unused bits are writable*
- BG(0,1)CNT can't set the d13
- BLDALPHA is readable (fixes Donkey Kong Country, etc)
- SNES: lots of code cleanups
- sfc/chip => sfc/coprocessor
- UI: save most recent controller selection
GBA test scores: 1552/1552, 37/38, 1020/1260
(* forgot to add the value to the read function, so endrift's I/O tests
for them will fail. Fixed locally.)
Note: SNES is the only system with multiple controller/expansion port
options, and as such is the only one with a "None" option. Because it's
shared by the controller and expansion port, it ends up sorted first in
the list. This means that on your first run, you'll need to go to Super
Famicom->Controller Port 1 and select "Gamepad", otherwise input won't
work.
Also note that changing the expansion port device requires loading a new
cart. Unlike controllers, you aren't meant to hotplug expansion port
devices.
2015-11-12 10:15:03 +00:00
|
|
|
uint diff = x - y + 0x8420;
|
|
|
|
uint borrow = (diff - ((x ^ y) & 0x8420)) & 0x8420;
|
2016-06-14 10:51:54 +00:00
|
|
|
if(!math.colorHalve) {
|
2010-08-09 13:28:56 +00:00
|
|
|
return (diff - borrow) & (borrow - (borrow >> 5));
|
|
|
|
} else {
|
|
|
|
return (((diff - borrow) & (borrow - (borrow >> 5))) & 0x7bde) >> 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-28 10:43:47 +00:00
|
|
|
auto PPU::Screen::paletteColor(uint8 palette) const -> uint15 {
|
2016-06-14 10:51:54 +00:00
|
|
|
ppu.latch.cgramAddress = palette;
|
2016-06-28 10:43:47 +00:00
|
|
|
return ppu.cgram[palette];
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2016-06-28 10:43:47 +00:00
|
|
|
auto PPU::Screen::directColor(uint palette, uint tile) const -> uint15 {
|
2010-08-09 13:28:56 +00:00
|
|
|
//palette = -------- BBGGGRRR
|
|
|
|
//tile = ---bgr-- --------
|
|
|
|
//output = 0BBb00GG Gg0RRRr0
|
|
|
|
return ((palette << 7) & 0x6000) + ((tile >> 0) & 0x1000)
|
|
|
|
+ ((palette << 4) & 0x0380) + ((tile >> 5) & 0x0040)
|
|
|
|
+ ((palette << 2) & 0x001c) + ((tile >> 9) & 0x0002);
|
|
|
|
}
|
|
|
|
|
2016-06-28 10:43:47 +00:00
|
|
|
auto PPU::Screen::fixedColor() const -> uint15 {
|
2016-06-14 10:51:54 +00:00
|
|
|
return r.colorBlue << 10 | r.colorGreen << 5 | r.colorRed << 0;
|
2013-01-23 08:28:35 +00:00
|
|
|
}
|
|
|
|
|
Update to v095r05 release.
byuu says:
Changelog:
- GBA: lots of emulation improvements
- PPU PRAM is 16-bits wide
- DMA masks &~1/Half, &~3/Word
- VRAM OBJ 8-bit writes are ignored
- OAM 8-bit writes are ignored
- BGnCNT unused bits are writable*
- BG(0,1)CNT can't set the d13
- BLDALPHA is readable (fixes Donkey Kong Country, etc)
- SNES: lots of code cleanups
- sfc/chip => sfc/coprocessor
- UI: save most recent controller selection
GBA test scores: 1552/1552, 37/38, 1020/1260
(* forgot to add the value to the read function, so endrift's I/O tests
for them will fail. Fixed locally.)
Note: SNES is the only system with multiple controller/expansion port
options, and as such is the only one with a "None" option. Because it's
shared by the controller and expansion port, it ends up sorted first in
the list. This means that on your first run, you'll need to go to Super
Famicom->Controller Port 1 and select "Gamepad", otherwise input won't
work.
Also note that changing the expansion port device requires loading a new
cart. Unlike controllers, you aren't meant to hotplug expansion port
devices.
2015-11-12 10:15:03 +00:00
|
|
|
auto PPU::Screen::reset() -> void {
|
2016-06-14 10:51:54 +00:00
|
|
|
r.blendMode = random(false);
|
|
|
|
r.directColor = random(false);
|
|
|
|
r.colorMode = random(false);
|
|
|
|
r.colorHalve = random(false);
|
|
|
|
r.bg1.colorEnable = random(false);
|
|
|
|
r.bg2.colorEnable = random(false);
|
|
|
|
r.bg3.colorEnable = random(false);
|
|
|
|
r.bg4.colorEnable = random(false);
|
2016-06-15 11:32:17 +00:00
|
|
|
r.obj.colorEnable = random(false);
|
2016-06-14 10:51:54 +00:00
|
|
|
r.back.colorEnable = random(false);
|
|
|
|
r.colorBlue = random(0);
|
|
|
|
r.colorGreen = random(0);
|
|
|
|
r.colorRed = random(0);
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|