• # Making Games For The Dreamcast Using Standard GNU Tools Part II: Putting Graphics On The Screen

General and Gameplay Programming

[b] 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.[/b]

[size="5"][b]Introduction[/b][/size]

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.

[size="3"][b]What you need to do before we start[/b][/size]

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.

[size="5"][b]Dreamcast Hardware[/b][/size]

Here's a quick overview of the Dreamcast hardware.

[b]Note:[/b] [i]You will need either [url="http://www.allusion.net/dcdev/softprj/libdream-0.71.tar.gz"]libdream 0.71[/url] or [url="http://www.allusion.net/dcdev/softprj/kallistios-0.6.tar.gz"]KallistiOS 0.6[/url] installed first. Instructions are found in the archive.[/i]

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 [i]Tile Accelerator[/i] 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.

[size="3"][b]Color Modes[/b][/size]

[font="Courier New"]RGB555[nbsp][nbsp][nbsp][nbsp][/font]2[nbsp]Bytes[nbsp](16-bit[nbsp]Color[nbsp]Depth)
[font="Courier New"]RGB565[nbsp][nbsp][nbsp][nbsp][/font]2[nbsp]Bytes[nbsp](16-bit[nbsp]Color[nbsp]Depth)
[font="Courier New"]ARGB4444[nbsp][nbsp][/font]2[nbsp]Bytes[nbsp](16-bit[nbsp]Color[nbsp]Depth)
[font="Courier New"]RGB888[nbsp][nbsp][nbsp][nbsp][/font]4[nbsp]Bytes[nbsp](32-bit[nbsp]Color[nbsp]Depth)
[font="Courier New"]ARGB888[nbsp][nbsp][nbsp][/font]4[nbsp]Bytes[nbsp](32-bit[nbsp]Color[nbsp]Depth)

[size="3"][b]Resolutions List[/b][/size]
[b]
Note:[/b] [i]This list is not complete because these are the only ones supported right now.[/i]

320x240x16
640x480x16
640x480x32

[b]Base Address of the frame buffer is[/b] 0xA5000000

[b]Base Address of the PowerVR chips is[/b] 0xA05F8000

[size="3"][b]What the Heck is RGBXXX?[/b][/size]

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.

[size="3"][b]How Do I Convert RGB5XX into a 16-bit number?[/b][/size]

[indent][code]#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)[/code][/indent]
[size="5"][b]Drawing Pixels on the Screen[/b][/size]

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.

[size="3"][b]Example Pseudo code:[/b][/size]

[indent][code]unsigned short * vram_s = (unsigned short *)0xA5000000;

// vram_s[x + (640*y) ] = 16bit Color
vram_s[100 + (640*50)] = RGB565(255,0,0);[/code][/indent] 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.

[indent][code]// 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;
}[/code][/indent] [size="3"][b]Sample Makefile:[/b][/size]

[indent][code]# 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.

TARGET=sh-elf
DCBASE=/usr/local/dc/$(TARGET) CC=$(DCBASE)/bin/$(TARGET)-gcc -ml -O -m4-single-only -Wall LD=$(DCBASE)/bin/$(TARGET)-ld AS=$(DCBASE)/bin/$(TARGET)-as AR=$(DCBASE)/bin/$(TARGET)-ar OBJCOPY=$(DCBASE)/bin/$(TARGET)-objcopy # !!!! Edit These Lines !!!! Change to program name #BIN = test #OBJS = test.o INCS=-I../../include 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$@

clean:
-rm -f *.o *.elf 1ST_READ.BIN *.bck \$(EXTRA_CLEAN)

reallyclean: clean

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!

[size="5"][b]Conclusion[/b][/size]

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.

Report Article

## User Feedback

You need to be a member in order to leave a review

## Create an account

Register a new account