clock.c 2.99 KB
/**************************************************************************
 *                                                                        *
 *               Copyright (C) 1994, Silicon Graphics, Inc.               *
 *                                                                        *
 *  These coded instructions, statements, and computer programs  contain  *
 *  unpublished  proprietary  information of Silicon Graphics, Inc., and  *
 *  are protected by Federal copyright  law.  They  may not be disclosed  *
 *  to  third  parties  or copied or duplicated in any form, in whole or  *
 *  in part, without the prior written consent of Silicon Graphics, Inc.  *
 *                                                                        *
 *************************************************************************/
#include <ultra64.h>
#include <sp.h>

#include "stress.h"
#include "font_ext.h"

#define CLOCK_X		200
#define CLOCK_Y		200

static char	Time_str[15] = "00:00:00.0\0";
static u8	Tenths  = 0;
static u8	Seconds = 0;
static u8	Minutes = 0;
static u8	Hours   = 0;

/*
 * Timer Stuff
 */
static  OSMesgQueue     timeMessageQ;
static  OSMesg          timeMessageBuf[10];
static  OSTimer         stresstimer;
static  OSMesg          dummyMessage;

/*
 *  Initialize clock
 */
void
  clock_init(void)
{
    /*
     *  set up interval timer for tenths of seconds
     */
    osCreateMesgQueue(&timeMessageQ, timeMessageBuf, 1);
    osSetTimer(&stresstimer, 0, 1000, &timeMessageQ, &dummyMessage);
}


/*
 *  get_time_string - this should wake up every 1/10 of a second
 */
static void
  get_time_string( void )
{
  int t;

  ++Tenths;
  if(Tenths == 10)
  {
    Tenths = 0;
    ++Seconds;
    if(Seconds == 60)
    {
      Seconds = 0;
      ++Minutes;
      if(Minutes == 60)
      {
        Minutes = 0;
        ++Hours;
        if(Hours == 99)
        {
          Hours = 0;
        }
        goto do_hours;
      }
      goto do_minutes;
    }
    goto do_seconds;
  }
  goto do_tenths;

do_hours:
  Time_str[1] = (Hours % 10) + '0';
  Time_str[0] = (Hours / 10) + '0';
do_minutes:
  Time_str[4] = (Minutes % 10) + '0';
  Time_str[3] = (Minutes / 10) + '0';
do_seconds:
  Time_str[7] = (Seconds % 10) + '0';
  Time_str[6] = (Seconds / 10) + '0';
do_tenths:
  Time_str[9] = Tenths + '0';
}


/*
 *  Render real time clock
 */
void
do_clock(Gfx **pglistp)
{
    Gfx *gp;
	u32 ticks;

    font_init( pglistp );           /* Initialize fonts */

    gp = *pglistp;              /* Make font transparent */
    gDPSetBlendColor( gp++, 0, 0, 0, 0 );
    gDPSetAlphaCompare( gp++, G_AC_THRESHOLD );
    *pglistp = gp;

	/* Setup where and how to draw text */
    font_set_pos( CLOCK_X, CLOCK_Y );
    font_set_color( 55, 55, 255, 255 );
    font_set_scale( 1.0, 1.0 );
    font_set_win( 10, 1 );

    /* display real time to tenths of seconds */
    ticks = MQ_GET_COUNT(&timeMessageQ);
    while (ticks > 0)
    {
      get_time_string();
      --ticks;
    }

    font_show_string( pglistp, Time_str);
	font_finish( pglistp );
}