` A.N.A.L.O.G. ISSUE 63 / AUGUST 1988 / PAGE 16`

Master Memory Map

My grandmother once
told me, "Do yourself a
economy size. You'll
need it:"

by Robin Sherer

What is a memory location?

Good question! Your Atari has many "places" within it that can contain numbers. These places we call memory cells, locations or addresses. You may use any of these words to mean the same thing, but "address" is the more formal term that you will hear computer programmers using. Since the computer can remember the numbers in each of these places, it is common to call them the computer's "memory." Memory is like many blank pages of paper. Each page can hold only 256 numbers, and we can have up to 256 of these pages.

We encounter another
small problem when we
mess with memory.
Some memory
but will not allow us to
write to them.

So where does this leave us? Well, 256 locations per page times 256 pages gives us 65536 locations total that can be in your computer. Computers count in terms of something called a "K." For reasons beyond my control, one K of memory is actually 1024 locations. Why? I'll explain all in a few pages. For now divide 65536 by 1024 to get a possible memory size for the Atari of 64K.
The Atari is capable of using 64K of memory. (The XE computers use something called "Bank Switching" to get around this limit.) The factory gives you 16K ROM and 64K RAM when you buy the computer (we'll explain ROM and RAM later), but there is a catch (of course). A lot of memory that comes with the Atari is already filled up with numbers that tell the computer how to run. The blank area available for you to use is a lot less than you're led to expect. If you want more memory, you have to go down to your friendly dealer and buy it. My grandmother once told me, "Do yourself a favor, buy the large economy size. You'll need it:" She was talking about soap, but her wisdom applies to computers as well.
Now that you understand how much memory you have, let's talk about it a little. Each memory address can hold numbers from 0 to 255. Computers start counting at 0 because "nothing" is a very valid piece of information. I certainly worry when my wallet has "0" in it! Let's learn how computers count.

Bits and bytes
A "byte" is really not complicated at all. It is simply a group of eight "bits." When eight bits are structured into a byte, each of those bits has special significance. You look puzzled! What, you say, is a bit?
A bit is the smallest piece of information that a computer can deal with. To help understand how bits are used by the computer, it may help to imagine the microprocessor as a bus station. This bus station is on a single-lane road. That means a bus can only travel in one direction at a time as there is not enough room for two buses to pass each other. Therefore, a bus may either be arriving at the station or departing. The microprocessor, or bus station, can schedule its bus with a signal light that says "I am accepting arrivals" or "I am sending departures:"
In fact, in real computer hardware architecture, the wires that carry information to and from a microprocessor are called the "data bus:" We don't need eight separate input and eight separate output wires because, like the single-lane road connected to the bus station, the wires are bi-directional. In other words, information can either be arriving (input) ordeparting (output), but not both. The microprocessor also has a signal of its own that determines whether it will receive (input) or send (output) information.
Let's take a closer look at that bus. It is known as the Byte Express, has eight seats and always carries eight passengers. Those passengers are little messengers known as bits, and, as a group, they are known as a byte. These messengers, or bits, are rather moody. They are either turned "on" or they are turned "off:' That is called "binary" as they are bi-state signals; on being a "1" state and off being a "0" state. Their vocabulary is just as limited-the only thing they are willing to tell you is their mood. Now how do we get any meaningful information out of a group of eight little messengers standing in front of us, each screaming "on" or "off' at one time?
Well, when the bus arrives, we could have the whole byte stand in front of us and count everyone who is turned "on:" That would give us the capability of counting to eight. Seems pretty limited, doesn't it? Hmmm, the group really needs a leader. That leader will be the first bit on the left. We'll call that the Most Significant Bit, or MSB. The last bit on the right will be the Least Significant Bit, or LSB. Terrific! Now that we have a group leader and a group follower, all the bits should be given a rank.
Handing out ranks is serious business and much thought should be given to it. We can start with the LSB and assign that bit the rank of "1," since it is the Least Significant Bit. We can be easy on everyone if we just double that rank for the next bit in line. So, why not just keep doubling the rank for the next bit in line and so on until we get to the MSB or Most Significant Bit. Now our byte looks something like this:

What have we gained? More than meets the eye! When the byte gets off the Byte Express and each bit starts telling us what its current mood is, we can make a different and more meaningful interpretation out of the little guys. If everyone is turned "off" except the fourth bit from the right, for example, we can check the rank of that bit and find it is eight (8). Unknown to the bits, they have brought us a message and the message is "8."
Aha, what if we want the bits to get on the bus and carry a message that says "9"? This is a problem because there is no bit with a rank (value) of 9. What to do? I guess the next best thing is to be very nice to the bits that have values of one and eight and turn them both on. When we look at the byte now we see 1 + 8 which gives us our 9. Easy. Even my student Nerdwell can count that high. In fact, Nerdwell can count to 255 because if you add up all the values of the bits, you get 255:

1+2+4+8+ 16+32+64+128 = 255

How to peek
In using the memory map, we are going to change the values that are stored in many of the bytes that make up memory. To make the discussion easier, we will usually talk about the bytes as locations or addresses. These addresses are just like those on mailboxes on a long street. They start at 0 at one end of the street and increase until they reach 65535 at the other end (64K ... remember). Yes, a computer's memory represents a long street. Let's look now at one such address. To see what is inside the location, we will use a BASIC command called PEEK.

In case you're
wondering, the
difference between
machine language and
assembly language is
not much,

To PEEK at memory location 764, type in this line:

10 PRINT PEEK(764):GOTO 10

Type RUN, press the return key and watch the number 255 print over and over on your screen. Now press the space bar and you should see 32 printing. What is happening? 764 is the location that tells you what key is being pressed. 255 means no key and 32 means the space bar. Now you can see how a program could know if you have pressed a certain key. Try a program something like this:

10 A=PEEK(764)
20 IF A=32 THEN PRINT "YOU P
RESSED THE SPACE BAR"
30 GOTO 10

Now you can see why it is important to have a memory map. It would be very difficult to know which location to PEEK at without a map of your computer's memory.

How to poke
Now that we can look at memory locations, we also want to be able to change what is inside them. Your wish is our command. Later in the map you will learn that a value of 1 in location 752 will cause the cursor to disappear (the cursor is the little white box on the screen). This can come in handy when you have a whole bunch of text on the screen, and you don't want the cursor up there with it. Since location 752 doesn't normally contain a value of 1, we must change it. The POKE command in BASIC will do this for us:

POKE 752, 1

That was easy. Now you know that POKEing and PEEKing are what a memory map is all about. For the most part, the map will just tell you different numbers to POKE and PEEK.

ROM and RAM
We encounter another small problem when we mess with memory. Some memory addresses will allow us to read what is there, but will not allow us to write to them. Memory that we can both read from and write to is called RAM, which stands for Random Access Memory. This means that we can put numbers into these kinds of memory locations as well as look at what they already contain. The other kind of memory is called ROM, Read Only Memory. It is just what its name implies-we can only read what number is inside a ROM location, not change it.
Now the next logical question is how do you know which is which? We will simply tell you as we go through the locations.

Computer mathematics
This section will open new vistas in your horizons. We are going to learn how the computer deals with numbers larger than 255, and also how to use the hexadecimal numbering system.
You must always use decimal numbers with a POKE statement. This means that sometimes you will have to convert between binary, hexadecimal and decimal. The "Bits and Bytes" section covered binary numbers where we turn on and off individual bits. In that section you saw that each memory location can only hold numbers up to 255. To store a value larger than that, we just use two locations in a row.
As an example, look at memory locations 88 and 89 which are called SAVMSC. These locations hold a number that tells where the top of the screen is. Because the screen is usually somewhere near the end of memory (it starts at location 40000 in a 48K Atari), at an address that is way beyond the 255 limit for one memory location, the computer needs two locations to store the address. Remember the ranking of the bits where the MSB, or bit seven as we called it, was valued at 128? If we double that rank again, we get 256. Here is the trick to computer math. Since there is no bit eight to give such a rank to, we give the rank to the entire next byte of 8 bits. Now we just see what the total of this second byte is and multiply it by 256. Figure 1 is a sample:

Figure 1. Bit map

Humans use dictionaries
to speak the same
words. In the case of
computers, ASCII
allows one computer
to understand the letters
and numbers created
on another computer.

When using two byte numbers, we call the first byte in memory the "low byte" because it stores the lower value. It can only count from 0 to 255. The second number counts in multiples of 256 and is called the "high byte:"
Let's try to PEEK and POKE a two-byte number. Suppose you wanted to fool the computer into thinking that the screen was in a different place in memory. Such a trick can come in handy when you want to have more than one screen at the same time. First let's look at memory and see where the computer thinks the screen is now. Here's a program to do this:

10 SCREEN=PEEK(88)+PEEK(89)*
256
20 PRINT SCREEN

Addresses 88 and 89 form a two-byte location called SAVMSC which points to where the computer thinks the first byte of screen memory is.
When you run the preceding program, the address that gets printed out will vary, depending on how much memory your computer has. What we're going to do is add 480 to this address so that the computer will think that screen memory starts halfway down the current screen. All this means is that no text will print in the top half of the screen, and you'll be able to type below the bottom of the screen (although you won't be able to see anything there).
Let's go ahead and replace the old value of SAVMSC with a new number that is exactly 480 more than the old one. Add the following lines to the preceding ones:

30 SCREEN=SCREEN+488
40 SCRHI=INT(SCREEN/256)

Line 40 finds out what number goes into the high byte of SAVMSC. Remember that the high byte counts the number of pages, or multiples of 256, and that's why we divide by 256.

50 SCRLO=SCREEN-SCRHI*256

Now we multiply the new high byte by 256 and subtract it from the total to get the low byte.
Finally we place the new values in memory:

60 POKE 88,SCRLO:POKE 89,SCR
HI

The high byte can count from 0 to 255 just like the low byte. This means the largest number we can have using a two-byte address is:

255 + (255*256) = 65535

If we count 0 as a number (since the computer does), that gives a total of 65536, which brings us back again to 64K. We have now come full circle in our discussion, so it is time to go on to something else to challenge you.

Come back. You don't have to run away at the sound of those words. Hex, as its friends call it, is not nearly as hard as everyone thinks it is. As a matter of fact, it's really quite simple. But, just in case you don't believe us, I provide both decimal and hexadecimal numbers throughout the map. Now, though, we're going to learn about hex together.
The main use for hex is in assembly language programming. Were not going to worry about that now though, because it's not really important. Instead, we're going to go back to grade school, where we first learned all about the number system. As you'll recall, we use the decimal number system, which means everything is based on powers of 10. For example, the number 452 is equal to 4*100 + 5*10+2*1, right? In other words, 4*10 ^2 + 5*10^1+2*10 ^0.
Now you're not going to believe this, but the particular difference between decimal and hex is that hex is based on powers of 16 instead of 10. For example, 452 hex would equal 4*16 ^ 2 + 5* 16 ^ 1+2*16 ^ 0 or 4* 256 +5*16 + 2 , in other words, 1106.
Pretty simple, huh? Actually, there's one more thing that I should probably mention. The number 9 in hex is the same as 9 decimal, but 10 hex is 16 decimal (1 * 16 ^    1). So how do you write 10, 11, 12, 13, 14 and 15 decimal in hex? Try A, B, C, D, E and F! That's why hex numbers look so confusing. So, for example, F in hex equals 15 decimal, 1F equals 31 (16 + 15), and so on. Oh, and by the way, binary is actually the same as hex and decimal, except it counts in powers of 2!
Don't worry, I'm not going to leave you yet. A few more examples should make you a little more comfortable about hex and how to use it, but first a chart (Table 1) to help us out.

Table 1. Hex Conversion Chart

 Column # 4th 3rd 2nd 1st | | # HEX 4096 256 16 1 | 1 8192 512 32 2 | 2 12288 768 48 3 | 3 16384 1024 64 4 | 4 20480 1280 80 5 | 5 24576 1536 96 6 | 6 28672 1792 112 7 | 7 32768 2048 128 8 | 8 36864 2304 144 9 | 9 40960 2560 160 10 | A 45056 2816 176 11 | B 49152 3072 192 12 | C 53248 3328 208 13 | D 57344 3594 224 14 | E 61440 3840 240 15 | F

Decimal to hex
Let's take the number 9304. Look in the chart to find the largest number that is smaller than 9304. That would be 8192, which is the second number in the fourth column. This means the hex number will have four digits because you found the decimal value 8192 in the fourth column. Write down the "hex #" from the chart in the fourth place:

2---
Now subtract 8192 from the original number of 9304 to leave a remainder of 1112. Looking at the chart again we find the nearest smaller number of 1024 in the third column. Put down the corresponding hex # and subtract 1024 from 1112:

24- -

Do the same for the new remainder of 88 to find the hex # digit for the second and first place of the hex number. Don't forget to mark hex numbers with a "\$" as is standard with computer types like us. Here is the complete example (Example 1):

Example 1. Decimal-to-hex example

If you find that you have numbers for only the first and third places, this means to add a 0 as a placeholder. \$040F would be an example.

Hex to decimal
Conversion in this direction is even easier. Just look up each hex number in the chart, find the corresponding decimal value, place them in a column and add them up to get a decimal total. Here is the mandatory example (Example 2) you are no doubt expecting:

Example 2. Hex-to-Declmal example

Glossary
Next month we will begin publishing the actual memory map. Until then, you should familiarize yourself with the following terms and definitions. As we explain the inner workings of the Atari, we will have to refer to some of the following words. If you find some term we forgot to mention here, it's probably because it is fully explained at the memory location it pertains to. You should also read your BASIC manual in order to understand the terms that have to do with the BASIC language.

6502: This is the heart of the computer, the chip that bosses everybody around. Actually, a lot of people even refer to 6502 as being the computer, since it does have almost all of the brains.

Accumulator: This is a location that is used to temporarily store the results of logic and arithmetic operations. The main accumulator is inside the 6502 chip, but sometimes memory locations are also used as an extra accumulator.

Address: The number assigned to an individual memory location. Each byte in the Atari has its own unique address, much like a house has a street address. The main use of the memory map is to provide you a roadmap to each address so you don't get lost.

Algorithm: A general procedure, plan or method that represents how your program will be written.

ANTIC: This is a chip in the Atari computers that figures out what the screen is supposed to look like.

ASCII: American Standard Code for Information Interchange (pronounced ASK-KEY). Everyone needs a standard or reference to refer to. This allows us to all speak to each other in the same terms. Humans use dictionaries to speak the same words. In the case of computers, ASCII allows one computer to understand the letters and numbers created on another computer. Atari computers do not follow a true ASCII, but have their own code instead which we explain later.

Assembly language: This is a programming language, just like BASIC, except it talks the computer's language instead of having to go through a translator. See "machine language" as well.

ATASCII: ATAri Standard Code for Information Interchange. This is the code the Atari uses to convert letters to numbers and vice versa. See your BASIC manual to find out how it differs from ASCII.

Baud: The rate of transmission of information conveyed between two computers. You usually say "Baud Rate" meaning how fast the two computers are talking to each other. This rate is determined by the bits per second that are being transferred. You encounter this term if you are using a modem, printer, disk drive, terminal or other device that needs to talk to a computer to work. Typical speeds of information transfer are 300, 1200, 2400, 9600 and 19200 bits per second.

Bit: The smallest piece of information the computer can handle. There are eight bits in a byte. Each bit can either be "on" or "off." See the section "Bits and Bytes" for a complete description. Sometimes you'll see "-" for the value of a bit. This just means that it doesn't matter if that particular bit is on or off.

Bit mapping: This refers to the process of turning individual bits on and off without changing the rest of the byte.

Boot: No, this isn't even close to what it sounds like. "Booting" a program means loading it in when the computer is turned on. For example, if you hold down the START button while turning on the computer, the computer will beep. This means that it expects a boot cassette to be in the cassette player. When you turn on the computer with the disk drive on, you will boot DOS. In other words, any program that loads in without you having to tell it to load is a boot program.

Boundary: As in "4K boundary." This is the end of the block of memory. For example, a lK boundary would be the end of 1024 byte block.

Buffer: A storage place, usually temporary, where information can come and go without disturbing things.

Bus: A bus is a system of electrical lines shared by all devices that are connected to it. This is a convenient way for these devices to share data. It works just like a party-line telephone. Different parts of the computer talk to each other by getting on the bus and sending messages.

Byte: Pronounced "bite." A collection of eight bits. Each memory address consists of one byte. Since we know at this point bytes and bits can be confusing, we provide a special section elsewhere called "Bits and Bytes" to explain it to you.

Checksum: A checksum is a special byte that the computer uses after talking to something to make sure it understood what was said correctly.

CIO: Central Input/Output. This is Atari's main I/O routine.

Coldstart: A routine the computer goes through after you turn it on and before it lets you tell it what to do.

Color clock: A unit of measurement on the screen. A color clock is the width of a pixel in graphics mode seven. That means that the screen is 160 color clocks wide from border to border.

Controller jack: What you plug your joystick into.

CTIA: This chip takes care of translating the data coming from ANTIC into something the television set can understand.

Cursor: The position on the screen where the next character or pixel will appear. In graphics mode zero, you can see the cursor; it's the white box.

Data: Any kind of information that is needed by a program or by the computer.

Default: When you first turn on the computer, each memory location will contain a value. These initial values are called defaults, meaning that this is what these locations will equal if you don't change them.

Device: Anything that the computer has to talk to is called a device. This includes the disk drive, printer and even the keyboard and television set.

Disable: To turn off. By disabling the BREAK key, for example, you can prevent someone from accidentally stopping your program.

Display list: The program for ANTIC that describes what the screen is to look like.

DLI: Display List Interrupt. See "interrupt:"

DMA: Direct Memory Access. The process of getting data from memory to put on the screen.

DOS: Disk Operating System. A program that controls the use of the disk drive. See "OS" as well.

DUP: Disk Utilities Package. This is a bunch of routines to do various things on the disk drive. The DOS menu is actually a list of these routines.

Enable: To turn on. The opposite of disable.

File: A whole bunch of data stored on disk or cassette.

Flag: A signal that a certain condition has been met. In many BASIC programs, variables are used as flags, as demonstrated in the following example:

10 IF A = B AND C = D THEN FLAG = 1
.
.
.
50 IF FLAG = 1 THEN 100

Floating point: A type of arithmetic where the decimal point can appear anywhere in the numbers (i.e., it can float around). An example of such numbers would be 1.0, 23.97 and 1.45678E + 04. Floating point numbers take up much more memory than fixed point (integer) numbers.

FMS: File Manager System. This is a group of routines, or handler, to help the computer talk to the disk drive.

GTIA: A fancy version of CTIA.

Handler: A series of routines that tell the OS how to handle a particular device.

HBLANK: Horizontal BLANK. The television set draws the screen one line at a time, from top to bottom and left to right. HBLANK is the time during which it is moving from the end of one line to the beginning of the next.

Hi-res: Pronounced "high rez" This is an abbreviation for "high resolution," which refers to a graphics display with very small dots.

Immediate mode: Using the computer without running a program. For example, if you type in:
PRINT 3 + 2
and then press RETURN, you will get a result of 5 on the screen immediately.

Index: This is a variable used to keep track of where we are in a loop. For example, in the following statement X would be an index:

FOR X = 1 to 100

Internal: If something is internal, then that usually means it is built into the computer.

Interrupt: An interrupt is something that interrupts whatever the computer is doing and tells it to do something else before it continues. You should also see DLI, IRQ, NMI and VBLANK.

I/O: Input/Output (I/O) is nothing more than a fancy way of referring to the computer talking to a device, or vice versa.

IOCB: Input/Output Control Block. This is a place that you use to talk to CIO.

IRQ: Interrupt ReQuest. This is a kind of interrupt that you can tell the computer to ignore (the 6502 can enable or disable it).

Jiffy: A jiffy is 1/60 of a second, the time that it takes the television set to completely draw the screen once. In European (PAL) systems, a jiffy is 1/50 of a second.

Jump: The same thing as GOTO. The expression "jump through location" means that the computer will GOTO the address stored in that location.

K: As in 1K, 8K, 16K, etc. 1K is equal to 1024 bytes.

Logical line: A logical line is the space that a program line takes up. It can be one, two or three screen lines (try typing in a BASIC line that is more than three screen lines).

Machine language: Machine language is a way of talking directly to the 6502 chip. Other languages like BASIC have to be translated into machine language before the 6502 can understand them. That takes time, which is why machine language programs run so much faster than BASIC ones. In case you're wondering, the difference between machine language and assembly language is, not much. Machine language is just a bunch of numbers. Assembly language gives these numbers names so that they make more sense.

Masking: When you're bit mapping, you have to have a way of ignoring the bits you're not interested in. This process is called masking, since you essentially place a mask over the bits you don't want to look at.

Nibble: This is going to sound funny, but I swear it's the truth. A nibble is half a byte or four bits.

NMI: Non-Maskable Interrupt. Unlike IRQs, you can't tell the 6502 to ignore this kind of interrupt. DLIs and VBLANK interrupts are both NMIs.

NTSC: A name for the television system that is used in North America. European television is slightly different and uses a system called PAL.

Offset: If you have a whole bunch of bytes making up a table of values or a buffer or something similar, then the offset is the number of the byte in this bunch that you are currently interested in.

OS: Operating System. Its job is to make the computer run. You can think of the OS as the coach directing the players in a game. We can change some of the numbers in the operating system to make the computer do what we want, instead of what it normally does.

Page: Computer memory in the Atari is divided into 256 sections, called pages. Each page consists of 256 bytes. The pages are numbered 0 through 255, and you can tell what page a particular location is in by looking at the high byte of its address. For example, location \$09AB would be page nine. See the section called "Computer Mathematics" for an explanation of what a "high byte" and "low byte" are, and also for an explanation of "hexadecimal;' which is what that funny number with a "\$" in front of it is.

PAL: The television system used in Europe. See NTSC as well.

Parallel: There are two ways that the computer can talk to something else. One of these is called parallel I/O, which simply means that the data is sent out one byte at a time. See"serial"for the other.

PIA: This chip takes care of the controller jacks.

Pixel: A fancy word for a dot on the screen.

Playfield: Anything that appears on the screen other than a player or missile.

Pointer: A pointer does exactly what it sounds like: points somewhere. Usually this "somewhere" is the location of some information that is needed. The pointer holds the address of this location.

ROM: Read Only Memory. Computer memory that you can't change with the POKE command or anything else (it's OK to PEEK them though). ROM locations even remember their values after you turn the computer off! BASIC and the Atari operating system are stored in ROM.

Scan line: If you look very closely at the screen, you'll see that it's made up of a whole bunch of tiny horizontal lines. These are called scan lines and are the height of a graphics mode eight pixel.

Screen memory: A bunch of bytes somewhere in memory (usually at the end) that ANTIC converts into a picture and sends to GTIA or CTIA which puts it on the screen. In other words, this is where the data that is to appear on the screen is stored. In case you don't understand the difference between this and the display list, the display list tells ANTIC how to interpret the screen memory (i.e., where is it, does the data represent characters or pixels, how big are they, etc.).

Sector: A group of 128 bytes on the disk. It may be difficult to do, but try to imagine a disk being made up of 40 concentric rings. Now imagine cutting the whole disk into 18 equal-size wedges. Each of the wedges will have 40 pieces for a total of 720 pieces altogether. Well, each of these pieces is a sector.

Serial: This is a method of I/O that sends data out one bit at a time rather than one byte at a time. See "parallel" also.

Shadow register: A shadow register is a RAM location that acts like a messenger for a chip location. Any changes to the shadow register are sent to the chip and vice versa. This is necessary because a chip location can't be changed permanently, and so it relies on its shadow register to get information from you.

SIO: Serial Input/Output. This refers to a routine in the OS that takes care of serial I/O See "serial:"

Timeout: Sometimes a device needs a little time to think and breathe, so it takes a timeout. If it takes too long a timeout, however, the computer gets upset and refuses to talk to it anymore.

User: You, anybody or anything that uses the computer. BASIC is considered a user by the OS, and the OS is considered a user by the 6502. Similarly, BASIC considers your program a user, and your program considers anyone that runs it a user.

VBLANK: Vertical BLANK. We already saw that the television set draws the screen over and over from top to bottom and left to right (see HBLANK). VBLANK is the time during which the television set is going from the bottom of the finished screen back to the top to start drawing again.

Vector: This is another kind of pointer. It refers to the starting address of a routine. The computer needs to know where to look for things, and the vectors help it along the way. Usually a vector references the starting address of a machine language subroutine.

Warmstart: A routine the computer goes through after you press SYSTEM RESET before it lets you tell it what to do.