Go to most recent revision | Details | 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 | ------------ |
||
21 | CVS : $Id: demo.c,v 1.1.1.1 2002-09-02 09:37:41 pj Exp $ |
||
22 | |||
23 | File: $File$ |
||
24 | Revision: $Revision: 1.1.1.1 $ |
||
25 | Last update: $Date: 2002-09-02 09:37:41 $ |
||
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 "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 | { |
||
68 | cprintf( "S.Ha.R.K. Pavia Demo 1.0\n" ); |
||
69 | cprintf( "------------------------\n" ); |
||
70 | cprintf( "by Paolo Gai 1999-2001\n" ); |
||
71 | cprintf( " <pj@sssup.it>\n" ); |
||
72 | cprintf( "------------------------\n" ); |
||
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 | { |
||
119 | grx_text("S.Ha.R.K. Pavia 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 ); |
||
122 | |||
123 | grx_text("Ctrl-C, Ctrr-C, Enter: exit" ,320, 0, gray, black ); |
||
124 | grx_text("Alt-C : void stat." ,320, 8, gray, black ); |
||
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 | |||
138 | |||
139 | void demo_exc_handler(int signo, siginfo_t *info, void *extra) |
||
140 | { |
||
141 | struct timespec t; |
||
142 | |||
143 | grx_close(); |
||
144 | |||
145 | /* Default action for an kern exception is */ |
||
146 | kern_cli(); |
||
147 | ll_gettime(TIME_EXACT, &t), |
||
148 | kern_printf("\nS.Ha.R.K. Exception raised!!!" |
||
149 | "\nTime (s:ns) :%d:%d" |
||
150 | "\nException number:%d" |
||
151 | "\nPID :%d\n", |
||
152 | t.tv_sec, t.tv_nsec, info->si_value.sival_int, |
||
153 | info->si_task); |
||
154 | sys_end(); |
||
155 | } |
||
156 | |||
157 | void my_close(void *arg) |
||
158 | { |
||
159 | grx_close(); |
||
160 | kern_printf("my_close\n"); |
||
161 | } |
||
162 | |||
163 | |||
164 | void endfun(KEY_EVT *k) |
||
165 | { |
||
166 | cprintf("Ctrl-Brk pressed! Ending...\n"); |
||
167 | sys_end(); |
||
168 | } |
||
169 | |||
170 | void zerofun(KEY_EVT *k) |
||
171 | { |
||
172 | int i; |
||
173 | for (i=0; i<MAX_PROC; i++) jet_delstat(i); |
||
174 | } |
||
175 | |||
176 | void printeventqueue(void *arg) |
||
177 | { |
||
178 | struct event *p; |
||
179 | extern struct event *firstevent; |
||
180 | |||
181 | kern_cli(); |
||
182 | grx_close(); |
||
183 | kern_cli(); |
||
184 | for (p = firstevent; p != NULL; p = p->next) { |
||
185 | kern_printf("par:%d time:%d.%d p:%d handler:%d\n", |
||
186 | p->par, p->time.tv_sec, p->time.tv_nsec/1000, p, p->handler); |
||
187 | } |
||
188 | kern_sti(); |
||
189 | } |
||
190 | |||
191 | int main(int argc, char **argv) |
||
192 | { |
||
193 | int modenum; |
||
194 | |||
195 | KEY_EVT k; |
||
196 | |||
197 | srand(4); |
||
198 | |||
199 | version(); |
||
200 | |||
201 | keyb_set_map(itaMap); |
||
202 | k.flag = CNTR_BIT; |
||
203 | k.scan = KEY_C; |
||
204 | k.ascii = 'c'; |
||
205 | keyb_hook(k,endfun); |
||
206 | k.flag = CNTL_BIT; |
||
207 | k.scan = KEY_C; |
||
208 | k.ascii = 'c'; |
||
209 | keyb_hook(k,endfun); |
||
210 | k.flag = ALTL_BIT; |
||
211 | k.scan = KEY_C; |
||
212 | k.ascii = 'c'; |
||
213 | keyb_hook(k,zerofun); |
||
214 | k.flag = 0; |
||
215 | k.scan = KEY_ENT; |
||
216 | k.ascii = 13; |
||
217 | keyb_hook(k,endfun); |
||
218 | |||
219 | set_exchandler_grx(); |
||
220 | sys_atrunlevel(my_close, NULL, RUNLEVEL_BEFORE_EXIT); |
||
221 | |||
222 | |||
223 | grx_init(); |
||
224 | modenum = grx_getmode(640, 480, 16); |
||
225 | |||
226 | grx_setmode(modenum); |
||
227 | |||
228 | /* init the graphic mutex */ |
||
229 | app_mutex_init(&mutex); |
||
230 | |||
231 | /* useful colors ... */ |
||
232 | white = rgb16(255,255,255); |
||
233 | black = rgb16(0,0,0); |
||
234 | red = rgb16(255,0,0); |
||
235 | gray = rgb16(128,128,128); |
||
236 | |||
237 | scenario(); |
||
238 | |||
239 | #ifdef JET_ON |
||
240 | init_jetcontrol(); |
||
241 | #endif |
||
242 | |||
243 | #ifdef BALL_ON |
||
244 | init_ball(); |
||
245 | #endif |
||
246 | |||
247 | group_activate(1); |
||
248 | |||
249 | return 0; |
||
250 | } |
||
251 | |||
252 |