Hi, I have my CPU for an NES emulator working and it passes nestest.nes. Now I am getting started with writing the PPU, but I am having a hard time actually knowing when an NMI is triggered for a VBLANK.
I am just trying to get the nametable to be written for Donkey Kong -- for something simple first...
If my understanding is correct, the NMI bit is controlled in BIT_7 in $2000. I am turning on this bit when my scanlines hit 241. I set the NMI bit, then the Vblank bit in 2002.
So my cycle is like this (in pseudo-code):
Do I have the right idea here? If so, I am having problems actually going into NMI. I actually go into the NMI handler in FFFA/FFFB, but then the instructions are
I am just trying to get the nametable to be written for Donkey Kong -- for something simple first...
If my understanding is correct, the NMI bit is controlled in BIT_7 in $2000. I am turning on this bit when my scanlines hit 241. I set the NMI bit, then the Vblank bit in 2002.
So my cycle is like this (in pseudo-code):
Code:
run() {
fetchOpcode();
executeOpcode();
ppuRun();
// check NMI here. and execute NMI.
}
ppuRun() {
incrementPPUCycles();
if(cycles === 341) ppuScanlines++;
if(ppuScanlines >= 241 && ppuScanlines <= 260) {
ppuSetNmi(1);
ppuSetVblank(1);
}
if(ppuScanlines == 261) {
ppuSetNmi(0);
ppuSetVblank(0);
}
if(ppuScanlines == 262) {
outputFrame();
ppuScanlines = 0;
}
}
fetchOpcode();
executeOpcode();
ppuRun();
// check NMI here. and execute NMI.
}
ppuRun() {
incrementPPUCycles();
if(cycles === 341) ppuScanlines++;
if(ppuScanlines >= 241 && ppuScanlines <= 260) {
ppuSetNmi(1);
ppuSetVblank(1);
}
if(ppuScanlines == 261) {
ppuSetNmi(0);
ppuSetVblank(0);
}
if(ppuScanlines == 262) {
outputFrame();
ppuScanlines = 0;
}
}
Do I have the right idea here? If so, I am having problems actually going into NMI. I actually go into the NMI handler in FFFA/FFFB, but then the instructions are
Code:
PHA
over and over again. My guess is that it's going into the NMI routine in every CPU cycle. Just making sure if i have things conceptually right before going further.