home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Raytrace & Morphing / SOS-RAYTRACE.ISO / programm / source / devel5 / drvload.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-23  |  1.4 KB  |  54 lines

  1. /* Code for loading drivers at runtime */
  2.  
  3. /* Written by Dave Stampe, August 1992 */
  4.  
  5. /* Copyright 1992 by Dave Stampe and Bernie Roehl.
  6.    May be freely used to write software for release into the public domain;
  7.    all commercial endeavours MUST contact Bernie Roehl and Dave Stampe
  8.    for permission to incorporate any part of this software into their
  9.    products!
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>   /* exit() */
  14. #include <dos.h>
  15. #include <alloc.h>
  16.  
  17. void *load_driver(char *dfile)
  18. {
  19.     FILE *f;
  20.     long s;
  21.     void *d_mem, *d_ptr;
  22.  
  23.     f = fopen(dfile,"rb"); /* open driver file */
  24.     if (f == NULL) return NULL;
  25.  
  26.     fseek(f, 0, SEEK_END); /* find length, get memory */
  27.     s = ftell(f);
  28.     d_mem = (char *) malloc(s+16);
  29.     if (d_mem == NULL)
  30.     {
  31.         fprintf(stderr,"Cannot allocate memory for driver.\n");
  32.         exit(0);
  33.     }/* setup for segment aligned load */
  34.  
  35.     d_ptr = MK_FP(FP_SEG(d_mem),0);
  36.     fseek(f, FP_OFF(d_mem), SEEK_SET);
  37.     fread(d_mem, 1, s-FP_OFF(d_mem), f);
  38.  
  39.     fclose(f);
  40.  
  41.     return d_ptr;
  42. }
  43.  
  44. extern void *screen_data(void);
  45.  
  46. unsigned char get_video_driver_version()
  47.     {
  48.     unsigned char *ptr;
  49.     ptr = screen_data();
  50.     if (ptr[22]) return 1;  /* if there's a string there, it's version 1 */
  51.     if (ptr[23] == 0) return 1;  /* if there's all zeros there, it's version 1 */
  52.     return ptr[23];  /* otherwise, the second byte is the version number */
  53.     }
  54.