Subversion Repositories shark

Rev

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

Rev Author Line No. Line
1091 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
 *   Massimiliano Giorgi <massy@gandalf.sssup.it>
11
 *   Luca Abeni          <luca@gandalf.sssup.it>
12
 *   (see the web pages for full authors list)
13
 *
14
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
15
 *
16
 * http://www.sssup.it
17
 * http://retis.sssup.it
18
 * http://shark.sssup.it
19
 */
20
 
1591 tullio 21
/* CVS :        $Id: bca.c,v 1.9 2006-07-03 15:29:11 tullio Exp $ */
1091 pj 22
 
23
/*
24
 * Copyright (C) 2000 Fabio Calabrese <fabiocalabrese77@yahoo.it>
25
 *
26
 * This program is free software; you can redistribute it and/or modify
27
 * it under the terms of the GNU General Public License as published by
28
 * the Free Software Foundation; either version 2 of the License, or
29
 * (at your option) any later version.
30
 *
31
 * This program is distributed in the hope that it will be useful,
32
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
34
 * GNU General Public License for more details.
35
 *
36
 * You should have received a copy of the GNU General Public License
37
 * along with this program; if not, write to the Free Software
38
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
39
 *
40
 */
41
 
42
/****************************************************
43
 *                                                  *
44
 *  file:        bca.c                              *
45
 *  header file: bca.h                              *
46
 *  data:        15/09/2002                         *
47
 *  creato da:   Fabio CALABRESE                    *
48
 *                                                  *
49
 ******************************************************
50
 *                                                    *
51
 *  descrizione: e' il file in cui  descritto il task*
52
 *               main del programma S.Ha.R.K.         *
53
 *               "(B)ase(C)ontr(A)rea".               *
54
 *               Il codice del programma comprende    *
55
 *               anche l'implementazione di altri task*
56
 *               distribuiti nei seguenti file che    *
57
 *               quindi sono inclusi:                 *
58
 *                dummy.c                             *
59
 *                control.c                           *
60
 *                aereo.c                             *
61
 *                cannone.c                           *
62
 *                missile.c                           *
63
 *                esplo.c                             *
64
 *               Inoltre  incluso anche il file:     *
65
 *                scenario.c                          *
66
 *               che descrive come disegnare lo       *
67
 *               scenario grafico iniziale            *
68
 *                                                    *
69
 ******************************************************/
70
 
71
 
72
// *** Librerie S.Ha.R.K ***
73
#include <kernel/kern.h>
74
#include <ll/i386/cons.h>
1448 giacomo 75
 
76
#include <drivers/shark_fb26.h>
77
#include <drivers/shark_keyb26.h>
78
 
1591 tullio 79
// *** Standard C library ***
1091 pj 80
#include <stdlib.h>
1591 tullio 81
 
82
// *** FAB library ***
1091 pj 83
#include "fab_lib/fab_msg.h"
84
#include "fab_lib/fab_show.h"
85
#include "fab_lib/fab_tool.h"
86
#include "fab_lib/fab_grx.h"
1591 tullio 87
 
88
// *** BCA library ***
1091 pj 89
#include "bca.h"
90
 
1591 tullio 91
void end_fun(KEY_EVT* k) {
92
        sys_shutdown_message("Ending...\n");
93
        exit(0);
1091 pj 94
}
1591 tullio 95
 
96
void inc_planes(KEY_EVT* k) {
97
        if (aereo_count < AEREO_N_MAX) aereo_count++;
1091 pj 98
}
1591 tullio 99
 
100
void dec_planes(KEY_EVT* k) {
101
        if (aereo_count > AEREO_N_MIN) aereo_count--;
1091 pj 102
}
1591 tullio 103
 
104
void inc_cannon(KEY_EVT* k) {
105
        if (cannone_count < CANNONE_N_MAX) cannone_count++;
1091 pj 106
}
1591 tullio 107
 
108
void dec_cannon(KEY_EVT* k) {
109
        if (cannone_count > CANNONE_N_MIN) cannone_count--;
1091 pj 110
}
111
 
1591 tullio 112
int main(int argc, char **argv) {
113
        PID pid_dummy_radar, pid_aereo_creator, pid_cannone_creator, pid_control;
1091 pj 114
 
1591 tullio 115
        KEY_EVT k;
1091 pj 116
 
1591 tullio 117
        k.flag = CNTL_BIT;
118
        k.scan = KEY_C;
119
        k.ascii = 'c';
120
        k.status = KEY_PRESSED;
121
        keyb_hook(k, end_fun, FALSE);
1589 tullio 122
 
1591 tullio 123
        k.flag = CNTR_BIT;
124
        k.status = KEY_PRESSED;
125
        keyb_hook(k, end_fun, FALSE);
126
 
127
        k.flag  = 0;
128
        k.scan  = KEY_1;
129
        k.ascii = '1';
130
        k.status = KEY_PRESSED;
131
        keyb_hook(k, inc_planes, FALSE);
132
 
133
        k.flag  = 0;
134
        k.scan  = KEY_2;
135
        k.ascii = '2';
136
        k.status = KEY_PRESSED;
137
        keyb_hook(k, dec_planes, FALSE);
138
 
139
        k.flag  = 0;
140
        k.scan  = KEY_3;
141
        k.ascii = '3';
142
        k.status = KEY_PRESSED;
143
        keyb_hook(k, inc_cannon, FALSE);
144
 
145
        k.flag  = 0;
146
        k.scan  = KEY_4;
147
        k.ascii = '4';
148
        k.status = KEY_PRESSED;
149
        keyb_hook(k, dec_cannon, FALSE);
1091 pj 150
 
1591 tullio 151
        /* inizializza il mutex grafico */
152
        app_mutex_init(&grx_mutex);
1091 pj 153
 
1591 tullio 154
        scenario();
1091 pj 155
 
1591 tullio 156
        //---init---
157
        srand(sys_gettime(NULL));
158
        aereo_count   = AEREO_N_MIN;
159
        cannone_count = CANNONE_N_MIN;
1091 pj 160
 
1591 tullio 161
        pid_dummy_radar = crea_soft_dummy_radar();
162
        if (pid_dummy_radar == -1) {
163
                sys_shutdown_message("bca.c(main): could not create task <dummy_radar>");
164
                exit(1);
165
        }
166
        task_activate(pid_dummy_radar);
1091 pj 167
 
1591 tullio 168
        pid_aereo_creator = crea_soft_aereo_creator();
169
        if (pid_aereo_creator == -1) {
170
                sys_shutdown_message("bca.c(main): could not create task <aereo_creator>");
171
                exit(1);
172
        }
173
        task_activate(pid_aereo_creator);
1091 pj 174
 
1591 tullio 175
        pid_cannone_creator = crea_soft_cannone_creator();
176
        if (pid_cannone_creator == -1) {
177
                sys_shutdown_message("bca.c(main): could not create task <cannone_creator>");
178
                exit(1);
179
        }
180
        task_activate(pid_cannone_creator);
1091 pj 181
 
1591 tullio 182
        pid_control = crea_soft_control();
183
        if (pid_control == -1) {
184
                sys_shutdown_message("bca.c(main): could not create task <control>");
185
                exit(1);
186
        }
187
        task_activate(pid_control);
188
        //----------
1448 giacomo 189
 
1591 tullio 190
        return 0;
1091 pj 191
}
192
 
193