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