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 = "=>";
60 void video_set_color(unsigned char attr)
62 unsigned char *fb = (unsigned char *)VIDEO_BASE;
65 current_attr = video_get_attr();
67 for (i=0; i<VIDEO_SIZE; i+=2)
69 *(fb+i+1) = current_attr;
73 unsigned char video_get_attr(void)
80 s = getenv("vga_fg_color");
86 s = getenv("vga_bg_color");
97 int drv_video_init(void)
99 int error, devices = 1 ;
101 if (video_inited) return 1;
104 memset (&vgadev, 0, sizeof(vgadev));
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;
112 vgadev.start = video_start;
114 error = device_register (&vgadev);
118 char *s = getenv("stdout");
119 if (s && strcmp(s, VIDEO_NAME)==0)
121 if (overwrite_console()) return 1;
122 error = console_assign(stdout, VIDEO_NAME);
123 if (error == 0) return 1;
134 cursor_position = VIDEO_BASE; /* Color text display base */
137 current_attr = video_get_attr(); /* Currently selected value for attribute. */
139 video_set_color(current_attr);
144 void video_set_cursor(int line, int column)
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);
154 void video_write_char(int character)
156 *cursor_position = character;
157 *(cursor_position+1) = current_attr;
160 void video_test(void)
165 void video_putc(char ch)
177 if (cursor_col) cursor_col--;
181 cursor_col = (cursor_col/8+1)*8;
184 video_write_char(ch);
186 if (cursor_col > VIDEO_COLS-1)
193 if (cursor_row > VIDEO_ROWS-1)
195 video_set_cursor(cursor_row, cursor_col);
198 void video_scroll(int rows)
200 unsigned short clear = ((unsigned short)current_attr) | (' '<<8);
201 unsigned short* addr16 = &((unsigned short *)VIDEO_BASE)[(VIDEO_ROWS-rows)*VIDEO_COLS];
205 s = getenv("vga_askscroll");
206 video_scrolls += rows;
208 if (video_scrolls >= video_numrows)
210 if (s && strcmp(s, "yes"))
212 while (-1 == tstc());
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++)
226 void video_puts(char *string)
235 int video_start(void)
240 unsigned char video_single_box[] =
247 unsigned char video_double_box[] =
254 unsigned char video_single_title[] =
256 195, 196, 180, 180, 195
259 unsigned char video_double_title[] =
261 204, 205, 185, 181, 198
267 unsigned char *video_addr(int x, int y)
269 return VIDEO_BASE + 2*(VIDEO_COLS*y) + 2*x;
272 void video_bios_print_string(char *s, int x, int y, int attr, int count)
274 int cattr = current_attr;
275 if (attr != -1) current_attr = attr;
276 video_set_cursor(x,y);
280 if (attr == -1) current_attr = *s++;
286 void video_draw_box(int style, int attr, char *title, int separate, int x, int y, int w, int h)
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;
293 fb = video_addr(x,y);
298 fb2 = video_addr(x,y+h-1);
322 fb = video_addr(x, y+1);
323 fb2 = video_addr(x+w-1, y+1);
324 for (i=0; i<h-2; i++)
327 *(fb+1) = attr; fb += 2*VIDEO_COLS;
330 *(fb2+1) = attr; fb2 += 2*VIDEO_COLS;
338 fb = video_addr(x+1, y);
356 fb = video_addr(x, y+2);
359 for (i=0; i<w-2; i++)
367 fb = video_addr(x+1, y+1);
368 for (i=0; i<w-2; i++)
374 fb = video_addr(x+2, y+1);
388 void video_draw_text(int x, int y, int attr, char *text)
390 unsigned char *fb = video_addr(x,y);
398 void video_save_rect(int x, int y, int w, int h, void *save_area, int clearchar, int clearattr)
400 unsigned char *save = (unsigned char *)save_area;
401 unsigned char *fb = video_addr(x,y);
405 unsigned char *fbb = fb;
409 if (clearchar > 0) *fb = clearchar;
412 if (clearattr > 0) *fb = clearattr;
414 fb = fbb + 2*VIDEO_COLS;
418 void video_restore_rect(int x, int y, int w, int h, void *save_area)
420 unsigned char *save = (unsigned char *)save_area;
421 unsigned char *fb = video_addr(x,y);
425 unsigned char *fbb = fb;
431 fb = fbb + 2*VIDEO_COLS;
446 void video_size(int cols, int rows)
448 video_numrows = rows;
449 video_numcols = cols;
452 void video_clear(void)
454 unsigned short *fbb = (unsigned short *)0xFD0B8000;
456 unsigned short val = 0x2000 | current_attr;
458 for (i=0; i<video_rows(); i++)
460 for (j=0; j<video_cols(); j++)
465 video_set_cursor(0,0);
471 int video_easteregg_active = 0;
473 void video_easteregg(void)
475 video_easteregg_active = 1;
479 extern block_dev_desc_t * ide_get_dev(int dev);
480 extern char version_string[];
482 void video_banner(void)
484 block_dev_desc_t *ide;
490 if (video_inited == 0) return;
492 if (video_easteregg_active)
497 printf(" **** COMMODORE 64 BASIC X2 ****\n\n");
498 printf(" 64K RAM SYSTEM 38911 BASIC BYTES FREE\n\n");
504 s = getenv("ide_maxbus");
506 maxdev = atoi(s) * 2;
510 s = getenv("stdout");
511 if (s && strcmp(s, "serial") == 0)
515 printf("%s\n\nCPU: ", version_string);
517 printf("DRAM: %ld MB\n", gd->bd->bi_memsize/(1024*1024));
518 printf("FSB: %ld MHz\n", gd->bd->bi_busfreq/1000000);
520 printf("\n---- Disk summary ----\n");
521 for (i = 0; i < maxdev; i++)
523 ide = ide_get_dev(i);
524 printf("Device %d: ", i);
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);
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");