• Create Account

Like
1Likes
Dislike

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

By Kevin Fowlks | Published May 15 2001 03:49 AM in Game Programming

 If you find this article contains errors or problems rendering it unreadable (missing images or files, mangled code, improper text formatting, etc) please contact the editor so corrections can be made. Thank you for helping us improve this resource

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.

Introduction

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

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.

320x240x16
640x480x16
640x480x32

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.

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
-rm -f *.bin *.srec

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!

Conclusion

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.