PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

GapiDraw Palm/Symbian notes (2003-12-10)

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:

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 //
}
Thanks for the info Johan! I guess its time to order CodeWarrior and start reading up on Palm programming.
Will you include sample codes in your future versions of gapidraw Johan? I think this will be beneficial to us especially in the Palm department. :)
Of course.. We have all samples split into separate folders now, such as:
samples\palm
samples\symbian
samples\win32

The release candidate of GapiDraw 2.10 ships not only with symbian sample projects, but also with installation files for all the samples so you can install them directly to a Symbian phone.

Basically you want to have different folders for your project files and the "myapplication" files, but the rest could probably be shared between platforms.
If you have a game which doesn't use global variables at all, but everything is stored inside the classes, does that mean that porting to Symbian should be very easy? Then it is just a matter of removing the static members...

Maurice
Pejo Software - Per · 06 Jan 2004, 21:47 UTC
:x
I am so stupid!!!!!
I am coding on Beshaped 2 and I thought things were coming along fine. My goal is that I shall be able to use the same source code for PPC, Smartphone, Symbian, Palm and Windows. I was thinking that I am not using any OS dependent calls, but I did not read this carefully enough and I just saw something about global variables and thought: fine I am not using any. The problem is that I use a lot of static member variables!

So I guess this means I will be forced to do some major refactoring now! Sometimes it really helps to pay attention!

Does this mean that the best way would be to start passing pointers around like a mad man! I really don't like that!
maurice wrote:[...]does that mean that porting to Symbian should be very easy?

Yes, that's the main point :D
It should be a matter of hours to port it if you got your Symbian tool chain installed.
That was me. I thought I was logged in...

/Jonas
PeJo: You can use a Thread Local Storage on Symbian to "simulate" global variables. Or pass a pointer to a system-global "System Properties" class to each class you create. I would recommend the last option since you don't have to mess too much with Symbian Macros and the 20 instruction set overhead in retrieving the TLS pointer...
Johan,

I have a few questions regarding gapidraw for symbian.

1) Have you benchmarked gapidraw and compaired to how it fairs against normal blit method using FB on symbian 60? If so was there a huge speed increase or was it relatively mild?

2) Can gapidraw be modified in a way to work in .exe insted of .app for symbian 60? I ask because I ported over a win32 applilcation to a symbian exe insted of app due to global varibles (they are allowed in exe). If no, do you plan to add suport in the future?
Hello subbie,

I know that you asked for Johan to answer, but I thought that i could chip in with a little info...

1) Have you benchmarked gapidraw and compaired to how it fairs against normal blit method using FB on symbian 60? If so was there a huge speed increase or was it relatively mild?


Myself and Jonas have done some basic benchmarking, but I don't have the actual figures in front of me. We'll post the figures later together with an explanation of our approach.

2) Can gapidraw be modified in a way to work in .exe insted of .app for symbian 60? I ask because I ported over a win32 applilcation to a symbian exe insted of app due to global varibles (they are allowed in exe). If no, do you plan to add suport in the future?


Actually, you can use GapiDraw from an exe as it is now, but then you have to provide your own image loading. All blit functions etc. works though. If you choose to do this, you must make your own equivalent of CGapiApplication as there is no easy way to make the one provided in the installation to work in an .exe.

//Erik
Actually, you can use GapiDraw from an exe as it is now, but then you have to provide your own image loading. All blit functions etc. works though. If you choose to do this, you must make your own equivalent of CGapiApplication as there is no easy way to make the one provided in the installation to work in an .exe.


Why is it that image loading functions would have to be provided by my self in an exe program? Also is there a specific setup I need to convert the loaded image into before passing it to gapi?

Another question I have is, is there a specific bit function in gapi I can use to pass it a pointer to an array holding my actual framebuffer in the standard 4:4:4 setup? (i'm still learning and going though the examples and just trying to see a good way to send it informaiton on a per pixel basis since the program has a preset framebuffer thatn I normaly just pass to a symbian 60 buffer then blit to the screen).

thanks for the reply,

- Brian
is there a specific bit function in gapi I can use to pass it a pointer to an array holding my actual framebuffer in the standard 4:4:4 setup?


Yes.. CGapiSurface::GetBuffer() (e.g. m_pBackBuffer->GetBuffer()). See the Plasma demo for details in the Win32 folder.
BETA1 seems to work in the simulator, and on Tungsten E, but both are horribly slow. For example, on a Tungsten E device, the simple sample gets 5fps/200ms and only displays the black screen with border, the icons, the center message, and the frame info, I see nothing else.
When I compile Simple for Palm BETA1, I get 22 compiler errors. All are undefined identifiers, the first is GapiApplication.cpp line 80 undefined identifier 'pinCreator'

I am using the latest CodeWarrior. What is misconfigured?
mlepage: We have improved performance significantly in the beta2 release. Please let me get back to you on the problem you experienced on Monday.
If it helps, I have a fresh install of CW9, updated from CD to 9.2, then updated from web to 9.3. I did the recommended install, and I don't think I've changed anything since.

I would like to be able to unzip GapiDraw for Palm into a folder, open the sample project in CodeWarrior, and have everything work out of the box.

What version of the Palm SDK are you using? CW9.3 only has SDK 5.0r2, not 5.0r3. Are any other SDKs (like the 5-way navigator) SDK required?
OK I answered my own question.

Searching all files in SDK 5.0r3 for "pinCreator" reveals it is in PenInputMgr.h.

Searching all files in CW9.3 for "pinCreator" reveals no results. There is no such header file.

Obviously the latest SDK is required. GapiDraw 3.01 BETA1 requires Palm SDK 5.0r3 which is not present in CW 9.3 update.

Guys, on your web page you say only "requires CodeWarrior 9." You have to be a little more specific about little details like this, savvy?

It builds fine with the latest SDK.
Either I'm doing something wrong or some images aren't working on Tungsten E.

I don't see the PDA image that should be rotozooming in the simple sample. I edited the sample to remove the keysrc/rotation/scaling from the blit and I still don't see it on the device.

I don't see it in Simulator 5.2 either.

I do see the three taskbar icons (minimize, orient, and exit), and the bitmapped text.
Could you try catching the return code from CreateSurface on the large PDA to see why it's not functioning. You could write it to the display using the built-in system font..

We are working on several variations internally of the Palm release.. Thanks for pointing out the SDK requirements, I'll modify the web page later today...
Yup I'll check it after a night's sleep.
By the way, I just saw that the readme-file included already specified that Palm OS SDK R3 is required. :) I have updated the frontpage on gapidraw.com with additional information though...
http://www.gapidraw.com/doc/301/doc-readmepalm.htm
OK I had read the readme originally, but when I went to actually try GapiDraw I just went by the web page.

I captured the return code, and now it is working. The image shows up in both simulator and on Tungsten E, with return code 0. It isn't keysrced, rotated, or scaled, so it fits the screen (remember I edited my simple sample). On Tungsten E it is running at 5.2fps, 192ms.

I removed the return code print and it still showed the image on simulator and Tungsten E, so I don't know what changed between last night and today, but I get the image now. Incidentally, without printing the return code, I get 5.58fps, 179ms on the device.

When I add back the keysrc/rotation/scaling, I lose the image again, in both simulator and on the device.

If I then add back printing the return code, it is 0 (on the device). So the surface is loading but it is not displaying. So let's test on the device, printing the result code.

If I remove flags except for keysrc, it displays and gets 5.24fps, 187ms.

If I remove flags except for rotationangle, I don't see the image.

If I remove flags except for rotationscale, I don't see the image.

So neither rotation nor scaling are working for me. The good news is, they don't seem to work in Palm Simulator 5.2 either, so you have a target you can test on even if you don't have a Tungsten E.
Ah.. :) You need mathlib on your device to see the rotation.. Sorry for that..
By the way, memory reads on Palm are terribly slow.. All memory access seems to go through handles, even if large blocks are allocated through MemGluePtrNew. That's basically why the rotation algorithm (once you get it up and running) is one of the slowest operations.

By the way, the simple demo got from 12fps to 20fps in beta2 in 320x480 on the T3.
Yes Palm is like Mac, it uses handles for everything. The OS can shuffle memory around underneath the application. You have to lock/unlock handles when you want to use them.

I will try to try rotation etc. later, but I'll assume for now that it should work with MathLib. I take it MathLib isn't installed by default on Palm devices?
Unfortunately it's not installed. And mathlib is not even a Palm shared library, it's from a third party.. Just to get sin/cos... GapiDraw require mathlib for the Blt rotation - if it's not installed it will simply not draw anything. We will try to add a new return code for the final 3.01. I'll add the mathlib requirement to the readme tomorrow...

It actually is possible to use pointers directly in Palm OS 3.5 and later to allocate memory (and to avoid locking handles), but in my experience these pointers still use handles underneath which cause significant overhead in all memory operations (even when using native PACE ARMlets like in GapiDraw).
ergo_etc · 26 Apr 2004, 02:33 UTC — Razor
Perhaps GapiDraw can take a cue from "Razor". Freeware game engine for Palm. It doesn't do whole screen blitting all the time and performance is so much better.

The source code is freely available, perhaps you guys can copy a few tricks they use...