10Fermer12
Kevin KoflerLe 23/06/2008 à 18:06
Ça ne sert à rien d'utiliser de l'assembleur inline pour ça, voilà la même chose en C pur (par Greg Dietsche):
//thanks to Samuel Stearely for explaining how his tsr hook, complete,
//gets the pointer to the home screen text edit structure in an ams
//independent manner. I (Greg) have taken his code and ported it to C.

TEXT_EDIT *TE_findHomeScreen(void)
{
	register void *a=HomeExecute;

	while(*(unsigned long*)a!=(unsigned long)TE_select)
		a+=2;

	return (TEXT_EDIT*)(unsigned long)(*(unsigned short*)(a-4));
}

En plus rapide et plus court (extension de signe de l'adresse comme le fait le CPU lui-même) et sans fautes d'orthographe, ça donne:
// Thanks to Samuel Stearley for explaining how his TSR hook, Complete,
// gets the pointer to the home screen text edit structure in an
// AMS-independent manner. I (Greg) have taken his code and ported it to C.

TEXT_EDIT *TE_findHomeScreen(void)
{
	void *a=HomeExecute;

	while(*(unsigned long*)a!=(unsigned long)TE_select)
		a+=2;

	return (TEXT_EDIT*)(long)(*(short*)(a-4));
}

(J'ai aussi supprimé le mot-clé register qui est ignoré par GCC.) Pour avoir le handle, tu utilises TE_findHomeScreen()->Text.Handle.