rayzor

diff 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
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/mouse.c	Sat Apr 05 08:46:27 2014 +0300
     1.3 @@ -0,0 +1,72 @@
     1.4 +/* TODO: try NOT using the v8086 interrupts to avoid the overhead */
     1.5 +#include "mouse.h"
     1.6 +#include "inttypes.h"
     1.7 +#include "dpmi.h"
     1.8 +
     1.9 +#define INTR	0x33
    1.10 +
    1.11 +#define QUERY	0
    1.12 +#define SHOW	1
    1.13 +#define HIDE	2
    1.14 +#define READ	3
    1.15 +#define WRITE	4
    1.16 +
    1.17 +#define XLIM	7
    1.18 +#define YLIM	8
    1.19 +
    1.20 +int have_mouse(void)
    1.21 +{
    1.22 +	struct dpmi_real_regs regs;
    1.23 +	memset(&regs, 0, sizeof regs);
    1.24 +	regs.eax = QUERY;
    1.25 +	dpmi_real_int(INTR, &regs);
    1.26 +	return regs.eax & 0xffff;
    1.27 +}
    1.28 +
    1.29 +void show_mouse(int show)
    1.30 +{
    1.31 +	struct dpmi_real_regs regs;
    1.32 +	memset(&regs, 0, sizeof regs);
    1.33 +	regs.eax = show ? SHOW : HIDE;
    1.34 +	dpmi_real_int(INTR, &regs);
    1.35 +}
    1.36 +
    1.37 +int read_mouse(int *xp, int *yp)
    1.38 +{
    1.39 +	struct dpmi_real_regs regs;
    1.40 +	memset(&regs, 0, sizeof regs);
    1.41 +
    1.42 +	regs.eax = READ;
    1.43 +	dpmi_real_int(INTR, &regs);
    1.44 +
    1.45 +	if(xp) *xp = regs.ecx & 0xffff;
    1.46 +	if(yp) *yp = regs.edx & 0xffff;
    1.47 +	return regs.ebx & 0xffff;
    1.48 +}
    1.49 +
    1.50 +void set_mouse(int x, int y)
    1.51 +{
    1.52 +	struct dpmi_real_regs regs;
    1.53 +	memset(&regs, 0, sizeof regs);
    1.54 +
    1.55 +	regs.eax = WRITE;
    1.56 +	regs.ecx = x;
    1.57 +	regs.edx = y;
    1.58 +	dpmi_real_int(INTR, &regs);
    1.59 +}
    1.60 +
    1.61 +void set_mouse_limits(int xmin, int ymin, int xmax, int ymax)
    1.62 +{
    1.63 +	struct dpmi_real_regs regs;
    1.64 +	memset(&regs, 0, sizeof regs);
    1.65 +	regs.eax = XLIM;
    1.66 +	regs.ecx = xmin;
    1.67 +	regs.edx = xmax;
    1.68 +	dpmi_real_int(INTR, &regs);
    1.69 +
    1.70 +	memset(&regs, 0, sizeof regs);
    1.71 +	regs.eax = YLIM;
    1.72 +	regs.ecx = ymin;
    1.73 +	regs.edx = ymax;
    1.74 +	dpmi_real_int(INTR, &regs);
    1.75 +}