1 /*
2 	This file is part of FreeIntv.
3 
4 	FreeIntv is free software: you can redistribute it and/or modify
5 	it under the terms of the GNU General Public License as published by
6 	the Free Software Foundation, either version 3 of the License, or
7 	(at your option) any later version.
8 
9 	FreeIntv is distributed in the hope that it will be useful,
10 	but WITHOUT ANY WARRANTY; without even the implied warranty of
11 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 	GNU General Public License for more details.
13 
14 	You should have received a copy of the GNU General Public License
15 	along with FreeIntv.  If not, see http://www.gnu.org/licenses/
16 */
17 
18 #include <string.h>
19 #include "osd.h"
20 
21 unsigned int DisplayWidth = 0;
22 unsigned int DisplayHeight = 0;
23 unsigned int DisplayColor[] = {0, 0xFFFFFF};
24 unsigned int DisplaySize = 0;
25 unsigned int *Frame;
26 
27 // Paused Message
28 
29 int pauseImage[572] =
30 {
31 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
32 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,
33 0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
34 0,1,0,1,1,1,1,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,1,1,1,0,0,1,1,1,1,1,0,1,1,1,1,0,0,1,1,0,1,0,
35 0,1,0,1,0,0,0,1,0,0,1,0,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,1,1,0,1,0,
36 0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,1,1,0,1,0,
37 0,1,0,1,1,1,1,0,0,1,1,1,1,1,0,1,0,0,0,1,0,0,1,1,1,0,0,1,1,1,0,0,0,1,0,0,0,1,0,1,1,0,1,0,
38 0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,
39 0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,1,1,0,1,0,
40 0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,0,1,1,1,0,0,0,1,1,1,0,0,1,1,1,1,1,0,1,1,1,1,0,0,1,1,0,1,0,
41 0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
42 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,
43 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
44 };
45 
OSD_drawPaused()46 void OSD_drawPaused()
47 {
48 	int i, j, k;
49 	int offset = 506;
50 	k = 0;
51 	for(i=0; i<13; i++)
52 	{
53 		for(j=0; j<44; j++)
54 		{
55 			Frame[offset+j] = pauseImage[k]*0xFFFFFF;
56 			k++;
57 		}
58 		offset+=352;
59 	}
60 }
61 
62 // Left / Right input Images
63 
64 int leftImage[377] = // 29x13
65 {
66 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
67 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,
68 0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
69 0,1,0,1,0,0,0,0,0,1,1,1,1,1,0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1,0,0,0,1,0,0,0,1,0,
89 0,1,0,1,1,1,1,0,0,0,0,1,0,0,0,1,0,1,1,1,0,1,1,1,1,1,0,0,0,1,0,0,0,1,0,
90 0,1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,
91 0,1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,
92 0,1,0,1,0,0,0,1,0,1,1,1,1,1,0,0,1,1,1,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,
93 0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
94 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,
95 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
96 };
97 
OSD_drawLeftRight()98 void OSD_drawLeftRight()
99 {
100 	int i, j, k1, k2;
101 	int offset = 73920; //210*352
102 	k1 = 0;
103 	k2 = 0;
104 	for(i=0; i<13; i++)
105 	{
106 		for(j=0; j<29; j++)
107 		{
108 			Frame[offset+j] = leftImage[k1]*0xFFFFFF;
109 			k1++;
110 		}
111 		for(j=0; j<35; j++)
112 		{
113 			Frame[offset+317+j] = rightImage[k2]*0xFFFFFF;
114 			k2++;
115 		}
116 		offset+=352;
117 	}
118 }
119 
OSD_drawRightLeft()120 void OSD_drawRightLeft()
121 {
122 	int i, j, k1, k2;
123 	int offset = 73920; //210*352
124 	k1 = 0;
125 	k2 = 0;
126 	for(i=0; i<13; i++)
127 	{
128 		for(j=0; j<35; j++)
129 		{
130 			Frame[offset+j] = rightImage[k1]*0xFFFFFF;
131 			k1++;
132 		}
133 		for(j=0; j<29; j++)
134 		{
135 			Frame[offset+323+j] = leftImage[k2]*0xFFFFFF;
136 			k2++;
137 		}
138 		offset+=352;
139 	}
140 }
141 
142 int letters[590] = // 32 - 90 59x10
143 {
144 	0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0, 0,  //0  space
145 	0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0, 0,  //1  !
146 	0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0, 0,  //2  "
147 	0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0, 0,  //3  #
148 	0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0, 0,  //4  $
149 	0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0, 0,  //5  %
150 	0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0, 0,  //6  &
151 	0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0, 0,  //7  '
152 	0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0, 0,  //8  (
153 	0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0, 0,  //9  )
154 	0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0, 0,  //10 *
155 	0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0, 0,  //11 +
156 	0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 8,  //12 ,
157 	0, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00, 0, 0,  //13 -
158 	0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0, 0,  //14 .
159 	0, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0, 0,  //15 /
160 	0, 0x3C, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3C, 0, 0,  //16 0
161 	0, 0x18, 0x28, 0x08, 0x08, 0x08, 0x08, 0x3E, 0, 0,  //17 1
162 	0, 0x3C, 0x42, 0x02, 0x04, 0x18, 0x20, 0x7E, 0, 0,  //18 2
163 	0, 0x3C, 0x42, 0x02, 0x1C, 0x02, 0x02, 0x3C, 0, 0,  //19 3
164 	0, 0x40, 0x44, 0x44, 0x7E, 0x04, 0x04, 0x04, 0, 0,  //20 4
165 	0, 0x7E, 0x40, 0x40, 0x7C, 0x02, 0x02, 0x7C, 0, 0,  //21 5
166 	0, 0x3E, 0x40, 0x40, 0x7C, 0x42, 0x42, 0x3C, 0, 0,  //22 6
167 	0, 0x7E, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0, 0,  //23 7
168 	0, 0x3C, 0x42, 0x42, 0x3C, 0x42, 0x42, 0x3C, 0, 0,  //24 8
169 	0, 0x3C, 0x42, 0x42, 0x3E, 0x02, 0x02, 0x3C, 0, 0,  //25 9
170 	0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0, 0,  //26 :
171 	0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0, 0,  //27 ;
172 	0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0, 0,  //28 <
173 	0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0, 0,  //29 =
174 	0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0, 0,  //30 >
175 	0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0, 0,  //31 ?
176 	0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0, 0,  //32 @
177 	0, 0x18, 0x24, 0x42, 0x7E, 0x42, 0x42, 0x42, 0, 0,  //33 A
178 	0, 0x7C, 0x42, 0x42, 0x7C, 0x42, 0x42, 0x7C, 0, 0,  //34 B
179 	0, 0x3C, 0x42, 0x40, 0x40, 0x40, 0x42, 0x3C, 0, 0,  //35 C
180 	0, 0x7C, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7C, 0, 0,  //36 D
181 	0, 0x7E, 0x40, 0x40, 0x7C, 0x40, 0x40, 0x7E, 0, 0,  //37 E
182 	0, 0x7E, 0x40, 0x40, 0x7C, 0x40, 0x40, 0x40, 0, 0,  //38 F
183 	0, 0x3C, 0x42, 0x40, 0x4E, 0x42, 0x42, 0x3C, 0, 0,  //39 G
184 	0, 0x42, 0x42, 0x42, 0x7E, 0x42, 0x42, 0x42, 0, 0,  //40 H
185 	0, 0x7C, 0x10, 0x10, 0x10, 0x10, 0x10, 0x7C, 0, 0,  //41 I
186 	0, 0x7E, 0x04, 0x04, 0x04, 0x04, 0x44, 0x38, 0, 0,  //42 J
187 	0, 0x42, 0x44, 0x48, 0x70, 0x48, 0x44, 0x42, 0, 0,  //43 K
188 	0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7E, 0, 0,  //44 L
189 	0, 0x42, 0x66, 0x5A, 0x42, 0x42, 0x42, 0x42, 0, 0,  //45 M
190 	0, 0x42, 0x62, 0x52, 0x52, 0x4A, 0x46, 0x42, 0, 0,  //46 N
191 	0, 0x3C, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3C, 0, 0,  //47 O
192 	0, 0x7C, 0x42, 0x42, 0x7C, 0x40, 0x40, 0x40, 0, 0,  //48 P
193 	0, 0x3C, 0x42, 0x42, 0x42, 0x4A, 0x46, 0x3D, 0, 0,  //49 Q
194 	0, 0x7C, 0x42, 0x42, 0x7C, 0x42, 0x42, 0x42, 0, 0,  //50 R
195 	0, 0x3C, 0x42, 0x40, 0x3C, 0x02, 0x42, 0x3C, 0, 0,  //51 S
196 	0, 0x7C, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0, 0,  //52 T
197 	0, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3C, 0, 0,  //53 U
198 	0, 0x42, 0x42, 0x42, 0x42, 0x24, 0x24, 0x18, 0, 0,  //54 V
199 	0, 0x42, 0x42, 0x42, 0x42, 0x5A, 0x66, 0x42, 0, 0,  //55 W
200 	0, 0x42, 0x42, 0x24, 0x18, 0x24, 0x42, 0x42, 0, 0,  //56 X
201 	0, 0x42, 0x42, 0x24, 0x18, 0x08, 0x08, 0x08, 0, 0,  //57 Y
202 	0, 0x7E, 0x04, 0x08, 0x10, 0x20, 0x40, 0x7E, 0, 0   //58 Z
203 };
204 
OSD_setDisplay(unsigned int frame[],unsigned int width,unsigned int height)205 void OSD_setDisplay(unsigned int frame[], unsigned int width, unsigned int height)
206 {
207 	Frame = frame;
208 	DisplayWidth = width;
209 	DisplayHeight = height;
210 	DisplaySize = width*height;
211 }
212 
OSD_setColor(unsigned int color)213 void OSD_setColor(unsigned int color)
214 {
215 	DisplayColor[1] = color;
216 }
217 
OSD_setBackground(unsigned int color)218 void OSD_setBackground(unsigned int color)
219 {
220 	DisplayColor[0] = color;
221 }
222 
223 /* Utility functions */
OSD_HLine(int x,int y,int len)224 void OSD_HLine(int x, int y, int len)
225 {
226 	int i, offset;
227 
228 	if(x<0 || y<0 || (y*DisplayWidth+x+len)>DisplaySize)
229       return;
230 
231 	offset = (y*DisplayWidth)+x;
232 	for(i = 0; i <= len; i++)
233 	{
234 		Frame[offset] = DisplayColor[1];
235 		offset = offset + 1;
236 	}
237 }
OSD_VLine(int x,int y,int len)238 void OSD_VLine(int x, int y, int len)
239 {
240    int i, offset;
241 
242 	if(x<0 || y<0 || ((y+len)*DisplayWidth+x)>DisplaySize)
243       return;
244 
245 	offset = (y*DisplayWidth)+x;
246 
247 	for(i = 0; i <= len; i++)
248 	{
249 		Frame[offset] = DisplayColor[1];
250 		offset = offset + DisplayWidth;
251 	}
252 }
253 
OSD_Box(int x1,int y1,int width,int height)254 void OSD_Box(int x1, int y1, int width, int height)
255 {
256 	OSD_HLine(x1, y1, width);
257 	OSD_HLine(x1, y1+height, width);
258 	OSD_VLine(x1, y1, height);
259 	OSD_VLine(x1+width, y1, height);
260 }
261 
OSD_FillBox(int x1,int y1,int width,int height)262 void OSD_FillBox(int x1, int y1, int width, int height)
263 {
264 	int i;
265 	for(i=0; i<height; i++)
266 	{
267 		OSD_HLine(x1, y1+i, width);
268 	}
269 }
270 
OSD_drawLetter(int x,int y,int c)271 void OSD_drawLetter(int x, int y, int c)
272 {
273 	int i, j;
274 	unsigned int t = DisplayColor[0];
275 	int offset     = (DisplayWidth*y)+x;
276 
277 	c = (c-32);
278 	if(c<0 || c>58)
279       return;
280 
281 	c = c * 10;
282 
283 	for(i=0; i<10; i++)
284 	{
285 		for(j=0; j<8; j++)
286 		{
287 			if((offset+j)<DisplaySize)
288 			{
289 				DisplayColor[0] = Frame[offset+j];
290 				Frame[offset+j] = DisplayColor[((letters[c]>>(7-j))&0x01)];
291 			}
292 		}
293 		offset+=DisplayWidth;
294 		c++;
295 	}
296 	DisplayColor[0] = t;
297 }
298 
OSD_drawTextFree(int x,int y,const char * text)299 void OSD_drawTextFree(int x, int y, const char *text)
300 {
301 	int len = strlen(text);
302 	int i = 0;
303 	int c = 32;
304 	while(i<len)
305 	{
306 		c = text[i];
307 		if(c<32) { break; }
308 		if(c>90) { c = 32; }
309 		i++;
310 		OSD_drawLetter(x, y, c);
311 		x+=8;
312 	}
313 }
314 
OSD_drawText(int x,int y,const char * text)315 void OSD_drawText(int x, int y, const char *text)
316 {
317 	x = x * 8;
318 	y = y * 10;
319 	OSD_drawTextFree(x, y, text);
320 }
321 
OSD_drawTextBG(int x,int y,const char * text)322 void OSD_drawTextBG(int x, int y, const char *text)
323 {
324 	unsigned int t1 = DisplayColor[1];
325 
326 	int len = (strlen(text)*8)+1;
327 
328 	x = x * 8;
329 	y = y * 10;
330 
331 	DisplayColor[1] = DisplayColor[0];
332 	OSD_FillBox(x, y, len, 10);
333 	DisplayColor[1] = t1;
334 
335 	OSD_drawTextFree(x+1, y+1, text);
336 }
337 
OSD_drawTextCenterBG(int y,const char * text)338 void OSD_drawTextCenterBG(int y, const char *text)
339 {
340 	unsigned int t1 = DisplayColor[1];
341 
342 	int len = (strlen(text)*8)+1;
343 	int x = (DisplayWidth-len) / 2;
344 	y = y * 10;
345 
346 	if(x>=0)
347 	{
348 		DisplayColor[1] = DisplayColor[0];
349 		OSD_FillBox(x, y, len, 10);
350 		DisplayColor[1] = t1;
351 
352 		OSD_drawTextFree(x+1, y+1, text);
353 	}
354 }
355 
OSD_drawInt(int x,int y,int num,int base)356 void OSD_drawInt(int x, int y, int num, int base)
357 {
358 	char buffer[2] = {0,0};
359 	int r = 0;
360 	int t = num;
361 
362 	if(base>2) { base = 10; }
363 
364 	if(num<0)
365 	{
366 		num = 0-num;
367 		buffer[0] = '-';
368 		OSD_drawText(x, y, buffer);
369 		x++;
370 	}
371 	if(num==0)
372 	{
373 		buffer[0] = '0';
374 		OSD_drawText(x, y, buffer);
375 	}
376 	else
377 	{
378 		x--;
379 		while(t>0)
380 		{
381 			r = t % base;
382 			t = (t-r) / base;
383 			x++;
384 		}
385 		while(num>0)
386 		{
387 			r = num % base;
388 			num = (num-r) / base;
389 			if(r>9)
390 			{
391 				buffer[0] = 'A' + r;
392 			}
393 			else
394 			{
395 				buffer[0] = '0' + r;
396 			}
397 			OSD_drawText(x, y, buffer);
398 			x--;
399 		}
400 	}
401 }
402