Classic Computer Magazine Archive ANTIC VOL. 2, NO. 4 / JULY 1983

ASSEMBLY LANGUAGE

Hokey Pokey Interrupts

by ED STEWART

Despite the great wealth of information available about the ATARI computers, I have been unable to get adequate information concerning the operation of the POKEY timers. The Hardware manual makes reference to these timers but there is no discussion of their function. De Re Atari has an excellent discussion of the POKEY chip, but nary a mention of how the interrupts operate. I couldn't believe that Atari would develop an interrupt mechanism for the POKEY timers without a reason, yet very little was ever said about it. I've investigated this area on my own and here are the results. POKEY generates sound in an interesting manner. A short pulse of electricity is sent to the TV speaker. This pulse causes the speaker cone to rapidly change its position with a resulting "pop" sound. This process is repeated many times per second. The sound produced can range from a musical tone to a synthesized human voice. The distance the cone travels corresponds to the volume of the sound since it requires more force to move the cone a longer distance. The frequency of the pulses sent to the speaker controls the pitch of the tone. Four semi-independent pulse generators, or voices, exist in the POKEY chip. These voices can generate pulses to the speaker simultaneously. The resulting frequency is the sum of the individual frequencies of the four voices and can range from about one pulse every four seconds to thousands of pulses per second. At very low frequencies individual "pops" are audible as you can hear using the program I have provided, while the higher frequencies are well beyond our range of hearing. It is possible to generate an interrupt each time a pulse is sent from voice numbers one, two, or four. The number of interrupts generated can therefore range from one every four seconds to thousands per second.

An interrupt is a pre-emption of the program which is currently executing in the computer. This interruption is completely transparent to the interrupted program. Interrupts happen frequently in most computer systems and are used to notify the CPU of the occurrence of some external event such as the completion of an I/O operation. In the ATARI computer, interrupts occur a minimum of 60 times per second during the vertical blank process, also known as VBI. POKEY timer interrupts can be used to keep track of events that occur more frequently than 60 times per second or as seldom as once every four seconds. If interrupts occur too often, there will be little time available for anything else but servicing of the interrupts.

Atari has not employed this POKEY interrupt scheme in any programs even though the Operating System supports It (except for POKEY timer number four, due to a bug in Operating System Revision A). The reasons for this lack of popularity are as follows:

1. Vertical Blank Interrupts (VBI's) are more regular, occuring 63.9210 times per second. They are therefore more appropriately used for clock and timer functions found in the computer.

2. POKEY interrupts are of the IRQ variety. This means its interrupts can be temporarily delayed if the computer has disabled IRQ interrupts as it does during VBI processing. This delay, along with the asynchronous fetching of video-screen data from RAM, causes the frequency of this timer interrupt to be somewhat irregular, especially at frequencies above 200 interrupts per second. Changing of graphics modes will also affect the frequency interference of POKEY interrupts.

3. If a timer (1, 2, or 4) is being used for this purpose, its use as a sound generating mechanism has been compromised. This is also true of I/O processing because POKEY uses the voices to clock data coming into and going out of the computer on the serial bus.

Nevertheless I feel that this POKEY timer has some potentially useful applications. For high-throughput applications such as real-time data monitoring, VBI's can be disabled along with the screen DMA process. You can then use this automatic interrupt mechanism to infrequently gain control of the computer rather than approximately 60 times per second. If you need to repeat a process more than 60 times per second you cannot do it using the current BVI mechanism--you must use the POKEY interrupt scheme.

I used the accompanying program to discover the secrets of this interrupt mechanism. You can also use this program to determine what frequency values to use in obtaining a specific interrupt rate per second. In order to increase accuracy I used the l6 bit mode of sound generation rather than the more commonly used 8-bit mode. Voices one and two were used together as the source listing shows. When you execute this program it will display the values of the system variable AUDCTL and AUDF. IFREQ will be displayed on your screen as the interrupt frequency-per-second encountered for a specific AUDCTL and AUDF value. Audio feedback will also be generated as you actually hear the interrupts occur.

A summary of the process of setting the interrupt environment is as follows:

1. set the correct interrupt exit vector starting at address $210,

2. enable the particular timer by Setting the correct IRQ mask in POKMSK and the associated hardware register at $D20E,

3. set AUDCTL and AUDF to the desired values which will determine the interrupt frequency,

4. start the timer by storing any value at location $D209.

In the interrupt routine note that you must restart the timer at $D209 to get additional interrupts to occur. This program counts the number of interrupts that occur in two seconds to determine the value IFREQ. When you run this program you will notice that the normal "divide by two" circuitry that occurs for the determination of the final output voice frequency does not apply to the interrupt frequency. Instead, the interrupt frequency is equal to twice the output voice frequency.

Many people confuse the POKEY timer interrupts with the software timers which occur during the VBI process. I hope that I have helped illuminate one of the lesser known secrets of your ATARI computer. I do know that I have enjoyed discovering how it functions and sharing that information with you.

Listing:POKEYINT.ASM Download / View