Subversion Repositories shark

Rev

Rev 1174 | Rev 1423 | 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
  grx_close();
1189 giacomo 81
 
82
  sys_end();
1174 giacomo 83
 
84
}
85
 
86
void elaborate_image(void *imageptr)
87
{
88
 
89
  WORD x,y;
90
  BYTE *col;
91
 
92
  if (color == FG_MONO) {
93
 
94
    for(y = 0; y < FG_H; y++)
95
      for(x = 0; x < FG_W; x++) {
96
 
97
        col = (BYTE *)(imageptr + y*FG_W + x);
98
        *(WORD *)(video_buf + y*(WIDTH*2) + (x*2)) = (WORD)rgb16(*(BYTE *)(col),*(BYTE *)(col),*(BYTE *)(col));
99
 
100
    }
101
 
102
  }
103
 
104
  if (color == FG_RGB24) {
105
 
106
    for(y = 0; y < FG_H; y++)
107
      for(x = 0; x < FG_W; x++) {
108
 
109
        col = (BYTE *)(imageptr + y*(FG_W*3) + (x*3));
110
        *(WORD *)(video_buf + y*(WIDTH*2) + (x*2)) = (WORD)rgb16(*(BYTE *)(col),*(BYTE *)(col+1),*(BYTE *)(col+2));
111
 
112
    }
113
 
114
  }
115
 
116
  //printf_xy(0,0,WHITE,"Grabbed = %08lx",*(DWORD *)(imageptr + 50*FG_W + 50));
117
  //printf_xy(0,1,WHITE,"Grabbed = %08lx",*(DWORD *)(imageptr + 51*FG_W + 50));
118
 
119
}
120
 
121
int main(int argc, char **argv)
122
{
123
 
124
  int channel = 0;
125
 
126
  if (argc < 2) {
127
        channel = 0;
128
  } else {
129
        channel = atoi(argv[1]);
130
  }
131
 
132
  sys_atrunlevel(program_end,NULL, RUNLEVEL_BEFORE_EXIT);
133
 
134
  screen();
135
  //video_buf = malloc(RGB565MEM);
136
 
137
  sleep(1);
138
 
139
  FG_init(FG_PERIOD, FG_WCET, FG_W, FG_H, color, channel);
140
 
141
  FG_set_hook(elaborate_image);
142
 
143
  FG_start_grabbing();
1189 giacomo 144
 
145
  while(keyb_getch(BLOCK) != ESC);
146
 
147
  FG_close();
148
 
149
  sys_end();
150
 
1174 giacomo 151
  return 0;
152
 
153
}