home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / CLIB2.ZIP / GETVECT.CAS < prev    next >
Encoding:
Text File  |  1990-06-07  |  2.8 KB  |  85 lines

  1. /*---------------------------------------------------------------------------
  2.  * filename - getvect.cas
  3.  *
  4.  * function(s)
  5.  *      getvect - gets interrupt vector entry
  6.  *      setvect - sets interrupt vector entry
  7.  *--------------------------------------------------------------------------*/
  8.  
  9. /*[]------------------------------------------------------------[]*/
  10. /*|                                                              |*/
  11. /*|     Turbo C Run Time Library - Version 3.0                   |*/
  12. /*|                                                              |*/
  13. /*|                                                              |*/
  14. /*|     Copyright (c) 1987,1988,1990 by Borland International    |*/
  15. /*|     All Rights Reserved.                                     |*/
  16. /*|                                                              |*/
  17. /*[]------------------------------------------------------------[]*/
  18.  
  19. #pragma inline
  20. #include <asmrules.h>
  21. #include <dos.h>
  22. #include <stdlib.h>
  23.  
  24. /*--------------------------------------------------------------------------*
  25.  
  26. Name        getvect - gets interrupt vector entry
  27.  
  28. Usage        void interrupt(far *getvect(int intr_num)) ( );
  29.  
  30. Prototype in    dos.h
  31.  
  32. Description    MS-DOS includes a set of "hard-wired" interrupt
  33.         vectors, numbered 0 to 255. The 4-byte value in each vector
  34.         is actually an address, which is the location of an interrupt
  35.         function.
  36.  
  37.         getvect reads the value of the vector named by intr_num and
  38.         interprets that value read as a (far) pointer to some
  39.         interrupt function.
  40.  
  41. Return value    getvect returns the current 4-byte value stored in
  42.         the interrupt vector named by intr_num.
  43.  
  44. *---------------------------------------------------------------------------*/
  45. void interrupt (far * _CType getvect(int intr))()
  46. {
  47. asm    mov    ah, 035h
  48. asm    mov    al, intr
  49. asm    int    021h
  50. asm     xchg    ax,bx
  51. asm     mov     dx,es
  52.  
  53.         return( (void interrupt (*)()) (MK_LONG) );
  54. }
  55.  
  56.  
  57. /*--------------------------------------------------------------------------*
  58.  
  59. Name        setvect - sets interrupt vector entry
  60.  
  61. Usage        void setvect(int intr_num, void interrupt (*isr)( ));
  62.  
  63. Prototype in    dos.h
  64.  
  65. Description    setvect sets the value of the vector named by intr_num to a
  66.         new value, vector, which is a far pointer containing the
  67.         address of a new interrupt function. The address of a C
  68.         routine may only be passed to vector if that routine is
  69.         declared to be an interrupt routine.
  70.  
  71.         Note: If you use the prototypes declared in dos.h, you can
  72.         simply pass the address of an interrupt function to setvect
  73.         in any memory model.
  74.  
  75. *---------------------------------------------------------------------------*/
  76. void _CType setvect(int intr, void interrupt (far *func)())
  77. {
  78. asm    mov    ah, 025h
  79. asm    mov    al, intr
  80. asm    push    ds
  81. asm    lds    dx, dword ptr func
  82. asm    int    021h
  83. asm    pop    ds
  84. }
  85.