Commodore VIC 20 BASIC programming: scrolling chessboard

Although the available BASIC RAM memory on an unexpanded Commodore VIC 20 is quite limited, it is still possible to achieve interesting results with this little nice machine. You may have already seen my posts dealing with programming scrolling chessboards by using Commodore 64 BASIC (please see the programming section of this blog). On this article, I will show you a VIC 20 version which scrolls the entire screen vertically.

The chessboard is 44 squares wide. Each square is as wide as half a character. Due to the low resolution of the VIC 20 screen, if we used a whole character as a chessboard square, the squares would have actually looked like rectangles. As a result, on each character we have a filled square and an empty square lined-up.

 

DOWNLOAD: VIC 20 BASIC program: scrolling chessboard (PAL, unexpanded machine) 

 

As you can see, the program allows full screen scrolling of the chessboard, without any flickers. The program is intended for a VIC 20 PAL machine. I have successfully tested the program on both a VIC 20-CR (the newer board that can be powered with a C64 PSU) and a VIC-20 E board (the one requiring 9 V AC).

 

 

Raster synchronization is achieved by using the address 36868 decimal. It contains the current raster line number. Using the good old “trial and error” method, I’ve found out that the instruction WAIT 36868,128 will work just nicely. It just happens to exit the WAIT loop when the rasterbeam is out of the viewable area, allowing to make changes to the graphics on the screen with no flicker. The instruction WAIT 53265,128 on the Commodore 64 is quite different instead: it tests a specific bit, waiting until the rasterbeam is out of the viewable area.

The instruction WAIT 36868,128 should theoretically wait until raster line #128 is being scanned. And that should be in the viewable area. But, the time required for the WAIT statement to be executed by the BASIC interpreter actually implies that the WAIT loop is exited with some delay. By that time, the rasterbeam is no longer on the viewable screen area. That just fits our needs.

On line 1, please notice the instruction POKE 36869,255, which is used on the VIC 20 to switch from ROM characters to RAM characters starting from location 7168 decimal.

Notice the two POKEs used on line 8. This is the good old trick to avoid screen editor scrolling when using the PRINT instruction to fill the whole screen with characters. So, the last character of the last row is POKEd, not PRINTed. Color RAM memory must be poked as well, otherwise that character will have an incorrect background color. On an unexpanded VIC 20, screen memory starts from location 7680 decimal. Color memory starts from location  38400.

The program only changes two bytes on each frame, actually changing the shapes of only two characters on the screen. Since the VIC chip updates any character on the screen with the same screen code of the character being modified, only those small changes are enough to scroll the whole screen smoothly.

The VIC 20 scrolling chessboard program is quite similar to this Commodore 64 program, so you may take a look at that article for further explanations, as the code presented there is more or less the same as the VIC 20 version. The only difference is the adjustment made in order to have half-character-sized squares.

Although the VIC 20 computer may happen to seem very limited, it is actually a very nice machine with many “hidden” features.

There are many books dealing with the VIC 20. I think you shouldn’t miss the following ones:

  • Commodore VIC 20 Programmer’s Reference Guide
  • Programming the VIC by Raeto West.

 

Precedente Garbage collection nel BASIC del Commodore 64: come gestirla Successivo Very basic BASIC - simple tips for entering strings with INPUT (Commodore 64 BASIC)

Lascia un commento

*