I have been trying to get my NMI/BRK timing just right and am a bit stumped (it always seems just a hair off, not matter what I do), so I have a few questions, the first I think is the easiest:
1. Since IRQ/NMI/RESET are basically special cases of BRK. Does they still check if an interrupt should happen during the last cycle? I would assume yes. I doubt it matters much since Interrupts will be disabled by that time, but perhaps NMI could do something weird there? I dunno.
2. The normal operation of execution always has the first cycle do a read from PC and then increment PC. During an IRQ/NMI/RESET, the CPU will force the IR to be $00 in order to trigger the interrupt dispatch logic. That's fine. My question is **Does the CPU still do the read from PC like normal, skip incrementing PC and THEN force the IR to $00. Or is forcing the IR to $00 pretty much the only thing it does during that cycle if an interrupt is pending?
4. At the moment I assume that the forcing of the IR to $00 is just about the only real thing that happens during that cycle (it obviously does some other stuff to make the BRK act like an IRQ/NMI, but I'm keeping it simple). Based on that assumption, here's my core execution logic for executing 1 cycle of the CPU. Is there any obvious flaw? NOTE: instructions $100, $101, $102 are special indexes for RST/NMI/IRQ:
Thanks guys.
1. Since IRQ/NMI/RESET are basically special cases of BRK. Does they still check if an interrupt should happen during the last cycle? I would assume yes. I doubt it matters much since Interrupts will be disabled by that time, but perhaps NMI could do something weird there? I dunno.
2. The normal operation of execution always has the first cycle do a read from PC and then increment PC. During an IRQ/NMI/RESET, the CPU will force the IR to be $00 in order to trigger the interrupt dispatch logic. That's fine. My question is **Does the CPU still do the read from PC like normal, skip incrementing PC and THEN force the IR to $00. Or is forcing the IR to $00 pretty much the only thing it does during that cycle if an interrupt is pending?
4. At the moment I assume that the forcing of the IR to $00 is just about the only real thing that happens during that cycle (it obviously does some other stuff to make the BRK act like an IRQ/NMI, but I'm keeping it simple). Based on that assumption, here's my core execution logic for executing 1 cycle of the CPU. Is there any obvious flaw? NOTE: instructions $100, $101, $102 are special indexes for RST/NMI/IRQ:
Code:
void clock() {
if(current_cycle == 0) {
if(rst_executing) {
instruction = 0x100;
} else if(nmi_executing) {
instruction = 0x101;
} else if(irq_executing) {
instruction = 0x102;
} else {
instruction = read_byte(PC++);
}
} else {
// execute the current part of the instruction
execute_opcode();
}
++current_cycle;
}
if(current_cycle == 0) {
if(rst_executing) {
instruction = 0x100;
} else if(nmi_executing) {
instruction = 0x101;
} else if(irq_executing) {
instruction = 0x102;
} else {
instruction = read_byte(PC++);
}
} else {
// execute the current part of the instruction
execute_opcode();
}
++current_cycle;
}
Thanks guys.