Dec 282017
 
BC++ class for ISR (interrupt handlers) that are instance specific.
File ISRCPP.ZIP from The Programmer’s Corner in
Category C++ Source Code
BC++ class for ISR (interrupt handlers) that are instance specific.
File Name File Size Zip Size Zip Type
HANDLER.CPP 2369 792 deflated
HANDLER.H 4704 1195 deflated
READ.ME 2339 1009 deflated
TEST.CPP 581 294 deflated
TEST.DSK 2723 922 deflated
TEST.PRJ 5138 1075 deflated

Download File ISRCPP.ZIP Here

Contents of the READ.ME file


This file contains a class for implementing instance-specific ISRs in a
clean, abstact manner. For instance , if you want to develope a serial
port ISR class such that two instances of it can service two different
interrupts, then all you have to do is:

#include "Handler.h"

class CommIsr : public Handler
{
public:
CommIsr(){}

virtual void far handler( HandlerRegs far * );
};

void far CommIsr::handler( HandlerRegs far * )
{
...
// code here to handle the interrupt
...
outportb( 0x21, 0x21 );
}

// In use:

...
CommIsr com1;
...
com1.install( 0x0C );
...
// if INT 0Ch occurs, com1.handler() will be called
...
com1.uninstall();

Or say that you want a class that will chain into the timer interrupt (0x1C)
so that multiple instances will be serviced by each timer interrupt. You
would code this like:

#include "Handler.h"

class TimerIsr : public Handler
{
public:
TimerIsr() : count(0){}

unsigned getCount(){return count;}

virtual void far handler( HandlerRegs far * );

protected:
unsigned count;
};

void far TimerIsr::handler( HandlerRegs far * )
{
count++;
}

// In use:

...
TimerIsr isr1, isr2;

isr1.chain( 0x1C );
isr2.chain( 0x1C );
...

isr1.uninstall();
isr2.uninstall();

In this instance , every time INT 1Ch occurs (15.2 times per second),
isr2.handler() is called, then isr1.handler() is called, then the original
ISR routine is called.

The concept behind Handler is not that difficult. Whenever you call
install() to install the handler (or chain() to chain into the handler),
a small memory buffer is allocated, and default code is copied into it: this
is the purpose of Handler::stdisr and Handler::chainisr. Both of these code
fragments contain a snippet that initializes a Handler far * to 0. What
install (and chain) do is to modify this code copy so that the Handler far *
is actually initialized the the "this" pointer for that instance of Handler;
then this copy of the code (which now references this instance of Handler) is
used as the ISR.

Pat Reilly
CIS: 70274,161
Please leave messages public on the BCPPDOS forum (C++ section) so that
others can benefit from any questions you may have on this class.


 December 28, 2017  Add comments

Leave a Reply