rayzor
diff src/mouse.c @ 7:75bc89c2abc4
fixed the mouse handling problem
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 07 Apr 2014 08:05:06 +0300 |
parents | a826bf0fb169 |
children |
line diff
1.1 --- a/src/mouse.c Mon Apr 07 06:04:11 2014 +0300 1.2 +++ b/src/mouse.c Mon Apr 07 08:05:06 2014 +0300 1.3 @@ -1,7 +1,5 @@ 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 @@ -10,63 +8,86 @@ 1.12 #define HIDE 2 1.13 #define READ 3 1.14 #define WRITE 4 1.15 +#define PIXRATE 0xf 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(®s, 0, sizeof regs); 1.24 - regs.eax = QUERY; 1.25 - dpmi_real_int(INTR, ®s); 1.26 - return regs.eax & 0xffff; 1.27 + uint16_t res = 0; 1.28 + _asm { 1.29 + mov eax, QUERY 1.30 + int INTR 1.31 + mov res, ax 1.32 + } 1.33 + return res; 1.34 } 1.35 1.36 void show_mouse(int show) 1.37 { 1.38 - struct dpmi_real_regs regs; 1.39 - memset(®s, 0, sizeof regs); 1.40 - regs.eax = show ? SHOW : HIDE; 1.41 - dpmi_real_int(INTR, ®s); 1.42 + uint16_t cmd = show ? SHOW : HIDE; 1.43 + _asm { 1.44 + mov ax, cmd 1.45 + int INTR 1.46 + } 1.47 } 1.48 1.49 int read_mouse(int *xp, int *yp) 1.50 { 1.51 - struct dpmi_real_regs regs; 1.52 - memset(®s, 0, sizeof regs); 1.53 + uint16_t x, y, state; 1.54 + _asm { 1.55 + mov eax, READ 1.56 + int INTR 1.57 + mov state, bx 1.58 + mov x, cx 1.59 + mov y, dx 1.60 + } 1.61 1.62 - regs.eax = READ; 1.63 - dpmi_real_int(INTR, ®s); 1.64 - 1.65 - if(xp) *xp = regs.ecx & 0xffff; 1.66 - if(yp) *yp = regs.edx & 0xffff; 1.67 - return regs.ebx & 0xffff; 1.68 + if(xp) *xp = x; 1.69 + if(yp) *yp = y; 1.70 + return state; 1.71 } 1.72 1.73 void set_mouse(int x, int y) 1.74 { 1.75 - struct dpmi_real_regs regs; 1.76 - memset(®s, 0, sizeof regs); 1.77 - 1.78 - regs.eax = WRITE; 1.79 - regs.ecx = x; 1.80 - regs.edx = y; 1.81 - dpmi_real_int(INTR, ®s); 1.82 + _asm { 1.83 + mov eax, WRITE 1.84 + mov ecx, x 1.85 + mov edx, y 1.86 + int INTR 1.87 + } 1.88 } 1.89 1.90 void set_mouse_limits(int xmin, int ymin, int xmax, int ymax) 1.91 { 1.92 - struct dpmi_real_regs regs; 1.93 - memset(®s, 0, sizeof regs); 1.94 - regs.eax = XLIM; 1.95 - regs.ecx = xmin; 1.96 - regs.edx = xmax; 1.97 - dpmi_real_int(INTR, ®s); 1.98 + _asm { 1.99 + mov eax, XLIM 1.100 + mov ecx, xmin 1.101 + mov edx, xmax 1.102 + int INTR 1.103 + mov eax, YLIM 1.104 + mov ecx, ymin 1.105 + mov edx, ymax 1.106 + int INTR 1.107 + } 1.108 +} 1.109 1.110 - memset(®s, 0, sizeof regs); 1.111 - regs.eax = YLIM; 1.112 - regs.ecx = ymin; 1.113 - regs.edx = ymax; 1.114 - dpmi_real_int(INTR, ®s); 1.115 +void set_mouse_rate(int xrate, int yrate) 1.116 +{ 1.117 + _asm { 1.118 + mov ax, PIXRATE 1.119 + mov ecx, xrate 1.120 + mov edx, yrate 1.121 + int INTR 1.122 + } 1.123 } 1.124 + 1.125 +void set_mouse_mode(enum mouse_mode mode) 1.126 +{ 1.127 + if(mode == MOUSE_GFX) { 1.128 + set_mouse_rate(1, 1); 1.129 + } else { 1.130 + set_mouse_rate(8, 16); 1.131 + } 1.132 +}