MAP PART X
MAP PART X
by Robin Sherer
How to Read the Memory Map
Beginning users: Read the text that is printed in bold type only. These memory locations will be the easiest for you to use and usually don't involve assembly language.
Advanced users: Read everything! Many areas of memory are not of any practical use, but you can learn a lot about how a computer works by reading the boring parts.
The Character Set
The data for the regular Atari character set is stored in Locations 57344 through 58367. There are eight bytes for each character and 128 characters in all (for a grand total of 1024 bytes). But wait a minute. Doesn't the Atari have 256 characters? Yes, but the information for the regular characters is all the Atari needs to know to print inverse characters, so that's why there are only 128 character descriptions.
For lots of information on how the bytes are used to describe a character, and on the order of the characters within the character set, see CHBAS at Location 756.
The following program will use the character descriptions to put text on the screen in graphics mode 8:
100 GRAPHICS 8
110 DIM TEXT$(120)
120 PRINT "Start text in wh
at column (0-39)";
130 INPUT COL
140 PRINT "In what row (0-1
150 INPUT ROW
160 PRINT "Type in the text
you want to print:"
170 INPUT TEXT$
190 FOR CHAR=1 TO LEN(TEXT$
230 FOR BYTE=CHSET+INTRNL*8
240 POKE SCRMEM+ROW*40+COL,
260 NEXT BYTE
290 IF COL=40 THEN COL=0:RO
300 NEXT CHAR
320 GOTO 120
Vectors and Vector TablesWhat are vector tables? You remember that a vector is a pair of memory locations that holds the address of a routine. A vector table is, quite simply, a table of vectors. Thus, Locations 58368 through 58533 hold the addresses of various routines, mostly having to do with I/O or interrupts.
This is the vector table for the screen-editor handler. For a description of its contents, along with the contents of the next four vector tables, see HATABS at Locations 794 through 831 (where we called it a "handler address table").
The vector table for the display handler. See the note at EDITRV.
The vector table for the keyboard handler. See the note at EDITRV.
The vector table for the printer handler. See the note at EDITRV.
The vector table for the cassette handler. See the note at EDITRV.
You will notice that the following 16 vectors are three bytes long rather than two. Why the extra byte? The first byte is a 6502 JMP instruction, while the address is in the second two bytes.
The purpose of these vectors may not be obvious to you (it wasn't to me). Atari knew that it would probably need to make changes to the OS at some point. It also wanted to make sure that old programs would still be able to work with these newer versions of the OS, even though some of the addresses would be different. The solution was to use vectors. That way, even though the addresses in the vectors would change, the addresses of the vectors would remain the same, and programs using these addresses would still work. The reason that some programs don't work with Version B of the OS is that these programs didn't use the vectors.
DISKIV is the initialization vector for the disk handler. It points to Location 60906.
This is the entry vector for the disk handler. It points to Location 60912.
CIOV is the entry vector for CIO (Central Input/Output).
You can see CIO yourself by first setting up an IOCB (see Locations 832 through 959), and then using the following routine:
100 DIM ML$(7)
110 GOSUB 10000
10000 FOR BYTE=1 TO 7
10010 READ INSTR
10030 NEXT BYTE
10050 DATA 104,104,104,170,
The data is for this machine-language routine:
2056E4 JSR $E456
CIO expects the number of the IOCB you want to use, times 16, in the X register. That's why we have IOCB*16 in the preceding program. You should substitute the IOCB number you are using for IOCB. Remember to OPEN the IOCB first.
CIOV points to 58564.
This is the entry vector for SIO (Serial Input/output).
SIOV points to 59737.
SETVBV is the entry vector for a routine that serves two purposes. First of all, as we saw at VVBLKD (548,549), it will set up VVBLKI and VVBLKD for us. Second, as we saw at CDTMAI (550,551), it will also set up the vectors for the system timers. See VVBLKD and CDTMAI for more information.
SETBV points to 59666 in Version A of the OS, and to 59629 in Version B.
This is the entry vector for the Stage 1 VBLANK routine. Unless you have your own routine, VVBLKI (546,547) normally points here. See VVBLKI and VVBLKD (548,549) for more information on VBLANK.
SYSVBV points to 59345 in Version A of the OS, and to 59310 in Version B.
XITVBV is the exit vector for the VBLANK routine. This is what VVBLKD points to unless you've changed it.
Use XITVBV to return to where the computer left off from when the VBLANK interrupt occurred. It points to 59710 in Version A of the OS, and to 59653 in Version B.
The following four vectors are designed for use by the OS only.
This is the initialization vector for SIO.
SENDEV is the vector for the "send-able" routine.
This is the initialization vector for the interrupt-handler routine.
CIOINV is the initialization vector for CIO.
This is the entry vector for the blackboard mode, which is more commonly known as the "Atari memo pad" mode. Type BYE from BASIC, or turn on the computer with no cartridges or disk drives to see what I mean. This mode lets you type things on the screen without anybody caring what you type. In other words, you can press Return and nothing will happen. To get back to BASIC, press System Reset (this won't erase your BASIC program).
BLKBDV points to 61987.
WARMSV is the entry vector for the warmstart routine. The OS jumps through here when System Reset is pressed.
WARMSV points to 61723.
In case these locations don't seem useful to you, try this:
X = USR(58484)
What you have just done is told the computer to go to 58484, which contains a machine-language instruction to go to the address in the next two memory locations. Since this routine is for what's called warmstart, the computer will now act just like you pressed System Reset. You use the other locations in this section just like this. Try it!
This, appropriately, is the entry vector for the coldstart routine. Whereas going through WARMSV only initializes the OS RAM, going through COLDSV initializes all RAM, meaning that any programs in memory will be erased. See COLDST at Location 580 for a way to hook COLDSV up to System Reset rather than WARMSV.
COLDSV points to 61733.
The following two vectors are designed for use by the OS only.
RBLOKV is the entry vector for the cassette "read-block" routine.
This is the vector for the cassette "OPENfor-input" routine.
VCTABL is a table of the initial values for the OS RAM vectors.
Now we're into the final part of the OS, which consists mostly of the various built-in handlers, interrupt routines, and so forth. What follows is a list of addresses for some of these routines, which can be useful to you in one of several ways. If you're a beginner, the list will provide you with an idea of exactly what the OS does. If you're a machinelanguage programmer then, along with the OS listing, the list will help you find the various routines so that you can see exactly how things are done. By studying the routines, you can also pick up on programming techniques (don't be afraid of the OS listing; it's really not that difficult to understand). Finally, if you really know what you're doing, you can rewrite the routines and put them in your own programs, customizing them to your own needs.
Most of the routines will not work without some kind of previous setup, so make sure you check the OS listing before you attempt to use them.
Please note that all the following addresses are for the original OS only. Some of them may be different in the newer versions. At the time of this writing, however, the OS listing is for the original version, and that is why these addresses are used.
CIO's initialization routine.
The main CIO routine (includes the following routines).
STATUS and special requests routine.
GET routine (GET character and GET record).
PUT routine (PUT character and PUT record).
Return from CIO with the status in the Y register.
Return from CIO with the status in ICSTAZ (35).
Compute the handler entry point using HATABS (794) and COMTAB (59081).
Jump indirectly to the device handler. An indirect jump, in this case, means fooling the 6502 into thinking that the address you want to jump to is actually the one you want to RTS to. This involves playing with the stack and is a pretty neat trick you may want to look at.
Find a particular device in the handler address table.
This is a table of offsets into the handler entry point table for the desired device. It is used to find the correct vector for the given command.
Interrupt Handler Routines
Initialize the interrupt handlers.
Jump to the main IRQ handler routine through VIMIRQ (534,535). Unless you've changed it, VIMIRQ points to SYIRQ.
This is the system's IRQ handler routine.
This is the system's NMI handler routine.
System VBLANK Routines
This is the immediate vertical blank routine (Stage 1 VBLANK).
This is the Stage 2 VBLANK routine.
This routine can be used to set up vectors for your own VBLANK routines, and also for the system timers. See SETVBV at 58460.
Exit from vertical blank.
SIO's initialization routine.
The main SIO routine (includes the following routines).
Return from SIO.
Wait for the device to finish what it has been told to do.
Send a buffer of bytes to a device.
This is the "serial-output data needed" interrupt routine. See SER-OUT at Location 53773.
This is the "transmission done interrupt" routine. See POKMSK at Location 16.
Receive a bunch of bytes from a device and store them in a buffer.
This is the "serial-input data needed" interrupt routine. See SERIN at Location 53773.
Read or write a record to cassette (SIO handles the cassette differently than other devices).
Figure out the baud rate for the next record. See CBAUDL/H at Locations 750 and 751.
This is a table of values used in the preceding baud-rate routine.
Disk Interface Routines
The disk interface's initialization routine.
The main disk interface routine.
Printer Handler Routines
This is the beginning of the printer handler. See HATABS at Location 794 for a list of routines in this or any handler.
Cassette Handler Routines
This is the beginning of the cassette handler. See the note at PRNORG.
The cassette handler uses this routine to make the keyboard speaker beep when you type CLOAD or CSAVE.
This is the start of the System Reset routine.
The start of the coldstart routine.
Clear all the RAM locations.
Clear the OS RAM only (for warmstart).
The blackboard routine (memo pad mode).
Check to see how much RAM there is.
Initialize the hardware locations.
Initialize the OS RAM locations.
Boot the disk if it's so desired (i.e., the disk drive is hooked up and turned on).
Boot the cassette if it's so desired (i.e., the Start button was held down when the computer was turned on).
Display Handler Routines
OPEN the display handler (set up a graphics mode).
GET a character from the screen.
PUT a character on the screen.
PLOT a point on the screen.
Screen Editor Routines
INPUT a logical line from the keyboard and print it to the screen. Remember that a logical line ends either when you press Return or fill three rows on the screen.
PRINT a character on the screen, making sure that control characters are processed instead of just printing (i.e., a CTRL-arrow will move the cursor rather than printing an arrow).
Keyboard Handler Routines
GET a character from the keyboard.
Process all the various control characters.
Ring the bell.
More Display Handler Routines
Take the row number and column number that the cursor is on and figure out what memory location that corresponds to.
Convert an internal character value to its ATASCII value.
Clear the line that the cursor is currently on.
Scroll the screen.
Draw a line from OLDROW OLDCOL to TWOCRS,COLCRS (Locations 90 through 92 and 84 through 86).
Tables, Tables and More Tables
Locations 65093 through 65469 are various tables for use with the display handler. Check the OS listing for more details and to find out which routines use them (use the cross-reference table at the end of the listing).
One More Keyboard Routine
The IRQ in this location's name should tip you off to the fact that this is the interrupt routine for the keyboard. It debounces the keys, checks for CTRL-1 (pause) and sets SSFLAG accordingly (767), stores the key value in CH (764) and CHI (754), and clears ATRACT (77).
That's All Folks
Yup, that brings us to the end of Atari memory. Thanks for bearing with me for all of this. You can now relax and take a welldeserved break!