Rev 1158 |
Rev 1380 |
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.5 2004-04-17 17:16:46 giacomo Exp $
File: $File$
Revision: $Revision: 1.5 $
Last update: $Date: 2004-04-17 17:16:46 $
------------
**/
/*
* Copyright (C) 2000-2003 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>
/* useful colors... */
int white
;
int black
;
int red
;
int gray
;
PID shutdown_task_PID
= -1;
int device_drivers_close
() {
FB26_close
(FRAME_BUFFER_DEVICE
);
KEYB26_close
();
INPUT26_close
();
return 0;
}
int device_drivers_init
() {
int res
;
KEYB_PARMS kparms
= BASE_KEYB
;
LINUXC26_register_module
();
PCI26_init
();
INPUT26_init
();
keyb_def_ctrlC
(kparms
, NULL
);
KEYB26_init
(&kparms
);
FB26_init
();
res
= FB26_open
(FRAME_BUFFER_DEVICE
);
if (res
) {
cprintf
("Error: Cannot open graphical mode\n");
KEYB26_close
();
INPUT26_close
();
sys_end
();
}
FB26_use_grx
(FRAME_BUFFER_DEVICE
);
FB26_setmode
(FRAME_BUFFER_DEVICE
,"640x480-16");
return 0;
}
TASK shutdown_task_body
(void *arg
) {
device_drivers_close
();
sys_shutdown_message
("-- S.Ha.R.K. Closed --\n");
sys_end
();
return NULL
;
}
void set_shutdown_task
() {
NRT_TASK_MODEL nrt
;
nrt_task_default_model
(nrt
);
shutdown_task_PID
= task_create
("Shutdown Task",shutdown_task_body
,&nrt
,NULL
);
if (shutdown_task_PID
== NIL
) {
sys_shutdown_message
("Error: Cannot create shutdown task\n");
sys_end
();
}
}
static void version
( void )
{
cprintf
( "S.Ha.R.K. Jumpball 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. Jumpball 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 statistics" ,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 endfun
(KEY_EVT
*k
)
{
task_activate
(shutdown_task_PID
);
}
void zerofun
(KEY_EVT
*k
)
{
int i
;
for (i
=0; i
<MAX_PROC
; i
++) jet_delstat
(i
);
}
int main
(int argc
, char **argv
)
{
KEY_EVT k
;
version
();
set_shutdown_task
();
device_drivers_init
();
srand(4);
k.
flag = CNTR_BIT
;
k.
scan = KEY_C
;
k.
ascii = 'c';
k.
status = KEY_PRESSED
;
keyb_hook
(k
,endfun
,FALSE
);
k.
flag = CNTL_BIT
;
k.
scan = KEY_C
;
k.
ascii = 'c';
k.
status = KEY_PRESSED
;
keyb_hook
(k
,endfun
,FALSE
);
k.
flag = ALTL_BIT
;
k.
scan = KEY_C
;
k.
ascii = 'c';
k.
status = KEY_PRESSED
;
keyb_hook
(k
,zerofun
,FALSE
);
k.
flag = 0;
k.
scan = KEY_ENT
;
k.
ascii = 13;
k.
status = KEY_PRESSED
;
keyb_hook
(k
,endfun
,FALSE
);
/* 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;
}