Subversion Repositories shark

Rev

Rev 1173 | Rev 1189 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1174 giacomo 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
 *   Giacomo Guidi       <giacomo@gandalf.sssup.it>
10
 *
11
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
12
 *
13
 * http://www.sssup.it
14
 * http://retis.sssup.it
15
 * http://shark.sssup.it
16
 */
17
 
18
/*
19
 * Copyright (C) 2003 Giacomo Guidi
20
 *
21
 * This program is free software; you can redistribute it and/or modify
22
 * it under the terms of the GNU General Public License as published by
23
 * the Free Software Foundation; either version 2 of the License, or
24
 * (at your option) any later version.
25
 *
26
 * This program is distributed in the hope that it will be useful,
27
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29
 * GNU General Public License for more details.
30
 *
31
 * You should have received a copy of the GNU General Public License
32
 * along with this program; if not, write to the Free Software
33
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
34
 */
35
 
36
#include "kernel/kern.h"
37
#include <drivers/fg.h>
38
#include <drivers/glib.h>
39
#include <drivers/keyb.h>
40
#include <unistd.h>
41
#include <stdlib.h>
42
 
43
#define WIDTH 640
44
#define HEIGHT 480
45
#define BYTES_PP 2
46
 
47
unsigned char *video_buf = NULL; //Video Buffer
48
unsigned long int VMEMLONG = WIDTH * HEIGHT * BYTES_PP / 4; // Used by copy_videomem_16to16
49
unsigned long int RGB565MEM = WIDTH * HEIGHT * BYTES_PP; // Total video mem
50
 
51
#define FG_PERIOD 40000
52
#define FG_WCET 30000
53
#define FG_W 320                
54
#define FG_H 200
55
 
56
unsigned int color = FG_MONO;
57
 
58
extern DWORD flbaddr;
59
 
60
static void screen()
61
{
62
 
63
  /* graphic card Initialization */
64
  if (grx_init() < 1) {
65
     sys_abort(1);
66
  }
67
 
68
  if (grx_open(640, 480, 16) < 0) {
69
     cprintf("GRX Err\n");
70
     sys_abort(1);
71
  }
72
 
73
  video_buf = (unsigned char *)flbaddr;
74
 
75
}
76
 
77
void program_end(void *arg)
78
{
79
 
80
  FG_close();
81
 
82
  grx_close();
83
 
84
  sys_end();
85
 
86
}
87
 
88
void program_key_end(KEY_EVT *k)
89
{
90
 
91
  sys_end();
92
 
93
}
94
 
95
void elaborate_image(void *imageptr)
96
{
97
 
98
  WORD x,y;
99
  BYTE *col;
100
 
101
  if (color == FG_MONO) {
102
 
103
    for(y = 0; y < FG_H; y++)
104
      for(x = 0; x < FG_W; x++) {
105
 
106
        col = (BYTE *)(imageptr + y*FG_W + x);
107
        *(WORD *)(video_buf + y*(WIDTH*2) + (x*2)) = (WORD)rgb16(*(BYTE *)(col),*(BYTE *)(col),*(BYTE *)(col));
108
 
109
    }
110
 
111
  }
112
 
113
  if (color == FG_RGB24) {
114
 
115
    for(y = 0; y < FG_H; y++)
116
      for(x = 0; x < FG_W; x++) {
117
 
118
        col = (BYTE *)(imageptr + y*(FG_W*3) + (x*3));
119
        *(WORD *)(video_buf + y*(WIDTH*2) + (x*2)) = (WORD)rgb16(*(BYTE *)(col),*(BYTE *)(col+1),*(BYTE *)(col+2));
120
 
121
    }
122
 
123
  }
124
 
125
  //printf_xy(0,0,WHITE,"Grabbed = %08lx",*(DWORD *)(imageptr + 50*FG_W + 50));
126
  //printf_xy(0,1,WHITE,"Grabbed = %08lx",*(DWORD *)(imageptr + 51*FG_W + 50));
127
 
128
}
129
 
130
int main(int argc, char **argv)
131
{
132
 
133
  int channel = 0;
134
 
135
  if (argc < 2) {
136
        channel = 0;
137
  } else {
138
        channel = atoi(argv[1]);
139
  }
140
 
141
  sys_atrunlevel(program_end,NULL, RUNLEVEL_BEFORE_EXIT);
142
 
143
  {
144
      KEY_EVT k;
145
      k.flag = ALTL_BIT;
146
      k.scan = KEY_C;
147
      k.ascii = 'c';
148
      keyb_hook(k,program_key_end);
149
  }
150
 
151
 
152
  screen();
153
  //video_buf = malloc(RGB565MEM);
154
 
155
  sleep(1);
156
 
157
  FG_init(FG_PERIOD, FG_WCET, FG_W, FG_H, color, channel);
158
 
159
  FG_set_hook(elaborate_image);
160
 
161
  FG_start_grabbing();
162
 
163
  return 0;
164
 
165
}