KOS and SDL

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
User avatar
Memorix101
DCEmu Cool Newbie
DCEmu Cool Newbie
Posts: 13
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Thu Apr 21, 2016 7:03 am
Has thanked: 3 times
Been thanked: 0
Contact:

KOS and SDL

Post by Memorix101 »

Hey dudes :)

Getting SDL working on DC isn't that easy :/
I searched through the forum for old threads to spot the mistake I made, but couldn't find anything that solved my issue :(

First up my setup is KOS 2.0 and I'm using the SDL that came with it.
I think my issue is the romdisk thing.

I wrote sample cpp to test it before I wanted to port my SDL game over to DC.

When I run the code on the DC it's caught in an endless looped bootscreen. :(

So my code is:

Code: Select all

#include <kos.h>
#include <stdio.h>
#include <SDL.h>
#include <SDL_dreamcast.h>

extern uint8 romdisk[];
KOS_INIT_ROMDISK(romdisk);

int main() {

   puts("\n\n * SDL Project");

       SDL_Surface * screen;
       SDL_Surface * image;
       Uint32 flags = SDL_HWSURFACE;
       
       SDL_Init(SDL_INIT_VIDEO);

       screen = SDL_SetVideoMode(320, 240, 16, flags);

       // Load BMP using SDL SDL_LoadBMP
       image  = SDL_LoadBMP("/rd/main_theme_2.bmp");
       
       // Load JPG using SDL_image
       // image  = IMG_Load("image.jpg");
       
       // Puting image on the screen up
       while(1){

       SDL_BlitSurface(image, NULL, screen, NULL);
       SDL_Flip(screen);
       //SDL_Delay(10000);

       }
   
      return 0;
}
My makefile looks this:

Code: Select all

all: rm-elf game.elf

include $(KOS_BASE)/Makefile.rules

OBJS = game.o

KOS_LOCAL_CFLAGS = -I$(KOS_BASE)/addons/zlib
	
clean:
	-rm -f game.elf $(OBJS)
	-rm -f romdisk.*

dist:
	-rm -f $(OBJS)
	-rm -f romdisk.*
	$(KOS_STRIP) game.elf
	
rm-elf:
	-rm -f game.elf
	-rm -f romdisk.*

game.elf: $(OBJS) romdisk.o 
	$(KOS_CC) $(KOS_CFLAGS) $(KOS_LDFLAGS) -o $@ $(KOS_START) $^ -lSDL -lz -lm $(KOS_LIBS)

romdisk.img:
	$(KOS_GENROMFS) -f $@ -d romdisk -v

romdisk.o: romdisk.img
	$(KOS_BASE)/utils/bin2o/bin2o $< romdisk $@

run: game.elf
	$(KOS_LOADER) $<
Memorix :)
tonma
DCEmu Freak
DCEmu Freak
Posts: 82
Joined: Thu Mar 10, 2016 7:14 am
Has thanked: 0
Been thanked: 1 time

Re: KOS and SDL

Post by tonma »

Do you try to add to your flags : SDL_FULLSCREEN | SDL_DOUBLEBUF

And to test if you think that come from the romdisk : if (!image) printf("erreur");

if (SDL_Init(SDL_INIT_VIDEO) < 0) printf("erreur init");
User avatar
Memorix101
DCEmu Cool Newbie
DCEmu Cool Newbie
Posts: 13
Joined: Thu Apr 21, 2016 7:03 am
Has thanked: 3 times
Been thanked: 0
Contact:

Re: KOS and SDL

Post by Memorix101 »

It works now :) Thanks.

Does anybody know a good way to get SDL_image to work ? I tried to use the SDL port by Chui, but it only makes errors :/
Should I post them for you ?

Code: Select all

ns/dc/kos/addons/lib/dreamcast -L/opt/toolchains/dc/kos/../kos-ports/lib -o game.elf  game.o romdisk.o -lSDL -lSDL_image_124 -lz -lm -Wl,--start-group -lkallisti -lc -lgcc -Wl,--end-group
/opt/toolchains/dc/kos/addons/lib/dreamcast/libSDL_image_124.a(IMG.o): In function `IMG_Load':
/opt/dc/kos-ports/SDL_image-1.2.4/IMG.c:75: undefined reference to `_SDL_RWFromFile'
/opt/toolchains/dc/kos/addons/lib/dreamcast/libSDL_image_124.a(IMG_bmp.o): In function `IMG_LoadBMP_RW':
/opt/dc/kos-ports/SDL_image-1.2.4/IMG_bmp.c:238: undefined reference to `_SDL_ReadLE32'
/opt/dc/kos-ports/SDL_image-1.2.4/IMG_bmp.c:238: undefined reference to `_SDL_ReadLE16'
/opt/toolchains/dc/kos/addons/lib/dreamcast/libSDL_image_124.a(IMG_png.o): In function `IMG_isPNG':
/opt/dc/kos-ports/SDL_image-1.2.4/IMG_png.c:87: undefined reference to `_png_sig_cmp'
/opt/toolchains/dc/kos/addons/lib/dreamcast/libSDL_image_124.a(IMG_png.o): In function `png_read_data':
/opt/dc/kos-ports/SDL_image-1.2.4/IMG_png.c:96: undefined reference to `_png_get_io_ptr'
/opt/toolchains/dc/kos/addons/lib/dreamcast/libSDL_image_124.a(IMG_png.o): In function `IMG_LoadPNG_RW':
/opt/dc/kos-ports/SDL_image-1.2.4/IMG_png.c:164: undefined reference to `_png_create_read_struct'
/opt/dc/kos-ports/SDL_image-1.2.4/IMG_png.c:164: undefined reference to `_png_create_info_struct'
/opt/dc/kos-ports/SDL_image-1.2.4/IMG_png.c:164: undefined reference to `_png_set_read_fn'
/opt/dc/kos-ports/SDL_image-1.2.4/IMG_png.c:164: undefined reference to `_png_read_info'
/opt/dc/kos-ports/SDL_image-1.2.4/IMG_png.c:164: undefined reference to `_png_get_IHDR'
/opt/dc/kos-ports/SDL_image-1.2.4/IMG_png.c:164: undefined reference to `_png_set_strip_16'
/opt/dc/kos-ports/SDL_image-1.2.4/IMG_png.c:164: undefined reference to `_png_set_packing'
/opt/dc/kos-ports/SDL_image-1.2.4/IMG_png.c:164: undefined reference to `_png_get_valid'
/opt/dc/kos-ports/SDL_image-1.2.4/IMG_png.c:164: undefined reference to `_png_read_update_info'
/opt/dc/kos-ports/SDL_image-1.2.4/IMG_png.c:164: undefined reference to `_png_read_image'
/opt/dc/kos-ports/SDL_image-1.2.4/IMG_png.c:164: undefined reference to `_png_destroy_read_struct'
/opt/dc/kos-ports/SDL_image-1.2.4/IMG_png.c:164: undefined reference to `_png_get_tRNS'
/opt/dc/kos-ports/SDL_image-1.2.4/IMG_png.c:164: undefined reference to `_png_set_expand'
/opt/dc/kos-ports/SDL_image-1.2.4/IMG_png.c:189: undefined reference to `_png_set_gray_to_rgb'
/opt/dc/kos-ports/SDL_image-1.2.4/IMG_png.c:189: undefined reference to `_png_set_expand'
/opt/toolchains/dc/kos/addons/lib/dreamcast/libSDL_image_124.a(IMG_xcf.o): In function `xcf_read_property':
/opt/dc/kos-ports/SDL_image-1.2.4/IMG_xcf.c:259: undefined reference to `_SDL_ReadBE32'
/opt/toolchains/dc/kos/addons/lib/dreamcast/libSDL_image_124.a(IMG_xcf.o): In function `read_xcf_header':
/opt/dc/kos-ports/SDL_image-1.2.4/IMG_xcf.c:319: undefined reference to `_SDL_ReadBE32'
/opt/toolchains/dc/kos/addons/lib/dreamcast/libSDL_image_124.a(IMG_xcf.o): In function `read_xcf_layer':
/opt/dc/kos-ports/SDL_image-1.2.4/IMG_xcf.c:348: undefined reference to `_SDL_ReadBE32'
/opt/toolchains/dc/kos/addons/lib/dreamcast/libSDL_image_124.a(IMG_xcf.o): In function `read_xcf_channel':
/opt/dc/kos-ports/SDL_image-1.2.4/IMG_xcf.c:376: undefined reference to `_SDL_ReadBE32'
/opt/toolchains/dc/kos/addons/lib/dreamcast/libSDL_image_124.a(IMG_xcf.o): In function `read_xcf_hierarchy':
/opt/dc/kos-ports/SDL_image-1.2.4/IMG_xcf.c:423: undefined reference to `_SDL_ReadBE32'
/opt/toolchains/dc/kos/addons/lib/dreamcast/libSDL_image_124.a(IMG_xcf.o):/opt/dc/kos-ports/SDL_image-1.2.4/IMG_xcf.c:446: more undefined references to `_SDL_ReadBE32' follow
collect2: error: ld returned 1 exit status
Makefile:23: recipe for target 'game.elf' failed
make: *** [game.elf] Error 1
User avatar
Memorix101
DCEmu Cool Newbie
DCEmu Cool Newbie
Posts: 13
Joined: Thu Apr 21, 2016 7:03 am
Has thanked: 3 times
Been thanked: 0
Contact:

Re: KOS and SDL

Post by Memorix101 »

I tried building SDL image myself ... still getting errors.

edit:
The errors are occurring because of`sdl-config --libs` but I need that for Image :/

Image

Code: Select all

all: rm-elf game.elf

include $(KOS_BASE)/Makefile.rules

OBJS = game.o

KOS_LOCAL_CFLAGS = -I$(KOS_BASE)/addons/zlib
	
clean:
	-rm -f game.elf $(OBJS)
	-rm -f romdisk.*

dist:
	-rm -f $(OBJS)
	-rm -f romdisk.*
	$(KOS_STRIP) game.elf
	
rm-elf:
	-rm -f game.elf
	-rm -f romdisk.*

game.elf: $(OBJS) romdisk.o 
	$(KOS_CC) $(KOS_CFLAGS) $(KOS_LDFLAGS) -o $@ $(KOS_START) $^ -lSDL `sdl-config --libs` -lSDL_image -lz -lm $(KOS_LIBS)

romdisk.img:
	$(KOS_GENROMFS) -f $@ -d romdisk -v

romdisk.o: romdisk.img
	$(KOS_BASE)/utils/bin2o/bin2o $< romdisk $@

run: game.elf
	$(KOS_LOADER) $<
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: KOS and SDL

Post by BlueCrab »

sdl_config will be referring to the one for your host system, not on the Dreamcast. The only library you have to link on the Dreamcast side is -lSDL.

SDL_Image probably requires -lpng and -ljpeg to be linked in, although if you're using Chui's stuff, I honestly have no idea.

Finally, not to discourage you or anything, but SDL on the Dreamcast is... well, really bad. The performance is horrible, because SDL1 isn't really designed for doing anything with a GPU. Framebuffer reads/writes are slow on the Dreamcast, so pretty much all blitting is very slow -- especially if there's alpha values involved.
Post Reply