home *** CD-ROM | disk | FTP | other *** search
/ Virtual Reality Homebrewer's Handbook / vr.iso / avril / vidsamp.c < prev   
C/C++ Source or Header  |  1996-03-19  |  3KB  |  109 lines

  1. /* Video routines for AVRIL, using mode 0x13 */
  2.  
  3. /* Written by Bernie Roehl, January 1995 */
  4.  
  5. /* Copyright 1995 by Bernie Roehl */
  6.  
  7. /* You may use this code for your own non-commercial projects without
  8.    paying any fees or royalties.  "Non-commercial", in this context,
  9.    means that the software you write is given away for free to anyone
  10.    who wants it.
  11.    
  12.    Commercial use, including shareware, requires a licensing
  13.    fee and a specific written agreement with the author.
  14.  
  15.    All programs created using this software (both commercial and
  16.    non-commercial) must acknowledge the use of the AVRIL library,
  17.    both in the documentation and in a banner screen at the start or
  18.    end of the program.
  19.  
  20.    For more information, contact Bernie Roehl (broehl@uwaterloo.ca).
  21.  
  22. */
  23.  
  24. #include "avril.h"
  25. #include <dos.h>     /* MK_FP(), int86() */
  26. #include <string.h>  /* strncpy() */
  27.  
  28. static unsigned char video(unsigned char cmd, unsigned char parm)
  29.     {
  30.     union REGS regs;
  31.     regs.h.ah = cmd;
  32.     regs.h.al = parm;
  33.     int86(0x10, ®s, ®s);
  34.     return regs.h.al;
  35.     }
  36.  
  37. static vrl_Raster our_raster =
  38.     {
  39.     320, 200, 8,       /* width, height, depth */
  40.     0, 0, 319, 199,    /* window */
  41.     320,               /* rowbytes */
  42.     NULL
  43.     };
  44.  
  45. static int oldmode = -1;
  46.  
  47. extern void ntsc(int mode);
  48.  
  49. static void mouse(int n)
  50.     {
  51.     union REGS regs;
  52.     regs.h.ah = 0;
  53.     regs.h.al = n;
  54.     int86(0x33, ®s, ®s);
  55.     }
  56.  
  57. vrl_32bit vrl_VideoDriverMode13(vrl_VideoCommand cmd, vrl_32bit lparm, void *pparm)
  58.     {
  59.     union REGS regs;
  60.     switch (cmd)
  61.         {
  62.         case VRL_VIDEO_GET_VERSION: return 1;
  63.         case VRL_VIDEO_GET_DESCRIPTION: strncpy((char *) pparm, "Mode 0x13 driver", lparm); return 0;
  64.         case VRL_VIDEO_SETUP:
  65.             /* lparm parameter not used, since this driver is only mode 0x13 */
  66.             our_raster.data = MK_FP(0xA000, 0);
  67.             /* save current mode */
  68.             oldmode = video(0x0F, 0x00) & 0xFF;
  69.             /* set mode 0x13 */
  70.             video(0x00, 0x13);
  71.             return 0;
  72.         case VRL_VIDEO_SHUTDOWN:
  73.             if (oldmode != -1)
  74.                 {
  75.                 video(0x00, oldmode);
  76.                 oldmode = -1;
  77.                 }
  78.             return 0;
  79.         case VRL_VIDEO_GET_MODE: return 0;  /* mode 13, submode 0 */
  80.         case VRL_VIDEO_GET_NPAGES: return 1;
  81.         case VRL_VIDEO_HAS_PALETTE: return 1;
  82.         case VRL_VIDEO_SET_PALETTE:
  83.             {
  84.             unsigned char *rgbtable = pparm;
  85.             vrl_16bit low = lparm >> 16, high = lparm, i;
  86.             outp(0x3C8, (unsigned char) low);
  87.             for (i = low; i <= high; ++i)
  88.                 {
  89.                 outp(0x3C9, (unsigned char) rgbtable[i*3+0]);
  90.                 outp(0x3C9, (unsigned char) rgbtable[i*3+1]);
  91.                 outp(0x3C9, (unsigned char) rgbtable[i*3+2]);
  92.                 }
  93.             }
  94.             break;
  95.         case VRL_VIDEO_SET_NTSC: ntsc(0x13); break;
  96.         case VRL_VIDEO_CHECK_RETRACE: return inp(0x3DA) & 0x08;
  97.         case VRL_VIDEO_GET_RASTER: *((vrl_Raster **) pparm) = &our_raster; break;
  98.         case VRL_VIDEO_BLIT:
  99.             if ((vrl_Raster *) pparm != &our_raster)
  100.                 memcpy(our_raster.data, vrl_RasterGetData((vrl_Raster *) pparm), 64000u);
  101.             break;
  102.         case VRL_VIDEO_CURSOR_HIDE: mouse(2); break;
  103.         case VRL_VIDEO_CURSOR_SHOW: mouse(1); break;
  104.         case VRL_VIDEO_CURSOR_RESET: mouse(0); break;
  105.         default: break;
  106.         }
  107.     return 0;
  108.     }
  109.