Screen full of garbace, the C version

I perhaps did not mention, but I am using DASM for compiling assembler code and cc65 for C code. Below is the the C equivalent of the previous routine.


#include "stdio.h"
#include "stdlib.h"

#define SCREENMEM 0x0400
#define COLORMEM 0xD800
#define RASTER 0xD012
#define KEYBOARDMEM 0xDC01

#define POKE(addr,val) (*(addr) = (val))
#define PEEK(addr) (*(addr))

int main(void) {
    int loc = 0;
    char ch = 0;
    char col = 0;
    _randomize();
    while(1)
    {
        if(PEEK((char*)RASTER) == 0x80)
        {
            loc = rand() % 1024;
            ch = PEEK((char*)(SCREENMEM+loc));
            if(ch == 0x51)
                ch = 0x57;
            else if(ch == 0x57)
                ch = 0x20;
            else if(ch == 0x2A)
                ch = 0x51;
            else
                ch = 0x2A;
            col = rand() % 16;

            POKE((char *)(SCREENMEM + loc), ch);
            POKE((char *)(COLORMEM + loc), col);
        }
        if(PEEK((char*)KEYBOARDMEM) == 0xEF)
            break;
    }
    return EXIT_SUCCESS;
}

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.