ED64 - HOW TO WRITE A COMMODORE 64 EMULATOR
By ir. Marc Dendooven


Chapter 9: The VIC – part 2 : color.

  1. Introduction

    In the previous chapter we adapted the memory access of the VIC. Now we will add color.

  2. Emulating color ram

    The color ram is a 1K nibble (4 bits) memory. Although it is an independent memory chip, we will place it in the vic unit, since the vic uses it intensively:

    color_ram : array[$D800..$DBFF] of nibble;

    We also provide two access methods :

procedure colorWrite(address : word; color : nibble);
begin
    color_ram[address] := color;
end;

function colorRead(address : word) : nibble;
begin
    colorRead := color_ram[address]
end;

    Since the color ram appears in the io section of the memory map, these access methods are called the usual way from ioIn and ioOut.

  1. Using the color ram

    Now we can use color in vicText:

procedure vicText(pos: word; val: byte);
...
    if ...
        then setPixel(x0+x,y0+y,color_ram[$D800+pos])
        else setPixel(x0+x,y0+y,reg[$D021])
end;

    backgroundcolor can be found in VIC register $D021.

    Now text is displayed in the right color. But what if someone alters the color whit out writing to the text area? We can intercept this by rewriting the text in the color write method:

procedure colorWrite(address : word; color : nibble);
begin
    color_ram[address] := color;
    vicText(address-$D800,peek( address-$D800+bankAddress+screenAddress))
end;

    This is not efficient since most writes to the screen will be doubled that way. But it works.

  1. Conclusion
    Now we have color in our textmode. In the next chapter we will provide other vic modes : Hi resolution and multicolor modes.
    See listing in memio.pas and vic.pas