peteym5 Posted March 19, 2012 Share Posted March 19, 2012 I am working on adding a pause to a game I am working on, but trying to do it with IRQ instead of polling inside of the VBI to save CPU time. 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. Quote Link to comment Share on other sites More sharing options...
Rybags Posted March 19, 2012 Share Posted March 19, 2012 You only have to disable/re-enable the key IRQ same as most others. This problem sounds much more like the stack level is wrong, ie you're pushing different # of registers than you're pulling. If you're using vectors ~ $200 area then the OS might have pushed a different number of registers depending on what vector you use. Quote Link to comment Share on other sites More sharing options...
thorfdbg Posted March 19, 2012 Share Posted March 19, 2012 (edited) 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 March 19, 2012 by thorfdbg Quote Link to comment Share on other sites More sharing options...
peteym5 Posted March 19, 2012 Author Share Posted March 19, 2012 I disabled the OS and using a custom routines. I was changing the IRQ vector addr while playing a sound. I originally designed all the IRQs to be starting on the same memory page so I just have to change the IRQ vector low. I discovered the keyboard IRQ was pushed up into the next page and was possibly causing the issue. I copied and pasted the routines around and seems to be working better. I did try some register saves to memory instead of using the stack. Quote Link to comment Share on other sites More sharing options...
Heaven/TQA Posted March 20, 2012 Share Posted March 20, 2012 I had similar issue in Beyond Evil as I am using custom mini-OS plus own keyboard routine. let me look into the code and see if I can find some stuff. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.