Drawing Pixels on the ScreenOk, 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 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! ConclusionI 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. |