Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1664 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 2004-07-05 14:39:38 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
  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
    //     }
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
  file=DOS_fopen(file_name,"r");
228
 
229
  if (file==NULL) return -1;
230
  FAB_print(NULL,"File opened");
231
  buf = image->buf;
232
  for (i=0; i<image->lx*image->ly; i++)
233
    {
234
       DOS_fread(&rgb[0],sizeof(BYTE),3,file);
235
      *buf = FAB_rgb(rgb[0],rgb[1],rgb[2]);
236
      buf++;
237
    }
238
 
239
  DOS_fclose(file);
240
  return(0);
241
}
242
void FAB_image_get(FAB_IMAGE* image, WORD x0, WORD y0, WORD lx, WORD ly)
243
{ WORD x, y;
244
  COLOR* buf;
245
 
246
  buf = image->buf;
247
  for (y=0; y<image->ly; y++)
248
    for (x=0; x<image->lx; x++) {
249
      *buf = (COLOR) grx_getpixel(x0+x,y0+y);
250
      buf++;
251
      }
252
  FAB_image_no_trasparent_set(image);
253
}
254
void FAB_image_put(FAB_IMAGE* image, WORD x0, WORD y0)
255
{ WORD x, y;
256
  COLOR* buf;
257
 
258
  buf = image->buf;
259
  if (!image->trasparent) {
260
    for (y=0; y<image->ly; y++)
261
      for (x=0; x<image->lx; x++)
262
        grx_plot(x0+x,y0+y,*buf++);
263
    }
264
  else {
265
    for (y=0; y<image->ly; y++)
266
      for (x=0; x<image->lx; x++) {
267
        if (*buf!=image->trasparent_col)
268
           grx_plot(x0+x,y0+y,*buf);
269
        buf++;
270
        }
271
    }
272
}
273
void FAB_image_put_within(FAB_IMAGE* image, WORD x0, WORD y0,
274
                          WORD xx0, WORD yy0, WORD xx1, WORD yy1)
275
{ int step_x0_xx0;
276
  int step_y0_yy0;
277
  int step_xx1_x1;
278
  int step_yy1_y1;
279
  WORD xx, yy;
280
  COLOR* buf;
281
 
282
  step_x0_xx0 = xx0 - x0;
283
  step_y0_yy0 = yy0 - y0;
284
  step_xx1_x1 = (x0 + image->lx - 1) - xx1;
285
  step_yy1_y1 = (y0 + image->ly - 1) - yy1;
286
 
287
  if (step_x0_xx0 < 0) step_x0_xx0 = 0;
288
  if (step_y0_yy0 < 0) step_y0_yy0 = 0;
289
  if (step_xx1_x1 < 0) step_xx1_x1 = 0;
290
  if (step_yy1_y1 < 0) step_yy1_y1 = 0;
291
 
292
  buf = image->buf + step_y0_yy0*image->lx;
293
  if (!image->trasparent) {
294
    for(yy=step_y0_yy0; yy<image->ly-step_yy1_y1; yy++) {
295
      buf += step_x0_xx0;
296
      for(xx=step_x0_xx0; xx<image->lx-step_xx1_x1; xx++)
297
          grx_plot(x0+xx,y0+yy,*buf++);
298
      buf += step_xx1_x1;
299
      }
300
    }
301
  else {
302
    for(yy=step_y0_yy0; yy<image->ly-step_yy1_y1; yy++) {
303
      buf += step_x0_xx0;
304
      for(xx=step_x0_xx0; xx<image->lx-step_xx1_x1; xx++) {
305
        if (*buf!=image->trasparent_col)
306
           grx_plot(x0+xx,y0+yy,*buf);
307
        buf++;
308
        }
309
      buf += step_xx1_x1;
310
      }
311
    }
312
}
313
//...funzione usata da FAB_image_fill()...
314
void __FAB_image_put_into(FAB_IMAGE* image, WORD x0, WORD y0, WORD lx, WORD ly)
315
{ WORD x, y;
316
  WORD skipped_pixels;
317
  COLOR* buf;
318
 
319
  if (lx < image->lx) skipped_pixels = image->lx - lx;
320
  else                skipped_pixels = 0;
321
  buf = image->buf;
322
 
323
  if (!image->trasparent) {
324
    for (y=0; y<ly; y++, buf+=skipped_pixels) {
325
      if (y > image->ly -1) break;
326
      for (x=0; x<lx; x++, buf++) {
327
        if (x < image->lx) grx_plot(x0+x,y0+y,*buf);
328
        else break;
329
        }
330
      }
331
    }
332
  else {
333
    for (y=0; y<ly; y++, buf+=skipped_pixels) {
334
      if (y > image->ly -1) break;
335
      for (x=0; x<lx; x++, buf++) {
336
        if (x < image->lx) {
337
           if (*buf!=image->trasparent_col)
338
              grx_plot(x0+x,y0+y,*buf);
339
           }
340
        else break;
341
        }
342
      }
343
    }
344
}
345
void FAB_image_fill(FAB_IMAGE* image, WORD x0, WORD y0, WORD lx, WORD ly)
346
{ WORD x, y;
347
  WORD sub_lx, sub_ly;
348
 
349
  for (y=0; y<ly; y+=image->ly) {
350
    sub_ly = ly - y; // spazio verticale disponibile
351
    if (sub_ly > image->ly) sub_ly = image->ly;
352
    for (x=0; x<lx; x+=image->lx) {
353
       sub_lx = lx - x; // spazio orizzontale disponibile
354
       if (sub_lx > image->lx) sub_lx = image->lx;
355
       __FAB_image_put_into(image,x0+x,y0+y,sub_lx,sub_ly);
356
       }
357
    }
358
}
359
void FAB_frame_put(FAB_FRAME* frame, WORD x0, WORD y0, WORD lx, WORD ly)
360
{
361
  WORD eff_dim;
362
  int j;
363
 
364
  //BORDO DEL FRAME
365
  if (frame->border!=NULL) eff_dim = frame->border->dim;
366
  else                     eff_dim = frame->border_dim;
367
  frame->x0 = x0 + eff_dim;    
368
  frame->y0 = y0 + eff_dim;
369
  frame->x1 = x0 + lx - eff_dim - 1;
370
  frame->y1 = y0 + ly - eff_dim - 1;
371
  if (frame->border!=NULL) {
372
     FAB_border_put(frame->border, frame->x0-1, frame->y0-1,
373
                                   frame->x1+1, frame->y1+1);
374
     }
375
  else {
376
     for (j=0; j<eff_dim; j++)
377
       grx_rect(frame->x0-1-j, frame->y0-1-j,
378
                frame->x1+1+j, frame->y1+1+j, frame->border_col);
379
     }
380
 
381
  //PANNELLO DEL FRAME
382
  if (!frame->trasparent) {
383
    if (frame->image==NULL) grx_box(frame->x0, frame->y0,
384
                                    frame->x1, frame->y1, frame->color);
385
    else                    FAB_image_fill(frame->image,
386
                                           frame->x0,    frame->y0,
387
                                           lx-eff_dim*2, ly-eff_dim*2);
388
    }
389
}
390
 
391
void FAB_ballframe_put(FAB_BALLFRAME* frame, WORD cx, WORD cy, WORD r)
392
{
393
  int j;
394
  WORD eff_dim;
395
 
396
  //BORDO DEL FRAME
397
  if (frame->border!=NULL) eff_dim = frame->border->dim;
398
  else                     eff_dim = frame->border_dim;
399
  frame->cx = cx;
400
  frame->cy = cy;
401
  frame->r = r - eff_dim;
402
 
403
  if (frame->border!=NULL) {
404
     FAB_ballborder_put(frame->border,frame->cx,frame->cy,frame->r+1);
405
     }
406
  else {
407
     for (j=0; j<eff_dim; j++)
408
       grx_circle(frame->cx,frame->cy,frame->r+1+j,frame->border_col);
409
     }
410
 
411
  //PANNELLO DEL FRAME
412
    if (!frame->trasparent) {
413
    grx_disc(frame->cx,frame->cy,frame->r,frame->color);
414
    }
415
}
416
 
417
void FAB_image_copy(FAB_IMAGE* orig_image, FAB_IMAGE* dest_image)
418
{
419
  COLOR* orig_buf;
420
  COLOR* dest_buf;
421
  int j,n;
422
 
423
  n = orig_image->lx * orig_image->ly;
424
  if (n==(dest_image->lx * dest_image->ly)) {
425
    orig_buf = orig_image->buf;
426
    dest_buf = dest_image->buf;
427
    for(j=0; j<n; j++) {
428
      *dest_buf = *orig_buf;
429
      orig_buf++;
430
      dest_buf++;
431
      }
432
    }
433
}
434
void   FAB_image_color_change(FAB_IMAGE* image, COLOR old_col, COLOR new_col)
435
{ COLOR* buf;
436
  int j,n;
437
 
438
  buf = image->buf;
439
  n = image->lx * image->ly;
440
  for(j=0; j<n; j++, buf++)
441
    if (*buf==old_col)
442
       *buf=new_col;
443
}
444
//----------------------END--------------------------
445
#endif