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