3 * Hyperion Entertainment, Hans-JoergF@hyperion-entertainment.com
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
29 DECLARE_GLOBAL_DATA_PTR;
31 unsigned char *cursor_position;
32 unsigned int cursor_row;
33 unsigned int cursor_col;
35 unsigned char current_attr;
37 unsigned int video_numrows = 25;
38 unsigned int video_numcols = 80;
39 unsigned int video_scrolls = 0;
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"
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);
54 int video_start(void);
58 char *prompt_string = "=>";
59 unsigned char video_get_attr(void);
61 void video_set_color(unsigned char attr)
63 unsigned char *fb = (unsigned char *)VIDEO_BASE;
66 current_attr = video_get_attr();
68 for (i=0; i<VIDEO_SIZE; i+=2)
70 *(fb+i+1) = current_attr;
74 unsigned char video_get_attr(void)
81 s = getenv("vga_fg_color");
87 s = getenv("vga_bg_color");
98 int drv_video_init(void)
100 int error, devices = 1 ;
102 if (video_inited) return 1;
105 memset (&vgadev, 0, sizeof(vgadev));
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;
113 vgadev.start = video_start;
115 error = device_register (&vgadev);
119 char *s = getenv("stdout");
120 if (s && strcmp(s, VIDEO_NAME)==0)
122 if (overwrite_console()) return 1;
123 error = console_assign(stdout, VIDEO_NAME);
124 if (error == 0) return 1;
135 cursor_position = VIDEO_BASE; /* Color text display base */
138 current_attr = video_get_attr(); /* Currently selected value for attribute. */
140 video_set_color(current_attr);
145 void video_set_cursor(int line, int column)
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);
155 void video_write_char(int character)
157 *cursor_position = character;
158 *(cursor_position+1) = current_attr;
161 void video_test(void)
166 void video_putc(char ch)
178 if (cursor_col) cursor_col--;
182 cursor_col = (cursor_col/8+1)*8;
185 video_write_char(ch);
187 if (cursor_col > VIDEO_COLS-1)
194 if (cursor_row > VIDEO_ROWS-1)
196 video_set_cursor(cursor_row, cursor_col);
199 void video_scroll(int rows)
201 unsigned short clear = ((unsigned short)current_attr) | (' '<<8);
202 unsigned short* addr16 = &((unsigned short *)VIDEO_BASE)[(VIDEO_ROWS-rows)*VIDEO_COLS];
206 s = getenv("vga_askscroll");
207 video_scrolls += rows;
209 if (video_scrolls >= video_numrows)
211 if (s && strcmp(s, "yes"))
213 while (-1 == tstc());
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++)
227 void video_puts(char *string)
236 int video_start(void)
241 unsigned char video_single_box[] =
248 unsigned char video_double_box[] =
255 unsigned char video_single_title[] =
257 195, 196, 180, 180, 195
260 unsigned char video_double_title[] =
262 204, 205, 185, 181, 198
268 unsigned char *video_addr(int x, int y)
270 return VIDEO_BASE + 2*(VIDEO_COLS*y) + 2*x;
273 void video_bios_print_string(char *s, int x, int y, int attr, int count)
275 int cattr = current_attr;
276 if (attr != -1) current_attr = attr;
277 video_set_cursor(x,y);
281 if (attr == -1) current_attr = *s++;
287 void video_draw_box(int style, int attr, char *title, int separate, int x, int y, int w, int h)
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;
294 fb = video_addr(x,y);
299 fb2 = video_addr(x,y+h-1);
323 fb = video_addr(x, y+1);
324 fb2 = video_addr(x+w-1, y+1);
325 for (i=0; i<h-2; i++)
328 *(fb+1) = attr; fb += 2*VIDEO_COLS;
331 *(fb2+1) = attr; fb2 += 2*VIDEO_COLS;
339 fb = video_addr(x+1, y);
357 fb = video_addr(x, y+2);
360 for (i=0; i<w-2; i++)
368 fb = video_addr(x+1, y+1);
369 for (i=0; i<w-2; i++)
375 fb = video_addr(x+2, y+1);
389 void video_draw_text(int x, int y, int attr, char *text)
391 unsigned char *fb = video_addr(x,y);
399 void video_save_rect(int x, int y, int w, int h, void *save_area, int clearchar, int clearattr)
401 unsigned char *save = (unsigned char *)save_area;
402 unsigned char *fb = video_addr(x,y);
406 unsigned char *fbb = fb;
410 if (clearchar > 0) *fb = clearchar;
413 if (clearattr > 0) *fb = clearattr;
415 fb = fbb + 2*VIDEO_COLS;
419 void video_restore_rect(int x, int y, int w, int h, void *save_area)
421 unsigned char *save = (unsigned char *)save_area;
422 unsigned char *fb = video_addr(x,y);
426 unsigned char *fbb = fb;
432 fb = fbb + 2*VIDEO_COLS;
447 void video_size(int cols, int rows)
449 video_numrows = rows;
450 video_numcols = cols;
453 void video_clear(void)
455 unsigned short *fbb = (unsigned short *)0xFD0B8000;
457 unsigned short val = 0x2000 | current_attr;
459 for (i=0; i<video_rows(); i++)
461 for (j=0; j<video_cols(); j++)
466 video_set_cursor(0,0);
472 int video_easteregg_active = 0;
474 void video_easteregg(void)
476 video_easteregg_active = 1;
480 extern block_dev_desc_t * ide_get_dev(int dev);
481 extern char version_string[];
483 void video_banner(void)
485 block_dev_desc_t *ide;
491 if (video_inited == 0) return;
493 if (video_easteregg_active)
498 printf(" **** COMMODORE 64 BASIC X2 ****\n\n");
499 printf(" 64K RAM SYSTEM 38911 BASIC BYTES FREE\n\n");
505 s = getenv("ide_maxbus");
507 maxdev = atoi(s) * 2;
511 s = getenv("stdout");
512 if (s && strcmp(s, "serial") == 0)
516 printf("%s\n\nCPU: ", version_string);
518 printf("DRAM: %ld MB\n", gd->bd->bi_memsize/(1024*1024));
519 printf("FSB: %ld MHz\n", gd->bd->bi_busfreq/1000000);
521 printf("\n---- Disk summary ----\n");
522 for (i = 0; i < maxdev; i++)
524 ide = ide_get_dev(i);
525 printf("Device %d: ", i);
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);
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");