Subversion Repositories shark

Rev

Rev 1030 | 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>
1030 tullio 12
 *   Tullio Facchinetti  <tullio.facchinetti@unipv.it>
538 mauro 13
 *   (see the web pages for full authors list)
14
 *
15
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
16
 *
17
 * http://www.sssup.it
18
 * http://retis.sssup.it
19
 * http://shark.sssup.it
20
 */
21
 
1063 tullio 22
/*
23
 * This program is free software; you can redistribute it and/or modify
24
 * it under the terms of the GNU General Public License as published by
25
 * the Free Software Foundation; either version 2 of the License, or
26
 * (at your option) any later version.
27
 *
28
 * This program is distributed in the hope that it will be useful,
29
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31
 * GNU General Public License for more details.
32
 *
33
 * You should have received a copy of the GNU General Public License
34
 * along with this program; if not, write to the Free Software
35
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
36
 *
37
 */
38
 
538 mauro 39
/*---------------*
40
 * GRX Management*
41
 *---------------*/
42
 
43
#include <kernel/kern.h>
44
//#include <drivers/glib.h>
45
 
46
#include "../include/drivers/shark_input26.h"
47
#include "../include/drivers/shark_mouse26.h"
48
 
49
/* External functions */
1030 tullio 50
extern void grx_getimage(WORD x1, WORD y1, WORD x2, WORD y2, WORD *buf);  // Tool
51
extern void grx_putimage(WORD x1, WORD y1, WORD x2, WORD y2, WORD *buf);  // Tool
538 mauro 52
extern int _mouse_cursor_init(int cmd, void(*my_show_cursor)(int, int), void(*my_restore_cursor)(int, int));
53
extern void _mouse_cursor_getposition(int *xptr, int *yptr);
54
 
55
extern int autocursormode;
56
 
57
static BYTE left_ptr_bits[] = { 0x00, 0x00, 0x08, 0x00, 0x18, 0x00, 0x38, 0x00,
58
                                0x78, 0x00, 0xf8, 0x00, 0xf8, 0x01, 0xf8, 0x03,
59
                                0xf8, 0x07, 0xf8, 0x00, 0xd8, 0x00, 0x88, 0x01,
60
                                0x80, 0x01, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00 };
61
 
62
 
63
static BYTE left_ptrmsk_bits[] = { 0x0c, 0x00, 0x1c, 0x00, 0x3c, 0x00, 0x7c, 0x00,
64
                                   0xfc, 0x00, 0xfc, 0x01, 0xfc, 0x03, 0xfc, 0x07,
65
                                   0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x01, 0xdc, 0x03,
66
                                   0xcc, 0x03, 0x80, 0x07, 0x80, 0x07, 0x00, 0x03 };
67
 
68
/* dimensions (16x16) */
69
#define SHAPE_DX MOUSESHAPEDX
70
#define SHAPE_DY MOUSESHAPEDY
71
 
72
/* shape hot spot (3,1) */
73
#define HOTSPOT_X MOUSEHOTSPOTX
74
#define HOTSPOT_Y MOUSEHOTSPOTY
75
 
76
/* cursor shape */
77
static BYTE shape[SHAPE_DX * SHAPE_DY * 4];
78
/* cursor mask */
79
static BYTE mask[SHAPE_DX * SHAPE_DY * 4];
80
 
81
/* old memory buffer */
82
static BYTE saved_shape[SHAPE_DX * SHAPE_DY * 4];
83
/* new memory buffer */
84
static BYTE new_shape[SHAPE_DX * SHAPE_DY * 4];
85
 
86
static BYTE *saved_shapeptr = (void*)DEFAULT;
87
static BYTE *saved_maskptr = (void*)DEFAULT;
88
 
89
static int bpp; // bytes per pixel
90
 
91
/* if called with NULL -> retrieve next bit of a bits-stream
92
 * else                -> initialize the bit stream
93
 */
94
static int get_bit(BYTE *p)
95
{
96
        static BYTE *ptr;
97
        static BYTE val;
98
        static int  c;
99
 
100
        if (p != NULL) {
101
                ptr = p;
102
                val = 0;
103
                c = 8;
104
                return 0;
105
        }
106
 
107
        if (c==8) {
108
                c = 0;
109
                val = *ptr;
110
                ptr++;
111
        } else
112
                val >>= 1;
113
 
114
        c++;
115
        return val&1;
116
}
117
 
118
/* show grx cursor */
119
static void show_grx_cursor(int x, int y)
120
{
121
        int i;
122
 
123
        x -= HOTSPOT_X - 1;
124
        y -= HOTSPOT_Y - 1;
125
        grx_getimage(x, y, x+SHAPE_DX-1, y+SHAPE_DY-1, saved_shape);
126
        for(i=0; i < SHAPE_DX*SHAPE_DY*bpp/4; i++)
127
                ((DWORD*)new_shape)[i] = ( ((DWORD*)saved_shape)[i] & ((DWORD*)mask)[i] ) | ((DWORD*)shape)[i];
128
        grx_putimage(x, y, x+SHAPE_DX-1, y+SHAPE_DY-1, new_shape);
129
}
130
 
131
/* restore grx cursor */
132
static void restore_grx_cursor(int x, int y)
133
{
134
        x -= HOTSPOT_X - 1;
135
        y -= HOTSPOT_Y - 1;
136
        grx_putimage(x, y, x+SHAPE_DX-1, y+SHAPE_DY-1, saved_shape);
137
}
138
 
139
int mouse_grxcursor(int cmd, int bpp)
140
{
141
        mouse_grxshape(saved_shapeptr, saved_maskptr, bpp);
142
        return _mouse_cursor_init(cmd|GRXCURSOR, show_grx_cursor, restore_grx_cursor);
143
}
144
 
145
/* compute the shape and mask array */
146
int mouse_grxshape(BYTE *shapeptr, BYTE *maskptr, int bpp_in)
147
{
148
        BYTE b;
149
        int  pc;
150
        int  i,j;
151
        int  saved_x, saved_y;
152
        int  cond;
153
        /*int  result;
154
        grx_vga_modeinfo info;*/
155
 
156
        /* Autocalculate bpp */
157
        /*result = gd_getmodeinfo(&info);
158
        if (result == -1)
159
                return -1;
160
        bpp = info.bytesperpixel;*/
161
 
162
        cond = ( ((autocursormode & STATUSMASK) == ENABLE) && ((autocursormode & GRXCURSOR) == GRXCURSOR) );
163
 
164
        if (cond) {
165
                _mouse_cursor_getposition(&saved_x,&saved_y);
166
                restore_grx_cursor(saved_x,saved_y);
167
        }
168
 
169
        if (bpp_in != -1)
170
                bpp = bpp_in;
171
 
172
        if (shapeptr == (void*)DEFAULT) {
173
                shapeptr = left_ptr_bits;
174
                pc = 0;
175
                get_bit(left_ptr_bits);
176
                for (i = 0; i < SHAPE_DX*SHAPE_DY; i++) {
177
                        b = get_bit(NULL) ? 255 : 0;
178
                        for (j = 0; j < bpp; j++)
179
                                shape[pc++] = b;
180
                }
181
        } else {
182
                memcpy(shape, shapeptr, SHAPE_DX*SHAPE_DY*bpp);
183
                saved_shapeptr = shapeptr;
184
        }
185
 
186
        if (maskptr == (void*)DEFAULT) {
187
                maskptr = left_ptrmsk_bits;
188
                pc = 0;
189
                get_bit(left_ptrmsk_bits);
190
                for (i = 0; i < SHAPE_DX*SHAPE_DY; i++) {
191
                        b=get_bit(NULL)?0:255;
192
                        for (j = 0; j < bpp; j++)
193
                                mask[pc++] = b;
194
                }
195
        } else {
196
                memcpy(mask, maskptr, SHAPE_DX*SHAPE_DY*bpp);
197
                saved_maskptr = maskptr;
198
        }
199
 
200
        if (cond)
201
                show_grx_cursor(saved_x,saved_y);
202
 
203
        return 0;
204
}