/****************************************************************************** * * project name: TICT Tutorial Series 1 - PART III * file name: sample.c * initial date: 02/11/2000 * author: thomas.nussbaumer@gmx.net * * description: sample TSR (statusline clock) * * --------------------------------------------------------------- * !!!! WARNING: DON'T START THIS DIRECTLY ON YOUR CALCULATOR !!!! * -------------- otherwise your calc will crash ----------------- * * * If you want to know more on the basics of building an own clock by using an * own interrupt handler, read the TICT TUTORIAL S1P2 (here we just re-use the * code without any further explanations !! * * * build this program by typing: tigcc -O2 -outputbin sample.c * * (and convert it to C array with ttbin2hex tool from the TIGCC Tools Suite) * * * $Id: sample.c,v 1.1 2000/11/04 19:23:38 Thomas Nussbaumer Exp $ * ******************************************************************************/ #include int _ti89, _ti92plus; // produce code for TI89 and TI92plus INT_HANDLER oldint5 = NULL; // will hold the address of the previous handler later volatile int mseconds50 = 0; // counts in 50ms steps (not exact 50ms, but 1000/19 ms) volatile int seconds = 0; // counts seconds volatile int minutes = 0; // counts minutes volatile int hours = 0; // counts hours volatile int resettime = 1; // used to signal a reset clock //============================================================================= // outputs the time to the statusline //============================================================================= void PrintTime(void) { char buffer[16]; sprintf(buffer,"%02d:%02d:%02d", hours, minutes, seconds); ST_showHelp(buffer); } //============================================================================= // our own interrupt handler hooked on interrupt 5 (updates clock variables) //============================================================================= DEFINE_INT_HANDLER (myint5handler) { if (resettime) { mseconds50=seconds=minutes=hours=resettime=0; } else { mseconds50++; if (mseconds50 == 19) { mseconds50 = 0; seconds++; //------------------------------------------------------- // we have counted a second, let's update the time output //------------------------------------------------------- PrintTime(); if (seconds == 60) { seconds = 0; minutes++; if (minutes == 60) { minutes = 0; hours++; if (hours == 24) hours = 0; } } } } //--------------------------------------------------------- // execute the old interrupt handler at the end of our own // to make sure that other timers which are generated using // the AMS timer routines like OSRegisterTimer() will still // work correctly //--------------------------------------------------------- ExecuteHandler(oldint5); } //============================================================================= // the main routine of the TSR program // // NOTE: this routine is called twice !! // // One time to install our handler and a second time to remove it again //============================================================================= void _main(void) { if (oldint5) { //-------------------------------------------------- // if TSR is already running (oldint5 != 0), stop it // by restoring the old interrupt vector //-------------------------------------------------- SetIntVec(AUTO_INT_5, oldint5); oldint5 = NULL; // make sure that oldint5 is zero afterwards } else { //----------------------------------------------------------- // the TSR is not running till now // backup the old interrupt handler address in global oldint5 // and install our own handler //----------------------------------------------------------- resettime = 1; oldint5 = GetIntVec(AUTO_INT_5); SetIntVec(AUTO_INT_5, myint5handler); } } //============================================================================= // Revision History //============================================================================= // // $Log: sample.c,v $ // Revision 1.1 2000/11/04 19:23:38 Thomas Nussbaumer // initial version // // //