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.

C/C++ > Linking Math.h with DevkitARM

#106000 - Jinroh - Sat Oct 14, 2006 12:52 am

Hello all, I searched on Beginner and C/C++ boards looking for a solution to this, but I have not been able to locate one for DevKitARM.

I'm needing to include Math.h so I can utilize some functions within. However, I can't for the life of me figure out how.

If anyone could give me a hand that would be great. A sample makefile is included just in case it's a makefile thing which I believe it would be:

Path=C:\devkitPro\devkitARM\bin;%Path%
arm-elf-gcc -Wall -mthumb -mthumb-interwork -specs=gba.specs polyRotate.cpp -o polyRotate.elf
arm-elf-objcopy -O binary polyRotate.elf polyRotate.gba
gbafix polyRotate.gba

Thanks in Advance.
_________________
The lone Wolf howls, driven by pride he presses on. Knowing not where he goes, but only where he wants to be.
~Me~

#106004 - tepples - Sat Oct 14, 2006 1:13 am

#include <math.h> is deprecated on the GBA and DS for a reason. The hardware has no support for the 'float' and 'double' data types, and the software workaround is slow. Which functions in math.h were you looking for?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#106007 - Jinroh - Sat Oct 14, 2006 2:34 am

Just Sin(), Cos(), and Tan(), I'm doing a quick test porting my polygon rotation function and don't really want to generate lookup tables if I don't have to.

Thanks for the info about it being deprecated, I would've busted my skull trying to get it to work.
_________________
The lone Wolf howls, driven by pride he presses on. Knowing not where he goes, but only where he wants to be.
~Me~

#106017 - poslundc - Sat Oct 14, 2006 4:30 am

Jinroh wrote:
Just Sin(), Cos(), and Tan(), I'm doing a quick test porting my polygon rotation function and don't really want to generate lookup tables if I don't have to.


You can calculate sin() from the Taylor series: Here's how.

You can then calculate cos() from the periodic identity: cos(a) = sin(a + 90 degrees).

And tan(a) = sin(a) / cos(a).

But... you're gonna be in for a world of hurt if you don't use lookup tables. :D

Dan.

#106020 - tepples - Sat Oct 14, 2006 5:23 am

Jinroh wrote:
Just Sin(), Cos(), and Tan(), I'm doing a quick test porting my polygon rotation function and don't really want to generate lookup tables if I don't have to.

You could build a lookup table at a comparatively low resolution (maybe 64 entries in a quadrant) and, if you desire more resolution, have cos() do linear interpolation on its entries.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#106045 - Jinroh - Sat Oct 14, 2006 3:05 pm

Thanks for the input guys.

I guess I'll just do my plan b and just write the LUTs from my raycaster to a header file.

Again, I appreciate the quick response time and I'll have something cool to submit soon.

Thanks again.
_________________
The lone Wolf howls, driven by pride he presses on. Knowing not where he goes, but only where he wants to be.
~Me~

#106048 - poslundc - Sat Oct 14, 2006 6:02 pm

Jinroh wrote:
I guess I'll just do my plan b and just write the LUTs from my raycaster to a header file.


You should write it to a source file, not a header file.

A couple of explanations:
http://forum.gbadev.org/viewtopic.php?t=2605
http://forum.gbadev.org/viewtopic.php?t=8299

Dan.

#107136 - wintermute - Fri Oct 27, 2006 12:48 am

tepples wrote:
#include <math.h> is deprecated on the GBA and DS for a reason. The hardware has no support for the 'float' and 'double' data types, and the software workaround is slow. Which functions in math.h were you looking for?


#include <math.h> is not deprecated. It's not recommended that you use floating point math but there's nothing preventing you from doing so.

It can be reasonable to use functions from math.h for prototyping code or even for code where speed isn't that much of an issue.

With the devkitPro makefiles you just need to add -lm to the LIBS variable to get the code to link.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#107229 - tepples - Fri Oct 27, 2006 9:46 pm

wintermute wrote:
It can be reasonable to use functions from math.h for prototyping code

LOCKJAW: The Overdose, Vitamins, and Luminesweeper began as prototypes developed for the PC using MinGW. I can imagine that so did a lot of GBA and DS games.

Quote:
or even for code where speed isn't that much of an issue.

How large in bytes is the floating point library compared to the size of a typical GBA multiboot program?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#107288 - wintermute - Sat Oct 28, 2006 7:19 am

tepples wrote:
wintermute wrote:
It can be reasonable to use functions from math.h for prototyping code

LOCKJAW: The Overdose, Vitamins, and Luminesweeper began as prototypes developed for the PC using MinGW. I can imagine that so did a lot of GBA and DS games.


I wasn't talking about prototyping on other platforms and, being honest, I'm not entirely convinced of the value of that approach.

Certainly the compile/test cycle can be reduced when you're programming natively but prototyping a GBA game on a PC seems a little odd considering the vast differences between the platforms.

Much of the commercial work I did involved cross platform programming where a game was being written for one platform and simultaneously ported to another. When the PC was the primary platform and the port was for a console of some description there were many problems with memory usage and control schemes, not to mention trying to fit graphics into texture memory even on some of the later consoles.

Something I noticed in my commercial work was that programmers whose experience was primarily PC based tended to have problems with the restrictive nature of consoles. When your onboard memory is fixed in size without virtual memory to falll back on it can be surprisingly easy to just run out of available RAM.

Personally I feel that the GBA is an ideal starter platform for the would be game programmer. It's powerful enough to be reasonably forgiving of novice code and serves as a fun introduction to the world of embedded programming.

Quote:

How large in bytes is the floating point library compared to the size of a typical GBA multiboot program?


That depends on which floating point functions you intend to use and can vary quite a lot.

For a GBA multiboot application I would advise against using much, if any, of the standard libraries. Stdio can be quite heavy and newlib's malloc can take up a sizeable chunk. I would also tend to avoid using heavy C++ for a multiboot application.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#108908 - Jinroh - Sun Nov 12, 2006 11:48 pm

Hey,

Sorry for the delayed post,

I appreciate the assistance. I went on the Pern Project and linked a .BIN Lookup Table. Worked great.

Thanks again.
_________________
The lone Wolf howls, driven by pride he presses on. Knowing not where he goes, but only where he wants to be.
~Me~