home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / linux / src / atalnx_3.lzh / atari-linux-0.01pl3 / atari / mouse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-05  |  2.2 KB  |  107 lines

  1. /*
  2.  * Atari Mouse Driver for Linux
  3.  * by Robert de Vries (robert@and.nl) 19Jul93
  4.  */
  5.  
  6. #include <linux/sched.h>
  7. #include <linux/errno.h>
  8. #include <linux/atarikb.h>
  9. #include <linux/atari_mouse.h>
  10. #include <asm/segment.h>
  11.  
  12. static struct mouse_status mouse;
  13.  
  14. void mouse_interrupt(char *buf)
  15. {
  16. /*    ikbd_mouse_disable(); */
  17.  
  18.     mouse.buttons = buf[0] & 0x3;
  19.     mouse.dx = buf[1];
  20.     mouse.dy = buf[2];
  21.     mouse.ready = 1;
  22.     wake_up_interruptible(&mouse.wait);
  23.  
  24. /*    ikbd_mouse_rel_pos(); */
  25. }
  26.  
  27. static void release_mouse(struct inode *inode, struct file *file)
  28. {
  29.     ikbd_mouse_disable();
  30.  
  31.     mouse.active = 0;
  32.     mouse.ready = 1;
  33. }
  34.  
  35. static int open_mouse(struct inode *inode, struct file *file)
  36. {
  37.     int minor = MINOR(inode->i_rdev);
  38.  
  39.     if (minor != ATARI_MOUSE_MINOR)
  40.     return -ENODEV;
  41.     if (mouse.active)
  42.     return -EBUSY;
  43.     mouse.active = 1;
  44.     mouse.ready = 0;
  45.     ikbd_mouse_rel_pos();
  46.     return 0;
  47. }
  48.  
  49. static int write_mouse(struct inode *inode, struct file *file, char *buffer, int count)
  50. {
  51.     return -EINVAL;
  52. }
  53.  
  54. static int read_mouse(struct inode *inode, struct file *file, char *buffer, int count)
  55. {
  56.     int i;
  57.  
  58.     if (count < 3)
  59.     return -EINVAL;
  60.     if (!mouse.ready)
  61.     return -EAGAIN;
  62.     /* ikbd_mouse_disable */
  63.     put_fs_byte(mouse.buttons, buffer++);
  64.     put_fs_byte(mouse.dx, buffer++);
  65.     put_fs_byte(mouse.dy, buffer++);
  66.     for (i = 3; i < count; i++)
  67.     put_fs_byte(0, buffer++);
  68.     mouse.ready = 0;
  69.     /* ikbd_mouse_rel_pos(); */
  70.     return i;
  71. }
  72.  
  73. static int mouse_select(struct inode *inode, struct file *file, int sel_type, select_table *wait)
  74. {
  75.     if (sel_type != SEL_IN)
  76.     return 0;
  77.     if (mouse.ready)
  78.     return 1;
  79.     select_wait(&mouse.wait, wait);
  80.     return 0;
  81. }
  82.  
  83. struct file_operations mouse_fops = {
  84.     NULL,        /* mouse_seek */
  85.     read_mouse,
  86.     write_mouse,
  87.     NULL,        /* mouse_readdir */
  88.     mouse_select,
  89.     NULL,        /* mouse_ioctl */
  90.     NULL,        /* mouse_mmap */
  91.     open_mouse,
  92.     release_mouse
  93. };
  94.  
  95. unsigned long mouse_init(unsigned long kmem_start)
  96. {
  97.     mouse.active = 0;
  98.     mouse.ready = 0;
  99.     mouse.wait = NULL;
  100.  
  101.     if (register_chrdev(10, "mouse", &mouse_fops))
  102.     printk("unable to get major 10 for mouse devices\n");
  103.     printk("Atari mouse driver installed.\n");
  104.     
  105.     return kmem_start;
  106. }
  107.