]> git.ozlabs.org Git - yaboot.git/blob - second/gui/video.c
Commit yaboot 1.3.3
[yaboot.git] / second / gui / video.c
1 #include "prom.h"
2
3 #define WINDOW_X_SIZE 640
4 #define WINDOW_Y_SIZE 480
5
6
7 static prom_handle videodev;
8 static prom_handle videop;
9 static int Xres, Yres;
10 static int Xstart, Ystart;
11 static int rowbytes;
12 static int zoom;
13 static unsigned char *address;
14
15 static int scrSetColorMap( unsigned char color,
16         unsigned char r, unsigned char g, unsigned char b );
17
18
19 int scrOpen()
20 {
21   int result = 0;
22  
23   videodev = (prom_handle)call_prom( "open", 1, 1, "screen" );
24   if( videodev == PROM_INVALID_HANDLE )
25      return(-1);
26   videop = (prom_handle)call_prom( "instance-to-package", 1, 1, videodev );
27   if( videop == PROM_INVALID_HANDLE )
28      return(-1);
29
30   result |= prom_getprop(videop, "width", &Xres, 4 );
31   result |= prom_getprop(videop, "height", &Yres, 4 );
32   result |= prom_getprop(videop, "address", &address, 4 );
33   result |= prom_getprop(videop, "linebytes", &rowbytes, 4 );
34
35   prom_map (address, address, rowbytes * Xres);
36
37 #if DEBUG
38   prom_printf("width     : %d\n", Xres);
39   prom_printf("height    : %d\n", Yres);
40   prom_printf("address   : 0x%08lx\n", address);
41   prom_printf("linebytes : %d\n", rowbytes);
42   prom_printf("result    : %d\n", result);
43 #endif
44  
45   if( result < 0 )
46      return( -1 );
47
48   zoom = Xres / WINDOW_X_SIZE > Yres / WINDOW_Y_SIZE ? Yres / WINDOW_Y_SIZE : Xres / WINDOW_X_SIZE;
49
50   Xstart = Xres / 2 - WINDOW_X_SIZE / 2 * zoom;
51   Ystart = Yres / 2 - WINDOW_Y_SIZE / 2 * zoom;
52
53 #if DEBUG
54   prom_printf("zoom      : %d\n", zoom);
55   prom_printf("Xstart    : %d\n", Xstart);
56   prom_printf("Ystart    : %d\n", Ystart);
57 #endif
58
59   return( 0 );
60 }
61
62
63 void scrClear( unsigned char c )
64 {
65   int x, y;
66
67   for (y = 0; y < Yres; y++)
68         for (x = 0; x < Xres; x++)
69                 address[y * rowbytes + x] = c;
70 }
71
72
73 void scrClose()
74 {
75   call_prom( "close", 1, 0, videodev );
76   videodev = 0;
77 }
78
79
80 void scrReset()
81 {
82   int c;
83   extern unsigned char color_table_red[],
84                        color_table_green[],
85                        color_table_blue[];
86
87   for( c = 0; c < 16; ++c )
88      scrSetColorMap( c, color_table_red[c],
89                         color_table_green[c],
90                         color_table_blue[c] );
91 //  scrClose();
92 }
93
94 static void inline do_pix( int x, int y, unsigned char c )
95 {
96   address[ y * rowbytes + x ] = c;
97 }
98
99
100 void scrPutPixel( int x, int y, unsigned char c )
101 {
102   int zx, zy;
103
104   for( zy = 0; zy < zoom; ++zy )
105      for( zx = 0; zx < zoom; ++zx )
106         do_pix( x * zoom + zx + Xstart, y * zoom + zy + Ystart, c );
107 }
108
109
110 int scrSetColorMap( unsigned char color, unsigned char r, unsigned char g, unsigned char b )
111 {
112   int result;
113
114   result = (int)call_prom( "call-method", 6, 1, "color!", videodev, color, b, g, r );
115
116   return( result );
117 }
118
119
120 void scrFillColorMap( unsigned char r, unsigned char g, unsigned char b )
121 {
122   int c;
123
124   for( c = 0; c < 256; ++c )
125      scrSetColorMap( c, r, g, b );
126 }
127
128
129 void scrSetEntireColorMap( unsigned char *map )
130 {
131   int c;
132
133   for( c = 0; c < 256; ++c )
134      scrSetColorMap( c, map[c * 3], map[c * 3 + 1], map[c * 3 + 2] );
135 }
136
137
138 void scrFadeColorMap( unsigned char *first, unsigned char *last, int rate )
139 {
140   int inc, c;
141
142   for( inc = 0; inc < 256; inc += rate )
143      for( c = 0; c < 256; ++c )
144         scrSetColorMap( c, first[c * 3 + 0] * (255 - inc) / 255 + last[c * 3 + 0] * inc / 255,
145                            first[c * 3 + 1] * (255 - inc) / 255 + last[c * 3 + 1] * inc / 255,
146                            first[c * 3 + 2] * (255 - inc) / 255 + last[c * 3 + 2] * inc / 255 );
147 }