How to: Line interrupts... (BASIC)

By NYYRIKKI

Enlighted (5270)

NYYRIKKI's picture

16-11-2008, 20:16

Every once in a while there comes someone to ask if I could give just a basic example of how to handle line interrupts.

So... Here you can find BASIC line interrupt handler with documentation:

10 ' This example program shows how to use line interrupts
20 ' Made By : NYYRIKKI 2008
30 '
40 DEFINT A-Z
50 ' This program requires X-BASIC
60 _TURBO ON
70 GOTO 90 ' Little jump to avoid RENUM problem
80 GOTO 410 ' This line will be copied to interrupt hook
90 VDP(9)=10 ' In this example we don't need sprites, so we disable them.
100 ' Let's draw something to screen to see the line interrupt effect
110 SCREEN 8:FORY=0TO255:FORX=0TO255:VPOKEX+Y*256,XXORY:NEXTX,Y
120 '
130 ' Let's disable interrups until we are ready (DI)
140 '#I 243
150 ' We will use general interrupt hook in address &hFD9A (-614)
160 ' This address is called every time when interrupt occurs.
170 ' To use it, we have to copy line 80 to the hook.
180 ' First we need to know in what memory address line 80 is:
190 ' AD = LINE 80 (NOTE: RENUM does not work in this case!!!)
200 '#I 33,@80,34,AD
210 ' ... and then just copy...
220 FOR I=0 TO 4:POKE -614+I,PEEK(AD+I):NEXT I
230 ' We want to have line interrupts, so let's enable them.
240 VDP(0)=VDP(0) OR 16
250 ' Let's set the interrupt to happen on line 100
260 VDP(20)=100
270 ' Now we are ready and we can enable interrupts (EI)
280 '#I 251
290 ' Do what ever you want to do here in main program
300 ' In this example we make some noise...
310 SOUND 8,15
320 SOUND 1,RND(1)*8:SOUND 0,RND(1)*255
330 IF INKEY$="" THEN 320
340 ' Before we can exit the program we have to disable line interrupts
350 VDP(0)=VDP(0) AND 239
360 ' ... and release the interrupt hook (put RETurn to it)
370 POKE -614,201
380 ' Now it is safe to exit
390 BEEP:END
400 '
410 ' This is interrupt routine
420 ' Here we make sure, that the example interrupt handler does not end up
430 ' to infinite loop in case of nested interrupts
440 IF IN=0 THEN IN=1:GOSUB 470:IN=0:T=0 ELSE T=T+1:IF T=100 THEN T=0:IN=0
450 RETURN
460 '
470 ' Example interrupt handler:
480 IF (VDP(-1)AND1)=1 THEN 530 ' Is this line interrupt?
490 ' This was not line interrupt, so it's propably VBLANK
500 ' VBLANK happens when screen has been drawn.
510 VDP(24)=0 ' Upper part of screen shows still picture
520 RETURN
530 ' Here we handle line interrupt
540 ' Lower part of screen jumps
550 VDP(24)=P:P=ABS(SIN(R/20)*100):R=R+1
560 RETURN

Eek!

Login or register to post comments

By Manuel

Ascended (15365)

Manuel's picture

16-11-2008, 22:58

Absolutely amazing! The only bad thing: you implemented a bounce with a sine!!!! How badly modeled! Tongue

By NYYRIKKI

Enlighted (5270)

NYYRIKKI's picture

17-11-2008, 11:04

Yes, I know... Even I didn't think that I could actually put so many remarks to MSX-BASIC program. Tongue

Sure I could have calculated gravity correctly or implemented example graphics much faster by using LINE, but I just wanted to make something simple and small, so that the focus stays on line interrupts. Smile

By ARTRAG

Enlighted (6174)

ARTRAG's picture

17-11-2008, 11:10

Lovely!
It is nice also for asm coders who never used line interrupts (like me)

By NYYRIKKI

Enlighted (5270)

NYYRIKKI's picture

17-11-2008, 23:09

Actually I would not call it "lovely"... I would rather call it... "carefully planned sum of unlucky insidents"...

How ever who cares as it is usable and in the end it works like I think you think it should work although it doesn't exactly work that way. Wink Tongue

... and yes, if you translate it to asm it will work as well... propably even just like you think it works... Smile2