home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Raytrace & Morphing / SOS-RAYTRACE.ISO / programm / source / devel5 / mouseptr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-27  |  3.9 KB  |  151 lines

  1. /* 2D pointer device (built-in) */
  2.  
  3. /* Written by Dave Stampe, Aug. 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.      ATTRIBUTION:  If you use any part of this source code or the libraries
  12.      in your projects, you must give attribution to REND386, Dave Stampe,
  13.      and Bernie Roehl in your documentation, source code, and at startup
  14.      of your program.  Let's keep the freeware ball rolling!
  15.  */
  16.  
  17. #include <stdio.h>
  18. #include <dos.h>
  19. #include <bios.h>
  20.  
  21. #include "rend386.h"
  22. #include "pointer.h"
  23.  
  24.  
  25. /************** INTERNAL MOUSE SETUP ***********/
  26.  
  27. PDRIVER *mouse_device;
  28.  
  29. void mouseptr_quit()
  30. {
  31.     pointer_quit(mouse_device);
  32. }
  33.  
  34.  
  35. PDRIVER *mouseptr_init(char *mname)
  36. {
  37.  PDRIVER *p;
  38.  POINTER x;
  39.  
  40.  p = pointer_init(P_IS2DP, mname); /* setup mouse device */
  41.  if (p==NULL) return NULL;
  42.  
  43.  init_pointer(&x); /* so that defaults are OK */
  44.  pointer_tscale(p, 1000, 1000, 1000); /* scale mouse */
  45.  set_mouse_limits(p, screeninfo->xmax, screeninfo->ymax);
  46.  pointer_read(p, &x);
  47.  pointer_read(p, &x); /* save current position */
  48.  mouse_read(p, NULL, NULL, NULL);
  49.  
  50.  mouse_device = p;
  51.  atexit(mouseptr_quit);
  52.  
  53.  return p;
  54. }
  55.  
  56.  
  57.  
  58. /***************** MOUSE POINTER DRIVER *************/
  59.  
  60. pconfig mouse_pconfig = {
  61.     65536L, 65536L, 65536L, /* position res: mm/tick in <16.16>  */
  62.     320, 200, 200, -320, -200, -200, /* xyz ranges:                */
  63.     0, 0, 0, 0, 0, 0, 0, 0, 0, /* no rotation                       */
  64.     640, 480, /* mouse emulation limits (writable) */
  65.     P_HASB1 | P_HASB2 | P_HASX | P_HASY | P_HASZ | P_HASSCR, /* databits  */
  66.     P_CENTER | P_SCREEN, 0, 0, /* modes, nullkey, flexnum           */
  67.     1, 10, 60, /* delay, idelay, reads/sec          */
  68.     P_IS2DP | P_IS2D, /* uses  */
  69.     "Default Mouse Driver"
  70. };
  71.  
  72.  
  73. static mtype; /* if == P_IS2D, don't map Z with buttons */
  74. static x_acc, y_acc, z_acc, xs_acc, ys_acc;
  75.  
  76. pconfig *mouse_driver(int op, POINTER *p, int mode)
  77. {
  78.  union REGS r;
  79.  int type = FP_OFF(p); /* way to get integer arg. */
  80.  
  81.  switch(op)
  82.   {
  83.    case DRIVER_CMD:
  84.     if (!(type & P_CENTER)) break;
  85.     if (type & P_SCREEN)
  86.      {
  87.       xs_acc = mouse_pconfig.maxsx >> 1;
  88.       ys_acc = mouse_pconfig.maxsy >> 1;
  89.      }
  90.     if (type & P_POINTER)
  91.      {
  92.       x_acc = y_acc = z_acc = 0;
  93.      }
  94.     break;
  95.    case DRIVER_INIT:
  96.    case DRIVER_RESET:
  97.     r.x.ax = 0;
  98.     int86(0x33, &r, &r);
  99.     if (r.x.ax == 0) return NULL;
  100.     x_acc = y_acc = z_acc = 0;
  101.     xs_acc = mouse_pconfig.maxsx>>1;
  102.     ys_acc = mouse_pconfig.maxsy>>1;
  103.     break;
  104.  
  105.    case DRIVER_READ:/* pointer (2DP) read */
  106.     if (mode == P_POINTER)
  107.      {
  108.       r.x.ax = 3; /* read button status */
  109.       int86(0x33, &r, &r);
  110.       p->buttons = r.x.bx;
  111.       r.x.ax = 11; /* read motion counters */
  112.       int86(0x33, &r, &r);
  113.       x_acc += ((int) r.x.cx);
  114.       if (p->buttons & 0x02)
  115.        {
  116.     z_acc -= ((int) r.x.dx);
  117.     p->buttons &= 0x01;
  118.        }
  119.       else
  120.        y_acc -= ((int) r.x.dx);
  121.        p->x = x_acc;
  122.        p->y = y_acc;
  123.        p->z = z_acc;
  124.      }
  125.     else if (mode == P_SCREEN) /* mouse read (640x480) */
  126.      {
  127.       r.x.ax = 3; /* read button status */
  128.       int86(0x33, &r, &r);
  129.       p->buttons = r.x.bx;
  130.       r.x.ax = 11; /* read motion counters */
  131.       int86(0x33, &r, &r);
  132.       xs_acc += ((int) r.x.cx);
  133.       ys_acc += ((int) r.x.dx);
  134.       if (xs_acc < 0) xs_acc = 0;
  135.       if (ys_acc < 0) ys_acc = 0;
  136.       if (xs_acc > mouse_pconfig.maxsx) xs_acc = mouse_pconfig.maxsx;
  137.       if (ys_acc > mouse_pconfig.maxsy) ys_acc = mouse_pconfig.maxsy;
  138.       p->x = xs_acc;
  139.       p->y = ys_acc;
  140.      }
  141.     break;
  142.  
  143.    case DRIVER_CHECK:
  144.     break;
  145.    case DRIVER_QUIT:
  146.     break;
  147.   }
  148.  return &mouse_pconfig;
  149. }
  150.  
  151.