mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-02-22 06:02:28 +01:00
byuu says: Changelog: - (u)int(max,ptr) abbreviations removed; use _t suffix now [didn't feel like they were contributing enough to be worth it] - cleaned up nall::integer,natural,real functionality - toInteger, toNatural, toReal for parsing strings to numbers - fromInteger, fromNatural, fromReal for creating strings from numbers - (string,Markup::Node,SQL-based-classes)::(integer,natural,real) left unchanged - template<typename T> numeral(T value, long padding, char padchar) -> string for print() formatting - deduces integer,natural,real based on T ... cast the value if you want to override - there still exists binary,octal,hex,pointer for explicit print() formatting - lstring -> string_vector [but using lstring = string_vector; is declared] - would be nice to remove the using lstring eventually ... but that'd probably require 10,000 lines of changes >_> - format -> string_format [no using here; format was too ambiguous] - using integer = Integer<sizeof(int)*8>; and using natural = Natural<sizeof(uint)*8>; declared - for consistency with boolean. These three are meant for creating zero-initialized values implicitly (various uses) - R65816::io() -> idle() and SPC700::io() -> idle() [more clear; frees up struct IO {} io; naming] - SFC CPU, PPU, SMP use struct IO {} io; over struct (Status,Registers) {} (status,registers); now - still some CPU::Status status values ... they didn't really fit into IO functionality ... will have to think about this more - SFC CPU, PPU, SMP now use step() exclusively instead of addClocks() calling into step() - SFC CPU joypad1_bits, joypad2_bits were unused; killed them - SFC PPU CGRAM moved into PPU::Screen; since nothing else uses it - SFC PPU OAM moved into PPU::Object; since nothing else uses it - the raw uint8[544] array is gone. OAM::read() constructs values from the OAM::Object[512] table now - this avoids having to determine how we want to sub-divide the two OAM memory sections - this also eliminates the OAM::synchronize() functionality - probably more I'm forgetting The FPS fluctuations are driving me insane. This WIP went from 128fps to 137fps. Settled on 133.5fps for the final build. But nothing I changed should have affected performance at all. This level of fluctuation makes it damn near impossible to know whether I'm speeding things up or slowing things down with changes.
103 lines
2.6 KiB
C++
103 lines
2.6 KiB
C++
//called once every four clock cycles;
|
|
//as NMI steps by scanlines (divisible by 4) and IRQ by PPU 4-cycle dots.
|
|
//
|
|
//ppu.(vh)counter(n) returns the value of said counters n-clocks before current time;
|
|
//it is used to emulate hardware communication delay between opcode and interrupt units.
|
|
auto CPU::pollInterrupts() -> void {
|
|
//NMI hold
|
|
if(status.nmiHold) {
|
|
status.nmiHold = false;
|
|
if(io.nmiEnabled) status.nmiTransition = true;
|
|
}
|
|
|
|
//NMI test
|
|
bool nmiValid = vcounter(2) >= ppu.vdisp();
|
|
if(!status.nmiValid && nmiValid) {
|
|
//0->1 edge sensitive transition
|
|
status.nmiLine = true;
|
|
status.nmiHold = true; //hold /NMI for four cycles
|
|
} else if(status.nmiValid && !nmiValid) {
|
|
//1->0 edge sensitive transition
|
|
status.nmiLine = false;
|
|
}
|
|
status.nmiValid = nmiValid;
|
|
|
|
//IRQ hold
|
|
status.irqHold = false;
|
|
if(status.irqLine) {
|
|
if(io.virqEnabled || io.hirqEnabled) status.irqTransition = true;
|
|
}
|
|
|
|
//IRQ test
|
|
bool irqValid = io.virqEnabled || io.hirqEnabled;
|
|
if(irqValid) {
|
|
if((io.virqEnabled && vcounter(10) != (io.virqPos))
|
|
|| (io.hirqEnabled && hcounter(10) != (io.hirqPos + 1) * 4)
|
|
|| (io.virqPos && vcounter(6) == 0) //IRQs cannot trigger on last dot of field
|
|
) irqValid = false;
|
|
}
|
|
if(!status.irqValid && irqValid) {
|
|
//0->1 edge sensitive transition
|
|
status.irqLine = true;
|
|
status.irqHold = true; //hold /IRQ for four cycles
|
|
}
|
|
status.irqValid = irqValid;
|
|
}
|
|
|
|
auto CPU::nmitimenUpdate(uint8 data) -> void {
|
|
bool nmiEnabled = io.nmiEnabled;
|
|
bool virqEnabled = io.virqEnabled;
|
|
bool hirqEnabled = io.hirqEnabled;
|
|
io.nmiEnabled = data & 0x80;
|
|
io.virqEnabled = data & 0x20;
|
|
io.hirqEnabled = data & 0x10;
|
|
|
|
//0->1 edge sensitive transition
|
|
if(!nmiEnabled && io.nmiEnabled && status.nmiLine) {
|
|
status.nmiTransition = true;
|
|
}
|
|
|
|
//?->1 level sensitive transition
|
|
if(io.virqEnabled && !io.hirqEnabled && status.irqLine) {
|
|
status.irqTransition = true;
|
|
}
|
|
|
|
if(!io.virqEnabled && !io.hirqEnabled) {
|
|
status.irqLine = false;
|
|
status.irqTransition = false;
|
|
}
|
|
|
|
status.irqLock = true;
|
|
}
|
|
|
|
auto CPU::rdnmi() -> bool {
|
|
bool result = status.nmiLine;
|
|
if(!status.nmiHold) {
|
|
status.nmiLine = false;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
auto CPU::timeup() -> bool {
|
|
bool result = status.irqLine;
|
|
if(!status.irqHold) {
|
|
status.irqLine = false;
|
|
status.irqTransition = false;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
auto CPU::nmiTest() -> bool {
|
|
if(!status.nmiTransition) return false;
|
|
status.nmiTransition = false;
|
|
r.wai = false;
|
|
return true;
|
|
}
|
|
|
|
auto CPU::irqTest() -> bool {
|
|
if(!status.irqTransition && !r.irq) return false;
|
|
status.irqTransition = false;
|
|
r.wai = false;
|
|
return !r.p.i;
|
|
}
|