2010-08-09 13:28:56 +00:00
|
|
|
//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.
|
2016-03-26 01:56:15 +00:00
|
|
|
auto CPU::pollInterrupts() -> void {
|
2010-08-09 13:28:56 +00:00
|
|
|
//NMI hold
|
|
|
|
if(status.nmi_hold) {
|
|
|
|
status.nmi_hold = false;
|
|
|
|
if(status.nmi_enabled) status.nmi_transition = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//NMI test
|
|
|
|
bool nmi_valid = (vcounter(2) >= (!ppu.overscan() ? 225 : 240));
|
|
|
|
if(!status.nmi_valid && nmi_valid) {
|
|
|
|
//0->1 edge sensitive transition
|
|
|
|
status.nmi_line = true;
|
|
|
|
status.nmi_hold = true; //hold /NMI for four cycles
|
|
|
|
} else if(status.nmi_valid && !nmi_valid) {
|
|
|
|
//1->0 edge sensitive transition
|
|
|
|
status.nmi_line = false;
|
|
|
|
}
|
|
|
|
status.nmi_valid = nmi_valid;
|
|
|
|
|
|
|
|
//IRQ hold
|
|
|
|
status.irq_hold = false;
|
|
|
|
if(status.irq_line) {
|
|
|
|
if(status.virq_enabled || status.hirq_enabled) status.irq_transition = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//IRQ test
|
|
|
|
bool irq_valid = (status.virq_enabled || status.hirq_enabled);
|
|
|
|
if(irq_valid) {
|
|
|
|
if((status.virq_enabled && vcounter(10) != (status.virq_pos))
|
|
|
|
|| (status.hirq_enabled && hcounter(10) != (status.hirq_pos + 1) * 4)
|
|
|
|
|| (status.virq_pos && vcounter(6) == 0) //IRQs cannot trigger on last dot of field
|
|
|
|
) irq_valid = false;
|
|
|
|
}
|
|
|
|
if(!status.irq_valid && irq_valid) {
|
|
|
|
//0->1 edge sensitive transition
|
|
|
|
status.irq_line = true;
|
|
|
|
status.irq_hold = true; //hold /IRQ for four cycles
|
|
|
|
}
|
|
|
|
status.irq_valid = irq_valid;
|
|
|
|
}
|
|
|
|
|
2016-03-26 01:56:15 +00:00
|
|
|
auto CPU::nmitimenUpdate(uint8 data) -> void {
|
2010-08-09 13:28:56 +00:00
|
|
|
bool nmi_enabled = status.nmi_enabled;
|
|
|
|
bool virq_enabled = status.virq_enabled;
|
|
|
|
bool hirq_enabled = status.hirq_enabled;
|
|
|
|
status.nmi_enabled = data & 0x80;
|
|
|
|
status.virq_enabled = data & 0x20;
|
|
|
|
status.hirq_enabled = data & 0x10;
|
|
|
|
|
|
|
|
//0->1 edge sensitive transition
|
|
|
|
if(!nmi_enabled && status.nmi_enabled && status.nmi_line) {
|
|
|
|
status.nmi_transition = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//?->1 level sensitive transition
|
|
|
|
if(status.virq_enabled && !status.hirq_enabled && status.irq_line) {
|
|
|
|
status.irq_transition = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!status.virq_enabled && !status.hirq_enabled) {
|
|
|
|
status.irq_line = false;
|
|
|
|
status.irq_transition = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
status.irq_lock = true;
|
|
|
|
}
|
|
|
|
|
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 CPU::rdnmi() -> bool {
|
2010-08-09 13:28:56 +00:00
|
|
|
bool result = status.nmi_line;
|
|
|
|
if(!status.nmi_hold) {
|
|
|
|
status.nmi_line = false;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
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 CPU::timeup() -> bool {
|
2010-08-09 13:28:56 +00:00
|
|
|
bool result = status.irq_line;
|
|
|
|
if(!status.irq_hold) {
|
|
|
|
status.irq_line = false;
|
|
|
|
status.irq_transition = false;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-26 01:56:15 +00:00
|
|
|
auto CPU::nmiTest() -> bool {
|
2010-08-09 13:28:56 +00:00
|
|
|
if(!status.nmi_transition) return false;
|
|
|
|
status.nmi_transition = false;
|
|
|
|
regs.wai = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-26 01:56:15 +00:00
|
|
|
auto CPU::irqTest() -> bool {
|
2010-08-09 13:28:56 +00:00
|
|
|
if(!status.irq_transition && !regs.irq) return false;
|
|
|
|
status.irq_transition = false;
|
|
|
|
regs.wai = false;
|
|
|
|
return !regs.p.i;
|
|
|
|
}
|