00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "dev/mouse/mouse.h"
00019
00020 DB mbyte[3];
00021 DW mcurx = TOTAL_WIDTH/2, mcury = TOTAL_HEIGHT/2;
00022 boolean mouse_inited = _false;
00023
00024 #define SAMPLE_MOVE 10
00025
00026 DB sample_no = 0;
00027
00028 void w64(DB val)
00029 {
00030 printf("\nIn w64->%x",val);
00031 printStatus();
00032
00033 while(readStatus() & IBF)
00034 ;
00035
00036 outb(0x64,val);
00037 printStatus();
00038 }
00039
00040 DB r60()
00041 {
00042 DB data;
00043 printf("\nIn r60");
00044
00045 printStatus();
00046 if(readStatus() & OBF)
00047 {
00048 data = inb(0x60);
00049 printf("\t %x",data);
00050 printStatus();
00051 return data;
00052 }
00053 else
00054 return 0xFC;
00055 }
00056
00057 void w60(DB val)
00058 {
00059 printf("\nIn w60->%x",val);
00060 printStatus();
00061
00062 while(readStatus() & OBF || readStatus() & MOBF)
00063 {
00064 printf("\n%x ",inb(0x60));
00065 }
00066
00067 if(!(readStatus() & OBF) && !(readStatus() & MOBF))
00068 {
00069 printf("\nIn w60: Writing %x",val);
00070 outb(0x60,val);
00071 }
00072 else
00073 {
00074 printf("\nIn w60: 0x60 Full");
00075 }
00076
00077 printStatus();
00078 }
00079
00080 void mouse_init()
00081 {
00082 DB cmdByte;
00083
00084 cls();
00085 printf("\nMouse Init");
00086
00087
00088 w64(0xAA);
00089 r60();
00090
00091
00092 w64(0xA8);
00093 r60();
00094
00095 w64(0x60);
00096 w60(0x47);
00097 r60();
00098
00099 w64(0x20);
00100 cmdByte = r60();
00101 printf("\nCMDBYTE %x %b",cmdByte,cmdByte);
00102
00103
00104 w64(0xD4);
00105 w60(0xFF);
00106 while(readStatus() & OBF && readStatus() & MOBF)
00107 {
00108 r60();
00109 }
00110
00111
00112 w64(0xD4);
00113 w60(0xEA);
00114 while(readStatus() & OBF || readStatus() & MOBF)
00115 {
00116 r60();
00117 }
00118
00119
00120 w64(0xD4);
00121 w60(0xF4);
00122 while(readStatus() & OBF)
00123 {
00124 r60();
00125 }
00126
00127 printf("\nPS/2 Mouse Initialized");
00128 }
00129
00130
00131
00132 void handle_mouse()
00133 {
00134 static int first;
00135 DB i = 0;
00136 DD count;
00137
00138 printf("\nIn handle_mouse");
00139
00140 while(readStatus() & OBF && readStatus() & MOBF && i<3)
00141 {
00142 printStatus();
00143 mbyte[i] = inb(0x60);
00144 printf(" %x ",mbyte[i]);
00145 i++;
00146
00147
00148 for(count=0 ; !(readStatus() & OBF) && count < PS2_TIMEOUT && i < 3; count++)
00149 ;
00150 printf(" %d ",count);
00151 }
00152
00153 printStatus();
00154
00155 if(i == 3)
00156 processData();
00157
00158 eoi();
00159
00160 return;
00161 }
00162
00163 void processData()
00164 {
00165 MSG mymsg;
00166 DW _x = 0, _y = 0;
00167 DW xdel = 0, ydel = 0;
00168 static DB mleft = 0;
00169
00170
00171 if(mbyte[0] & XSGN)
00172 mbyte[1] = ~mbyte[1] + 1;
00173
00174 if(mbyte[0] & YSGN)
00175 mbyte[2] = ~mbyte[2] + 1;
00176
00177 printf("\nm[0] %b m[1] %d m[2] %d ",mbyte[0],mbyte[1],mbyte[2]);
00178
00179 xdel = 4 * mbyte[1];
00180 ydel = 3 * mbyte[2];
00181
00182 if(mbyte[0] & XSGN)
00183 _x = mcurx - xdel;
00184 else
00185 _x = mcurx + xdel;
00186
00187 if(mbyte[0] & YSGN)
00188 _y = mcury + ydel;
00189 else
00190 _y = mcury - ydel;
00191
00192 if( _x & 0x8000)
00193 _x = 1;
00194
00195 if( _x > TOTAL_WIDTH - 16)
00196 _x = TOTAL_WIDTH - 16;
00197
00198 if( _y & 0x8000)
00199 _y = 1;
00200
00201 if( _y > TOTAL_HEIGHT - 16)
00202 _y = TOTAL_HEIGHT - 16;
00203
00204
00205 if(graphics)
00206 {
00207 if(!mouse_inited)
00208 {
00209 getimage(mcurx,mcury,16,16,mouseimg);
00210 gcls_delay = 0x5FFF;
00211 mouse_inited = _true;
00212 }
00213
00214 drawMousePtr(_x,_y);
00215
00216
00217 if(mbyte[0] & LBTN)
00218 {
00219 if(mleft == 0)
00220 {
00221 sample_no = 0;
00222
00223 mymsg.type = ACTION;
00224 mymsg.sub_type = MOUSE;
00225 mymsg.length = 10;
00226 *(DW*)mymsg.msg_buf = _x + 3;
00227 *(DW*)(mymsg.msg_buf+2) = _y + 1;
00228 *(DW*)(mymsg.msg_buf+4) = CLICK;
00229
00230 printf("\n KSEND CALLED ");
00231
00232 if(ksend(GUI_PID,&mymsg) == -1)
00233 panic("from mouse message overflow");
00234
00235 printf("\n AFTER KSEND CALLED ");
00236 mleft = 1;
00237
00238 }
00239 else
00240 {
00241 sample_no++;
00242
00243 if(sample_no > SAMPLE_MOVE)
00244 {
00245 sample_no = 0;
00246
00247 mymsg.type = ACTION;
00248 mymsg.sub_type = MOUSE;
00249 mymsg.length = 10;
00250 *(DW*)mymsg.msg_buf = _x + 3;
00251 *(DW*)(mymsg.msg_buf+2) = _y + 1;
00252 *(DW*)(mymsg.msg_buf+4) = MOVE;
00253
00254 if(ksend(GUI_PID,&mymsg) == -1)
00255 panic("From mouse message overflow");
00256
00257 }
00258
00259 }
00260
00261 }
00262 else if(mleft == 1)
00263 {
00264 mleft = 0;
00265 }
00266
00267 mcurx = _x;
00268 mcury = _y;
00269
00270 }
00271 else
00272 {
00273 mcurx = _x;
00274 mcury = _y;
00275 }
00276
00277
00278 printf("\n _x: %d _y %d",_x,_y);
00279
00280 printf("\n x: %d y %d",mcurx,mcury);
00281
00282 if(mbyte[0] & MBTN)
00283 {
00284 printf("\nMBtn Pressed");
00285 }
00286
00287 if(mbyte[0] & LBTN)
00288 {
00289 printf("\nLBtn Pressed");
00290 }
00291
00292 if(mbyte[0] & RBTN)
00293 {
00294 printf("\nRBtn Pressed");
00295 }
00296
00297 }
00298
00299 void printStatus()
00300 {
00301 printf("\nStatus %x %b",readStatus(),readStatus());
00302 }
00303
00304 DB readData()
00305 {
00306 DD i = 0;
00307
00308 printf("\nIn readData()");
00309 printStatus();
00310
00311 while(i < PS2_TIMEOUT)
00312 {
00313 i++;
00314 if(readStatus() & OBF)
00315 break;
00316 }
00317
00318 if(i == PS2_TIMEOUT)
00319 return 0xFC;
00320
00321 return inb(0x60);
00322 }
00323
00324 void mouse_restore()
00325 {
00326 DB i, j;
00327
00328 if(graphics)
00329 {
00330 getimage(mcurx,mcury,16,16, &mouseimg[0][0]);
00331 }
00332 }