PDA

View Full Version : SDL Examples for NDS porting



jdarling
22-12-2006, 03:47 PM
I have quite a few simple SDL examples I could post up if you want something to test with. As a sample; One to draw a line on the screen, One to display a png to the screen, One to place a TTF font on the screen, One to place a raster font on the screen, and many more. Just little quick hits to remind me how to do the things I seem to forget all the time :)

Legolas
22-12-2006, 04:02 PM
I have quite a few simple SDL examples I could post up if you want something to test with. As a sample; One to draw a line on the screen, One to display a png to the screen, One to place a TTF font on the screen, One to place a raster font on the screen, and many more. Just little quick hits to remind me how to do the things I seem to forget all the time :)
Good! Yes please, post them all :D

WILL
22-12-2006, 05:12 PM
So you said before that you were able to get SDL working under NDS?

What was the deal with the dynamic libraries though? You find a way to compile the libs into the rom it's self?

How much bloat does that work out to?

Legolas
22-12-2006, 06:05 PM
I was able to get SDL compiling for NDS :lol:
I need some basic examples to see if it works too. No dynamic libs, it works like as libnds: libs are statically (smart)linked inside the rom. About using sdl, it's only matter of adding sdl to uses. Of course I have adapted sdl.pas only, so I don't know how much work it is needed to get a complete sdl for nds package (sprite engine, mixer, logger, ...)

WILL
22-12-2006, 07:01 PM
Ah, ok... well I believe I'd want/need sdl and sdl_mixer. Don't know about sdl_image but my game uses it. Not that I'm planning on trying to get PNG files going on NDS. :P

And then there is the issue of OpenGL through SDL ala included gl and glu. :)


Well like I mentioned before we have that little demo to work on. :shhh:

Legolas
22-12-2006, 07:33 PM
Not sure about png, but libnds allows to use pcx images :)


Well like I mentioned before we have that little demo to work on. :shhh:
Yep! :whistle: :mrgreen:

WILL
22-12-2006, 07:53 PM
What about sdl_mixer?

Legolas
22-12-2006, 08:04 PM
What about sdl_mixer?
The sdl libs ported to nds are: SDL_flic, SDL_gfx, SDL_image, SDL_mixer, SDL_ttf and SFont. There is a support for zip (via zlib), jpeg and png.
About audio, seems that sometime it goes out of sync :/

http://gpf.dcemu.co.uk/ndsSDL.shtml

http://www.dcemu.co.uk/vbulletin/forumdisplay.php?f=78

savage
27-12-2006, 06:20 AM
Ooops only just found this thread. Sounds like excellent stuff!! It would be nice to release v1.0 with preliminary NDS support. Please let me know if there are any other changes required to sdl.pas or any of the other sdl_*.pas files.

savage
27-12-2006, 06:58 AM
http://gpf.dcemu.co.uk/ndsSDL.shtml

I also noticed that this link has a libSDL for GBA. Has anyone tried it?

Legolas
27-12-2006, 12:47 PM
Ooops only just found this thread. Sounds like excellent stuff!! It would be nice to release v1.0 with preliminary NDS support. Please let me know if there are any other changes required to sdl.pas or any of the other sdl_*.pas files.

Here is a quick list of changes I made in order to compile it:

:arrow: NDS needs "uses types;" only
:arrow: libSDL.a depends from libnds9.a and some other gcc libs:
{$IFDEF NDS}
SDLLibName = 'libSDL.a';
{$]
:arrow: I have commented out all SDL_mutex and thread parts
:arrow: All external funcs are declared as:
[pascal]
function SDL_Init( flags : UInt32 ) : Integer;
cdecl; external {$IFNDEF NDS}{$IFDEF __GPC__}name 'SDL_Init'{$ELSE} SDLLibName{$ENDIF __GPC__}{$ENDIF NDS};


That's all :)
As I said, it compiles fine but I dont' know if it works too :P

technomage
27-12-2006, 07:03 PM
That would be soooo cool if it works on the NDS as well. From what I have seen there is an OpenGL API layer as well, my new engine could have a NDS kernel and then pretty much work after that...

Are the .a files like the library files on Windows, or are they more like Dll's? I always get comfused when linking to those.

Also I thought there were some license implications regarding linking to the libraries in SDL rather than using the DLL. I could be wrong though.

Legolas
27-12-2006, 07:20 PM
[quote="technomage"]That would be soooo cool if it works on the NDS as well. From what I have seen there is an OpenGL API layer as well, my new engine could have a NDS kernel and then pretty much work after that...

Are the .a files like the library files on Windows, or are they more like Dll's? I always get comfused when ]

AFAIK the .a files are statically linked to the executable. What about these license issues?

noeska
27-12-2006, 08:54 PM
the license of sdl is explained here: http://www.libsdl.org/license-lgpl.php
seems you are ok with distributing their license together with a link to their site. In my opinion using lgpl directly you should also distribute the source of your own application but they do not state that on their site. E.g. read the last line.

dmantione
27-12-2006, 09:40 PM
This is correct and the reason why FPC uses a modified LGPL. Well, you don't need to provide source code, but ensure people can use all freedoms on the LGPL part of the program, that is replace it with their own version. In general this means dynamic linking, not possible on NDS. Perhaps providing object files would satisfy as well, but in general, LGPL means all statically linked programs need their source code available.

WILL
28-12-2006, 01:59 AM
If thats the case then that would mean that commercial development is out. Well with SDL anyway...

noeska
28-12-2006, 06:53 PM
Maybe we can write a sdl like library? As i think most sourcecode will be unuseable. Or is using the same naming for the commands enough te let i fall under the sdl lgpl license? We could release the result under a modified lgpl license allowing what we want. Also we could contact the people behind sdl and ask them what we want is agreeable with them. As reading their last line of their explanation of lgpl could mean we could just use the lib and compile it in, but we should provide a link to their site then, or i could be misreading that last line.

WILL
28-12-2006, 08:10 PM
I think we'd need to clarify the exact terms and definitions with the SDL people in regards to NDS compiling. I doubt that they really had commercial console development in mind at the time of it's creation, but they may see reason to make a way or at least an exception for legitimate console compilation.

As far as making a library... thats not a bad idea... I doubt that naming conventions would hold us to any of SDL's licensing restrictions as the entire make-up of functionality beneath is totally different.

It kind of cancels out being able to include it with JEDI-SDL as it would really have nothing to do with SDL at all except that the function calls are the same to match the game's code.

We could simply describe the project as 'a bridging unit for JEDI-SDL to NDS porting.' A list of SDL compatibility functions would need to be created in the documentation as well.


I'd see what the SDL people have to say before starting it up though.

technomage
06-02-2007, 10:34 PM
Anyone got the compiled versions of the SDL , SDL_Image and accosiated libraries for the DS :?: I'm trying to see if I can port my code over to the DS and I have most stuff working, but I just can't compile the SDL libraries...

Or are there any instructions on how to compile the lib's on a Windows box for the DS?

Legolas
08-02-2007, 07:28 PM
Anyone got the compiled versions of the SDL , SDL_Image and accosiated libraries for the DS :?: I'm trying to see if I can port my code over to the DS and I have most stuff working, but I just can't compile the SDL libraries...

Or are there any instructions on how to compile the lib's on a Windows box for the DS?

As far as I have seen, sdl for nds does not compile with devkitPro r20. With dkP r19 you need to modify a little bit makefile.ds. If you want, I can send it to you (for some strange reason I can put it here between code tags :shock:)

technomage
08-02-2007, 10:18 PM
If you could PM me the code that would be great.

I'll get r19 down instead and try that.

Legolas
09-02-2007, 01:05 AM
Uhm... same error in pm. Maybe the forum engine parses the makefile text and comes out something wrong. When I try to make a message preview or try to send it, I get a 404 error :D
I'll send that makefile via email (PM me your address) :wink:

WILL
09-02-2007, 04:51 AM
Hmm... couldn't you alternately use PasteBin? www.pastebin.com (http://pastebin.com/)

technomage
09-02-2007, 02:56 PM
Here is a quick list of changes I made in order to compile it:

:arrow: NDS needs "uses types;" only
:arrow: libSDL.a depends from libnds9.a and some other gcc libs:
{$IFDEF NDS}
SDLLibName = 'libSDL.a';
{$]
:arrow: I have commented out all SDL_mutex and thread parts
:arrow: All external funcs are declared as:
[pascal]
function SDL_Init( flags : UInt32 ) : Integer;
cdecl; external {$IFNDEF NDS}{$IFDEF __GPC__}name 'SDL_Init'{$ELSE} SDLLibName{$ENDIF __GPC__}{$ENDIF NDS};


That's all :)
As I said, it compiles fine but I dont' know if it works too :P

I'm making changed to the sdl.pas for JEDI-SDL to see if I can make is conpile out of the box for the ds.

I have made all of the changes you specified with the exception of defining PSDL_mutex as it is defined in the source code.

But I get



sdl.pas (4207,4) Error : Creation of Dynamic/Shared Libraries not supported


Any ideas?

Legolas
09-02-2007, 04:47 PM
I got a similar error. I can't remember how I have solved it, but if it can help you, here (http://pastebin.ca/347704) is a pastebin (thanks WILL :D) of my sdl.pas ;)

technomage
10-02-2007, 10:51 AM
I got everything compiling OK. And a basic sample working :D.

I'm now looking into OpenGL support, unfortunately the port of SDL to the DS does not support Opengl so I'm having to add it. Currently I just adding code like this



// Set the video mode to 3D
if (flags & SDL_OPENGL) {
videoSetMode(MODE_0_3D| DISPLAY_BG2_ACTIVE);
//set the sub background up for text display (we could just print to one
//of the main display text backgrounds just as easily
videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); //sub bg 0 will be used to print text
}


but apart from the MODE_0_3D I'm not sure what everything else actially does....

But things are looking good so far. :)

technomage
10-02-2007, 12:15 PM
Some progresss on the plain SDL front.

http://www.infinitespace-online.net/PGD2007/Screenshots/jedisdl-ds.png

This is running on the dualis emulator.

the Red box is using the standard SDL_FillRect, the Blue box is done using the JEDI-SDL SDL_PutPixel routine. Only the changes suggested by Legolas were made to the sdl.pas file. The sdlutils.pas was untouched and worked as is. :D

here is the code


program sdltest;

{$IFDEF NDS}
{$apptype arm9} //...or arm7
{$define ARM9} //...or arm7, according to apptype

{$mode objfpc} // required for some libc funcs implementation

uses
ctypes, sdl, SysUtils, sdlutils; // required by nds headers!

{$include nds.inc} // headers!
{$ELSE}
{$APPTYPE CONSOLE}
uses
sdl,
gl,
SysUtils, sdlutils;
{$ENDIF}

var Screen: PSDL_Surface;
r: TSDL_Rect;
x,y: Integer;

begin
SDL_Init(SDL_INIT_VIDEO);
try
Screen := SDL_SetVideoMode(320,200,16,SDL_HWSURFACE or SDL_DOUBLEBUF);
if Screen = nil then Exit;
try
r := SDLRect(10,10,20,20);
while True do
begin
SDL_FillRect(Screen, nil, SDL_MapRGB(Screen^.format, 255,0,0));
SDL_FillRect(Screen, @r, SDL_MapRGB(Screen^.format, 0,255,0));
for y := 40 to 80 do
begin
for x := 40 to 80 do
begin
SDL_PutPixel(Screen, x,y, SDL_MapRGB(Screen^.format, 0,0,255));
end;
end;
SDL_Flip(Screen);
end;
finally
SDL_FreeSurface(Screen);
end;
finally
SDL_Quit;
end;
end.


Dom, shall I send you the changes to make the DS work with JEDI-SDL :?:

VilleK
10-02-2007, 05:14 PM
This is extremely cool :thumbup:

Legolas
10-02-2007, 07:27 PM
Cool! I'm very pleased to see that it works :thumbup:
Nice work, Dean! :clap:

savage
10-02-2007, 08:44 PM
Dom, shall I send you the changes to make the DS work with JEDI-SDL :?:

This is super cool. Would I say no to such an opportunity. Btw, The latest version of sdl.pas is in CVS. Are you not able to merge the changes in? If not send it over and tell me what needs changing. I don't have a diff tool so will need some hand holding to get it right.

dmantione
10-02-2007, 08:55 PM
Perhaps you should check the bin directory of your Free Pascal directory. There is a diff there.

savage
11-02-2007, 09:45 AM
Btw, has anyone tried to get the SDL for GBA working with JEDI-SDL?

The NDS changes have been merged into the main sdl.pas file and I'm just waiting for Dean to double check that everything is sweet, before I commit it to CVS.

savage
12-03-2007, 12:18 AM
Hi Dean,
Any further news on the OpenGL side of things or did you give up/run out of time?

technomage
12-03-2007, 10:33 PM
I kinda run out of time. I did port a sample over but couldn't get it working. There are differences between the NDS opengl and the real on that might be causing a problem.

I also had to hack the SDL source to put it into 3D mode when the SDL_OPENGL flag was passed as the current version just ignored it.

savage
10-12-2007, 01:54 PM
Damn I totally forgot about this thread.

Dean, could you outline know how to get SDL working/installed inside a NDS emulator and how you compiled your 2D sample for it?

If it's too much hassle, let me know.