PDA

View Full Version : floating point on nds...



21o6
06-07-2007, 08:28 PM
hi again :D

i wanted to display a sinewave on screen but ran into several
problems, which made me do a simple floatingpoint-testprogram:


Program blah;
{$APPTYPE ARM9}
{$DEFINE ARM9}
{$MODE OBJFPC}

uses
cTypes;

{$INCLUDE NDS.INC}

Var
NewX,NewY : Integer;
a,s,d : integer;
i : real;

Dummy : String;

Begin
consoleDemoInit();
videoSetMode(MODE_FB0);
vramSetBankA(VRAM_A_LCD);

lcdSwap;

i := 0;
newy := 0;

for a := 0 to 255 do
Begin
newy := trunc(i);
i:=i+1;

vram_A[(95 + NewY) * 256 + a] := rgb15(31,31,31);

Str(i,Dummy);
Dummy := Dummy + ' ';

printf(@Dummy+1);
End;

While True do;
end.

This produces:

http://members.chello.at/thedoc/real.gif

... but when i replace "real" with "integer" it works normally, shown here:

http://members.chello.at/thedoc/integer.gif


shouldn't both ways produce the same result, as i only increment
a variable by 1?

oh and: is there any other way simple way to output a non-PChar? :D

dmantione
07-07-2007, 07:33 AM
This indeed smells like a bug. Francesco, does NDS use fpu opcodes or
softfpu calls?

Despite the bug, the Nintendo devices are probably a bit too slow for
floating point calculations; use an old fashioned sine table.

JSoftware
07-07-2007, 09:43 AM
Weren't there a fixedpoint unit posted here a while ago?

21o6
07-07-2007, 10:32 AM
i wanted to create a sinetable, but that gave me odd results ... so i made
this testprogram.

err... i guess i found the problem. as far as i understand, the nds does not
support floating point ... it uses fixed point arithmetics.
see: http://dev-scene.com/NDS/Tutorials_Day_2

shame on me for not informing myself enough about the hardware.

thanks anyway :D

Legolas
07-07-2007, 10:33 AM
As far as I remember, Florian activated softfpu on arm compiler some months ago.

21o6
07-07-2007, 10:36 AM
but... it SHOULD work with i:=i+1, shouldn't it??

i'm confused.

Legolas
07-07-2007, 10:57 AM
I have tested your code and it works as expected here (on no$gba and ideas emulator) with fpc trunk 2.3. Maybe it is a bug related to 2.1.4... :think:

21o6
07-07-2007, 11:28 AM
i guess you've used arm-linux, right?

actually, i think i misunderstand something.

as far as i can see, there is no need to install fpc, as long as ppcarmnds (=fpc4nds),
devkitpro and libnds are installed...

how i know? i have downloaded 213 for i386 (which of course, like 214) does
not natively support ARM (at least i can't select a target for it) ...
but i thought "ok, just do it" and copied libnds and fpc4nds into the
directory... and as expected: no change at all.

what am i doing wrong? i mean, why should i bother installing fpc if it's not
needed at all?? i can't see where ppcarmnds connects to fpc...

21o6
07-07-2007, 01:22 PM
i wanted to tell you that i've rebuild fpc4nds from ground up and
that there are no more errors with the code i've posted :D

Legolas
07-07-2007, 01:56 PM
i wanted to tell you that i've rebuild fpc4nds from ground up and
that there are no more errors with the code i've posted :D

Cool :)
However, fpc4nds 2.1.4 worked fine too, so I really don't know what appened :?

21o6
07-07-2007, 03:09 PM
it's probably just me. i always have problems like that, without ever
knowing where they come from.

... at least i can keep the forum alive xD

thank you again :D