Monday 15 July 2019

Adding Color RAM

Foreword

In the previous post we managed to emulate the flashing borders when the game Dan Dare loads on a C64.

Our next goal would be to display the Splash screen while the game loads. To do this we need to add some more functionality to our VIC-II core.

A fundamental block that is missing from our C64 design is color RAM, that is used to give the color for characters. Color RAM also plays an important role in rendering our Splash screen.

So, in this post we will implement color RAM and integrate it to our VIC-II core.

Defining Color RAM as Block RAM

We start off by defining some Verilog code that will synthesise our color RAM into Block RAM elements:

...
    reg [3:0] color_ram [999:0];
    reg [3:0] color_ram_out;
...
     always @ (posedge clk_1_mhz)
       begin
        if (color_ram_write_enable) 
        begin
         color_ram[addr[9:0]] <= ram_in[3:0];
         color_ram_out <= ram_in[3:0];
        end
        else 
        begin
         color_ram_out <= color_ram[addr[9:0]];
        end 
       end 
...

We directly connect to the Data Out pin of our CPU via the ram_in wire.

Since the Color RAM only contain a thousand items, we only need to connect the lowest 10 bits of the address bus. This makes it crucial to only enable writing within the correct address range:

assign color_ram_write_enable = we & (addr >= 16'hd800 & addr < 16'hdbe8);

Next, we should add  second port to our Color RAM for providing information to our VIC-II module:

...
    reg [3:0] color_ram_out2;
...
    always @ (posedge clk_2_mhz)
       begin
         color_ram_out2 <= color_ram[portb_add[9:0]]; 
       end 
...

Finally we need to hook up to the VIC-II module:

vic_ii vic_inst
    (
...
        .data_in({color_ram_out2,vic_combined_d}),
...
        );

The data in bus to a VIC-II is 12 bits wide and the upper 4 bits contains the color information.

Test Results

I did a quick test to see if our C64 module can render the colors stored in Color RAM correctly.

For this exercise I run a couple of POKE commands to write color values directly to COLOR RAM.

The results are as follows:


In Summary

In this post we have added COLOR RAM to our C64 design and verified that our VIC-II module render the colors correctly.

In the next post we will continue to add more functionality to our VIC-II module in order to display the splash screen.

Till next time!

No comments:

Post a Comment