1 /*
2  * modified 2008 by
3  * Max Tretene, ACube Systems Srl. mtretene@acube-systems.com.
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23 
24 //-----------------------------------------------------------------------------
25 // SAM440EP extensions to support SLB - to be moved outside cfb_console.c
26 //-----------------------------------------------------------------------------
27 
28 #include <common.h>
29 #include <devices.h>
30 #include "memio.h"
31 #include <part.h>
32 #include "../menu/menu.h"
33 #include "hvideo.h"
34 #include <malloc.h>
35 #include <video_fb.h>
36 #include <video_font.h>
37 
38 
39 #undef DEBUG
40 
41 #ifdef DEBUG
42 #define PRINTF(format, args...) _printf(format , ## args)
43 #else
44 #define PRINTF(format, argc...)
45 #endif
46 
47 #define VIDEO_VISIBLE_COLS	(pGD->winSizeX)
48 #define VIDEO_VISIBLE_ROWS	(pGD->winSizeY)
49 #define VIDEO_PIXEL_SIZE	(pGD->gdfBytesPP)
50 #define VIDEO_DATA_FORMAT	(pGD->gdfIndex)
51 #define VIDEO_FB_ADRS		(pGD->frameAdrs)
52 
53 #define VIDEO_COLS			VIDEO_VISIBLE_COLS
54 #define VIDEO_ROWS			VIDEO_VISIBLE_ROWS
55 #define VIDEO_SIZE			(VIDEO_ROWS*VIDEO_COLS*VIDEO_PIXEL_SIZE)
56 #define VIDEO_PIX_BLOCKS	(VIDEO_SIZE >> 2)
57 #define VIDEO_LINE_LEN		(VIDEO_COLS*VIDEO_PIXEL_SIZE)
58 #define VIDEO_BURST_LEN		(VIDEO_COLS/8)
59 
60 #define CONSOLE_ROWS		(VIDEO_ROWS / VIDEO_FONT_HEIGHT)
61 #define CONSOLE_COLS		(VIDEO_COLS / VIDEO_FONT_WIDTH)
62 #define CONSOLE_ROW_SIZE	(VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
63 #define CONSOLE_ROW_FIRST	(video_console_address)
64 #define CONSOLE_ROW_SECOND	(video_console_address + CONSOLE_ROW_SIZE)
65 #define CONSOLE_ROW_LAST	(video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
66 #define CONSOLE_SIZE		(CONSOLE_ROW_SIZE * CONSOLE_ROWS)
67 #define CONSOLE_SCROLL_SIZE	(CONSOLE_SIZE - CONSOLE_ROW_SIZE
68 
69 extern GraphicDevice *pGD;	/* Pointer to Graphic array */
70 
71 extern const int video_font_draw_table8[];
72 extern const int video_font_draw_table15[];
73 extern const int video_font_draw_table16[];
74 extern const int video_font_draw_table24[16][3];
75 extern const int video_font_draw_table32[16][4];
76 
77 extern void *video_fb_address;		/* frame buffer address */
78 extern void *video_console_address;	/* console buffer start address */
79 
80 extern int console_col; /* cursor col */
81 extern int console_row; /* cursor row */
82 
83 extern u32 eorx, fgx, bgx;  /* color pats */
84 
85 extern void memsetl (int *p, int c, int v);
86 
overwrite_console(void)87 int overwrite_console(void)
88 {
89     return 0;
90 }
91 
set_partial_scroll_limits(const short start,const short end)92 unsigned short set_partial_scroll_limits(const short start, const short end)
93 {
94 /*
95 	if(!PARTIAL_SCROLL_ACTIVE(start, end))
96 	{
97 		// Deactivates the partial scroll
98 		partial_scroll_start=-1;
99 		partial_scroll_end=-1;
100 
101 		return 1;
102 	}
103 
104 	if(	(start < end) &&
105 		((start >= 0) && (start <= video_numrows-1)) &&
106 		((end >= 1) && (end <= video_numrows)))
107 	{
108 		partial_scroll_start = start;
109 		partial_scroll_end = end;
110 
111 		cursor_row = start;
112 		cursor_col = 0;
113 		video_set_cursor(start,0);
114 
115 		return 1;
116 	}
117 */
118 	return 0;
119 }
120 
get_partial_scroll_limits(short * const start,short * const end)121 void get_partial_scroll_limits(short * const start, short * const end)
122 {
123 /*
124 	*start = partial_scroll_start;
125 	*end = partial_scroll_end;
126 */
127 }
128 
video_get_key(void)129 int video_get_key(void)
130 {
131 	int c = getc();
132 
133 	switch(c)
134 	{
135 		case 0x1B:
136 			return KEY_ABORT;
137 		case 0x0D:
138 			return KEY_ACTIVATE;
139 		case 0x08:
140 			return KEY_DELETE;
141 	}
142 
143 	return c;
144 }
145 
146 unsigned char video_single_box[] =
147 {
148     218, 196, 191,
149     179,      179,
150     192, 196, 217
151 };
152 
153 unsigned char video_single_title[] =
154 {
155     195, 196, 180, 180, 195
156 };
157 
video_clear(void)158 void video_clear(void)
159 {
160 	memsetl (CONSOLE_ROW_FIRST, CONSOLE_SIZE >> 2, CONSOLE_BG_COL);
161 }
162 
video_set_color(unsigned char attr)163 void video_set_color(unsigned char attr)
164 {
165 	memsetl (CONSOLE_ROW_FIRST, CONSOLE_SIZE >> 2, attr);
166 }
167 
video_drawchars_color(int xx,int yy,unsigned char * s,int count,int attr)168 static void video_drawchars_color (int xx, int yy, unsigned char *s, int count, int attr)
169 {
170 	u8 *cdat, *dest, *dest0;
171 	u32 oldfgx, oldbgx;
172 	int rows, offset, c;
173 
174 	offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
175 	dest0 = video_fb_address + offset;
176 
177 	/* change drawing colors */
178 	oldfgx = fgx;
179 	oldbgx = bgx;
180 
181 	switch (attr) {
182 	case 0:
183 	case 4:
184 		fgx = 0x01010101;	// White on Black
185 		bgx = 0x00000000;
186 		break;
187 	case 1:
188 		fgx = 0x04040404;	// Red on Black
189 		bgx = 0x00000000;
190 		break;
191 	case 2:
192 		fgx = 0x01010101;	// White on Blue
193 		bgx = 0x08080808;
194 		break;
195 	case 3:
196 		fgx = 0x07070707;	// Dark Gray on Black
197 		bgx = 0x00000000;
198 		break;
199 	}
200 
201 	eorx = fgx ^ bgx;
202 
203 	switch (VIDEO_DATA_FORMAT) {
204 	case GDF__8BIT_INDEX:
205 	case GDF__8BIT_332RGB:
206 		while (count--) {
207 			c = *s;
208 			cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
209 			for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
210 			     rows--;
211 			     dest += VIDEO_LINE_LEN) {
212 				u8 bits = *cdat++;
213 
214 				((u32 *) dest)[0] = (video_font_draw_table8[bits >> 4] & eorx) ^ bgx;
215 				((u32 *) dest)[1] = (video_font_draw_table8[bits & 15] & eorx) ^ bgx;
216 			}
217 			dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
218 			s++;
219 		}
220 		break;
221 	}
222 
223    	/* restore drawing colors */
224 	fgx = oldfgx;
225 	bgx = oldbgx;
226 	eorx = fgx ^ bgx;
227 }
228 
video_clear_attr(void)229 void video_clear_attr(void)
230 {
231   video_set_color(0); //current_attr);
232 }
233 
video_attr(int which,int color)234 void video_attr(int which, int color)
235 {
236 /*
237 	if (which > 4)
238 		return;
239 
240 	int back = (color & 0x70) >> 4;
241 	color = color & 0x0f;
242 
243 	color *= 3;
244 	back *= 3;
245 
246 	video_fore[which] = pack_color(vga_color_table[color], vga_color_table[color+1], vga_color_table[color+2]);
247 	video_back[which] = pack_color(vga_color_table[back], vga_color_table[back+1], vga_color_table[back+2]);
248 */
249 }
250 
video_clear_box(int x,int y,int w,int h,int clearchar,int attr)251 void video_clear_box(int x, int y, int w, int h, int clearchar, int attr)
252 {
253     int line, col;
254 	unsigned char c = (unsigned char)clearchar;
255 
256     for (line=y; line<y+h; line++)
257     {
258 		for (col=x; col<x+w; col++)
259 		{
260 	    	video_drawchars_color(col*VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE,
261 	    						  line*VIDEO_FONT_HEIGHT * VIDEO_PIXEL_SIZE,
262 	    						  &c, 1, attr);
263 		}
264     }
265 }
266 
video_draw_text(int x,int y,int attr,char * text,int field)267 void video_draw_text(int x, int y, int attr, char *text, int field)
268 {
269 	x *= VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
270 	y *= VIDEO_FONT_HEIGHT * VIDEO_PIXEL_SIZE;
271 
272     while (*text)
273     {
274      	video_drawchars_color(x, y, text, 1, attr);
275 		x += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
276 
277 		if (field != -1) field--;
278 		if (field == 0) break;
279 
280 		text++;
281     }
282 
283     while (field > 0)
284     {
285      	video_drawchars_color(x, y, " ", 1, attr);
286 		x += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
287 		field--;
288     }
289 }
290 
video_repeat_char(int x,int y,int repcnt,int repchar,int attr)291 void video_repeat_char(int x, int y, int repcnt, int repchar, int attr)
292 {
293 	unsigned char c = (unsigned char)repchar;
294 
295 	x *= VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
296 	y *= VIDEO_FONT_HEIGHT * VIDEO_PIXEL_SIZE;
297 
298     while (repcnt--)
299     {
300     	video_drawchars_color(x, y, &c, 1, attr);
301     	x += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
302     }
303 }
304 
video_draw_box(int style,int attr,char * title,int separate,int xp,int yp,int w,int h)305 void video_draw_box(int style, int attr, char *title, int separate,
306 	int xp, int yp, int w, int h)
307 {
308     unsigned char *st = video_single_box;
309     unsigned char *ti = video_single_title;
310 
311     int i;
312     int x1, y1;
313     int x2, y2;
314 
315     xp *= VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
316     yp *= VIDEO_FONT_HEIGHT * VIDEO_PIXEL_SIZE;
317 
318     x1 = xp;
319     y1 = yp;
320     x2 = xp;
321     y2 = yp + ((h - 1) * VIDEO_FONT_HEIGHT * VIDEO_PIXEL_SIZE);
322 
323     video_drawchars_color(x1, y1, &st[0], 1, attr);
324     x1 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
325 
326     video_drawchars_color(x2, y2, &st[5], 1, attr);
327     x2 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
328 
329     for (i=0; i<w-2;i++)
330     {
331     	video_drawchars_color(x1, y1, &st[1], 1, attr);
332     	x1 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
333 
334 		video_drawchars_color(x2, y2, &st[6], 1, attr);
335 		x2 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
336     }
337 
338     video_drawchars_color(x1, y1, &st[2], 1, attr);
339     video_drawchars_color(x2, y2, &st[7], 1, attr);
340 
341     x1 = xp;
342     y1 = yp + VIDEO_FONT_HEIGHT * VIDEO_PIXEL_SIZE;
343     x2 = xp + (w - 1) * VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
344     y2 = yp + VIDEO_FONT_HEIGHT * VIDEO_PIXEL_SIZE;
345 
346     for (i=0; i<h-2; i++)
347     {
348     	video_drawchars_color(x1, y1, &st[3], 1, attr);
349 		y1 += VIDEO_FONT_HEIGHT * VIDEO_PIXEL_SIZE;
350 		video_drawchars_color(x2, y2, &st[4], 1, attr);
351 		y2 += VIDEO_FONT_HEIGHT * VIDEO_PIXEL_SIZE;
352     }
353 
354     // Draw title
355     if (title)
356     {
357 		if (separate == 0)
358 		{
359 		    x1 = xp + VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
360 		    y1 = yp;
361 		    video_drawchars_color(x1, y1, &ti[3], 1, attr);
362 		    x1 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
363 		    video_drawchars_color(x1, y1, " ", 1, attr);
364 		    x1 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
365 
366 		    //while (*title)
367 		    {
368 		    	video_drawchars_color(x1, y1, title, strlen(title), attr);
369 		    	x1 += strlen(title) * VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
370 		    	//title++;
371 		    }
372 
373 		    video_drawchars_color(x1, y1, " ", 1, attr);
374 		    x1 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
375 		    video_drawchars_color(x1, y1, &ti[4], 1, attr);
376 
377 		}
378 		else
379 		{
380 		    x1 = xp;
381 		    y1 = yp + 2 * VIDEO_FONT_HEIGHT * VIDEO_PIXEL_SIZE;
382 		    video_drawchars_color(x1, y1, &ti[0], 1, attr);
383 		    x1 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
384 
385 		    for (i=0; i<w-2; i++)
386 		    {
387 		    	video_drawchars_color(x1, y1, &ti[1], 1, attr);
388 				x1 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
389 		    }
390 
391 		    video_drawchars_color(x1, y1, &ti[2], 1, attr);
392 
393 		    x1 = xp + VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
394 		    y1 = yp + VIDEO_FONT_HEIGHT * VIDEO_PIXEL_SIZE;
395 
396 		    for (i=0; i<w-2; i++)
397 		    {
398 		    	video_drawchars_color(x1, y1, " ", 1, attr);
399 				x1 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
400 		    }
401 
402 			x1 = xp + 2 * VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
403 		    y1 = yp + VIDEO_FONT_HEIGHT * VIDEO_PIXEL_SIZE;
404 
405 	    	video_drawchars_color(x1, y1, title, strlen(title), attr);;
406 		}
407     }
408 }
409