Cleanup in elf.c with .bss section clean; adm command mounts cdrom instead of floppy...
[ZeXOS.git] / kernel / drivers / char / mouse / com.c
blobd82f96197040ac7f8f97157a80e81ee3a6206ac5
1 /*
2 * ZeX/OS
3 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.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 <http://www.gnu.org/licenses/>.
20 #include <build.h>
21 #include <system.h>
22 #include <arch/io.h>
23 #include <rs232.h>
24 #include <mouse.h>
25 #include <dev.h>
27 dev_mouse_t commouse;
29 unsigned commouse_handler ()
31 char b1 = rs232_read_nonblock ();
33 if ((b1 & (1 << 6)) == 0)
34 return 0;
36 // beginning of packet
37 char b2 = rs232_read ();
38 char b3 = rs232_read ();
40 commouse.pos_x = (int) (char) ((b1 << 6) | (b2 & 0x3f));
41 commouse.pos_y = (int) (char) (((b1 << 4) & 0xc0) | (b3 & 0x3f));
43 unsigned short flags = (b1 >> 4) & 3;
45 commouse.flags |= (flags == 0x2) ? MOUSE_FLAG_BUTTON1 : 0;
46 commouse.flags |= (flags == 0x1) ? MOUSE_FLAG_BUTTON2 : 0;
47 commouse.flags |= (flags == 0x4) ? MOUSE_FLAG_BUTTON3 : 0;
49 return 1;
52 unsigned commouse_init ()
54 unsigned timeout;
56 for (timeout = 3; timeout; timeout --) {
57 char protocol = rs232_read_nonblock ();
59 if (protocol == 'M')
60 return 1;
63 return 0;
66 bool commouse_acthandler (unsigned act, char *block, unsigned block_len)
68 switch (act) {
69 case DEV_ACT_INIT:
71 dev_flags_t *flags = (dev_flags_t *) block;
73 if (!flags)
74 return 0;
76 if (block_len != sizeof (dev_flags_t))
77 return 0;
79 unsigned r = commouse_init ();
81 if (!r)
82 return 0;
84 flags->iomem = (void *) &commouse;
85 flags->iolen = sizeof (dev_mouse_t);
87 memset (flags->iomem, 0, sizeof (dev_mouse_t));
89 return 1;
91 break;
92 case DEV_ACT_READ:
94 unsigned r = commouse_handler ();
96 memcpy (block, &commouse, sizeof (commouse));
98 return r;
100 break;
101 case DEV_ACT_WRITE:
103 memcpy (&commouse, block, sizeof (commouse));
105 return 1;
107 break;
110 return 0;