Subversion Repositories shark

Rev

Blame | Last modification | View Log | RSS feed

/************************** Simcity ************************/
// Main,initialization functions and global variables allocation
#include <kernel/func.h>
#include <string.h>
#include <stdlib.h>
#include <drivers/keyb.h>
#include <drivers/glib.h>
#include <kernel/kern.h>
#include <semaphore.h>
#include <math.h>
#include "include/constant.h"
#include "include/misc.h"
#include "include/draw.h"
#include "include/proc.h"
#define rgb rgb16

/* graphic mutex... */
sem_t mutex;
//kill flag mutexes
sem_t kill_mutex[MAX_CAR];

// various sprites to use with grx_putimage()....
BYTE vbuf[MAX_CAR][ROW*COL*2];
BYTE clrscr[800*600*2];
BYTE clrcam[(ROW+2)*(COL+2)*2];
BYTE gauge_img[ROW*COL*2];
BYTE brk_gauge[ROW*COL*2];
BYTE arrow[3][ROW*COL*2];
BYTE street[H*W*2];

//task chain pointers
car_data *free_n,*free_o,*busy_n,*busy_o;

// various sprites to plot
extern DWORD macchine[ROW][COL][NCAR];
extern DWORD sprites[ROW][COL][NO_SPRITE];
extern DWORD strada[H][W];

//resolution to use
WORD r=600;
WORD c=800;
BYTE bpp=16;

// useful colors...
DWORD white;
DWORD black;
DWORD red;
DWORD gray;
DWORD blue;
DWORD green;
DWORD border;
DWORD tl_bg;

//PID vectors

PID p_table[MAX_CAR];
PID c_table[MAX_CAR];
PID g_table[MAX_CAR];
PID a_table[MAX_CAR];

char kill_flag[MAX_CAR];
float cosine[360],sine[360];

// data structures
car_data car_data_array[MAX_CAR];
tl_data tl_data_array[MAX_TL];
starting_set starting_set_array[S_POINT];

void keyb_h(void);

static void version( void )
{
  cprintf("\n\nDemo presented by\n");
  cprintf("Aguzzi Marco\n");
  cprintf("   &\n");
  cprintf("Ferrari Fabio\n");
}

void my_close(void *arg)
{
  grx_close();
  kern_printf("Shutting down SIMCITY\n");
}

int main(int argc, char **argv)
{
  int i;
  char tl_name[4];

  version();

  sys_atrunlevel(my_close, NULL, RUNLEVEL_BEFORE_EXIT);

//resetting kill flags
  for(i=0;i<MAX_CAR;i++) {
    p_table[i]=0;
    kill_flag[i]=0;
  }

// graphic mode initialization
#ifdef GRAPH
  if (grx_init() < 1) {
    kern_printf("Error initializing graphics\n");
    sys_abort(1);
  }
  if (grx_open(c,r,bpp) < 0) {
    kern_printf("GRX Open Err\n");
    sys_abort(1);
  }
  get_images();
#endif
  srand(sys_gettime(NULL));

//init the graphic mutex
  sem_init(&mutex,1,1);
//init kill flag mutexes
  for(i=0;i<MAX_CAR;i++) sem_init(&(kill_mutex[i]),1,1);
//fill sine & cosine lookup tables
  fill_table();
/*init keys*/
  keyb_h();
  set_start_point();
  tl_init();
  init_struct();

/* useful colors ... */
  white = rgb(255,255,255);
  black = rgb(0,0,0);
  red   = rgb(255,0,0);
  gray  = rgb(210,210,210);
  blue  = rgb(0,0,220);
  green = rgb(0,255,0);
  border= rgb(128,128,128);
  tl_bg= rgb(0,128,0);
#ifdef GRAPH
/* paint scenario*/
  draw_scenario();
#endif
#ifndef GRAPH
  cprintf("Main: max_tl:%d\n",MAX_TL);
#endif

//creating refresher,killer and traffic light processes...
  ref_create();
  killer_create();
  for(i=0;i<MAX_TL;i++) {
    sprintf(tl_name,"tl%d",i+1);
#ifndef GRAPH
    cprintf("main:tname=%s",tl_name);
#endif
    stl_create(tl_name,i);
  }
  return 0;
}