Jump to content

Photo

IRQ Questions - Keyboard and Pokey Timers


4 replies to this topic

#1 peteym5 OFFLINE  

peteym5

    Dragonstomper

  • 892 posts
  • Location:Buffalo NY USA

Posted Mon Mar 19, 2012 12:10 PM

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.

#2 Rybags OFFLINE  

Rybags

    Quadrunner

  • 12,753 posts
  • Location:Australia

Posted Mon Mar 19, 2012 3:23 PM

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.

#3 thorfdbg OFFLINE  

thorfdbg

    Moonsweeper

  • 469 posts

Posted Mon Mar 19, 2012 3:31 PM

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.


#4 peteym5 OFFLINE  

peteym5

    Dragonstomper

  • Topic Starter
  • 892 posts
  • Location:Buffalo NY USA

Posted Mon Mar 19, 2012 5:07 PM

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.

#5 Heaven/TQA OFFLINE  

Heaven/TQA

    Quadrunner

  • 8,912 posts
  • Location:Baden-Württemberg, Germany

Posted Tue Mar 20, 2012 12:03 AM

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.




0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users