Can someone advice me if I am handling interupts correctly here?
I have an Interupt Handler class in my CPU that monitors a flag for NMI and a flag for IRQ once per CPU cycle, if either flag is set, it executes the interupt and then clears the flag:
FlySwat wrote:Can someone advice me if I am handling interupts correctly here?
I have an Interupt Handler class in my CPU that monitors a flag for NMI and a flag for IRQ once per CPU cycle, if either flag is set, it executes the interupt and then clears the flag:
-primary registers-
=register name ; desc=
A ; Accumulator
X ; Variable X
Y ; Variable Y
-flag registers-
=bit ; flag name ; desc=
7 ; N ; negative result
6 ; V ; result overflowed
5 ; - ; (unused)
4 ; B ; BRK instruction used
3 ; D ; decimal mode
2 ; I ; interrupt disabled
1 ; Z ; result zero
0 ; C ; carry occured
you seem to not be emulating the actual 8bit mask of the flags,
otherwise looks okay to me, but then again i am a newb to _nes_ emu.
Looks good to me except you should set the I flag on NMIs as well as IRQs.
Also... if you're doing this between cycles like you claim that might be a problem. IRQs/NMIs can only occur between CPU instructions. If you attempt an interrupt in the middle of an instruction you could end up borking something.
Disch wrote:Looks good to me except you should set the I flag on NMIs as well as IRQs.
Also... if you're doing this between cycles like you claim that might be a problem. IRQs/NMIs can only occur between CPU instructions. If you attempt an interrupt in the middle of an instruction you could end up borking something.
that is why i suggest emulating the actual flags mask.
that way you refer to the mask between instructions, but edit the vars between cycles, and only refer to the mask to place into vars temporarily when emulating between instructions.
You should listen to Disch. What he said is correct. The CPU doesn't check for interrupts until it's done executing the current opcode. You cannot interrupt an opcode.