Subversion Repositories shark

Rev

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