sb.c
3.53 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*---------------------------------------------------------------------*
Copyright (C) 1998 Nintendo.
$RCSfile: sb.c,v $
$Revision: 1.1.1.1 $
$Date: 2002/05/02 03:27:33 $
*---------------------------------------------------------------------*/
#include "hglobals.h"
#include "htry.h"
#include "hsb.h"
#include "hdd.h"
#include "hvideo_str.h"
s32
sbar_create(TStringBar * bar,u8 * str, s32 xpos ,s32 ypos )
{
try_assert("sbar create : str is null" ,(s32)str);
try_assert("sbar create : str is too long" ,( sb_length(str) < SBAR_MAXLENGTH ));
sprintf( bar->str,str);
bar->x = xpos;
bar->y = ypos;
bar->color = RGBA_WHITE ;
bar->visible = true;
bar->clipping = false;
bar->autoprintf = false;
bar->base.x=0;
bar->base.y=0;
return -1;
}
s32
sbar_moveCenter(TStringBar * bar ,s32 left ,s32 right )
{
try_assert("sbar movecenter : right < left " , ((right - left) > 0 ) );
bar->x = left + ( (right - left - sbar_getWidth(bar) ) / 2 );
return -1;
}
s32
sbar_getWidth(TStringBar * bar)
{
return ( bar->autoprintf ) ?
str_getFontWidth() * bar->src_length : str_getWidth(bar->str);
}
s32
sbar_setBase(TStringBar * bar,s32 x ,s32 y)
{
bar->base.x = x;
bar->base.y = y;
return -1;
}
s32
sbar_setClip(TStringBar * bar,s32 left ,s32 top ,s32 right ,s32 bottom )
{
bar->clip.left = left;
bar->clip.top = top;
bar->clip.right = right;
bar->clip.bottom = bottom;
bar->clipping = true;
return -1;
}
s32
sbar_setSrc(TStringBar * bar,void * src, s32 type ,s32 length )
{
if( (type != AS_ASC ) && (length > 16) ) length=16;
bar->src = src;
bar->src_as = type;
bar->src_length = length;
bar->autoprintf = true;
return -1;
}
s32
sbar_setSubst(TStringBar * bar,void * src, u8 ** src_sub ,s32 length )
{
bar->src = src;
bar->src_as = AS_SUBST;
bar->src_length = length;
bar->src_sub = src_sub;
bar->autoprintf = true;
return -1;
}
s32
sbar_show(TStringBar * bar)
{
s32 i,x,y;
s32 ret;
if ( !bar->visible ) return 0;
if( bar->autoprintf )
{
switch( bar->src_as )
{
case AS_HEX:
sprintf( bar->str ,"0x");
for(i=0;i< bar->src_length ;i++)
sprintf( bar->str + i*2 + 2 ,"%02x" ,*((u8 *)(bar->src) + i) );
break;
case AS_DEC:
if( try_warning("illegal size for dec" , (bar->src_length <= 4) ) )
return 0;
ret = 0;
for(i=0;i<bar->src_length;i++)
{
ret <<= 8;
ret += *((u8 *)(bar->src) + i);
}
sprintf( bar->str ,"%d" , ret );
break;
case AS_ASC:
for(i=0;i< bar->src_length ;i++)
{
ret = *((u8 *)(bar->src) + i);
sprintf( bar->str + i ,"%c" ,ret);
}
break;
case AS_SUBST:
ret = *(s32 *)(bar->src);
if ( ret >= bar->src_length ) return 0;
sprintf( bar->str ,"%s" ,*(bar->src_sub + ret) );
break;
default:
break;
}
}
x = bar->x + bar->base.x;
y = bar->y + bar->base.y;
if( !bar->clipping || EXIST_IN(x,y,bar->clip) )
{
if( *(bar->str) & 0x80 )
video_setJStr(bar->str , x , y , bar->color );
else if( *(bar->str) == '#' )
video_setString( bar->str + 1 , x , y , bar->color );
else
video_setJStr(bar->str , x , y , bar->color );
}
return -1;
}
s32
sb_clip(s32 val ,s32 from ,s32 to)
{
s32 ret;
ret = val;
if( val < from ) ret = to;
else if( val > to ) ret = from;
return ret;
}
u16
sb_jpad( u16 trig )
{
s32 i;
u16 mask;
mask=1;
for(i=0;i<16;i++)
{
mask = 1<<i;
if( trig & mask ) return mask;
}
return 0;
}
s32
sb_length(u8 *s)
{
s32 i=0;
if(s == 0) return -1;
while( *(s+i) != 0 ) ++i;
return i;
}