Rev 447 | Rev 1063 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pj | 1 | #include <ll/i386/hw-data.h> |
2 | #include <ll/i386/mem.h> |
||
3 | #include <ll/i386/string.h> |
||
4 | #include <ll/i386/error.h> |
||
5 | #include <ll/sys/ll/ll-func.h> |
||
6 | |||
7 | #include <drivers/gd.h> |
||
8 | #include <drivers/glib.h> |
||
9 | |||
10 | #include "drawfun/fun8.h" |
||
11 | #include "drawfun/fun16.h" |
||
12 | |||
13 | /*#define FORCEBANK // 4 dbg purpose*/ |
||
14 | |||
15 | int videocard; |
||
16 | DWORD flbaddr = 0; |
||
17 | |||
18 | void (*grx_plot)(WORD x, WORD y, DWORD color); |
||
19 | DWORD (*grx_getpixel)(WORD x, WORD y); |
||
1030 | tullio | 20 | void (*grx_getimage)(WORD x1, WORD y1, WORD x2, WORD y2, WORD *buf); // Tool |
21 | void (*grx_putimage)(WORD x1, WORD y1, WORD x2, WORD y2, WORD *buf); // Tool |
||
2 | pj | 22 | void (*grx_box)(WORD x1, WORD y1, WORD x2, WORD y2, DWORD color); |
23 | void (*grx_rect)(WORD x1, WORD y1, WORD x2, WORD y2, DWORD color); |
||
24 | void (*grx_line)(WORD x1, WORD y1, WORD x2, WORD y2, DWORD color); |
||
25 | void (*grx_text)(char *text, WORD x, WORD y, DWORD fg, DWORD bg); |
||
26 | void (*grx_circle)(WORD x, WORD y, WORD r, DWORD col); |
||
27 | void (*grx_disc)(WORD x, WORD y, WORD r, DWORD col); |
||
28 | |||
29 | void dummyfun(void) |
||
30 | { |
||
31 | error("Not yet implemented...\n"); |
||
32 | ll_abort(500); |
||
33 | } |
||
34 | |||
35 | static void circlepixels(WORD x, WORD y, WORD sx, WORD sy, DWORD c) |
||
36 | { |
||
37 | grx_plot(sx + x, sy + y, c); |
||
38 | grx_plot(sx - x, sy + y, c); |
||
39 | grx_plot(sx + x, sy - y, c); |
||
40 | grx_plot(sx - x, sy - y, c); |
||
41 | grx_plot(sx + y, sy + x, c); |
||
42 | grx_plot(sx - y, sy + x, c); |
||
43 | grx_plot(sx + y, sy - x, c); |
||
44 | grx_plot(sx - y, sy - x, c); |
||
45 | } |
||
46 | |||
47 | void circle(WORD sx, WORD sy, WORD r, DWORD c) |
||
48 | { |
||
49 | int x, y, d; |
||
50 | |||
51 | if (r < 1) { |
||
52 | grx_plot(sx, sy, c); |
||
53 | return; |
||
54 | } |
||
55 | x = 0; |
||
56 | y = r; |
||
57 | d = 1 - r; |
||
58 | circlepixels(x, y, sx, sy, c); |
||
59 | while (x < y) { |
||
60 | if (d < 0) |
||
61 | d += x * 2 + 3; |
||
62 | else { |
||
63 | d += x * 2 - y * 2 + 5; |
||
64 | y--; |
||
65 | } |
||
66 | x++; |
||
67 | circlepixels(x, y, sx, sy, c); |
||
68 | } |
||
69 | } |
||
70 | |||
71 | /* grx_disc by Massy */ |
||
72 | |||
73 | static __inline__ void discpixels(WORD x, WORD y, WORD sx, WORD sy, DWORD c) |
||
74 | { |
||
75 | grx_line(sx + x, sy + y, sx + x, sy - y, c); |
||
76 | grx_line(sx - x, sy + y, sx - x, sy - y, c); |
||
77 | grx_line(sx + y, sy + x, sx + y, sy - x , c); |
||
78 | grx_line(sx - y, sy + x, sx - y, sy - x , c); |
||
79 | } |
||
80 | |||
81 | void disc(WORD sx, WORD sy, WORD r, DWORD c) |
||
82 | { |
||
83 | int x, y, d; |
||
84 | |||
85 | if (r < 1) { |
||
86 | grx_plot(sx, sy, c); |
||
87 | return; |
||
88 | } |
||
89 | x = 0; |
||
90 | y = r; |
||
91 | d = 1 - r; |
||
92 | discpixels(x, y, sx, sy, c); |
||
93 | while (x < y) { |
||
94 | if (d < 0) |
||
95 | d += x * 2 + 3; |
||
96 | else { |
||
97 | d += x * 2 - y * 2 + 5; |
||
98 | y--; |
||
99 | } |
||
100 | x++; |
||
101 | discpixels(x, y, sx, sy, c); |
||
102 | } |
||
103 | } |
||
104 | |||
105 | int grx_init(void) |
||
106 | { |
||
107 | #ifdef FORCEBANK |
||
108 | videocard = gd_init(NOLINEAR); |
||
109 | #else |
||
110 | videocard = gd_init(0); |
||
111 | #endif |
||
112 | if (videocard < 0) { |
||
113 | cprintf("Graphic Driver Info error...\n"); |
||
114 | return -1; |
||
115 | } |
||
116 | return 1; |
||
117 | } |
||
118 | |||
119 | int grx_close(void) |
||
120 | { |
||
121 | gd_setmode(0); |
||
122 | return 1; |
||
123 | } |
||
124 | |||
125 | int grx_setmode(WORD mode) |
||
126 | { |
||
127 | int lin; |
||
51 | pj | 128 | grx_vga_modeinfo m; |
2 | pj | 129 | |
130 | if ((lin = gd_setmode(mode)) < 0){ |
||
131 | return -1; |
||
132 | } |
||
133 | gd_getmodeinfo(&m); |
||
134 | |||
135 | switch (m.bytesperpixel) { |
||
136 | case 1 : if (lin == TRUE){ |
||
137 | flbaddr = gd_getflb(); |
||
138 | grx_plot = linWr8; |
||
139 | grx_getpixel = linRd8; |
||
140 | grx_rect = linRect8; |
||
141 | grx_box = linBox8; |
||
142 | grx_text = linText8; |
||
143 | grx_line = linLine8; |
||
144 | grx_putimage = linPut8; |
||
145 | grx_getimage = linGet8; |
||
146 | } else { |
||
147 | grx_plot = WrPixel_256; |
||
148 | grx_getpixel = RdPixel_256; |
||
149 | grx_rect = WrRect_256; |
||
150 | grx_box = ClrWin_256; |
||
151 | grx_text = WrText_256; |
||
152 | grx_line = WrLine_256; |
||
153 | grx_putimage = WrWin_256; |
||
154 | grx_getimage = RdWin_256; |
||
155 | } |
||
156 | break; |
||
157 | case 2 : if (lin == TRUE){ |
||
158 | flbaddr = gd_getflb(); |
||
159 | grx_plot = linWr16; |
||
160 | grx_getpixel = linRd16; |
||
161 | grx_rect = linRect16; |
||
162 | grx_box = linBox16; |
||
163 | grx_text = linText16; |
||
164 | grx_line = linLine16; |
||
165 | grx_putimage = linPut16; |
||
166 | grx_getimage = linGet16; |
||
167 | } else { |
||
168 | grx_plot = WrPixel_Hi; |
||
169 | grx_getpixel= RdPixel_Hi; |
||
170 | grx_rect = WrRect_Hi; |
||
171 | grx_box = ClrWin_Hi; |
||
172 | grx_text = WrText_Hi; |
||
173 | grx_line = WrLine_Hi; |
||
174 | grx_putimage = WrWin_Hi; |
||
175 | grx_getimage = RdWin_Hi; |
||
176 | } |
||
177 | break; |
||
178 | default : |
||
179 | grx_plot = (void (*)(WORD, WORD, DWORD))dummyfun; |
||
180 | grx_getpixel = (DWORD (*)(WORD, WORD))dummyfun; |
||
181 | grx_rect = (void (*)(WORD, WORD, WORD, WORD, DWORD))dummyfun; |
||
182 | grx_box = (void (*)(WORD, WORD, WORD, WORD, DWORD))dummyfun; |
||
183 | grx_text = (void (*)(char *, WORD, WORD, DWORD, DWORD))dummyfun; |
||
184 | grx_line = (void (*)(WORD, WORD, WORD, WORD, DWORD))dummyfun; |
||
1030 | tullio | 185 | grx_putimage = (void (*)(WORD, WORD, WORD, WORD, WORD *))dummyfun; // Tool |
186 | grx_getimage = (void (*)(WORD, WORD, WORD, WORD, WORD *))dummyfun; // Tool |
||
2 | pj | 187 | break; |
188 | } |
||
189 | grx_circle = circle; |
||
190 | grx_disc = disc; |
||
191 | return 1; |
||
192 | } |
||
193 | |||
194 | void grx_modeinfo(void) |
||
195 | { |
||
196 | gd_showmodeinfo(); |
||
197 | } |
||
198 | int grx_getmode(WORD x, WORD y, BYTE depth) |
||
199 | { |
||
200 | return gd_modenum(x, y, depth); |
||
201 | } |
||
202 | void grx_cardinfo(void) |
||
203 | { |
||
204 | gd_showinfo(); |
||
205 | } |
||
206 | |||
207 | void grx_getcolor(BYTE ind, BYTE *r, BYTE *g, BYTE *b) |
||
208 | { |
||
209 | gd_getcolor(ind, r, g, b); |
||
210 | } |
||
211 | void grx_setcolor(BYTE ind,BYTE r,BYTE g,BYTE b) |
||
212 | { |
||
213 | gd_setcolor(ind, r, g, b); |
||
214 | } |
||
215 | void grx_getpalette(BYTE start, BYTE num, BYTE *pal) |
||
216 | { |
||
217 | gd_getpalette(start, num, pal); |
||
218 | } |
||
219 | void grx_setpalette(BYTE start, BYTE num, BYTE *pal) |
||
220 | { |
||
221 | gd_setpalette(start, num, pal); |
||
222 | } |
||
223 | |||
224 | |||
225 | int grx_open(WORD x, WORD y, BYTE depth) |
||
226 | { |
||
227 | int mode; |
||
228 | |||
229 | mode = grx_getmode(x, y, depth); |
||
230 | |||
231 | if (grx_setmode(mode) < 0) { |
||
232 | return -1; |
||
233 | } |
||
234 | |||
235 | return 1; |
||
236 | } |
||
237 | |||
238 | void grx_clear(DWORD color) |
||
239 | { |
||
51 | pj | 240 | grx_vga_modeinfo m; |
2 | pj | 241 | |
242 | gd_getmodeinfo(&m); |
||
243 | grx_box(0, 0, m.width, m.height, color); |
||
244 | } |