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.

DS development > atan2 on DS?

#59044 - Extreme Coder - Fri Oct 28, 2005 11:29 am

Hi. I've been looking for the trigonometry function "atan2" on the ds, but with no luck. AFAIK, the GBA had one in its bios,right? Because then I don't want to be forced to use math.h, since it would be much slower on the ds.

#59054 - strager - Fri Oct 28, 2005 1:05 pm

There is an SWI/BIOS call/function for atan2: SWI 10. Here's how to use it (not sure if it's the best way, or if it works):

Code:
// Assumed to be compiled as ARM code
int swi_atan2(int x, int y)
{
    int result;

    asm volatile(
    "mov r0, %1\n"
    "mov r1, %2\n"
    "swi #0x000A0000\n"
    "mov %0, r0"
    : "=r" (result)
    : "r" (x), "r" (y)
    : "r0", "r1", "r2", "r3");
};

// If you are using C this might work
// Again, ARM is expected
int swi_atan2_c(int x, int y)
{
    asm("swi #0x000A0000\n");
};


GBATek Specifications wrote:
SWI 10 (0Ah) - ArcTan2
Calculates the arc tangent after correction processing.
Use this in normal situations.

r0 X, 16bit (1bit sign, 1bit integral part, 14bit decimal part)
r1 Y, 16bit (1bit sign, 1bit integral part, 14bit decimal part)

Return:

r0 0000h-FFFFh for 0<=THETA<2PI.


Hope this helps!

#59059 - Extreme Coder - Fri Oct 28, 2005 3:32 pm

Thanks strager. But this is for the DS,right? Just want to make sure since you mention GBATek there, I'm guessing there might be a difference in the DS.

#59080 - strager - Fri Oct 28, 2005 9:22 pm

Extreme Coder wrote:
Thanks strager. But this is for the DS,right? Just want to make sure since you mention GBATek there, I'm guessing there might be a difference in the DS.

Yes, it is for the DS. That function, as well as some others, are the same as in the GBA.

#59123 - Extreme Coder - Sat Oct 29, 2005 9:34 am

Thanks strager, I just had my doubts that it wouldn't be in the DS bios since it isnt mentioned anywhere in NDSTech Wiki, or DSTek.

I will try it anyway.

#59185 - Joat - Sun Oct 30, 2005 3:33 am

I don't mention it anywhere on the wiki, because it doesn't exist!

Quoth the revevant portion of the ARM9 bios, nevermore:

Code:
swiTable:
.word   swi00_SoftReset
.word   0x00000000   @ 01
.word   0x00000000   @ 02
.word   swi03_Delay|1
.word   swi04_IntrWait
.word   swi05_WaitForVBlank
.word   swi06_WaitForIRQ
.word   0x00000000   @ 07
.word   0x00000000   @ 08
.word   swi09_Divide
.word   0x00000000   @ 0A
.word   swi0B_CpuSet|1
.word   swi0C_CpuFastSet
.word   swi0D_Sqrt
.word   swi0E_CRC16|1
.word   swi0F_IsDebugger|1

.word   swi10_UnpackBits
.word   swi11_DecompressLZSSWram
.word   swi12_DecompressLZSSVram|1
.word   swi13_DecompressHuffman|1
.word   swi14_DecompressRLEWram|1
.word   swi15_DecompressRLEVram|1
.word   swi16_DecodeDelta8|1
.word   0x00000000   @ 17
.word   swi18_DecodeDelta16|1
.word   0x00000000   @ 19
.word   0x00000000   @ 1a
.word   0x00000000   @ 1b
.word   0x00000000   @ 1c
.word   0x00000000   @ 1d
.word   0x00000000   @ 1e
.word   swi1F_SetHaltCR|1


Notice the hole at swi 0x0A with an entry of zero. Bad things will happen if you call it.
_________________
Joat
http://www.bottledlight.com

#59193 - tepples - Sun Oct 30, 2005 5:57 am

Then it might have been clearer to mention the holes themselves.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.