Blame | Last modification | View Log | RSS feed
#include "include/auto.h"
#include "include/const.h"
PID pid1,pid2,pid3,pid4;
SOFT_TASK_MODEL mp;
/* Semaphores */
sem_t grx_mutex;
/* Useful colors */
int black1 = rgb16( 0, 0, 0);
int red = rgb16(255, 0, 0);
int green = rgb16( 0,255, 0);
int blue = rgb16( 0, 0,255);
int lightgray = rgb16(192,192,192);
int car_colour = rgb16( 40, 80,125);
int track_colour = rgb16( 15, 70,175);
int track_direction;
void drive_car();
/* -------------------------------------------------------*/
/* Closing function */
void byebye()
{
grx_close();
// we need clear to reposition the cursor in the right place after
// going back from the graphical mode.
clear();
kern_printf("ROAD CROSS GAME IS OVER, WERE U HURT!\n");
}
/* -------------------------------------------------------*/
void draw_highway()
{
/* Track drawing */
sem_wait(&grx_mutex);
grx_box(0,HIGHWAY_Y_MIN,800,HIGHWAY_Y_MAX,track_colour);
grx_line(0,HIGHWAY_Y_MIN ,800,HIGHWAY_Y_MIN ,115);
grx_line(0,HIGHWAY_Y_MIN+75,800,HIGHWAY_Y_MIN+75,115);
grx_line(0,HIGHWAY_Y_MIN+150,800,HIGHWAY_Y_MIN+150,115);
grx_line(0,HIGHWAY_Y_MIN+225,800,HIGHWAY_Y_MIN+225,115);
grx_line(0,HIGHWAY_Y_MAX,800,HIGHWAY_Y_MAX,115);
grx_line(390,450,390,0,25);
grx_line(410,450,410,0,25);
sem_post(&grx_mutex);
}
//task for car on each
TASK drive_car1(void *arg)
{
while (1)
{
drive_car(1);
task_endcycle();
}
}
TASK drive_car2(void *arg)
{
while (1)
{
drive_car(2);
task_endcycle();
}
}
TASK drive_car3(void *arg)
{
while (1)
{
drive_car(3);
task_endcycle();
}
}
TASK drive_car4(void *arg)
{
while (1)
{
drive_car(4);
task_endcycle();
}
}
void drive_car(int track)
{
int x1=0;
int x2=0;
int y1=0;
int y2=0;
int x1o=0;
int x2o=0;
int x_size=50;
int y_size=35;
switch(track)
{
case 1:
x1=0;
y1=110;
track_direction = FORWARD;
break;
case 2:
x1=0;
y1=185 ;
track_direction = FORWARD;
break;
case 3:
x1=800-x_size;
y1=260;
track_direction =BACKWARD;
break;
case 4:
x1=800-x_size;
y1=335;
track_direction =BACKWARD;
break;
}//end of switch
x2=x1+x_size;
y2=y1+y_size;
if(track_direction == FORWARD)
{
do
{
x1o=x1;
x2o=x2;
x1 =x1o+5*track;
x2 =x1+x_size;
task_delay(60000);
grx_box(x1o,y1,x2o,y2,track_colour) ;
grx_box(x1,y1,x2,y2,car_colour);
} while(x1<800);
}//end of true condition of if
else
{//TRACK == BACKWARD
do
{
x1o=x1;
x2o=x2;
x1 =x1o-(5*track);
x2 =x1+x_size;
task_delay(70000);
grx_box(x1o,y1,x2o,y2,track_colour) ;
grx_box(x1,y1,x2,y2,car_colour);
if(track==3)
grx_box(0,260,x_size,265+y_size,track_colour) ;
// if(track==4)
grx_box(700,405,800,500,black1) ;
} while(x1>0);
}//end of else
} //end of the method drive_car
/* -------------------------------------------------------*/
void initiate_task(){
soft_task_default_model(mp);
soft_task_def_level(mp,1);
soft_task_def_ctrl_jet(mp);
soft_task_def_arg(mp,NULL);
soft_task_def_group(mp, 1);
soft_task_def_met(mp,100);
soft_task_def_period(mp,700);
soft_task_def_usemath(mp);
pid1 = task_create("track1", drive_car1, &mp, NULL);
pid2 = task_create("track2", drive_car2, &mp, NULL);
pid3 = task_create("track3", drive_car3, &mp, NULL);
pid4 = task_create("track4", drive_car4, &mp, NULL);
task_activate(pid1);
task_activate(pid2);
task_activate(pid3);
task_activate(pid4);
create_man();
while(1)
{
grx_line(390,450,390,0,25);
grx_line(410,450,410,0,25);
task_endcycle();
}
}
/* ------------------- */
/* The main function */
/* ------------------- */
int main(int argc, char **argv) {
HARD_TASK_MODEL m;
PID main_pid;
/* Set the exception handler */
set_exchandler_grx();
/* Set the closing function */
sys_atrunlevel(byebye, NULL, RUNLEVEL_BEFORE_EXIT);
/* Keyboard handling */
keyb_handler();
kern_printf("KEYBOARD initialized...\n");
/* Graphics mutex */
sem_init(&grx_mutex, 0, 1);
/* Graphics init */
grx_init();
grx_open(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BIT_COLORS);
draw_highway();
sem_post(&grx_mutex);
/* Command and info display */
cmd_display();
/* ------------ */
/* Task Calls */
/* ------------ */
hard_task_default_model(m);
hard_task_def_arg(m,NULL);
hard_task_def_wcet(m, CONTROL_WCET);
hard_task_def_mit(m, CONTROL_PERIOD);
hard_task_def_usemath(m);
main_pid = task_create("controller",initiate_task, &m, NULL);
if(main_pid == -1)
sys_end();
task_activate(main_pid);
return 0;
}
/* -------------------------------------------------------*/