2010-08-09 13:28:56 +00:00
|
|
|
#include "list.cpp"
|
|
|
|
|
2016-06-15 11:32:17 +00:00
|
|
|
auto PPU::Object::addressReset() -> void {
|
2016-06-14 10:51:54 +00:00
|
|
|
ppu.r.oamAddress = ppu.r.oamBaseAddress;
|
|
|
|
setFirstSprite();
|
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
|
|
|
}
|
|
|
|
|
2016-06-15 11:32:17 +00:00
|
|
|
auto PPU::Object::setFirstSprite() -> void {
|
2016-06-14 10:51:54 +00:00
|
|
|
r.firstSprite = !ppu.r.oamPriority ? 0 : ppu.r.oamAddress >> 2;
|
2010-09-24 13:15:21 +00:00
|
|
|
}
|
|
|
|
|
2016-06-15 11:32:17 +00:00
|
|
|
auto PPU::Object::frame() -> void {
|
2016-06-14 10:51:54 +00:00
|
|
|
r.timeOver = false;
|
|
|
|
r.rangeOver = false;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2016-06-15 11:32:17 +00:00
|
|
|
auto PPU::Object::scanline() -> void {
|
2010-08-09 13:28:56 +00:00
|
|
|
t.x = 0;
|
2016-06-14 10:51:54 +00:00
|
|
|
t.y = ppu.vcounter();
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
t.itemCount = 0;
|
|
|
|
t.tileCount = 0;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
t.active = !t.active;
|
2016-06-14 10:51:54 +00:00
|
|
|
auto oamItem = t.item[t.active];
|
|
|
|
auto oamTile = t.tile[t.active];
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
if(t.y == ppu.vdisp() && !ppu.r.displayDisable) addressReset();
|
|
|
|
if(t.y >= ppu.vdisp() - 1) return;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
for(auto n : range(32)) oamItem[n].valid = false; //default to invalid
|
|
|
|
for(auto n : range(34)) oamTile[n].valid = false; //default to invalid
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2016-02-18 10:32:22 +00:00
|
|
|
for(auto n : range(128)) {
|
2016-06-14 10:51:54 +00:00
|
|
|
uint7 sprite = r.firstSprite + n;
|
|
|
|
if(!onScanline(list[sprite])) continue;
|
|
|
|
if(t.itemCount++ >= 32) break;
|
|
|
|
oamItem[t.itemCount - 1] = {true, sprite};
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
if(t.itemCount > 0 && oamItem[t.itemCount - 1].valid) {
|
|
|
|
ppu.latch.oamAddress = 0x0200 + (oamItem[t.itemCount - 1].index >> 2);
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-15 11:32:17 +00:00
|
|
|
auto PPU::Object::onScanline(Sprite& sprite) -> bool {
|
2010-08-09 13:28:56 +00:00
|
|
|
if(sprite.x > 256 && (sprite.x + sprite.width() - 1) < 512) return false;
|
2016-06-14 10:51:54 +00:00
|
|
|
int height = sprite.height() >> r.interlace;
|
2010-08-09 13:28:56 +00:00
|
|
|
if(t.y >= sprite.y && t.y < (sprite.y + height)) return true;
|
|
|
|
if((sprite.y + height) >= 256 && t.y < ((sprite.y + height) & 255)) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-06-15 11:32:17 +00:00
|
|
|
auto PPU::Object::run() -> void {
|
2016-06-14 10:51:54 +00:00
|
|
|
output.above.priority = 0;
|
|
|
|
output.below.priority = 0;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
auto oamTile = t.tile[!t.active];
|
2016-02-18 10:32:22 +00:00
|
|
|
uint x = t.x++;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2016-02-18 10:32:22 +00:00
|
|
|
for(auto n : range(34)) {
|
2016-06-14 10:51:54 +00:00
|
|
|
const auto& tile = oamTile[n];
|
2016-02-18 10:32:22 +00:00
|
|
|
if(!tile.valid) break;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
int px = x - (int9)tile.x;
|
2010-08-09 13:28:56 +00:00
|
|
|
if(px & ~7) continue;
|
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
uint color = 0, shift = tile.hflip ? px : 7 - px;
|
|
|
|
color += tile.data >> (shift + 0) & 1;
|
|
|
|
color += tile.data >> (shift + 7) & 2;
|
|
|
|
color += tile.data >> (shift + 14) & 4;
|
|
|
|
color += tile.data >> (shift + 21) & 8;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
if(color) {
|
2016-06-14 10:51:54 +00:00
|
|
|
if(r.aboveEnable) {
|
|
|
|
output.above.palette = tile.palette + color;
|
|
|
|
output.above.priority = r.priority[tile.priority];
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
if(r.belowEnable) {
|
|
|
|
output.below.palette = tile.palette + color;
|
|
|
|
output.below.priority = r.priority[tile.priority];
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-15 11:32:17 +00:00
|
|
|
auto PPU::Object::tilefetch() -> void {
|
2016-06-14 10:51:54 +00:00
|
|
|
auto oamItem = t.item[t.active];
|
|
|
|
auto oamTile = t.tile[t.active];
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2016-02-18 10:32:22 +00:00
|
|
|
for(int i = 31; i >= 0; i--) {
|
2016-06-14 10:51:54 +00:00
|
|
|
if(!oamItem[i].valid) continue;
|
|
|
|
const auto& sprite = list[oamItem[i].index];
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
uint tileWidth = sprite.width() >> 3;
|
2016-02-18 10:32:22 +00:00
|
|
|
int x = sprite.x;
|
|
|
|
int y = (t.y - sprite.y) & 0xff;
|
2016-06-14 10:51:54 +00:00
|
|
|
if(r.interlace) y <<= 1;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
if(sprite.vflip) {
|
|
|
|
if(sprite.width() == sprite.height()) {
|
|
|
|
y = (sprite.height() - 1) - y;
|
|
|
|
} else if(y < sprite.width()) {
|
|
|
|
y = (sprite.width() - 1) - y;
|
|
|
|
} else {
|
|
|
|
y = sprite.width() + ((sprite.width() - 1) - (y - sprite.width()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
if(r.interlace) {
|
|
|
|
y = !sprite.vflip ? y + ppu.field() : y - ppu.field();
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
x &= 511;
|
|
|
|
y &= 255;
|
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
uint16 tiledataAddress = r.tiledataAddress;
|
2010-08-09 13:28:56 +00:00
|
|
|
uint16 chrx = (sprite.character >> 0) & 15;
|
|
|
|
uint16 chry = (sprite.character >> 4) & 15;
|
2016-06-14 10:51:54 +00:00
|
|
|
if(sprite.nameSelect) {
|
|
|
|
tiledataAddress += (256 * 32) + (r.nameSelect << 13);
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
chry += (y >> 3);
|
|
|
|
chry &= 15;
|
|
|
|
chry <<= 4;
|
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
for(uint tx : range(tileWidth)) {
|
2016-02-18 10:32:22 +00:00
|
|
|
uint sx = (x + (tx << 3)) & 511;
|
2010-08-09 13:28:56 +00:00
|
|
|
if(x != 256 && sx >= 256 && (sx + 7) < 512) continue;
|
2016-06-14 10:51:54 +00:00
|
|
|
if(t.tileCount++ >= 34) break;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
uint n = t.tileCount - 1;
|
|
|
|
oamTile[n].valid = true;
|
|
|
|
oamTile[n].x = sx;
|
|
|
|
oamTile[n].priority = sprite.priority;
|
|
|
|
oamTile[n].palette = 128 + (sprite.palette << 4);
|
|
|
|
oamTile[n].hflip = sprite.hflip;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
uint mx = !sprite.hflip ? tx : (tileWidth - 1) - tx;
|
|
|
|
uint pos = tiledataAddress + ((chry + ((chrx + mx) & 15)) << 5);
|
2010-08-09 13:28:56 +00:00
|
|
|
uint16 addr = (pos & 0xffe0) + ((y & 7) * 2);
|
|
|
|
|
2016-06-15 11:32:17 +00:00
|
|
|
oamTile[n].data.byte(0) = ppu.vram[addr + 0];
|
|
|
|
oamTile[n].data.byte(1) = ppu.vram[addr + 1];
|
2016-06-14 10:51:54 +00:00
|
|
|
ppu.addClocks(2);
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2016-06-15 11:32:17 +00:00
|
|
|
oamTile[n].data.byte(2) = ppu.vram[addr + 16];
|
|
|
|
oamTile[n].data.byte(3) = ppu.vram[addr + 17];
|
2016-06-14 10:51:54 +00:00
|
|
|
ppu.addClocks(2);
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
if(t.tileCount < 34) ppu.addClocks((34 - t.tileCount) * 4);
|
|
|
|
r.timeOver |= (t.tileCount > 34);
|
|
|
|
r.rangeOver |= (t.itemCount > 32);
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2016-06-15 11:32:17 +00:00
|
|
|
auto PPU::Object::reset() -> void {
|
2016-02-18 10:32:22 +00:00
|
|
|
for(auto n : range(128)) {
|
|
|
|
list[n].x = 0;
|
|
|
|
list[n].y = 0;
|
|
|
|
list[n].character = 0;
|
2016-06-14 10:51:54 +00:00
|
|
|
list[n].nameSelect = 0;
|
2016-02-18 10:32:22 +00:00
|
|
|
list[n].vflip = 0;
|
|
|
|
list[n].hflip = 0;
|
|
|
|
list[n].priority = 0;
|
|
|
|
list[n].palette = 0;
|
|
|
|
list[n].size = 0;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
2011-04-27 08:57:31 +00:00
|
|
|
synchronize();
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
t.x = 0;
|
|
|
|
t.y = 0;
|
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
t.itemCount = 0;
|
|
|
|
t.tileCount = 0;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
t.active = 0;
|
2016-02-18 10:32:22 +00:00
|
|
|
for(auto p : range(2)) {
|
|
|
|
for(auto n : range(32)) {
|
|
|
|
t.item[p][n].valid = false;
|
|
|
|
t.item[p][n].index = 0;
|
|
|
|
}
|
|
|
|
for(auto n : range(34)) {
|
|
|
|
t.tile[p][n].valid = false;
|
|
|
|
t.tile[p][n].x = 0;
|
|
|
|
t.tile[p][n].priority = 0;
|
|
|
|
t.tile[p][n].palette = 0;
|
|
|
|
t.tile[p][n].hflip = 0;
|
2016-06-14 10:51:54 +00:00
|
|
|
t.tile[p][n].data = 0;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
r.aboveEnable = random(false);
|
|
|
|
r.belowEnable = random(false);
|
|
|
|
r.interlace = random(false);
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
r.baseSize = random(0);
|
|
|
|
r.nameSelect = random(0);
|
|
|
|
r.tiledataAddress = (random(0x0000) & 3) << 14;
|
|
|
|
r.firstSprite = 0;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
for(auto& p : r.priority) p = 0;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
r.timeOver = false;
|
|
|
|
r.rangeOver = false;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
output.above.palette = 0;
|
|
|
|
output.above.priority = 0;
|
|
|
|
output.below.palette = 0;
|
|
|
|
output.below.priority = 0;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|