Subversion Repositories shark

Rev

Rev 1158 | Rev 1380 | 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
 ------------
1379 giacomo 21
 CVS :        $Id: demo.c,v 1.5 2004-04-17 17:16:46 giacomo Exp $
1085 pj 22
 
23
 File:        $File$
1379 giacomo 24
 Revision:    $Revision: 1.5 $
25
 Last update: $Date: 2004-04-17 17:16:46 $
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
 
1379 giacomo 61
int device_drivers_close() {
62
 
63
        FB26_close(FRAME_BUFFER_DEVICE);
64
 
65
        KEYB26_close();
66
        INPUT26_close();
67
 
68
        return 0;
69
 
70
}
71
 
72
int device_drivers_init() {
73
 
74
        int res;
75
 
76
        KEYB_PARMS kparms = BASE_KEYB;                                                                                                              
77
        LINUXC26_register_module();
78
 
79
        PCI26_init();
80
 
81
        INPUT26_init();
82
 
83
        keyb_def_ctrlC(kparms, NULL);
84
 
85
        KEYB26_init(&kparms);
86
 
87
        FB26_init();                                                                                                                            
88
        res = FB26_open(FRAME_BUFFER_DEVICE);
89
        if (res) {
90
                cprintf("Error: Cannot open graphical mode\n");
91
                KEYB26_close();
92
                INPUT26_close();
93
                sys_end();
94
        }                                                                                            
95
        FB26_use_grx(FRAME_BUFFER_DEVICE);                                                                                
96
        FB26_setmode(FRAME_BUFFER_DEVICE,"640x480-16");
97
 
98
        return 0;
99
 
100
}
101
 
102
TASK shutdown_task_body(void *arg) {
103
 
104
        device_drivers_close();
105
 
106
        sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
107
 
108
        sys_end();
109
 
110
        return NULL;
111
 
112
}
113
 
114
void set_shutdown_task() {
115
 
116
        NRT_TASK_MODEL nrt;
117
 
118
        nrt_task_default_model(nrt);
119
 
120
        shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
121
        if (shutdown_task_PID == NIL) {
122
                sys_shutdown_message("Error: Cannot create shutdown task\n");
123
                sys_end();
124
        }
125
 
126
}
127
 
1085 pj 128
static void version( void )
129
{
1158 pj 130
  cprintf( "S.Ha.R.K. Jumpball Demo 1.0\n" );
131
  cprintf( "---------------------------\n" );
1085 pj 132
  cprintf( "by Paolo Gai 1999-2001\n"   );
133
  cprintf( "   <pj@sssup.it>\n"         );
1158 pj 134
  cprintf( "---------------------------\n" );
1085 pj 135
}
136
 
137
int myrand(int x)
138
{
139
  return rand()%x;
140
}
141
 
142
void reverse(char s[])
143
{
144
  int c, i, j;
145
 
146
  for (i = 0, j = strlen(s)-1; i<j; i++, j--)
147
  {
148
    c = s[i];
149
    s[i] = s[j];
150
    s[j] = c;
151
  }
152
}
153
 
154
char * itoa(int n, char *s)
155
{
156
  int i, sign;
157
 
158
  if ((sign = n) < 0)
159
    n = -n;
160
 
161
  i = 0;
162
 
163
  do
164
  {
165
    s[i++] = n % 10 + '0';
166
  } while ((n /= 10) > 0);
167
 
168
  if (sign < 0)
169
    s[i++] = '-';
170
 
171
  s[i] = 0;
172
 
173
  reverse(s);
174
 
175
  return s;
176
}
177
 
178
 
179
void scenario()
180
{
1158 pj 181
  grx_text("S.Ha.R.K. Jumpball Demo 1.0", 0, 0, rgb16(0,255,0), black );
182
  grx_text("  by Paolo Gai 1999-2001"   , 0, 8, rgb16(0,255,0), black );
183
  grx_text("       pj@sssup.it"         , 0,16, rgb16(0,255,0), black );
1085 pj 184
 
185
  grx_text("Ctrl-C, Ctrr-C, Enter: exit"             ,320, 0, gray, black );
1158 pj 186
  grx_text("Alt-C                : void statistics"  ,320, 8, gray, black );
1085 pj 187
  grx_text("Space                : create noise ball",320,16, gray, black );
188
  grx_text("Backspace            : kill noise balls" ,320,24, gray, black );
189
 
190
 
191
  #ifdef JET_ON
192
  scenario_jetcontrol();
193
  #endif
194
 
195
  #ifdef BALL_ON
196
  scenario_ball();
197
  #endif
198
}
199
 
200
void endfun(KEY_EVT *k)
201
{
1379 giacomo 202
  task_activate(shutdown_task_PID);
1085 pj 203
}
204
 
205
void zerofun(KEY_EVT *k)
206
{
207
  int i;
208
  for (i=0; i<MAX_PROC; i++) jet_delstat(i);
209
}
210
 
211
int main(int argc, char **argv)
212
{
213
 
214
    KEY_EVT k;
215
 
1379 giacomo 216
    version();
217
 
218
    set_shutdown_task();
219
 
220
    device_drivers_init();
221
 
1085 pj 222
    srand(4);
223
 
224
    k.flag = CNTR_BIT;
225
    k.scan = KEY_C;
226
    k.ascii = 'c';
1379 giacomo 227
    k.status = KEY_PRESSED;
228
    keyb_hook(k,endfun,FALSE);
1085 pj 229
    k.flag = CNTL_BIT;
230
    k.scan = KEY_C;
231
    k.ascii = 'c';
1379 giacomo 232
    k.status = KEY_PRESSED;
233
    keyb_hook(k,endfun,FALSE);
1085 pj 234
    k.flag = ALTL_BIT;
235
    k.scan = KEY_C;
236
    k.ascii = 'c';
1379 giacomo 237
    k.status = KEY_PRESSED;
238
    keyb_hook(k,zerofun,FALSE);
1085 pj 239
    k.flag = 0;
240
    k.scan = KEY_ENT;
241
    k.ascii = 13;
1379 giacomo 242
    k.status = KEY_PRESSED;
243
    keyb_hook(k,endfun,FALSE);
1085 pj 244
 
245
    /* useful colors ... */
246
    white = rgb16(255,255,255);
247
    black = rgb16(0,0,0);
248
    red   = rgb16(255,0,0);
249
    gray  = rgb16(128,128,128);
250
 
251
    scenario();
252
 
253
    #ifdef JET_ON
254
    init_jetcontrol();
255
    #endif
256
 
257
    #ifdef BALL_ON
258
    init_ball();
259
    #endif
260
 
261
    group_activate(1);
262
 
263
    return 0;
264
}
265
 
266