
One of the most confusing things about the VIC-20 is the screwy way that memory locations shift around when you add RAM expansion. Add 8K of RAM or more and everything changes: suddenly Screen and Color Memory move to different locations. Old programs for the unexpanded VIC that POKE to the screen or use redefined character graphics no longer work. Depending on the amount of RAM expansion you have, BASIC even begins in different locations. Aargh!
The diagrams on this page all come from Leif Bloomquist's Commodore VIC-20 Memory Blocks Illustrated. This PDF helped me a lot in my own quest to figure all this out. Click HERE to visit Leif's site.
Also, Anders Persson has written a great tutorial: Graphics and Bigger Screen in BASIC on the Expanded VIC-20. Anders' website is HERE.
Another good resource is the book VIC Revealed, by Nick Hampshire. If you want to really understand how the VIC works, you owe it to yourself to get this book. It's fairly common, you can often find it on eBay.
Like most things, it doesn't seem that hard
once you figure it all out ...
FIGURING IT ALL OUT

Let's imagine the VIC's memory as a series of 8K "blocks," starting at 0000 (block 0) and ending with block 7 (E000). Expansion RAM can be placed in the yellow blocks: 1,2,3 and 5. There's also a little 3K slice available in block 0 that we'll talk about later.
If you put 8K in blocks 1,2, and 3 your VIC will have 29K total RAM available to BASIC. That's the 5K the VIC came with plus 8K in blocks 1,2 and 3. RAM has to be contiguous to be seen by BASIC. That is, BASIC only sees RAM as a single big chunk of memory. Since blocks 1 - 3 are right next to each other, the VIC can see all of it as one big 24K hunk of RAM. So, looking at the diagram, you can understand why 24K is the maximum amount of RAM expansion available to BASIC.
BLOCK 5
You've no doubt observed that block 5 is not contiguous with blocks 1,2, and 3. Block 4 is in the way. So BASIC can't see RAM in block 5. You might be asking yourself: If RAM in block 5 is invisible to BASIC, what good is it? You can place machine language programs in block 5, or use the RAM to store data that can be read with BASIC's PEEK statement. So, RAM in block 5 can still be quite useful. The only thing you can't use it for is to add to the RAM available for BASIC programs.
Another feature of block 5 is that programs stored in this area can be "auto-started" when the VIC is reset. Most cartridge games are located in block 5. You can tell because these games start automatically when you turn the VIC on. To further illustrate, the Programmers' Aid Cartridge puts its program in block 3. That explains why you have to enter SYS 28681 to launch the Programmers' Aid. Only programs located in block 5 will start automatically when you reset the VIC.
It sounds pretty straightforward, doesn't it? Can it really be this simple? Unfortunately, the answer is no. We're going to have to take a look at what's in block 0 and block 4 to see where things get a little tricky.
BLOCK 0

The diagram above blows up blocks 0 and 4 so we can see their contents. Take a close look at block 0 on the unexpanded VIC. The white area, from 1000 to 1DFF, is our User BASIC Area. This is the RAM that's available for BASIC programs. This one tiny little slice of block 0 is all the RAM we have to work with. Not much, is it? Let's start adding some RAM and see what happens.
ADDING 3K
The yellow section from 0400 to 0FFF in our block 0 diagram is a 3K area set aside for RAM expansion. This is where the RAM in Commodore's 3K RAM Expansion cartridge or 3K Super Expander goes. After adding one of these cartridges our block 0 diagram looks like this:

And there we have it-- The beginning of BASIC moves down to 0400 and we now have an extra 3K of RAM to work with. Now let's add an 8K RAM cartridge to block 1.

The diagram above represents our VIC with 3K expansion, plus 8K in block 1. Uh oh, there's a problem. Do you see it? Remember, all RAM available to BASIC must be in a single continuous chunk. Screen Memory (1E00 - 1FFF) is separating the User BASIC Area from the 8K expansion we want to put in block 1. What do we do? There's only one thing we can do: we have to move Screen Memory somewhere else. The VIC does this automatically when you add expansion RAM to block 1. Here's what block 0 and 1 look like after adding 8K to block 1.

Screen Memory moves from 1E00 to 1000. Now we can add 8K to blocks 1,2, and 3 and all the BASIC RAM will be in one continuous chunk. BASIC now begins at 1200 and runs until the end of expansion RAM. One more detail: Color Memory in block 4 has to be a precise distance from Screen Memory. Since we moved Screen Memory, Color Memory will have to move too-- from 9600 down to 9400.
Hey, what about my 3K RAM at 0400? Since Screen Memory is now separating our 3K area from the User Basic Area, RAM in the 3K area becomes invisible to BASIC just like RAM in block 5. It's a trade-off, but it allows us to fill blocks 1 - 3 with RAM that can be used by BASIC.
Let's tie it together with a diagram showing
all the possible memory configurations. Note
how Screen Memory (block 0) and Color Memory (block 4) move to different
locations when adding 8K+ of RAM expansion.
