]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/MAI/AmigaOneG3SE/video.c
imported Freescale specific U-Boot additions for i.MX28,... release L2.6.31_10.08.01
[karo-tx-uboot.git] / board / MAI / AmigaOneG3SE / video.c
1 /*
2  * (C) Copyright 2002
3  * Hyperion Entertainment, Hans-JoergF@hyperion-entertainment.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 #include <common.h>
25 #include <stdio_dev.h>
26 #include "memio.h"
27 #include <part.h>
28
29 DECLARE_GLOBAL_DATA_PTR;
30
31 unsigned char *cursor_position;
32 unsigned int cursor_row;
33 unsigned int cursor_col;
34
35 unsigned char current_attr;
36
37 unsigned int video_numrows = 25;
38 unsigned int video_numcols = 80;
39 unsigned int video_scrolls = 0;
40
41 #define VIDEO_BASE (unsigned char *)0xFD0B8000
42 #define VIDEO_ROWS video_numrows
43 #define VIDEO_COLS video_numcols
44 #define VIDEO_PITCH (2 * video_numcols)
45 #define VIDEO_SIZE (video_numrows * video_numcols * 2)
46 #define VIDEO_NAME "vga"
47
48 void video_test(void);
49 void video_putc(char ch);
50 void video_puts(char *string);
51 void video_scroll(int rows);
52 void video_banner(void);
53 int  video_init(void);
54 int  video_start(void);
55 int  video_rows(void);
56 int  video_cols(void);
57
58 char *prompt_string = "=>";
59 unsigned char video_get_attr(void);
60
61 void video_set_color(unsigned char attr)
62 {
63     unsigned char *fb = (unsigned char *)VIDEO_BASE;
64     int i;
65
66     current_attr = video_get_attr();
67
68     for (i=0; i<VIDEO_SIZE; i+=2)
69     {
70         *(fb+i+1) = current_attr;
71     }
72 }
73
74 unsigned char video_get_attr(void)
75 {
76     char *s;
77     unsigned char attr;
78
79     attr = 0x0f;
80
81     s = getenv("vga_fg_color");
82     if (s)
83     {
84         attr = atoi(s);
85     }
86
87     s = getenv("vga_bg_color");
88     if (s)
89     {
90         attr |= atoi(s)<<4;
91     }
92
93     return attr;
94 }
95
96 int video_inited = 0;
97
98 int drv_video_init(void)
99 {
100     int error, devices = 1 ;
101     struct stdio_dev vgadev ;
102     if (video_inited) return 1;
103     video_inited = 1;
104     video_init();
105     memset (&vgadev, 0, sizeof(vgadev));
106
107     strcpy(vgadev.name, VIDEO_NAME);
108     vgadev.flags =  DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM;
109     vgadev.putc = video_putc;
110     vgadev.puts = video_puts;
111     vgadev.getc = NULL;
112     vgadev.tstc = NULL;
113     vgadev.start = video_start;
114
115     error = stdio_register (&vgadev);
116
117     if (error == 0)
118     {
119         char *s = getenv("stdout");
120         if (s && strcmp(s, VIDEO_NAME)==0)
121         {
122             if (overwrite_console()) return 1;
123             error = console_assign(stdout, VIDEO_NAME);
124             if (error == 0) return 1;
125             else return error;
126         }
127         return 1;
128     }
129
130     return error;
131 }
132
133 int video_init(void)
134 {
135     cursor_position = VIDEO_BASE; /* Color text display base */
136     cursor_row = 0;
137     cursor_col = 0;
138     current_attr = video_get_attr(); /* Currently selected value for attribute. */
139 /*    video_test(); */
140     video_set_color(current_attr);
141
142     return 0;
143 }
144
145 void video_set_cursor(int line, int column)
146 {
147     unsigned short offset = line*video_numcols + column;
148     cursor_position = VIDEO_BASE +  line*VIDEO_PITCH + column*2;
149     out_byte(0x3D4, 0x0E);
150     out_byte(0x3D5, offset/256);
151     out_byte(0x3D4, 0x0F);
152     out_byte(0x3D5, offset%256);
153 }
154
155 void video_write_char(int character)
156 {
157     *cursor_position = character;
158     *(cursor_position+1) = current_attr;
159 }
160
161 void video_test(void)
162 {
163
164 }
165
166 void video_putc(char ch)
167 {
168     switch(ch)
169     {
170     case '\n':
171         cursor_col = 0;
172         cursor_row += 1;
173         break;
174     case '\r':
175         cursor_col = 0;
176         break;
177     case '\b':
178         if (cursor_col) cursor_col--;
179         else return;
180         break;
181     case '\t':
182         cursor_col = (cursor_col/8+1)*8;
183         break;
184     default:
185         video_write_char(ch);
186         cursor_col++;
187         if (cursor_col > VIDEO_COLS-1)
188         {
189             cursor_row++;
190             cursor_col=0;
191         }
192     }
193
194     if (cursor_row > VIDEO_ROWS-1)
195         video_scroll(1);
196     video_set_cursor(cursor_row, cursor_col);
197 }
198
199 void video_scroll(int rows)
200 {
201     unsigned short clear = ((unsigned short)current_attr) | (' '<<8);
202     unsigned short* addr16 = &((unsigned short *)VIDEO_BASE)[(VIDEO_ROWS-rows)*VIDEO_COLS];
203     int i;
204     char *s;
205
206     s = getenv("vga_askscroll");
207     video_scrolls += rows;
208
209     if (video_scrolls >= video_numrows)
210     {
211         if (s && strcmp(s, "yes"))
212         {
213             while (-1 == tstc());
214         }
215
216         video_scrolls = 0;
217     }
218
219
220     memcpy(VIDEO_BASE, VIDEO_BASE+rows*(VIDEO_COLS*2), (VIDEO_ROWS-rows)*(VIDEO_COLS*2));
221     for (i = 0 ; i < rows * VIDEO_COLS ; i++)
222         addr16[i] = clear;
223     cursor_row-=rows;
224     cursor_col=0;
225 }
226
227 void video_puts(char *string)
228 {
229     while (*string)
230     {
231         video_putc(*string);
232         string++;
233     }
234 }
235
236 int video_start(void)
237 {
238     return 0;
239 }
240
241 unsigned char video_single_box[] =
242 {
243     218, 196, 191,
244     179,      179,
245     192, 196, 217
246 };
247
248 unsigned char video_double_box[] =
249 {
250     201, 205, 187,
251     186,      186,
252     200, 205, 188
253 };
254
255 unsigned char video_single_title[] =
256 {
257     195, 196, 180, 180, 195
258 };
259
260 unsigned char video_double_title[] =
261 {
262     204, 205, 185, 181, 198
263 };
264
265 #define SINGLE_BOX 0
266 #define DOUBLE_BOX 1
267
268 unsigned char *video_addr(int x, int y)
269 {
270     return VIDEO_BASE + 2*(VIDEO_COLS*y) + 2*x;
271 }
272
273 void video_bios_print_string(char *s, int x, int y, int attr, int count)
274 {
275     int cattr = current_attr;
276     if (attr != -1) current_attr = attr;
277     video_set_cursor(x,y);
278     while (count)
279     {
280         char c = *s++;
281         if (attr == -1) current_attr = *s++;
282         video_putc(c);
283         count--;
284     }
285 }
286
287 void video_draw_box(int style, int attr, char *title, int separate, int x, int y, int w, int h)
288 {
289     unsigned char *fb, *fb2;
290     unsigned char *st = (style == SINGLE_BOX)?video_single_box : video_double_box;
291     unsigned char *ti = (style == SINGLE_BOX)?video_single_title : video_double_title;
292     int i;
293
294     fb = video_addr(x,y);
295     *(fb) = st[0];
296     *(fb+1) = attr;
297     fb += 2;
298
299     fb2 = video_addr(x,y+h-1);
300     *(fb2) = st[5];
301     *(fb2+1) = attr;
302     fb2 += 2;
303
304     for (i=0; i<w-2;i++)
305     {
306         *fb = st[1];
307         fb++;
308         *fb = attr;
309         fb++;
310
311         *fb2 = st[6];
312         fb2++;
313         *fb2 = attr;
314         fb2++;
315
316     }
317     *fb = st[2];
318     *(fb+1) = attr;
319
320     *fb2 = st[7];
321     *(fb2+1) = attr;
322
323     fb  = video_addr(x, y+1);
324     fb2 = video_addr(x+w-1, y+1);
325     for (i=0; i<h-2; i++)
326     {
327         *fb = st[3];
328         *(fb+1) = attr; fb += 2*VIDEO_COLS;
329
330         *fb2 = st[4];
331         *(fb2+1) = attr; fb2 += 2*VIDEO_COLS;
332     }
333
334     /* Draw title */
335     if (title)
336     {
337         if (separate == 0)
338         {
339             fb = video_addr(x+1, y);
340             *fb = ti[3];
341             fb += 2;
342             *fb = ' ';
343             fb += 2;
344             while (*title)
345             {
346                 *fb = *title;
347                 fb ++;
348                 *fb = attr;
349                 fb++; title++;
350             }
351             *fb = ' ';
352             fb += 2;
353             *fb = ti[4];
354         }
355         else
356         {
357             fb = video_addr(x, y+2);
358             *fb = ti[0];
359             fb += 2;
360             for (i=0; i<w-2; i++)
361             {
362                 *fb = ti[1];
363                 *(fb+1) = attr;
364                 fb += 2;
365             }
366             *fb = ti[2];
367             *(fb+1) = attr;
368             fb = video_addr(x+1, y+1);
369             for (i=0; i<w-2; i++)
370             {
371                 *fb = ' ';
372                 *(fb+1) = attr;
373                 fb += 2;
374             }
375             fb = video_addr(x+2, y+1);
376
377             while (*title)
378             {
379                 *fb = *title;
380                 *(fb+1) = attr;
381                 fb += 2;
382                 title++;
383             }
384         }
385     }
386
387 }
388
389 void video_draw_text(int x, int y, int attr, char *text)
390 {
391     unsigned char *fb = video_addr(x,y);
392     while (*text)
393     {
394         *fb++ = *text++;
395         *fb++ = attr;
396     }
397 }
398
399 void video_save_rect(int x, int y, int w, int h, void *save_area, int clearchar, int clearattr)
400 {
401     unsigned char *save = (unsigned char *)save_area;
402     unsigned char *fb = video_addr(x,y);
403     int i,j;
404     for (i=0; i<h; i++)
405     {
406         unsigned char *fbb = fb;
407         for (j=0; j<w; j++)
408         {
409             *save ++ = *fb;
410             if (clearchar > 0) *fb = clearchar;
411             fb ++;
412             *save ++ = *fb;
413             if (clearattr > 0) *fb = clearattr;
414         }
415         fb = fbb + 2*VIDEO_COLS;
416     }
417 }
418
419 void video_restore_rect(int x, int y, int w, int h, void *save_area)
420 {
421     unsigned char *save = (unsigned char *)save_area;
422     unsigned char *fb = video_addr(x,y);
423     int i,j;
424     for (i=0; i<h; i++)
425     {
426         unsigned char *fbb = fb;
427         for (j=0; j<w; j++)
428         {
429             *fb ++ = *save ++;
430             *fb ++ = *save ++;
431         }
432         fb = fbb + 2*VIDEO_COLS;
433     }
434
435 }
436
437 int video_rows(void)
438 {
439     return VIDEO_ROWS;
440 }
441
442 int video_cols(void)
443 {
444     return VIDEO_COLS;
445 }
446
447 void video_size(int cols, int rows)
448 {
449     video_numrows = rows;
450     video_numcols = cols;
451 }
452
453 void video_clear(void)
454 {
455     unsigned short *fbb = (unsigned short *)0xFD0B8000;
456     int i,j;
457     unsigned short val = 0x2000 | current_attr;
458
459     for (i=0; i<video_rows(); i++)
460     {
461         for (j=0; j<video_cols(); j++)
462         {
463             *fbb++ = val;
464         }
465     }
466     video_set_cursor(0,0);
467     cursor_row = 0;
468     cursor_col = 0;
469 }
470
471 #ifdef EASTEREGG
472 int video_easteregg_active = 0;
473
474 void video_easteregg(void)
475 {
476     video_easteregg_active = 1;
477 }
478 #endif
479
480 extern block_dev_desc_t * ide_get_dev(int dev);
481 extern char version_string[];
482
483 void video_banner(void)
484 {
485     block_dev_desc_t *ide;
486     int i;
487     char *s;
488     int maxdev;
489
490
491     if (video_inited == 0) return;
492 #ifdef EASTEREGG
493     if (video_easteregg_active)
494     {
495         prompt_string="";
496         video_clear();
497         printf("\n");
498         printf("    **** COMMODORE 64 BASIC X2 ****\n\n");
499         printf(" 64K RAM SYSTEM  38911 BASIC BYTES FREE\n\n");
500         printf("READY\n");
501     }
502     else
503     {
504 #endif
505         s = getenv("ide_maxbus");
506         if (s)
507             maxdev = atoi(s) * 2;
508         else
509             maxdev = 4;
510
511         s = getenv("stdout");
512         if (s && strcmp(s, "serial") == 0)
513             return;
514
515         video_clear();
516         printf("%s\n\nCPU: ", version_string);
517         checkcpu();
518         printf("DRAM: %ld MB\n", gd->bd->bi_memsize/(1024*1024));
519         printf("FSB: %ld MHz\n", gd->bd->bi_busfreq/1000000);
520
521         printf("\n---- Disk summary ----\n");
522         for (i = 0; i < maxdev; i++)
523         {
524             ide = ide_get_dev(i);
525             printf("Device %d: ", i);
526             dev_print(ide);
527         }
528
529 /*
530     video_draw_box(SINGLE_BOX, 0x0F, "Test 1", 0, 0,18, 72, 4);
531     video_draw_box(DOUBLE_BOX, 0x0F, "Test 2", 1, 4,10, 50, 6);
532     video_draw_box(DOUBLE_BOX, 0x0F, "Test 3", 0, 40, 3, 20, 5);
533
534     video_draw_text(1, 4, 0x2F, "Highlighted options");
535     video_draw_text(1, 5, 0x0F, "Non-selected option");
536     video_draw_text(1, 6, 0x07, "disabled option");
537 */
538 #ifdef EASTEREGG
539     }
540 #endif
541 }