As most of you probably have already noticed, Binary Clock for Palm OS now supports the WristPDA. When creating the WristPDA frontend, I decided to add a cool new feature that shows the battery status permanentely(not only if low).

Recreating the Palm OS battery gadget is not too difficult, however, the program simply didn’t work. I managed to track the bug down to a line like this one:

srcrect.extent.x=0.3*percent;

A bit of research made me find out that most Palm OS compilers need globals to execute this operation – multiplication was no option, and division wasnt either. However, as you can see in the image below, the battery gadget works. But why?
DSC00017 Dont multiply when in non globals mode

I decided to substitute the multiplication with a lookup table. Here is the new code:

UInt8 coord[101]={0,0,0,0,1,1,1,2,2,2,3,3,3,3,4,4,4,5,5,5,6,6,6,
6,7,7,7,8,8,8,9,9,9,9,10,10,10,11,11,11,12,12,12,12,13,13,13,
14,14,14,15,15,15,15,16,16,16,17,17,17,18,18,18,18,19,19,19,
20,20,20,21,21,21,21,22,22,22,23,23,23,24,24,24,24,25,25,25,26
,26,26,27,27,27,27,28,28,28,29,29,29,30};
srcrect.extent.x=coord[percent];

Obviously, lookup tables don’t work for very big ranges of numbers – however, when you have less than a few hundred values, they make for a very good way around the problem.

Ever had such a problem?

Related posts:

  1. Globals in DAs
  2. Attention to all GMAIL users-DONT FOLLOW THE GMAIL HACK
  3. Drive Mode / MS Import in background
  4. Switch-Mode power supplies explained
  5. Binary Clock 3.0 is here…and it supports the Watch Face mode of the WristPDA!

5 Responses to “Don’t multiply when in non-globals mode”

  1. Floating point multiplication and division need globals, I believe because they resolve into calls to the FloatMgr. But if you wrote something like

    srcrect.extent.x=percent/3;
    that should be just fine, since it’ll end up as integer division, which doesn’t need the FloatMgr…

    Later,
    Blake.

  2. Why do you need float for such a task at all? Come on and think before posting…

  3. Hi,
    I used no float here…just a plain C multiplication….

    Best regards
    Tam Hanna

  4. I’m not very familiar with C (Java fan), but 0.3 seems to be a float value, isn’t it? I think Blake Winton was right.

  5. surly no need for floats as someone pointed out. also if you call float point manager directly using the sysTrap FlmEm, you need no globals. try it….

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting

© 2013 TamsPalm - the Palm OS / web OS Blog Suffusion theme by Sayontan Sinha