OSDN Git Service

AI003:config.txt, words.txtを追加。
[chnosproject/CHNOSProject.git] / CHNOSProject / chnos / tolset_chn_000 / chnos_009 / chnos / mouse.c
1 \r
2 #include "core.h"\r
3 \r
4 uint offset_data_m;\r
5 DATA_FIFO *sendto_m;\r
6 UI_MouseInfo *decode_m;\r
7 \r
8 uchar mcursor_pattern0[24][24] = {\r
9         ".**.....................",\r
10         "*O**....................",\r
11         "*OO**...................",\r
12         "*OOO**..................",\r
13         "*OOOO**.................",\r
14         "*OOOOO**................",\r
15         "*OOOOOO**...............",\r
16         "*OOOOOOO**..............",\r
17         "*OOOOOOOO**.............",\r
18         "*OOOOOOOOO**............",\r
19         "*OOOOOOOOOO**...........",\r
20         "*OOOOOOOOOOO**..........",\r
21         "*OOOOOOOOOOOO**.........",\r
22         "*OOOOOOOOOOOOO**........",\r
23         "*OOOOOOOOOOOOOO**.......",\r
24         "*OOOOOOOOOOOOOOO**......",\r
25         "*OOOOOOOOOOOOOOOO**.....",\r
26         "*OOOOOO*************....",\r
27         "*OOOOO**................",\r
28         "*OOOO**.................",\r
29         "*OOO**..................",\r
30         "*OO**...................",\r
31         "*O**....................",\r
32         "***.....................",\r
33 };\r
34 \r
35 void Initialise_Mouse(DATA_FIFO *sendto, uint offset, UI_MouseInfo *decode)\r
36 {\r
37         sendto_m = sendto;\r
38         offset_data_m = offset;\r
39         decode_m = decode;\r
40 Emergency_Out("Mouse Initialise Start");\r
41         decode->phase = 0;\r
42         Mouse_Send_Command(MOUSECMD_RESET);\r
43 Emergency_Out("Mouse Send Command");\r
44         System_GateDescriptor_Set(0x2c, (uint)asm_InterruptHandler2c, 0x02, AR_INTGATE32);\r
45         IO_Out8(PIC1_IMR, IO_In8(PIC1_IMR) & 0xef);\r
46 Emergency_Out("Mouse Set INT");\r
47 \r
48         return;\r
49 }\r
50 \r
51 void InterruptHandler2c(int *esp)\r
52 {\r
53         int data;\r
54 \r
55         data = IO_In8(KEYB_DATA);\r
56         IO_Out8(PIC1_OCW2, 0x64);\r
57         IO_Out8(PIC0_OCW2, 0x62);\r
58         FIFO32_Put(sendto_m, data + offset_data_m);\r
59         return;\r
60 }\r
61 \r
62 int Mouse_Decode(uint data)\r
63 {\r
64         switch (decode_m->phase){\r
65                 case 0:\r
66                         if(data == 0xfa){\r
67                                 decode_m->phase++;\r
68                         }\r
69                         break;\r
70                 case 1:\r
71                         if(data == 0xaa){\r
72                                 Mouse_Send_Command(MOUSECMD_SET_SAMPLE_RATE);\r
73                                 decode_m->phase++;\r
74                         }\r
75                         break;\r
76                 case 2:\r
77                         if(data == 0xfa){\r
78                                 Mouse_Send_Command(200);\r
79                                 decode_m->phase++;\r
80                         }\r
81                         break;\r
82                 case 3:\r
83                         if(data == 0xfa){\r
84                                 Mouse_Send_Command(MOUSECMD_SET_SAMPLE_RATE);\r
85                                 decode_m->phase++;\r
86                         }\r
87                         break;\r
88                 case 4:\r
89                         if(data == 0xfa){\r
90                                 Mouse_Send_Command(100);\r
91                                 decode_m->phase++;\r
92                         }\r
93                         break;\r
94                 case 5:\r
95                         if(data == 0xfa){\r
96                                 Mouse_Send_Command(MOUSECMD_SET_SAMPLE_RATE);\r
97                                 decode_m->phase++;\r
98                         }\r
99                         break;\r
100                 case 6:\r
101                         if(data == 0xfa){\r
102                                 Mouse_Send_Command(80);\r
103                                 decode_m->phase++;\r
104                         }\r
105                         break;\r
106                 case 7:\r
107                         if(data == 0xfa){\r
108                                 Mouse_Send_Command(MOUSECMD_GET_DEVICE_ID);\r
109                                 decode_m->phase++;\r
110                         }\r
111                         break;\r
112                 case 8:\r
113                         if(data == 0xfa){\r
114                                 break;\r
115                         }\r
116                         if(data == 0x00){\r
117                                 decode_m->type = threebtn;\r
118                                 Mouse_Send_Command(MOUSECMD_ENABLE_DATA_REPORTING);\r
119                                 decode_m->phase = 10;\r
120                         } else if(data == 0x03){\r
121                                 decode_m->type = threebtn_scroll;\r
122                                 Mouse_Send_Command(MOUSECMD_ENABLE_DATA_REPORTING);\r
123                                 decode_m->phase = 20;\r
124                         } else{\r
125                                 Mouse_Send_Command(MOUSECMD_RESET);\r
126                                 decode_m->phase = 0;\r
127                         }\r
128                         break;\r
129 \r
130                 case 10:\r
131                         if(data == 0xfa){\r
132                                 decode_m->phase++;\r
133                         }\r
134                         break;\r
135                 case 11:\r
136                         if((data & 0xc8) == 0x08) {\r
137                                 decode_m->buf[0] = data;\r
138                                 decode_m->phase++;\r
139                         }\r
140                         break;\r
141                 case 12:\r
142                         decode_m->buf[1] = data;\r
143                         decode_m->phase++;\r
144                         break;\r
145                 case 13:\r
146                         decode_m->buf[2] = data;\r
147                         decode_m->phase -= 2;\r
148                         decode_m->btn = decode_m->buf[0];\r
149                         decode_m->move.x = decode_m->buf[1];\r
150                         decode_m->move.y = decode_m->buf[2];\r
151                         if(decode_m->buf[0] & 0x10){\r
152                                 decode_m->move.x |= 0xffffff00;\r
153                         }\r
154                         if(decode_m->buf[0] & 0x20){\r
155                                 decode_m->move.y |= 0xffffff00;\r
156                         }\r
157                         decode_m->move.y = - decode_m->move.y;\r
158                         return 1;\r
159 \r
160                 case 20:\r
161                         if(data == 0xfa){\r
162                                 decode_m->phase++;\r
163                         }\r
164                         break;\r
165                 case 21:\r
166                         if((data & 0xc8) == 0x08) {\r
167                                 decode_m->buf[0] = data;\r
168                                 decode_m->phase++;\r
169                         }\r
170                         break;\r
171                 case 22:\r
172                         decode_m->buf[1] = data;\r
173                         decode_m->phase++;\r
174                         break;\r
175                 case 23:\r
176                         decode_m->buf[2] = data;\r
177                         decode_m->btn = decode_m->buf[0];\r
178                         decode_m->move.x = decode_m->buf[1];\r
179                         decode_m->move.y = decode_m->buf[2];\r
180                         if(decode_m->buf[0] & 0x10){\r
181                                 decode_m->move.x |= 0xffffff00;\r
182                         }\r
183                         if(decode_m->buf[0] & 0x20){\r
184                                 decode_m->move.y |= 0xffffff00;\r
185                         }\r
186                         decode_m->move.y = - decode_m->move.y;\r
187                         decode_m->phase++;\r
188                         break;\r
189                 case 24:\r
190                         decode_m->phase -= 3;\r
191                         decode_m->buf[3] = data;\r
192                         decode_m->scroll = decode_m->buf[3] & 0x0f;\r
193                         if(decode_m->scroll & 0x08) {\r
194                                 decode_m->scroll |= 0xfffffff0;\r
195                         }\r
196                         return 1;\r
197         }\r
198         return 0;\r
199 }\r
200 \r
201 void Mouse_Send_Command(uint data)\r
202 {\r
203         Keyboard_Controller_Wait_SendReady();\r
204         IO_Out8(PORT_KEYCMD, KEYCMD_SENDTO_MOUSE);\r
205         Keyboard_Controller_Wait_SendReady();\r
206         IO_Out8(KEYB_DATA, data);\r
207         return;\r
208 }\r
209 \r
210 void Mouse_Make_MouseCursor(UI_MouseCursor *cursor, int rangex0, int rangey0, int rangex1, int rangey1, uint height)\r
211 {\r
212         cursor->move_range0.x = rangex0;\r
213         cursor->move_range0.y = rangey0;\r
214         cursor->move_range1.x = rangex1;\r
215         cursor->move_range1.y = rangey1;\r
216         cursor->position.x = rangex0;\r
217         cursor->position.y = rangey0;\r
218         cursor->sheet = System_Sheet_Get(24, 24, 0, 0x000000FF);\r
219         Mouse_Draw_MouseCursor(cursor, normal);\r
220         Sheet_Show(cursor->sheet, cursor->position.x, cursor->position.y, height);\r
221         return;\r
222 }\r
223 \r
224 void Mouse_Draw_MouseCursor(UI_MouseCursor *cursor, mcursor_state state)\r
225 {\r
226         uint x, y;\r
227         uchar *pattern;\r
228 \r
229         pattern = &mcursor_pattern0[0][0];\r
230 \r
231         if(state == normal){\r
232                 cursor->state = normal;\r
233         } else if(state == wait){\r
234                 cursor->state = wait;\r
235         }\r
236 \r
237         for (y = 0; y < 24; y++) {\r
238                 for (x = 0; x < 24; x++) {\r
239                         if (pattern[y * 24 + x] == '*') {\r
240                                 Sheet_Draw_Point(cursor->sheet, 0x000000, x, y);\r
241                         }\r
242                         if (pattern[y * 24 + x] == 'O') {\r
243                                 Sheet_Draw_Point(cursor->sheet, 0xFFFFFF, x, y);\r
244                         }\r
245                         if (pattern[y * 24 + x] == '.') {\r
246                                 Sheet_Draw_Point(cursor->sheet, 0x0000FF, x, y);\r
247                         }\r
248                 }\r
249         }\r
250 \r
251         return;\r
252 }\r
253 \r
254 void Mouse_Move_Relative(UI_MouseCursor *cursor, int movex, int movey)\r
255 {\r
256         cursor->position.x += movex;\r
257         cursor->position.y += movey;\r
258 \r
259         if(cursor->position.x < cursor->move_range0.x){\r
260                 cursor->position.x = cursor->move_range0.x;\r
261         } else if(cursor->position.x > cursor->move_range1.x){\r
262                 cursor->position.x = cursor->move_range1.x;\r
263         }\r
264         if(cursor->position.y < cursor->move_range0.y){\r
265                 cursor->position.y = cursor->move_range0.y;\r
266         } else if(cursor->position.y > cursor->move_range1.y){\r
267                 cursor->position.y = cursor->move_range1.y;\r
268         }\r
269 \r
270         Sheet_Slide(cursor->sheet, cursor->position.x, cursor->position.y);\r
271 \r
272         return;\r
273 }\r
274 \r
275 void Mouse_Move_Absolute(UI_MouseCursor *cursor, int px, int py)\r
276 {\r
277         cursor->position.x = px;\r
278         cursor->position.y = py;\r
279 \r
280         if(cursor->position.x < cursor->move_range0.x){\r
281                 cursor->position.x = cursor->move_range0.x;\r
282         } else if(cursor->position.x > cursor->move_range1.x){\r
283                 cursor->position.x = cursor->move_range1.x;\r
284         }\r
285         if(cursor->position.y < cursor->move_range0.y){\r
286                 cursor->position.y = cursor->move_range0.y;\r
287         } else if(cursor->position.y > cursor->move_range1.y){\r
288                 cursor->position.y = cursor->move_range1.y;\r
289         }\r
290 \r
291         Sheet_Slide(cursor->sheet, cursor->position.x, cursor->position.y);\r
292 \r
293         return;\r
294 }\r