Menu

#48 FixedPoint-support bug

closed-out-of-date
compiler (25)
5
2001-11-05
2000-09-29
Anonymous
No

I think I'm dealing with a strangr bug of the GBDK compiler.
Please, read the following lines and help me:

_____________

typedef union _fixed2 {
struct {
BYTE l;
BYTE h;
BYTE l2;
BYTE h2;
} b;
struct {
BYTE l;
WORD pi;
BYTE h2;
} bw;
LWORD l;
} fixed2;

gravity.l = 0x0040;
velocity_y.l += gravity.l;
sprite_y.l += velocity_x.l;

__________________

yes I know that the code will seem stupid but I cut all the unuseful
lines and I pasted ONLY the three lines in which there is the error.

It seems that the compiler refuses to add correctly two variables of the
type "fixed2".
It adds all the four bytes of the longword but without the carry!
For example, the piece of code that I wrote will bug in this way:

gravity = 0x0040;
velocity_y.l += gravity.l;

( LOOP-1: velocity = 0x0040
( LOOP-2: velocity = 0x0080
( LOOP-3: velocity = 0x00c0
( LOOP-4: velocity = 0x0000 ----> ERROR!!! it should have been 0x0100
!!!!

This bug happened to me sometimes when using simple "fixed" variables
but with my "fixed2" variables, it seems to happen always.

Ah!!...
I discovered a way to make the program run properly:

velocity_y += 0x0040;
sprite_y.l += velocity_x.l;

probably it could help someone to understand the reason of the bug
because I can't surely change my code in that way :-)

_________

I'm a newbie gameboy coder and it seems really strange that nobody
experienced this bug!
Do you know a cleaner way to implement fixed-point operations??? Don'y
you use "union" of "struct"?? How can I solve my problem???

Discussion

  • Michael Hope

    Michael Hope - 2000-09-30
    • assigned_to: nobody --> michaelh
     
  • Michael Hope

    Michael Hope - 2001-11-05
    • status: open --> closed-out-of-date
     
  • Michael Hope

    Michael Hope - 2001-11-05

    Logged In: YES
    user_id=373

    This is a canned message in response to all of the pre 2.96 open
    bugs. Could you please try and reproduce this under 2.96? gbdk
    2.96 is available from the gbdk download page or from
    http://gbdk.sourceforge.net/staging.

     

Log in to post a comment.