Rev 1091 | Go to most recent revision | 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 | |||
1123 | pj | 21 | /* CVS : $Id: fab_lib.c,v 1.3 2003-01-07 17:10:16 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> |
||
58 | #include<drivers/gd.h> |
||
59 | #include<drivers/glib.h> |
||
60 | #include<ll/sys/types.h> |
||
61 | #include<ll/i386/x-dos.h> |
||
62 | // *** Librerie Standard C *** |
||
63 | // *** Librerie FAB *** |
||
64 | #include"fab_lib/fab_msg.h" |
||
65 | #include"fab_lib/fab_tool.h" |
||
66 | #include"fab_lib/fab_grx.h" |
||
67 | |||
68 | // *** Corpo delle funzioni in FAB_msg.h *** // |
||
69 | |||
70 | void FAB_print(char * InitMsg, char * msg) |
||
71 | { if (InitMsg!=NULL) {kern_printf("\n[%s]",(InitMsg));} |
||
72 | if (msg!=NULL) {kern_printf("\n %s.",msg);} |
||
73 | } |
||
74 | void __FAB_go(int test, char * OkMsg, char * ErrorMsg,int EXITflag) |
||
75 | { |
||
76 | if (OkMsg==NULL) OkMsg=FAB_EMPTY_MSG; |
||
77 | if (ErrorMsg==NULL) ErrorMsg=FAB_EMPTY_MSG; |
||
78 | |||
79 | if (!test) {kern_printf("\n OK: %s.",OkMsg);} |
||
80 | else {kern_printf("\n ERROR: %s!",ErrorMsg); |
||
81 | if (EXITflag==FAB_EXIT_YES) sys_end(); |
||
82 | } |
||
83 | } |
||
84 | |||
85 | // *** Corpo delle funzioni in FAB_tool.h *** // |
||
86 | |||
87 | // nessun corpo! |
||
88 | |||
89 | // *** Corpo delle funzioni in FAB_show.h *** // |
||
90 | |||
91 | void FAB_show_sched_modules() |
||
1123 | pj | 92 | { //int i; |
1091 | pj | 93 | |
94 | FAB_print("MODULI DI SCHEDULAZIONE",NULL); |
||
95 | kern_printf("\n (livello) (nome)"); |
||
1123 | pj | 96 | kern_printf("Names non more available!"); |
97 | //for (i=0; i<sched_levels; i++) |
||
98 | // {kern_printf("\n %-9d %s",i,(level_table[i])->level_name); |
||
99 | // } |
||
1091 | pj | 100 | FAB_newline(); |
101 | } |
||
102 | |||
103 | // *** Corpo delle funzioni in FAB_grx.h *** |
||
104 | |||
105 | FAB_BALLFRAME* FAB_ballframe_alloc() |
||
106 | { FAB_BALLFRAME* frame; |
||
107 | |||
108 | frame=(FAB_BALLFRAME*)kern_alloc(sizeof(FAB_BALLFRAME)); |
||
109 | if (frame==NULL) { |
||
110 | FAB_print(NULL,"BALLFRAME CREATING... ERROR #1"); |
||
111 | return NULL; |
||
112 | } |
||
113 | return frame; |
||
114 | } |
||
115 | void FAB_ballframe_free(FAB_BALLFRAME * frame) |
||
116 | { if (frame!=NULL) |
||
117 | { kern_free(frame,sizeof(FAB_BALLFRAME)); |
||
118 | } |
||
119 | } |
||
120 | |||
121 | FAB_FRAME* FAB_frame_alloc() |
||
122 | { FAB_FRAME* frame; |
||
123 | |||
124 | frame=(FAB_FRAME*)kern_alloc(sizeof(FAB_FRAME)); |
||
125 | if (frame==NULL) { |
||
126 | FAB_print(NULL,"FRAME CREATING... ERROR #1"); |
||
127 | return NULL; |
||
128 | } |
||
129 | |||
130 | return frame; |
||
131 | } |
||
132 | void FAB_frame_free(FAB_FRAME * frame) |
||
133 | { if (frame!=NULL) |
||
134 | { kern_free(frame,sizeof(FAB_FRAME)); |
||
135 | } |
||
136 | } |
||
137 | void FAB_ballborder_put(FAB_BORDER* border, WORD cx, WORD cy, WORD r_int) |
||
138 | { int i; |
||
139 | |||
140 | for (i=0; i<border->dim; i++) |
||
141 | grx_circle(cx, cy, r_int+i, border->buf[i]); |
||
142 | } |
||
143 | void FAB_border_put(FAB_BORDER* border, WORD x0, WORD y0, WORD x1, WORD y1) |
||
144 | { int i; |
||
145 | |||
146 | for (i=0; i<border->dim; i++) |
||
147 | grx_rect(x0-i, y0-i, x1+i, y1+i, border->buf[i]); |
||
148 | } |
||
149 | FAB_BORDER* FAB_border_alloc(WORD dim) |
||
150 | { FAB_BORDER* border; |
||
151 | |||
152 | border=(FAB_BORDER*)kern_alloc(sizeof(FAB_BORDER)); |
||
153 | if (border==NULL) { |
||
154 | FAB_print(NULL,"BORDER CREATING... ERROR #1"); |
||
155 | return NULL; |
||
156 | } |
||
157 | |||
158 | border->buf=(COLOR*)kern_alloc(dim*sizeof(COLOR)); |
||
159 | if (border->buf==NULL) { |
||
160 | FAB_print(NULL,"BORDER CREATING... ERROR #2"); |
||
161 | return NULL; |
||
162 | } |
||
163 | |||
164 | border->dim = dim; |
||
165 | |||
166 | return border; |
||
167 | } |
||
168 | void FAB_border_free(FAB_BORDER * border) |
||
169 | { if (border!=NULL) |
||
170 | { kern_free(border->buf,border->dim*sizeof(COLOR)); |
||
171 | kern_free(border,sizeof(FAB_BORDER)); |
||
172 | } |
||
173 | } |
||
174 | void FAB_image_free(FAB_IMAGE* image) |
||
175 | { if (image!=NULL) |
||
176 | { kern_free(image->buf,image->lx*image->ly*sizeof(COLOR)); |
||
177 | kern_free(image,sizeof(FAB_IMAGE)); |
||
178 | } |
||
179 | } |
||
180 | FAB_IMAGE* FAB_image_alloc(WORD lx, WORD ly) |
||
181 | { FAB_IMAGE* image; |
||
182 | |||
183 | image=(FAB_IMAGE*)kern_alloc(sizeof(FAB_IMAGE)); |
||
184 | if (image==NULL) { |
||
185 | FAB_print(NULL,"IMAGE CREATING... ERROR #1"); |
||
186 | return NULL; |
||
187 | } |
||
188 | |||
189 | image->buf=(COLOR*)kern_alloc(lx*ly*sizeof(COLOR)); |
||
190 | if (image->buf==NULL) { |
||
191 | FAB_print(NULL,"IMAGE CREATING... ERROR #2"); |
||
192 | return NULL; |
||
193 | } |
||
194 | FAB_image_no_trasparent_set(image); |
||
195 | image->lx = lx; |
||
196 | image->ly = ly; |
||
197 | |||
198 | return image; |
||
199 | } |
||
200 | int FAB_grx_open(WORD lx, WORD ly) |
||
201 | { int modenum; |
||
202 | |||
203 | FAB_print("VIDEO",NULL); |
||
204 | if (grx_init()==-1) { |
||
205 | FAB_print(NULL,"ERRORE nell'inizializzazione!"); |
||
206 | return -1; |
||
207 | } |
||
208 | if((modenum = grx_getmode(lx, ly, FAB_BPP))==-1) { |
||
209 | FAB_print(NULL,"Modalita' NON supportata!"); |
||
210 | return -1; |
||
211 | } |
||
212 | if(grx_setmode(modenum)==-1) { |
||
213 | FAB_print(NULL,"ERRORE nell'apertura della modalita'video"); |
||
214 | return -1; |
||
215 | } |
||
216 | return 0; |
||
217 | } |
||
218 | void FAB_grx_close() |
||
219 | { grx_close(); |
||
220 | } |
||
221 | int FAB_image_load(FAB_IMAGE* image, char* file_name) |
||
222 | { |
||
223 | DOS_FILE* file; |
||
224 | BYTE rgb[3]; |
||
225 | COLOR * buf; |
||
226 | int i; |
||
227 | |||
228 | file=DOS_fopen(file_name,"r"); |
||
229 | if (file==NULL) return -1; |
||
230 | |||
231 | buf = image->buf; |
||
232 | for (i=0; i<image->lx*image->ly; i++) |
||
233 | { DOS_fread(&rgb[0],sizeof(BYTE),3,file); |
||
234 | *buf = FAB_rgb(rgb[0],rgb[1],rgb[2]); |
||
235 | buf++; |
||
236 | } |
||
237 | |||
238 | DOS_fclose(file); |
||
239 | return(0); |
||
240 | } |
||
241 | void FAB_image_get(FAB_IMAGE* image, WORD x0, WORD y0, WORD lx, WORD ly) |
||
242 | { WORD x, y; |
||
243 | COLOR* buf; |
||
244 | |||
245 | buf = image->buf; |
||
246 | for (y=0; y<image->ly; y++) |
||
247 | for (x=0; x<image->lx; x++) { |
||
248 | *buf = (COLOR) grx_getpixel(x0+x,y0+y); |
||
249 | buf++; |
||
250 | } |
||
251 | FAB_image_no_trasparent_set(image); |
||
252 | } |
||
253 | void FAB_image_put(FAB_IMAGE* image, WORD x0, WORD y0) |
||
254 | { WORD x, y; |
||
255 | COLOR* buf; |
||
256 | |||
257 | buf = image->buf; |
||
258 | if (!image->trasparent) { |
||
259 | for (y=0; y<image->ly; y++) |
||
260 | for (x=0; x<image->lx; x++) |
||
261 | grx_plot(x0+x,y0+y,*buf++); |
||
262 | } |
||
263 | else { |
||
264 | for (y=0; y<image->ly; y++) |
||
265 | for (x=0; x<image->lx; x++) { |
||
266 | if (*buf!=image->trasparent_col) |
||
267 | grx_plot(x0+x,y0+y,*buf); |
||
268 | buf++; |
||
269 | } |
||
270 | } |
||
271 | } |
||
272 | void FAB_image_put_within(FAB_IMAGE* image, WORD x0, WORD y0, |
||
273 | WORD xx0, WORD yy0, WORD xx1, WORD yy1) |
||
274 | { int step_x0_xx0; |
||
275 | int step_y0_yy0; |
||
276 | int step_xx1_x1; |
||
277 | int step_yy1_y1; |
||
278 | WORD xx, yy; |
||
279 | COLOR* buf; |
||
280 | |||
281 | step_x0_xx0 = xx0 - x0; |
||
282 | step_y0_yy0 = yy0 - y0; |
||
283 | step_xx1_x1 = (x0 + image->lx - 1) - xx1; |
||
284 | step_yy1_y1 = (y0 + image->ly - 1) - yy1; |
||
285 | |||
286 | if (step_x0_xx0 < 0) step_x0_xx0 = 0; |
||
287 | if (step_y0_yy0 < 0) step_y0_yy0 = 0; |
||
288 | if (step_xx1_x1 < 0) step_xx1_x1 = 0; |
||
289 | if (step_yy1_y1 < 0) step_yy1_y1 = 0; |
||
290 | |||
291 | buf = image->buf + step_y0_yy0*image->lx; |
||
292 | if (!image->trasparent) { |
||
293 | for(yy=step_y0_yy0; yy<image->ly-step_yy1_y1; yy++) { |
||
294 | buf += step_x0_xx0; |
||
295 | for(xx=step_x0_xx0; xx<image->lx-step_xx1_x1; xx++) |
||
296 | grx_plot(x0+xx,y0+yy,*buf++); |
||
297 | buf += step_xx1_x1; |
||
298 | } |
||
299 | } |
||
300 | else { |
||
301 | for(yy=step_y0_yy0; yy<image->ly-step_yy1_y1; yy++) { |
||
302 | buf += step_x0_xx0; |
||
303 | for(xx=step_x0_xx0; xx<image->lx-step_xx1_x1; xx++) { |
||
304 | if (*buf!=image->trasparent_col) |
||
305 | grx_plot(x0+xx,y0+yy,*buf); |
||
306 | buf++; |
||
307 | } |
||
308 | buf += step_xx1_x1; |
||
309 | } |
||
310 | } |
||
311 | } |
||
312 | //...funzione usata da FAB_image_fill()... |
||
313 | void __FAB_image_put_into(FAB_IMAGE* image, WORD x0, WORD y0, WORD lx, WORD ly) |
||
314 | { WORD x, y; |
||
315 | WORD skipped_pixels; |
||
316 | COLOR* buf; |
||
317 | |||
318 | if (lx < image->lx) skipped_pixels = image->lx - lx; |
||
319 | else skipped_pixels = 0; |
||
320 | buf = image->buf; |
||
321 | |||
322 | if (!image->trasparent) { |
||
323 | for (y=0; y<ly; y++, buf+=skipped_pixels) { |
||
324 | if (y > image->ly -1) break; |
||
325 | for (x=0; x<lx; x++, buf++) { |
||
326 | if (x < image->lx) grx_plot(x0+x,y0+y,*buf); |
||
327 | else break; |
||
328 | } |
||
329 | } |
||
330 | } |
||
331 | else { |
||
332 | for (y=0; y<ly; y++, buf+=skipped_pixels) { |
||
333 | if (y > image->ly -1) break; |
||
334 | for (x=0; x<lx; x++, buf++) { |
||
335 | if (x < image->lx) { |
||
336 | if (*buf!=image->trasparent_col) |
||
337 | grx_plot(x0+x,y0+y,*buf); |
||
338 | } |
||
339 | else break; |
||
340 | } |
||
341 | } |
||
342 | } |
||
343 | } |
||
344 | void FAB_image_fill(FAB_IMAGE* image, WORD x0, WORD y0, WORD lx, WORD ly) |
||
345 | { WORD x, y; |
||
346 | WORD sub_lx, sub_ly; |
||
347 | |||
348 | for (y=0; y<ly; y+=image->ly) { |
||
349 | sub_ly = ly - y; // spazio verticale disponibile |
||
350 | if (sub_ly > image->ly) sub_ly = image->ly; |
||
351 | for (x=0; x<lx; x+=image->lx) { |
||
352 | sub_lx = lx - x; // spazio orizzontale disponibile |
||
353 | if (sub_lx > image->lx) sub_lx = image->lx; |
||
354 | __FAB_image_put_into(image,x0+x,y0+y,sub_lx,sub_ly); |
||
355 | } |
||
356 | } |
||
357 | } |
||
358 | void FAB_frame_put(FAB_FRAME* frame, WORD x0, WORD y0, WORD lx, WORD ly) |
||
359 | { |
||
360 | WORD eff_dim; |
||
361 | int j; |
||
362 | |||
363 | //BORDO DEL FRAME |
||
364 | if (frame->border!=NULL) eff_dim = frame->border->dim; |
||
365 | else eff_dim = frame->border_dim; |
||
366 | frame->x0 = x0 + eff_dim; |
||
367 | frame->y0 = y0 + eff_dim; |
||
368 | frame->x1 = x0 + lx - eff_dim - 1; |
||
369 | frame->y1 = y0 + ly - eff_dim - 1; |
||
370 | if (frame->border!=NULL) { |
||
371 | FAB_border_put(frame->border, frame->x0-1, frame->y0-1, |
||
372 | frame->x1+1, frame->y1+1); |
||
373 | } |
||
374 | else { |
||
375 | for (j=0; j<eff_dim; j++) |
||
376 | grx_rect(frame->x0-1-j, frame->y0-1-j, |
||
377 | frame->x1+1+j, frame->y1+1+j, frame->border_col); |
||
378 | } |
||
379 | |||
380 | //PANNELLO DEL FRAME |
||
381 | if (!frame->trasparent) { |
||
382 | if (frame->image==NULL) grx_box(frame->x0, frame->y0, |
||
383 | frame->x1, frame->y1, frame->color); |
||
384 | else FAB_image_fill(frame->image, |
||
385 | frame->x0, frame->y0, |
||
386 | lx-eff_dim*2, ly-eff_dim*2); |
||
387 | } |
||
388 | } |
||
389 | |||
390 | void FAB_ballframe_put(FAB_BALLFRAME* frame, WORD cx, WORD cy, WORD r) |
||
391 | { |
||
392 | int j; |
||
393 | WORD eff_dim; |
||
394 | |||
395 | //BORDO DEL FRAME |
||
396 | if (frame->border!=NULL) eff_dim = frame->border->dim; |
||
397 | else eff_dim = frame->border_dim; |
||
398 | frame->cx = cx; |
||
399 | frame->cy = cy; |
||
400 | frame->r = r - eff_dim; |
||
401 | |||
402 | if (frame->border!=NULL) { |
||
403 | FAB_ballborder_put(frame->border,frame->cx,frame->cy,frame->r+1); |
||
404 | } |
||
405 | else { |
||
406 | for (j=0; j<eff_dim; j++) |
||
407 | grx_circle(frame->cx,frame->cy,frame->r+1+j,frame->border_col); |
||
408 | } |
||
409 | |||
410 | //PANNELLO DEL FRAME |
||
411 | if (!frame->trasparent) { |
||
412 | grx_disc(frame->cx,frame->cy,frame->r,frame->color); |
||
413 | } |
||
414 | } |
||
415 | |||
416 | void FAB_image_copy(FAB_IMAGE* orig_image, FAB_IMAGE* dest_image) |
||
417 | { |
||
418 | COLOR* orig_buf; |
||
419 | COLOR* dest_buf; |
||
420 | int j,n; |
||
421 | |||
422 | n = orig_image->lx * orig_image->ly; |
||
423 | if (n==(dest_image->lx * dest_image->ly)) { |
||
424 | orig_buf = orig_image->buf; |
||
425 | dest_buf = dest_image->buf; |
||
426 | for(j=0; j<n; j++) { |
||
427 | *dest_buf = *orig_buf; |
||
428 | orig_buf++; |
||
429 | dest_buf++; |
||
430 | } |
||
431 | } |
||
432 | } |
||
433 | void FAB_image_color_change(FAB_IMAGE* image, COLOR old_col, COLOR new_col) |
||
434 | { COLOR* buf; |
||
435 | int j,n; |
||
436 | |||
437 | buf = image->buf; |
||
438 | n = image->lx * image->ly; |
||
439 | for(j=0; j<n; j++, buf++) |
||
440 | if (*buf==old_col) |
||
441 | *buf=new_col; |
||
442 | } |
||
443 | //----------------------END-------------------------- |
||
444 | #endif |