From: AsciiRider Subject: DE RE ATARI CHAPTER 5 - Part 2 Date: Wednesday, November 19, 1997 2:50 PM DISPLAY LIST INTERRUPTS MULTIPLE DLls It is often desirable to have a number of DLls occurring at several vertical positions on the screen. This is an important way to add color to a display. Unfortunately, there is only one DLI vector; if multiple DLls are to be implemented then the vectoring to the appropriate DLI must be implemented, in the DLI routine itself. There are several ways to do this. If the DLI routine does the same process with different values then it can be table-driven. On each pass through the DLI routine, a counter is incremented and used as an index to a table of values. A sample DLI routine for doing this is as follows: PHA TXA PHA INC COUNTR LDX COUNTR LDA COLTAB,X Use page two for color table STA WSYNC Wait STA COLBAK CPX #$4F Last Iine? BNE ENDDLI No, exit LDA #$00 Yes, reset counter STA COUNTR ENDDLI PLA TAX PLA Restore accumulator RTI The BASIC program to call this routine is: 10 GRAPHICS 7 20 DLIST=PEEK(560)+256*PEEK(561):REM Find display list 30 FOR J=6 TO 84:REM Give every mode line a DLI 40 POKE DLIST+J,141:REM BASIC mode 7 with DLI bit set 50 NEXT J 60 FOR J=0 TO 30 70 READ A:POKE 1536+J,A:NEXTJ:REM Poke in DLI service routine 80 DATA 72,138,72,238,32,6,175,32,6 90 DATA 189,0,240,141,10,212,141,26,208 100 DATA 224,79,208,5,169,0 110 DATA 141,32,6,104,170,104,64 120 POKE 512,0:POKE 513,6:REM Vector to DLI service routine 130 POKE 54286,192:REM Enable DLI This program will put 80 different colors onto the screen. There are other ways to implement multiple DLls. One way is to use a DLI counter as a test for branching through the DLI service routines to the 5-6 DISPLAY LIST INTERRUPTS proper DLI service routine. This slows down the response of all the DLls, particularly the ones at the end of the test sequence. A better way is to have each DLI service routine write the address of the next routine into the DLI vector at $200, $201. This should be done during Phase Three. This is the most general solution to the problem of multiple DLls. It has the additional advantage that vectoring Iogic is performed after the time critical portion of the DLI, not before. The OS keyboard click routine interferes with the function of the DLI. Whenever a key is pressed and acknowledged, the onboard speaker is clicked. The timing for this click is provided by several STA WSYNC instructions. This can throw off the timing of a DLI routine and cause the screen colors to jump downward by one scan line for a fraction of a second. There is no easy solution to this problem. One possible solution involves the VCOUNT register, a read-only register in ANTIC which tells what scan line ANTIC is displaying. A DLI routine could examine this register to decide when to change a color. Another solution is to disable the OS keyboard service routine and provide your own keyboard routine. This would be a tedious job. The final solution is to accept no inputs from the keyboard. If key presses are-not acknowledged, the screen jiggle does not occur. KERNELS The DLI was designed to replace a more primitive software/hardware technique called a kernel. A kernel is a 6502 program loop which is precisely timed to the display cycle of the television set. By monitoring the VCOUNT register and consulting a table of screen changes cataloged as a function of VCOUNT values, the 6502 can arbitrarily control all graphics values for the entire screen. A high price is paid for this power: the 6502 is not available for computations during the screen display time, which is about 75 percent of the time. Furthermore, no computation may consume more than the 4000 or so machine cycles available during vertical blank and overscan periods. This restriction means that kernels can only be used with programs requiring Iittle computation, such as certain skill and action games. For example, the BASKETBALL program for the ATARI 400/800 Computers uses a kernel; the program requires little computation but much color. The multicolored players in this game could not be done with display list interrupts, because DLls are keyed to playfield vertical positions, not player positions. It is possible to extend the kernel idea right into a single scan line and change graphics registers on the fly. In this way a single color register can present several colors on a single scan line. The horizontal position of the color change is determined by the amount of time that elapses before the change goes in. Thus, by carefully counting machine cycles, the programmer can get more graphics onto the screen. Unfortunately, this is extremely difficult to achieve in practice. With ANTIC DMAing the 6502, it is very difficult to know exactly how many cycles have really elapsed; a simple count of 6502 cycles is not adequate. If ANTIC's DMA Is turned off, the 6502 can assume full control of the display but must then perform all the work that ANTIC normally does. For these 5-7 DISPLAY LIST INTERRUPTS reasons horizontal kernels are seldom worth the effort. However, if the two images to be displayed in different colors are widely separated, say by 20 color clocks or more, the separation should cover up the timing uncertainties and render this technique feasible. APPLICATIONS OF DISPLAY LIST INTERRUPTS The tremendous value of graphics indirection and all those modifiable registers in the hardware now becomes obvious. With display list interrupts, every one of those registers can be changed on the fly. You can put lots of color, graphics, and special effects onto the screen. The most obvious application of DLls is to put more color onto the screen. Each color register can be changed as many times as you have DLls. This applies to both playfield color registers and player color registers. Thus, you have up to nine color registers, each of which can display up to 128 different colors. Is that enough color for you? Of course, a normal program would not lend itself to effectively using all of those colors. Too many DLls start slowing down the whole program. Sometimes the screen layout cannot accommodate lots of DLls. In practice, a dozen colors is easy, two dozen requires careful planning, and more than that requires a contrived situation. Display list interrupts can give more than color; they can also be used to extend the power of player-missile graphics. The horizontal positlon of a player can be changed by a DLI. In this way a player can be repositioned partway down the screen. A single player can have several incarnations on the screen. If you imagine a player as a vertical column with images drawn on it, a DLI becomes a pair of scissors with which you can snip the column and reposition sections of it on the screen. Of course, no two sections of the player can be on the same horizontal line, so two incarnations of the player cannot be on the same horizontal line. If your display needs allow graphics objects that will never be on the same horizontal line, a single player can do the job. Another way to use DLls in conjunction with players is to change their width or priority. This would most often be used along with the priority masking trick described in Section 4. The last application of DLls is the changing of character sets partway down the screen. This allows a program to use character graphics in a large window and regular text in a text window. Multiple character set changes are possible; a program might use one graphics character set at the top of the screen, another graphics character set in the middle of the screen, and a regular text character set at the bottom. A 'Rosetta Stone' program would also be possible, showing different text fonts on the same screen. The vertical reflect bit can be changed with a DLI routine, allowing some text to be rightside up and other text to be upside down. The proper use of the DLI requires careful layout of the screen display. The designer must give close consideration to the vertical architecture of display. The raster scan television system is not 5-8 DISPLAY LIST INTERRUPTS two-dimensionally symmetric; it has far more vertical structure than horizontal structure. This is because the pace for horizontal screen drawing is 262 times faster than the pace for vertical screen drawing. The ATARI Home Computer display system was designed specifically for raster scan television, and it mirrors the anisotropy of the raster scan system. The ATARI Home Computer display is not a flat, blank sheet of paper on which you draw; it is a stack of thin strips, each of which can take different parameters. The programmer who insists on designing an isotropic display wastes many opportunities. You will achieve optimal results when you organize the information you wish to display in a strong vertical structure. This allows the full power of the DLI to be brought to bear. Figure 5-1 shows some screen displays from various programs and gives estimates of the degree of vertical screen architecture used in each. 5-9 Page 5-10 has some lovely black and white screens of the following games: SPACE INVADERS SCRAM MISSLE COMMAND STAR RAIDERS GRAPH IT ASTEROIDS Examples of Vertical Screen Architecture