peteym5, on Mon Mar 19, 2012 12:10 PM, said:
It works for the most part, but the game also plays some 4bit sound samples and it is crashing from time to time. The RTI sometimes sends the program somewhere not part of the main program area after the sound plays, even if I never hit pause. I disable the keyboard IRQ while playing a sound, but didn't help much. Wouder if there is a POKEY register I have to do to clear the last key pressed or something.
Not in this sense. To indicate that you handled the IRQ, you need to clear the keyboard IRQ. For that, write first #$bf to IRQStat ($d20e) which resets the IRQ. Then write again a mask into IRQStat to indicate which IRQs you would like to receive.
The reason why your program crashes "sometimes" might be because you're running out of stack. What may happen is that your interrupt interrupts itself - happens if interrupts happen too often - and at a certain point overwrites its return address. Consider for example the case where your IRQ is interrupted by the VBI, which is then again interrupted by the next IRQ if you're depending on the pokey timer, for example.
One notice: The Os will already save the accu on the stack for you, that is, you should return with a PLA RTI from your code, not with an RTI alone.
Edited by thorfdbg, Mon Mar 19, 2012 3:32 PM.