| www.retrosoftware.co.uk http://www.retrosoftware.co.uk/forum/ |
|
| The Joys of Interrupts... http://www.retrosoftware.co.uk/forum/viewtopic.php?f=95&t=879 |
Page 1 of 1 |
| Author: | JoolsH [ Sun Dec 15, 2013 12:32 am ] |
| Post subject: | The Joys of Interrupts... |
I'm finally getting round to doing a bit more work on Cavern Racer. I'm messing around with Interrupts, and I don't really understand what I'm doing I've taken the Interrupt code from the MovingSpritesMode2 example code, to set a flag on VBL (actually, using it's fancy timer code to set the flag just after the screen's finished being drawn - search for "SetUpGameScreen" and "IRQHandler" in that code). It goes a little over my head, but it seems to work when used in my code, which is good Couple of quick questions on it, though, if anyone could help with them: Firstly, er, how do you turn it off when you don't need it any more and want the usual "lda #19, jsr osbyte" to start working again? Secondly, it doesn't seem to work on the Electron... is there a way of doing something similar on the Electron? It doesn't even have to have the fancy timing stuff that the above code has if that can't be done, a simple flag set on VBL would still be helpful. Ironically, the BBC version runs fast enough without this interrupt stuff - it's the Electron version that needs the extra speed boost that this could provide. Thanks... |
|
| Author: | tricky [ Sun Dec 15, 2013 11:13 am ] |
| Post subject: | Re: The Joys of Interrupts... |
I can't help much, as I usually take over the BBC and pretend the OS isn't there. "lda #19, jsr osbyte" does a *FX19, which waits for vsync, an interrupt which happens at the end of what would be the 16th scan line off the bottom of the screen, giving you 40 more scan lines of time before you get back to the start of screen again. I don't know anything about the Electron - sorry. Using an interrupt doesn't gain much over *FX 19, other than you can use it to increment a counter which you can wait on, thus not waiting if you have overrun and as long as you make the time up in the next frame or so, usually avoid flickering too much flicker without dropping whole frames. It is probably way more than you want, but sometimes you need more than one interrupt, so that you can wait for the scan line to pass some bit of the screen you want to update and then again to draw another. In "Vertical Rupture Pixel Scrolling Mode 5" I use multiple interrupts as I need to reprogram the video chip to get multiple "screens" into one (this might interest you as it does vertical scrolling with landscapes - but in a very different way to you). I currently only use a very simple "vsync" only interrupt for "I'm thinking of writing a version of carnival for the BBC", but again, it ignores the OS and takes over all interrupts. DaveF is the interrupt master (AFAIK), but having re-read your post, I seem to have gone way off topic. |
|
| Author: | JoolsH [ Sun Dec 15, 2013 3:35 pm ] |
| Post subject: | Re: The Joys of Interrupts... |
tricky wrote: Using an interrupt doesn't gain much over *FX 19, other than you can use it to increment a counter which you can wait on, thus not waiting if you have overrun and as long as you make the time up in the next frame or so, usually avoid flickering too much flicker without dropping whole frames. Thanks for the reply. That's exactly it - most of the time on the BBC the rendering fits into one frame fine, so *FX19 works just as well; but occasionally it goes slightly over, and ends up twiddling its thumbs for most of the next frame waiting for the VBL when it could be rendering the next frame. This happens occasionally on the BBC, but a lot more often on the Electron version for obvious reasons |
|
| Author: | tricky [ Sun Dec 15, 2013 6:20 pm ] |
| Post subject: | Re: The Joys of Interrupts... |
I use this in the interrupt handler (IRQHandler) lda &FE4D \\ SysViaIFR and #&02 \\ irq_CA1_6845_vsync beq not_vsync inc vsync_next \\ flag game to continue and then this to wait for the next vsync lda vsync_done .wait cmp vsync_next beq wait \\ will fail if vsync_next has already been executed inc vsync_done you may need to check a little more in the interrupt handler eg is the msb of SysViaIFR set (otherwise it didn't generate the interrupt). |
|
| Author: | oss003 [ Sun Dec 15, 2013 6:40 pm ] | ||
| Post subject: | Re: The Joys of Interrupts... | ||
Hi guys, I found this article about speeding up Electron code from Michael Jacobsen a while ago on the internet. Michael is the writer of Citadel. Maybe you can use it. Greetings Kees
|
|||
| Author: | JoolsH [ Sun Dec 15, 2013 9:48 pm ] |
| Post subject: | Re: The Joys of Interrupts... |
I had a read of the Electron AUG - I found this, which seems to work: First, turn on VBL events using *FX14,4 Then, set the event vector at $220 to point to my new event handling function, which contains simply: Code: EventHandler: cmp #4 bne EventIsNotVBL LDA #0 STA waitForVsync EventIsNotVBL: rts In fact, as VBL events are the only ones I turned on, maybe even that cmp/bne is unnecessary. Pretty simple stuff, and perhaps not the absolute fastest way of doing it, but it works on both the BBC and Electron. The Electron version is pretty playable - it's still a bit choppy compared to the BBC, but not bad at all. It might improve it further if I can decouple the game logic from the rendering, so that the game itself runs at the same speed as the BBC, even if it doesn't render quite so fast. Kees - thanks for that, I've saved a copy for future reference. It looks like the osbyte $79 method of reading the keyboard still works even if keyboard interrupts are turned off, which is helpful. Maybe could be made even faster by using the hardware method of reading the keyboard, but I might come back to that later... |
|
| Author: | JoolsH [ Thu Jan 23, 2014 2:01 am ] |
| Post subject: | Re: The Joys of Interrupts... |
FYI - new dev diary entries (good news for Electron fans http://www.retrosoftware.co.uk/wiki/index.php/Cavern_Racer#21_Jan_2014 |
|
| Author: | DavidB [ Fri Jan 24, 2014 8:14 pm ] |
| Post subject: | Re: The Joys of Interrupts... |
Nice work! I'm looking forward to trying this. |
|
| Page 1 of 1 | All times are UTC [ DST ] |
| Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |
|