Subversion Repositories shark

Rev

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