Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / openbios / packages / molvideo.c
1 /*
2  *   Creation Date: <2002/10/23 20:26:40 samuel>
3  *   Time-stamp: <2004/01/07 19:39:15 samuel>
4  *
5  *      <molvideo.c>
6  *
7  *      Mac-on-Linux display node
8  *
9  *   Copyright (C) 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
10  *
11  *   This program is free software; you can redistribute it and/or
12  *   modify it under the terms of the GNU General Public License
13  *   as published by the Free Software Foundation
14  *
15  */
16
17 #include "config.h"
18 #include "libopenbios/bindings.h"
19 #include "libc/diskio.h"
20 #include "libopenbios/ofmem.h"
21 #include "drivers/drivers.h"
22 #include "packages/video.h"
23 #include "libopenbios/video.h"
24 #include "drivers/vga.h"
25
26
27 /************************************************************************/
28 /*      OF methods                                                      */
29 /************************************************************************/
30
31 DECLARE_NODE( video, 0, 0, "Tdisplay" );
32
33 /* ( r g b index -- ) */
34 static void
35 molvideo_color_bang( void )
36 {
37         int index = POP();
38         int b = POP();
39         int g = POP();
40         int r = POP();
41         unsigned long col = ((r << 16) & 0xff0000) | ((g << 8) & 0x00ff00) | (b & 0xff);
42         /* printk("color!: %08lx %08lx %08lx %08lx\n", r, g, b, index ); */
43
44         if( VIDEO_DICT_VALUE(video.depth) == 8 ) {
45                 OSI_SetColor( index, col );
46                 OSI_RefreshPalette();
47         }
48 }
49
50 /* ( -- ) - really should be reworked as draw-logo */
51 static void
52 molvideo_startup_splash( void )
53 {
54         int fd, s, i, y, x, dx, dy;
55         int width, height;
56         char *pp, *p;
57         char buf[64];
58
59         /* only draw logo in 24-bit mode (for now) */
60         if( VIDEO_DICT_VALUE(video.depth) < 15 )
61                 return;
62
63         for( i=0; i<2; i++ ) {
64                 if( !BootHGetStrResInd("bootlogo", buf, sizeof(buf), 0, i) )
65                         return;
66                 *(!i ? &width : &height) = atol(buf);
67         }
68
69         if( (s=width * height * 3) > 0x20000 )
70                 return;
71
72         if( (fd=open_io("pseudo:,bootlogo")) >= 0 ) {
73                 p = malloc( s );
74                 if( read_io(fd, p, s) != s )
75                         printk("bootlogo size error\n");
76                 close_io( fd );
77
78                 dx = (VIDEO_DICT_VALUE(video.w) - width)/2;
79                 dy = (VIDEO_DICT_VALUE(video.h) - height)/3;
80
81                 pp = (char*)VIDEO_DICT_VALUE(video.mvirt) + dy * VIDEO_DICT_VALUE(video.rb) + dx * (VIDEO_DICT_VALUE(video.depth) >= 24 ? 4 : 2);
82
83                 for( y=0 ; y<height; y++, pp += VIDEO_DICT_VALUE(video.rb) ) {
84                         if( VIDEO_DICT_VALUE(video.depth) >= 24 ) {
85                                 unsigned long *d = (unsigned long*)pp;
86                                 for( x=0; x<width; x++, p+=3, d++ )
87                                         *d = ((int)p[0] << 16) | ((int)p[1] << 8) | p[2];
88                         } else if( VIDEO_DICT_VALUE(video.depth) == 15 ) {
89                                 unsigned short *d = (unsigned short*)pp;
90                                 for( x=0; x<width; x++, p+=3, d++ ) {
91                                         int col = ((int)p[0] << 16) | ((int)p[1] << 8) | p[2];
92                                         *d = ((col>>9) & 0x7c00) | ((col>>6) & 0x03e0) | ((col>>3) & 0x1f);
93                                 }
94                         }
95                 }
96                 free( p );
97         }
98
99         /* No bootlogo support yet on other platforms */
100         return;
101 }
102
103
104 NODE_METHODS( video ) = {
105         {"mol-startup-splash",  molvideo_startup_splash },
106 };
107
108
109 /************************************************************************/
110 /*      init                                                            */
111 /************************************************************************/
112
113 void
114 molvideo_init(void)
115 {
116         xt_t color_bang;
117
118         REGISTER_NODE( video );
119
120         /* Bind the MOL graphic routines to the mol-color! defer */
121         color_bang = bind_noname_func(molvideo_color_bang);
122         PUSH(color_bang);
123         feval(" to mol-color!");
124 }