Rev 81 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
54 | pj | 1 | /* VGAlib version 1.2 - (c) 1993 Tommy Frandsen */ |
2 | /* */ |
||
3 | /* This library is free software; you can redistribute it and/or */ |
||
4 | /* modify it without any restrictions. This library is distributed */ |
||
5 | /* in the hope that it will be useful, but without any warranty. */ |
||
6 | |||
7 | /* Multi-chipset support Copyright 1993 Harm Hanemaayer */ |
||
8 | /* partially copyrighted (C) 1993 by Hartmut Schirmer */ |
||
9 | |||
10 | /* Converted to especially ugly code and seriously hacked for Mach32: */ |
||
11 | /* M. Weller in 1994 */ |
||
12 | #include <stdlib.h> |
||
13 | |||
14 | #include "vga.h" |
||
15 | #include "vgaio.h" |
||
16 | #include "libvga.h" |
||
17 | #include "driver.h" |
||
18 | |||
19 | /* |
||
20 | * In grayscale mode, we convert RGB colors to a Y component on the |
||
21 | * green-channel (the Y component is used in grayscale TV sets for the |
||
22 | * same purpose and corresponds to the "brightness" of the color as |
||
23 | * perceived by the human eye. In order to be able to return to the |
||
24 | * user the original green-component, we save a backup copy of the |
||
25 | * green channel in __svgalib_green_backup: |
||
26 | */ |
||
27 | int __svgalib_green_backup[256]; |
||
28 | |||
29 | |||
30 | static int set_lut(int index, int red, int green, int blue) |
||
31 | { |
||
32 | if (__svgalib_novga) return 1; |
||
33 | |||
34 | /* prevents lockups */ |
||
35 | if ((__svgalib_chipset == MACH64)) { |
||
36 | outb(0x02ec+0x5c00,index); |
||
37 | outb(0x02ec+0x5c01,red); |
||
38 | outb(0x02ec+0x5c01,green); |
||
39 | outb(0x02ec+0x5c01,blue); |
||
40 | return 0; |
||
41 | } |
||
42 | |||
43 | __svgalib_outpal(index,red,green,blue); |
||
44 | |||
45 | return 0; |
||
46 | } |
||
47 | |||
48 | |||
49 | static int get_lut(int index, int *red, int *green, int *blue) |
||
50 | { |
||
51 | if (__svgalib_novga) return 0; |
||
52 | |||
53 | /* prevents lockups on mach64 */ |
||
54 | if ((__svgalib_chipset == MACH64)) { |
||
55 | outb(0x02ec+0x5c00,index); |
||
56 | *red=port_in(0x02ec+0x5c01); |
||
57 | *green=port_in(0x02ec+0x5c01); |
||
58 | *blue=port_in(0x02ec+0x5c01); |
||
59 | return 0; |
||
60 | } |
||
61 | |||
62 | __svgalib_inpal(index,red,green,blue); |
||
63 | |||
64 | return 0; |
||
65 | } |
||
66 | |||
67 | int vga_setpalette(int index, int red, int green, int blue) |
||
68 | { |
||
69 | |||
70 | DTP((stderr,"setpalette %i %i %i %i\n",index,red,green,blue)); |
||
71 | |||
72 | if (__svgalib_grayscale) { |
||
73 | if ((unsigned) index >= sizeof(__svgalib_green_backup) / sizeof(__svgalib_green_backup[0])) { |
||
74 | fprintf(stderr,"vga_setpalette: color index %d out of range\n", index); |
||
75 | } |
||
76 | __svgalib_green_backup[index] = green; |
||
77 | |||
78 | green = 0.299 * red + 0.587 * green + 0.114 * blue; |
||
79 | if (green < 0) |
||
80 | green = 0; |
||
81 | if (green > 255) |
||
82 | green = 255; |
||
83 | } |
||
84 | |||
85 | if (__svgalib_driverspecs->emul && __svgalib_driverspecs->emul->setpalette) { |
||
86 | return __svgalib_driverspecs->emul->setpalette(index, red, green, blue); |
||
87 | } else { |
||
88 | return set_lut(index, red, green, blue); |
||
89 | } |
||
90 | } |
||
91 | |||
92 | int vga_getpalette(int index, int *red, int *green, int *blue) |
||
93 | { |
||
94 | if (__svgalib_driverspecs->emul && __svgalib_driverspecs->emul->getpalette) |
||
95 | __svgalib_driverspecs->emul->getpalette(index, red, green, blue); |
||
96 | else get_lut(index, red, green, blue); |
||
97 | if (__svgalib_grayscale) { |
||
98 | if ((unsigned) index >= sizeof(__svgalib_green_backup) / sizeof(__svgalib_green_backup[0])) { |
||
99 | fprintf(stderr,"vga_getpalette: color index %d out of range\n", index); |
||
100 | } |
||
101 | *green = __svgalib_green_backup[index]; |
||
102 | } |
||
103 | return 0; |
||
104 | } |
||
105 | |||
106 | |||
107 | int vga_setpalvec(int start, int num, int *pal) |
||
108 | { |
||
109 | int i; |
||
110 | |||
111 | DTP((stderr,"setpalvec %i %i %x\n",start,num,pal)); |
||
112 | |||
113 | if ((__svgalib_driverspecs->emul && __svgalib_driverspecs->emul->setpalette) || |
||
114 | (__svgalib_outpal!=__svgalib_vga_outpal)) { |
||
115 | for (i = start; i < start + num; ++i) { |
||
116 | vga_setpalette(i, pal[0], pal[1], pal[2]); |
||
117 | pal += 3; |
||
118 | } |
||
119 | } else { |
||
120 | unsigned char string[768]; |
||
121 | |||
122 | if ( num > 256 ) |
||
123 | return 0; |
||
124 | |||
125 | for (i = 0; i < num * 3; i++) |
||
126 | string[i] = pal[i]; |
||
127 | |||
128 | port_out ( start, 0x3c8 ); |
||
129 | #if 0 |
||
130 | port_rep_outb( string, num * 3, 0x3c9 ); |
||
131 | #else |
||
132 | for(i=0;i<num*3;i++)port_out(string[i],0x3c9); |
||
133 | #endif |
||
134 | } |
||
135 | |||
136 | return num; |
||
137 | } |
||
138 | |||
139 | |||
140 | int vga_getpalvec(int start, int num, int *pal) |
||
141 | { |
||
142 | int i; |
||
143 | |||
144 | for (i = start; i < start + num; ++i) { |
||
145 | vga_getpalette(i, pal + 0, pal + 1, pal + 2); |
||
146 | pal += 3; |
||
147 | } |
||
148 | return num; |
||
149 | } |