Subversion Repositories shark

Rev

Rev 486 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
485 giacomo 1
#include <ll/i386/hw-data.h>
2
#include <ll/i386/mem.h>
3
#include <linux/fb.h>
4
 
5
#include <drivers/grx_fb.h>
6
 
7
static unsigned char font_table[127][8] =
8
      {
9
        {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
10
        {0x7e, 0x81, 0xa5, 0x81, 0xbd, 0x99, 0x81, 0x7e},
11
        {0x7e, 0xff, 0xdb, 0xff, 0xc3, 0xe7, 0xff, 0x7e},
12
        {0x6c, 0xfe, 0xfe, 0xfe, 0x7c, 0x38, 0x10, 0x00},
13
        {0x10, 0x38, 0x7c, 0xfe, 0x7c, 0x38, 0x10, 0x00},
14
        {0x38, 0x7c, 0x38, 0xfe, 0xfe, 0x7c, 0x38, 0x7c},
15
        {0x10, 0x10, 0x38, 0x7c, 0xfe, 0x7c, 0x38, 0x7c},
16
        {0x00, 0x00, 0x18, 0x3c, 0x3c, 0x18, 0x00, 0x00},
17
        {0xff, 0xff, 0xe7, 0xc3, 0xc3, 0xe7, 0xff, 0xff},
18
        {0x00, 0x3c, 0x66, 0x42, 0x42, 0x66, 0x3c, 0x00},
19
        {0xff, 0xc3, 0x99, 0xbd, 0xbd, 0x99, 0xc3, 0xff},
20
        {0x0f, 0x07, 0x0f, 0x7d, 0xcc, 0xcc, 0xcc, 0x78},
21
        {0x3c, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x7e, 0x18},
22
        {0x3f, 0x33, 0x3f, 0x30, 0x30, 0x70, 0xf0, 0xe0},
23
        {0x7f, 0x63, 0x7f, 0x63, 0x63, 0x67, 0xe6, 0xc0},
24
        {0x99, 0x5a, 0x3c, 0xe7, 0xe7, 0x3c, 0x5a, 0x99},
25
        {0x80, 0xe0, 0xf8, 0xfe, 0xf8, 0xe0, 0x80, 0x00},
26
        {0x02, 0x0e, 0x3e, 0xfe, 0x3e, 0x0e, 0x02, 0x00},
27
        {0x18, 0x3c, 0x7e, 0x18, 0x18, 0x7e, 0x3c, 0x18},
28
        {0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x00},
29
        {0x7f, 0xdb, 0xdb, 0x7b, 0x1b, 0x1b, 0x1b, 0x00},
30
        {0x3e, 0x63, 0x38, 0x6c, 0x6c, 0x38, 0xcc, 0x78},
31
        {0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x00},
32
        {0x18, 0x3c, 0x7e, 0x18, 0x7e, 0x3c, 0x18, 0xff},
33
        {0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x00},
34
        {0x18, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x00},
35
        {0x00, 0x18, 0x0c, 0xfe, 0x0c, 0x18, 0x00, 0x00},
36
        {0x00, 0x30, 0x60, 0xfe, 0x60, 0x30, 0x00, 0x00},
37
        {0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xfe, 0x00, 0x00},
38
        {0x00, 0x24, 0x66, 0xff, 0x66, 0x24, 0x00, 0x00},
39
        {0x00, 0x18, 0x3c, 0x7e, 0xff, 0xff, 0x00, 0x00},
40
        {0x00, 0xff, 0xff, 0x7e, 0x3c, 0x18, 0x00, 0x00},
41
        {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
42
        {0x30, 0x78, 0x78, 0x30, 0x30, 0x00, 0x30, 0x00},
43
        {0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00},
44
        {0x6c, 0x6c, 0xfe, 0x6c, 0xfe, 0x6c, 0x6c, 0x00},
45
        {0x30, 0x7c, 0xc0, 0x78, 0x0c, 0xf8, 0x30, 0x00},
46
        {0x00, 0xc6, 0xcc, 0x18, 0x30, 0x66, 0xc6, 0x00},
47
        {0x38, 0x6c, 0x38, 0x76, 0xdc, 0xcc, 0x76, 0x00},
48
        {0x60, 0x60, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00},
49
        {0x18, 0x30, 0x60, 0x60, 0x60, 0x30, 0x18, 0x00},
50
        {0x60, 0x30, 0x18, 0x18, 0x18, 0x30, 0x60, 0x00},
51
        {0x00, 0x66, 0x3c, 0xff, 0x3c, 0x66, 0x00, 0x00},
52
        {0x00, 0x30, 0x30, 0xfc, 0x30, 0x30, 0x00, 0x00},
53
        {0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x60},
54
        {0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00},
55
        {0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00},
56
        {0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x80, 0x00},
57
        {0x7c, 0xc6, 0xce, 0xde, 0xf6, 0xe6, 0x7c, 0x00},
58
        {0x30, 0x70, 0x30, 0x30, 0x30, 0x30, 0xfc, 0x00},
59
        {0x78, 0xcc, 0x0c, 0x38, 0x60, 0xcc, 0xfc, 0x00},
60
        {0x78, 0xcc, 0x0c, 0x38, 0x0c, 0xcc, 0x78, 0x00},
61
        {0x1c, 0x3c, 0x6c, 0xcc, 0xfe, 0x0c, 0x1e, 0x00},
62
        {0xfc, 0xc0, 0xf8, 0x0c, 0x0c, 0xcc, 0x78, 0x00},
63
        {0x38, 0x60, 0xc0, 0xf8, 0xcc, 0xcc, 0x78, 0x00},
64
        {0xfc, 0xcc, 0x0c, 0x18, 0x30, 0x30, 0x30, 0x00},
65
        {0x78, 0xcc, 0xcc, 0x78, 0xcc, 0xcc, 0x78, 0x00},
66
        {0x78, 0xcc, 0xcc, 0x7c, 0x0c, 0x18, 0x70, 0x00},
67
        {0x00, 0x30, 0x30, 0x00, 0x00, 0x30, 0x30, 0x00},
68
        {0x00, 0x30, 0x30, 0x00, 0x00, 0x30, 0x30, 0x60},
69
        {0x18, 0x30, 0x60, 0xc0, 0x60, 0x30, 0x18, 0x00},
70
        {0x00, 0x00, 0xfc, 0x00, 0x00, 0xfc, 0x00, 0x00},
71
        {0x60, 0x30, 0x18, 0x0c, 0x18, 0x30, 0x60, 0x00},
72
        {0x78, 0xcc, 0x0c, 0x18, 0x30, 0x00, 0x30, 0x00},
73
        {0x7c, 0xc6, 0xde, 0xde, 0xde, 0xc0, 0x78, 0x00},
74
        {0x30, 0x78, 0xcc, 0xcc, 0xfc, 0xcc, 0xcc, 0x00},
75
        {0xfc, 0x66, 0x66, 0x7c, 0x66, 0x66, 0xfc, 0x00},
76
        {0x3c, 0x66, 0xc0, 0xc0, 0xc0, 0x66, 0x3c, 0x00},
77
        {0xf8, 0x6c, 0x66, 0x66, 0x66, 0x6c, 0xf8, 0x00},
78
        {0xfe, 0x62, 0x68, 0x78, 0x68, 0x62, 0xfe, 0x00},
79
        {0xfe, 0x62, 0x68, 0x78, 0x68, 0x60, 0xf0, 0x00},
80
        {0x3c, 0x66, 0xc0, 0xc0, 0xce, 0x66, 0x3e, 0x00},
81
        {0xcc, 0xcc, 0xcc, 0xfc, 0xcc, 0xcc, 0xcc, 0x00},
82
        {0x78, 0x30, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00},
83
        {0x1e, 0x0c, 0x0c, 0x0c, 0xcc, 0xcc, 0x78, 0x00},
84
        {0xe6, 0x66, 0x6c, 0x78, 0x6c, 0x66, 0xe6, 0x00},
85
        {0xf0, 0x60, 0x60, 0x60, 0x62, 0x66, 0xfe, 0x00},
86
        {0xc6, 0xee, 0xfe, 0xfe, 0xd6, 0xc6, 0xc6, 0x00},
87
        {0xc6, 0xe6, 0xf6, 0xde, 0xce, 0xc6, 0xc6, 0x00},
88
        {0x38, 0x6c, 0xc6, 0xc6, 0xc6, 0x6c, 0x38, 0x00},
89
        {0xfc, 0x66, 0x66, 0x7c, 0x60, 0x60, 0xf0, 0x00},
90
        {0x78, 0xcc, 0xcc, 0xcc, 0xdc, 0x78, 0x1c, 0x00},
91
        {0xfc, 0x66, 0x66, 0x7c, 0x6c, 0x66, 0xe6, 0x00},
92
        {0x78, 0xcc, 0xe0, 0x70, 0x1c, 0xcc, 0x78, 0x00},
93
        {0xfc, 0xb4, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00},
94
        {0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xfc, 0x00},
95
        {0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x78, 0x30, 0x00},
96
        {0xc6, 0xc6, 0xc6, 0xd6, 0xfe, 0xee, 0xc6, 0x00},
97
        {0xc6, 0xc6, 0x6c, 0x38, 0x38, 0x6c, 0xc6, 0x00},
98
        {0xcc, 0xcc, 0xcc, 0x78, 0x30, 0x30, 0x78, 0x00},
99
        {0xfe, 0xc6, 0x8c, 0x18, 0x32, 0x66, 0xfe, 0x00},
100
        {0x78, 0x60, 0x60, 0x60, 0x60, 0x60, 0x78, 0x00},
101
        {0xc0, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x02, 0x00},
102
        {0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78, 0x00},
103
        {0x10, 0x38, 0x6c, 0xc6, 0x00, 0x00, 0x00, 0x00},
104
        {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff},
105
        {0x30, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00},
106
        {0x00, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0x76, 0x00},
107
        {0xe0, 0x60, 0x60, 0x7c, 0x66, 0x66, 0xdc, 0x00},
108
        {0x00, 0x00, 0x78, 0xcc, 0xc0, 0xcc, 0x78, 0x00},
109
        {0x1c, 0x0c, 0x0c, 0x7c, 0xcc, 0xcc, 0x76, 0x00},
110
        {0x00, 0x00, 0x78, 0xcc, 0xfc, 0xc0, 0x78, 0x00},
111
        {0x38, 0x6c, 0x60, 0xf0, 0x60, 0x60, 0xf0, 0x00},
112
        {0x00, 0x00, 0x76, 0xcc, 0xcc, 0x7c, 0x0c, 0xf8},
113
        {0xe0, 0x60, 0x6c, 0x76, 0x66, 0x66, 0xe6, 0x00},
114
        {0x30, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00},
115
        {0x0c, 0x00, 0x0c, 0x0c, 0x0c, 0xcc, 0xcc, 0x78},
116
        {0xe0, 0x60, 0x66, 0x6c, 0x78, 0x6c, 0xe6, 0x00},
117
        {0x70, 0x30, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00},
118
        {0x00, 0x00, 0xcc, 0xfe, 0xfe, 0xd6, 0xc6, 0x00},
119
        {0x00, 0x00, 0xf8, 0xcc, 0xcc, 0xcc, 0xcc, 0x00},
120
        {0x00, 0x00, 0x78, 0xcc, 0xcc, 0xcc, 0x78, 0x00},
121
        {0x00, 0x00, 0xdc, 0x66, 0x66, 0x7c, 0x60, 0xf0},
122
        {0x00, 0x00, 0x76, 0xcc, 0xcc, 0x7c, 0x0c, 0x1e},
123
        {0x00, 0x00, 0xdc, 0x76, 0x66, 0x60, 0xf0, 0x00},
124
        {0x00, 0x00, 0x7c, 0xc0, 0x78, 0x0c, 0xf8, 0x00},
125
        {0x10, 0x30, 0x7c, 0x30, 0x30, 0x34, 0x18, 0x00},
126
        {0x00, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00},
127
        {0x00, 0x00, 0xcc, 0xcc, 0xcc, 0x78, 0x30, 0x00},
128
        {0x00, 0x00, 0xc6, 0xd6, 0xfe, 0xfe, 0x6c, 0x00},
129
        {0x00, 0x00, 0xc6, 0x6c, 0x38, 0x6c, 0xc6, 0x00},
130
        {0x00, 0x00, 0xcc, 0xcc, 0xcc, 0x7c, 0x0c, 0xf8},
131
        {0x00, 0x00, 0xfc, 0x98, 0x30, 0x64, 0xfc, 0x00},
132
        {0x1c, 0x30, 0x30, 0xe0, 0x30, 0x30, 0x1c, 0x00},
133
        {0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00},
134
        {0xe0, 0x30, 0x30, 0x1c, 0x30, 0x30, 0xe0, 0x00},
135
        {0x76, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
136
      };
137
 
138
#define memsetw(addr, val, n) {LIN_ADDR i; for(i = addr; i < addr + n; i += 2) *(WORD *)i = val;}
139
 
140
struct fb_info *grx_info = NULL;
141
 
142
void grx_fb_init(struct fb_info *info)
143
{
144
 
145
  if (!info) return;
146
 
147
  grx_info = info;
148
 
149
}
150
 
151
void grx_putimage(WORD x1, WORD y1, WORD x2, WORD y2, BYTE *buf)
152
{
153
 
154
  struct fb_image image;
155
 
156
  if (!grx_info || grx_info->var.bits_per_pixel != 16) return;
157
 
158
  image.depth = grx_info->var.bits_per_pixel;
159
  image.data = buf;
160
  image.width = x2-x1+1;
161
  image.height = y2-y1+1;
162
  image.dy = y1;
163
  image.dx = x1;
164
 
165
  grx_info->fbops->fb_imageblit(grx_info, &image);
166
 
167
}
168
 
169
void grx_getimage(WORD x1, WORD y1, WORD x2, WORD y2, BYTE *buf)
170
{
171
    WORD bpr;
172
    LIN_ADDR addr, p;
173
    WORD dx, y;
174
 
175
    if (!grx_info || grx_info->var.bits_per_pixel != 16) return;
176
 
177
    bpr = grx_info->var.xres * 2;
178
    p = buf;
179
    addr = (LIN_ADDR)(grx_info->screen_base + x1 * 2 + bpr * y1);
180
    dx = (x2 - x1 + 1) * 2;
181
 
182
    for (y = y1; y <= y2; y++) {
183
        memcpy(p, addr, dx);
184
        p += dx;
185
        addr += bpr;
186
    }
187
 
188
}
189
 
190
void grx_box(WORD x1, WORD y1, WORD x2, WORD y2, DWORD color)
191
{
192
 
193
  struct fb_fillrect rect;
194
 
195
  if (!grx_info || grx_info->var.bits_per_pixel != 16) return;
196
 
197
  rect.dx = x1;
198
  rect.dy = y1;
199
  rect.width = x2-x1+1;
200
  rect.height = x2-x1+1;
201
  rect.color = color;
202
  rect.rop = ROP_COPY;
203
 
204
  grx_info->fbops->fb_fillrect(grx_info, &rect);
205
 
206
}
207
 
208
void grx_rect(WORD x1, WORD y1, WORD x2, WORD y2, DWORD color)
209
{
210
    WORD bpr;
211
    DWORD addr;
212
    WORD dx, y;
213
 
214
    if (!grx_info || grx_info->var.bits_per_pixel != 16) return;
215
 
216
    bpr = grx_info->var.xres * 2;
217
    addr = (DWORD)(grx_info->screen_base + x1 * 2 + bpr * y1);
218
    dx = (x2 - x1) * 2;
219
 
220
    memsetw((LIN_ADDR)addr, color, dx+2);
221
    addr += bpr;
222
 
223
    for (y = y1 + 1; y <= y2 - 1; y++) {
224
        *(WORD *)addr = color;
225
        *(WORD *)(addr + dx) = color;
226
        addr += bpr;
227
    }
228
    memsetw((LIN_ADDR)addr, color, dx+2);
229
}
230
 
231
void grx_text(char *text, WORD x, WORD y, DWORD fg, DWORD bg)
232
{
233
    DWORD fp, addr;
234
    WORD bpr;
235
    int r, c, bits;
236
 
237
    if (!grx_info || grx_info->var.bits_per_pixel != 16) return;
238
 
239
    bpr = grx_info->var.xres * 2;
240
    addr = (DWORD)(grx_info->screen_base);
241
    while (*text) {
242
        fp = (DWORD)&(font_table[*(BYTE *)text][0]);
243
        for (r=0; r<8; r++) {
244
            bits = *(BYTE *)(fp++);
245
            for (c=0; c<8; c++)
246
                if (bits & (0x80>>c))
247
                    *(WORD *)(addr + (y + r) * bpr + ((x + c) * 2)) =  fg;
248
                else
249
                    *(WORD *)(addr + (y + r) * bpr + ((x + c) * 2)) = bg;
250
        }
251
        text++;
252
        x += 8;
253
    }
254
}
255
 
256
void linLine16(WORD x1, WORD y1, WORD x2, WORD y2, DWORD color)
257
{
258
    register int t, distance;
259
    register DWORD addr;
260
    register WORD bpr;
261
    int xerr=0, yerr=0, deltax, deltay;
262
    int incx, incy;
263
 
264
    bpr = grx_info->var.xres * 2;
265
    addr = (DWORD)(grx_info->screen_base);
266
    deltax = x2 - x1;                   /* compute both distances */
267
    deltay = y2 - y1;
268
 
269
    if (deltax > 0)                     /* compute increments */
270
        incx = 1;
271
    else if (deltax == 0)
272
        incx = 0;
273
    else
274
        incx = -1;
275
 
276
    if (deltay > 0)
277
        incy = 1;
278
    else if (deltay == 0)
279
        incy = 0;
280
    else
281
        incy = -1;
282
 
283
    deltax = abs(deltax);               /* determine greater distance */
284
    deltay = abs(deltay);
285
    if (deltax > deltay)
286
        distance = deltax;
287
    else
288
        distance = deltay;
289
 
290
    for (t=0; t<=distance+1; t++) {     /* draw the line */
291
        *(WORD *)(addr + y1 * bpr + (x1 * 2)) = color;
292
        xerr += deltax;
293
        yerr += deltay;
294
        if (xerr > distance) {
295
            xerr -= distance;
296
            x1 += incx;
297
        }
298
        if (yerr > distance) {
299
            yerr -= distance;
300
            y1 += incy;
301
        }
302
    }
303
}
304
 
305
void grx_plot(WORD x, WORD y, DWORD color)
306
{
307
    WORD bpr;
308
 
309
    if (!grx_info || grx_info->var.bits_per_pixel != 16) return;
310
 
311
    bpr = grx_info->var.xres * 2;
312
    *(WORD *)(grx_info->screen_base + y * bpr + (x * 2)) = color;
313
}
314
 
315
DWORD grx_getpixel(WORD x, WORD y)
316
{
317
    WORD bpr;
318
    DWORD rv;
319
 
320
    if (!grx_info || grx_info->var.bits_per_pixel != 16) return -1;
321
 
322
    bpr = grx_info->var.xres * 2;
323
    rv = *(WORD *)(grx_info->screen_base + y * bpr + (x * 2));
324
    return rv;
325
 
326
}
327
 
328
static void circlepixels(WORD x, WORD y, WORD sx, WORD sy, DWORD c)
329
{
330
    grx_plot(sx + x, sy + y, c);
331
    grx_plot(sx - x, sy + y, c);
332
    grx_plot(sx + x, sy - y, c);
333
    grx_plot(sx - x, sy - y, c);
334
    grx_plot(sx + y, sy + x, c);
335
    grx_plot(sx - y, sy + x, c);
336
    grx_plot(sx + y, sy - x, c);
337
    grx_plot(sx - y, sy - x, c);
338
}
339
 
340
void grx_circle(WORD sx, WORD sy, WORD r, DWORD c)
341
{
342
    int x, y, d;
343
 
344
    if (!grx_info || grx_info->var.bits_per_pixel != 16) return;
345
 
346
    if (r < 1) {
347
        grx_plot(sx, sy, c);
348
        return;
349
    }
350
 
351
    x = 0;
352
    y = r;
353
    d = 1 - r;
354
    circlepixels(x, y, sx, sy, c);
355
    while (x < y) {
356
        if (d < 0)
357
            d += x * 2 + 3;
358
        else {
359
            d += x * 2 - y * 2 + 5;
360
            y--;
361
        }
362
        x++;
363
        circlepixels(x, y, sx, sy, c);
364
    }
365
}
366
 
367
static __inline__ void discpixels(WORD x, WORD y, WORD sx, WORD sy, DWORD c)
368
{
369
    grx_line(sx + x, sy + y, sx + x, sy - y, c);
370
    grx_line(sx - x, sy + y, sx - x, sy - y, c);
371
    grx_line(sx + y, sy + x, sx + y, sy - x , c);
372
    grx_line(sx - y, sy + x, sx - y, sy - x , c);
373
}
374
 
375
void grx_disc(WORD sx, WORD sy, WORD r, DWORD c)
376
{
377
    int x, y, d;
378
 
379
    if (!grx_info || grx_info->var.bits_per_pixel != 16) return;
380
 
381
    if (r < 1) {
382
        grx_plot(sx, sy, c);
383
        return;
384
    }
385
    x = 0;
386
    y = r;
387
    d = 1 - r;
388
    discpixels(x, y, sx, sy, c);
389
    while (x < y) {
390
        if (d < 0)
391
            d += x * 2 + 3;
392
        else {
393
            d += x * 2 - y * 2 + 5;
394
            y--;
395
        }
396
        x++;   
397
        discpixels(x, y, sx, sy, c);
398
    }
399
}
400