Rev 54 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
54 | pj | 1 | #include "glib.h" |
2 | #include <stdlib.h> |
||
3 | |||
4 | #include "../vga.h" |
||
5 | |||
6 | #define fontaddr 0xffa6eL /* indirizzo set caratteri */ |
||
7 | |||
74 | giacomo | 8 | BYTE * flbaddr; |
9 | WORD bpr; |
||
10 | WORD height, width; |
||
54 | pj | 11 | |
74 | giacomo | 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 | |||
54 | pj | 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 | |||
74 | giacomo | 100 | int grx_setbuffer(BYTE *vbuf, WORD w, WORD h) |
54 | pj | 101 | { |
102 | |||
74 | giacomo | 103 | //This functions are designed to work only whit 16 bpp |
104 | |||
54 | pj | 105 | flbaddr = vbuf; |
106 | width = w; |
||
107 | height = h; |
||
74 | giacomo | 108 | bpr = 2 * w; |
54 | pj | 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 | { |
||
74 | giacomo | 128 | BYTE * addr; |
129 | int dx, y; |
||
54 | pj | 130 | |
74 | giacomo | 131 | addr = flbaddr + (x1 << 1) + bpr * y1; |
132 | dx = (x2 - x1 + 1) << 1; |
||
54 | pj | 133 | |
134 | for (y = y1; y <= y2; y++) { |
||
74 | giacomo | 135 | memsetw(addr,color,(dx>>1)); |
54 | pj | 136 | addr += bpr; |
137 | } |
||
138 | } |
||
139 | |||
140 | void grx_rect(WORD x1, WORD y1, WORD x2, WORD y2, DWORD color) |
||
141 | { |
||
74 | giacomo | 142 | BYTE * addr; |
143 | int dx, y; |
||
54 | pj | 144 | |
74 | giacomo | 145 | addr = flbaddr + (x1 << 1) + bpr * y1; |
146 | dx = (x2 - x1) << 1; |
||
54 | pj | 147 | |
74 | giacomo | 148 | memsetw(addr,color,(dx>>1)+1); |
54 | pj | 149 | addr += bpr; |
150 | |||
151 | for (y = y1 + 1; y <= y2 - 1; y++) { |
||
74 | giacomo | 152 | *(WORD *)(addr) = (WORD)(color); |
153 | *(WORD *)(addr + dx) = (WORD)(color); |
||
54 | pj | 154 | addr += bpr; |
155 | } |
||
74 | giacomo | 156 | memsetw(addr,color,(dx>>1)+1); |
54 | pj | 157 | |
158 | } |
||
159 | |||
160 | void grx_text(char *text, WORD x, WORD y, DWORD fg, DWORD bg) |
||
161 | { |
||
74 | giacomo | 162 | BYTE * fp; |
163 | BYTE * addr; |
||
54 | pj | 164 | int r, c, bits; |
165 | |||
166 | addr = flbaddr; |
||
167 | while (*text) { |
||
74 | giacomo | 168 | fp = (BYTE *)(fontaddr + (8 * *(BYTE *)text)); |
54 | pj | 169 | for (r=0; r<8; r++) { |
74 | giacomo | 170 | bits = *(BYTE *)(fp++); |
54 | pj | 171 | for (c=0; c<8; c++) |
172 | if (bits & (0x80>>c)) |
||
74 | giacomo | 173 | *(WORD *)(addr + (y + r) * bpr + ((x + c) << 1)) = (WORD)(fg); |
54 | pj | 174 | else |
74 | giacomo | 175 | *(WORD *)(addr + (y + r) * bpr + ((x + c) << 1)) = (WORD)(bg); |
54 | pj | 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; |
||
74 | giacomo | 185 | BYTE * addr; |
54 | pj | 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 */ |
||
74 | giacomo | 215 | *(WORD *)(addr + y1 * bpr + (x1 << 1)) = (WORD)color; |
54 | pj | 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 | { |
||
74 | giacomo | 231 | *(WORD *)(flbaddr + y * bpr + (x << 1)) = (WORD)color; |
54 | pj | 232 | } |
233 | |||
234 | DWORD grx_getpixel(WORD x, WORD y) |
||
235 | { |
||
236 | DWORD rv; |
||
237 | |||
74 | giacomo | 238 | (DWORD)rv = *(WORD *)(flbaddr + y * bpr + (x << 1)); |
54 | pj | 239 | return rv; |
240 | } |
||
241 |