Subversion Repositories shark

Rev

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

Rev Author Line No. Line
1163 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/vga.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
#define INITSTR G640x480x64K //SVGAlib standard mode definitions
47
#define CARD VESA //Video driver
48
 
49
unsigned char *video_buf = NULL; //Video Buffer
50
unsigned long int VMEMLONG = WIDTH * HEIGHT * BYTES_PP / 4; // Used by copy_videomem_16to16
51
unsigned long int RGB565MEM = WIDTH * HEIGHT * BYTES_PP; // Total video mem
52
 
1165 giacomo 53
#define FG_PERIOD 40000
1164 giacomo 54
#define FG_WCET 30000
1165 giacomo 55
#define FG_W 320                
56
#define FG_H 200
1163 giacomo 57
 
1165 giacomo 58
unsigned int color = FG_MONO;
59
 
1163 giacomo 60
static int screen(int mode)
61
{
62
 
63
  vga_modeinfo *minf;
64
 
65
  vga_setmode(mode,CARD);
66
  minf = vga_getmodeinfo(mode);
67
  if(! (minf->flags & CAPABLE_LINEAR)){
68
    vga_setmode(TEXT,CARD);
69
    printk(KERN_INFO "The mode %d is not capable of linear\n",mode);
70
    return 1;
71
  }
72
  vga_setpage(0);
73
  if(vga_setlinearaddressing() == -1) {
74
    vga_setmode(TEXT,CARD);
75
    printk(KERN_INFO "Could not set linear addressing for mode %d\n",mode);
76
    return 1;
77
  }
78
 
79
  video_buf = vga_getgraphmem();
80
 
81
  memset(video_buf, 0, RGB565MEM);
82
 
83
  grx_setbuffer(video_buf, WIDTH, HEIGHT);      //Init of RGBA version of grx functions
84
                                                //created to work with Mesa buffer
85
  return 0;
86
 
87
}
88
 
89
void program_end(void *arg)
90
{
1164 giacomo 91
 
92
  FG_close();
93
 
1163 giacomo 94
  vga_setmode(TEXT,CARD);
95
 
96
  sys_end();
97
 
98
}
99
 
100
void program_key_end(KEY_EVT *k)
101
{
102
 
103
  sys_end();
104
 
105
}
106
 
1164 giacomo 107
void elaborate_image(void *imageptr)
1163 giacomo 108
{
109
 
1165 giacomo 110
  WORD x,y;
111
  BYTE *col;
1163 giacomo 112
 
1165 giacomo 113
  if (color == FG_MONO) {
1163 giacomo 114
 
1164 giacomo 115
    for(y = 0; y < FG_H; y++)
1165 giacomo 116
      for(x = 0; x < FG_W; x++) {
1163 giacomo 117
 
1165 giacomo 118
        col = (BYTE *)(imageptr + y*FG_W + x);
119
        *(WORD *)(video_buf + y*(WIDTH*2) + (x*2)) = (WORD)rgb16(*(BYTE *)(col),*(BYTE *)(col),*(BYTE *)(col));
1163 giacomo 120
 
1165 giacomo 121
    }
1163 giacomo 122
 
123
  }
124
 
1165 giacomo 125
  if (color == FG_RGB24) {
1163 giacomo 126
 
1165 giacomo 127
    for(y = 0; y < FG_H; y++)
128
      for(x = 0; x < FG_W; x++) {
129
 
130
        col = (BYTE *)(imageptr + y*(FG_W*3) + (x*3));
131
        *(WORD *)(video_buf + y*(WIDTH*2) + (x*2)) = (WORD)rgb16(*(BYTE *)(col),*(BYTE *)(col+1),*(BYTE *)(col+2));
132
 
133
    }
134
 
135
  }
136
 
1163 giacomo 137
}
138
 
139
int main(int argc, char **argv)
140
{
141
 
142
  sys_atrunlevel(program_end,NULL, RUNLEVEL_BEFORE_EXIT);
143
 
144
  {
145
      KEY_EVT k;
146
      k.flag = ALTL_BIT;
147
      k.scan = KEY_C;
148
      k.ascii = 'c';
149
      keyb_hook(k,program_key_end);
150
  }
151
 
152
  screen(INITSTR);
153
 
1165 giacomo 154
  FG_init(FG_PERIOD, FG_WCET, FG_W, FG_H, color);
1163 giacomo 155
 
1164 giacomo 156
  FG_set_hook(elaborate_image);
1165 giacomo 157
 
158
  FG_start_grabbing();
1163 giacomo 159
 
160
  return 0;
161
 
162
}