Making Games For The Dreamcast Using Standard GNU Tools
Part II: Putting Graphics On The Screen
by Kevin Fowlks

Disclaimer: Please be aware that all information is provided as-is, and may be used at your own risk. "Sega" and "Dreamcast" are trademarks of Sega Enterprises. All information here has derived from my own experience. Nothing in this document is under any type of NDA nor does it include any information from the official dreamcast development kit.


In Part I we talked about what you need in order to start developing Dreamcast programs. Assuming now that you have your Dreamcast development system up and running, itís time to get started doing some really cool stuff, like drawing graphics on the screen. So without further ado let's get started.

What you need to do before we start

You are going to need to download and install libdream 0.71 or KOS 0.6. Please READ the libdream.txt before you get started!!!

This is a simple guide to get you started in DC programming it is by no means complete.

The goal of this series is to get experienced game programmers into Dreamcast coding thus it is missing all those nice hand-holding beginnerís steps.

Dreamcast Hardware

Hereís a quick overview of the dreamcast hardware.

Note: You will need either libdream 0.71 or KallistiOS 0.6 installed first. Instructions are found in the archive.

The Dreamcast is a nice, cleanly designed beast that has a total of 8 megs of video memory. Now that may not seem like that much but itís more then enough to create great looking programs. The Dreamcast comes with a TA or a Tile Accelerator provided by NEC's PowerVR chip. The TA gives the Dreamcast all that 3D power that weíre used to. For now, we're not going to use the TA, we're just going to use the video memory as a large frame buffer.

Since we're using libdream we donít really need know every thing about the Dreamcast in order to get things done. However, I believe that youíll learn more about the Dreamcast as time goes on and you continue to program for this amazing system. So hereís a basic rundown of what we have to work with hardware-wise.

Color Modes

RGB555 2 Bytes (16-bit Color Depth)
RGB565 2 Bytes (16-bit Color Depth)
ARGB4444    2 Bytes (16-bit Color Depth)
RGB888 4 Bytes (32-bit Color Depth)
ARGB888 4 Bytes (32-bit Color Depth)

Resolutions List

Note: This list is not complete because these are the only ones supported right now.


Base Address of the frame buffer is 0xA5000000

Base Address of the PowerVR chips is 0xA05F8000

What the Heck is RGBXXX?

Well, the 565 in RGB565 represents the number of bits used to store each color component. The red and blue components are stored with 5 bits and the green component is stored with 6 bits.

How Do I Convert RGB5XX into a 16-bit number?

#define RGB565(r, g, b) ((r >> 3) << 11)| ((g >> 2) << 5)| ((b >> 3) << 0)
#define RGB555(r, g, b) ((r >> 3) << 10)| ((g >> 3) << 5)| ((b >> 3) << 0)

Drawing Pixels on the Screen

Ok, believe it or not we now have enough info to draw graphics on the screen. Now those of you that remember the old school DOS mode13 stuff should know what Iím talking about. First what we do is setup a pointer to our frame buffer using the same size that we intend to access. So if we're going to use RGB565 or RGB555 then you would use a unsigned short.

Example Pseudo code:

unsigned short * vram_s = (unsigned short *)0xA5000000;

// vram_s[x + (640*y) ] =  16bit Color
vram_s[100 + (640*50)] =  RGB565(255,0,0);

The above example plots a red pixel at position (100, 50) on the screen.

Hereís a real program that does the above that you can compile and use.

// Look No stdio.h or malloc.h

#include "dream.h"

#define RGB565(r, g, b) ((r >> 3) << 11)| ((g >> 2) << 5)| ((b >> 3) << 0)

int dc_main() { int x=100, y=50;

dc_setup_quiet(DM_640x480, PM_RGB565); vram_s[x + (640*y)] = RGB565(255,0,0); return 0; }

Sample Makefile:

# Generic Makefile for DC Coding with libdream 
# Edit this configuration to match your system. Currently every one of
# these but LD is used directly, but you might as well be complete.
CC=$(DCBASE)/bin/$(TARGET)-gcc -ml -O -m4-single-only -Wall
# !!!! Edit These Lines !!!! Change to program name
#BIN = test
#OBJS = test.o
LIBS=-L../../lib -ldream
all: $(BIN).srec 
$(BIN).srec: $(BIN).elf
            $(OBJCOPY) -O srec $(BIN).elf $(BIN).srec
$(BIN).bin: $(BIN).elf
            $(OBJCOPY) -O binary $(BIN).elf $(BIN).bin
$(BIN).elf: $(OBJS)
            $(CC) -Wl,-Ttext,0x8c010000 -o $(BIN).elf $(OBJS) $(LIBS)
%.o: %.c
            $(CC) $(INCS) -c $< -o $@
            -rm -f *.o *.elf 1ST_READ.BIN *.bck $(EXTRA_CLEAN)
reallyclean: clean
            -rm -f *.bin *.srec

You're now ready to upload your srec to your Dreamcast. Happy Coding!!!!

Added Note:

Remember that since we donít have a real C library to use we have to either build our own or use libs like libdream. So start trying to do crazy things like including malloc.h or conio.h!


I think that everyone would agree that Dreamcast Programming is really not that hard, thanks to all those super coders that discovered all of those neat things you could do with the Dreamcast. Now you can write your own line and circle functions and you can now copy image data to display pictures. Look out for Part III where we're going to talk about using the TA to render 3D stuff.

Discuss this article in the forums

Date this article was posted to 5/15/2001
(Note that this date does not necessarily correspond to the date the article was written)

See Also:

© 1999-2011 All rights reserved. Terms of Use Privacy Policy
Comments? Questions? Feedback? Click here!