Animations with Commodore 64 BASIC: zooming chessboard

A zooming chessboard is a classic on demo coding. Assembler is a must here if you want the effect to be smooth and real-time. But, we can get some sort of zooming chessboard even with Commodore 64 BASIC.

 

Download: chessboard animation with C64 BASIC

Video

 

The program takes some seconds to draw the frames, then it shows a coarse but fast chessboard zoom effect. This is just an animation flipping between different video matrixes on Ram memory. Each frame contains a chessboard pattern of a given characters size. In a way it is not a zoomer but looks like it.

 

Chessboard animation Commodore 64 BASIC

 

The first problem is drawing a chessboard of a given size. For the sake of simplicity we are going to deal with 8*8 pixels resolution, so that we will use characters to draw the chessboard. This is much faster than dealing with bitmapping (either on a bitmapped screen or programmable characters). However, size changes of the chessboard will be quite coarse, as the minimum size increment of each square will be no less than one character on both x and y directions.

As we draw chessboards of different sizes, a problem arises. The whole chessboard pattern of a 1×1 characters size fits entirely on the screen. But a 3×3 will not for instance. The last square to the right will be only partially viewable.

So, the code will have to draw the right number of squares for each chessboard size. And also, some squares may need to be trimmed so that the chessboard fits properly on the screen.

On the code, I have used accumulators to accomplish this. Furthermore, the variable SL is modified when needed to accommodate for the trimmed squares to the right (you may see line 16 in the program).

Trimming is also handled on vertical direction. Counters are used so that the code draws only a part of squares to the bottom when needed. Variable CR is used as a correction value for the purpose (please see lines 26 and 32).

Correction values on both direction affect the end value of the variables on the FOR… NEXT cycles used for drawing, so that chessboard trimming is performed when needed.

As a chessboard pattern is quite repetitive, only two 40 characters strings are needed to draw the whole pattern on the screen. The variable I is used to switch from the two different characters ditherings, so that the chessboard shape is properly drawn.

By using the two strings on the array B$, chessboard drawing speed is vastly improved compared to a one by one character drawing approach.

Each frame is drawn on a particular screen memory block. Each block is 1000 bytes, as we have 40*25 characters on screen. To be exact, the last characters line is not used. This is a simple way to avoid text scrolling performed by the operating system right after the last character on line 25 has been printed.

The program uses bank 1 of the Vic-ii chip to store 14 frames (bank 1 is on memory locations from 16384 to 32767). Bank 1 was my choice as it has no ROM characters shadow and it has no I/O registers too. Only 14 frames are used because the last 2 kbytes of this 16k bank are used for the custom characters set (though only a couple of characters are used by the program, each with a dither).

Of course we could use other banks in addition to get more frames, but to keep things simple this was my choice. After all, the more frames, the more time for setup.

Characters used are multicolor, so that we overcome the fact that color memory cannot be moved. Thanks to multicolor mode, we are not stuck with monochrome frames here. I used dithering because it somehow helps to make the zoom effect look less coarse.

As usual, raster synchronization with the wait statement is used for the animation. And flipping between frames was just a matter of setting the upper 4 bits of register 53272.

 

Previous Entries The C64 mini by Retrogames - is this a new Commodore 64? Next Entries Digiloi: a full PETSCII graphics game for the C64 and Plus/4

Leave a Reply