Subversion Repositories shark

Rev

Blame | 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: biliardo.c,v 1.1 2003-06-04 09:41:32 giacomo Exp $

 File:        $File$
 Revision:    $Revision: 1.1 $
 Last update: $Date: 2003-06-04 09:41:32 $
 ------------
**/


/*
 * 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 "biliardo.h"
#include <kernel/func.h>
#include <string.h>
#include <stdlib.h>
#include <drivers/keyb.h>
#include <drivers/glib.h>

/* graphic mutex... */
mutex_t mutex;

mutex_t palmutex;
mutex_t delmutex;
//mutex_t punmutex;

/* useful colors... */
int white;
int black;
int red;
int gray;
int green;
int lime;
int brown;

void app_mutex_init(mutex_t *m);

static void version( void )
{
  cprintf( "S.Ha.R.K. San Martino Sicc. Demo 1.0\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. - Biliardo rivisitato", 322,2, white, black );
  grx_text("q          : uscita",322, 18, gray, black );
  grx_text("i          : inizio partita",322,28, gray, black );
  grx_text("Space      : scocca il colpo" ,322,38, gray, black );
  grx_text("a,z        : calibra la forza" ,322,48, gray, black );
  grx_text("Freccie    : posiziona cursore" ,322,58, gray, black );
  grx_text("Backspace  : nuova partita" ,322,68, 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("Termine programma\n");
}


void endfun(KEY_EVT *k)
{
    cprintf("Tasto q premuto, termine programma\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;

//  Evento di termine programma
  k.flag = 0;
  k.scan = KEY_Q;
  k.ascii = 'q';
  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);
    green = rgb16(0,128,0);
    lime = rgb16(0,255,0);
    brown = rgb16(128,0,0);

    scenario();

    init_jetcontrol();

    app_mutex_init(&palmutex);
    app_mutex_init(&delmutex);
    init_ball();

    initSched();

    group_activate(JET_GROUP);

    return 0;
}