clock.c
2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**************************************************************************
* *
* 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 );
}