Subversion Repositories shark

Rev

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