home *** CD-ROM | disk | FTP | other *** search
- /*
- This example demostraits the use of a shared resident library. The
- library uses interrupt 60h, functions 0 through 5 to perform some
- simple but common string functions. This ISR library has no real
- practicle purpose, but is rather designed only to demonstrait the
- use of an ISR library.
-
- The registers are used as follows:
-
- ah function number called
- 0 = print values of registers used
- 1 = print array 1 in a 20 character field
- 2 = print array 2 in a 20 character field
- 3 = return the value from comparing array 1 and array 2
- 4 = copy array 2 into array 1
- 5 = return the length of array 1
- ds:dx pointer to first character array
- es:cx pointer to second character array
-
- The ax register is used to return any required values to the
- calling program.
-
- Note: Since these functions are used to access the data in the
- calling program's data segment and standard C functions are
- used to manipulate the data, the large or compact memory model
- must be used to support the far pointers. This library should
- be compiled using:
-
- cl /AL /c reslib.c Microsoft
- lc -ml reslib.c Lattice
- tcc -ml -c reslib.c Turbo
- */
-
- #include "tsr.h"
- #include "resproto.h"
- #include "stdio.h"
- #include "string.h"
- #include "conio.h"
- #include "process.h"
- #ifndef M_I86 /* only define for Turbo C */
- #include "mem.h"
- #endif
- #include "dos.h"
- #include "isr.h" /* required for all TSR/ISR programs */
-
- unsigned int myfunc = 0x4757; /* int 16 function used to see if loaded */
- int user_vector;
-
- void mylib(void);
-
- void main()
- {
-
- /* check to see if we are already loaded */
- if (tsrloaded(myfunc) == FALSE)
- {
- user_vector = find_vector(0x60,0x66);
- if(user_vector == 0)
- {
- printf("No user vectors available\n");
- exit(1);
- }
- initisr(user_vector, mylib, 20, myfunc, SIG, (void far *)&user_vector,0);
- }
- else
- {
- printf("RESLIB Already Loaded!\n");
- exit(1);
- }
- }
-
- void mylib()
- {
- char *strng1; /* far pointers */
- char *strng2;
- #ifndef M_I86 /* defined by MSC compiler */
- long lstr; /* needed for Lattice code below */
- #endif
-
- /* build far pointer from two unsigned ints */
-
- /* The following works for Microsoft but not the others */
- #ifdef M_I86 /* defined by MSC compiler */
- FP_SEG(strng1) = isr_ds;
- FP_OFF(strng1) = isr_dx;
- FP_SEG(strng2) = isr_es;
- FP_OFF(strng2) = isr_cx;
- #else
-
- /* Lattice kludge is to move data into long then into pointer. */
- /* This also works for Turbo but movmem would have to be */
- /* to something else for Microsoft. */
-
- lstr = ((long) (isr_ds) << 16) | (long) (isr_dx);
- movmem(&lstr,&strng1,4);
- lstr = ((long) (isr_es) << 16) | (long) (isr_cx);
- movmem(&lstr,&strng2,4);
-
- #endif
-
- switch(isr_ah) { /* function number for user Int 60 */
-
- case 0: /* print the value of some registers */
- printf(" ah = %u\n ds = %u\n dx = %u\n es = %u\n cx = %u\n",
- isr_ah, isr_ds, isr_dx, isr_es, isr_cx);
- break;
-
- case 1: /* print string1 */
- printf("%-20.20s\n", strng1);
- break;
-
- case 2: /* print string2 */
- printf("%-20.20s\n", strng2);
- break;
-
- case 3: /* return compare of strng1 and strng2 */
- isr_ax = strcmp(strng1,strng2);
- break;
-
- case 4: /* copy strng2 into strng1 */
- isr_ax = (unsigned) strcpy(strng1,strng2);
- break;
-
- case 5: /* return length of strng1 */
- isr_ax = strlen(strng1);
- break;
-
- default: /* any other function return 0 in AX */
- printf("function %d not supported\n", isr_ah);
- isr_ax = 0;
- break;
- }
-
- return;
- }
-
- void tsrpre()
- {
- printf("RESLIB Version 2.0 By South Mountain Software, Inc.\n");
- }
-