Dingoonity.org

Dingoo Official Firmware => Development => Topic started by: Harteex on August 20, 2010, 02:03:50 am

Title: Native now has SDL
Post by: Harteex on August 20, 2010, 02:03:50 am
I've spent a lot of time on porting SDL to native and I'm now very happy to have finally made it.
Of course, also thanks to alekmaul and especially flatmush, which code I'm using parts of.

So what's ported?
* SDL
* SDL_ttf
  - freetype
* SDL_image
  - libpng
* SDL_mixer
  - tremor (ogg)
  - libmikmod (xm, mod, it, ...)

Right now the video device only supports 320x240 16bit, but I plan on adding scaling for 640x480 and possibly other resolutions as well.


What does this mean?
Porting some games will be much easier now, so hopefully we'll see a bunch of new releases.

If you want to develop using SDL, be sure to grab the latest version of the dingoo-sdk at
http://code.google.com/p/dingoo-sdk/downloads/detail?name=dingoo_sdk_r251.zip
(Mirror (http://www.mediafire.com/?wml1gffscf8v690))
Title: Re: Native now has SDL
Post by: Shin-NiL on August 20, 2010, 02:13:32 am
Thank you for the hard work of all of you! You are opening wide possibilities for the native system this way.

I will be testing as soon as possible!  :)
Title: Re: Native now has SDL
Post by: alekmaul on August 20, 2010, 05:48:10 am
thanks for the hard work Harteex and sorry to be a little out of the scene actually  :-\ ...
Title: Re: Native now has SDL
Post by: VampireSlug on August 20, 2010, 10:19:55 am
This is awesome news... congrats!
Title: Re: Native now has SDL
Post by: protomank on August 20, 2010, 02:47:45 pm
WoW! That is GREAT news! :)
I was planning to port my projet (a megaman-like game) to Dingux, but now I can port it to the native. I use the exactaly same libs (sdl, sdl_ttf, sdl_image and sdl_mixer) that were ported, awesome! :D
Title: Re: Native now has SDL
Post by: zear on August 20, 2010, 02:52:04 pm
WoW! That is GREAT news! :)
I was planning to port my projet (a megaman-like game) to Dingux, but now I can port it to the native. I use the exactaly same libs (sdl, sdl_ttf, sdl_image and sdl_mixer) that were ported, awesome! :D
Why don't you port it to both? A lot of people here don't use native os at all.
Title: Re: Native now has SDL
Post by: kswildside on August 20, 2010, 04:57:06 pm
Zear not saying your wrong but to say most don't use native is not true I use both some emulators on native aren't on Dingux just as I use Dingux for emulators that aren't on Native or work better ;)
Title: Re: Native now has SDL
Post by: alekmaul on August 20, 2010, 06:38:31 pm
yes, i also think 'non linux users' are on native os.
so sdl port is really a GREAT thing. Thanks again for that Harteex
Title: Re: Native now has SDL
Post by: kswildside on August 20, 2010, 07:11:03 pm
I think there are alot of native OS users they have just learned that the community is more unix and open source based than developing for the Native and have learned to live with it. But we have a great core of native developers who deserve more appreciation then they get...
Title: Re: Native now has SDL
Post by: vgx on August 20, 2010, 10:38:27 pm
Thanks a lot guys!!! You're simply awesome :).
Title: Re: Native now has SDL
Post by: Harteex on August 20, 2010, 10:48:32 pm
Glad you all like it  :)
Feel free to post if you encounter any problems.

And hi again alekmaul. I'm also hoping we'll get a Dingoo with more RAM available for native, as this will probably hinder some of the larger SDL games/emulators.
Title: Re: Native now has SDL
Post by: Kojote on August 20, 2010, 11:43:23 pm
i smell a SQRXZ http://www.sqrxz.de (http://www.sqrxz.de) port for Dingoo native, by alekmaul?! ;)
Title: Re: Native now has SDL
Post by: zear on August 20, 2010, 11:51:47 pm
I hope you guys are still interested in dingux port of SQRXZ? Because I wait for it since it was first announced ;D
Title: Re: Native now has SDL
Post by: Kojote on August 21, 2010, 12:28:51 am
I hope you guys are still interested in dingux port of SQRXZ? Because I wait for it since it was first announced ;D

We would love to work with Slaanesh again, as he also brought Giana's Return to Dingux. Slaanesh currently enjoys his summer outdoor hobbys rather than porting things, so I fear no Dingux Sqrxz before autumn/winter. Maybe we can get alekmaul to port to native Dingoo for now. Still working on Sqrxz v0.9.9.6 with multi language support. Spanish and French are pending, German should be done and needs another test run. So once the latest version is done, let's see what will happen.
Title: Re: Native now has SDL
Post by: alekmaul on August 21, 2010, 05:54:02 am
ok for a try of porting SQRXZ to dingoo native OS, no pb.
Just have to finish some things on another handheld and i will try to port it.
Title: Re: Native now has SDL
Post by: spn-x on August 21, 2010, 09:22:29 am
SB got a good tutorial for sth easy ? ( hello world or sth. ... i've some free time so i want to get into this )
Title: Re: Native now has SDL
Post by: joyrider on August 21, 2010, 03:41:00 pm
almost have my sokoban game running on native, i did had to include sdl_gfx (which is quite easy) to the sdl lib and had to add -fno-rtti since it used c++ and gotten weird errors otherwise, i'm down to 1 stupid error some undefined reference to lrint, which should have something to do with the math lib, if i can't find a solution on how to fix it i'll just search for another implementation of it. But didn't bother anymore with it atm :)
Title: Re: Native now has SDL
Post by: Harteex on August 21, 2010, 06:10:41 pm
Nice, we don't seem to have lrint though (yet).

spn-x: Might add some kind of sample tomorrow.
Title: Re: Native now has SDL
Post by: spn-x on August 22, 2010, 08:41:13 am
@harteex : Do u think it would be easier to start with dingux ? Or is there no difference between Native and Dingux.
Title: Re: Native now has SDL
Post by: zear on August 22, 2010, 09:47:53 am
@harteex : Do u think it would be easier to start with dingux ? Or is there no difference between Native and Dingux.
Well, as for Dingux you can start with any SDL tutorial for windows/linux as there is no difference between that platforms and Dingux :)
Title: Re: Native now has SDL
Post by: spn-x on August 22, 2010, 10:34:18 am
Ok, is there any chance to code with OSX ? Or do i have to use my WIN Laptop ?
Title: Re: Native now has SDL
Post by: joyrider on August 22, 2010, 10:41:03 am
Ok, is there any chance to code with OSX ? Or do i have to use my WIN Laptop ?

Gcc tools exist for mac, but i do not think there is a "all in one" package downloadable for mac, unless a dev that uses mac has created one and upload it somewhere. This means it is possible, i'm pretty sure of it but you would have to compile the (cross)compiler yourselve from sources and that's a dauting task. Once you have that you can probably just use the dingoo sdk as usual ...

do some googling around

this is some info of the gcc tools (used with the dingoo sdk for native that flatmush made)
$ mipsel-linux-gcc -v
Using built-in specs.
Target: mipsel-linux
Configured with: ../src/configure --target=mipsel-linux -enable-languages=c++ --
host=i686-pc-linux-gnu --prefix=/cygdrive/d/user/daniel/work-gcc/tools/mipsel-gc
c4.1-nopic --disable-multilib --disable-shared --with-headers=/cygdrive/d/user/d
aniel/work-gcc/tools/mipsel-gcc4.1-nopic/mipsel-linux/include
Thread model: posix
gcc version 4.1.2

mipsel-gcc4.1-nopic

it might be wise if you start from source to perhaps use the exact same version and use the same configure flags etc

Title: Re: Native now has SDL
Post by: spn-x on August 22, 2010, 11:39:43 am
Ok, then i'll try it with Windows ..
Title: Re: Native now has SDL
Post by: joyrider on August 22, 2010, 12:19:06 pm
Ok, then i'll try it with Windows ..

if you'd really like to work on your mac for example because you don't like laptop keyboards (like me) or other reason's like you have other programma's you use constantly on your mac... Try looking for some vnc like tool or some other remote desktop program that works on both windows and mac, you can the basically take over your laptop on your mac and do whatever you like.

You could also create a samba share to the files on your windows laptop so you can edit the files on your mac using mac tools which you like and are used too. and just use the remote desktop to run cygwin and compile...

I can suggest code::blocks which exists for mac (i use it myselve).. although it's a preference...

as far as a remote desktop tool teamviewer (www.teamviewer.com) seems like a viable option it's easy to use and works on both windows and mac, and free for non comercial use, so you can do what i suggested above ..
Title: Re: Native now has SDL
Post by: Harteex on August 22, 2010, 02:07:17 pm
@harteex : Do u think it would be easier to start with dingux ? Or is there no difference between Native and Dingux.
Well, as for Dingux you can start with any SDL tutorial for windows/linux as there is no difference between that platforms and Dingux :)

Same for SDL for native pretty much, the only thing you need specifically is a makefile.
If you want to move your game/app to the dingoo, make sure you use 320x240 graphics resolution.
Title: Re: Native now has SDL
Post by: Harteex on August 24, 2010, 12:06:53 am
I've made a simple Pong sample to show C++ and SDL, you can find it in the SVN repository:
http://code.google.com/p/dingoo-sdk/source/browse/#svn/trunk/dingoo_sdk/samples/SDLPong

From the readme:
Quote
This sample is more meant to be a sample than to be a game.
It's currently not very exciting to play because it's easy to predict how the ball bounces.

The sample provides the following:
* A makefile for C++ / SDL
* An example game loop (there are many different ways of doing this, probably many better ways also)
* SDL_image usage (png splash screen)
* SDL_mixer usage (sound and music)
* SDL_ttf usage (fonts and text)
* A way to handle keys
Title: Re: Native now has SDL
Post by: joyrider on August 24, 2010, 12:59:05 am
Hey harteex,

i noticed the function "static void SLCD_UpdateRects(_THIS, int numrects, SDL_Rect *rects)"

Doesn't take into account the rects param yet, so in other words your always flipping the whole screen, even when users didn't ask for this (by for example not calling SDL_Flip but calling SDL_Updaterect or something) that has a kind of performance impact, since in such cases the user (well programmer) doesn't want to update the whole screen, but only a part of it to gain speed (which we don't now) ... I think it can't be too hard to do this, since it's always a rect so you could calculate starting offset  (top left corner of rect) in the real screen,  and then calculate based the rectheight and rectwidth and update one line at a time for the rectangle adding each time the offset to the next starting point, that should speed up certain games or at least do what the user asked or expected, since now it doesn't make a diffrence :)
Title: Re: Native now has SDL
Post by: Harteex on August 24, 2010, 01:52:13 am
Yea, you're right. That was one of the first things I did (the actual code is copy-pasted from flatmush SML stuff), and I kind of forgot about it.

I'll look into it when I have time, should have some the next couple of days.

BTW, if any dev wants to contribute code to the SDK and/or SDL, I could give you commit access.
Title: Re: Native now has SDL
Post by: joyrider on August 24, 2010, 08:19:55 am
i'm not into svn's etc only for downloading sources hehe, since i'm affraid to mess things up... but i'll send you the things i did to include SDL_Gfx, you don't actually have to do anything for it to work, except modify the header files for it (like replace <header> with "header". The rest worked out of the box (well it compiled the sdl lib at least with it in it) since it works on top SDL, i couldn't actually test all the functions yet, since i haven't messed around with my sokoban game anymore... might do sometime this week... but i think they should work :)
Title: Re: Native now has SDL
Post by: joyrider on August 25, 2010, 11:33:15 am
Harteex, i played a bit with the sdl source and got an idea that might help certain apps / games (specifically emulators most of the time), when they are written in a certain way ...

Looking at the sdl source for native, it's basically always using double buffering since you do the following :
this->hidden->buffer = SDL_malloc(width * height * (bpp / 8));

and afterwards with the updaterects, you write the temporary surface to the real dingoo screen using slcd_getframe and setframe...
so thats actually double buffering ... I understand why you did this though, because if you don't and you do 2 blits on the same spot you get flickering, i've come accross that on the gp2x as well..

However some people know about this and can use it to their advantages gaining 7 extra fps according to my tests (when blitting a 320x240 image as fast as the dingoo can to the screen)

so here's an idea :
keep your current setup but only activate it when SDL_DOUBLEBUFF flag is set


when the flag is not set just do this : (it's only a few changes but you have to watch out not to free the hidden buffer then on a few places in the code)

this->hidden->buffer = lcd_get_frame();

and in the update rects do only this :

if (this->hidden->buffer == NULL)
      return;
  __dcache_writeback_all();
  lcd_set_frame();

that way you give people the option to either use a double buffer or not and for those who don't need it they can get extra speed given they don't blit a surface "over" each other before flipping the screen plus more free ram because a second buffer is not allocated

it would be even better to make an adopted function from the function on this page : http://wakaba.c3.cx/w/dingoo_coding
SendLCDFrame(uint16_t *frame)

because then you can take the rect into account as well, by only updating the places on the screen that need it (when not using double buffer) since the current  lcd_set_frame(); always writes back the whole screen i think ..

not sure who's the author of that site though
Title: Re: Native now has SDL
Post by: Harteex on August 25, 2010, 04:53:25 pm
Very nice, thanks a lot for your ideas :)
I will definitely look into this.

SDL_DOUBLEBUF is not valid together with SDL_SWSURFACE so I think I will keep the current way (but fix the rects updating) for this type.

For SDL_HWSURFACE, I will try drawing to lcd_get_frame() directly and for DOUBLEBUF the SendLCDFrame function approach.
Title: Re: Native now has SDL
Post by: Harteex on August 28, 2010, 04:52:46 pm
If you grab the latest SDL code from SVN, it now updates the rects as it should and not just the whole screen.

I also filed a google code issue on the HWSURFACE ideas: http://code.google.com/p/dingoo-sdk/issues/detail?id=51
Title: Re: Native now has SDL
Post by: alekmaul on September 05, 2010, 07:01:31 am
Just one question Harteex, i testeed a port of a game and i think SDL for dingoo does not support timer callback, do you confirm this fact ?
Title: Re: Native now has SDL
Post by: Harteex on September 05, 2010, 01:52:31 pm
Yea, they don't work currently. I'll see if I can fix that, and post back if I do.
Title: Re: Native now has SDL
Post by: alekmaul on September 05, 2010, 06:00:44 pm
ok, so it's not a pb from my port ^^
thanks for your fast reply ^^
Title: Re: Native now has SDL
Post by: Yongary on September 09, 2010, 01:59:48 am
Does this mean that we can finally get a Dingoo version of Cave Story?

Cave Story SDL link: http://sourceforge.net/projects/cavestory/ (http://sourceforge.net/projects/cavestory/)
Title: Re: Native now has SDL
Post by: zear on September 09, 2010, 10:48:23 am
Does this mean that we can finally get a Dingoo version of Cave Story?

Cave Story SDL link: http://sourceforge.net/projects/cavestory/ (http://sourceforge.net/projects/cavestory/)

Cave Story is not open source. This thing is a try to rewrite the engine, but AFAIK it's not working and is long abandoned ;)

Edit: I found a fresh and very complete engine reimplementation for Cave Story. It's called NXEngine. I gave it a try on Dingux and that's the result: http://www.youtube.com/watch?v=dUFO48HiXhg
Title: Re: Native now has SDL
Post by: Harteex on September 09, 2010, 02:52:27 pm
ok, so it's not a pb from my port ^^
thanks for your fast reply ^^

I think I will have very limited time for dingoo coding for a while, so this might take some time.
You could replace the timers with the standard SDL_GetTicks if it's easy to do in the port, or wait with it to a later time.
Title: Re: Native now has SDL
Post by: nzeemin on September 17, 2010, 08:49:29 am
Harteex, looks like SDL has the bug with X button: if the button pressed for long time (about 3 sec) the program quits.
That's standard "feature" of sys_judge_event -- Tim0xA was first who found it: http://boards.dingoonity.org/dingoo-development/platform-independant-dingoo-sdk/msg17853/#msg17853
So now all SDL-based games build with dingoo-sdk have the same "feature".
Title: Re: Native now has SDL
Post by: Harteex on September 17, 2010, 10:56:10 am
It's not really bug, but a feature in the OS. There are two ways you can use to fix it:

Either, before SDL init, do SDL_putenv("DINGOO_IGNORE_OS_EVENTS=1");
This is a dingoo specific flag to ignore the system events.

Otherwise you may also simply look for this code: if (event.type == SDL_QUIT)
and comment out the code so that you don't do anything on a quit event.
Title: Re: Native now has SDL
Post by: nzeemin on September 24, 2010, 11:41:28 am
Harteex, can you address this issue? or maybe advice me some workaround?

http://code.google.com/p/dingoo-sdk/issues/detail?id=54

SDL_OpenAudio function hangs for samples = 441. If you change samples to 512 then it works fine.
Title: Re: Native now has SDL
Post by: Harteex on September 24, 2010, 04:49:24 pm
Yea I saw the issue, but haven't had time to look at it yet. I'm very busy at the moment.
My guess is that the waveout function expects a buffer with a size with the power of two, but I haven't looked into it yet. I should be able to work around that, if that is the case though.
Title: Re: Native now has SDL
Post by: Harteex on September 24, 2010, 08:41:49 pm
I've updated your issue. Basically, 8bit sound is not supported.
As for a workaround, convert your audio to 16bit instead and use double the buffer size.
Title: Re: Native now has SDL
Post by: djdron on September 25, 2010, 03:36:04 pm
Hello, Hartex!
Looks like SDL depends from sml. Can we remove this dependence?
Title: Re: Native now has SDL
Post by: Harteex on September 26, 2010, 03:07:14 pm
Sure, it's only the controls which depends on SML right now if I remember correctly. But what would it accomplish?

I don't have time to do that right now though. You're welcome to fix it yourself if you feel like it.