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 > Question about touch pixel position

#74872 - patroclus02 - Wed Mar 08, 2006 11:58 am

Hello,

I'm going through http://www.double.co.nz/nintendo_ds/index.html tutorial
I'm trying to understand how the demos work, though it is quite difficult to figure out everything, as there're lots of defines, procedure, and so on.

So far, I wonder how does first demo calculate pixel position touched.

It defines

Code:

#define TOUCH_CAL_X1 (*(vs16*)0x027FFCD8)
#define TOUCH_CAL_Y1 (*(vs16*)0x027FFCDA)
#define TOUCH_CAL_X2 (*(vs16*)0x027FFCDE)
#define TOUCH_CAL_Y2 (*(vs16*)0x027FFCE0)


and the calculates

Code:

s32 TOUCH_WIDTH  = TOUCH_CAL_X2 - TOUCH_CAL_X1;
s32 TOUCH_HEIGHT = TOUCH_CAL_Y2 - TOUCH_CAL_Y1;
s32 TOUCH_OFFSET_X = ( ((SCREEN_WIDTH -60) * TOUCH_CAL_X1) / TOUCH_WIDTH  ) - 28;
s32 TOUCH_OFFSET_Y = ( ((SCREEN_HEIGHT-60) * TOUCH_CAL_Y1) / TOUCH_HEIGHT ) - 28;



so when you retrieve x and y positions (not given in pixels when calling touchRead), it computes the real pixel data doing:

Code:

xpx = ( ((SCREEN_WIDTH -60) * x) / TOUCH_WIDTH  ) - TOUCH_OFFSET_X;
      ypx = ( ((SCREEN_HEIGHT-60) * y) / TOUCH_HEIGHT ) - TOUCH_OFFSET_Y;
     


I don't understand how this is done. why - 60? why - 28?...
As I read it is a calibrating routine or something like that.

But, if you use your own IRQ handler, you need to do this? or in latest NDSLIB you can just use IPC->touchXpx or touchRead without including the above code in the handler??

Thank you

#74873 - natrium42 - Wed Mar 08, 2006 1:11 pm

This is very old code. That tutorial is outdated... You should look at the examples from LibNDS (not NDSLIB).
_________________
www.natrium42.com

#74881 - patroclus02 - Wed Mar 08, 2006 1:56 pm

Thank you, I'm working with demo shipped with LibNDS.

But I see no code for ARM7 and code for ARM9. I just see all code in the same c++ source file. So, there's no need to write code separately, or tell the compiler which is which?

And last thing, makefile confuses me. It is different from the one used in the tutorial. Is there any place I can read about how does this makefile work? I see some comments in it, but I don't see where the compiler and linker are called.
I see editing makefile is necessary for somethings like to make a header file for access to binary data.

Thank you!

#75105 - HyperHacker - Fri Mar 10, 2006 3:38 am

I think it uses default ARM7 code if you don't give it any.

#75128 - patroclus02 - Fri Mar 10, 2006 9:43 am

Thanks.
Yes, it seems it that tasks such as get screen touch position or X/Y buttons are done by default ARM7 code, so you automatically can use them in ARM9.