GapiDraw Palm/Symbian notes
Updated 2003-12-10
Hi,
I posted this thread to make you aware of some of the issues you might experience when you are looking into targeting platforms other than Win32. Porting to Symbian is actually quite easy and requires no commercial tools (you can even use global variables if you use a combination of a TLS and macros, see below), where porting to Palm in most cases require CodeWarrior and possibly quite a few changes to your current code.
I will try to keep this thread updated as much as possible.
------------
Palm OS
------------
The current Palm OS 5 is not really designed to handle applications depending on large amounts of dynamic data, such as a game drawing high-resolution graphics to a 320x480 16-bit display. The available dynamic heap (used by surfaces) is very limited, there is no built-in image decoder, there is no file system (except when using external memory cards), and there are limited free development tools available. One of the most cumbersome issues is probably the 64k code segment limit due to the 16-bit architecture still inherent in the Palm OS5 devices, meaning that you probably have to use an off-the-shelf product such as CodeWarrior to split your application in multiple segments in an easy way.
Multi-segment Applications
from http://www.devx.com/tips/Tip/14953
In Palm OS, the memory chunk size is 64K. This means that a single segment like a code segment cannot be greater then 64K. To make applications larger than this, you have to split the applications into segments less than 64K. These are called multi-segment applications. Multi-segment applications can be created with the help of a constructor. One major point to take care of is that the first segment should contain the pilot runtime library and all the code that PilotMain() calls directly.
What this means? This means that it's a lot of puzzling to make your application fit into nice 64k code segments. CGapiSurface for example is larger than 64k, which has proven to be quite the challenge to fit into the 16-bit architecture.
Little Endian / Big Endian
Applications for Palm are compiled as Motorola native code, which means that they use the Big Endian byte alignment (the high and low part is swapped). If the data type is 32-bit, the high and low words are swapped. If the data type is 16-bit, the high and low bytes are swapped. All Win32 devices use the Little Endian byte format.
While the Big Endian byte format is no big issue for most applications, it must be considered by game developers. Consider the 565 display used by the latest Palm devices, which uses the LITTLE ENDIAN byte format (Since the CPU is ARM-based). Reading a 16-bit pixel from the display results in a "GGGBBBBB RRRRRGGG" word. Operating the pixels require a byte swap before the operation, and then again a byte swap after the operation (or in some cases such as color conversion you can write specific routines for this odd pixel format). The reason the display is Little Endian, while the application is Big Endian, is simply that the ARM core of Palm OS5 uses Little Endian.
ARMLets
Some functions can be moved to separate modules called ARMLets, which in use are very similar to using assembler functions in the Win32 environment. You can only supply one parameters to an ARMLet, which is typically a 32-bit pointer to a data structure used for parameter passing. ARMLets are a way for developers to create code that use the Little Endian byte format, and can be used to access the display in a native 565 RGB format (RRRRRGGG GGGBBBBB). Unfortunately each ARMLet module can only have one main entrypoint, so encapsulating large code chunks as ARMLets is not quite that easy.
If you want to debug an application using ARMLets on the Palm Simulator on a stationary PC, each ARMLet has to be compiled into a separate Windows DLL file. In general, PalmSource does not recommend creating ARMLets if your application runs "fast enough". Read more on ARMLets here:
http://www.palmos.com/dev/support/docs/ ... apter.html
------------------------
Symbian platform
------------------------
Global variables and static member variables
Global variables are not supported in Symbian, which may cause issues for developers used to the Win32 environment. Since static member variables also are not available (preventing the use design patterns such as the Singleton pattern), it might not be clear how to work around this issue. The solution is to use a Thread Local Storage (TLS) to store one global pointer to a STRUCT created on the heap. This struct can contain unique pointers to all the global data in your application, and you can then define macros so that myglobalobject->myfunction will be replaced by Dll::Tls()->myglobalobject->myfunction. Using the TLS workaround, porting applications to Symbian is actually quite easy. The drawback is that there is a 20 cycle overhead in retreiving the TLS pointer, but in most cases this is not an issue. The solution of using a TLS is used in many cross-platform products such as Opera and GapiDraw. A DLL has it's own TLS so there should be no conflict between the GapiDraw TLS and the application TLS.
Display configurations
To get information on the current display type on Pocket PCs, a DLL called "gx.dll" is available that returns the address to the display memory and also exposes functions to lock all hardware keys. On Symbian it's not quite so easy. GapiDraw uses an undocumented function called UserSvr::ScreenInfo to get the address to the frame buffer on Symbian devices. Unfortunately, on some devices the frame buffer is offsetted by 32 bytes, and there is no way to know this beforehand. In fact, getting the frame buffer address and writing to any of these 32 bytes crashes devices such as the Motorola a920. There is also no way of knowing if the pointer points to the actual frame buffer or a back buffer. If the pointer should point to a backbuffer, developers are required to manually copy the backbuffer to the display using UserSvr::AddEvent. We will provide a test program on our web page to test the device configuration, and we will also provide a page with device information for new devices. GapiDraw does not contain information on devices since it would mean having to distribute a new DLL when new devices emerge, so this information can be added to your application using flags sent to OpenDisplay later.
In GapiDraw you specify what display type to use when you set the application configuration:
Updated 2003-12-10
Hi,
I posted this thread to make you aware of some of the issues you might experience when you are looking into targeting platforms other than Win32. Porting to Symbian is actually quite easy and requires no commercial tools (you can even use global variables if you use a combination of a TLS and macros, see below), where porting to Palm in most cases require CodeWarrior and possibly quite a few changes to your current code.
I will try to keep this thread updated as much as possible.
------------
Palm OS
------------
The current Palm OS 5 is not really designed to handle applications depending on large amounts of dynamic data, such as a game drawing high-resolution graphics to a 320x480 16-bit display. The available dynamic heap (used by surfaces) is very limited, there is no built-in image decoder, there is no file system (except when using external memory cards), and there are limited free development tools available. One of the most cumbersome issues is probably the 64k code segment limit due to the 16-bit architecture still inherent in the Palm OS5 devices, meaning that you probably have to use an off-the-shelf product such as CodeWarrior to split your application in multiple segments in an easy way.
Multi-segment Applications
from http://www.devx.com/tips/Tip/14953
In Palm OS, the memory chunk size is 64K. This means that a single segment like a code segment cannot be greater then 64K. To make applications larger than this, you have to split the applications into segments less than 64K. These are called multi-segment applications. Multi-segment applications can be created with the help of a constructor. One major point to take care of is that the first segment should contain the pilot runtime library and all the code that PilotMain() calls directly.
What this means? This means that it's a lot of puzzling to make your application fit into nice 64k code segments. CGapiSurface for example is larger than 64k, which has proven to be quite the challenge to fit into the 16-bit architecture.
Little Endian / Big Endian
Applications for Palm are compiled as Motorola native code, which means that they use the Big Endian byte alignment (the high and low part is swapped). If the data type is 32-bit, the high and low words are swapped. If the data type is 16-bit, the high and low bytes are swapped. All Win32 devices use the Little Endian byte format.
While the Big Endian byte format is no big issue for most applications, it must be considered by game developers. Consider the 565 display used by the latest Palm devices, which uses the LITTLE ENDIAN byte format (Since the CPU is ARM-based). Reading a 16-bit pixel from the display results in a "GGGBBBBB RRRRRGGG" word. Operating the pixels require a byte swap before the operation, and then again a byte swap after the operation (or in some cases such as color conversion you can write specific routines for this odd pixel format). The reason the display is Little Endian, while the application is Big Endian, is simply that the ARM core of Palm OS5 uses Little Endian.
ARMLets
Some functions can be moved to separate modules called ARMLets, which in use are very similar to using assembler functions in the Win32 environment. You can only supply one parameters to an ARMLet, which is typically a 32-bit pointer to a data structure used for parameter passing. ARMLets are a way for developers to create code that use the Little Endian byte format, and can be used to access the display in a native 565 RGB format (RRRRRGGG GGGBBBBB). Unfortunately each ARMLet module can only have one main entrypoint, so encapsulating large code chunks as ARMLets is not quite that easy.
If you want to debug an application using ARMLets on the Palm Simulator on a stationary PC, each ARMLet has to be compiled into a separate Windows DLL file. In general, PalmSource does not recommend creating ARMLets if your application runs "fast enough". Read more on ARMLets here:
http://www.palmos.com/dev/support/docs/ ... apter.html
------------------------
Symbian platform
------------------------
Global variables and static member variables
Global variables are not supported in Symbian, which may cause issues for developers used to the Win32 environment. Since static member variables also are not available (preventing the use design patterns such as the Singleton pattern), it might not be clear how to work around this issue. The solution is to use a Thread Local Storage (TLS) to store one global pointer to a STRUCT created on the heap. This struct can contain unique pointers to all the global data in your application, and you can then define macros so that myglobalobject->myfunction will be replaced by Dll::Tls()->myglobalobject->myfunction. Using the TLS workaround, porting applications to Symbian is actually quite easy. The drawback is that there is a 20 cycle overhead in retreiving the TLS pointer, but in most cases this is not an issue. The solution of using a TLS is used in many cross-platform products such as Opera and GapiDraw. A DLL has it's own TLS so there should be no conflict between the GapiDraw TLS and the application TLS.
Display configurations
To get information on the current display type on Pocket PCs, a DLL called "gx.dll" is available that returns the address to the display memory and also exposes functions to lock all hardware keys. On Symbian it's not quite so easy. GapiDraw uses an undocumented function called UserSvr::ScreenInfo to get the address to the frame buffer on Symbian devices. Unfortunately, on some devices the frame buffer is offsetted by 32 bytes, and there is no way to know this beforehand. In fact, getting the frame buffer address and writing to any of these 32 bytes crashes devices such as the Motorola a920. There is also no way of knowing if the pointer points to the actual frame buffer or a back buffer. If the pointer should point to a backbuffer, developers are required to manually copy the backbuffer to the display using UserSvr::AddEvent. We will provide a test program on our web page to test the device configuration, and we will also provide a page with device information for new devices. GapiDraw does not contain information on devices since it would mean having to distribute a new DLL when new devices emerge, so this information can be added to your application using flags sent to OpenDisplay later.
In GapiDraw you specify what display type to use when you set the application configuration:
- Code:
enum
{
SYMBIAN_P800 = 0x101F408B,
SYMBIAN_P900 = 0x101FB2AE,
SYMBIAN_7650 = 0x101f4fc3,
SYMBIAN_3650 = 0x101f466a,
SYMBIAN_NGAGE = 0x101f8c19,
SYMBIAN_6600 = 0x101fb3dd,
SYMBIAN_92x0 = 0x10005e33,
SYMBIAN_A920 = 0x101f6b26
};
void CMyApplication::ConstructL()
{
// Init code here //
// Get device ID
int tmp_muid;
HAL::Get(HALData::EMachineUid, tmp_muid);
DWORD muid = tmp_muid;
// Check for devices with buffered display access (UserSvr::ScreenInfo points to a backbuffer)
// Add devices you want to support in your application to this list
if(muid==SYMBIAN_7650 ||
muid==SYMBIAN_3650 ||
muid==SYMBIAN_6600 ||
muid==SYMBIAN_NGAGE)
{
m_config.dwDisplayFlags |= GDDISPLAY_SYMBIANBUFFERED;
}
// Check for devices with direct display access (UserSvr::ScreenInfo points to the display)
// Add devices you want to support in your application to this list
if(muid==SYMBIAN_P800 ||
muid==SYMBIAN_P900 ||
muid==SYMBIAN_92x0 ||
muid==SYMBIAN_A920)
{
// Don't call UserSvr::AddEvent after each display update
m_config.dwDisplayFlags |= GDDISPLAY_SYMBIANDIRECT;
}
// Check for devices with palette offset (UserSvr::ScreenInfo points to a 32-byte palette)
// Add devices you want to support in your application to this list
if(muid==SYMBIAN_7650 ||
muid==SYMBIAN_3650 ||
muid==SYMBIAN_6600 ||
muid==SYMBIAN_NGAGE ||
muid==SYMBIAN_92x0 ||
muid==SYMBIAN_A920)
{
m_config.dwDisplayFlags |= GDDISPLAY_SYMBIANPALETTE32;
}
// Rest of code follows //
}