<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://dsibrew.org/w/index.php?action=history&amp;feed=atom&amp;title=Sourcecode%2Ftp.c</id>
	<title>Sourcecode/tp.c - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://dsibrew.org/w/index.php?action=history&amp;feed=atom&amp;title=Sourcecode%2Ftp.c"/>
	<link rel="alternate" type="text/html" href="https://dsibrew.org/w/index.php?title=Sourcecode/tp.c&amp;action=history"/>
	<updated>2026-05-02T11:49:54Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>https://dsibrew.org/w/index.php?title=Sourcecode/tp.c&amp;diff=2800&amp;oldid=prev</id>
		<title>Neimod: New page: &lt;source lang=cpp&gt;  /*     Read touchscreen positions.      Returns 1 if touched, and the average position in xpos and ypos. Otherwise, if not touched, returns 0.  */  u32 TouchRead(u32* xp...</title>
		<link rel="alternate" type="text/html" href="https://dsibrew.org/w/index.php?title=Sourcecode/tp.c&amp;diff=2800&amp;oldid=prev"/>
		<updated>2010-03-21T01:24:06Z</updated>

		<summary type="html">&lt;p&gt;New page: &amp;lt;source lang=cpp&amp;gt;  &lt;span class=&quot;autocomment&quot;&gt;Read touchscreen positions.      Returns 1 if touched, and the average position in xpos and ypos. Otherwise, if not touched, returns 0.: &lt;/span&gt;  u32 TouchRead(u32* xp...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;source lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
    Read touchscreen positions.&lt;br /&gt;
&lt;br /&gt;
    Returns 1 if touched, and the average position in xpos and ypos. Otherwise, if not touched, returns 0.&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
u32 TouchRead(u32* xpos, u32* ypos)&lt;br /&gt;
{&lt;br /&gt;
	int i;&lt;br /&gt;
	u8 buf[20];&lt;br /&gt;
	u16 x[5];&lt;br /&gt;
	u16 y[5];&lt;br /&gt;
	u32 xavg;&lt;br /&gt;
	u32 yavg;&lt;br /&gt;
	u8 state;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	state = CDC_ReadRegisterEx(3,9);&lt;br /&gt;
	if ( (state &amp;amp; 0xC0) == 0x40 )&lt;br /&gt;
		return 0;&lt;br /&gt;
&lt;br /&gt;
	state = CDC_ReadRegisterEx(3, 14);&lt;br /&gt;
	if (state &amp;amp; 2)&lt;br /&gt;
		return 0;&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
	CDC_ReadRegistersEx(252, 1, buf, 20);&lt;br /&gt;
&lt;br /&gt;
	xavg = 0;&lt;br /&gt;
	yavg = 0;&lt;br /&gt;
&lt;br /&gt;
	for(i=0; i&amp;lt;5; i++)&lt;br /&gt;
	{&lt;br /&gt;
		x[i] = buf[i*2+1] | (buf[i*2+0]&amp;lt;&amp;lt;8);&lt;br /&gt;
		y[i] = buf[10+i*2+1] | (buf[10+i*2+0]&amp;lt;&amp;lt;8);&lt;br /&gt;
&lt;br /&gt;
		if (x[i] &amp;amp; 0xF000)&lt;br /&gt;
			return 0;&lt;br /&gt;
		&lt;br /&gt;
		if (y[i] &amp;amp; 0xF000)&lt;br /&gt;
			return 0;&lt;br /&gt;
&lt;br /&gt;
		xavg += x[i];&lt;br /&gt;
		yavg += y[i];&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	xavg /= 5;&lt;br /&gt;
	yavg /= 5;&lt;br /&gt;
&lt;br /&gt;
	*xpos = xavg;&lt;br /&gt;
	*ypos = yavg;&lt;br /&gt;
&lt;br /&gt;
	return 1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Neimod</name></author>
	</entry>
</feed>