Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 1668 → Rev 1669

/unsupported/trunk/arezzo/2004/defender/def_01.c
4,8 → 4,8
/*--------------------------------------------------------------*/
 
#include <kernel/kern.h>
#include <drivers/glib.h>
#include <drivers/keyb.h>
#include <drivers/shark_fb26.h>
#include <drivers/shark_keyb26.h>
#include <semaphore.h>
#include <stdlib.h>
#include <math.h>
19,7 → 19,6
#define ANG 30 /* angolo massimo sterzata (30) */
#define D 3 /* raggio alieno */
#define DD 6 /* diametro alieno */
#define ESC 27 /* ASCII code of ESCAPE key */
#define MAX_ALIEN 30 /* max number of aliens */
#define MAX_MISSIL 10 /* numero massimo di missili */
 
43,6 → 42,8
char command_astro ; // comandi astronave
int AstroCmdState ;
 
extern int vga16color[16];
 
struct argAlien {
int orig_x ; // coordinate iniziali
int orig_y ;
96,20 → 97,20
if (y < 8) y = 8;
 
sem_wait(&grx_mutex);
grx_line(x, y-8, x, y+8, c);
grx_line(x, y-8, x+5, y-4, c);
grx_line(x, y+8, x+5, y+4, c);
grx_line(x+5, y-4, x+10, y-4, c);
grx_line(x+5, y+4, x+10, y+4, c);
grx_line(x+10, y-4, x+15, y, c);
grx_line(x+10, y+4, x+15, y, c);
grx_line(x+15, y, x+17, y, c);
grx_box(x-3, y-6, x, y-2, c);
grx_box(x-3, y+2, x, y+6, c);
grx_box(x+8, y-3, x+10, y-1, c);
grx_box(x+8, y+1, x+10, y+3, c);
grx_line(x+3, y-4, x+8, y-1, c);
grx_line(x+3, y+4, x+8, y+1, c);
grx_line(x, y-8, x, y+8, vga16color[c]);
grx_line(x, y-8, x+5, y-4, vga16color[c]);
grx_line(x, y+8, x+5, y+4, vga16color[c]);
grx_line(x+5, y-4, x+10, y-4, vga16color[c]);
grx_line(x+5, y+4, x+10, y+4, vga16color[c]);
grx_line(x+10, y-4, x+15, y, vga16color[c]);
grx_line(x+10, y+4, x+15, y, vga16color[c]);
grx_line(x+15, y, x+17, y, vga16color[c]);
grx_box(x-3, y-6, x, y-2, vga16color[c]);
grx_box(x-3, y+2, x, y+6, vga16color[c]);
grx_box(x+8, y-3, x+10, y-1, vga16color[c]);
grx_box(x+8, y+1, x+10, y+3, vga16color[c]);
grx_line(x+3, y-4, x+8, y-1, vga16color[c]);
grx_line(x+3, y+4, x+8, y+1, vga16color[c]);
sem_post(&grx_mutex);
}
 
120,8 → 121,8
if (y < 0) y = 0;
 
sem_wait(&grx_mutex);
grx_disc(x, y, D, c); // disco
grx_line(x-DD, y, x+DD, y, c); // linea
grx_disc(x, y, D, vga16color[c]); // disco
grx_line(x-DD, y, x+DD, y, vga16color[c]); // linea
sem_post(&grx_mutex);
}
 
134,12 → 135,12
if (y < 8) y = 8;
 
sem_wait(&grx_mutex);
grx_box(x-10, y-10, x-5, y+5, c); // box
grx_box(x+5, y-10, x+10, y+5, c); // box
grx_disc(x, y, 5, c); // disco
grx_line(x, y+8, x, y-8, c); // linea
grx_box(x-10, y-10, x-5, y+5, vga16color[c]); // box
grx_box(x+5, y-10, x+10, y+5, vga16color[c]); // box
grx_disc(x, y, 5, vga16color[c]); // disco
grx_line(x, y+8, x, y-8, vga16color[c]); // linea
for (i = 0; i < d ; i++) {
grx_disc(x + (rand()%20)-10, y + (rand()%10)-5, d/2, 0);
grx_disc(x + (rand()%20)-10, y + (rand()%10)-5, d/2, vga16color[0]);
}
sem_post(&grx_mutex);
}
149,11 → 150,11
if (y < 3) y = 3;
 
sem_wait(&grx_mutex);
grx_box (x, y-1, x+6, y+1, c);
grx_line(x+1, y-3, x+1, y+3, c);
grx_line(x+1, y+3, x+3, y, c);
grx_line(x+1, y-3, x+3, y, c);
grx_disc(x+6, y, 1, c);
grx_box (x, y-1, x+6, y+1, vga16color[c]);
grx_line(x+1, y-3, x+1, y+3, vga16color[c]);
grx_line(x+1, y+3, x+3, y, vga16color[c]);
grx_line(x+1, y-3, x+3, y, vga16color[c]);
grx_disc(x+6, y, 1, vga16color[c]);
sem_post(&grx_mutex);
}
/******************************************************************/
501,11 → 502,8
 
if (pid_Alien == NIL)
{
grx_text("pid_Alien == NIL", 200, 80 , 4, 0);
grx_text("pid_Alien == NIL", 200, 80 , vga16color[4], 0);
return 0;
//grx_close();
//perror("Could not create task <Alieno>\n");
//sys_abort(1);
}
 
task_activate(pid_Alien);
827,12 → 825,12
if (stat1==0)
{
sprintf(s,"Astro->TimeMax = %d ", (int) T_Astro_Max);
grx_text(s , XMIN+350, YMENU+20, 4, 0);
grx_text(s , XMIN+350, YMENU+20, vga16color[4], vga16color[0]);
}
else
{
sprintf(s," ") ;
grx_text(s , XMIN+350, YMENU+20, 4, 0) ;
grx_text(s , XMIN+350, YMENU+20, vga16color[4], vga16color[0]) ;
}
 
 
844,12 → 842,12
if (stat2==0)
{
sprintf(s,"Madre->TimeMax = %d ", (int) T_Madre_Max);
grx_text(s , XMIN+350, YMENU+30, 4, 0);
grx_text(s , XMIN+350, YMENU+30, vga16color[4], vga16color[0]);
}
else
{
sprintf(s," ") ;
grx_text(s , XMIN+350, YMENU+30, 4, 0) ;
grx_text(s , XMIN+350, YMENU+30, vga16color[4], vga16color[0]) ;
}
 
 
857,14 → 855,7
 
}
}
/****************************************************************/
 
/* This function is called when the system exits */
void byebye(void *arg)
{
grx_close();
cprintf("Bye Bye!\n");
}
 
/****************************** MAIN ******************************/
 
908,17 → 899,12
pid_Monitor = task_create("Monitor", Monitor, &monitor, NULL);
 
if (pid_Monitor == NIL) {
grx_close();
perror("Could not create task <Monitor>\n");
sys_abort(1);
sys_shutdown_message("Could not create task <Monitor>\n");
sys_end();
}
 
task_activate(pid_Monitor); // parte immediatamente
 
 
/* Set the closing function */
sys_atrunlevel(byebye, NULL, RUNLEVEL_BEFORE_EXIT);
 
/* Semaphore Initialization */
sem_init(&grx_mutex,0,1);
sem_init(&keyb_mutex,0,1);
929,27 → 915,16
sem_init(&missile_mutex[i],0,1);
}
 
/* graphic card Initialization */
if (grx_init() < 1) {
cprintf("GRX Init\n");
sys_abort(1);
}
 
if (grx_open(640, 480, 8) < 0) {
cprintf("GRX Err\n");
sys_abort(1);
}
 
/* The scenario */
grx_line(XMIN-D-1, YMIN-D-1, XMAX+D+1, YMIN-D-1, 14);
grx_line(XMIN-D-1, YMAX+D+1, XMAX+D+1, YMAX+D+1, 14);
grx_line(XMIN-D-1, YMIN-D-1, XMAX+D+1, YMIN-D-1, vga16color[14]);
grx_line(XMIN-D-1, YMAX+D+1, XMAX+D+1, YMAX+D+1, vga16color[14]);
 
grx_text("Simulation of Defender Game", XMIN, YMENU+10, 1, 0);
grx_text("a -> crea Astronave" , XMIN, YMENU+20, 3, 0);
grx_text("m -> crea Madre alieni" , XMIN, YMENU+30, 13, 0);
grx_text("space -> sparo" , XMIN, YMENU+40, 14, 0);
grx_text("ESC exit to DOS" , XMIN, YMENU+50, 4, 0);
grx_text("SCORE " , XMIN, YMENU+60, 4, 0);
grx_text("Simulation of Defender Game", XMIN, YMENU+10, vga16color[1], 0);
grx_text("a -> crea Astronave" , XMIN, YMENU+20, vga16color[3], 0);
grx_text("m -> crea Madre alieni" , XMIN, YMENU+30, vga16color[13], 0);
grx_text("space -> sparo" , XMIN, YMENU+40, vga16color[14], 0);
grx_text("ESC exit to DOS" , XMIN, YMENU+50, vga16color[4], 0);
grx_text("SCORE " , XMIN, YMENU+60, vga16color[4], 0);
 
c = keyb_getch(BLOCK);
 
980,9 → 955,8
pid_Missile = task_create("Missile", Missile, &ms, NULL);
 
if (pid_Missile == NIL) {
grx_close();
perror("Could not create task <Missile>\n");
sys_abort(1);
sys_shutdown_message("Could not create task <Missile>\n");
sys_end();
}
 
task_activate(pid_Missile);
1005,9 → 979,8
pid_Madre = task_create("MadreAlieni", MadreAlieni, &m, NULL);
 
if (pid_Madre == NIL) {
grx_close();
perror("Could not create task <MadreAlieni>\n");
sys_abort(1);
sys_shutdown_message("Could not create task <MadreAlieni>\n");
sys_end();
}
task_activate(pid_Madre);
}
1024,9 → 997,8
pid_Astro = task_create("Astronave", Astronave, &a, NULL);
 
if (pid_Astro == NIL) {
grx_close();
perror("Could not create task <Astronave>\n");
sys_abort(1);
sys_shutdown_message("Could not create task <Astronave>\n");
sys_end();
}
 
AstronavePosition.FlagAstronave = TRUE ;
1049,12 → 1021,12
 
grx_text( s , XMIN, YMENU+60, 4, 0);
 
grx_text("Nemici uccisi", XMIN+250, YMENU+10, 1, 0);
grx_text(s1 , XMIN+250, YMENU+20, 1, 0);
grx_text(s2 , XMIN+250, YMENU+30, 1, 0);
grx_text(s3 , XMIN+250, YMENU+40, 1, 0);
grx_text(s4 , XMIN+250, YMENU+50, 1, 0);
grx_text(s5 , XMIN+250, YMENU+60, 1, 0);
grx_text("Nemici uccisi", XMIN+250, YMENU+10, vga16color[1], 0);
grx_text(s1 , XMIN+250, YMENU+20, vga16color[1], 0);
grx_text(s2 , XMIN+250, YMENU+30, vga16color[1], 0);
grx_text(s3 , XMIN+250, YMENU+40, vga16color[1], 0);
grx_text(s4 , XMIN+250, YMENU+50, vga16color[1], 0);
grx_text(s5 , XMIN+250, YMENU+60, vga16color[1], 0);
 
c = keyb_getch(BLOCK);
 
/unsupported/trunk/arezzo/2004/defender/initfile.c
1,132 → 1,198
/*
* 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
*/
 
/*
17 Giugno 2004 : commenti - da verificare - di Simone Mannori
 
*/
 
 
 
/*
------------
CVS : $Id: initfile.c,v 1.1 2004-08-05 11:34:34 pj Exp $
 
File: $File$
Revision: $Revision: 1.1 $
Last update: $Date: 2004-08-05 11:34:34 $
------------
 
System initialization file
 
This file contains the 2 functions needed to initialize the system.
 
These functions register the following levels:
 
an EDF (Earliest Deadline First) level
a RR (Round Robin) level
a CBS (Costant Bandwidth Server) level
a Dummy level
 
It can accept these task models:
 
HARD_TASK_MODEL (wcet+mit) at level 0
SOFT_TASK_MODEL (met, period) at level 1
NRT_TASK_MODEL at level 2
 
This file is similar to the configuration of kernel/init/hartik3.c
 
TICK is set to 0 (one-shot timer is used)
*/
 
/*
* 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 "kernel/kern.h"
#include "modules/edf.h"
#include "modules/cbs.h"
#include "modules/rr.h"
#include "modules/dummy.h"
 
#include "modules/sem.h"
#include "modules/hartport.h"
#include "modules/cabs.h"
 
#include "drivers/keyb.h"
 
 
/*+ sysyem tick in us +*/
#define TICK 0
 
/*+ RR tick in us +*/
#define RRTICK 10000
 
TIME __kernel_register_levels__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
EDF_register_level(EDF_ENABLE_ALL); // 1 - scheduler EDF
 
CBS_register_level(CBS_ENABLE_ALL, 0); // 2 - scheduler CBS
 
RR_register_level(RRTICK, RR_MAIN_YES, mb); // 3 - round robin affettato @ 10 ms
 
dummy_register_level(); // il dummy task (!)
 
SEM_register_module(); // semafori
 
CABS_register_module(); // CABS
 
return TICK;
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
 
 
KEYB_PARMS kparms = BASE_KEYB;
 
HARTPORT_init();
 
keyb_def_ctrlC(kparms, NULL);
keyb_def_map(kparms,itaMap);
KEYB_init(&kparms);
 
__call_main__(mb);
 
return (void *)0;
}
 
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Giacomo Guidi <giacomo@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
*/
 
/*
* 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 "kernel/kern.h"
#include "modules/intdrive.h"
#include "modules/edf.h"
#include "modules/hardcbs.h"
#include "modules/rr.h"
#include "modules/dummy.h"
 
#include "modules/sem.h"
#include "modules/hartport.h"
#include "modules/cabs.h"
 
#include <drivers/shark_linuxc26.h>
#include <drivers/shark_pci26.h>
#include <drivers/shark_input26.h>
#include <drivers/shark_keyb26.h>
#include <drivers/shark_fb26.h>
 
#define FRAME_BUFFER_DEVICE 0
 
/*+ sysyem tick in us +*/
#define TICK 0
 
/*+ RR tick in us +*/
#define RRTICK 2000
 
/*+ Interrupt Server +*/
#define INTDRIVE_Q 1000
#define INTDRIVE_T 10000
#define INTDRIVE_FLAG 0
 
void call_shutdown_task(void *arg);
int device_drivers_init();
int device_drivers_close();
void set_shutdown_task();
TASK shutdown_task_body(void *arg);
 
PID shutdown_task_PID = -1;
 
TIME __kernel_register_levels__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
INTDRIVE_register_level(INTDRIVE_Q,INTDRIVE_T,INTDRIVE_FLAG);
EDF_register_level(EDF_ENABLE_ALL);
HCBS_register_level(HCBS_ENABLE_ALL, 1);
RR_register_level(RRTICK, RR_MAIN_YES, mb);
dummy_register_level();
 
SEM_register_module();
CABS_register_module();
 
return TICK;
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
HARTPORT_init();
 
/* Create the shutdown task. It will be activated at RUNLEVEL
SHUTDOWN */
set_shutdown_task();
 
/* Init the drivers */
device_drivers_init();
 
/* Set the shutdown task activation */
sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
 
__call_main__(mb);
 
return (void *)0;
}
 
void set_shutdown_task() {
 
/* WARNING: the shutdown task is a background thread. It cannot execute
if the system is overloaded */
NRT_TASK_MODEL nrt;
 
nrt_task_default_model(nrt);
nrt_task_def_system(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();
}
 
}
 
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;
 
}
 
int device_drivers_close() {
FB26_close(FRAME_BUFFER_DEVICE);
KEYB26_close();
INPUT26_close();
return 0;
}
 
#define SHUTDOWN_TIMEOUT_SEC 3
 
void call_shutdown_task(void *arg)
{
struct timespec t;
 
sys_gettime(&t);
t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
 
/* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
 
task_activate(shutdown_task_PID);
}
 
TASK shutdown_task_body(void *arg) {
 
device_drivers_close();
 
sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
 
sys_abort_shutdown(0);
 
return NULL;
 
}
/unsupported/trunk/arezzo/2004/defender/readme.txt
0,0 → 1,3
- this demo has been made for Shark 1.22
- ported to Shark 1.4 by Giacomo Guidi
 
/unsupported/trunk/arezzo/2004/defender/makefile
12,6 → 12,6
include $(BASE)/config/example.mk
 
def_01:
make -f $(SUBMAKE) APP=def_01 INIT= OTHEROBJS="initfile.o" OTHERINCL= SHARKOPT="__OLDCHAR__ __GRX__"
make -f $(SUBMAKE) APP=def_01 INIT= OTHEROBJS="initfile.o" OTHERINCL= SHARKOPT="__LINUXC26__ __PCI__ __INPUT__ __FB__ __NET__"