// C Source File // Created 2/9/01; 10:52:07 AM //Sample TSR by Greg Dietsche - Last Modification: 10/22/2002 #define TSR_NAME "SampTSR " #define OPTIMIZE_ROM_CALLS #define NO_CALC_DETECT #define USE_TI89 #include <tigcclib.h> void Install_TSR(void); void EventHandler(EVENT *ev); void AFunction(void); asm(".ascii \"evHk" TSR_NAME "\"");asm(".globl gpOldHandler");asm("gpOldHandler:");asm(".long 0");asm("__jmp__Event_Hook__:");asm("jmp Install_TSR:l"); #ifndef NO_CALC_DETECT asm(".global __calculator");asm("__calculator:");asm(".word 0"); #endif //Final offset: 22 bytes extern EVENT_HANDLER gpOldHandler; //a pointer to a pointer to the old handler //Install Function - this function will be executed ONCE, and ONLY ONCE void Install_TSR(void) { extern char __jmp__Event_Hook__; char *ptr=&__jmp__Event_Hook__; *(unsigned long*)&ptr[2]=(unsigned long)EventHandler; #ifndef NO_CALC_DETECT asm volatile("move.l 0xC8,%%a0 /* Calculator Detection */ moveq #1,%%d0 move.l %%a0,%%d1 and.l #0x400000,%%d1 jbne __calc_in_d0__ clr.w %%d0 move.l (%%a0,0x2F*4),%%a1 /* ScrRect */ cmp.b #200,2(%%a1) jbcs __calc_in_d0__ moveq #3,%%d0 _calc_in_d0__: lea __calculator(%%pc),%%a1 move.w %%d0,(%%a1) /* End Of Calculator Detection Code -- From TIGCC Sources */" : : : "a0", "a1", "d1"); #endif } void EventHandler(EVENT *ev) { EVENT_HANDLER OldHook; #ifdef OPTIMIZE_ROM_CALLS void *__saved_a5__;//a variable to save the register a5 so it can be restored later asm("/*START: Support for OPTIMIZE_ROM_CALLS*/");asm("move.l %%a5,%0":"=p"(__saved_a5__));asm("move.l 0xC8,%a5");asm("/*END: Support for OPTIMIZE_ROM_CALLS*/"); #endif if(ev->Type==CM_KEYPRESS) { if(ev->extra.Key.Code==256) { AFunction(); } } OldHook=gpOldHandler; if(OldHook) {asm("move.l %0,%%a2 /*TEOS expects the parameter to be in a2*/ move.l %%a2,-(%%sp) /*other event hooks expect it on the stack*/ move.l %1,%%a0 /*Get the address to call*/ jsr (%%a0) /*Call the next event hook*/ addq.l #4,%%sp /*restore the stack*/ "::"p"(ev),"g"(OldHook):"a0","a2"); } #ifdef OPTIMIZE_ROM_CALLS asm("/*START: Support for OPTIMIZE_ROM_CALLS*/"); asm("move.l %0, %%a5 /*support for OPTIMIZE_ROM_CALLS*/"::"p"(__saved_a5__));asm("/*END: Support for OPTIMIZE_ROM_CALLS*/"); #endif } void AFunction(void) { ST_helpMsg("vous avez pressé APPS"); }
matthieu
: enfin non pas tou, y'a un truc qui me derange, quand je dois choper le code hexa de mon tsr qui sera ds le ghost
ExtendeD
:matthieu
: enfin non pas tou, y'a un truc qui me derange, quand je dois choper le code hexa de mon tsr qui sera ds le ghost
Attention, plus de ghost sur Titanium, programmez compatible dès maintenant : http://p080.ezboard.com/ftichessteamhqfrm10.showMessage?topicID=142.topic
Toutes les commandes de compilation pour SampleTSR sont dans Make.bat.
Et SampleTSR doit être légèrement modifié pour pouvoir être compilé avec TIGCC 0.95 : http://p080.ezboard.com/ftichessteamhqfrm5.showMessage?topicID=2480.topic
error: unrecognized option `-strip' error: output filename specified twice
voila le source de hook.c // C Source File
// Created 2/9/01; 10:52:07 AM
//Sample TSR by Greg Dietsche - Last Modification: 10/22/2002
//TODO: Set Your Event Hook's Name
//Hook Name: Must Be 8 non-zero characters! Use Spaces if necessary to fill this requirement
//You should edit this to reflect the name of your event hook...
//When uninstalling your event hook, the uninstall program will use this name in its list of
//installed TSR Event Hooks
#define _NO_INCLUDE_PATCH
#define TSR_NAME "SampTSR "
//Usually this results in smaller code, OPTIMIZE_ROM_CALLS also makes calling rom functions faster
//than they would be normally
#define OPTIMIZE_ROM_CALLS
//TODO: Do you need to have TIGCC detect the calc type?
//For Sample TSR, defining NO_CALC_DETECT will result in smaller code
//You should comment this out to see if smaller code is produced in your own projects...
//Often times, undefining (commenting out) NO_CALC_DETECT will result in
//smaller code if you use the so-called psuedo constants such as KEY_UP in compat.h
#define NO_CALC_DETECT
//TODO: Select the calculators that you are compiling for...
#define USE_TI89
//Necessary Header Files
#include <tigcclib.h>
//TODO: Add your own header files, and other information that needs a global scope
void Install_TSR(void);
void EventHandler(EVENT *ev);
void AFunction(void);
//This Code needs TIGCC 0.94 beta 19 at the very least to function properly
///////////////////////
// EV_hook Header //
/////////////////////
//The Total Length of this header is 22 bytes
//The Offset to jmp Install_TSR:l is 16 bytes
//The Offset to gpOldHandler is 12 bytes
asm(".section _stl1 | First library startup section. This is what the executable starts with.
.ascii \"EvHk" TSR_NAME "\"
.globl gpOldHandler
gpOldHandler:
.long 0
__jmp__Event_Hook__:
jmp Install_TSR:l
.global __calculator
__calculator:
.word 0");
//Final offset: 22 bytes
///////////////////////////////
// End of EV_hook Header //
/////////////////////////////
//Global Variables Go Here
extern EVENT_HANDLER gpOldHandler; //a pointer to a pointer to the old handler
//Install Function - this function will be executed ONCE, and ONLY ONCE
void Install_TSR(void)
{
extern char __jmp__Event_Hook__;
char *ptr=&__jmp__Event_Hook__;
//Set EventHandler as the default entry point from now on
//instead of Install_TSR (this function)
*(unsigned long*)&ptr[2]=(unsigned long)EventHandler;
#ifndef NO_CALC_DETECT
asm volatile("
/* Start Of Calculator Detection Code -- From TIGCC Sources */
move.l 0xC8,%%a0
/* Calculator Detection */
moveq #1,%%d0
move.l %%a0,%%d1
and.l #0x400000,%%d1
jbne __calc_in_d0__
clr.w %%d0
move.l (%%a0,0x2F*4),%%a1 /* ScrRect */
cmp.b #200,2(%%a1)
jbcs __calc_in_d0__
moveq #3,%%d0
__calc_in_d0__:
lea __calculator(%%pc),%%a1
move.w %%d0,(%%a1)
/* End Of Calculator Detection Code -- From TIGCC Sources */"
:
:
: "a0", "a1", "d1");
#endif
//TODO: Add any one time initialization code here
//Warning, what ever you write here must be absolutely
//crash/error proof!!
}
void EventHandler(EVENT *ev)
{
//////////////////////////////////////////////
//Prepatory Setup for the Event Handler //
////////////////////////////////////////////
// a special variable: pointer to a function
EVENT_HANDLER OldHook;
#ifdef OPTIMIZE_ROM_CALLS
void *__saved_a5__;//a variable to save the register a5 so it can be restored later
asm("/*START: Support for OPTIMIZE_ROM_CALLS*/");
asm("move.l %%a5,%0":"=p"(__saved_a5__));
asm("move.l 0xC8,%a5");
asm("/*END: Support for OPTIMIZE_ROM_CALLS*/");
#endif
/////////////////////////////////////////////////////////////////
//////////////////////////////////////////
//Your Event Handler Code Starts Here //
////////////////////////////////////////
//TODO: write your very own event hook code
if(ev->Type==CM_KEYPRESS)
{
//this is a lame example (good april fools joke though)
if(ev->extra.Key.Code=='a')
{
ev->extra.Key.Code='A'; //now, the user cannot type a lowercase 'a'
//proof that you can call functions using this method
AFunction();
}
}
///////////////////////////////
//End of Your Event Handler //
/////////////////////////////
///////////////////////////////////////
//Call the Old hook if there was one//
/////////////////////////////////////
//get the address of the next TSR in line to be executed NULL if there is none
OldHook=gpOldHandler;
//Call the old hook if there is one to be called
if(OldHook)
{
asm(" /*This inline asm takes the place of OldHook(ev);
the difference is that a2 will also contain ev
as a parameter to support TEOS. Without this code,
you would need to use the switch -ffixed a2 when
compiling this example.*/
move.l %0,%%a2 /*TEOS expects the parameter to be in a2*/
move.l %%a2,-(%%sp) /*other event hooks expect it on the stack*/
move.l %1,%%a0 /*Get the address to call*/
jsr (%%a0) /*Call the next event hook*/
addq.l #4,%%sp /*restore the stack*/
"::"p"(ev),"g"(OldHook):"a0","a2");
}//end if(OldHook)
#ifdef OPTIMIZE_ROM_CALLS
asm("/*START: Support for OPTIMIZE_ROM_CALLS*/");
asm("move.l %0, %%a5 /*support for OPTIMIZE_ROM_CALLS*/"::"p"(__saved_a5__));
asm("/*END: Support for OPTIMIZE_ROM_CALLS*/");
#endif
}
///////////////////////////////////////////////////////////////////////////
//A Small function to prove that it is possible to call other functions //
/////////////////////////////////////////////////////////////////////////
void AFunction(void)
{
ST_hel