Commodore Banner Exchange
Get a site

C64 BASIC: ECM and MCM scrolling routines

I have been still doing experiments with C64 BASIC this week. Again, I have been working on scrolling routines. This time, I made two experiments – scrolling a pattern using Extended Color Mode (ECM), and scrolling a road with multicolor mode combined with hi-res characters.


Download: The Road


Click on the image for Youtube video


[Download “ECM thing”: link to be fixed]


Click on the image for Youtube video


“The Road” – How it works

We don’t have any new things here. Actually, it uses again the very same concepts of my Basic checkerboard routines (please refer to the programming section of this blog).

The green part is made up of programmable multicolor characters. Their shape is updated on the fly for each frame. It’s the same mechanism used on the checkerboards, it’s only that we now have stripes.

Road strips are drawn with hi-res programmable characters. Again, character shapes are updated on each frame.

Different counters have been used for green stripes and road stripes. In fact, while green stripes are two characters tall, road stripes are only one character tall. So, one counter must be reset after 16 bytes have been scrolled, while the other one must be reset after 8 bytes.

The scrolling loop is between lines 2 and 5. It has been placed on top of the program to gain a little speed.

The subroutine on line 40 prints the message “THE ROAD” on screen. This is printed just right after characters for the road have been printed on screen. So, that subroutine doesn’t off course clear the screen, but just performs a homing.

So we are writing to an already nearly full screen. This leads to some inconveniences. When a line has been printed, the operating system goes to the following LOGIC line. So a physic line gets skipped. To fix the problem, I came up with a not too efficient yet effective solution.  Subroutine on line 90 performs a homing and then a variable number of cursor downs. For each call, we have one more cursore down. This way, we get the message printed without stepping lines.

A static message made up of static characters over moving characters was possible. In fact, we did not use scrolling registers. So, no need for sprites to draw the message (as long as we agree with this blocky graphics).


ECM pattern scroller (extended color mode)

ECM is used very rarely on the Commodore 64. It does have the advantage of allowing more background colors for any character cell, but it restricts the character set to only 64 different shapes.

ECM only works with hi-res characters (both ROM characters and programmable characters). To put is simple, on each character cell, dots turned on have cursor color, while dots turned off have one of the extended background colors available, that is:

  • color in register 53281 decimal for screen codes from 0 to 63 (un-shifted un-reversed characters for letters);
  • color in register 53282 decimal for screen codes from 64 to 127 (shifted un-reversed characters for letters);
  • color in register 53283 decimal for screen codes from 128 to 191 (reversed un-shifted characters for letters);
  • color in register 53284 decimal for screen codes from 192 to 255 (reversed shifted characters for letters).

Let’s try to test the ECM with direct mode commands.

To turn ECM on:

POKE 53265, 155+64

This is because standard value of this register is 155. By adding 64 we turn on bit 6 for ECM. Of course, POKE 53265,219 will work too. I chosen this form for better understanding of things.

Now, the cursor has changed color (usually, it turns red). Be sure that the cursor is over an un-shifted space. Try this command:

POKE 53283,1

Now the cursor should be white. This is because a cursor over an un-shifted space is a reversed un-shifted space.

Now you may try the following test:



This shows how ECM mode works in a hopefully simple way. Be sure to hold shift or press shift-lock while typing characters between brackets only when needed (a REM statement tells you when you have to).


ECM scrolling routine

What may be the use for scrolling of ECM? Well, with only three POKEs you can change the color of three different groups of characters on screen. In a way, you can do a very fast color cycling. And this can be quite useful to perform an ultrafast coarse scrolling of a pattern with BASIC.

The above scrolling patter routine with ECM just uses this principle. As BASIC is quite slow, color cycling is performed by PRINTing values on the color registers rather than POKEing them. This makes the program a bit more complex yet much faster.

Scrolling code is on lines 2 to 7. Notice that we have some unrolled code here to gain speed. The strings for color codes are printed without using arrays. So we have a line with PRINT “GHI”, a line with PRINT “HIG” and a line with PRINT “IGH”. We could use a string array on a loop. Code would be shorter, but array access is slower. That’s why I used this approach.

On the PRINT statements, G stays for yellow (G screen code is 7, the color code for yellow). Similarly, the remaining letters represent the other colors. Letter sequence is changed on each PRINT statement to get the color cycling.

Here, X scrolling register has been used. So, for example, on line 2 the FOR… NEXT statement performs the fine scrolling by changing the value in the scrolling register, while the PRINT statement performs the coarse scrolling of the pattern by doing a color cycling of extended color mode color registers. The same goes for lines 4 and 6.

One Reply to “C64 BASIC: ECM and MCM scrolling routines”

  1. The download link for the ECM pattern thing is a Youtube redirect link.. so it goes to Youtube and then back for no reason :).. Guessing that isn’t on purpose.

Leave a Reply

Your email address will not be published.

Commodore Banner Exchange