Rev 1085 |
Rev 1123 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
/**
------------
CVS : $Id: demo.c,v 1.1.1.1 2002-09-02 09:37:41 pj Exp $
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:41 $
------------
**/
/*
* Copyright (C) 2000 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "demo.h"
#include <kernel/func.h>
#include <string.h>
#include <stdlib.h>
#include <drivers/keyb.h>
#include <drivers/glib.h>
/* graphic mutex... */
mutex_t mutex
;
/* useful colors... */
int white
;
int black
;
int red
;
int gray
;
void app_mutex_init
(mutex_t
*m
);
static void version
( void )
{
cprintf
( "S.Ha.R.K. Pavia Demo 1.0\n" );
cprintf
( "------------------------\n" );
cprintf
( "by Paolo Gai 1999-2001\n" );
cprintf
( " <pj@sssup.it>\n" );
cprintf
( "------------------------\n" );
}
int myrand
(int x
)
{
return rand()%x
;
}
void reverse
(char s
[])
{
int c
, i
, j
;
for (i
= 0, j
= strlen(s
)-1; i
<j
; i
++, j
--)
{
c
= s
[i
];
s
[i
] = s
[j
];
s
[j
] = c
;
}
}
char * itoa(int n
, char *s
)
{
int i
, sign
;
if ((sign
= n
) < 0)
n
= -n
;
i
= 0;
do
{
s
[i
++] = n
% 10 + '0';
} while ((n
/= 10) > 0);
if (sign
< 0)
s
[i
++] = '-';
s
[i
] = 0;
reverse
(s
);
return s
;
}
void scenario
()
{
grx_text
("S.Ha.R.K. Pavia Demo 1.0", 0, 0, rgb16
(0,255,0), black
);
grx_text
("by Paolo Gai 1999-2001" , 0, 8, rgb16
(0,255,0), black
);
grx_text
(" pj@sssup.it" , 0,16, rgb16
(0,255,0), black
);
grx_text
("Ctrl-C, Ctrr-C, Enter: exit" ,320, 0, gray
, black
);
grx_text
("Alt-C : void stat." ,320, 8, gray
, black
);
grx_text
("Space : create noise ball",320,16, gray
, black
);
grx_text
("Backspace : kill noise balls" ,320,24, gray
, black
);
#ifdef JET_ON
scenario_jetcontrol
();
#endif
#ifdef BALL_ON
scenario_ball
();
#endif
}
void demo_exc_handler
(int signo
, siginfo_t
*info
, void *extra
)
{
struct timespec t
;
grx_close
();
/* Default action for an kern exception is */
kern_cli
();
ll_gettime
(TIME_EXACT
, &t
),
kern_printf
("\nS.Ha.R.K. Exception raised!!!"
"\nTime (s:ns) :%d:%d"
"\nException number:%d"
"\nPID :%d\n",
t.
tv_sec, t.
tv_nsec, info
->si_value.
sival_int,
info
->si_task
);
sys_end
();
}
void my_close
(void *arg
)
{
grx_close
();
kern_printf
("my_close\n");
}
void endfun
(KEY_EVT
*k
)
{
cprintf
("Ctrl-Brk pressed! Ending...\n");
sys_end
();
}
void zerofun
(KEY_EVT
*k
)
{
int i
;
for (i
=0; i
<MAX_PROC
; i
++) jet_delstat
(i
);
}
void printeventqueue
(void *arg
)
{
struct event
*p
;
extern struct event
*firstevent
;
kern_cli
();
grx_close
();
kern_cli
();
for (p
= firstevent
; p
!= NULL
; p
= p
->next
) {
kern_printf
("par:%d time:%d.%d p:%d handler:%d\n",
p
->par
, p
->time.
tv_sec, p
->time.
tv_nsec/1000, p
, p
->handler
);
}
kern_sti
();
}
int main
(int argc
, char **argv
)
{
int modenum
;
KEY_EVT k
;
srand(4);
version
();
keyb_set_map
(itaMap
);
k.
flag = CNTR_BIT
;
k.
scan = KEY_C
;
k.
ascii = 'c';
keyb_hook
(k
,endfun
);
k.
flag = CNTL_BIT
;
k.
scan = KEY_C
;
k.
ascii = 'c';
keyb_hook
(k
,endfun
);
k.
flag = ALTL_BIT
;
k.
scan = KEY_C
;
k.
ascii = 'c';
keyb_hook
(k
,zerofun
);
k.
flag = 0;
k.
scan = KEY_ENT
;
k.
ascii = 13;
keyb_hook
(k
,endfun
);
set_exchandler_grx
();
sys_atrunlevel
(my_close
, NULL
, RUNLEVEL_BEFORE_EXIT
);
grx_init
();
modenum
= grx_getmode
(640, 480, 16);
grx_setmode
(modenum
);
/* init the graphic mutex */
app_mutex_init
(&mutex
);
/* useful colors ... */
white
= rgb16
(255,255,255);
black
= rgb16
(0,0,0);
red
= rgb16
(255,0,0);
gray
= rgb16
(128,128,128);
scenario
();
#ifdef JET_ON
init_jetcontrol
();
#endif
#ifdef BALL_ON
init_ball
();
#endif
group_activate
(1);
return 0;
}