home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / C / ISC365 / ISC.H < prev    next >
C/C++ Source or Header  |  1992-10-15  |  6KB  |  130 lines

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