/shark/trunk/drivers/input/shark/shark_mouse.c |
---|
75,7 → 75,8 |
static int mouse_z = 0; |
static unsigned long mouse_buttons = 0; |
static MOUSE_HANDLER mouse_handler = NULL; |
MOUSE_HANDLER user_mouse_handler = NULL; |
MOUSE_HANDLER show_mouse_handler = NULL; |
#ifdef MOUSE_TASK |
/* mouse task PID */ |
143,7 → 144,10 |
dx, dy, dz, (int)dbuttons, mouse_x, mouse_y, mouse_z, (int)mouse_buttons); |
#endif |
/* mouse handler */ |
if (mouse_handler!=NULL) mouse_handler(&ev); |
if (show_mouse_handler != NULL) |
show_mouse_handler(&ev); |
else if (user_mouse_handler != NULL) |
user_mouse_handler(&ev); |
} |
} |
#ifdef MOUSE_TASK |
216,7 → 220,7 |
void mouse_hook(MOUSE_HANDLER h) |
{ |
mouse_handler = h; |
user_mouse_handler = h; |
} |
int mouse_getthreshold(void) |
/shark/trunk/drivers/input/shark/mcurtxt.c |
---|
0,0 → 1,348 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: |
* Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@gandalf.sssup.it> |
* |
* Authors : |
* Paolo Gai <pj@gandalf.sssup.it> |
* Massimiliano Giorgi <massy@gandalf.sssup.it> |
* Luca Abeni <luca@gandalf.sssup.it> |
* Mauro Marinoni <mauro.marinoni@unipv.it> |
* (see the web pages for full authors list) |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
/* |
* Copyright (C) 2000 Paolo Gai |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
*/ |
/* |
* |
* Auto Pointer management |
* |
*/ |
#include <kernel/kern.h> |
#include <modules/sem.h> |
#include "../include/drivers/shark_input26.h" |
#include "../include/drivers/shark_mouse26.h" |
//#define CURTXT_DEBUG |
/* these variables are managed by this module but MUST be declared |
* into shark_mouse.c to prevent implicit inclusion of this module |
* when a user link the mouse library |
*/ |
extern MOUSE_HANDLER show_mouse_handler; |
extern MOUSE_HANDLER user_mouse_handler; |
/* a mutex semaphore */ |
static sem_t mutex=-1; |
/* Setup function */ |
int _mouse_cursor_init(int cmd, void(*my_show_cursor)(int, int), void(*my_restore_cursor)(int, int)); |
/* |
* |
* autocursor mouse handler |
* |
*/ |
/* >=0 hide cursor; <0 show cursor */ |
static int mouse_cursor_state = 0; |
/* mouse status */ |
static int autocursormode = 0; |
/* saved mouse_position */ |
static int saved_x, saved_y; |
static void dummy(int x,int y){} |
static void (*show_cursor)(int x, int y) = dummy; |
static void (*restore_cursor)(int x, int y) = dummy; |
/* those are the 4 mouse handlers */ |
/* AUTOOFF -> call the user handler with no mouse displayed */ |
/* WITHOUTSEM -> does not use a mutex semaphore */ |
/* with no flags */ |
static void autocursor_mouse_handler_1(MOUSE_EVT *event) |
{ |
#ifdef CURTXT_DEBUG |
printk(KERN_DEBUG "mcurtxt.c: autocursor_mouse_handler_1\n"); |
#endif |
if (user_mouse_handler != NULL) |
user_mouse_handler(event); |
sem_wait(&mutex); |
if ( (mouse_cursor_state < 0) && (event->x != saved_x || event->y != saved_y)) { |
restore_cursor(saved_x, saved_y); |
saved_x = event->x; |
saved_y = event->y; |
show_cursor(saved_x, saved_y); |
} |
sem_post(&mutex); |
} |
/* with WITHOUTSEM flag*/ |
static void autocursor_mouse_handler_2(MOUSE_EVT *event) |
{ |
#ifdef CURTXT_DEBUG |
printk(KERN_DEBUG "mcurtxt.c: autocursor_mouse_handler_2\n"); |
#endif |
if (user_mouse_handler != NULL) |
user_mouse_handler(event); |
if ( (mouse_cursor_state < 0) && (event->x != saved_x || event->y != saved_y)) { |
restore_cursor(saved_x, saved_y); |
saved_x = event->x; |
saved_y = event->y; |
show_cursor(saved_x, saved_y); |
} |
} |
/* with AUTOOFF flag*/ |
static void autocursor_mouse_handler_3(MOUSE_EVT *event) |
{ |
#ifdef CURTXT_DEBUG |
printk(KERN_DEBUG "mcurtxt.c: autocursor_mouse_handler_3\n"); |
#endif |
sem_wait(&mutex); |
if (mouse_cursor_state < 0) { |
restore_cursor(saved_x, saved_y); |
saved_x = event->x; |
saved_y = event->y; |
if (user_mouse_handler != NULL) |
user_mouse_handler(event); |
show_cursor(saved_x, saved_y); |
} else if (user_mouse_handler != NULL) |
user_mouse_handler(event); |
sem_post(&mutex); |
} |
/* with WITHOUTSEM & AUTOOFF flags */ |
static void autocursor_mouse_handler_4(MOUSE_EVT *event) |
{ |
#ifdef CURTXT_DEBUG |
printk(KERN_DEBUG "mcurtxt.c: autocursor_mouse_handler_4\n"); |
#endif |
if (mouse_cursor_state < 0) { |
restore_cursor(saved_x, saved_y); |
saved_x = event->x; |
saved_y = event->y; |
if (user_mouse_handler != NULL) |
user_mouse_handler(event); |
show_cursor(saved_x, saved_y); |
} else if (user_mouse_handler != NULL) |
user_mouse_handler(event); |
} |
/* -------------- |
* TXT management |
* -------------- |
*/ |
/* text cursor shape */ |
#define DEFAULTTXTSHAPE 0x7700ffff |
static DWORD saved_txtshape = DEFAULTTXTSHAPE; |
static BYTE attr_andmask, attr_xormask; |
static BYTE c_andmask, c_xormask; |
/* saved values */ |
static BYTE saved_attr, saved_c; |
/* show txt cursor */ |
void show_txt_cursor(int x, int y) |
{ |
int attr,c; |
getc_xy(x, y, &saved_attr, &saved_c); |
attr = (saved_attr & attr_andmask) ^ attr_xormask; |
c = (saved_c & c_andmask) ^ c_xormask; |
putc_xy(x, y, attr, c); |
} |
/* restore txt cursor */ |
static void restore_txt_cursor(int x, int y) |
{ |
putc_xy(x, y, saved_attr, saved_c); |
} |
/* define text shape */ |
int mouse_txtshape(DWORD img) |
{ |
int cond; |
if (img == DEFAULT) |
img = DEFAULTTXTSHAPE; |
cond = ( (autocursormode & STATUSMASK) == ENABLE && (autocursormode & TXTCURSOR) == TXTCURSOR ); |
if (cond) |
restore_txt_cursor(saved_x, saved_y); |
saved_txtshape = img; |
c_andmask = img & 0xff; |
attr_andmask = (img & 0xff00) >> 8; |
c_xormask = (img & 0xff0000) >> 16; |
attr_xormask = (img & 0xff000000) >> 24; |
#ifdef CURTXT_DEBUG |
printk(KERN_DEBUG "MouseTxt_Shape: %x %x %x %x\n", c_andmask, attr_andmask, c_xormask, attr_xormask); |
#endif |
if (cond) |
show_txt_cursor(saved_x, saved_y); |
return 0; |
} |
/* |
* User interface to autocursor functions |
*/ |
/* display the cursor */ |
#define MOUSE_ON() { \ |
int unused; \ |
unsigned long lunused; \ |
mouse_cursor_state--; \ |
if (mouse_cursor_state == -1) { \ |
mouse_getpos(&saved_x, &saved_y, &unused, &lunused); \ |
show_cursor(saved_x, saved_y); \ |
} \ |
} |
static void mouse_on_sem(void) |
{ |
sem_wait(&mutex); |
MOUSE_ON(); |
sem_post(&mutex); |
} |
static void mouse_on_nosem(void) |
{ |
MOUSE_ON(); |
} |
void (*mouse_on)(void)=mouse_on_nosem; |
/* hide the cursor */ |
#define MOUSE_OFF() { \ |
mouse_cursor_state++; \ |
if (mouse_cursor_state == 0) \ |
restore_cursor(saved_x, saved_y); \ |
} |
void mouse_off_sem(void) |
{ |
sem_wait(&mutex); |
MOUSE_OFF(); |
sem_post(&mutex); |
} |
void mouse_off_nosem(void) |
{ |
MOUSE_OFF(); |
} |
void (*mouse_off)(void) = mouse_off_nosem; |
static MOUSE_HANDLER wich_handler(int cmd) |
{ |
if ( ((cmd & WITHOUTSEM) == WITHOUTSEM) && ((cmd & AUTOOFF) == AUTOOFF) ) |
return autocursor_mouse_handler_4; |
if ((cmd & WITHOUTSEM) == WITHOUTSEM) |
return autocursor_mouse_handler_2; |
if ((cmd & AUTOOFF) == AUTOOFF) |
return autocursor_mouse_handler_3; |
return autocursor_mouse_handler_1; |
} |
int mouse_txtcursor(int cmd) |
{ |
mouse_txtshape(saved_txtshape); |
return _mouse_cursor_init(cmd|TXTCURSOR, show_txt_cursor, restore_txt_cursor); |
} |
/* Generic functions, both for text & graphics mode */ |
int _mouse_cursor_init(int cmd, void(*my_show_cursor)(int, int), void(*my_restore_cursor)(int, int)) |
{ |
if (mutex == -1) { |
if (sem_init(&mutex, 0, 1) == -1) |
return -1; |
} |
#ifdef CURTXT_DEBUG |
printk(KERN_DEBUG "mouse_cursor_init: command %x\n", cmd); |
#endif |
switch (cmd & STATUSMASK) { |
case DISABLE: |
//show_mouse_handler = user_mouse_handler; |
show_mouse_handler = NULL; |
restore_cursor(saved_x, saved_y); |
show_cursor = dummy; |
restore_cursor = dummy; |
mouse_cursor_state = 0; |
break; |
case ENABLE: |
restore_cursor(saved_x, saved_y); |
restore_cursor = my_restore_cursor; |
show_cursor = my_show_cursor; |
if ((autocursormode & STATUSMASK) == DISABLE) { |
//user_mouse_handler = show_mouse_handler; |
show_mouse_handler = wich_handler(cmd); |
} |
mouse_cursor_state = -1; |
break; |
default: |
return -1; |
} |
autocursormode = cmd; |
if ((autocursormode & STATUSMASK) == ENABLE) { |
if ((cmd & WITHOUTSEM) == WITHOUTSEM) { |
mouse_on = mouse_on_nosem; |
mouse_off = mouse_off_nosem; |
} else { |
mouse_on = mouse_on_sem; |
mouse_off = mouse_off_sem; |
} |
} |
return 0; |
} |
void _mouse_cursor_getposition(int *xptr, int *yptr) |
{ |
*xptr = saved_x; |
*yptr = saved_y; |
} |
/shark/trunk/drivers/input/shark/shark_input.c |
---|
51,16 → 51,6 |
/*extern int serport_init(void); |
extern int serport_exit(void);*/ |
/* Devices */ |
/*extern int ns558_init(void); |
extern int ns558_exit(void); |
extern int analog_init(void); |
extern int analog_exit(void); |
extern int joydump_init(void); |
extern int joydump_exit(void);*/ |
/* Handlers */ |
extern int evbug_init(void); |
extern int evbug_exit(void); |
116,41 → 106,7 |
return -1; |
} |
/* Init the Linux Joystick Driver */ |
/*int JOY26_init() { |
int ret; |
if (input_installed == FALSE) |
if (INPUT26_init()) { |
printk(KERN_ERR "Unable to open Input SubSystem.\n"); |
return -1; |
} |
ret = ns558_init(); |
if (ret) { |
printk(KERN_ERR "Gameport_Init return: %d\n", ret); |
return -1; |
} |
//ret = analog_init(); |
ret = joydump_init(); |
if (ret) { |
printk(KERN_ERR "Joystick_Init return: %d\n", ret); |
return -1; |
} |
return 0; |
} |
int JOY26_close() { |
//analog_exit(); |
joydump_exit(); |
ns558_exit(); |
return 0; |
}*/ |
/* Init the Linux Event Debug Driver */ |
int EVBUG26_init() { |
evbug_init(); |
/shark/trunk/drivers/input/shark/mcurgrx.c |
---|
0,0 → 1,205 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: |
* Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@gandalf.sssup.it> |
* |
* Authors : |
* Paolo Gai <pj@gandalf.sssup.it> |
* Massimiliano Giorgi <massy@gandalf.sssup.it> |
* Luca Abeni <luca@gandalf.sssup.it> |
* (see the web pages for full authors list) |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
/* |
* Copyright (C) 2000 Paolo Gai |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
*/ |
/*---------------* |
* GRX Management* |
*---------------*/ |
#include <kernel/kern.h> |
//#include <drivers/glib.h> |
#include "../include/drivers/shark_input26.h" |
#include "../include/drivers/shark_mouse26.h" |
/* External functions */ |
extern void grx_getimage(WORD x1, WORD y1, WORD x2, WORD y2, BYTE *buf); |
extern void grx_putimage(WORD x1, WORD y1, WORD x2, WORD y2, BYTE *buf); |
extern int _mouse_cursor_init(int cmd, void(*my_show_cursor)(int, int), void(*my_restore_cursor)(int, int)); |
extern void _mouse_cursor_getposition(int *xptr, int *yptr); |
extern int autocursormode; |
static BYTE left_ptr_bits[] = { 0x00, 0x00, 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, |
0x78, 0x00, 0xf8, 0x00, 0xf8, 0x01, 0xf8, 0x03, |
0xf8, 0x07, 0xf8, 0x00, 0xd8, 0x00, 0x88, 0x01, |
0x80, 0x01, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00 }; |
static BYTE left_ptrmsk_bits[] = { 0x0c, 0x00, 0x1c, 0x00, 0x3c, 0x00, 0x7c, 0x00, |
0xfc, 0x00, 0xfc, 0x01, 0xfc, 0x03, 0xfc, 0x07, |
0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x01, 0xdc, 0x03, |
0xcc, 0x03, 0x80, 0x07, 0x80, 0x07, 0x00, 0x03 }; |
/* dimensions (16x16) */ |
#define SHAPE_DX MOUSESHAPEDX |
#define SHAPE_DY MOUSESHAPEDY |
/* shape hot spot (3,1) */ |
#define HOTSPOT_X MOUSEHOTSPOTX |
#define HOTSPOT_Y MOUSEHOTSPOTY |
/* cursor shape */ |
static BYTE shape[SHAPE_DX * SHAPE_DY * 4]; |
/* cursor mask */ |
static BYTE mask[SHAPE_DX * SHAPE_DY * 4]; |
/* old memory buffer */ |
static BYTE saved_shape[SHAPE_DX * SHAPE_DY * 4]; |
/* new memory buffer */ |
static BYTE new_shape[SHAPE_DX * SHAPE_DY * 4]; |
static BYTE *saved_shapeptr = (void*)DEFAULT; |
static BYTE *saved_maskptr = (void*)DEFAULT; |
static int bpp; // bytes per pixel |
/* if called with NULL -> retrieve next bit of a bits-stream |
* else -> initialize the bit stream |
*/ |
static int get_bit(BYTE *p) |
{ |
static BYTE *ptr; |
static BYTE val; |
static int c; |
if (p != NULL) { |
ptr = p; |
val = 0; |
c = 8; |
return 0; |
} |
if (c==8) { |
c = 0; |
val = *ptr; |
ptr++; |
} else |
val >>= 1; |
c++; |
return val&1; |
} |
/* show grx cursor */ |
static void show_grx_cursor(int x, int y) |
{ |
int i; |
x -= HOTSPOT_X - 1; |
y -= HOTSPOT_Y - 1; |
grx_getimage(x, y, x+SHAPE_DX-1, y+SHAPE_DY-1, saved_shape); |
for(i=0; i < SHAPE_DX*SHAPE_DY*bpp/4; i++) |
((DWORD*)new_shape)[i] = ( ((DWORD*)saved_shape)[i] & ((DWORD*)mask)[i] ) | ((DWORD*)shape)[i]; |
grx_putimage(x, y, x+SHAPE_DX-1, y+SHAPE_DY-1, new_shape); |
} |
/* restore grx cursor */ |
static void restore_grx_cursor(int x, int y) |
{ |
x -= HOTSPOT_X - 1; |
y -= HOTSPOT_Y - 1; |
grx_putimage(x, y, x+SHAPE_DX-1, y+SHAPE_DY-1, saved_shape); |
} |
int mouse_grxcursor(int cmd, int bpp) |
{ |
mouse_grxshape(saved_shapeptr, saved_maskptr, bpp); |
return _mouse_cursor_init(cmd|GRXCURSOR, show_grx_cursor, restore_grx_cursor); |
} |
/* compute the shape and mask array */ |
int mouse_grxshape(BYTE *shapeptr, BYTE *maskptr, int bpp_in) |
{ |
BYTE b; |
int pc; |
int i,j; |
int saved_x, saved_y; |
int cond; |
/*int result; |
grx_vga_modeinfo info;*/ |
/* Autocalculate bpp */ |
/*result = gd_getmodeinfo(&info); |
if (result == -1) |
return -1; |
bpp = info.bytesperpixel;*/ |
cond = ( ((autocursormode & STATUSMASK) == ENABLE) && ((autocursormode & GRXCURSOR) == GRXCURSOR) ); |
if (cond) { |
_mouse_cursor_getposition(&saved_x,&saved_y); |
restore_grx_cursor(saved_x,saved_y); |
} |
if (bpp_in != -1) |
bpp = bpp_in; |
if (shapeptr == (void*)DEFAULT) { |
shapeptr = left_ptr_bits; |
pc = 0; |
get_bit(left_ptr_bits); |
for (i = 0; i < SHAPE_DX*SHAPE_DY; i++) { |
b = get_bit(NULL) ? 255 : 0; |
for (j = 0; j < bpp; j++) |
shape[pc++] = b; |
} |
} else { |
memcpy(shape, shapeptr, SHAPE_DX*SHAPE_DY*bpp); |
saved_shapeptr = shapeptr; |
} |
if (maskptr == (void*)DEFAULT) { |
maskptr = left_ptrmsk_bits; |
pc = 0; |
get_bit(left_ptrmsk_bits); |
for (i = 0; i < SHAPE_DX*SHAPE_DY; i++) { |
b=get_bit(NULL)?0:255; |
for (j = 0; j < bpp; j++) |
mask[pc++] = b; |
} |
} else { |
memcpy(mask, maskptr, SHAPE_DX*SHAPE_DY*bpp); |
saved_maskptr = maskptr; |
} |
if (cond) |
show_grx_cursor(saved_x,saved_y); |
return 0; |
} |
/shark/trunk/drivers/input/shark/shark_joy.c |
---|
0,0 → 1,112 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: |
* Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@gandalf.sssup.it> |
* |
* Authors : |
* Mauro Marinoni <mauro.marinoni@unipv.it> |
* |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
/* |
* Copyright (C) 2000 Paolo Gai |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
*/ |
#define __JOY_DEBUG__ |
//#define __JOY_DUMP__ |
#include <kernel/kern.h> |
#include "../include/drivers/shark_input26.h" |
#include "../include/drivers/shark_joy26.h" |
#include <kernel/func.h> |
/* Devices */ |
extern int ns558_init(void); |
extern int ns558_exit(void); |
extern int analog_init(void); |
extern int analog_exit(void); |
extern int joydump_init(void); |
extern int joydump_exit(void); |
/* Handler */ |
extern int joystick_init(void); |
extern int joystick_exit(void); |
extern int input_installed; |
/* User Functions */ |
/* Init the Linux Joystick Driver */ |
int JOY26_init() { |
int ret; |
if (input_installed == FALSE) |
if (INPUT26_init()) { |
printk(KERN_ERR "Unable to open Input SubSystem.\n"); |
return -1; |
} |
ret = ns558_init(); |
if (ret) { |
printk(KERN_ERR "Gameport_Init return: %d\n", ret); |
return -1; |
} |
#ifdef __JOY_DUMP__ |
ret = joydump_init(); |
#else |
ret = analog_init(); |
#endif |
if (ret) { |
printk(KERN_ERR "Joystick_Device_Init return: %d\n", ret); |
return -1; |
} |
ret = joystick_init(); |
if (ret) { |
printk(KERN_ERR "Joystick_Handler_Init return: %d\n", ret); |
return -1; |
} |
return 0; |
} |
int JOY26_close() { |
joystick_exit(); |
#ifdef __JOY_DUMP__ |
joydump_exit(); |
#else |
analog_exit(); |
#endif |
ns558_exit(); |
return 0; |
} |