home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c222 / 1.ddi / SOURCE / IBMLIB / IN_HANDL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-10  |  1.8 KB  |  93 lines

  1. /*********************
  2.  *
  3.  *  in_handl.c - interrupt handler function.
  4.  *
  5.  *  Purpose: This file contains the handler functions for general
  6.  *           interrupts of the IBM PC.
  7.  *
  8.  *  Blackstar C Function Library
  9.  *  (c) Copyright 1985,1989 Sterling Castle Software
  10.  *
  11.  *******/
  12.  
  13. #include <dos.h>
  14. #include <process.h>
  15. #include <stdlib.h>
  16. #include "blackstr.h"
  17. #include "sc_head.h"
  18. #include "primitiv.h"
  19.  
  20.  
  21. /********
  22.  *
  23.  *   in_setint(vector,function,stack,type) - set an interrupt
  24.  *
  25.  **/
  26.  
  27. int in_setint(int vector, int (*function)(), char *stack, int type)
  28. {
  29.     int stseg,stoff,cseg,off;
  30.     struct SREGS segs;
  31.  
  32.     segread(&segs);
  33.     if(!stack)
  34.     stack = malloc(10);      /* create a stack location from heap */
  35.     cseg = sy_pseg(function);
  36.     off = sy_poff(function);
  37.     stseg = sy_dseg(stack);
  38.     stoff = sy_doff(stack);
  39.     return(in_setvec_(vector,off,cseg,stoff,stseg,type));
  40. }
  41.  
  42.  
  43. /********
  44.  *
  45.  *   in_remint - remove previously set interrupt
  46.  *
  47.  **/
  48.  
  49. int in_remint(int intno)
  50. {
  51.     return(in_remvec_(intno));  /* just use primitive */
  52. }
  53.  
  54.  
  55. /********
  56.  *
  57.  *   in_tsr() - terminate and stay resident
  58.  *
  59.  **/
  60.  
  61. void in_tsr(void)
  62. {
  63.     _far char *start;
  64.     _far char *end;
  65.     long length;
  66.     struct SREGS segs;
  67.  
  68.     if (_osmajor < 2) {
  69.     puts("TSR requires DOS version 2 or over.\n");
  70.     exit(-1);
  71.     }
  72.  
  73.     if (sizeof(char *) == 2)  /* Small data model */
  74.        length = 65535;
  75.     else {
  76.     FP_SEG(start) = getpid();
  77.     FP_OFF(start) = 0;
  78.  
  79.     segread(&segs);
  80.     FP_SEG(end) = segs.ss;
  81.     FP_OFF(end) = 0xffff;
  82.  
  83.     length = FP_SEG(end) - FP_SEG(start);
  84.     length = (length << 4) + FP_OFF(end) - FP_OFF(start);
  85.     }
  86.  
  87.     if (length & 0xf)         /* round up to next 16 byte paragraph */
  88.     length += 0x10;
  89.     length >>= 4;             /* convert to paragraphs */
  90.     _dos_keep(0, length);
  91. }
  92.     
  93.