Subversion Repositories shark

Rev

Rev 1684 | 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
 ------------
1550 pj 21
 CVS :        $Id: demo.c,v 1.8 2005-01-08 14:35:17 pj Exp $
1085 pj 22
 
23
 File:        $File$
1550 pj 24
 Revision:    $Revision: 1.8 $
25
 Last update: $Date: 2005-01-08 14:35:17 $
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
 
1686 fabio 53
mutex_t mutex;
54
 
1085 pj 55
/* useful colors... */
56
int white;
57
int black;
58
int red;
59
int gray;
60
 
1380 giacomo 61
void app_mutex_init(mutex_t *m);
62
 
1085 pj 63
static void version( void )
64
{
1158 pj 65
  cprintf( "S.Ha.R.K. Jumpball Demo 1.0\n" );
66
  cprintf( "---------------------------\n" );
1085 pj 67
  cprintf( "by Paolo Gai 1999-2001\n"   );
68
  cprintf( "   <pj@sssup.it>\n"         );
1158 pj 69
  cprintf( "---------------------------\n" );
1085 pj 70
}
71
 
72
int myrand(int x)
73
{
74
  return rand()%x;
75
}
76
 
77
void reverse(char s[])
78
{
79
  int c, i, j;
80
 
81
  for (i = 0, j = strlen(s)-1; i<j; i++, j--)
82
  {
83
    c = s[i];
84
    s[i] = s[j];
85
    s[j] = c;
86
  }
87
}
88
 
89
char * itoa(int n, char *s)
90
{
91
  int i, sign;
92
 
93
  if ((sign = n) < 0)
94
    n = -n;
95
 
96
  i = 0;
97
 
98
  do
99
  {
100
    s[i++] = n % 10 + '0';
101
  } while ((n /= 10) > 0);
102
 
103
  if (sign < 0)
104
    s[i++] = '-';
105
 
106
  s[i] = 0;
107
 
108
  reverse(s);
109
 
110
  return s;
111
}
112
 
113
 
114
void scenario()
115
{
1158 pj 116
  grx_text("S.Ha.R.K. Jumpball Demo 1.0", 0, 0, rgb16(0,255,0), black );
117
  grx_text("  by Paolo Gai 1999-2001"   , 0, 8, rgb16(0,255,0), black );
118
  grx_text("       pj@sssup.it"         , 0,16, rgb16(0,255,0), black );
1085 pj 119
 
120
  grx_text("Ctrl-C, Ctrr-C, Enter: exit"             ,320, 0, gray, black );
1158 pj 121
  grx_text("Alt-C                : void statistics"  ,320, 8, gray, black );
1085 pj 122
  grx_text("Space                : create noise ball",320,16, gray, black );
123
  grx_text("Backspace            : kill noise balls" ,320,24, gray, black );
124
 
125
 
126
  #ifdef JET_ON
127
  scenario_jetcontrol();
128
  #endif
129
 
130
  #ifdef BALL_ON
131
  scenario_ball();
132
  #endif
133
}
134
 
135
void endfun(KEY_EVT *k)
136
{
1550 pj 137
  exit(0);
1085 pj 138
}
139
 
140
void zerofun(KEY_EVT *k)
141
{
142
  int i;
143
  for (i=0; i<MAX_PROC; i++) jet_delstat(i);
144
}
145
 
146
int main(int argc, char **argv)
147
{
148
 
149
    KEY_EVT k;
150
 
1379 giacomo 151
    version();
152
 
1085 pj 153
    srand(4);
154
 
155
    k.flag = CNTR_BIT;
156
    k.scan = KEY_C;
157
    k.ascii = 'c';
1379 giacomo 158
    k.status = KEY_PRESSED;
159
    keyb_hook(k,endfun,FALSE);
1085 pj 160
    k.flag = CNTL_BIT;
161
    k.scan = KEY_C;
162
    k.ascii = 'c';
1379 giacomo 163
    k.status = KEY_PRESSED;
164
    keyb_hook(k,endfun,FALSE);
1085 pj 165
    k.flag = ALTL_BIT;
166
    k.scan = KEY_C;
167
    k.ascii = 'c';
1379 giacomo 168
    k.status = KEY_PRESSED;
169
    keyb_hook(k,zerofun,FALSE);
1085 pj 170
    k.flag = 0;
171
    k.scan = KEY_ENT;
172
    k.ascii = 13;
1379 giacomo 173
    k.status = KEY_PRESSED;
174
    keyb_hook(k,endfun,FALSE);
1085 pj 175
 
1380 giacomo 176
    /* init the graphic mutex */
177
    app_mutex_init(&mutex);
178
 
1085 pj 179
    /* useful colors ... */
180
    white = rgb16(255,255,255);
181
    black = rgb16(0,0,0);
182
    red   = rgb16(255,0,0);
183
    gray  = rgb16(128,128,128);
184
 
185
    scenario();
186
 
187
    #ifdef JET_ON
188
    init_jetcontrol();
189
    #endif
190
 
191
    #ifdef BALL_ON
192
    init_ball();
193
    #endif
194
 
195
    group_activate(1);
196
 
197
    return 0;
198
}
199
 
200