textlib.c
4.86 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/*---------------------------------------------------------------------
File : textlib.c
Coded by
Modified by Koji Mitsunari. Feb 27, 1997.
Copyright by Nintendo, Co., Ltd. 1997.
---------------------------------------------------------------------*/
#include "textlib.h"
#include "ncode.h"
extern u16 *bitmap_buf;
extern u16 bitmap_buf1[];
extern u16 bitmap_buf2[];
extern u8 patterns[NUM_OF_CHAR][PATTERN_SIZE_Y];
u32 x_pos = 0;
u32 y_pos = 0;
u16 color = 0;
u16 bg_color = 0;
u8 str[256];
u8 *err_mes_ptr;
#ifdef __MWERKS__
u8 CR25[] = "\f\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
u8 CR21[] = "\f\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t";
#endif /* __MWERKS__ */
void v_sync_double_buffer(OSMesgQueue *queue)
{
static int toggle=0;
osWritebackDCache(bitmap_buf, sizeof(u16) * SCREEN_SIZE_X * SCREEN_SIZE_Y);
if (MQ_IS_FULL(queue))
(void)osRecvMesg(queue, NULL, OS_MESG_BLOCK);
(void)osRecvMesg(queue, NULL, OS_MESG_BLOCK);
osViSwapBuffer( bitmap_buf );
toggle ^= 1;
if( toggle == 1 ) {
bitmap_buf = bitmap_buf2;
} else {
bitmap_buf = bitmap_buf1;
}
}
void init_draw(void)
{
int mode=RESOLUTION;
int i;
u16 *r;
bitmap_buf = bitmap_buf1;
if(mode == SCREEN_LOW) {
osViSetMode(&osViModeTable[OS_VI_NTSC_LPF1]);
} else {
osViSetMode(&osViModeTable[OS_VI_NTSC_HPF1]);
}
osViSwapBuffer( bitmap_buf );
r = bitmap_buf1;
for (i = 0; i < SCREEN_SIZE_X * SCREEN_SIZE_Y; i ++)
*r++ = bg_color;
r = bitmap_buf2;
for (i = 0; i < SCREEN_SIZE_X * SCREEN_SIZE_Y; i ++)
*r++ = bg_color;
}
void clear_draw(void)
{
int i;
u16 *r;
r = bitmap_buf;
for (i = 0; i < SCREEN_SIZE_X * SCREEN_SIZE_Y; i++, *r++ = bg_color);
}
void draw_char( int in_code )
{
int i,j;
int code;
switch( in_code ) {
case '\n':
x_pos = 0;
if( ++y_pos >= NUM_OF_Y ) {
y_pos=0;
}
break;
case '\r':
x_pos = 0;
break;
case '\t':
x_pos += 8;
if( x_pos >= NUM_OF_X ) {
x_pos = 0;
if( ++y_pos >= NUM_OF_Y ) {
y_pos=0;
}
}
break;
case '\f':
y_pos = 0;
x_pos = 0;
break;
case NULL:
x_pos ++;
break;
default:
if( 0 > ( code = in_code - 0x20 )) {
code = 0x1f;
} else if( 0x5f < code) {
code = 0x1f;
}
for(i = 0 ; i < PATTERN_SIZE_Y ; i++)
for(j = 0 ; j < PATTERN_SIZE_X ; j++)
bitmap_buf[ (y_pos * PATTERN_SIZE_Y + i) * SCREEN_SIZE_X +
(x_pos * PATTERN_SIZE_X + j) ]
= ( ((patterns[code][i]>>(7-j)) & 0x01)? color:bg_color);
if( ++x_pos >= NUM_OF_X ) {
x_pos = 0;
if( ++y_pos >= NUM_OF_Y ) {
y_pos=0;
}
}
break;
}
}
void draw_uint( unsigned long num )
{
int i;
for(i = 0 ; i < 4; i++)
draw_hex( num >> (8 * (3 - i)) );
}
void draw_ushort( unsigned short num )
{
int i;
for(i = 0 ; i < 2; i++)
draw_hex( num >> (8 * (1 - i)) );
}
void draw_hex( int num )
{
int lo = num & 0x0f;
int hi = (num >> 4) & 0x0f;
if(hi >= 10) {
draw_char('a' + hi -10);
} else {
draw_char('0' + hi);
}
if(lo >= 10) {
draw_char('a' + lo -10);
} else {
draw_char('0' + lo);
}
}
#define DEC_NUM 5
void draw_dec( int num )
{
u8 s[DEC_NUM];
int i = num;
int j = DEC_NUM-2;
for (j = DEC_NUM - 2 ; j >= 0 ; j-- ){
s[j] = (i % 10) + '0';
i = (int)(i/10);
}
s[DEC_NUM-1] = '\0';
draw_puts(s);
}
void draw_puts(char *s)
{
while( *s )
draw_char( *s++ );
}
u8 *n64c2asc(u8 *s, int length) {
int i;
for (i = 0 ; i < length ; i ++ ) {
if ( s[i] >= __0 && s[i] <= __9) {
str[i] = s[i] + ('0' - __0);
} else if ( s[i] >= __A && s[i] <= __Z) {
str[i] = s[i] + ('A' - __A);
} else if (s[i] == __NUL && i < length-1) {
str[i] = ' ';
} else {
switch(s[i]) {
case __NUL:
str[i] = NULL;
break;
case __SPC:
str[i] = ' ';
break;
case __EXCLAM:
str[i] = '!';
break;
case __2QUOTE:
str[i] = '\"';
break;
case __NUMBR:
str[i] = '#';
break;
case __1QUOTE:
str[i] = '\'';
break;
case __ASTER:
str[i] = '*';
break;
case __PLUS:
str[i] = '+';
break;
case __COMMA:
str[i] = ',';
break;
case __MINUS:
str[i] = '-';
break;
case __PERIOD:
str[i] = '.';
break;
case __SLASH:
str[i] = '/';
break;
case __COLON:
str[i] = ':';
break;
case __EQUAL:
str[i] = '=';
break;
case __QUEST:
str[i] = '?';
break;
case __AT:
str[i] = '@';
break;
default:
str[i] = ' ';
}
}
}
return str;
}
u8 *uint2str( u32 num )
{
int i;
for(i = 0 ; i < 4; i++) {
str[i] = num >> (8 * (3 - i));
}
return str;
}
void
mes_init(u8 *s1)
{
u8 *s;
err_mes_ptr = s1;
s = CR21;
while(*s) {
*err_mes_ptr++ = *s++;
}
err_mes_ptr++;
}
void
mes_add(u8 *s)
{
err_mes_ptr--;
while(*s) {
*err_mes_ptr++ = *s++;
}
*err_mes_ptr++ = '\0';
}