File: status.c

package info (click to toggle)
infocom 4.01pl2-5
  • links: PTS
  • area: non-free
  • in suites: hamm
  • size: 508 kB
  • ctags: 991
  • sloc: ansic: 8,228; makefile: 209
file content (115 lines) | stat: -rw-r--r-- 2,220 bytes parent folder | download | duplicates (3)
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
/*
**	File:	status.c
**
**	(C)opyright 1987-1992 InfoTaskforce.
*/

#include	"infocom.h"

/*
**	Status-Bar Routine Variables.
**
**	Note:
**		The variable "s_buff_ptr" is of type "byte *"
**		NOT "byte_ptr" - these definitions are
**		different for MSDOS Compilers ("byte_ptr" is huge).
*/

byte			s_buffer[MAX_LINE_LENGTH] ;
byte			*s_buff_ptr ;
static char		*score_str	= "Score: " ;
static char		*time_str	= "Time:  " ;

Void
put_status ( ch )
word	ch ;
{
	*s_buff_ptr++ = (byte)ch ;
}

char
*copy_string ( src,dst )
char	*src ;
char	*dst ;
{
	while ( *src != '\0' )
		*dst++ = *src++ ;
	return ( dst ) ;
}

Void
prt_status ()
{
	extern header	data_head ;
	extern boolean	disable_script ;
	extern proc_ptr	PrintChar ;
	extern int		screen_width ;

	word			hour ;
	word			minutes ;
	char			ch ;
	boolean			old_disable_script ;
	proc_ptr		old_procptr ;

	s_buff_ptr = s_buffer ;
	*s_buff_ptr++ = ' ' ;
	old_disable_script = disable_script ;
	disable_script = TRUE ;
	old_procptr = PrintChar ;
	PrintChar = put_status ;

	std_p_obj ( load_var ( 0x10 ) ) ;

	if (( data_head.mode_bits & USE_TIME ) == 0 )
	{
		while ( s_buff_ptr < ( s_buffer + screen_width - 0x14 ) )
			*s_buff_ptr++ = ' ' ;
		s_buff_ptr = (byte *)copy_string ( score_str,(char *)s_buff_ptr ) ;
		print_num ( load_var ( 0x11 ) ) ;
		*s_buff_ptr++ = '/' ;
		print_num ( load_var ( 0x12 ) ) ;
	}
	else
	{
		while ( s_buff_ptr < ( s_buffer + screen_width - 0x10 ) )
			*s_buff_ptr++ = ' ' ;
		s_buff_ptr = (byte *)copy_string ( time_str,(char *)s_buff_ptr ) ;
		hour = load_var ( 0x11 ) ;

		/*
		**	Convert 24 hour time to AM/PM
		*/

		ch = 'A' ;
		if ( hour >= 12 )
		{
			hour -= 12 ;
			ch = 'P' ;
		}
		if ( hour == 0 )
			hour = 12 ;

		/*
		**	Print Time
		*/

		print_num ( hour ) ;
		*s_buff_ptr++ = ':' ;

		/*
		**	Can't use print_num for minutes since we want leading zeros
		*/

		minutes = load_var ( 0x12 ) ;
		*s_buff_ptr++ = ((minutes / 10) + '0') ;
		*s_buff_ptr++ = ((minutes % 10) + '0') ;
		*s_buff_ptr++ = ' ' ;
		*s_buff_ptr++ = ch ;
		*s_buff_ptr++ = 'M' ;
	}
	while ( s_buff_ptr < ( s_buffer + screen_width ) )
		*s_buff_ptr++ = ' ' ;
	print_status ( s_buffer ) ;
	disable_script = old_disable_script ;
	PrintChar = old_procptr ;
}