Go to most recent revision | Details | 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 | |||
8 | unsigned char * flbaddr; |
||
9 | unsigned int bpr; |
||
10 | unsigned int height, width; |
||
11 | |||
12 | static void circlepixels(WORD x, WORD y, WORD sx, WORD sy, DWORD c) |
||
13 | { |
||
14 | grx_plot(sx + x, sy + y, c); |
||
15 | grx_plot(sx - x, sy + y, c); |
||
16 | grx_plot(sx + x, sy - y, c); |
||
17 | grx_plot(sx - x, sy - y, c); |
||
18 | grx_plot(sx + y, sy + x, c); |
||
19 | grx_plot(sx - y, sy + x, c); |
||
20 | grx_plot(sx + y, sy - x, c); |
||
21 | grx_plot(sx - y, sy - x, c); |
||
22 | } |
||
23 | |||
24 | void grx_circle(WORD sx, WORD sy, WORD r, DWORD c) |
||
25 | { |
||
26 | int x, y, d; |
||
27 | |||
28 | if (r < 1) { |
||
29 | grx_plot(sx, sy, c); |
||
30 | return; |
||
31 | } |
||
32 | x = 0; |
||
33 | y = r; |
||
34 | d = 1 - r; |
||
35 | circlepixels(x, y, sx, sy, c); |
||
36 | while (x < y) { |
||
37 | if (d < 0) |
||
38 | d += x * 2 + 3; |
||
39 | else { |
||
40 | d += x * 2 - y * 2 + 5; |
||
41 | y--; |
||
42 | } |
||
43 | x++; |
||
44 | circlepixels(x, y, sx, sy, c); |
||
45 | } |
||
46 | } |
||
47 | |||
48 | /* grx_disc by Massy */ |
||
49 | |||
50 | static __inline__ void discpixels(WORD x, WORD y, WORD sx, WORD sy, DWORD c) |
||
51 | { |
||
52 | grx_line(sx + x, sy + y, sx + x, sy - y, c); |
||
53 | grx_line(sx - x, sy + y, sx - x, sy - y, c); |
||
54 | grx_line(sx + y, sy + x, sx + y, sy - x , c); |
||
55 | grx_line(sx - y, sy + x, sx - y, sy - x , c); |
||
56 | } |
||
57 | |||
58 | void grx_disc(WORD sx, WORD sy, WORD r, DWORD c) |
||
59 | { |
||
60 | int x, y, d; |
||
61 | |||
62 | if (r < 1) { |
||
63 | grx_plot(sx, sy, c); |
||
64 | return; |
||
65 | } |
||
66 | x = 0; |
||
67 | y = r; |
||
68 | d = 1 - r; |
||
69 | discpixels(x, y, sx, sy, c); |
||
70 | while (x < y) { |
||
71 | if (d < 0) |
||
72 | d += x * 2 + 3; |
||
73 | else { |
||
74 | d += x * 2 - y * 2 + 5; |
||
75 | y--; |
||
76 | } |
||
77 | x++; |
||
78 | discpixels(x, y, sx, sy, c); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | int grx_setbuffer(unsigned char *vbuf, unsigned int w, unsigned int h) |
||
83 | { |
||
84 | |||
85 | flbaddr = vbuf; |
||
86 | width = w; |
||
87 | height = h; |
||
88 | bpr = 4 * w; |
||
89 | |||
90 | return 1; |
||
91 | |||
92 | } |
||
93 | |||
94 | void grx_clear(DWORD color) |
||
95 | { |
||
96 | |||
97 | grx_box(0, 0, width, height, color); |
||
98 | |||
99 | } |
||
100 | |||
101 | void grx_putimage(WORD x1, WORD y1, WORD x2, WORD y2, BYTE *buf) |
||
102 | { |
||
103 | |||
104 | } |
||
105 | |||
106 | void grx_box(WORD x1, WORD y1, WORD x2, WORD y2, DWORD color) |
||
107 | { |
||
108 | unsigned char * addr; |
||
109 | WORD dx, y; |
||
110 | |||
111 | addr = flbaddr + (x1 << 2) + bpr * y1; |
||
112 | dx = (x2 - x1 + 1); |
||
113 | |||
114 | for (y = y1; y <= y2; y++) { |
||
115 | memset((unsigned long int *)(addr),(DWORD)(color),dx); |
||
116 | addr += bpr; |
||
117 | } |
||
118 | } |
||
119 | |||
120 | void grx_rect(WORD x1, WORD y1, WORD x2, WORD y2, DWORD color) |
||
121 | { |
||
122 | unsigned char * addr; |
||
123 | WORD dx, y; |
||
124 | |||
125 | addr = flbaddr + (x1 << 2) + bpr * y1; |
||
126 | dx = (x2 - x1); |
||
127 | |||
128 | memset((unsigned long int *)(addr),(DWORD)color,dx+2); |
||
129 | addr += bpr; |
||
130 | |||
131 | for (y = y1 + 1; y <= y2 - 1; y++) { |
||
132 | *(unsigned long int *)addr = (DWORD)color; |
||
133 | *(unsigned long int *)(addr + (dx<<2)) = (DWORD)color; |
||
134 | addr += bpr; |
||
135 | } |
||
136 | memset((unsigned long int *)(addr),(DWORD)(color),dx+2); |
||
137 | |||
138 | } |
||
139 | |||
140 | void grx_text(char *text, WORD x, WORD y, DWORD fg, DWORD bg) |
||
141 | { |
||
142 | unsigned char * fp, * addr; |
||
143 | int r, c, bits; |
||
144 | |||
145 | addr = flbaddr; |
||
146 | while (*text) { |
||
147 | fp = (unsigned char *)(fontaddr + (8 * *(BYTE *)text)); |
||
148 | for (r=0; r<8; r++) { |
||
149 | bits = *(unsigned char *)(fp++); |
||
150 | for (c=0; c<8; c++) |
||
151 | if (bits & (0x80>>c)) |
||
152 | *(unsigned long int *)(addr + (y + r) * bpr + ((x + c) << 2)) = (DWORD)fg; |
||
153 | else |
||
154 | *(unsigned long int *)(addr + (y + r) * bpr + ((x + c) << 2)) = (DWORD)bg; |
||
155 | } |
||
156 | text++; |
||
157 | x += 8; |
||
158 | } |
||
159 | } |
||
160 | |||
161 | void grx_line(WORD x1, WORD y1, WORD x2, WORD y2, DWORD color) |
||
162 | { |
||
163 | register int t, distance; |
||
164 | unsigned char * addr; |
||
165 | int xerr=0, yerr=0, deltax, deltay; |
||
166 | int incx, incy; |
||
167 | |||
168 | addr = flbaddr;; |
||
169 | deltax = x2 - x1; /* compute both distances */ |
||
170 | deltay = y2 - y1; |
||
171 | |||
172 | if (deltax > 0) /* compute increments */ |
||
173 | incx = 1; |
||
174 | else if (deltax == 0) |
||
175 | incx = 0; |
||
176 | else |
||
177 | incx = -1; |
||
178 | |||
179 | if (deltay > 0) |
||
180 | incy = 1; |
||
181 | else if (deltay == 0) |
||
182 | incy = 0; |
||
183 | else |
||
184 | incy = -1; |
||
185 | |||
186 | deltax = abs(deltax); /* determine greater distance */ |
||
187 | deltay = abs(deltay); |
||
188 | if (deltax > deltay) |
||
189 | distance = deltax; |
||
190 | else |
||
191 | distance = deltay; |
||
192 | |||
193 | for (t=0; t<=distance+1; t++) { /* draw the line */ |
||
194 | *(unsigned long int *)(addr + y1 * bpr + (x1 << 2)) = (DWORD)color; |
||
195 | xerr += deltax; |
||
196 | yerr += deltay; |
||
197 | if (xerr > distance) { |
||
198 | xerr -= distance; |
||
199 | x1 += incx; |
||
200 | } |
||
201 | if (yerr > distance) { |
||
202 | yerr -= distance; |
||
203 | y1 += incy; |
||
204 | } |
||
205 | } |
||
206 | } |
||
207 | |||
208 | void grx_plot(WORD x, WORD y, DWORD color) |
||
209 | { |
||
210 | *(unsigned long int *)(flbaddr + y * bpr + (x << 2)) = (DWORD)color; |
||
211 | } |
||
212 | |||
213 | DWORD grx_getpixel(WORD x, WORD y) |
||
214 | { |
||
215 | DWORD rv; |
||
216 | |||
217 | (DWORD)rv = *(unsigned long int *)(flbaddr + y * bpr + (x << 2)); |
||
218 | return rv; |
||
219 | } |
||
220 |