textlib.c
2.9 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
#include "textlib.h"
extern u16 *bitmap_buf;
extern u16 bitmap_buf1[];
extern u16 bitmap_buf2[];
unsigned int x_pos=0;
unsigned int y_pos=0;
unsigned int scroll_top=0;
unsigned int scroll_x=0;
unsigned int scroll_y=0;
extern u8 patterns[NUM_OF_CHAR][PATTERN_SIZE_Y];
u16 color;
u16 bg_color=0;
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 setcolor( int r, int g, int b)
{
color = GPACK_RGBA5551(r,g,b,1);
}
void setbgcolor( int r, int g, int b)
{
bg_color = GPACK_RGBA5551(r,g,b,1);
}
void init_draw(void)
{
int mode=RESOLUTION;
int i;
u16 *r;
bitmap_buf = bitmap_buf1;
if(mode == 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;
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,hi;
lo = num & 0x0f;
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);
}
void draw_puts(char *s)
{
while( *s )
draw_char( *s++ );
}