home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / ISC366.ZIP / ISC / ISC.H < prev    next >
C/C++ Source or Header  |  1993-09-01  |  6KB  |  129 lines

  1.  
  2. ////////////////////////////////////////////////////////////////////////////
  3. //                                                                        //
  4. //            File: Isc.h                                                 //
  5. //            started on: 5/2/92                                          //
  6. //                                                                        //
  7. ////////////////////////////////////////////////////////////////////////////
  8. //                                                                        //
  9. //                              V3.66                                     //
  10. //                            ---------                                   //
  11. //                                                                        //
  12. ////////////////////////////////////////////////////////////////////////////
  13. //                                                                        //
  14. //  - DO not use the TINY memory model.                                   //
  15. //                                                                        //
  16. ////////////////////////////////////////////////////////////////////////////
  17. //                                                                        //
  18. // new in V3.0:- the dispatch method has been moved to mostly C code.     //
  19. //                                                                        //
  20. // new in V3.5:- the assembler part has been optimized significantly.     //
  21. //      + An example of stack frame management has been added.            //
  22. //                                                                        //
  23. // new in V3.6:- the stack frame has been integrated into ISC itself.     //
  24. //      + the way of calculating how much space the program takes has been//
  25. //        updated to ensure that no heap blocks may be forgotten (that    //
  26. //        may of happened in the V3.5-- method!).                         //
  27. //                                                                        //
  28. // new in V3.66:- Interrupt handlers that are not TSRs (like in embedded  //
  29. //      + systems) can use #define __NOT_TSR__ to make lib smaller- and   //
  30. //        more compatible. Assume DS/SS problem solved. But DO NOT USE    //
  31. //        ASSUME ALWAYS IN MEDIUM- LARGE models (might be a problem!).    //
  32. //                                                                        //
  33. ////////////////////////////////////////////////////////////////////////////
  34. //                                                                        //
  35. //                    by Ofer Laor (AKA LeucroTTA)                        //
  36. //                                                                        //
  37. ////////////////////////////////////////////////////////////////////////////
  38.  
  39. #ifndef __ISC_H
  40. #define __ISC_H
  41.  
  42. #if (__BORLANDC__< 0x300)
  43. #error Fatal: ISC will only work on BC++ versions 3.0 and up!!!
  44. #endif
  45.  
  46.  
  47. #pragma option -k    // standard stack frame from now on...
  48.  
  49. #include <stddef.h>; // NULL, size_t.
  50.  
  51. struct IBYTEREGS  {
  52.   unsigned char  al, ah, bl, bh,
  53.                  cl, ch, dl, dh;
  54. };
  55.  
  56. struct IWORDREGS  {
  57.   unsigned int  ax, bx, cx, dx,
  58.                 si, di, ds, es, cs, flags, ip, bp;
  59. };
  60.  
  61.  
  62. union IREGS {
  63.       struct IWORDREGS x;
  64.       struct IBYTEREGS h;
  65. };
  66.  
  67.  
  68. extern "C" void interrupt ISCDispatch(unsigned bp, unsigned di, unsigned si,
  69.                            unsigned ds, unsigned es, unsigned dx,
  70.                            unsigned cx, unsigned bx, unsigned ax,
  71.                            unsigned ip, unsigned cs, unsigned flags
  72. );
  73.  
  74. class ISC {
  75. protected:
  76.  
  77.        virtual void isr (IREGS ®s);
  78.        virtual void isr (void);
  79.  
  80.        char* NewServerPtr;
  81.        unsigned char InitFlag;
  82.        int interrupt_num;
  83.        void interrupt (*old_vect)(...);
  84.  
  85.        friend void interrupt ISCDispatch(unsigned bp, unsigned di, unsigned si,
  86.                            unsigned ds, unsigned es, unsigned dx,
  87.                            unsigned cx, unsigned bx, unsigned ax,
  88.                            unsigned ip, unsigned cs, unsigned flags);
  89.        virtual void far * GetLocalRoutine(void);
  90.  
  91.        static char *StackFrame;
  92.        static unsigned long StackFrameLen;
  93.        static int ISCcount;
  94.  
  95.        ISC (void);
  96.        virtual ~ISC (void);
  97. public:
  98.        void activate(const int int_num); // call this function if you want to
  99.                                          // hook an interrupt, and you didn't
  100.                                          // do it through the constructor.
  101.        void deactivate(void); // call this function to unhook the interrupt.
  102.  
  103. #ifndef __NOT_TSR__
  104.        static int TSR(const int exit_code= 0, const unsigned long extraheaplen= 0);
  105.                                          // call this function to remain TSR,
  106.                                          // exit code ususaly is 0 (unless
  107.                                          // you change it), extraheaplen is
  108.                                          // the amount of heap you want to
  109.                                          // remain on top of what's already
  110.                                          // allocated... (makes the TSR
  111.                                          // longer in that many bytes...).
  112.  
  113.        static int is_TSR(const char* app_name);
  114.                                          // checks to see if this program is
  115.                                          // already resident.
  116.                                          // it checks for another TSR that
  117.                                          // called the is_TSR with the same
  118.                                          // app_name...
  119. #endif
  120.        static int reallocStack(unsigned StackLen);
  121.                                          // reallocates the stack frame.
  122.                                          // HAS to be called BEFORE any ISC
  123.                                          // is active!!!
  124.  
  125. };
  126.  
  127.  
  128. #endif /* __ISC_H */
  129.