home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 267.img / RESIDNTC.ZIP / DEMOS.ZIP / RESLIB.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-13  |  4.1 KB  |  142 lines

  1. /*
  2.    This example demostraits the use of a shared resident library.  The
  3.    library uses interrupt 60h, functions 0 through 5 to perform some
  4.    simple but common string functions.  This ISR library has no real
  5.    practicle purpose, but is rather designed only to demonstrait the
  6.    use of an ISR library.
  7.   
  8.    The registers are used as follows:
  9.   
  10.       ah       function number called
  11.                0 = print values of registers used
  12.                1 = print array 1 in a 20 character field
  13.                2 = print array 2 in a 20 character field
  14.                3 = return the value from comparing array 1 and array 2
  15.                4 = copy array 2 into array 1
  16.                5 = return the length of array 1
  17.       ds:dx    pointer to first character array
  18.       es:cx    pointer to second character array
  19.   
  20.       The ax register is used to return any required values to the
  21.       calling program.
  22.   
  23.       Note:  Since these functions are used to access the data in the
  24.              calling program's data segment and standard C functions are
  25.              used to manipulate the data, the large or compact memory model
  26.              must be used to support the far pointers.  This library should
  27.              be compiled using:
  28.   
  29.                cl /AL /c reslib.c     Microsoft
  30.                     lc -ml reslib.c      Lattice
  31.                tcc -ml -c reslib.c    Turbo
  32. */
  33.   
  34. #include "tsr.h"
  35. #include "resproto.h"
  36. #include "stdio.h"
  37. #include "string.h"
  38. #include "conio.h"
  39. #include "process.h"
  40. #ifndef M_I86            /* only define for Turbo C */
  41. #include "mem.h"
  42. #endif
  43. #include "dos.h"
  44. #include "isr.h"                /* required for all TSR/ISR programs */
  45.   
  46. unsigned int myfunc = 0x4757;   /* int 16 function used to see if loaded */
  47. int user_vector;
  48.   
  49. void mylib(void);
  50.   
  51. void main()
  52. {
  53.   
  54.    /* check to see if we are already loaded */
  55. if (tsrloaded(myfunc) == FALSE)
  56.     {
  57.     user_vector = find_vector(0x60,0x66);
  58.     if(user_vector == 0)
  59.         {
  60.         printf("No user vectors available\n");
  61.         exit(1);
  62.         }
  63.     initisr(user_vector, mylib, 20, myfunc, SIG, (void far *)&user_vector,0);
  64.     }
  65. else
  66.     {
  67.     printf("RESLIB Already Loaded!\n");
  68.     exit(1);
  69.     }
  70. }
  71.   
  72. void mylib()
  73. {
  74. char *strng1;   /* far pointers */
  75. char *strng2;
  76. #ifndef M_I86        /* defined by MSC compiler */
  77. long lstr;        /* needed for Lattice code below */
  78. #endif
  79.   
  80. /* build far pointer from two unsigned ints */
  81.   
  82. /*  The following works for Microsoft but not the others */
  83. #ifdef M_I86                    /* defined by MSC compiler */
  84. FP_SEG(strng1) = isr_ds;
  85. FP_OFF(strng1) = isr_dx;
  86. FP_SEG(strng2) = isr_es;
  87. FP_OFF(strng2) = isr_cx;
  88. #else
  89.   
  90. /* Lattice kludge is to move data into long then into pointer. */
  91. /* This also works for Turbo but movmem would have to be       */
  92. /* to something else for Microsoft.                            */
  93.   
  94. lstr = ((long) (isr_ds) << 16) | (long) (isr_dx);
  95. movmem(&lstr,&strng1,4);
  96. lstr = ((long) (isr_es) << 16) | (long) (isr_cx);
  97. movmem(&lstr,&strng2,4);
  98.   
  99. #endif
  100.   
  101.     switch(isr_ah) {   /* function number for user Int 60 */
  102.   
  103.     case 0:   /* print the value of some registers  */
  104.         printf(" ah = %u\n ds = %u\n dx = %u\n es = %u\n cx = %u\n",
  105.         isr_ah, isr_ds, isr_dx, isr_es, isr_cx);
  106.         break;
  107.   
  108.     case 1:   /* print string1 */
  109.         printf("%-20.20s\n", strng1);
  110.         break;
  111.   
  112.     case 2:   /* print string2 */
  113.         printf("%-20.20s\n", strng2);
  114.         break;
  115.   
  116.     case 3:   /* return compare of strng1 and strng2 */
  117.         isr_ax = strcmp(strng1,strng2);
  118.         break;
  119.   
  120.     case 4:   /* copy strng2 into strng1 */
  121.         isr_ax = (unsigned) strcpy(strng1,strng2);
  122.         break;
  123.   
  124.     case 5:   /* return length of strng1 */
  125.         isr_ax = strlen(strng1);
  126.         break;
  127.   
  128.     default:   /* any other function return 0 in AX */
  129.         printf("function %d not supported\n", isr_ah);
  130.         isr_ax = 0;
  131.         break;
  132.     }
  133.   
  134. return;
  135. }
  136.   
  137. void tsrpre()
  138. {
  139. printf("RESLIB Version 2.0  By South Mountain Software, Inc.\n");
  140. }
  141.   
  142.