Subversion Repositories shark

Rev

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

Rev Author Line No. Line
1085 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
 *   (see the web pages for full authors list)
11
 *
12
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
13
 *
14
 * http://www.sssup.it
15
 * http://retis.sssup.it
16
 * http://shark.sssup.it
17
 */
18
 
19
/**
20
 ------------
1380 giacomo 21
 CVS :        $Id: demo.c,v 1.6 2004-04-18 09:45:27 giacomo Exp $
1085 pj 22
 
23
 File:        $File$
1380 giacomo 24
 Revision:    $Revision: 1.6 $
25
 Last update: $Date: 2004-04-18 09:45:27 $
1085 pj 26
 ------------
27
**/
28
 
29
/*
1158 pj 30
 * Copyright (C) 2000-2003 Paolo Gai
1085 pj 31
 *
32
 * This program is free software; you can redistribute it and/or modify
33
 * it under the terms of the GNU General Public License as published by
34
 * the Free Software Foundation; either version 2 of the License, or
35
 * (at your option) any later version.
36
 *
37
 * This program is distributed in the hope that it will be useful,
38
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
40
 * GNU General Public License for more details.
41
 *
42
 * You should have received a copy of the GNU General Public License
43
 * along with this program; if not, write to the Free Software
44
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
45
 *
46
 */
47
 
48
#include "demo.h"
49
#include <kernel/func.h>
50
#include <string.h>
51
#include <stdlib.h>
52
 
53
/* useful colors... */
54
int white;
55
int black;
56
int red;
57
int gray;
58
 
1379 giacomo 59
PID shutdown_task_PID = -1;
1085 pj 60
 
1380 giacomo 61
void app_mutex_init(mutex_t *m);
62
 
1379 giacomo 63
int device_drivers_close() {
64
 
65
        FB26_close(FRAME_BUFFER_DEVICE);
66
 
67
        KEYB26_close();
68
        INPUT26_close();
69
 
70
        return 0;
71
 
72
}
73
 
74
int device_drivers_init() {
75
 
76
        int res;
77
 
78
        KEYB_PARMS kparms = BASE_KEYB;                                                                                                              
79
        LINUXC26_register_module();
80
 
81
        PCI26_init();
82
 
83
        INPUT26_init();
84
 
85
        keyb_def_ctrlC(kparms, NULL);
86
 
87
        KEYB26_init(&kparms);
88
 
89
        FB26_init();                                                                                                                            
90
        res = FB26_open(FRAME_BUFFER_DEVICE);
91
        if (res) {
92
                cprintf("Error: Cannot open graphical mode\n");
93
                KEYB26_close();
94
                INPUT26_close();
95
                sys_end();
96
        }                                                                                            
97
        FB26_use_grx(FRAME_BUFFER_DEVICE);                                                                                
98
        FB26_setmode(FRAME_BUFFER_DEVICE,"640x480-16");
99
 
100
        return 0;
101
 
102
}
103
 
104
TASK shutdown_task_body(void *arg) {
105
 
106
        device_drivers_close();
107
 
108
        sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
109
 
110
        sys_end();
111
 
112
        return NULL;
113
 
114
}
115
 
116
void set_shutdown_task() {
117
 
118
        NRT_TASK_MODEL nrt;
119
 
120
        nrt_task_default_model(nrt);
121
 
122
        shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
123
        if (shutdown_task_PID == NIL) {
124
                sys_shutdown_message("Error: Cannot create shutdown task\n");
125
                sys_end();
126
        }
127
 
128
}
129
 
1085 pj 130
static void version( void )
131
{
1158 pj 132
  cprintf( "S.Ha.R.K. Jumpball Demo 1.0\n" );
133
  cprintf( "---------------------------\n" );
1085 pj 134
  cprintf( "by Paolo Gai 1999-2001\n"   );
135
  cprintf( "   <pj@sssup.it>\n"         );
1158 pj 136
  cprintf( "---------------------------\n" );
1085 pj 137
}
138
 
139
int myrand(int x)
140
{
141
  return rand()%x;
142
}
143
 
144
void reverse(char s[])
145
{
146
  int c, i, j;
147
 
148
  for (i = 0, j = strlen(s)-1; i<j; i++, j--)
149
  {
150
    c = s[i];
151
    s[i] = s[j];
152
    s[j] = c;
153
  }
154
}
155
 
156
char * itoa(int n, char *s)
157
{
158
  int i, sign;
159
 
160
  if ((sign = n) < 0)
161
    n = -n;
162
 
163
  i = 0;
164
 
165
  do
166
  {
167
    s[i++] = n % 10 + '0';
168
  } while ((n /= 10) > 0);
169
 
170
  if (sign < 0)
171
    s[i++] = '-';
172
 
173
  s[i] = 0;
174
 
175
  reverse(s);
176
 
177
  return s;
178
}
179
 
180
 
181
void scenario()
182
{
1158 pj 183
  grx_text("S.Ha.R.K. Jumpball Demo 1.0", 0, 0, rgb16(0,255,0), black );
184
  grx_text("  by Paolo Gai 1999-2001"   , 0, 8, rgb16(0,255,0), black );
185
  grx_text("       pj@sssup.it"         , 0,16, rgb16(0,255,0), black );
1085 pj 186
 
187
  grx_text("Ctrl-C, Ctrr-C, Enter: exit"             ,320, 0, gray, black );
1158 pj 188
  grx_text("Alt-C                : void statistics"  ,320, 8, gray, black );
1085 pj 189
  grx_text("Space                : create noise ball",320,16, gray, black );
190
  grx_text("Backspace            : kill noise balls" ,320,24, gray, black );
191
 
192
 
193
  #ifdef JET_ON
194
  scenario_jetcontrol();
195
  #endif
196
 
197
  #ifdef BALL_ON
198
  scenario_ball();
199
  #endif
200
}
201
 
202
void endfun(KEY_EVT *k)
203
{
1379 giacomo 204
  task_activate(shutdown_task_PID);
1085 pj 205
}
206
 
207
void zerofun(KEY_EVT *k)
208
{
209
  int i;
210
  for (i=0; i<MAX_PROC; i++) jet_delstat(i);
211
}
212
 
213
int main(int argc, char **argv)
214
{
215
 
216
    KEY_EVT k;
217
 
1379 giacomo 218
    version();
219
 
220
    set_shutdown_task();
221
 
222
    device_drivers_init();
223
 
1085 pj 224
    srand(4);
225
 
226
    k.flag = CNTR_BIT;
227
    k.scan = KEY_C;
228
    k.ascii = 'c';
1379 giacomo 229
    k.status = KEY_PRESSED;
230
    keyb_hook(k,endfun,FALSE);
1085 pj 231
    k.flag = CNTL_BIT;
232
    k.scan = KEY_C;
233
    k.ascii = 'c';
1379 giacomo 234
    k.status = KEY_PRESSED;
235
    keyb_hook(k,endfun,FALSE);
1085 pj 236
    k.flag = ALTL_BIT;
237
    k.scan = KEY_C;
238
    k.ascii = 'c';
1379 giacomo 239
    k.status = KEY_PRESSED;
240
    keyb_hook(k,zerofun,FALSE);
1085 pj 241
    k.flag = 0;
242
    k.scan = KEY_ENT;
243
    k.ascii = 13;
1379 giacomo 244
    k.status = KEY_PRESSED;
245
    keyb_hook(k,endfun,FALSE);
1085 pj 246
 
1380 giacomo 247
    /* init the graphic mutex */
248
    app_mutex_init(&mutex);
249
 
1085 pj 250
    /* useful colors ... */
251
    white = rgb16(255,255,255);
252
    black = rgb16(0,0,0);
253
    red   = rgb16(255,0,0);
254
    gray  = rgb16(128,128,128);
255
 
256
    scenario();
257
 
258
    #ifdef JET_ON
259
    init_jetcontrol();
260
    #endif
261
 
262
    #ifdef BALL_ON
263
    init_ball();
264
    #endif
265
 
266
    group_activate(1);
267
 
268
    return 0;
269
}
270
 
271