Rev 1448 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1091 | pj | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Paolo Gai <pj@gandalf.sssup.it> |
||
10 | * Massimiliano Giorgi <massy@gandalf.sssup.it> |
||
11 | * Luca Abeni <luca@gandalf.sssup.it> |
||
12 | * (see the web pages for full authors list) |
||
13 | * |
||
14 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
15 | * |
||
16 | * http://www.sssup.it |
||
17 | * http://retis.sssup.it |
||
18 | * http://shark.sssup.it |
||
19 | */ |
||
20 | |||
1550 | pj | 21 | /* CVS : $Id: fab_lib.c,v 1.5 2005-01-08 14:34:28 pj Exp $ */ |
1091 | pj | 22 | |
23 | /* |
||
24 | * Copyright (C) 2000 Fabio Calabrese <fabiocalabrese77@yahoo.it> |
||
25 | * |
||
26 | * This program is free software; you can redistribute it and/or modify |
||
27 | * it under the terms of the GNU General Public License as published by |
||
28 | * the Free Software Foundation; either version 2 of the License, or |
||
29 | * (at your option) any later version. |
||
30 | * |
||
31 | * This program is distributed in the hope that it will be useful, |
||
32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
34 | * GNU General Public License for more details. |
||
35 | * |
||
36 | * You should have received a copy of the GNU General Public License |
||
37 | * along with this program; if not, write to the Free Software |
||
38 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
39 | * |
||
40 | */ |
||
41 | |||
42 | /**************************************************** |
||
43 | * * |
||
44 | * file: FAB_lib.c * |
||
45 | * libreria: FAB_LIB * |
||
46 | * version: 1.0 25/08/2002 * |
||
47 | * creato da: Fabio CALABRESE * |
||
48 | * * |
||
49 | ****************************************************/ |
||
50 | |||
51 | #ifndef __FAB_LIB_c__ |
||
52 | #define __FAB_LIB_c__ |
||
53 | //-------------------BEGIN--------------------------- |
||
54 | |||
55 | // *** Librerie di S.Ha.R.K. *** |
||
56 | #include<kernel/kern.h> |
||
57 | #include<kernel/mem.h> |
||
1448 | giacomo | 58 | |
59 | #include<drivers/shark_fb26.h> |
||
60 | |||
1091 | pj | 61 | #include<ll/sys/types.h> |
62 | #include<ll/i386/x-dos.h> |
||
63 | // *** Librerie Standard C *** |
||
64 | // *** Librerie FAB *** |
||
65 | #include"fab_lib/fab_msg.h" |
||
66 | #include"fab_lib/fab_tool.h" |
||
67 | #include"fab_lib/fab_grx.h" |
||
68 | |||
69 | // *** Corpo delle funzioni in FAB_msg.h *** // |
||
70 | |||
71 | void FAB_print(char * InitMsg, char * msg) |
||
72 | { if (InitMsg!=NULL) {kern_printf("\n[%s]",(InitMsg));} |
||
73 | if (msg!=NULL) {kern_printf("\n %s.",msg);} |
||
74 | } |
||
75 | void __FAB_go(int test, char * OkMsg, char * ErrorMsg,int EXITflag) |
||
76 | { |
||
77 | if (OkMsg==NULL) OkMsg=FAB_EMPTY_MSG; |
||
78 | if (ErrorMsg==NULL) ErrorMsg=FAB_EMPTY_MSG; |
||
79 | |||
80 | if (!test) {kern_printf("\n OK: %s.",OkMsg);} |
||
81 | else {kern_printf("\n ERROR: %s!",ErrorMsg); |
||
1550 | pj | 82 | if (EXITflag==FAB_EXIT_YES) exit(0); |
1091 | pj | 83 | } |
84 | } |
||
85 | |||
86 | // *** Corpo delle funzioni in FAB_tool.h *** // |
||
87 | |||
88 | // nessun corpo! |
||
89 | |||
90 | // *** Corpo delle funzioni in FAB_show.h *** // |
||
91 | |||
92 | void FAB_show_sched_modules() |
||
1123 | pj | 93 | { //int i; |
1091 | pj | 94 | |
95 | FAB_print("MODULI DI SCHEDULAZIONE",NULL); |
||
96 | kern_printf("\n (livello) (nome)"); |
||
1123 | pj | 97 | kern_printf("Names non more available!"); |
98 | //for (i=0; i<sched_levels; i++) |
||
99 | // {kern_printf("\n %-9d %s",i,(level_table[i])->level_name); |
||
100 | // } |
||
1091 | pj | 101 | FAB_newline(); |
102 | } |
||
103 | |||
104 | // *** Corpo delle funzioni in FAB_grx.h *** |
||
105 | |||
106 | FAB_BALLFRAME* FAB_ballframe_alloc() |
||
107 | { FAB_BALLFRAME* frame; |
||
108 | |||
109 | frame=(FAB_BALLFRAME*)kern_alloc(sizeof(FAB_BALLFRAME)); |
||
110 | if (frame==NULL) { |
||
111 | FAB_print(NULL,"BALLFRAME CREATING... ERROR #1"); |
||
112 | return NULL; |
||
113 | } |
||
114 | return frame; |
||
115 | } |
||
116 | void FAB_ballframe_free(FAB_BALLFRAME * frame) |
||
117 | { if (frame!=NULL) |
||
118 | { kern_free(frame,sizeof(FAB_BALLFRAME)); |
||
119 | } |
||
120 | } |
||
121 | |||
122 | FAB_FRAME* FAB_frame_alloc() |
||
123 | { FAB_FRAME* frame; |
||
124 | |||
125 | frame=(FAB_FRAME*)kern_alloc(sizeof(FAB_FRAME)); |
||
126 | if (frame==NULL) { |
||
127 | FAB_print(NULL,"FRAME CREATING... ERROR #1"); |
||
128 | return NULL; |
||
129 | } |
||
130 | |||
131 | return frame; |
||
132 | } |
||
133 | void FAB_frame_free(FAB_FRAME * frame) |
||
134 | { if (frame!=NULL) |
||
135 | { kern_free(frame,sizeof(FAB_FRAME)); |
||
136 | } |
||
137 | } |
||
138 | void FAB_ballborder_put(FAB_BORDER* border, WORD cx, WORD cy, WORD r_int) |
||
139 | { int i; |
||
140 | |||
141 | for (i=0; i<border->dim; i++) |
||
142 | grx_circle(cx, cy, r_int+i, border->buf[i]); |
||
143 | } |
||
144 | void FAB_border_put(FAB_BORDER* border, WORD x0, WORD y0, WORD x1, WORD y1) |
||
145 | { int i; |
||
146 | |||
147 | for (i=0; i<border->dim; i++) |
||
148 | grx_rect(x0-i, y0-i, x1+i, y1+i, border->buf[i]); |
||
149 | } |
||
150 | FAB_BORDER* FAB_border_alloc(WORD dim) |
||
151 | { FAB_BORDER* border; |
||
152 | |||
153 | border=(FAB_BORDER*)kern_alloc(sizeof(FAB_BORDER)); |
||
154 | if (border==NULL) { |
||
155 | FAB_print(NULL,"BORDER CREATING... ERROR #1"); |
||
156 | return NULL; |
||
157 | } |
||
158 | |||
159 | border->buf=(COLOR*)kern_alloc(dim*sizeof(COLOR)); |
||
160 | if (border->buf==NULL) { |
||
161 | FAB_print(NULL,"BORDER CREATING... ERROR #2"); |
||
162 | return NULL; |
||
163 | } |
||
164 | |||
165 | border->dim = dim; |
||
166 | |||
167 | return border; |
||
168 | } |
||
169 | void FAB_border_free(FAB_BORDER * border) |
||
170 | { if (border!=NULL) |
||
171 | { kern_free(border->buf,border->dim*sizeof(COLOR)); |
||
172 | kern_free(border,sizeof(FAB_BORDER)); |
||
173 | } |
||
174 | } |
||
175 | void FAB_image_free(FAB_IMAGE* image) |
||
176 | { if (image!=NULL) |
||
177 | { kern_free(image->buf,image->lx*image->ly*sizeof(COLOR)); |
||
178 | kern_free(image,sizeof(FAB_IMAGE)); |
||
179 | } |
||
180 | } |
||
181 | FAB_IMAGE* FAB_image_alloc(WORD lx, WORD ly) |
||
182 | { FAB_IMAGE* image; |
||
183 | |||
184 | image=(FAB_IMAGE*)kern_alloc(sizeof(FAB_IMAGE)); |
||
185 | if (image==NULL) { |
||
186 | FAB_print(NULL,"IMAGE CREATING... ERROR #1"); |
||
187 | return NULL; |
||
188 | } |
||
189 | |||
190 | image->buf=(COLOR*)kern_alloc(lx*ly*sizeof(COLOR)); |
||
191 | if (image->buf==NULL) { |
||
192 | FAB_print(NULL,"IMAGE CREATING... ERROR #2"); |
||
193 | return NULL; |
||
194 | } |
||
195 | FAB_image_no_trasparent_set(image); |
||
196 | image->lx = lx; |
||
197 | image->ly = ly; |
||
198 | |||
199 | return image; |
||
200 | } |
||
201 | int FAB_image_load(FAB_IMAGE* image, char* file_name) |
||
202 | { |
||
203 | DOS_FILE* file; |
||
204 | BYTE rgb[3]; |
||
205 | COLOR * buf; |
||
206 | int i; |
||
207 | |||
208 | file=DOS_fopen(file_name,"r"); |
||
209 | if (file==NULL) return -1; |
||
210 | |||
211 | buf = image->buf; |
||
212 | for (i=0; i<image->lx*image->ly; i++) |
||
213 | { DOS_fread(&rgb[0],sizeof(BYTE),3,file); |
||
214 | *buf = FAB_rgb(rgb[0],rgb[1],rgb[2]); |
||
215 | buf++; |
||
216 | } |
||
217 | |||
218 | DOS_fclose(file); |
||
219 | return(0); |
||
220 | } |
||
221 | void FAB_image_get(FAB_IMAGE* image, WORD x0, WORD y0, WORD lx, WORD ly) |
||
222 | { WORD x, y; |
||
223 | COLOR* buf; |
||
224 | |||
225 | buf = image->buf; |
||
226 | for (y=0; y<image->ly; y++) |
||
227 | for (x=0; x<image->lx; x++) { |
||
228 | *buf = (COLOR) grx_getpixel(x0+x,y0+y); |
||
229 | buf++; |
||
230 | } |
||
231 | FAB_image_no_trasparent_set(image); |
||
232 | } |
||
233 | void FAB_image_put(FAB_IMAGE* image, WORD x0, WORD y0) |
||
234 | { WORD x, y; |
||
235 | COLOR* buf; |
||
236 | |||
237 | buf = image->buf; |
||
238 | if (!image->trasparent) { |
||
239 | for (y=0; y<image->ly; y++) |
||
240 | for (x=0; x<image->lx; x++) |
||
241 | grx_plot(x0+x,y0+y,*buf++); |
||
242 | } |
||
243 | else { |
||
244 | for (y=0; y<image->ly; y++) |
||
245 | for (x=0; x<image->lx; x++) { |
||
246 | if (*buf!=image->trasparent_col) |
||
247 | grx_plot(x0+x,y0+y,*buf); |
||
248 | buf++; |
||
249 | } |
||
250 | } |
||
251 | } |
||
252 | void FAB_image_put_within(FAB_IMAGE* image, WORD x0, WORD y0, |
||
253 | WORD xx0, WORD yy0, WORD xx1, WORD yy1) |
||
254 | { int step_x0_xx0; |
||
255 | int step_y0_yy0; |
||
256 | int step_xx1_x1; |
||
257 | int step_yy1_y1; |
||
258 | WORD xx, yy; |
||
259 | COLOR* buf; |
||
260 | |||
261 | step_x0_xx0 = xx0 - x0; |
||
262 | step_y0_yy0 = yy0 - y0; |
||
263 | step_xx1_x1 = (x0 + image->lx - 1) - xx1; |
||
264 | step_yy1_y1 = (y0 + image->ly - 1) - yy1; |
||
265 | |||
266 | if (step_x0_xx0 < 0) step_x0_xx0 = 0; |
||
267 | if (step_y0_yy0 < 0) step_y0_yy0 = 0; |
||
268 | if (step_xx1_x1 < 0) step_xx1_x1 = 0; |
||
269 | if (step_yy1_y1 < 0) step_yy1_y1 = 0; |
||
270 | |||
271 | buf = image->buf + step_y0_yy0*image->lx; |
||
272 | if (!image->trasparent) { |
||
273 | for(yy=step_y0_yy0; yy<image->ly-step_yy1_y1; yy++) { |
||
274 | buf += step_x0_xx0; |
||
275 | for(xx=step_x0_xx0; xx<image->lx-step_xx1_x1; xx++) |
||
276 | grx_plot(x0+xx,y0+yy,*buf++); |
||
277 | buf += step_xx1_x1; |
||
278 | } |
||
279 | } |
||
280 | else { |
||
281 | for(yy=step_y0_yy0; yy<image->ly-step_yy1_y1; yy++) { |
||
282 | buf += step_x0_xx0; |
||
283 | for(xx=step_x0_xx0; xx<image->lx-step_xx1_x1; xx++) { |
||
284 | if (*buf!=image->trasparent_col) |
||
285 | grx_plot(x0+xx,y0+yy,*buf); |
||
286 | buf++; |
||
287 | } |
||
288 | buf += step_xx1_x1; |
||
289 | } |
||
290 | } |
||
291 | } |
||
292 | //...funzione usata da FAB_image_fill()... |
||
293 | void __FAB_image_put_into(FAB_IMAGE* image, WORD x0, WORD y0, WORD lx, WORD ly) |
||
294 | { WORD x, y; |
||
295 | WORD skipped_pixels; |
||
296 | COLOR* buf; |
||
297 | |||
298 | if (lx < image->lx) skipped_pixels = image->lx - lx; |
||
299 | else skipped_pixels = 0; |
||
300 | buf = image->buf; |
||
301 | |||
302 | if (!image->trasparent) { |
||
303 | for (y=0; y<ly; y++, buf+=skipped_pixels) { |
||
304 | if (y > image->ly -1) break; |
||
305 | for (x=0; x<lx; x++, buf++) { |
||
306 | if (x < image->lx) grx_plot(x0+x,y0+y,*buf); |
||
307 | else break; |
||
308 | } |
||
309 | } |
||
310 | } |
||
311 | else { |
||
312 | for (y=0; y<ly; y++, buf+=skipped_pixels) { |
||
313 | if (y > image->ly -1) break; |
||
314 | for (x=0; x<lx; x++, buf++) { |
||
315 | if (x < image->lx) { |
||
316 | if (*buf!=image->trasparent_col) |
||
317 | grx_plot(x0+x,y0+y,*buf); |
||
318 | } |
||
319 | else break; |
||
320 | } |
||
321 | } |
||
322 | } |
||
323 | } |
||
324 | void FAB_image_fill(FAB_IMAGE* image, WORD x0, WORD y0, WORD lx, WORD ly) |
||
325 | { WORD x, y; |
||
326 | WORD sub_lx, sub_ly; |
||
327 | |||
328 | for (y=0; y<ly; y+=image->ly) { |
||
329 | sub_ly = ly - y; // spazio verticale disponibile |
||
330 | if (sub_ly > image->ly) sub_ly = image->ly; |
||
331 | for (x=0; x<lx; x+=image->lx) { |
||
332 | sub_lx = lx - x; // spazio orizzontale disponibile |
||
333 | if (sub_lx > image->lx) sub_lx = image->lx; |
||
334 | __FAB_image_put_into(image,x0+x,y0+y,sub_lx,sub_ly); |
||
335 | } |
||
336 | } |
||
337 | } |
||
338 | void FAB_frame_put(FAB_FRAME* frame, WORD x0, WORD y0, WORD lx, WORD ly) |
||
339 | { |
||
340 | WORD eff_dim; |
||
341 | int j; |
||
342 | |||
343 | //BORDO DEL FRAME |
||
344 | if (frame->border!=NULL) eff_dim = frame->border->dim; |
||
345 | else eff_dim = frame->border_dim; |
||
346 | frame->x0 = x0 + eff_dim; |
||
347 | frame->y0 = y0 + eff_dim; |
||
348 | frame->x1 = x0 + lx - eff_dim - 1; |
||
349 | frame->y1 = y0 + ly - eff_dim - 1; |
||
350 | if (frame->border!=NULL) { |
||
351 | FAB_border_put(frame->border, frame->x0-1, frame->y0-1, |
||
352 | frame->x1+1, frame->y1+1); |
||
353 | } |
||
354 | else { |
||
355 | for (j=0; j<eff_dim; j++) |
||
356 | grx_rect(frame->x0-1-j, frame->y0-1-j, |
||
357 | frame->x1+1+j, frame->y1+1+j, frame->border_col); |
||
358 | } |
||
359 | |||
360 | //PANNELLO DEL FRAME |
||
361 | if (!frame->trasparent) { |
||
362 | if (frame->image==NULL) grx_box(frame->x0, frame->y0, |
||
363 | frame->x1, frame->y1, frame->color); |
||
364 | else FAB_image_fill(frame->image, |
||
365 | frame->x0, frame->y0, |
||
366 | lx-eff_dim*2, ly-eff_dim*2); |
||
367 | } |
||
368 | } |
||
369 | |||
370 | void FAB_ballframe_put(FAB_BALLFRAME* frame, WORD cx, WORD cy, WORD r) |
||
371 | { |
||
372 | int j; |
||
373 | WORD eff_dim; |
||
374 | |||
375 | //BORDO DEL FRAME |
||
376 | if (frame->border!=NULL) eff_dim = frame->border->dim; |
||
377 | else eff_dim = frame->border_dim; |
||
378 | frame->cx = cx; |
||
379 | frame->cy = cy; |
||
380 | frame->r = r - eff_dim; |
||
381 | |||
382 | if (frame->border!=NULL) { |
||
383 | FAB_ballborder_put(frame->border,frame->cx,frame->cy,frame->r+1); |
||
384 | } |
||
385 | else { |
||
386 | for (j=0; j<eff_dim; j++) |
||
387 | grx_circle(frame->cx,frame->cy,frame->r+1+j,frame->border_col); |
||
388 | } |
||
389 | |||
390 | //PANNELLO DEL FRAME |
||
391 | if (!frame->trasparent) { |
||
392 | grx_disc(frame->cx,frame->cy,frame->r,frame->color); |
||
393 | } |
||
394 | } |
||
395 | |||
396 | void FAB_image_copy(FAB_IMAGE* orig_image, FAB_IMAGE* dest_image) |
||
397 | { |
||
398 | COLOR* orig_buf; |
||
399 | COLOR* dest_buf; |
||
400 | int j,n; |
||
401 | |||
402 | n = orig_image->lx * orig_image->ly; |
||
403 | if (n==(dest_image->lx * dest_image->ly)) { |
||
404 | orig_buf = orig_image->buf; |
||
405 | dest_buf = dest_image->buf; |
||
406 | for(j=0; j<n; j++) { |
||
407 | *dest_buf = *orig_buf; |
||
408 | orig_buf++; |
||
409 | dest_buf++; |
||
410 | } |
||
411 | } |
||
412 | } |
||
413 | void FAB_image_color_change(FAB_IMAGE* image, COLOR old_col, COLOR new_col) |
||
414 | { COLOR* buf; |
||
415 | int j,n; |
||
416 | |||
417 | buf = image->buf; |
||
418 | n = image->lx * image->ly; |
||
419 | for(j=0; j<n; j++, buf++) |
||
420 | if (*buf==old_col) |
||
421 | *buf=new_col; |
||
422 | } |
||
423 | //----------------------END-------------------------- |
||
424 | #endif |