Visualizing Zero Page on the Commodore VIC-20

The VIC-20 is a very flexible little machine and allows us to choose which area of memory represents the screen map. One interesting thing we can do is use this to visualize a section of memory such as the zero page. This can create quite interesting patterns on the screen and allows us to actually see some of the processing of the Vic in action.

Moving the Screen Map

The VIC chip uses a 14-bit screen map address and uses bits in locations $9002 (36866) and $9005 (36869) to set it. Because of the peculiar way the VIC chip works when we alter location $9005, bit 7 must be set even though it will be changed to 0 in the final address for the screen map. Bit 7 of location $9002 also determines the location of the colour map. The remaining bits of $9005 set the character map address and they default to 0 on an unexpanded Vic. The remaining bits of $9002 set the number of columns displayed and they default to 22.

Screen MapColour Map$9005 Bits 7-4$9002 Bit 7Notes
0Display pages 0 and 1
0Default screen map with 8Kb+ RAM expansion
Default screen map for unexpanded Vics or those with 3Kb RAM expansion

Compute credits Jim Butterfield with demonstrating how you can set the screen map to start at location 0 which allows you to observe the first two pages of memory. Well nearly, because the screen can only display 506 bytes so the end of the second page can't be seen on the screen.

Page 0 - Zero Page

The zero page is important because it allows machine code programs to use shorter and faster instructions. BASIC and the Kernal make heavy use of the locations in this page for frequently used data storage and therefore it is an interesting section of memory to look at.

On an unexpanded Vic we don't need to worry about what is already in locations 36869 and 36866 and therefore we can easily set the colour map to black text on a white background to make all the locations visible and then set the screen map to location 0 using:

FOR I=37888 TO 37888+505:POKE I,0:NEXT I
POKE 36869,128:POKE 36866,22

While the screen is showing the zero page we could enter and run code to see what happens in zero page. An easy demonstration would be to enter a FOR loop:


Page 1 - The Stack

The 6502 reserves 256 bytes for the stack beginning at location $100 (256). However, Basic uses locations $140-$1FF (320-511) as a stack and the preceding locations for a tape error log and for converting floating point numbers to ASCII.

We could demonstrate the BASIC stack being filled by repeatedly calling a nested GOSUB routine:

10 GOSUB 10

Interesting Locations

There are a number of interesting locations and patterns that we can see. There are lots of '@' symbols which would be $00 in memory. There are two locations that we can see counting. There is also a location that oscillates between '@' and 'A' which would be between $00 and $01 in memory.

87Jiffy Clock counting one-sixtieths of a second
$C5 (197)922Matrix coordinate of last key pressed, 64 if none pressed
$CB (203)106Matrix coordinate of current key pressed, 64 if none pressed
$CD (205)108Cursor countdown before blink. Normally counts 20 jiffies before blink of cursor.
$CF (207)1010Cursor blink status 1 = reversed character, 0 = non-reversed. We can see alternating between '@' which is 0 and 'A' which is 1.
$D3 (211)1014Cursor position within the logical screen line. Keep pressing a key to see increment from '@' which is 0 and then press return to see it revert to '@'.
$D7 (215)1018ASCII value of last key pressed. Change to lowercase to see key pressed.
1215The 6502 stack
1513The BASIC stack


The following video shows zero page being visualized and exercised to create interesting patterns.

Creative Commons License
Visualizing Zero Page on the Commodore VIC-20 by Lawrence Woodman is licensed under a Creative Commons Attribution 4.0 International License.

Share This Post


Sign up to get new articles straight to your inbox.

Delivered by FeedBurner

Related Articles

Saving and Loading Memory on the VIC-20

Saving and loading memory is quite easy on the VIC-20 once you know how. However, it isn't obvious how to do this and therefore this article will present a few simple ways of doing it from BASIC and A...   Read More

Basic Line Storage on the VIC-20

BASIC programs are stored in memory using a simple structure that we can investigate and manipulate. This article will show how they are stored and contains a BASIC program to go through each line of ...   Read More

Programming in Assembly with VICMON on the VIC-20

VICMON is a machine language monitor released by Commodore in 1982 and is great for programming the VIC-20. Its interactive nature means that it can often be quicker to develop via this rather than us...   Read More

Storing Machine Code in REM Statements on the VIC-20

BASIC programs often contain machine code routines but they take up quite a lot of space in BASIC. An interesting way to reduce the amount of space that they take is to store the machine code in REM s...   Read More

Code and Data in Display Memory on the VIC-20

The unexpanded Commodore VIC-20 only had 5K of RAM and therefore creative ways had to be found to maximize the available RAM. The display memory would use some of this memory and therefore one option ...   Read More