Classic Computer Magazine Archive ANTIC VOL. 4, NO. 7 / NOVEMBER 1985

software

130XE MEMORY MANAGEMENT

How to use the XE's extra 64K

IAN CHADWICK


A complete explanation of the extended 64K RAM in the Atari 130XE, by Ian Chadwick, author of Mapping The Atari. Includes a tutorial program showing how to access the extra memory from BASIC. Requires a 130XE computer and intermediate programming knowledge.

If we were stranded on a desert island with nothing but our (solar-powered?) Atari and only one book, we'd have no hesitation in choosing lan Chadwick's Mapping The Atari. During any Programming session at Antic, this comprehensive sourcebook is never more than anarms' length away. Our copy of the familiar white, spiral-bound book is dog-eared and smudged. We were about to order another when lan told us he just finished revising his classic to include the XL and XE memory locations. At our request, he generously provided this thorough description of the 130XE extended RAM--and how to get at it. --ANTIC ED


Atari has released a computer with 128K RAM, but it may not be exactly what you expected. True, it has 128K RAM available. But's it's not entirely available as one large block. Instead, it's switched in and out in 16K blocks by setting and resetting bits in PORTB (54017--$D301).

Machine language programmers will have no difficulty in bank selecting the extended area fast enough to make it seem that a larger selection of RAM is available--Atari's own DOS 2.5 RAMdisk program does this. BASIC programmers will have to be content with shunting about in 16K blocks.


MEMORY MANAGEMENT

Briefly, you can tell either the CPU or the ANTIC chip that a block is available for that chip's use. The CPU can use it for data and variable storage, altered character sets, P/M graphic assemblies, machine language routines and the like. ANTIC uses the banks for graphic screens and display lists. Most BASIC commands--like PRINT and LIST--work in the main bank area and don't write to the extended bank unless you tell the CPU to use an extended bank at the same time ANTIC is using it. (See Figure 1.)

On the other hand, BASIC's clear screen command used in the extended bank will crash the program quite effectively. It disables the screen and keyboard, making it necessary to press [RESET] to recover.

This happens because the command clears screen memory to RAMTOP, but gets confused by the bank switching. It clears the extended bank area and then the main bank which follows, erasing the display list and screen in higher RAM as well.

To avoid this, move RAMTOP (location 106) down (for example; POKE 106,128) while ANTIC accesses the extended bank area, then POKE it back up for the original main bank display. Now if you [BREAK] your program while an extended bank is displayed, [SHIFT] [CLEAR] will only clear the main bank area to 32768. The upper bank area, which was the original screen display, remains intact.

The extended bank has four separate 16K blocks (See Figure 3) which can each be accessed through the main addresses 16384 to 32767 ($4000--$7FFF). No matter what the address of the extended bank, you still read and write (PEEK and POKE) to this range, not to the address of the bank itself.

Imagine the extended bank as a collection of four identical ranges, each one individually accessible. The only way to use all four as one large block is by a machine language routine which rapidly selects the proper block, so it seems to be using one larger section. This is best done in vertical blank interrupts.


FREDDIE

Access to any bank is through PORTB. Previously this was the controller for the two additional joystick ports on the Atari 400/800 computers. Now it is the memory manager on the XL and XE models. Bits 2 and 3 select the bank to be accessed, bits 4 and 5 select the processor (See Figure 2.) Both processors can access the same area at the same time if you set the bits correctly. The memory management chip is called "Freddie"

The key to access is POKEing PORTB with 129, plus the mode times 16, plus the bank times 4. (See Figure 3.) 129 turns off the self-test ROM, and turns on BASIC and ROM. 253 ($FD) is the default value. Machine language programmers obviously don't need BASIC, so add 131 ($83) to the formula instead of 129. The sixth bit isn't used in the 130XE, but it may be used in future Ataris. So you can also use 193 or 135 instead of 129, with the same results.


Figure 3
PORTB MEMORY ASSIGNMENT PORTB BANK ASSIGNMENT
BIT:6502
uses
ANTIC
uses
MODE
No.
45
0
0
1
1
0
1
0
1
Extd
Main
Extd
Main
Extd
Extd
Main
Main
0
1
2
3
BIT:ADDRESS: BANK
No.
23
0
0
1
1
0
1
0
1
$0000-$3FFF
$4000-$7FFF
$8000-$BFFF
$C000-$FFFF
0
1
2
3
POKE 54017,129+(MODE*16)+(BANK*4)


PROGRAM EXAMPLE

Listing 1 demonstrates the extra memory by filling a portion of each extended bank with a value corresponding to the bank number--0 to 3. Main bank 1 (16384 to 32767) is represented by number 4. Type in Listing 1, check it with TYPO II and SAVE a copy before you RUN it.

When you press a console key, the program jumps to a subroutine which POKES the new address of the screen into the display list (DL + 4, DL + 5) and the screen pointers into RAM (88, 89). Then it POKEs the corresponding bank and mode number into PORTB, telling ANTIC to get the screen display from that bank.

The fill routine is slow, but it's not meant to demonstrate speed. Once you've filled the banks, you can usually type GOTO 140 to display the memory again after any modifications. [RESET] doesn't clear the extended banks.

Key:
[START]
[SELECT]
[OPTION]
[START] [SELECT]
[START] [OPTION]
[START] [SELECT] [OPTION]
Banks:
Extended 0
Extended 1
Extended 2
Extended 3
Main 1
Main 2 (Original screen)

The last key selection returns you to the original screen and display list seen when you boot BASIC.

If you press [BREAK] while any of the extended banks are displayed, the system appears to hang. It's not really locked up. Carefully type POKE 54017,253 and you'll get control back.

The problem comes when BASIC passes' control back to the screen editor, which is processing in the main bank while you're displaying a block of extended memory. You have to tell both CPU and ANTIC to use that bank in order to use [BREAK] properly. Of course, [BREAK] works properly when any of the main banks are displayed.

Try changing line 1020 to POKE 54017,193--this selects both processors to access the bank. Now add 1025 LIST 100,200 and type GOTO 160. The zero in an extended bank can use BASIC screen and graphic commands. If you press [BREAK] when this screen is displayed, it displays properly.


CAUTION!

There are several precautions to take!

First, fill all of the banks before you fill the main section or use it for programming or data. If you are using the CPU (POKEs) to fill the banks while the display routine routes ANTIC to the extended area for the display, you could end up over-writing your own program space.

Try to avoid large strings as well. It's best to load the extended banks with a simple routine first, then fill the main bank with your strings and program.

For example, delete line 1025 and restore line 1020 to its original state. Now, add these lines to your program:

132 GOSUB 8500
8500 DIM A$(10000)
8600 A$(1)="A":A$(9999)=A$(2)=A$
8700 RETURN

Now, when you press [START] [OPTION], instead of seeing main bank 1 filled with 4's, you see Atari Fuji symbols. You're looking into the heart of A$!

If the DIM statement appears before the banks are filled, the program generates illogical error messages. (Try adding this code between lines 10 and 20 instead). This is an example of the CPU using one bank of main memory while ANTIC uses a bank of extended memory, both at the same address. This limits your program somewhat. It might mean you have to write a two-part program, the first part being a loader for the extended bank.

Notice the program fills the banks with internal codes rather than ATASCII (see Mapping The Atari, page 180). This is because the bank area becomes the screen display, bypassing the ATASCII to internal translation routine. In onder to display "A" instead of the graphics symbol, change A$(1)="A" to A$(l)="!".

You can use other graphics modes besides GRAPHICS 0 in your displays. Try adding to the original program:

4525 GRAPHICS 20:COLOR 1:DRAWTO 20,20
4526 DRAWTO 40,40:DRAWTO 20,20
5000 GOTO 5000

However, to display the other screens properly, add a GRAPHICS 0 into the first line of each subroutine, since doing this sets up a GRAPHICS 4 + 16 display list that won't display anything in the other banks. Another method is to move the entire display list with an associated screen up into the extended area and simply point to the display list instead of the screen memory.


BANK ON THE FUTURE

There are many avenues of exploration open to programmers using the new memory bank. You could write an adventure game with all the rooms entirely in memory, or a scrolling graphics game. You could use the space to store BBS bulletins and sign-on messages.

Since you don't have to use the banks linearly, you could make the main display area the "center" of a game, while "north" would move into one bank--say 3-west into 2, east into 1 and south into 0--all controlled by joystick input. You could use the space to store classic openings in a chess game, or use it as a disk I/O buffer or print spooler.

As a RAMdisk, it means fast overlay programs that used to be unbearably slow on the old drives. A RAMdisk can also be used to hold graphic screens for games. The possibilities are limitless...


RAMDISK

Atari DOS 2.5 creates RAMdisk #8 on the 130XE. Since the RAMdisk occupies all of the extended bank, you'll have to choose between it and your own programming. You can't have both without problems. With the RAMdisk, DOS 2.5 sets the extended bank as D8: and copies MEM.SAV and DUP.SYS to it. You can use it as a very fast 64K drive with 499 sectors. When you type DOS from BASIC, it jumps to DUY.SYS in the RAM area rather than loading from D1:. You can delete MEM.SAV if you don't need it.

Do you want to use DOS 2.5 and extended memory programming? From BASIC, POKE 5439, ASC("1"). This tells DOS to search for DUP.SYS on drive 1. POKE 1802 with the number of drives in your system. Each bit represents a drive from 1 to 8, so POKE with the total of their binary equivalents. If you have two drives, POKE 1802,3--the value of bits 1 and 2 added together.

Now, type DOS and, from the menu, delete the file RAMDISK.SYS. Then write DOS files back to the disk. This disk will now boot with extended RAM but without a RAMdisk.


ADDENDUM

Devices or programs which load the 400/800 Operating System into the 130XE RAM (such as FIX XL or XL BOSS) can also access the additional 64K and use the RAMdisk! Listing 1 works equally well on my 130XE unadorned or using my XL BOSS to switch in the older 400/800 OS. Of course, once you run it, you wipe out DUP.SYS in the extended memory and eliminate the RAMdisk. So you can't take advantage of both at the same time.


MAPPING THE ATARI (Revised Edition)
COMPUTEI Publications, Inc.
314 W. Wendover Avenue, Suite 200
Greensboro, NC 27408
(919) 275-9809
$16.95

XL BOSS
Allen Macroware
P.O. Box 2205
Redondo Beach, CA 90878
(213) 376-4105
$79.95

FIX XL
Antic Arcade Catalog
PD026
$10