Subversion Repositories shark

Rev

Rev 1091 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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