xzerix Posted August 20, 2014 Share Posted August 20, 2014 Hi all, I'm starting out with VBIs. What I - eventually - want to do is have a table driven DLI with the counter telling it which line of the screen it's on being reset to zero during the VBI. I figured this gives me the greatest flexibility over using VCOUNT especially if I only want interrupts on some lines and not all of them (and it means I can figure out how to do other stuff - play music? - during the VBI) So I've tried: 0600: 68 PLA0601: AD 24 02 LDA VVBLKD0604: 8D 4D 06 STA $064D0607: AD 25 02 LDA VVBLKD+1060A: 8D 4E 06 STA $064E060D: A2 06 LDX #$06060F: A0 24 LDY #$240611: A9 07 LDA #$070613: 20 5C E4 JSR SETVBV Which as I see it backs up the old interrupt vector to $064D/E and sets the interrupt vector to $0624, which is where the following routine resides... 0624: A9 00 LDA #$000626: 8D FF 06 STA $06FF0629: 4C 62 E4 JMP XITVBV Then I use X=USR(1536) which causes an immediate crash - so what am I doing wrong, please? Quote Link to comment Share on other sites More sharing options...
Rybags Posted August 20, 2014 Share Posted August 20, 2014 Calling it from Basic? You need RTS after the JSR SETVBV. Potential problem you might see is that the DLI might execute first up before the VBlank (and not necessarily the first of multiple DLIs). You can avoid that with something like a wait: lda $14 waitvb cmp $14 beq waitvb lda #$c0 sta $d40e ; enable DLI when VBlank finishes 1 Quote Link to comment Share on other sites More sharing options...
xzerix Posted August 20, 2014 Author Share Posted August 20, 2014 D'oh! That's it - of course! Thanks very much Rybags. I'd previously tried your way (wait vbl, then enable interrupts) but I stumbled across the VBI way and then lost the link, so I had a go at doing it for myself. If its not a daft question why DON'T I need to push the X, Y, and A to the stack and then pull them off after the routine - like a DLI - is it that the interrupt handler does it for itself? Cheers! Quote Link to comment Share on other sites More sharing options...
+Stephen Posted August 20, 2014 Share Posted August 20, 2014 D'oh! That's it - of course! Thanks very much Rybags. I'd previously tried your way (wait vbl, then enable interrupts) but I stumbled across the VBI way and then lost the link, so I had a go at doing it for myself. If its not a daft question why DON'T I need to push the X, Y, and A to the stack and then pull them off after the routine - like a DLI - is it that the interrupt handler does it for itself? Cheers! If I understand correctly, the OS handles pushing and popping the registers for VBIs, but for DLIs the user must do this. Keep in mind, that DLIs are very limited in time, so try to keep the pushing and popping to a minimum, Quote Link to comment Share on other sites More sharing options...
phaeron Posted August 20, 2014 Share Posted August 20, 2014 Since this is for DLI control, the immediate VBI is recommended over the deferred VBI. The deferred VBI can be skipped if a random IRQ happens to be going on when the VBI fires, and you don't want the DLI setup to be skipped. To do this, use VVBLKI instead of VVBLKD, and chain from the end of your code to the old handler instead of to XITVBV. 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.