Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5305 | codemaster | 1 | ; $$$$$$$$$$$$$$$$$$$ ABAKIS $$$$$$$$$$$$$$$$$$$$$ |
2 | ; *************** STAR^2 SOFTWARE **************** |
||
3 | ; ?????????????????? DRAW.INC ???????????????????? |
||
4 | |||
5 | ; fast portable graphics |
||
6 | |||
7 | include 'color.inc' |
||
8 | include 'box.inc' |
||
9 | |||
10 | ;;;;;;;;;;;;;;;;;;;;; SCREEN ;;;;;;;;;;;;;;;;;;;;; |
||
11 | |||
12 | align |
||
13 | |||
14 | vga equ (gs:r0) |
||
15 | |||
16 | ; void vga.p |
||
17 | |||
18 | integer \ |
||
19 | screen.w, screen.h, screen.n,\ |
||
20 | screen.size, screen.pitch,\ |
||
21 | screen.bpp, screen.pw |
||
22 | |||
23 | void palette.p |
||
24 | |||
25 | function set.screen, w, h, bpp |
||
26 | alias n=r0, pw=r1 |
||
27 | . screen.w=w, screen.h=h ; size |
||
28 | . n=w, n*h, screen.n=n ; # pixels |
||
29 | . n=bpp, n>>>3, pw=n ; pixel width |
||
30 | . screen.pw=pw, n*pw ; size |
||
31 | . screen.size=n ; in bytes |
||
32 | . n=w, n*4 ; width |
||
33 | . screen.pitch=n ; in bytes |
||
34 | . screen.bpp=bpp ; bits per pixel |
||
35 | endf |
||
36 | |||
37 | ; calculate x/y offset: (y*screen.w+x)*4 |
||
38 | |||
39 | macro xy x, y { |
||
40 | . r0=y, r0*1024, r0+x, r0*4 |
||
41 | . r1=WINDOW.Y, r1*4096, r0+r1 |
||
42 | . r1=WINDOW.X, r1*4, r0+r1 |
||
43 | } |
||
44 | |||
45 | ; erase screen with color |
||
46 | |||
47 | function clear.screen, c |
||
48 | callf draw.box, 0, 0, WINDOW.W-1, WINDOW.H-1, c |
||
49 | endf |
||
50 | |||
51 | ; draw straight line: loop n, *p++=c |
||
52 | |||
53 | function draw.line.h, x, y, w, c |
||
54 | xy x, y |
||
55 | . r1=c |
||
56 | loop w, (u32) *vga=r1, r0+4, endl |
||
57 | endf |
||
58 | |||
59 | ; draw vertical line |
||
60 | |||
61 | function draw.line.v, x, y, n, c |
||
62 | locals swb |
||
63 | alias p=r0, z=r1, h=r2 |
||
64 | xy x, y |
||
65 | . z=c, swb=4096 |
||
66 | loop n, (u32) *vga=z, p+swb, endl |
||
67 | endf 1 |
||
68 | |||
69 | ; draw solid rectangle |
||
70 | |||
71 | function draw.box, x, y, w, h, c |
||
72 | try visible x, y, w, h |
||
73 | loop h |
||
74 | draw.line.h x, y, w, c |
||
75 | . y++ |
||
76 | endl |
||
77 | endf |
||
78 | |||
79 | ; draw rectangle outline |
||
80 | |||
81 | function draw.outline, x, y, w, h, c |
||
82 | try visible x, y, w, h |
||
83 | draw.line.h x, y, w, c |
||
84 | . r0=y, r0+h, r0-- |
||
85 | draw.line.h x, r0, w, c |
||
86 | . r0=y, r0++, r1=h, r1-2 |
||
87 | draw.line.v x, r0, r1, c |
||
88 | . r0=x, r0+w, r0-- |
||
89 | . r1=y, r1++, r2=h, r2-2 |
||
90 | draw.line.v r0, r1, r2, c |
||
91 | endf |
||
92 | |||
93 | macro draw.box.s b, c |
||
94 | { draw.box b#.x, b#.y, b#.w, b#.h, c } |
||
95 | macro draw.box.o b, c |
||
96 | { draw.outline b#.x, b#.y, b#.w, b#.h, c } |
||
97 | |||
98 | macro draw.box a, b, c, d, e { |
||
99 | IF ~e eq |
||
100 | draw.box a, b, c, d, e |
||
101 | ELSE IF ~d eq |
||
102 | 'Unsupported' |
||
103 | ELSE IF ~c eq |
||
104 | draw.box.s a, b |
||
105 | draw.box.o a, c |
||
106 | ELSE IF ~b eq |
||
107 | draw.box.s a, b |
||
108 | END IF |
||
109 | } |
||
110 | |||
111 | ; draw scanline: multi-color line, |
||
112 | ; array of pixels: |
||
113 | |||
114 | ; loop w, *p++=*s++, endl |
||
115 | |||
116 | function draw.scanline, s, x, y, w |
||
117 | alias p=r0, q=r1, c=r2 |
||
118 | xy x, y |
||
119 | . q=s |
||
120 | loop w, (u32) c=*q, (u32) *vga=c |
||
121 | . p+4, q+4 |
||
122 | endl |
||
123 | endf |
||
124 | |||
125 | ; draw transparent scanline with color |
||
126 | ; "key" to exclude |
||
127 | |||
128 | function draw.scanline.t, s, x, y, w, k |
||
129 | alias p=r0, q=r1, c=r2 |
||
130 | xy x, y |
||
131 | . q=s |
||
132 | loop w, (u32) c=*q |
||
133 | if c<>k, (u32) *vga=c, end |
||
134 | . p+4, q+4 |
||
135 | endl |
||
136 | endf |
||
137 | |||
138 | ; draw scanline with inverted x |
||
139 | |||
140 | function draw.scanline.ix, pixels, x, y, w |
||
141 | alias p=r0, s=r1, c=r2 |
||
142 | . r0=x, r0+w |
||
143 | xy r0, y |
||
144 | . p-4, s=pixels |
||
145 | loop w, (u32) c=*s++, (u32) *vga=c, p-4, endl |
||
146 | endf 1 |
||
147 | |||
148 | ; draw variant scanline. pixels are |
||
149 | ; grayscale, alpha intensity of co=color. |
||
150 | ; for brushes and special effects |
||
151 | |||
152 | function draw.scanline.v, pixels, x, y, w, co |
||
153 | locals a |
||
154 | alias p=r0, s=r1, c=r2, c2=r3 |
||
155 | xy x, y |
||
156 | . s=pixels |
||
157 | loop w, (u32) c=*s++ |
||
158 | . a=c, a&0FFh |
||
159 | if a=0, go .next, end |
||
160 | if a=0FFh, c=co, go .draw, end |
||
161 | . (u32) c2=*p |
||
162 | push p s |
||
163 | get c=mix co, c2, a |
||
164 | pop s p |
||
165 | .draw: . (u32) *vga=c |
||
166 | .next: . p+4 |
||
167 | endl |
||
168 | endf 1 |
||
169 | |||
170 | ; draw transparent scanline with key and |
||
171 | ; alpha (0-255) applied to entire line |
||
172 | |||
173 | function draw.scanline.a, s, x, y, w, k, a |
||
174 | alias p=r0, q=r1, c=r2, c2=r3 |
||
175 | xy x, y |
||
176 | . q=s |
||
177 | loop w, (u32) c=*q |
||
178 | if c<>k, (u32) c2=*vga |
||
179 | push p q |
||
180 | get c=mix c, c2, a |
||
181 | pop q p |
||
182 | end, (u32) *vga=c |
||
183 | .next: |
||
184 | . p+4, q+4 |
||
185 | endl |
||
186 | endf |
||
187 | |||
188 | ; draw bitmap; 2D array of pixels |
||
189 | |||
190 | function draw.bitmap, p, x, y, w, h |
||
191 | locals i |
||
192 | try visible x, y, w, h |
||
193 | . i=y |
||
194 | loop h, i++ |
||
195 | draw.scanline p, x, i, w |
||
196 | . r0=w, r0*4, p+r0 |
||
197 | endl |
||
198 | endf |
||
199 | |||
200 | ; draw transparent bitmap with color |
||
201 | ; "key" by upper left pixel (X0,Y0) |
||
202 | |||
203 | function draw.bitmap.t, p, x, y, w, h |
||
204 | locals i, k |
||
205 | try visible x, y, w, h |
||
206 | . r0=p, (u32) r0=*r0, k=r0 |
||
207 | . i=y |
||
208 | loop h, i++ |
||
209 | draw.scanline.t p, x, i, w, k |
||
210 | . r0=w, r0*4, p+r0 |
||
211 | endl |
||
212 | endf |
||
213 | |||
214 | ; draw transparent bitmap with key and |
||
215 | ; alpha (0-255) applied to entire image |
||
216 | |||
217 | function draw.bitmap.a, p, x, y, w, h, a |
||
218 | locals i, k |
||
219 | try visible x, y, w, h |
||
220 | . i=y, r0=p, (u32) r0=*r0, k=r0 |
||
221 | loop h, i++ |
||
222 | draw.scanline.a p, x, i, w, k, a |
||
223 | . r0=w, r0*4, p+r0 |
||
224 | endl |
||
225 | endf |
||
226 | |||
227 | ; draw bitmap with inverted x |
||
228 | |||
229 | function draw.bitmap.ix, pixels, x, y, w, h |
||
230 | locals p |
||
231 | try visible x, y, w, h |
||
232 | . p=pixels |
||
233 | loop h |
||
234 | draw.scanline.ix p, x, y, w |
||
235 | . r0=w, r0*4, p+r0, y++ |
||
236 | endl |
||
237 | endf 1 |
||
238 | |||
239 | ; draw bitmap with inverted y |
||
240 | |||
241 | function draw.bitmap.iy, pixels, x, y, w, h |
||
242 | locals p |
||
243 | try visible x, y, w, h |
||
244 | . r0=h, r0--, y+r0, p=pixels |
||
245 | loop h |
||
246 | draw.scanline p, x, y, w |
||
247 | . r0=w, r0*4, p+r0, y-- |
||
248 | endl |
||
249 | endf 1 |
||
250 | |||
251 | ; draw bitmap with both inverted |
||
252 | |||
253 | function draw.bitmap.ixy, pixels, x, y, w, h |
||
254 | locals p, n |
||
255 | try visible x, y, w, h |
||
256 | . p=pixels |
||
257 | loop h |
||
258 | draw.scanline.ix p, x, y, w |
||
259 | . r0=w, r0*4, p+r0, y-- |
||
260 | endl |
||
261 | endf 1 |
||
262 | |||
263 | ; draw variant bitmap |
||
264 | |||
265 | function draw.bitmap.v, pixels, x, y, w, h, c |
||
266 | locals i, p |
||
267 | try visible x, y, w, h |
||
268 | . i=y, r0=pixels, p=r0 |
||
269 | loop h |
||
270 | draw.scanline.v p, x, i, w, c |
||
271 | . r0=w, r0*4, p+r0, i++ |
||
272 | endl |
||
273 | endf 1 |
||
274 | |||
275 | ;;;;;;;;;;;;;;;;; PALETTE PIXELS ;;;;;;;;;;;;;;;;; |
||
276 | |||
277 | ; 8BPP versions with pa/lette. no clipping |
||
278 | |||
279 | function draw.scanline.8, pixels, x, y, w |
||
280 | alias p=r0, s=r1, c=r2, q=r3 |
||
281 | xy x, y |
||
282 | . s=pixels |
||
283 | loop w, q=*s++, q*4, q+palette.p |
||
284 | . (u32) c=*q, (u32) *vga=c, r0+4 |
||
285 | endl |
||
286 | endf 1 |
||
287 | |||
288 | function draw.bitmap.8, pixels, x, y, w, h |
||
289 | locals i, p |
||
290 | try visible x, y, w, h |
||
291 | . i=y, p=pixels |
||
292 | loop h |
||
293 | draw.scanline.8 p, x, i, w |
||
294 | . i++, r0=w, p+r0 |
||
295 | endl |
||
296 | endf 1 |
||
297 | |||
298 | ;;;;;;;;;;;;;;;;;;;;; SPECIAL ;;;;;;;;;;;;;;;;;;;; |
||
299 | |||
300 | ; special variant 8BPP with alpha bias for |
||
301 | ; fonts and sketching effects (example: |
||
302 | ; chalkboard) |
||
303 | |||
304 | A.LIGHTEST=128 |
||
305 | A.LIGHTER=96 |
||
306 | A.LIGHT=64 |
||
307 | A.DARK=-32 |
||
308 | A.DARKER=-64 |
||
309 | A.DARKEST=-96 |
||
310 | |||
311 | align |
||
312 | integer alpha.bias=0 ; A.DARKEST |
||
313 | |||
314 | function draw.scanline.v.8, pixels, x, y, w, co |
||
315 | locals a |
||
316 | alias p=r0, s=r1, c=r2, c2=r3, q=r3 |
||
317 | xy x, y |
||
318 | . s=pixels |
||
319 | loop w, q=*s++, q*4, q+palette.p |
||
320 | . (u32) c=*q, a=c, a&0FFh |
||
321 | if a=0, go .next, end |
||
322 | . (u32) c2=*vga |
||
323 | push p s |
||
324 | . r0=a |
||
325 | if alpha.bias, r0+alpha.bias |
||
326 | if r0<0, r0=0 |
||
327 | else.if r0>255, r0=255, end |
||
328 | end |
||
329 | get c=mix co, c2, r0 |
||
330 | pop s p |
||
331 | .draw: . (u32) *vga=c |
||
332 | .next: . p+4 |
||
333 | endl |
||
334 | endf 1 |
||
335 | |||
336 | function draw.bitmap.v.8, pixels, x, y, w, h, c |
||
337 | locals i, p |
||
338 | try visible x, y, w, h |
||
339 | . i=y, p=pixels |
||
340 | loop h |
||
341 | draw.scanline.v.8 p, x, i, w, c |
||
342 | . i++, r0=w, p+r0 |
||
343 | endl |
||
344 | endf 10,>>> |