psmouse.c
资源名称:tizos.rar [点击查看]
上传用户:qddsws
上传日期:2022-06-22
资源大小:723k
文件大小:3k
源码类别:
操作系统开发
开发平台:
C/C++
- #include <devices/psmouse.h>
- struct Ps2Mouse* ctx;
- int px;
- static int volatile int_pending_mouse;
- void __init_device init_psmouse (struct device* dev) {
- /* Agafats del gpm_Imps2 (Linux mouse driver), serveixen per establir el sample rate*/
- static byte s1[] = { 0xF3, 0xC8, 0xF3, 0x64, 0xF3, 0x50, 0 };
- static byte s2[] = { 0xF6, 0xE6, 0xF4, 0xF3, 0x64, 0xE8, 0x03, 0 };
- const byte* ch;
- int wait;
- dev->command=(void*)&psmouse_command;
- kprint ("Registered ISA Device:");
- kprint (dev->name);
- kprint (" n");
- /*Activem IRQ 1 and 12 (keyboard, mouse) */
- kbdWrite(KEYB_CTRL, KCTRL_WRITE_CMD_BYTE);
- kbdWrite(KEYB_PORT, KCTRL_SYS | KCTRL_TRANSLATE_XT | KCTRL_IRQ1 | KCTRL_IRQ12 );
- /* Activem el port PS/2 Auxiliar (MOUSE) */
- kbdWrite(KEYB_CTRL, KCTRL_ENABLE_AUX);
- for (ch = s1; *ch; ch++){
- kbdWrite(KEYB_CTRL, KCTRL_WRITE_AUX);
- kbdWriteRead(KEYB_PORT, *ch, KEYB_ACK);
- }
- for (ch = s2; *ch; ch++){
- kbdWrite(KEYB_CTRL, KCTRL_WRITE_AUX);
- kbdWriteRead(KEYB_PORT, *ch, KEYB_ACK);
- }
- for(wait = 0; wait < 3000; wait++);
- kbdWrite(KEYB_CTRL, KCTRL_WRITE_AUX);
- kbdWriteRead(KEYB_PORT, AUX_ENABLE, KEYB_ACK);
- ctx=(struct Ps2Mouse*)kmalloc(sizeof(struct Ps2Mouse));
- /*La mouse comen鏰 al centre de la pantalla
- */
- ctx->xmin = 0;
- ctx->ymin = 0;
- ctx->xmax = 800;
- ctx->ymax = 600;
- ctx->x = (ctx->xmin + ctx->xmax) / 2 ;
- ctx->y = (ctx->ymin + ctx->ymax) / 2 ;
- ctx->buttons=0;
- AddInt (44,(void*)rsi_mouse,0);
- unmaskIRQ(ALL);
- __asm__ volatile ("sti");
- px=0;
- }
- void bottom_mouse_rsi () {
- int_pending_mouse=1;
- }
- void get_mouse_coord() {
- byte Stat,Data;
- byte mouse_buf[3];
- int dx,dy,but;
- Stat = inportb(KEYB_CTRL);
- if ((Stat & 0x01) != 0) {
- Data = kbdRead();
- mouse_buf[0]=Data;
- Data = kbdRead();
- mouse_buf[1]=Data;
- Data = kbdRead();
- mouse_buf[2]=Data;
- if (MOUSE==3) Data = kbdRead();
- but= (mouse_buf[0] & 0x02)>>1| (mouse_buf[0] & 0x01) << 1;
- dx = (mouse_buf[0] & 0x10) ? mouse_buf[1] - 256 : mouse_buf[1];
- dy = (mouse_buf[0] & 0x20) ? -(mouse_buf[2] - 256) : -mouse_buf[2];
- ctx->x += dx;
- ctx->y += dy;
- if(ctx->x > ctx->xmax) ctx->x = ctx->xmin;
- if(ctx->x < ctx->xmin) ctx->x = ctx->xmax;
- if(ctx->y > ctx->ymax) ctx->y = ctx->ymax;
- if(ctx->y < ctx->ymin) ctx->y = ctx->ymin;
- ctx->buttons = but;
- }
- int_pending_mouse=0;
- }
- void psmouse_command(unsigned long cmd, void* param) {
- char text[200];
- switch (cmd) {
- case GET_MOUSE_COORDINATES:
- if (int_pending_mouse==1) {
- get_mouse_coord();
- memcpy(param,ctx,sizeof(struct Ps2Mouse));
- }
- else {
- ((struct Ps2Mouse*)param)->buttons=0;
- }
- break;
- }
- }