Adding some color to that mess

OK back to business. Here is a short addition to the previous “character stars” program that adds some random colors to it. The new file can be downloaded here. As before, the file suffix has been changed to fool WordPress. The file is plain ascii asm code.

So what has changed to the previous routine you ask anxiously. Not much actually. First we add some new hard-coded memory locations to the routine just like we did with the screen memory. This is the memory area that defines the color of a specific location on the screen. $D800 (55296) is the address where the color memory starts by default.


SCRMEM1 .byte $00, $04, $FF, $04, $FE, $05, $FF, $06 ; screen memory
COLMEM1 .byte $00, $D8, $FF, $D8, $FE, $D9, $FF, $DA ; color memory

Then we modify the TRANSFER routine so that we take up (to zero page addresses $BD & $BE) the screen color address for the same screen location we randomly chose to draw our character to:


TRANSFER1
    CLC
    ROL    ; get correct screen memory location
    TAY
    LDA    SCRMEM1,Y    ;first half of screen address
    STA    $BB
    LDA    COLMEM1,Y    ; first half of color address
    STA    $BD
    INY
    LDA    SCRMEM1,Y    ; second half of screen address
    STA    $BC
    LDA    COLMEM1,Y    ; second half of color address
    STA    $BE
    JSR    TAILPART

And finally we add some new lines to the DRAW routine that will eventually draw the character on the screen:


DRAW
    STA    ($BB),Y    ; print character
    JSR    RNDBYT
    AND    #$0F    ; scale to 0-15
    STA    ($BD),Y    ; store value to color memory
    RTS

What next?
I have been looking at cc65 a C-crosscompiler that can generate code for Commodore64. I am most likely to go on creating a simple game using sprites and character graphics either with C or assembly. I am also looking at how to generate high resolution (300×200 pixels) graphics in assembler, but that may take a while. I may also expand this blog to cover some of my beginner electronics projects such as this.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.