7

Positioning Player/Missile and
Regular Graphics in Memory

titlebar.gif

Fred Pinho


Strange things indeed can appear on your display if memory is not protected properly for player/missile graphics. These charts should help you avoid memory conflicts in your Atari.

Have you ever used player/missile graphics only to notice funny looking colored lines or dots on the screen with your carefully crafted images? When you moved your player or missile, these lines and dots seemed to acquire a life of their own. While it was fascinating to watch this "extra" display, it also quickly became frustrating to your programming attempts. The problem is that all the instructional articles I've seen tell you that you must step back in RAM a minimum of 1K (four pages) for double-line resolution and 2K (eight pages) for single-line resolution. They either ignore, or barely mention in passing, the important fact that you must also allow for the screen display memory in this calculation.

The Atari uses two blocks of memory to control the TV screen display. Residing at the very top of RAM is the display data. This block of memory contains a bitmap for the TV screen in graphics modes 3-8 and a character map for text modes 0-2. Residing just below the display data is the display list. This block of memory is essentially a short program that tells the Atari how to set up the TV screen for the desired mode. The total memory required for the display list and display data varies with the graphics mode used. This is illustrated in Table 1. As you can see, the highest resolution mode, GRAPHICS 8, requires the most RAM.

Thus, the explanation for the "extra bonus" lines or dots in your P/M display is that the program did not step back far enough into RAM and consequently located the P/M data in the display data memory area. The Atari then obediently displayed this data both from the normal display and through the P/M system. Since the display data is displayed as a number of bytes per line (Table 2), you will see a line of varying colored dots. By contrast, the P/M display is organized to display the bytes in a "stack" arrangement and so you see the desired figure (possibly as you designed it).


Table 1. Memory Required for Display List and Display Data

GRAPHICS
MODE*

TOTAL MEMORY BYTES ALLOCATED TO
Total
Bytes
Memory Step-
Back To Be
Added To
P/M Step-
Back, Pages t
DISPLAY DATA
DISPLAY LIST
Bottom
Text
Window
Unused Bytes
Text or
Graphics
Screen
Unused
Bytes
Used
Bytes
Always
Conditional
0
1
2
3
4
5
6
7
8
none
160
160
160
160
160
160
160
160
none
none
none
none
none
none
none
none
16
none
80
40
40
80
160
320
640
1280
960
400
200
200
400
800
1600
3200
6400
none
none
none
none
none
none
none
96
80
32
34
24
34
54
54
94
94
176
992
674
424
434
694
1174
2174
4190
8112
4
3
2
2
3
5
9
17
32

*If 16 is added to the GRAPHICS mode number, then the conditional unused bytes are added to the screen memory block. The bytes formerly used for the text window then become unused. Also the display list expands slightly

t To be added to player/missile step-back pages.


To aid you in using P/M graphics, Table 1 gives the number of pages that must be stepped back in memory (from the top of available RAM) to avoid interference between the two systems. For those not familiar with the concept of paging, the memory addressing system of the 6502 microprocessor within the Atari is based on the concept of a memory page.Each page is equivalent to 256 bytes of memory. Thus there are four pages of memory in each K (1024 bytes) of memory.

Note that, in calculating the step-back value for Table 1, a restriction must be observed: positioning for the P/M RAM must be on a 1K boundary for double-line resolution and on a 2K boundary for single-line resolution. If you position the P/M memory incorrectly, the P/M data will not be displayed. Since the Atari will be equipped with a varying amount of memory, it must be able to keep track of the amount available so that it knows where to locate the display data and display list. This is done at memory location 106 (RAMTOP). If you PEEK this location, you'll find the number of pages, not the number of bytes,in your machine. You can get the number of bytes by multiplying by 256.

POKEing into this location can be very useful for the programmer. One example is the location of large machine language programs that must be placed in a secure location that is not touched by BASIC. One way to accomplish this is to POKE a lower number of pages into RAMTOP, fooling the computer into believing that it has less memory than is the case. Then you can load your machine code in this safe hiding place, yet still access it when needed.

Another use is as a safe location for a redefined Atari character set. Again, there is one restriction. The relocated display data cannot cross a 4K boundary (graphics modes up to 7). If you don't observe this restriction, you'll find that you will be unable to plot and draw on part of the screen. RAMTOP for GRAPHICS 8 must be lowered in multiple 4K blocks. If you try it otherwise, you'll see weird and unwanted displays on your screen.

Thus, two methods for storing P/M data are:

1. Beneath the display list

2. Above a lowered RAMTOP

An example calculation for method one is shown below. However, it is tedious to have to calculate each time you program, so I've provided Table 3 for your use. This table gives the correct number of pages to offset the P/M system for either method of storage.

I hope these tables aid you in using the P/M and graphics systems. The systems are powerful, and their use will result in increasingly sophisticated displays.


Table 2. Example of P/M Positioning in Memory

Assume you wish to run P/M graphics mode 7. You want to use all four players, so all of the player/missile memory must be free and clear of the Screen Display memory.

  Required Step-Back
In Memory, Pages
GRAPHICS 7, Screen Display (Table 1)
P/M graphics, single-line resolution (requires 2K)
17
8
Total = 25 pages

However, 25 pages is not on a 2K boundary:

6K = 24 pages
8K = 32 pages

Therefore, you must step back 32 pages for proper positioning of the P/M system.


Table 3. Player/Missile Positioning

  Above RAMTOP* Beneath Display List t
Graphics
Mode

0
1
2
3
4
5
6
7
8-11
Double
Resolution

4
4
4
4
4
4
4
12
16
Single
Resolution

8
8
8
8
8
8
16
16
16
Double
Resolution

8
8
8
8
8
12
16
24
36
Single
Resolution

16
16
16
16
16
16
24
32
40

*Number of pages to lower RAMTOP. Locate PMBASE at new RAMTOP
t Locate PMBASE at indicated offset (in pages) below RAMTOP.

Notes

1. RAMTOP (location 106) defines the top of available memory. The display data lies just beneath RAMTOP. The display list resides just beneath the display data.

2. When lowering RAMTOP, the display data memory area must not cross a 4K boundary. RAMTOP for GR.8 must always be lowered in 4K increments.

3. Player/missile offsets are calculated by observing the following restrictions for the location of PMBASE:

  Double
Resolution
Single
Resolution
Offset from any other data
Boundary location for PMBASE
1K
1K
2K
2K

Return to Table of Contents | Previous Section | Next Section