2 pcboot - bootable PC demo/game kernel
3 Copyright (C) 2018 John Tsiombikas <nuclear@member.fsf.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY, without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>.
25 static void init_mouse();
26 static void psaux_intr();
29 static unsigned int bnstate;
35 interrupt(IRQ_TO_INTR(12), psaux_intr);
37 set_mouse_bounds(0, 0, 319, 199);
42 static void init_mouse()
46 kb_send_cmd(KB_CMD_AUX_ENABLE);
49 printf("aux enable: %02x\n", (unsigned int)val);
52 kb_send_cmd(KB_CMD_GET_CMDBYTE);
54 val &= ~KB_CCB_AUX_DISABLE;
55 val |= KB_CCB_AUX_INTREN;
56 kb_send_cmd(KB_CMD_SET_CMDBYTE);
61 printf("set cmdbyte: %02x\n", (unsigned int)val);
64 kb_send_cmd(KB_CMD_PSAUX);
65 kb_send_data(AUX_CMD_DEFAULTS);
68 kb_send_cmd(KB_CMD_PSAUX);
69 kb_send_data(AUX_CMD_ENABLE);
72 present = (val == KB_ACK) ? 1 : 0;
73 printf("init_mouse: %spresent\n", present ? "" : "not ");
81 void set_mouse_bounds(int x0, int y0, int x1, int y1)
89 unsigned int mouse_state(int *xp, int *yp)
96 static void psaux_intr()
98 static unsigned char data[3];
102 if(!(inb(KB_STATUS_PORT) & KB_STAT_AUX)) {
103 /* no mouse data pending, ignore interrupt */
107 data[idx] = kb_read_data();
111 if(data[0] & AUX_PKT0_OVF_BITS) {
112 /* consensus seems to be that if overflow bits are set, something is
113 * fucked, and it's best to re-initialize the mouse
118 printf("psaux data packet: %02x %02x %02x\n", (unsigned int)data[0],
119 (unsigned int)data[1], (unsigned int)data[2]);
122 bnstate = data[0] & AUX_PKT0_BUTTON_BITS;
126 if(data[0] & AUX_PKT0_XSIGN) {
129 if(data[0] & AUX_PKT0_YSIGN) {
136 if(mx < bounds[0]) mx = bounds[0];
137 if(mx > bounds[2]) mx = bounds[2];
138 if(my < bounds[1]) my = bounds[1];
139 if(my > bounds[3]) my = bounds[3];
142 printf("mouse: %d,%d [%c%c%c]\n", mx, my, bnstate & AUX_PKT0_LEFTBN ? '1' : '0',
143 bnstate & AUX_PKT0_MIDDLEBN ? '1' : '0', bnstate & AUX_PKT0_RIGHTBN ? '1' : '0');