Rev 5309 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5305 | codemaster | 1 | ; $$$$$$$$$$$$$$$$$$$ ABAKIS $$$$$$$$$$$$$$$$$$$$$ |
2 | ; *************** STAR^2 SOFTWARE **************** |
||
3 | ; ;;;;;;;;;;;;;;;;;;; IMAGE ;;;;;;;;;;;;;;;;;;;;;; |
||
4 | |||
5 | ; image class/object/structure |
||
6 | |||
7 | macro IMAGE a { |
||
8 | a: |
||
9 | void a#.p |
||
10 | integer a#.x, a#.y, a#.w, a#.h |
||
11 | integer a#.bpp=32, a#.key, a#.alpha |
||
12 | } |
||
13 | |||
14 | virtual at 0 |
||
15 | ?image.p dd 0 |
||
16 | ?image.x dd 0 |
||
17 | ?image.y dd 0 |
||
18 | ?image.w dd 0 |
||
19 | ?image.h dd 0 |
||
20 | ?image.bpp dd 32 |
||
21 | ?image.key dd 0 |
||
22 | ?image.alpha dd 0 |
||
23 | END virtual |
||
24 | |||
25 | ?image.box fix ?image.x |
||
26 | |||
27 | ; create image file/s with header: |
||
28 | ; 8 bytes: |
||
29 | |||
30 | ; byte s='I' ; signature |
||
31 | ; byte v=0 ; version: AABBCC.VV |
||
32 | ; int16 w, h ; size: w:h |
||
33 | ; byte bpp ; bpp: 32/24/16/15/8 |
||
34 | ; byte n ; # colors or 0=256+ |
||
35 | |||
36 | ; byte pixels[w*h*(bpp/8)] ; or *2 if 15 |
||
37 | |||
38 | macro IMAGE [p] { |
||
39 | forward |
||
40 | local w, h |
||
41 | w=0 |
||
42 | h=0 |
||
43 | define ?s 0 |
||
44 | match a==b, p \{ |
||
45 | \local ..q |
||
46 | ..q: inject.image b, 32 |
||
47 | load w word from ..q+2 |
||
48 | load h word from ..q+4 |
||
49 | a: |
||
50 | void a\#.p=..q+8 |
||
51 | integer a\#.x, a\#.y, a\#.w=w, a\#.h=h |
||
52 | integer a\#.bpp, a\#.key, a\#.alpha |
||
53 | define ?s 1 |
||
54 | \} |
||
55 | IF ?s eq 0 |
||
56 | IMAGE p |
||
57 | END IF |
||
58 | } |
||
59 | |||
60 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
61 | |||
62 | ; load 24PP .BMP, store as .IMAGE 15/16/24/32. |
||
63 | ; for OSs, ROMs. warning: causes slow compile |
||
64 | ; with 1+ MB worth of images. to compile fast |
||
65 | ; without images, comment "; IMAGE name='abc'" |
||
66 | |||
67 | macro inject.image name, bpp { |
||
68 | local i, p, a, r, g, b,\ |
||
69 | x, y, w, h, wb |
||
70 | virtual at 0 |
||
5311 | yogev_ezra | 71 | p:: file CD#'media/'#name#'.bmp' |
5305 | codemaster | 72 | END virtual |
73 | IF ~bpp in <15,16,24,32> |
||
74 | 'Invalid BPP' name |
||
75 | END IF |
||
76 | load a word from p:0 |
||
77 | IF a<>'BM' |
||
78 | 'Invalid signature' name |
||
79 | END IF |
||
80 | load a byte from p:1Ch |
||
81 | IF a<>24 |
||
82 | 'Must be 24BPP' name |
||
83 | END IF |
||
84 | load w dword from p:12h |
||
85 | load h dword from p:16h |
||
86 | db 'I', 0 |
||
87 | dw w, h |
||
88 | db bpp, 0 |
||
89 | a=((3-((w*3)+3)) and 3) |
||
90 | wb=(w*3)+a |
||
91 | y=h |
||
92 | WHILE y>0 |
||
93 | o=36h+((y-1)*wb) |
||
94 | x=0 |
||
95 | WHILE x |
||
96 | i=o+(x*3) |
||
97 | load b byte from p:i |
||
98 | load g byte from p:i+1 |
||
99 | load r byte from p:i+2 |
||
100 | IF bpp=32 |
||
101 | dd (r shl 16) or (g shl 8) or b |
||
102 | ELSE IF bpp=24 |
||
103 | db r, g, b ; or b, g, r |
||
104 | ELSE IF bpp=16 |
||
105 | r=((r and 11111b)/8) shl 11 |
||
106 | g=((g and 111111b)/4) shl 5 |
||
107 | b=((b and 11111b)/8) |
||
108 | dw r or g or b |
||
109 | ELSE IF bpp=15 |
||
110 | r=((r and 11111b)/8) shl 10 |
||
111 | g=((g and 11111b)/8) shl 5 |
||
112 | b=((b and 11111b)/8) |
||
113 | dw r or g or b |
||
114 | END IF |
||
115 | x=x+1 |
||
116 | END WHILE |
||
117 | y=y-1 |
||
118 | END WHILE |
||
119 | } |
||
120 | |||
121 | ; insert 8BPP .BMP as .IMAGE with palette. |
||
122 | ; note: must use special .8 drawing |
||
123 | |||
124 | macro inject.image.8 name { |
||
125 | local i, p, a, c,\ |
||
126 | x, y, w, h, wb |
||
127 | virtual at 0 |
||
5311 | yogev_ezra | 128 | p:: file CD#'media/'#name#'.bmp' |
5305 | codemaster | 129 | END virtual |
130 | load a word from p:0 |
||
131 | IF a<>'BM' |
||
132 | 'Invalid signature' name |
||
133 | END IF |
||
134 | load a byte from p:1Ch |
||
135 | IF a<>8 |
||
136 | 'Must be 8BPP' name |
||
137 | END IF |
||
138 | load w dword from p:12h |
||
139 | load h dword from p:16h |
||
140 | db 'I', 0 |
||
141 | dw w, h |
||
142 | db 8, 0 |
||
143 | i=0 |
||
144 | WHILE i<256 |
||
145 | o=36h+(i*4) |
||
146 | load b byte from p:o |
||
147 | load g byte from p:o+1 |
||
148 | load r byte from p:o+2 |
||
149 | db b, g, r, 0 |
||
150 | i=i+1 |
||
151 | END WHILE |
||
152 | a=((3-(w+3)) and 3) |
||
153 | wb=w+a |
||
154 | y=h |
||
155 | WHILE y>0 |
||
156 | o=436h+((y-1)*wb) |
||
157 | x=0 |
||
158 | WHILE x |
||
159 | load c byte from p:o+x |
||
160 | db c |
||
161 | x=x+1 |
||
162 | END WHILE |
||
163 | y=y-1 |
||
164 | END WHILE |
||
165 | } |
||
166 | |||
167 | macro IMAGE8 [p] { |
||
168 | forward |
||
169 | local w, h |
||
170 | w=0 |
||
171 | h=0 |
||
172 | define ?s 0 |
||
173 | match a==b, p \{ |
||
174 | \local ..q |
||
175 | ..q: inject.image.8 b |
||
176 | load w word from ..q+2 |
||
177 | load h word from ..q+4 |
||
178 | a: |
||
179 | void a\#.p=..q+408h |
||
180 | integer a\#.x, a\#.y, a\#.w=w, a\#.h=h |
||
181 | integer a\#.bpp, a\#.key, a\#.alpha |
||
182 | ; ... |
||
183 | void a\#.palette=..q+8 |
||
184 | define ?s 1 |
||
185 | \} |
||
186 | IF ?s eq 0 |
||
187 | 'Error: 8BPP must specify file' |
||
188 | END IF |
||
189 | } |
||
190 | |||
191 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
192 | |||
193 | ; unfinished, unorganized... |
||
194 | |||
195 | ; 2-DO: convert to functions. create one |
||
196 | ; good draw.scanline.x with bpp and type |
||
197 | ; BIT flags: |
||
198 | |||
199 | ; draw.scanline.x p, x, y, w, 32,\ |
||
200 | ; G.KEY or G.ALPHA or G.GRAY or G.INVERT.X |
||
201 | |||
202 | macro move.image i, x, y { |
||
203 | IF ~x eq |
||
204 | . i#.x=x, i#.y=y |
||
205 | END IF |
||
206 | } |
||
207 | |||
208 | macro draw.image i, x, y { |
||
209 | move.image i, x, y |
||
210 | draw.bitmap i#.p, i#.x, i#.y, i#.w, i#.h |
||
211 | } |
||
212 | |||
213 | macro draw.image.t i, x, y { |
||
214 | IF ~x eq |
||
215 | move.image i, x, y |
||
216 | END IF |
||
217 | draw.bitmap.t i#.p, i#.x, i#.y, i#.w, i#.h |
||
218 | } |
||
219 | |||
220 | ; draw with inverted x/y |
||
221 | |||
222 | macro draw.image.ix i, x, y { |
||
223 | IF ~x eq |
||
224 | move.image i, x, y |
||
225 | END IF |
||
226 | draw.bitmap.ix i#.p,\ |
||
227 | i#.x, i#.y, i#.w, i#.h |
||
228 | } |
||
229 | |||
230 | macro draw.image.iy i, x, y { |
||
231 | IF ~x eq |
||
232 | move.image i, x, y |
||
233 | END IF |
||
234 | draw.bitmap.iy i#.p, i#.x, i#.y, i#.w, i#.h |
||
235 | } |
||
236 | |||
237 | macro draw.image.ixy i, x, y, ix, iy { |
||
238 | IF ~x eq |
||
239 | move.image i, x, y |
||
240 | END IF |
||
241 | draw.bitmap.ixy i#.p, i#.x, i#.y, i#.w, i#.h |
||
242 | } |
||
243 | |||
244 | macro draw.image.v i, x, y, c { |
||
245 | IF ~x eq |
||
246 | move.image i, x, y |
||
247 | END IF |
||
248 | draw.bitmap.v i#.p, i#.x, i#.y, i#.w, i#.h, c |
||
249 | } |
||
250 | |||
251 | ; draw rotated. warning: no clipping |
||
252 | |||
253 | function draw.scanline.rl, pixels, x, y, w |
||
254 | alias p=r0, s=r1, n=r2, c=r3 |
||
255 | xy x, y |
||
256 | . s=w, s--, s*4, s+pixels, n=4096 ; screen.pitch |
||
257 | loop w, (u32) c=*s--, (u32) *vga=c, p+n, endl |
||
258 | endf 1 |
||
259 | |||
260 | function draw.scanline.rr, pixels, x, y, w |
||
261 | alias p=r0, s=r1, n=r2, c=r3 |
||
262 | xy x, y |
||
263 | . s=pixels, n=4096 ; screen.pitch |
||
264 | loop w, (u32) c=*s++, (u32) *vga=c, p+n, endl |
||
265 | endf 1 |
||
266 | |||
267 | function draw.bitmap.rl, pixels, x, y, w, h |
||
268 | locals p |
||
269 | try visible x, y, w, h |
||
270 | . p=pixels |
||
271 | loop h |
||
272 | draw.scanline.rl p, x, y, w |
||
273 | . r0=w, r0*4, p+r0, x++ |
||
274 | endl |
||
275 | endf 1 |
||
276 | |||
277 | function draw.bitmap.rr, pixels, x, y, w, h |
||
278 | locals p |
||
279 | try visible x, y, w, h |
||
280 | . r0=w, r0--, x+r0, p=pixels |
||
281 | loop h |
||
282 | draw.scanline.rr p, x, y, w |
||
283 | . r0=w, r0*4, p+r0, x-- |
||
284 | endl |
||
285 | endf 1 |
||
286 | |||
287 | macro draw.image.rl i, x, y { |
||
288 | IF ~x eq |
||
289 | move.image i, x, y |
||
290 | END IF |
||
291 | draw.bitmap.rl i#.p, i#.x, i#.y, i#.w, i#.h |
||
292 | } |
||
293 | |||
294 | macro draw.image.rr i, x, y { |
||
295 | IF ~x eq |
||
296 | move.image i, x, y |
||
297 | END IF |
||
298 | draw.bitmap.rr i#.p, i#.x, i#.y, i#.w, i#.h |
||
299 | } |
||
300 | |||
301 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
302 | |||
303 | ; 8BPP with palette... |
||
304 | |||
305 | macro draw.image.8 i, x, y { |
||
306 | IF ~x eq |
||
307 | move.image i, x, y |
||
308 | END IF |
||
309 | . palette.p=i#.palette |
||
310 | draw.bitmap.8 i#.p, i#.x, i#.y, i#.w, i#.h |
||
311 | } |
||
312 | |||
313 | macro draw.image.v.8 i, x, y, c { |
||
314 | IF ~x eq |
||
315 | move.image i, x, y |
||
316 | END IF |
||
317 | . palette.p=i#.palette |
||
318 | draw.bitmap.v.8 i#.p, i#.x, i#.y, i#.w, i#.h, c |
||
319 | } |
||
320 | |||
321 | function draw.image.v8, im, x, y, co |
||
322 | locals p, w, h |
||
323 | . r0=im |
||
324 | . (u32) r1=*(r0+?image.p), p=r1 |
||
325 | . (u32) r1=*(r0+?image.w), w=r1 |
||
326 | . (u32) r1=*(r0+?image.h), h=r1 |
||
327 | draw.bitmap.v.8 p, x, y, w, h, co |
||
328 | endf |
||
329 | |||
330 | function draw.bitmap.viy.8, pixels,\ |
||
331 | x, y, w, h, c |
||
332 | locals i, p |
||
333 | try visible x, y, w, h |
||
334 | . r0=h, y+r0, p=pixels |
||
335 | loop h |
||
336 | draw.scanline.v.8 p, x, y, w, c |
||
337 | . r0=w, p+r0, y-- |
||
338 | endl |
||
339 | endf 1 |
||
340 | |||
341 | function draw.image.viy.8, im, x, y, co |
||
342 | locals p, w, h |
||
343 | . r0=im |
||
344 | . (u32) r1=*(r0+?image.p), p=r1 |
||
345 | . (u32) r1=*(r0+?image.w), w=r1 |
||
346 | . (u32) r1=*(r0+?image.h), h=r1 |
||
347 | draw.bitmap.viy.8 p, x, y, w, h, co |
||
348 | endf |