Subversion Repositories shark

Rev

Rev 538 | Rev 1030 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
538 mauro 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Paolo Gai           <pj@gandalf.sssup.it>
10
 *   Massimiliano Giorgi <massy@gandalf.sssup.it>
11
 *   Luca Abeni          <luca@gandalf.sssup.it>
12
 *   (see the web pages for full authors list)
13
 *
14
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
15
 *
16
 * http://www.sssup.it
17
 * http://retis.sssup.it
18
 * http://shark.sssup.it
19
 */
20
 
21
/*---------------*
22
 * GRX Management*
23
 *---------------*/
24
 
25
#include <kernel/kern.h>
26
//#include <drivers/glib.h>
27
 
28
#include "../include/drivers/shark_input26.h"
29
#include "../include/drivers/shark_mouse26.h"
30
 
31
/* External functions */
32
extern void grx_getimage(WORD x1, WORD y1, WORD x2, WORD y2, BYTE *buf);
33
extern void grx_putimage(WORD x1, WORD y1, WORD x2, WORD y2, BYTE *buf);
34
extern int _mouse_cursor_init(int cmd, void(*my_show_cursor)(int, int), void(*my_restore_cursor)(int, int));
35
extern void _mouse_cursor_getposition(int *xptr, int *yptr);
36
 
37
extern int autocursormode;
38
 
39
static BYTE left_ptr_bits[] = { 0x00, 0x00, 0x08, 0x00, 0x18, 0x00, 0x38, 0x00,
40
				0x78, 0x00, 0xf8, 0x00, 0xf8, 0x01, 0xf8, 0x03,
41
				0xf8, 0x07, 0xf8, 0x00, 0xd8, 0x00, 0x88, 0x01,
42
				0x80, 0x01, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00 };
43
 
44
 
45
static BYTE left_ptrmsk_bits[] = { 0x0c, 0x00, 0x1c, 0x00, 0x3c, 0x00, 0x7c, 0x00,
46
				   0xfc, 0x00, 0xfc, 0x01, 0xfc, 0x03, 0xfc, 0x07,
47
				   0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x01, 0xdc, 0x03,
48
				   0xcc, 0x03, 0x80, 0x07, 0x80, 0x07, 0x00, 0x03 };
49
 
50
/* dimensions (16x16) */
51
#define SHAPE_DX MOUSESHAPEDX
52
#define SHAPE_DY MOUSESHAPEDY
53
 
54
/* shape hot spot (3,1) */
55
#define HOTSPOT_X MOUSEHOTSPOTX
56
#define HOTSPOT_Y MOUSEHOTSPOTY
57
 
58
/* cursor shape */
59
static BYTE shape[SHAPE_DX * SHAPE_DY * 4];
60
/* cursor mask */
61
static BYTE mask[SHAPE_DX * SHAPE_DY * 4];
62
 
63
/* old memory buffer */
64
static BYTE saved_shape[SHAPE_DX * SHAPE_DY * 4];
65
/* new memory buffer */
66
static BYTE new_shape[SHAPE_DX * SHAPE_DY * 4];
67
 
68
static BYTE *saved_shapeptr = (void*)DEFAULT;
69
static BYTE *saved_maskptr = (void*)DEFAULT;
70
 
71
static int bpp; // bytes per pixel
72
 
73
/* if called with NULL -> retrieve next bit of a bits-stream
74
 * else                -> initialize the bit stream
75
 */
76
static int get_bit(BYTE *p)
77
{
78
	static BYTE *ptr;
79
	static BYTE val;
80
	static int  c;
81
 
82
	if (p != NULL) {
83
		ptr = p;
84
		val = 0;
85
		c = 8;
86
		return 0;
87
	}
88
 
89
	if (c==8) {
90
		c = 0;
91
		val = *ptr;
92
		ptr++;
93
	} else
94
		val >>= 1;
95
 
96
	c++;
97
	return val&1;
98
}
99
 
100
/* show grx cursor */
101
static void show_grx_cursor(int x, int y)
102
{
103
	int i;
104
 
105
	x -= HOTSPOT_X - 1;
106
	y -= HOTSPOT_Y - 1;
107
	grx_getimage(x, y, x+SHAPE_DX-1, y+SHAPE_DY-1, saved_shape);
108
	for(i=0; i < SHAPE_DX*SHAPE_DY*bpp/4; i++)
109
		((DWORD*)new_shape)[i] = ( ((DWORD*)saved_shape)[i] & ((DWORD*)mask)[i] ) | ((DWORD*)shape)[i];
110
	grx_putimage(x, y, x+SHAPE_DX-1, y+SHAPE_DY-1, new_shape);
111
}
112
 
113
/* restore grx cursor */
114
static void restore_grx_cursor(int x, int y)
115
{
116
	x -= HOTSPOT_X - 1;
117
	y -= HOTSPOT_Y - 1;
118
	grx_putimage(x, y, x+SHAPE_DX-1, y+SHAPE_DY-1, saved_shape);
119
}
120
 
121
int mouse_grxcursor(int cmd, int bpp)
122
{
123
	mouse_grxshape(saved_shapeptr, saved_maskptr, bpp);
124
	return _mouse_cursor_init(cmd|GRXCURSOR, show_grx_cursor, restore_grx_cursor);
125
}
126
 
127
/* compute the shape and mask array */
128
int mouse_grxshape(BYTE *shapeptr, BYTE *maskptr, int bpp_in)
129
{
130
	BYTE b;
131
	int  pc;
132
	int  i,j;
133
	int  saved_x, saved_y;
134
	int  cond;
135
	/*int  result;
136
	grx_vga_modeinfo info;*/
137
 
138
	/* Autocalculate bpp */
139
	/*result = gd_getmodeinfo(&info);
140
	if (result == -1)
141
		return -1;
142
	bpp = info.bytesperpixel;*/
143
 
144
	cond = ( ((autocursormode & STATUSMASK) == ENABLE) && ((autocursormode & GRXCURSOR) == GRXCURSOR) );
145
 
146
	if (cond) {
147
		_mouse_cursor_getposition(&saved_x,&saved_y);
148
		restore_grx_cursor(saved_x,saved_y);
149
	}
150
 
151
	if (bpp_in != -1)
152
		bpp = bpp_in;
153
 
154
	if (shapeptr == (void*)DEFAULT) {
155
		shapeptr = left_ptr_bits;
156
		pc = 0;
157
		get_bit(left_ptr_bits);
158
		for (i = 0; i < SHAPE_DX*SHAPE_DY; i++) {
159
			b = get_bit(NULL) ? 255 : 0;
160
			for (j = 0; j < bpp; j++)
161
				shape[pc++] = b;
162
		}
163
	} else {
164
		memcpy(shape, shapeptr, SHAPE_DX*SHAPE_DY*bpp);
165
		saved_shapeptr = shapeptr;
166
	}
167
 
168
	if (maskptr == (void*)DEFAULT) {
169
		maskptr = left_ptrmsk_bits;
170
		pc = 0;
171
		get_bit(left_ptrmsk_bits);
172
		for (i = 0; i < SHAPE_DX*SHAPE_DY; i++) {
173
			b=get_bit(NULL)?0:255;
174
			for (j = 0; j < bpp; j++)
175
				mask[pc++] = b;
176
		}
177
	} else {
178
		memcpy(mask, maskptr, SHAPE_DX*SHAPE_DY*bpp);
179
		saved_maskptr = maskptr;
180
	}
181
 
182
	if (cond)
183
		show_grx_cursor(saved_x,saved_y);
184
 
185
	return 0;
186
}