rayzor

annotate src/mouse.c @ 0:2a5340a6eee4

rayzor first commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 05 Apr 2014 08:46:27 +0300
parents
children a826bf0fb169
rev   line source
nuclear@0 1 /* TODO: try NOT using the v8086 interrupts to avoid the overhead */
nuclear@0 2 #include "mouse.h"
nuclear@0 3 #include "inttypes.h"
nuclear@0 4 #include "dpmi.h"
nuclear@0 5
nuclear@0 6 #define INTR 0x33
nuclear@0 7
nuclear@0 8 #define QUERY 0
nuclear@0 9 #define SHOW 1
nuclear@0 10 #define HIDE 2
nuclear@0 11 #define READ 3
nuclear@0 12 #define WRITE 4
nuclear@0 13
nuclear@0 14 #define XLIM 7
nuclear@0 15 #define YLIM 8
nuclear@0 16
nuclear@0 17 int have_mouse(void)
nuclear@0 18 {
nuclear@0 19 struct dpmi_real_regs regs;
nuclear@0 20 memset(&regs, 0, sizeof regs);
nuclear@0 21 regs.eax = QUERY;
nuclear@0 22 dpmi_real_int(INTR, &regs);
nuclear@0 23 return regs.eax & 0xffff;
nuclear@0 24 }
nuclear@0 25
nuclear@0 26 void show_mouse(int show)
nuclear@0 27 {
nuclear@0 28 struct dpmi_real_regs regs;
nuclear@0 29 memset(&regs, 0, sizeof regs);
nuclear@0 30 regs.eax = show ? SHOW : HIDE;
nuclear@0 31 dpmi_real_int(INTR, &regs);
nuclear@0 32 }
nuclear@0 33
nuclear@0 34 int read_mouse(int *xp, int *yp)
nuclear@0 35 {
nuclear@0 36 struct dpmi_real_regs regs;
nuclear@0 37 memset(&regs, 0, sizeof regs);
nuclear@0 38
nuclear@0 39 regs.eax = READ;
nuclear@0 40 dpmi_real_int(INTR, &regs);
nuclear@0 41
nuclear@0 42 if(xp) *xp = regs.ecx & 0xffff;
nuclear@0 43 if(yp) *yp = regs.edx & 0xffff;
nuclear@0 44 return regs.ebx & 0xffff;
nuclear@0 45 }
nuclear@0 46
nuclear@0 47 void set_mouse(int x, int y)
nuclear@0 48 {
nuclear@0 49 struct dpmi_real_regs regs;
nuclear@0 50 memset(&regs, 0, sizeof regs);
nuclear@0 51
nuclear@0 52 regs.eax = WRITE;
nuclear@0 53 regs.ecx = x;
nuclear@0 54 regs.edx = y;
nuclear@0 55 dpmi_real_int(INTR, &regs);
nuclear@0 56 }
nuclear@0 57
nuclear@0 58 void set_mouse_limits(int xmin, int ymin, int xmax, int ymax)
nuclear@0 59 {
nuclear@0 60 struct dpmi_real_regs regs;
nuclear@0 61 memset(&regs, 0, sizeof regs);
nuclear@0 62 regs.eax = XLIM;
nuclear@0 63 regs.ecx = xmin;
nuclear@0 64 regs.edx = xmax;
nuclear@0 65 dpmi_real_int(INTR, &regs);
nuclear@0 66
nuclear@0 67 memset(&regs, 0, sizeof regs);
nuclear@0 68 regs.eax = YLIM;
nuclear@0 69 regs.ecx = ymin;
nuclear@0 70 regs.edx = ymax;
nuclear@0 71 dpmi_real_int(INTR, &regs);
nuclear@0 72 }