gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Problem with our college project

#19310 - slboytoy - Fri Apr 16, 2004 10:09 pm

Hi, my group and I are doing a handheld logic analyzer, which we are using the GBA to read memory and display the waveforms accordingly. The one problem is our zooming. We have a bunch of waveforms and we can zoom in and out to give the user a better view of what they sampled. To do this, we just sample more or less spots of memory, but here is the problem.

When we try to sample more then 30 spots of memory into an array, our waveforms screw up. The code can be downloaded from..

www.slboytoy.com/program.zip

?Saving.c? is where we are sampling the test data.

?Input.c? has 18 zooms, the first two don?t work. It?s when Mem_length (the length in size of memory being sampled) goes more then 30.

Even our C++/java teacher can?t figure this one out. If anyone could fix it, I?ll call them GBA king. Lol. Thanks if anyone takes a look. Just post back, if you have any questions.

#19346 - sajiimori - Sat Apr 17, 2004 7:13 pm

I posted this last night, but to the wrong thread. ;P I've been staying up too late...
Code:

   for(i=0; i < 7; i++)
   {
      for(b=0; b < Mem_Length; b++)
      {
         if(Data[b] & (1 << i ))
            channels[i] |= 1 << ((Mem_Length - 1) - b);
      }
   }

If Mem_Length is greater than 32, you're shifting off the edge of the 32-bit long. Try long long for 64 bits (if your compiler supports it), or use a custom structure.

#19404 - slboytoy - Mon Apr 19, 2004 5:29 am

Thanks, that was one of the main things we were looking at. We tried a long, but still got the same effect, so we didn't think about it.

By long long, don't you mean a double? Over the weekend, that part is what I was thinking about looking into again, about shifting off the edge. I'll post back and let you know if we got it or not tomorrow.
Thanks again.

#19415 - slboytoy - Mon Apr 19, 2004 4:22 pm

well, i tried using long long AND double but neither of them work. you mentioned using a custom structure....will that allow us to define a 64 bit variable or is it literally a structure containing multiple ints????

#19421 - poslundc - Mon Apr 19, 2004 7:27 pm

long long is not the same as a double. long long is an integer data type, and double is a floating-point type. Although they technically both consume two 64-bit registers, as a general rule floating point types do not go well with GBA programming.

long long - in my experience with GCC - is kind of a finicky bugger and really only designed to do a few special-case things you can't do with 32-bit data types. You should not use long long for general-purpose calculations like the kind you are doing.

You should rework your code so that you cannot shift past the end of a variable. Eg. if the shift is too big, move on to the next entry in the array. Or however your application is designed.

Dan.

#19422 - sajiimori - Mon Apr 19, 2004 7:28 pm

Long long is an integer type, and on ARM-GCC it's 64 bits. Long and int are both 32 bits. Double is a floating point type, so it's totally different.

I think the problem is that the compiler assumes the result of this expression is an int:
Code:
1 << ((Mem_Length - 1) - b);
I tried get it to treat that expression as a long long by putting LL on the 1 and casting the whole expression, but it didn't work. Unless somebody else has an answer, this seems like a reasonable solution:
Code:

typedef struct { unsigned int hi, lo; } DoubleWord;

void GetChannels(...)
{
  ...
  // does this initialize all?
  DoubleWord channels[7] = {{0,0}};

  ...
  {
    int shift = Mem_Length - 1 - b;
    if(shift > 31)
      channels[i].hi |= 1 << (shift - 31);
    else
      channels[i].lo |= 1 << shift;
  }
  ...
}

Of course, you'll also have to modify Display() to handle the new type.