Lowering the priority of the IKBD interrupt

From AtariForumWiki
Jump to: navigation, search

Wikified by Simon Sunnyboy / Paradize

Extended explanation by MiKRO / Mystic Bytes

Sometimes you have raster effects on Timer B and you do not want to stabilize them by killing all other interrupts which would force you to implement your own IKBD reading routine.

Atari officially used a very similar code to the following to stabilize Timer Bs in their STE Developer Addendum from 1989.

The reason why this works is that every MFP interrupt (which IKBD is) enters its service routine with IPL set to 6. That is to prevent other MFP interrupts to interfere while the service routine is being executed (as MFP interrupts are level 6). What do we do here is to lower it to IPL 5, i.e. re-enabling other MFP interrupts (which Timer B is, too). And since Timer B has (within the MFP) higher priority than IKBD, it gets serviced first and rasters are stable because Timer B service routine doesn't have to wait for IKBD to finish. And: all BIOS routines for reading the keyboard stay intact. This means, GFA_BASIC coders like me can still use INKEY$ an INP(2) to poll the keyboard and have stable rasters.

Official code snippet by Atari Corp.:

ikbdvec	equ $118
; IKBD interrupt to lower its priority below the priority of the HBL
newikbd:
	move d0,-(sp)
	move sr,d0
	and #$f8ff,d0
	or #$500,d0
	move d0,sr
	move (sp)+,d0
	dc.w $4ef9
oldikbd:
	dc.l 0
	illegal

Install the new IKBD interrupt service routine to its vector at $118 and make sure to save the old vector into oldikbd.