How to set SDL in KOS?

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
NeoSnk
DCEmu Cool Newbie
DCEmu Cool Newbie
Posts: 13
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Sat Sep 17, 2016 6:39 am
Has thanked: 0
Been thanked: 0

How to set SDL in KOS?

Post by NeoSnk »

Hi guys, I've developed a game for PC using SDL. I want to port it for DC, however I have some problems setting SDL in KOS...

First I went to Chui's website: http://chui.dcemu.co.uk/sdl.html and I downloaded the Precompiled Libraries and Headers
and put the files in addons like the instructions ask to do.

Then I downloaded the examples, however when I try to run make on the examples I have errors with the elf files.

Here are my errors:

For the framerate example:

Code: Select all

/opt/toolchains/dc/sh-elf/bin/sh-elf-gcc -O2 -fomit-frame-pointer -ml -m4-single-only -ffunction-sections -fdata-sections  -I/opt/toolchains/dc/kos/include -I/opt/toolchains/dc/kos/kernel/arch/dreamcast/include -I/opt/toolchains/dc/kos/addons/include -I/opt/toolchains/dc/kos/../kos-ports/include -D_arch_dreamcast -D_arch_sub_pristine -Wall -g -fno-builtin -fno-strict-aliasing -I/opt/toolchains/dc/kos/addons/include -I/opt/toolchains/dc/kos/addons/include/SDL -O3 -fomit-frame-pointer -DDREAMCAST   -ml -m4-single-only -Wl,-Ttext=0x8c010000 -Wl,--gc-sections -T/opt/toolchains/dc/kos/utils/ldscripts/shlelf.xc -nodefaultlibs -L/opt/toolchains/dc/kos/lib/dreamcast -L/opt/toolchains/dc/kos/addons/lib/dreamcast -L/opt/toolchains/dc/kos/../kos-ports/lib -o framerate.elf  \
framerate.o -lSDL_gfx -lSDL_129 -lm  -Wl,--start-group -lkallisti -lc -lgcc -Wl,--end-group
/opt/toolchains/dc/kos/addons/lib/dreamcast/libSDL_129.a(SDL_systhread.o): In function `SDL_SYS_WaitThread':
/opt/dc/kos-ports/SDL-1.2.9/src/thread/dc/SDL_systhread.c:93: undefined reference to `_thd_wait'
/opt/toolchains/dc/kos/addons/lib/dreamcast/libSDL_129.a(SDL_sysjoystick.o): In function `SDL_SYS_JoystickInit':
/opt/dc/kos-ports/SDL-1.2.9/src/joystick/dc/SDL_sysjoystick.c:131: undefined reference to `_maple_device_func'
/opt/dc/kos-ports/SDL-1.2.9/src/joystick/dc/SDL_sysjoystick.c:131: undefined reference to `_maple_first_kb'
/opt/dc/kos-ports/SDL-1.2.9/src/joystick/dc/SDL_sysjoystick.c:131: undefined reference to `_maple_first_mouse'
/opt/toolchains/dc/kos/addons/lib/dreamcast/libSDL_129.a(SDL_sysjoystick.o): In function `SDL_SYS_JoystickName':
/opt/dc/kos-ports/SDL-1.2.9/src/joystick/dc/SDL_sysjoystick.c:140: undefined reference to `_maple_compat_resolve'
/opt/toolchains/dc/kos/addons/lib/dreamcast/libSDL_129.a(SDL_sysjoystick.o): In function `joyUpdate':
/opt/dc/kos-ports/SDL-1.2.9/src/joystick/dc/SDL_sysjoystick.c:219: undefined reference to `_cont_get_cond'
/opt/toolchains/dc/kos/addons/lib/dreamcast/libSDL_129.a(SDL_dcvideo.o): In function `__ask_60hz_wait':
/opt/dc/kos-ports/SDL-1.2.9/src/video/dc/60hz.h:771: undefined reference to `_maple_device_func'
/opt/dc/kos-ports/SDL-1.2.9/src/video/dc/60hz.h:771: undefined reference to `_cont_get_cond'
/opt/toolchains/dc/kos/addons/lib/dreamcast/libSDL_129.a(SDL_dcevents.o): In function `DC_PumpEvents':
/opt/dc/kos-ports/SDL-1.2.9/src/video/dc/SDL_dcevents.c:104: undefined reference to `_maple_first_kb'
/opt/dc/kos-ports/SDL-1.2.9/src/video/dc/SDL_dcevents.c:104: undefined reference to `_maple_first_mouse'
/opt/dc/kos-ports/SDL-1.2.9/src/video/dc/SDL_dcevents.c:104: undefined reference to `_mouse_get_cond'
collect2: error: ld returned 1 exit status
Makefile:19: recipe for target 'framerate.elf' failed
make: *** [framerate.elf] Error 1
For the font example:

Code: Select all

/opt/toolchains/dc/sh-elf/bin/sh-elf-gcc -O2 -fomit-frame-pointer -ml -m4-single-only -ffunction-sections -fdata-sections  -I/opt/toolchains/dc/kos/include -I/opt/toolchains/dc/kos/kernel/arch/dreamcast/include -I/opt/toolchains/dc/kos/addons/include -I/opt/toolchains/dc/kos/../kos-ports/include -D_arch_dreamcast -D_arch_sub_pristine -Wall -g -fno-builtin -fno-strict-aliasing -I/opt/toolchains/dc/kos/addons/include -I/opt/toolchains/dc/kos/addons/include/SDL  -O3 -fomit-frame-pointer -DDREAMCAST   -ml -m4-single-only -Wl,-Ttext=0x8c010000 -Wl,--gc-sections -T/opt/toolchains/dc/kos/utils/ldscripts/shlelf.xc -nodefaultlibs -L/opt/toolchains/dc/kos/lib/dreamcast -L/opt/toolchains/dc/kos/addons/lib/dreamcast -L/opt/toolchains/dc/kos/../kos-ports/lib -o fonts.elf  \
fonts.o -lSDL_gfx -lSDL_129 -lm  -Wl,--start-group -lkallisti -lc -lgcc -Wl,--end-group
/opt/toolchains/dc/kos/addons/lib/dreamcast/libSDL_129.a(SDL_systhread.o): In function `SDL_SYS_WaitThread':
/opt/dc/kos-ports/SDL-1.2.9/src/thread/dc/SDL_systhread.c:93: undefined reference to `_thd_wait'
/opt/toolchains/dc/kos/addons/lib/dreamcast/libSDL_129.a(SDL_sysjoystick.o): In function `SDL_SYS_JoystickInit':
/opt/dc/kos-ports/SDL-1.2.9/src/joystick/dc/SDL_sysjoystick.c:131: undefined reference to `_maple_device_func'
/opt/dc/kos-ports/SDL-1.2.9/src/joystick/dc/SDL_sysjoystick.c:131: undefined reference to `_maple_first_kb'
/opt/dc/kos-ports/SDL-1.2.9/src/joystick/dc/SDL_sysjoystick.c:131: undefined reference to `_maple_first_mouse'
/opt/toolchains/dc/kos/addons/lib/dreamcast/libSDL_129.a(SDL_sysjoystick.o): In function `SDL_SYS_JoystickName':
/opt/dc/kos-ports/SDL-1.2.9/src/joystick/dc/SDL_sysjoystick.c:140: undefined reference to `_maple_compat_resolve'
/opt/toolchains/dc/kos/addons/lib/dreamcast/libSDL_129.a(SDL_sysjoystick.o): In function `joyUpdate':
/opt/dc/kos-ports/SDL-1.2.9/src/joystick/dc/SDL_sysjoystick.c:219: undefined reference to `_cont_get_cond'
/opt/toolchains/dc/kos/addons/lib/dreamcast/libSDL_129.a(SDL_dcvideo.o): In function `__ask_60hz_wait':
/opt/dc/kos-ports/SDL-1.2.9/src/video/dc/60hz.h:771: undefined reference to `_maple_device_func'
/opt/dc/kos-ports/SDL-1.2.9/src/video/dc/60hz.h:771: undefined reference to `_cont_get_cond'
/opt/toolchains/dc/kos/addons/lib/dreamcast/libSDL_129.a(SDL_dcevents.o): In function `DC_PumpEvents':
/opt/dc/kos-ports/SDL-1.2.9/src/video/dc/SDL_dcevents.c:104: undefined reference to `_maple_first_kb'
/opt/dc/kos-ports/SDL-1.2.9/src/video/dc/SDL_dcevents.c:104: undefined reference to `_maple_first_mouse'
/opt/dc/kos-ports/SDL-1.2.9/src/video/dc/SDL_dcevents.c:104: undefined reference to `_mouse_get_cond'
collect2: error: ld returned 1 exit status
Makefile:19: recipe for target 'fonts.elf' failed
make: *** [fonts.elf] Error 1
Could you guys explain me how to set it in the correct way? Thank you so much.
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5652
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: How to set SDL in KOS?

Post by BlueCrab »

Chui's SDL will not work, as it is using function calls that have been deprecated (and removed) from KOS. That is to say, it is old and very out of date. Without a bunch of updates to the source code, it's not going to work.

There is a version of SDL included in kos-ports that is much more up-to-date.

However, it is worth noting that SDL on the Dreamcast is basically junk. It is slow, leaks memory, and just generally does not work the way that one might expect. I would not recommend using it for anything, unless you really just want a super-quick port of something that already uses SDL (as a stepping stone to porting it properly without SDL).

SDL 1.x is designed as a simple framebuffer blitting system, which does not mesh well with the Dreamcast's hardware. SDL 2.x basically requires video hardware functionality that is much newer than what the Dreamcast provides (really, it's not SDL itself, but rather the stuff using it), and thus would be a pain to use even if you did have a port of the library itself.
User avatar
bogglez
Moderator
Moderator
Posts: 578
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Re: How to set SDL in KOS?

Post by bogglez »

I agree with BlueCrab. Some things to consider:

Are you just using SDL to create an OpenGL context, pretty much? In that case it shouldn't be a big deal to just remove it. The OpenGL context on KOS is already set up, check kos/examples/kgl.

Using SDL for input? Asking for gamepad state on KOS is very simple (no external libraries etc), check the kos/examples folder out and look at the main loops.

Do you write to the framebuffer directly and just use SDL to flip the framebuffer? While writing to the framebuffer directly is too slow, as BlueCrab mentioned, I was able to make it fast enough for simple stuff by having a framebuffer double buffer in memory (u16 framebuffers[2][640*480]), writing to one of those, doing an asynchronous DMA copy to the screen, while writing to the other buffer. The better solution is to use the PVR chip, however.

I don't know about the SDL networking and sound library.
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5652
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: How to set SDL in KOS?

Post by BlueCrab »

bogglez wrote:I don't know about the SDL networking and sound library.
SDL 1.x does not have any built-in networking. The SDL_net library (an extra library you'd need), is just a very thin wrapper around standard BSD sockets, which KOS supports.

Sound-wise, the base SDL sound system is very similar to what KOS has already between the snd_sfx and snd_stream stuff, albeit a lot more limited than what KOS allows you to do. There's also SDL_mixer (another external library), but that basically just adds support for playing MP3s and other such files, which KOS already provides libraries for anyway.
NeoSnk
DCEmu Cool Newbie
DCEmu Cool Newbie
Posts: 13
Joined: Sat Sep 17, 2016 6:39 am
Has thanked: 0
Been thanked: 0

Re: How to set SDL in KOS?

Post by NeoSnk »

Wow, I didn't know SDL for DC was so bad =/ I thought it was good after seeing a Zelda game written on it!

My game is a very simple 2d platform. I had written it in BennuGD for Dreamcast before. However when I started to add things on it the performance started to be really bad... Then I wrote everything again in SDL for PC and I thought it would run well on DC haha big mistake, but at least I learned something new.

What you guys recommend then? Thank you for all the attention guys and I'm sorry for all the questions. I'm very newbie on the Dreamcast. But I wish to get my game running on it.
User avatar
bogglez
Moderator
Moderator
Posts: 578
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Re: How to set SDL in KOS?

Post by bogglez »

Even if you say you're using sdl that doesn't say much about how you're drawing. Are you using opengl or software blitting?
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5652
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: How to set SDL in KOS?

Post by BlueCrab »

NeoSnk wrote:What you guys recommend then? Thank you for all the attention guys and I'm sorry for all the questions. I'm very newbie on the Dreamcast. But I wish to get my game running on it.
If you're using SDL, you must be at least somewhat comfortable with C or C++, right?

To be honest for 2D stuff, you'd probably be best off either using libparallax (or libtsunami if you want C++ classes for things) or just going at the PVR directly, depending on what you're doing. libparallax is just a very thin wrapper around the PVR functionality (and libtsunami is a relatively thin wrapper around libparallax). I know that libparallax was pretty easy for me to pick up back when I was a relative beginner at Dreamcast stuff.

Also, for reference, libtsunami is what was used to write the game Feet of Fury for the Dreamcast (a commercially sold homebrew DDR-like game).
NeoSnk
DCEmu Cool Newbie
DCEmu Cool Newbie
Posts: 13
Joined: Sat Sep 17, 2016 6:39 am
Has thanked: 0
Been thanked: 0

Re: How to set SDL in KOS?

Post by NeoSnk »

bogglez wrote:Even if you say you're using sdl that doesn't say much about how you're drawing. Are you using opengl or software blitting?
I'm using software blitting, loading bmps and drawing it.
NeoSnk
DCEmu Cool Newbie
DCEmu Cool Newbie
Posts: 13
Joined: Sat Sep 17, 2016 6:39 am
Has thanked: 0
Been thanked: 0

Re: How to set SDL in KOS?

Post by NeoSnk »

BlueCrab wrote:
NeoSnk wrote:What you guys recommend then? Thank you for all the attention guys and I'm sorry for all the questions. I'm very newbie on the Dreamcast. But I wish to get my game running on it.
If you're using SDL, you must be at least somewhat comfortable with C or C++, right?

To be honest for 2D stuff, you'd probably be best off either using libparallax (or libtsunami if you want C++ classes for things) or just going at the PVR directly, depending on what you're doing. libparallax is just a very thin wrapper around the PVR functionality (and libtsunami is a relatively thin wrapper around libparallax). I know that libparallax was pretty easy for me to pick up back when I was a relative beginner at Dreamcast stuff.

Also, for reference, libtsunami is what was used to write the game Feet of Fury for the Dreamcast (a commercially sold homebrew DDR-like game).
Yes, I feel more comfortable using C and C++ . I'll have a look on libparallax and libtsunami, tks for the tips man. I'll post here the results hehe!
User avatar
bogglez
Moderator
Moderator
Posts: 578
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Re: How to set SDL in KOS?

Post by bogglez »

I haven't used libtsunami myself but this tutorial should be helpful if you find it lacking and want to use the pvr directly
http://dcemulation.org/?title=PVR_Spritesheets
Some other people on the forum successfully wrote a 2d renderer that way.
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
User avatar
ThePerfectK
Insane DCEmu
Insane DCEmu
Posts: 147
Joined: Thu Apr 27, 2006 10:15 am
Has thanked: 27 times
Been thanked: 35 times

Re: How to set SDL in KOS?

Post by ThePerfectK »

As BlueCrab mentioned, SDL2 works much differently from SDL1.x, but if you're familiar with using it, working in PVR is not all that different than working with hardware textures in SDL2 conceptually. Mechanically, very different. But if you can wrap your mind around SDL2, working with PVR isn't that hard.
Still Thinking!~~
User avatar
Neoblast
DC Developer
DC Developer
Posts: 314
Joined: Sat Dec 01, 2007 8:51 am
Has thanked: 3 times
Been thanked: 1 time

Re: How to set SDL in KOS?

Post by Neoblast »

Is there any example other than what it's included in the Kos examples for libtsunami? What happened to libtiki? I want to start a 2D renderer. I've used SDL for a lot of ports and it does the job, but not if you want to squeeze the system. The good thing about it is the multi platform without too many headaches.

Enviado desde mi Aquaris X5 Plus mediante Tapatalk
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5652
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: How to set SDL in KOS?

Post by BlueCrab »

I don't have any other examples for libtsunami other than what's included with KOS. Of course, the Feet of Fury source code might provide some insights, since that's where libtsunami was derived from.

As for libtiki, that's pretty much dead since nobody has been maintaining it for a while. The source code to it is still available in the SVN repo, if you're interested in it.
User avatar
Neoblast
DC Developer
DC Developer
Posts: 314
Joined: Sat Dec 01, 2007 8:51 am
Has thanked: 3 times
Been thanked: 1 time

Re: How to set SDL in KOS?

Post by Neoblast »

BlueCrab wrote:I don't have any other examples for libtsunami other than what's included with KOS. Of course, the Feet of Fury source code might provide some insights, since that's where libtsunami was derived from.

As for libtiki, that's pretty much dead since nobody has been maintaining it for a while. The source code to it is still available in the SVN repo, if you're interested in it.
Excellent, that's definitely going to help. Thanks bluecrab!

Enviado desde mi Aquaris X5 Plus mediante Tapatalk
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: How to set SDL in KOS?

Post by Memorix101 »

Yep SDL for DC is really broken :(
I asked about it this summer over here ... however, last weekend I gave it a shot and see how it worked out ...
It's REALLY broken :c

I will write a wrapper for my SDL Blitting stuff in tsunami for my DC port ...

https://www.youtube.com/watch?v=uWGrhg1 ... e=youtu.be
Post Reply