Subversion Repositories shark

Rev

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

Rev Author Line No. Line
1655 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
 *   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
 ------------
21
 CVS :        $Id: biliardo.c,v 1.1.1.1 2004-05-24 18:03:47 giacomo Exp $
22
 
23
 File:        $File$
24
 Revision:    $Revision: 1.1.1.1 $
25
 Last update: $Date: 2004-05-24 18:03:47 $
26
 ------------
27
**/
28
 
29
/*
30
 * Copyright (C) 2000 Paolo Gai
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 "biliardo.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
mutex_t palmutex;
59
mutex_t delmutex;
60
//mutex_t punmutex;
61
 
62
/* useful colors... */
63
int white;
64
int black;
65
int red;
66
int gray;
67
int green;
68
int lime;
69
int brown;
70
 
71
void app_mutex_init(mutex_t *m);
72
 
73
static void version( void )
74
{
75
  cprintf( "S.Ha.R.K. San Martino Sicc. Demo 1.0\n" );
76
}
77
 
78
int myrand(int x)
79
{
80
  return rand()%x;
81
}
82
 
83
void reverse(char s[])
84
{
85
  int c, i, j;
86
 
87
  for (i = 0, j = strlen(s)-1; i<j; i++, j--)
88
  {
89
    c = s[i];
90
    s[i] = s[j];
91
    s[j] = c;
92
  }
93
}
94
 
95
char * itoa(int n, char *s)
96
{
97
  int i, sign;
98
 
99
  if ((sign = n) < 0)
100
    n = -n;
101
 
102
  i = 0;
103
 
104
  do
105
  {
106
    s[i++] = n % 10 + '0';
107
  } while ((n /= 10) > 0);
108
 
109
  if (sign < 0)
110
    s[i++] = '-';
111
 
112
  s[i] = 0;
113
 
114
  reverse(s);
115
 
116
  return s;
117
}
118
 
119
 
120
void scenario()
121
{
122
  grx_text("S.Ha.R.K. - Biliardo rivisitato", 322,2, white, black );
123
  grx_text("q          : uscita",322, 18, gray, black );
124
  grx_text("i          : inizio partita",322,28, gray, black );
125
  grx_text("Space      : scocca il colpo" ,322,38, gray, black );
126
  grx_text("a,z        : calibra la forza" ,322,48, gray, black );
127
  grx_text("Freccie    : posiziona cursore" ,322,58, gray, black );
128
  grx_text("Backspace  : nuova partita" ,322,68, gray, black );
129
 
130
 
131
  #ifdef JET_ON
132
  scenario_jetcontrol();
133
  #endif
134
 
135
  #ifdef BALL_ON
136
  scenario_ball();
137
  #endif
138
}
139
 
140
 
141
void demo_exc_handler(int signo, siginfo_t *info, void *extra)
142
{
143
  struct timespec t;
144
 
145
  grx_close();
146
 
147
  /* Default action for an kern exception is  */
148
  kern_cli();
149
  ll_gettime(TIME_EXACT, &t),
150
  kern_printf("\nS.Ha.R.K. Exception raised!!!"
151
              "\nTime (s:ns)     :%d:%d"
152
              "\nException number:%d"
153
              "\nPID             :%d\n",
154
              t.tv_sec, t.tv_nsec, info->si_value.sival_int,
155
              info->si_task);
156
  sys_end();
157
}
158
 
159
void my_close(void *arg)
160
{
161
  grx_close();
162
  kern_printf("Termine programma\n");
163
}
164
 
165
 
166
void endfun(KEY_EVT *k)
167
{
168
    cprintf("Tasto q premuto, termine programma\n");
169
    sys_end();
170
}
171
 
172
void zerofun(KEY_EVT *k)
173
{
174
  int i;
175
  for (i=0; i<MAX_PROC; i++) jet_delstat(i);
176
}
177
 
178
void printeventqueue(void *arg)
179
{
180
  struct event *p;
181
  extern struct event *firstevent;
182
 
183
  kern_cli();
184
  grx_close();
185
  kern_cli();
186
  for (p = firstevent; p != NULL; p = p->next) {
187
    kern_printf("par:%d time:%d.%d p:%d handler:%d\n",
188
        p->par, p->time.tv_sec, p->time.tv_nsec/1000, p, p->handler);
189
  }
190
  kern_sti();
191
}
192
 
193
int main(int argc, char **argv)
194
{
195
    int modenum;
196
 
197
    KEY_EVT k;
198
 
199
//  Evento di termine programma
200
  k.flag = 0;
201
  k.scan = KEY_Q;
202
  k.ascii = 'q';
203
  keyb_hook(k,endfun);
204
 
205
    //set_exchandler_grx();
206
    sys_atrunlevel(my_close, NULL, RUNLEVEL_BEFORE_EXIT);
207
 
208
    grx_init();
209
    modenum = grx_getmode(640, 480, 16);
210
 
211
    grx_setmode(modenum);
212
 
213
    /* init the graphic mutex */
214
    app_mutex_init(&mutex);
215
 
216
    /* useful colors ... */
217
    white = rgb16(255,255,255);
218
    black = rgb16(0,0,0);
219
    red = rgb16(255,0,0);
220
    gray = rgb16(128,128,128);
221
    green = rgb16(0,128,0);
222
    lime = rgb16(0,255,0);
223
    brown = rgb16(128,0,0);
224
 
225
    scenario();
226
 
227
    init_jetcontrol();
228
 
229
    app_mutex_init(&palmutex);
230
    app_mutex_init(&delmutex);
231
    init_ball();
232
 
233
    initSched();
234
 
235
    group_activate(JET_GROUP);
236
 
237
    return 0;
238
}
239
 
240