Subversion Repositories shark

Rev

Rev 1063 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1063 tullio 1
 
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License as published by
5
 * the Free Software Foundation; either version 2 of the License, or
6
 * (at your option) any later version.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 * GNU General Public License for more details.
12
 *
13
 * You should have received a copy of the GNU General Public License
14
 * along with this program; if not, write to the Free Software
15
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 *
17
 */
18
 
2 pj 19
#include <ll/i386/hw-data.h>
20
#include <ll/i386/mem.h>
1689 fabio 21
#include <arch/i386/string.h>
2 pj 22
#include <ll/i386/error.h>
23
#include <ll/sys/ll/ll-func.h>
24
 
25
#include <drivers/gd.h>
26
#include <drivers/glib.h>
27
 
28
#include "drawfun/fun8.h"
29
#include "drawfun/fun16.h"
30
 
31
/*#define FORCEBANK             // 4 dbg purpose*/
32
 
33
int videocard;
34
DWORD flbaddr = 0;
35
 
36
void (*grx_plot)(WORD x, WORD y, DWORD color);
37
DWORD (*grx_getpixel)(WORD x, WORD y);
1030 tullio 38
void (*grx_getimage)(WORD x1, WORD y1, WORD x2, WORD y2, WORD *buf);  // Tool
39
void (*grx_putimage)(WORD x1, WORD y1, WORD x2, WORD y2, WORD *buf);  // Tool
2 pj 40
void (*grx_box)(WORD x1, WORD y1, WORD x2, WORD y2, DWORD color);
41
void (*grx_rect)(WORD x1, WORD y1, WORD x2, WORD y2, DWORD color);
42
void (*grx_line)(WORD x1, WORD y1, WORD x2, WORD y2, DWORD color);
43
void (*grx_text)(char *text, WORD x, WORD y, DWORD fg, DWORD bg);
44
void (*grx_circle)(WORD x, WORD y, WORD r, DWORD col);
45
void (*grx_disc)(WORD x, WORD y, WORD r, DWORD col);
46
 
47
void dummyfun(void)
48
{
49
    error("Not yet implemented...\n");
50
    ll_abort(500);
51
}
52
 
53
static void circlepixels(WORD x, WORD y, WORD sx, WORD sy, DWORD c)
54
{
55
    grx_plot(sx + x, sy + y, c);
56
    grx_plot(sx - x, sy + y, c);
57
    grx_plot(sx + x, sy - y, c);
58
    grx_plot(sx - x, sy - y, c);
59
    grx_plot(sx + y, sy + x, c);
60
    grx_plot(sx - y, sy + x, c);
61
    grx_plot(sx + y, sy - x, c);
62
    grx_plot(sx - y, sy - x, c);
63
}
64
 
65
void circle(WORD sx, WORD sy, WORD r, DWORD c)
66
{
67
    int x, y, d;
68
 
69
        if (r < 1) {
70
        grx_plot(sx, sy, c);
71
        return;
72
    }
73
    x = 0;
74
    y = r;
75
    d = 1 - r;
76
    circlepixels(x, y, sx, sy, c);
77
    while (x < y) {
78
        if (d < 0)
79
            d += x * 2 + 3;
80
        else {
81
            d += x * 2 - y * 2 + 5;
82
            y--;
83
        }
84
        x++;
85
        circlepixels(x, y, sx, sy, c);
86
    }
87
}
88
 
89
/* grx_disc by Massy */
90
 
91
static __inline__ void discpixels(WORD x, WORD y, WORD sx, WORD sy, DWORD c)
92
{
93
    grx_line(sx + x, sy + y, sx + x, sy - y, c);
94
    grx_line(sx - x, sy + y, sx - x, sy - y, c);
95
    grx_line(sx + y, sy + x, sx + y, sy - x , c);
96
    grx_line(sx - y, sy + x, sx - y, sy - x , c);
97
}
98
 
99
void disc(WORD sx, WORD sy, WORD r, DWORD c)
100
{
101
    int x, y, d;
102
 
103
        if (r < 1) {
104
        grx_plot(sx, sy, c);
105
        return;
106
    }
107
    x = 0;
108
    y = r;
109
    d = 1 - r;
110
    discpixels(x, y, sx, sy, c);
111
    while (x < y) {
112
        if (d < 0)
113
            d += x * 2 + 3;
114
        else {
115
            d += x * 2 - y * 2 + 5;
116
            y--;
117
        }
118
        x++;   
119
        discpixels(x, y, sx, sy, c);
120
    }
121
}
122
 
123
int grx_init(void)
124
{
125
#ifdef FORCEBANK
126
    videocard = gd_init(NOLINEAR);
127
#else 
128
    videocard = gd_init(0);
129
#endif
130
    if (videocard < 0) {
131
        cprintf("Graphic Driver Info error...\n");
132
        return -1;
133
    }
134
    return 1;
135
}
136
 
137
int grx_close(void)
138
{
139
    gd_setmode(0);
140
    return 1;
141
}
142
 
143
int grx_setmode(WORD mode)
144
{
145
    int lin;
51 pj 146
    grx_vga_modeinfo m;
2 pj 147
 
148
    if ((lin = gd_setmode(mode)) < 0){
149
        return -1;
150
    }
151
    gd_getmodeinfo(&m);
152
 
153
    switch (m.bytesperpixel) {
154
        case 1 : if (lin == TRUE){
155
                flbaddr = gd_getflb();
156
                grx_plot = linWr8;
157
                grx_getpixel = linRd8;
158
                grx_rect = linRect8;
159
                grx_box = linBox8;
160
                grx_text = linText8;
161
                grx_line = linLine8;
162
                grx_putimage = linPut8;
163
                grx_getimage = linGet8;
164
            } else {
165
                grx_plot = WrPixel_256;
166
                grx_getpixel = RdPixel_256;
167
                grx_rect = WrRect_256;
168
                grx_box = ClrWin_256;
169
                grx_text = WrText_256;
170
                grx_line = WrLine_256;
171
                grx_putimage = WrWin_256;
172
                grx_getimage = RdWin_256;
173
            }
174
            break;
175
        case 2 : if (lin == TRUE){
176
                flbaddr = gd_getflb();
177
                grx_plot = linWr16;
178
                grx_getpixel = linRd16;
179
                grx_rect = linRect16;
180
                grx_box = linBox16;
181
                grx_text = linText16;
182
                grx_line = linLine16;
183
                grx_putimage = linPut16;
184
                grx_getimage = linGet16;
185
            } else {
186
                grx_plot = WrPixel_Hi;
187
                grx_getpixel= RdPixel_Hi;
188
                grx_rect = WrRect_Hi;
189
                grx_box = ClrWin_Hi;
190
                grx_text = WrText_Hi;
191
                grx_line = WrLine_Hi;
192
                grx_putimage = WrWin_Hi;
193
                grx_getimage = RdWin_Hi;
194
            }
195
            break;
196
        default :
197
            grx_plot = (void (*)(WORD, WORD, DWORD))dummyfun;
198
            grx_getpixel = (DWORD (*)(WORD, WORD))dummyfun;
199
            grx_rect = (void (*)(WORD, WORD, WORD, WORD, DWORD))dummyfun;
200
            grx_box = (void (*)(WORD, WORD, WORD, WORD, DWORD))dummyfun;
201
            grx_text = (void (*)(char *, WORD, WORD, DWORD, DWORD))dummyfun;
202
            grx_line = (void (*)(WORD, WORD, WORD, WORD, DWORD))dummyfun;
1030 tullio 203
            grx_putimage = (void (*)(WORD, WORD, WORD, WORD, WORD *))dummyfun;  // Tool
204
            grx_getimage = (void (*)(WORD, WORD, WORD, WORD, WORD *))dummyfun;  // Tool
2 pj 205
            break;
206
    }
207
        grx_circle = circle;
208
        grx_disc = disc;
209
    return 1;
210
}
211
 
212
void grx_modeinfo(void)
213
{
214
    gd_showmodeinfo();
215
}
216
int grx_getmode(WORD x, WORD y, BYTE depth)
217
{
218
    return gd_modenum(x, y, depth);
219
}
220
void grx_cardinfo(void)
221
{
222
    gd_showinfo();
223
}
224
 
225
void grx_getcolor(BYTE ind, BYTE *r, BYTE *g, BYTE *b)
226
{
227
    gd_getcolor(ind, r, g, b);
228
}
229
void grx_setcolor(BYTE ind,BYTE r,BYTE g,BYTE b)
230
{
231
    gd_setcolor(ind, r, g, b);
232
}
233
void grx_getpalette(BYTE start, BYTE num, BYTE *pal)
234
{
235
    gd_getpalette(start, num, pal);
236
}
237
void grx_setpalette(BYTE start, BYTE num, BYTE *pal)
238
{
239
    gd_setpalette(start, num, pal);
240
}
241
 
242
 
243
int grx_open(WORD x, WORD y, BYTE depth)
244
{
245
    int mode;
246
 
247
    mode = grx_getmode(x, y, depth);
248
 
249
    if (grx_setmode(mode) < 0) {
250
        return -1;
251
    }
252
 
253
    return 1;
254
}
255
 
256
void grx_clear(DWORD color)
257
{
51 pj 258
    grx_vga_modeinfo m;
2 pj 259
 
260
    gd_getmodeinfo(&m);
261
    grx_box(0, 0, m.width, m.height, color);
262
}