SmartRAM
2.5
Super RAMdisk for all XL/XE memory upgrades.
by Tim Patrick
Take advantage of your XL/XE's upgraded memory with SmartRAM II. This BASIC super RAMdisk works on Atari XL and XE computers with a minimum 128K memory and requires DOS 2.5.
The various XL/XE memory upgrades have many differences, but they also have significant similarities In this article I will discuss how these upgrades are alike and even teach you how to talk to your extra memory so you can experiment with your own software.
SmartRAM 2.5 is a powerful RAMdisk that can cake charge of your extra memory, no matter what upgrade you have installed. You'll find that SmartRAM 2.5 is more convenient and versatile than Atari's official RAMDISK.COM file.
For a good general description of the various Atari RAM upgrades you may wish to review Dr. Brilliant's Incredible Atari Brain Transplants, which appeared in the November 1988 issue of Antic. However, SmartRAM 2.5 does not support the Atari 800 upgrades.
All of the XL/XE upgrades are really very similar. It is not difficult to distinguish between them and it's a snap to talk to them. You can control any common XL or XE RAM upgrade with just a few bytes of code.
I will try to explain the function of SmartRAM 2.5 as clearly as possible, but it is complex, requiring some understanding of binary numbers and 6502 assembly language However, you don't need to understand SmartRAM 2.5 in order to use it effectively.
TYPING IT IN
SmartRAM 2.5 requires Atari DOS 2.5. Boot with a copy of DOS 2.5 and type in Listing 1, RAMDISK.BAS, check it with TYPO II and SAVE a copy to disk before you RUN it. This listing is the BASIC translation of an assembly language program. The assembler source code is also on this month's Antic Disk so that experienced programmers can adapt it if they wish.
Make sure to RUN SmartRAM 2.5 in drive 1 on a disk which includes a copy of the genuine DOS 2.5. The program will check its own data and write out a RAMDISK.COM file to Dl:. Your new RAMdisk is now ready to use. So reboot by pressing [RESET] and check it out.
The extra features don't cost more memory:
By the way, for all you 256K 800XL/1200XL users and 320K XE users: I have not tested this with BASIC-XE from OSS/ICD, but it should allow you to use the EXTEND mode with a "1050" RAMdisk! SmartRAM also works with the XE-GM1 and XE-GM2 RAM upgrades for the XEGS from Innovative Concepts.
SWITCHABLE BANKS
Located in the Atari's 6502 microprocessor, the program counter tells the computer where to go in memory for instructions or data. This counter is 16 bits wide. With 16 bits we can have 65,536 different addresses, or 64K of addressable memory.
While you can install the larger 256K RAM chips, the 6,502 cannot "see" any more than 64K. It's like having a 256 story building with no elevators or stairs above the 64th floor. When extra memory is installed in a 64K computer, it must be done in a way that allows small pieces of it, called "banks", to temporarily replace a similar segment of the main memory,. This "bank-switching" is what allows us to have a 130XE with 128K, or an 800XL with 256K.
The Atari 130XE set the standard for bank switching on all XL/XE computers. In the 130XE there is an extra 6rK, which is accessed in four 16K banks. All of the currently available XL/XE upgrades utilize this method, which is the most striking similarity among them.
MEMORY CONTROL
You control this extra memory by setting or clearing bits at address 54017 decimal ($D301 hex), the PORTB register in the PIA chip. The eight bits of PORTB are assigned as follows:
Bit 7: Controls the diagnostics Self-Test, 2K ROM
Bit 6: Currently unused in the 130XE (controls built-in Missile Command on the XEGS).
Bit 5: Controls the ANTIC video processor during banking.
Bit 4: Controls the 6502 microprocessor during banking.
Bit 3: Bank address bit 1.
Bit 2: Bank address bit 0.
Bit 1: Controls the built-in BASIC. 8K ROM
Bit 0: Controls the operating system. 16K ROM
In the 130XE with 128K memory, the four banks are addressed as banks 0 through 3, requiring 2 bits set in one of 4 patterns -- 00, 0l, 10, or 11. To access a new bank, set bits 2 and 3 to the desired bank address, clear bit 4 for the 6502, and/or bit 5 for ANTIC video. Our new bank will then appear in place of the second 16K of main RAM at address 16384 to 32767 decimal ($4000-$7FFF). This area is called the "bank window."
With two bits we can address four 16K banks, or 64K. Another bit would give us addresses for another 64K (8 banks), for a tout of 128K extra. Yet another bit would give us addresses for an additional 128K (16 banks) for a total of 256K memory plus the 64K of main RAM, which equals 320K.
This is the principle behind all of 6502 bit shifting instructions to move them into position. This won't work for SmartRAM 2.5 because you need different instructions depending on which bits you are shifting, and where you are moving them.
My solution was to figure out which bit patterns were necessary for each of the combinations. Then I assembled them into a bank control cable This is a table of bytes, from which SmartRAM pulls the needed bit address.
Bank Control Table Master:
130XE | $E3,$E7,$EB,$EF |
Bit 6 | $A3,$A7,$AB,$AF |
Bit 5 | $C3,$C7,$CB,$CF |
Newell | $83,$87$88,$8F |
Bit 7 | $63,$67,$6B,$6F ;BANKS 4-7 |
Bit 7Z | $23,$27,$2B,$2F ;BANKS 0-3 |
Bit 1 | $E1,$E5,$E9,$ED |
Bit 1Z | $AI,$A5,$A9,$AD |
There arc a total of 32 bytes in the master table, but only four are used for 128K, eight for 192K. 12 for 256K, and 16 for 320K. As the memory test passes each stage, the proper bytes are placed into the control table. When the test is finished, so is the table.
After this, SmartRAM only has to use simple division to determine which bank it will be accessing and pull that byte from the table. For example, there are 128 single density "sectors" in each bank. If SmartRAM needs sector 129, it wants the second bank, so it just grabs the second byte from the table and stuffs it into PORTB. Poof, Bank 2 is in the window.
7050 EMULATOR
Now let's rake a look at the SmartRAM 2.5 new 1050 Emulator This will work in the standard 130XE with 128K, as well as upgrades with 192K or 256K.
The emulator can handle bits 2, 3, 5, 6, and 7 (sorry, no bit 1). In a stock 128K 130XE it will give you the normal Atari 499-sector RAMdisk. In a 192K XE it will give you a "1050" density RAMdisk. And in a 256K XL (or 320K XE) it will give you the 1050 RAMdisk without using any of the 130XE banks! This allows you to use the 130XE banks for other things (like BASIC-XE).
One of the nicest features of SmartRAM 2.5 is that it will only enable the MEM.SAV file if BASIC (or a cartridge) is active I'm sure you have all been annoyed by that "TYPE 'Y' IF OK TO USE PROGRAM AREA" message, when you are just using DOS. This is no problem now. If you are not using BASIC, no MEM.SAV prompt is given. You can still use DOS option N (create MEM.SAV) if you want to preserve lower memory.
Another nice feature is the ability to reboot without reformatting a valid RAMdisk. If you have data previously written to the RAMdisk, a software reboot at $E477 will not wipe it out. SmartRAM can be "reboot proof" using the RAMaid coldstart reset button from Innovative Concepts as well. SmartRAM 2.5 checks for valid data before formatting, thus preserving your important data.
NO MEMORY LOSS
All this doesn't cost you any memory. I managed to stuff SmartRAM 2.5 into the locations used by Atari's old handler. And it doesn't cost you any disk space. SmartRAM 2.5 is only eight sectors long, actually one sector shorter than Atari's RAMDISK.COM.
Are there any limitations? Of course. As with all RAMdisks, save what you need to a real disk before you turn off the computer. When the power goes off, any files on RAMdisk will disappear. Also, when designing this program I decided for the sake of compatibility to retain as much of Atari's original DOS 2.5 RAMdisk handler as possible.
This means the program should work with anything designed for the DOS 2.5 RAMdisk. But it will still be incompatible with software that has problems with the old handler (like DUP.SYS option J).
Note that there is a small bug in DOS 2.5 (not SmartRAM 2.5) which will occasionally give unusual results when reading the RAMdisk directory. The size of the DUP.SYS file will be much larger than the normal 42 sectors. Sometimes a directory Using will report "999+ FREE SECTORS". This is also incorrect, but seems to cause no problems. Although annoying, this bug is apparently harmless, usually occurring after you run a binary file and return to DUP. The problem seems to be caused by the MEM.SAV routines. It usually doesn't happen if MEM.SAV is enabled.
When SmartRAM 2.5 loads into a machine with more than 128K, it patches DOS 2.5 to access the extra memory. While this patched DOS is completely functional and can be written out to a disk, it will no longer be compatible with the standard RAMDISK.COM file and a 128K Atari 130XE. So it is best to reboot without SmartRAM 2.5 before writing DOS. The DUP menu is modified to remind you that DOS has been modified.
Notice that the SmartRAM boot message is printed on the bottom of the screen, so as not to interfere with AUTORUN files that print a RUN "D1:FILENAME" type of message. The boot message will say D8:DISK EMULATOR for the 128K Atari 130XE, and D8:1050 EMULATOR for expanded memory systems. A message on the DUP menu will indicate 192K or 256K, as required. There is no special message for the standard 128K system configuration.
Tim Patrick, 30, lives in Hawaii's Oahu island. He enjoys assembly language programming and has written numerous utilities which can be found on bulletin boards as far away as Germany. This is his first Antic appearance.
Executable: RAMDISK.COM Download / View
Source code: RAMDISK.SRC Download / View