2
* $RCSId: xc/programs/Xserver/hw/kdrive/vesa/vga.c,v 1.1 2000/10/20 00:19:51 keithp Exp $
4
* Copyright � 2000 Keith Packard
6
* Permission to use, copy, modify, distribute, and sell this software and its
7
* documentation for any purpose is hereby granted without fee, provided that
8
* the above copyright notice appear in all copies and that both that
9
* copyright notice and this permission notice appear in supporting
10
* documentation, and that the name of Keith Packard not be used in
11
* advertising or publicity pertaining to distribution of the software without
12
* specific, written prior permission. Keith Packard makes no
13
* representations about the suitability of this software for any purpose. It
14
* is provided "as is" without express or implied warranty.
16
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22
* PERFORMANCE OF THIS SOFTWARE.
26
#include <kdrive-config.h>
30
static const VesaModeRec vgaModes[] = {
33
MODE_SUPPORTED | MODE_GRAPHICS | MODE_VGA | MODE_LINEAR,
35
0, 0, 0, 0, 0, 0, 0, 0, 0,
40
MODE_SUPPORTED | MODE_GRAPHICS | MODE_VGA | MODE_COLOUR,
42
0, 0, 0, 0, 0, 0, 0, 0, 0,
47
MODE_SUPPORTED | MODE_GRAPHICS | MODE_VGA | MODE_COLOUR,
49
0, 0, 0, 0, 0, 0, 0, 0, 0,
54
MODE_SUPPORTED | MODE_GRAPHICS | MODE_VGA | MODE_COLOUR,
56
0, 0, 0, 0, 0, 0, 0, 0, 0,
61
MODE_SUPPORTED | MODE_GRAPHICS | MODE_VGA | MODE_LINEAR,
63
0, 0, 0, 0, 0, 0, 0, 0, 0,
68
MODE_SUPPORTED | MODE_GRAPHICS | MODE_VGA | MODE_COLOUR,
70
0, 0, 0, 0, 0, 0, 0, 0, 0,
75
MODE_SUPPORTED | MODE_GRAPHICS | MODE_VGA | MODE_COLOUR | MODE_LINEAR,
77
0, 0, 0, 0, 0, 0, 0, 0, 0,
82
#define NUM_VGA_MODE (sizeof vgaModes / sizeof vgaModes[0])
85
VgaGetNmode (Vm86InfoPtr vi)
91
VgaGetModes (Vm86InfoPtr vi, VesaModePtr mode, int nmode)
93
if (nmode > NUM_VGA_MODE)
95
memcpy (mode, vgaModes, nmode * sizeof (VesaModeRec));
100
VgaSetMode(Vm86InfoPtr vi, int mode)
104
vi->vms.regs.eax = mode & 0x7f;
105
code = Vm86DoInterrupt (vi, 0x10);
112
VgaGetMode (Vm86InfoPtr vi, int *mode)
114
*mode = Vm86Memory (vi, 0x449);
119
VgaSetWritePlaneMask(Vm86InfoPtr vi, int mask)
121
asm volatile ("outb %b0,%w1" : : "a" (2), "d" (0x3c4));
122
asm volatile ("outb %b0,%w1" : : "a" (mask), "d" (0x3c5));
126
VgaSetReadPlaneMap(Vm86InfoPtr vi, int map)
128
asm volatile ("outb %b0,%w1" : : "a" (4), "d" (0x3ce));
129
asm volatile ("outb %b0,%w1" : : "a" (map), "d" (0x3cf));
133
VgaSetPalette(Vm86InfoPtr vi, int first, int number, U8 *entries)
143
if(first < 0 || number < 0 || first + number > 256) {
144
ErrorF("Cannot set %d, %d palette entries\n", first, number);
148
mark = Vm86MarkMemory (vi);
149
palette_base = Vm86AllocateMemory (vi, 3 * 256);
151
palette_scratch = &LM(vi, palette_base);
153
vi->vms.regs.eax = 0x1012;
154
vi->vms.regs.ebx = first;
155
vi->vms.regs.ecx = number;
156
vi->vms.regs.es = POINTER_SEGMENT(palette_base);
157
vi->vms.regs.edx = POINTER_OFFSET(palette_base);
162
palette_scratch[j++] = entries[i++] >> 2;
163
palette_scratch[j++] = entries[i++] >> 2;
164
palette_scratch[j++] = entries[i++] >> 2;
167
code = Vm86DoInterrupt(vi, 0x10);
168
Vm86ReleaseMemory (vi, mark);
176
VgaGetPalette(Vm86InfoPtr vi, int first, int number, U8 *entries)
186
if(first < 0 || number < 0 || first + number > 256) {
187
ErrorF("Cannot get %d, %d palette entries\n", first, number);
191
mark = Vm86MarkMemory (vi);
192
palette_base = Vm86AllocateMemory (vi, 3 * 256);
194
palette_scratch = &LM(vi, palette_base);
196
vi->vms.regs.eax = 0x1017;
197
vi->vms.regs.ebx = first;
198
vi->vms.regs.ecx = number;
199
vi->vms.regs.es = POINTER_SEGMENT(palette_base);
200
vi->vms.regs.edx = POINTER_OFFSET(palette_base);
202
code = VbeDoInterrupt10(vi);
210
entries[i++] = palette_scratch[j++] << 2;
211
entries[i++] = palette_scratch[j++] << 2;
212
entries[i++] = palette_scratch[j++] << 2;
216
Vm86ReleaseMemory (vi, mark);
221
#define VGA_FB(vm) ((vm) < 8 ? 0xb8000 : 0xa0000)
224
VgaSetWindow (Vm86InfoPtr vi, int vmode, int bytes, int mode, int *size)
226
*size = 0x10000 - bytes;
227
return &LM(vi,VGA_FB(vmode) + bytes);
231
VgaMapFramebuffer (Vm86InfoPtr vi, int vmode, int *size, CARD32 *ret_phys)
233
if (VGA_FB(vmode) == 0xa0000)
237
*ret_phys = VGA_FB(vmode);
238
return &LM(vi,VGA_FB(vmode));
242
VgaUnmapFramebuffer (Vm86InfoPtr vi)