Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
110 | giacomo | 1 | #include "drivers/glib.h" |
2 | #include <stdlib.h> |
||
3 | |||
4 | #include "vga.h" |
||
5 | |||
6 | #define fontaddr 0xffa6eL /* indirizzo set caratteri */ |
||
7 | |||
8 | BYTE * flbaddr; |
||
9 | WORD bpr; |
||
10 | WORD height, width; |
||
11 | |||
12 | inline void memsetw(void *dst, unsigned int c, unsigned long int memdiv2) |
||
13 | { |
||
14 | __asm__ __volatile__("push %%edi |
||
15 | push %%eax |
||
16 | push %%ecx |
||
17 | movl %2, %%edi |
||
18 | cld |
||
19 | rep |
||
20 | stosw |
||
21 | pop %%ecx |
||
22 | pop %%eax |
||
23 | pop %%edi" |
||
24 | : |
||
25 | : "c" (memdiv2), "a" (c), "b" (dst)); |
||
26 | |||
27 | } |
||
28 | |||
29 | |||
30 | static void circlepixels(WORD x, WORD y, WORD sx, WORD sy, DWORD c) |
||
31 | { |
||
32 | grx_plot(sx + x, sy + y, c); |
||
33 | grx_plot(sx - x, sy + y, c); |
||
34 | grx_plot(sx + x, sy - y, c); |
||
35 | grx_plot(sx - x, sy - y, c); |
||
36 | grx_plot(sx + y, sy + x, c); |
||
37 | grx_plot(sx - y, sy + x, c); |
||
38 | grx_plot(sx + y, sy - x, c); |
||
39 | grx_plot(sx - y, sy - x, c); |
||
40 | } |
||
41 | |||
42 | void grx_circle(WORD sx, WORD sy, WORD r, DWORD c) |
||
43 | { |
||
44 | int x, y, d; |
||
45 | |||
46 | if (r < 1) { |
||
47 | grx_plot(sx, sy, c); |
||
48 | return; |
||
49 | } |
||
50 | x = 0; |
||
51 | y = r; |
||
52 | d = 1 - r; |
||
53 | circlepixels(x, y, sx, sy, c); |
||
54 | while (x < y) { |
||
55 | if (d < 0) |
||
56 | d += x * 2 + 3; |
||
57 | else { |
||
58 | d += x * 2 - y * 2 + 5; |
||
59 | y--; |
||
60 | } |
||
61 | x++; |
||
62 | circlepixels(x, y, sx, sy, c); |
||
63 | } |
||
64 | } |
||
65 | |||
66 | /* grx_disc by Massy */ |
||
67 | |||
68 | static __inline__ void discpixels(WORD x, WORD y, WORD sx, WORD sy, DWORD c) |
||
69 | { |
||
70 | grx_line(sx + x, sy + y, sx + x, sy - y, c); |
||
71 | grx_line(sx - x, sy + y, sx - x, sy - y, c); |
||
72 | grx_line(sx + y, sy + x, sx + y, sy - x , c); |
||
73 | grx_line(sx - y, sy + x, sx - y, sy - x , c); |
||
74 | } |
||
75 | |||
76 | void grx_disc(WORD sx, WORD sy, WORD r, DWORD c) |
||
77 | { |
||
78 | int x, y, d; |
||
79 | |||
80 | if (r < 1) { |
||
81 | grx_plot(sx, sy, c); |
||
82 | return; |
||
83 | } |
||
84 | x = 0; |
||
85 | y = r; |
||
86 | d = 1 - r; |
||
87 | discpixels(x, y, sx, sy, c); |
||
88 | while (x < y) { |
||
89 | if (d < 0) |
||
90 | d += x * 2 + 3; |
||
91 | else { |
||
92 | d += x * 2 - y * 2 + 5; |
||
93 | y--; |
||
94 | } |
||
95 | x++; |
||
96 | discpixels(x, y, sx, sy, c); |
||
97 | } |
||
98 | } |
||
99 | |||
100 | int grx_setbuffer(BYTE *vbuf, WORD w, WORD h) |
||
101 | { |
||
102 | |||
103 | //This functions are designed to work only whit 16 bpp |
||
104 | |||
105 | flbaddr = vbuf; |
||
106 | width = w; |
||
107 | height = h; |
||
108 | bpr = 2 * w; |
||
109 | |||
110 | return 1; |
||
111 | |||
112 | } |
||
113 | |||
114 | void grx_clear(DWORD color) |
||
115 | { |
||
116 | |||
117 | grx_box(0, 0, width, height, color); |
||
118 | |||
119 | } |
||
120 | |||
121 | void grx_putimage(WORD x1, WORD y1, WORD x2, WORD y2, BYTE *buf) |
||
122 | { |
||
123 | |||
124 | } |
||
125 | |||
126 | void grx_box(WORD x1, WORD y1, WORD x2, WORD y2, DWORD color) |
||
127 | { |
||
128 | BYTE * addr; |
||
129 | int dx, y; |
||
130 | |||
131 | addr = flbaddr + (x1 << 1) + bpr * y1; |
||
132 | dx = (x2 - x1 + 1) << 1; |
||
133 | |||
134 | for (y = y1; y <= y2; y++) { |
||
135 | memsetw(addr,color,(dx>>1)); |
||
136 | addr += bpr; |
||
137 | } |
||
138 | } |
||
139 | |||
140 | void grx_rect(WORD x1, WORD y1, WORD x2, WORD y2, DWORD color) |
||
141 | { |
||
142 | BYTE * addr; |
||
143 | int dx, y; |
||
144 | |||
145 | addr = flbaddr + (x1 << 1) + bpr * y1; |
||
146 | dx = (x2 - x1) << 1; |
||
147 | |||
148 | memsetw(addr,color,(dx>>1)+1); |
||
149 | addr += bpr; |
||
150 | |||
151 | for (y = y1 + 1; y <= y2 - 1; y++) { |
||
152 | *(WORD *)(addr) = (WORD)(color); |
||
153 | *(WORD *)(addr + dx) = (WORD)(color); |
||
154 | addr += bpr; |
||
155 | } |
||
156 | memsetw(addr,color,(dx>>1)+1); |
||
157 | |||
158 | } |
||
159 | |||
160 | void grx_text(char *text, WORD x, WORD y, DWORD fg, DWORD bg) |
||
161 | { |
||
162 | BYTE * fp; |
||
163 | BYTE * addr; |
||
164 | int r, c, bits; |
||
165 | |||
166 | addr = flbaddr; |
||
167 | while (*text) { |
||
168 | fp = (BYTE *)(fontaddr + (8 * *(BYTE *)text)); |
||
169 | for (r=0; r<8; r++) { |
||
170 | bits = *(BYTE *)(fp++); |
||
171 | for (c=0; c<8; c++) |
||
172 | if (bits & (0x80>>c)) |
||
173 | *(WORD *)(addr + (y + r) * bpr + ((x + c) << 1)) = (WORD)(fg); |
||
174 | else |
||
175 | *(WORD *)(addr + (y + r) * bpr + ((x + c) << 1)) = (WORD)(bg); |
||
176 | } |
||
177 | text++; |
||
178 | x += 8; |
||
179 | } |
||
180 | } |
||
181 | |||
182 | void grx_line(WORD x1, WORD y1, WORD x2, WORD y2, DWORD color) |
||
183 | { |
||
184 | register int t, distance; |
||
185 | BYTE * addr; |
||
186 | int xerr=0, yerr=0, deltax, deltay; |
||
187 | int incx, incy; |
||
188 | |||
189 | addr = flbaddr;; |
||
190 | deltax = x2 - x1; /* compute both distances */ |
||
191 | deltay = y2 - y1; |
||
192 | |||
193 | if (deltax > 0) /* compute increments */ |
||
194 | incx = 1; |
||
195 | else if (deltax == 0) |
||
196 | incx = 0; |
||
197 | else |
||
198 | incx = -1; |
||
199 | |||
200 | if (deltay > 0) |
||
201 | incy = 1; |
||
202 | else if (deltay == 0) |
||
203 | incy = 0; |
||
204 | else |
||
205 | incy = -1; |
||
206 | |||
207 | deltax = abs(deltax); /* determine greater distance */ |
||
208 | deltay = abs(deltay); |
||
209 | if (deltax > deltay) |
||
210 | distance = deltax; |
||
211 | else |
||
212 | distance = deltay; |
||
213 | |||
214 | for (t=0; t<=distance+1; t++) { /* draw the line */ |
||
215 | *(WORD *)(addr + y1 * bpr + (x1 << 1)) = (WORD)color; |
||
216 | xerr += deltax; |
||
217 | yerr += deltay; |
||
218 | if (xerr > distance) { |
||
219 | xerr -= distance; |
||
220 | x1 += incx; |
||
221 | } |
||
222 | if (yerr > distance) { |
||
223 | yerr -= distance; |
||
224 | y1 += incy; |
||
225 | } |
||
226 | } |
||
227 | } |
||
228 | |||
229 | void grx_plot(WORD x, WORD y, DWORD color) |
||
230 | { |
||
231 | *(WORD *)(flbaddr + y * bpr + (x << 1)) = (WORD)color; |
||
232 | } |
||
233 | |||
234 | DWORD grx_getpixel(WORD x, WORD y) |
||
235 | { |
||
236 | DWORD rv; |
||
237 | |||
238 | (DWORD)rv = *(WORD *)(flbaddr + y * bpr + (x << 1)); |
||
239 | return rv; |
||
240 | } |
||
241 |