mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-02-24 07:02:27 +01:00
byuu says: Changelog: - GB core code cleanup completed - GBA core code cleanup completed - some more cleanup on missed processor/arm functions/variables - fixed FC loading icarus bug - "Load ROM File" icarus functionality restored - minor code unification efforts all around (not perfect yet) - MMIO->IO - mmio.cpp->io.cpp - read,write->readIO,writeIO It's been a very long work in progress ... starting all the way back with v094r09, but the major part of the higan code cleanup is now completed! Of course, it's very important to note that this is only for the basic style: - under_score functions and variables are now camelCase - return-type function-name() are now auto function-name() -> return-type - Natural<T>/Integer<T> replace (u)intT_n types where possible - signed/unsigned are now int/uint - most of the x==true,x==false tests changed to x,!x A lot of spot improvements to consistency, simplicity and quality have gone in along the way, of course. But we'll probably never fully finishing beautifying every last line of code in the entire codebase. Still, this is a really great start. Going forward, WIP diffs should start being smaller and of higher quality once again. I know the joke is, "until my coding style changes again", but ... this was way too stressful, way too time consuming, and way too risky. I'm too old and tired now for extreme upheavel like this again. The only major change I'm slowly mulling over would be renaming the using Natural<T>/Integer<T> = (u)intT; shorthand to something that isn't as easily confused with the (u)int_t types ... but we'll see. I'll definitely continue to change small things all the time, but for the larger picture, I need to just accept the style I have and live with it.
81 lines
2.7 KiB
C++
81 lines
2.7 KiB
C++
auto PPU::renderObjects() -> void {
|
|
if(regs.control.enable[OBJ] == false) return;
|
|
for(auto n : range(128)) renderObject(object[n]);
|
|
}
|
|
|
|
//px,py = pixel coordinates within sprite [0,0 - width,height)
|
|
//fx,fy = affine pixel coordinates
|
|
//pa,pb,pc,pd = affine pixel adjustments
|
|
//x,y = adjusted coordinates within sprite (linear = vflip/hflip, affine = rotation/zoom)
|
|
auto PPU::renderObject(Object& obj) -> void {
|
|
uint8 py = regs.vcounter - obj.y;
|
|
if(obj.affine == 0 && obj.affinesize == 1) return; //hidden
|
|
if(py >= obj.height << obj.affinesize) return; //offscreen
|
|
|
|
auto& output = layer[OBJ];
|
|
uint rowsize = regs.control.objmapping == 0 ? 32 >> obj.colors : obj.width / 8;
|
|
uint baseaddr = obj.character * 32;
|
|
|
|
if(obj.mosaic && regs.mosaic.objvsize) {
|
|
int mosaicy = (regs.vcounter / (1 + regs.mosaic.objvsize)) * (1 + regs.mosaic.objvsize);
|
|
py = obj.y >= 160 || mosaicy - obj.y >= 0 ? mosaicy - obj.y : 0;
|
|
}
|
|
|
|
int16 pa = objectparam[obj.affineparam].pa;
|
|
int16 pb = objectparam[obj.affineparam].pb;
|
|
int16 pc = objectparam[obj.affineparam].pc;
|
|
int16 pd = objectparam[obj.affineparam].pd;
|
|
|
|
//center-of-sprite coordinates
|
|
int16 centerx = obj.width / 2;
|
|
int16 centery = obj.height / 2;
|
|
|
|
//origin coordinates (top-left of sprite)
|
|
int28 originx = -(centerx << obj.affinesize);
|
|
int28 originy = -(centery << obj.affinesize) + py;
|
|
|
|
//fractional pixel coordinates
|
|
int28 fx = originx * pa + originy * pb;
|
|
int28 fy = originx * pc + originy * pd;
|
|
|
|
for(uint px = 0; px < (obj.width << obj.affinesize); px++) {
|
|
uint x, y;
|
|
if(obj.affine == 0) {
|
|
x = px;
|
|
y = py;
|
|
if(obj.hflip) x ^= obj.width - 1;
|
|
if(obj.vflip) y ^= obj.height - 1;
|
|
} else {
|
|
x = (fx >> 8) + centerx;
|
|
y = (fy >> 8) + centery;
|
|
}
|
|
|
|
uint9 ox = obj.x + px;
|
|
if(ox < 240 && x < obj.width && y < obj.height) {
|
|
uint offset = (y / 8) * rowsize + (x / 8);
|
|
offset = offset * 64 + (y & 7) * 8 + (x & 7);
|
|
|
|
uint8 color = readObjectVRAM(baseaddr + (offset >> !obj.colors));
|
|
if(obj.colors == 0) color = (x & 1) ? color >> 4 : color & 15;
|
|
if(color) {
|
|
if(obj.mode & 2) {
|
|
windowmask[Obj][ox] = true;
|
|
} else if(output[ox].enable == false || obj.priority < output[ox].priority) {
|
|
if(obj.colors == 0) color = obj.palette * 16 + color;
|
|
output[ox].write(true, obj.priority, pram[256 + color], obj.mode == 1, obj.mosaic);
|
|
}
|
|
}
|
|
}
|
|
|
|
fx += pa;
|
|
fy += pc;
|
|
}
|
|
}
|
|
|
|
auto PPU::readObjectVRAM(uint addr) const -> uint8 {
|
|
if(regs.control.bgmode == 3 || regs.control.bgmode == 4 || regs.control.bgmode == 5) {
|
|
if(addr <= 0x3fff) return 0u;
|
|
}
|
|
return vram[0x10000 + (addr & 0x7fff)];
|
|
}
|