Category : C++ Source Code
Archive   : C_ALL.ZIP
Filename : TI652.ASC

 
Output of file : TI652.ASC contained in archive : C_ALL.ZIP







PRODUCT : C++ NUMBER : 652
VERSION : All
OS : PC DOS
DATE : September 3, 1992 PAGE : 1/1

TITLE : Interrupt Handlers as Member Functions





A static member function of a class can be used as an interrupt
handler. It is not possible to use a 'regular or normal' member
function as an Interrupt Handler because such functions expect a
hidden parameter when called ( i.e. the 'this' pointer ) and the
Intel interrupt mechanism cannot push the 'this' pointer prior to
calling a handler. ( See your C++ documentation for more
information about the 'this' parameter passed to member functions
).


The following provides an example where a static member function
is used as an interrupt handler. The class also contains a
pointer to an instance of the class, therefore providing more
flexibility to the handler. The only requirement is that the
static pointer must be initialized to a valid instance of the
class:


#include
#include
#include


_CLASSDEF( ISR )

class ISR
{
int intNumber;
void interrupt (*oldHandler)(...);

public:
static PISR curISR;

ISR( int );
~ISR();
static void interrupt __handler(...);
virtual void handler();

virtual void justBeep();
};
PISR ISR::curISR = NULL;














PRODUCT : C++ NUMBER : 652
VERSION : All
OS : PC DOS
DATE : September 3, 1992 PAGE : 2/1

TITLE : Interrupt Handlers as Member Functions




ISR::ISR( int iNum )
{
intNumber = iNum;
oldHandler = getvect( intNumber );
setvect( intNumber, (void interrupt(*)(...))__handler );
}


ISR::~ISR()
{
setvect( intNumber, (void interrupt (*)(...))oldHandler );
curISR = NULL;
}


void interrupt ISR::__handler(...)
{
if ( curISR )
curISR->handler();
}


void ISR::handler()
{
justBeep();
}


void ISR::justBeep()
{
_AX = 0x0E07;
geninterrupt( 0x10 );
}


int main( void )
{
int key = 0;
ISR myPrintISR( 5 );

ISR::curISR = &myPrintISR;

printf("Hit ESC to terminate or PrintScreen to trigger\n" );













PRODUCT : C++ NUMBER : 652
VERSION : All
OS : PC DOS
DATE : September 3, 1992 PAGE : 3/1

TITLE : Interrupt Handlers as Member Functions




printf("the Interrupt 5 and listen to my Beep !\n" );

while( key != 27 )
{
if ( !(key = getch()) )
key = getch();
putch( key );
}
return( 0 );
}

DISCLAIMER: You have the right to use this technical information
subject to the terms of the No-Nonsense License Statement that
you received with the Borland product to which this information
pertains.




































  3 Responses to “Category : C++ Source Code
Archive   : C_ALL.ZIP
Filename : TI652.ASC

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/