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
$0000$94001000
(128)
0Display pages 0 and 1
$1000$94001100
(192)
0Default screen map with 8Kb+ RAM expansion
$1E00$96001111
(240)
1
(128)
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:

FOR I=1 TO 1000:PRINT"HELLO":NEXT I

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.

LocationRowColumnPurpose
$A0-$A2
(160-162)
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.
$100-$1FF
(256-511)
1215The 6502 stack
$140-$1FF
(320-511)
1513The BASIC stack

Video

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

Feedback/Discuss

Related Articles

80 Columns in Software on the Commodore VIC-20

If you have good eyesight, a well-tuned display and patience it is possible to use 80 columns in software on the VIC-20. This is really just an experiment but considering the limitations of the Vic I ...   Read More

64 Column Text Mode on the Commodore VIC-20

With a little lateral thinking and by putting the television on its side we can create a 64 column sideways text mode on the VIC-20. This article will demonstrate this and show how it is done. Previo...   Read More

Getting the Address of BASIC Variables on the VIC-20

Getting the address of a BASIC variable can be useful if you want to pass data to a machine code routine or want to access the bytes of a variable directly to improve speed and reduce garbage collectio...   Read More

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