Author Best Practices for porting Apps
Admin


Joined: Apr 11, 2001
Posts: 284
Post_IconPosted: 2009-02-17 14:58   
I'll try to post here some best practices when porting applications to Morphos.

As they are developped for Over Powered Computers, SDL coders usually don't activate all accelerations.

------------------------------------------
Find SDL_SetColorKey() function an look if SDL_RLEACCEL flag have been used. Note that SDL_RLAACCEL must be used with SDL_SRCALPHA to be accelerated
Quote:

Function should look like this
SDL_SetColorKey(..., SDL_SRCCOLORKEY|SDL_RLEACCEL, ...);

To find SDL_SetColorKey in entire source :
find .|grep ".c"|xargs grep SDL_SetColorKey

Note that thing's can be slower when using SDL_RLEACCEL on too complexe Surfaces like Elipses for exemple.

------------------------------------------
Some coders never use the SDL_HWSURFACE flag.
An easy optimisation is then to replace SDL_SWSURFACE by SDL_HWSURFACE
Quote:
SDL_SWSURFACE flag can be found with this :
find .|grep ".c"|xargs grep SDL_SWSURFACE

You have to be carefull when using SDL_HWSURFACE cause all surfaces created with this flag will be stored in Video Card Memory. So your app may crash if there is still no memory available. Using SDL_SWSURFACE is sometimes faster when doing some operations on the surface. SDL documentation recommand to use SDL_SWSURFACE for Alpha Channel Surfaces.
Best is to have a look at the Surface use before using SDL_HWSURFACE

------------------------------------------
SDL games may crash on Morphos when cursor is customized by the game.
It's safer to remove all SDL_SetCursor() calls and only reactivate them once you're sure there is no other bug
Quote:

You can use something like this :
find .|grep ".c"|xargs grep SDL_SetCursor



------------------------------------------
Some apps try to save and read environnement variables. This usually try to acces Unix paths (you will find things like this (getenv("HOME");)that are not available for amiga.

Find getenv or setenv calls
Quote:
find .|grep ".c"|xargs grep getenv
and modify the function call like this :
getenv("PROGDIR:");



------------------------------------------
Some games need to run a configure file trying to test various exotics library.
It may be usefull to skip all errors avoiding the Makefile creation.
Quote:

For this replace all "exit " occurences by "print " in the configure file.

If you are lucky you will be able to compile your app without any modification to the makefile


[ This Message was edited by: admin on 2010-03-25 18:55 ]


  View Profile of Admin   Email Admin   Goto the website of Admin   Div   Edit/Delete This Post   Reply with quote
Admin


Joined: Apr 11, 2001
Posts: 284
Post_IconPosted: 2009-02-18 16:30   
RGB Big and little Endian Masks :
Quote:

switch (bits_per_pixel)
{
case 15: // RGB 555
*rmask = 0x7c00;
*gmask = 0x03e0;
*bmask = 0x001f;
break;
case 16: // RGB 565
*rmask = 0xf800;
*gmask = 0x07e0;
*bmask = 0x001f;
break;
case 24:
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
*rmask = 0x00ff0000;
*gmask = 0x0000ff00;
*bmask = 0x000000ff;
#else
*rmask = 0x000000ff;
*gmask = 0x0000ff00;
*bmask = 0x00ff0000;
#endif
break;
case 32:
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
*rmask = 0x00ff0000;
*gmask = 0x0000ff00;
*bmask = 0x000000ff;
*amask = 0xff000000;
#else
*rmask = 0x000000ff;
*gmask = 0x0000ff00;
*bmask = 0x00ff0000;
*amask = 0xff000000;
#endif
break;
}



[ This Message was edited by: Admin on 2009-02-18 16:39 ]

[ This Message was edited by: Admin on 2009-02-18 17:08 ]

[ This Message was edited by: admin on 2010-02-25 23:51 ]


  View Profile of Admin   Email Admin   Goto the website of Admin   Div   Edit/Delete This Post   Reply with quote
Admin


Joined: Apr 11, 2001
Posts: 284
Post_IconPosted: 2009-02-18 17:35   
An interesting Note about Mix_OpenAudio that may explain why lots of games crash when playing music :
Quote:
Note: You must not use AUDIO_S16, AUDIO_U16, AUDIO_S16LSB, or AUDIO_U16LSB. They are not portable, and SDL will not return an error code when they fail. The result will be a horrible staticy noise. You can usually use AUDIO_S16SYS, though not always. Future versions of SDL should take this parameter only as a hint, then read back the value that the OS (for example, OSS or ALSA) has chosen to use in case the desired audio type is not supported.



I had a problem too with powersdl_mixer.library crashing when compiling with -O3 option...

[ This Message was edited by: admin on 2009-02-18 23:30 ]


  View Profile of Admin   Email Admin   Goto the website of Admin   Div   Edit/Delete This Post   Reply with quote
Admin


Joined: Apr 11, 2001
Posts: 284
Post_IconPosted: 2009-02-27 20:46   
When debugging, remove all optimisations and don't strip the executable.

Here is the command to disassemble a binary :
Quote:

for C programs :
ppc-morphos-objdump --syms --reloc --disassemble-all unstripped_exe >disassembled_exe

for C++ programs :
ppc-morphos-objdump --demangle --syms --reloc --disassemble-all unstripped_exe >disassembled_exe

To see sourcecode (need compiling with -g and linking with -Wl,--traditional-format):
ppc-morphos-objdump --source --line-numbers --demangle --syms --reloc --disassemble-all unstripped_exe >disassembled_exe




[ This Message was edited by: admin on 2009-12-21 15:20 ]

[ This Message was edited by: admin on 2009-12-21 17:12 ]


  View Profile of Admin   Email Admin   Goto the website of Admin   Div   Edit/Delete This Post   Reply with quote
Admin


Joined: Apr 11, 2001
Posts: 284
Post_IconPosted: 2009-03-01 20:33   
Some options that can be added to LD parameters
-ffunction-sections -Wl,--gc-sections

This should remove all unused functions.

This can be added in makefile with this parametre :
LDFLAGS=" -ffunction-sections -Wl,--gc-sections "


  View Profile of Admin   Email Admin   Goto the website of Admin   Div   Edit/Delete This Post   Reply with quote
Admin


Joined: Apr 11, 2001
Posts: 284
Post_IconPosted: 2009-03-08 13:49   
Round function is missing on amiga plateform.
It's possible to use this define :
#define round(x) (int)(x+(x<0? -0.5 : 0.5))



  View Profile of Admin   Email Admin   Goto the website of Admin   Div   Edit/Delete This Post   Reply with quote
Admin


Joined: Apr 11, 2001
Posts: 284
Post_IconPosted: 2009-07-16 21:56   
define this :
#define unlink(foobar) { remove(foobar); }


  View Profile of Admin   Email Admin   Goto the website of Admin   Div   Edit/Delete This Post   Reply with quote
Admin


Joined: Apr 11, 2001
Posts: 284
Post_IconPosted: 2009-10-19 13:56   
sentenv can be replaced by SetVar() from DOS functions.
A stub can be created too :
int setenv(const char *name, const char *value, int overwrite) { printf("DTCn"); }

dos/dos.h
proto/dos.h
SetVar(name, buffer, size, flags)
size = -1
flags = (GVF_LOCAL_ONLY ou GVF_GLOBAL_ONLY)

[ This Message was edited by: admin on 2009-10-19 14:00 ]

[ This Message was edited by: admin on 2009-10-19 14:06 ]


  View Profile of Admin   Email Admin   Goto the website of Admin   Div   Edit/Delete This Post   Reply with quote
Admin


Joined: Apr 11, 2001
Posts: 284
Post_IconPosted: 2009-12-21 21:08   
add some stack :
Code:

unsigned long __stack = 1000000;



  View Profile of Admin   Email Admin   Goto the website of Admin   Div   Edit/Delete This Post   Reply with quote
Admin


Joined: Apr 11, 2001
Posts: 284
Post_IconPosted: 2010-01-10 22:50   
For games based on floats, always use a :
Code:

#include <stdio.h>
#include <time.h>
#include <locale.h>

setlocale(LC_ALL, "C");



  View Profile of Admin   Email Admin   Goto the website of Admin   Div   Edit/Delete This Post   Reply with quote
Admin


Joined: Apr 11, 2001
Posts: 284
Post_IconPosted: 2010-02-16 22:47   
conflict functions or types :
#undef myfunc
or
find . |grep ".cpp|.h" |xargs sed -i 's/func/myFunc/g'
find . |grep ".cpp|.h" |xargs sed -i -r "s|bla|myBla|g"


[ This Message was edited by: admin on 2014-04-02 23:45 ]


  View Profile of Admin   Email Admin   Goto the website of Admin   Div   Edit/Delete This Post   Reply with quote
Admin


Joined: Apr 11, 2001
Posts: 284
Post_IconPosted: 2010-03-18 19:54   
Seem's that SDL_RWops are broken at least in powerSDL 14.0

You may encounter such code that will explode :
Code:

pRWop->read = Pakfile::ReadFile;
pRWop->write = Pakfile::WriteFile;
pRWop->seek = Pakfile::SeekFile;
pRWop->close = Pakfile::CloseFile;
pRWop->hidden.unknown.data1 = (void*) pRWopData;



Problem can be solved like this :
Code:

pRWop->read = pRWop->read2 = Pakfile::ReadFile;
pRWop->write = pRWop->write2 = Pakfile::WriteFile;
pRWop->seek = pRWop->seek2 = Pakfile::SeekFile;
pRWop->close = pRWop->close2 = Pakfile::CloseFile;
pRWop->hidden.unknown.data1 = (void*) pRWopData;



[ This Message was edited by: admin on 2010-04-13 22:07 ]


  View Profile of Admin   Email Admin   Goto the website of Admin   Div   Edit/Delete This Post   Reply with quote
Admin


Joined: Apr 11, 2001
Posts: 284
Post_IconPosted: 2010-03-24 00:20   
Convert little-endian float to big-endian float :
Code:
float floatSwap(float f)

{
union foobar {int i; float f;};
union foobar fb;
fb.f=f;
fb.i=SDL_Swap32(fb.i);
f=fb.f;

return f;
}



  View Profile of Admin   Email Admin   Goto the website of Admin   Div   Edit/Delete This Post   Reply with quote
Admin


Joined: Apr 11, 2001
Posts: 284
Post_IconPosted: 2010-08-02 23:02   
Replace socklen_t : typedef int socklen_t;
Replace ioctl : IoctlSocket(s, FIONBIO, &on_mode);
Dont forget to close the socket :
close(s); : CloseSocket(s);


[ This Message was edited by: admin on 2011-01-01 21:03 ]


  View Profile of Admin   Email Admin   Goto the website of Admin   Div   Edit/Delete This Post   Reply with quote
Admin


Joined: Apr 11, 2001
Posts: 284
Post_IconPosted: 2011-01-13 00:09   
optimised SQRT() functions :
http://ilab.usc.edu/wiki/index.php/Fast_Square_Root


  View Profile of Admin   Email Admin   Goto the website of Admin   Div   Edit/Delete This Post   Reply with quote
   Reply
 
Lock this Topic Move this Topic Delete this Topic

Powered by phpBB Version 1.4.4
Copyright © 2000 - 2001 The phpBB Group

phpBB Created this page in 0.500751 seconds.