2 * Copyright © 2000 Keith Packard
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Keith Packard not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Keith Packard makes no
11 * representations about the suitability of this software for any purpose. It
12 * is provided "as is" without express or implied warranty.
14 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
24 #include <kdrive-config.h>
28 static const VesaModeRec vgaModes
[] = {
31 MODE_SUPPORTED
| MODE_GRAPHICS
| MODE_VGA
| MODE_LINEAR
,
33 0, 0, 0, 0, 0, 0, 0, 0, 0,
38 MODE_SUPPORTED
| MODE_GRAPHICS
| MODE_VGA
| MODE_COLOUR
,
40 0, 0, 0, 0, 0, 0, 0, 0, 0,
45 MODE_SUPPORTED
| MODE_GRAPHICS
| MODE_VGA
| MODE_COLOUR
,
47 0, 0, 0, 0, 0, 0, 0, 0, 0,
52 MODE_SUPPORTED
| MODE_GRAPHICS
| MODE_VGA
| MODE_COLOUR
,
54 0, 0, 0, 0, 0, 0, 0, 0, 0,
59 MODE_SUPPORTED
| MODE_GRAPHICS
| MODE_VGA
| MODE_LINEAR
,
61 0, 0, 0, 0, 0, 0, 0, 0, 0,
66 MODE_SUPPORTED
| MODE_GRAPHICS
| MODE_VGA
| MODE_COLOUR
,
68 0, 0, 0, 0, 0, 0, 0, 0, 0,
73 MODE_SUPPORTED
| MODE_GRAPHICS
| MODE_VGA
| MODE_COLOUR
| MODE_LINEAR
,
75 0, 0, 0, 0, 0, 0, 0, 0, 0,
80 #define NUM_VGA_MODE (sizeof vgaModes / sizeof vgaModes[0])
83 VgaGetNmode (Vm86InfoPtr vi
)
89 VgaGetModes (Vm86InfoPtr vi
, VesaModePtr mode
, int nmode
)
91 if (nmode
> NUM_VGA_MODE
)
93 memcpy (mode
, vgaModes
, nmode
* sizeof (VesaModeRec
));
98 VgaSetMode(Vm86InfoPtr vi
, int mode
)
102 vi
->vms
.regs
.eax
= mode
& 0x7f;
103 code
= Vm86DoInterrupt (vi
, 0x10);
110 VgaGetMode (Vm86InfoPtr vi
, int *mode
)
112 *mode
= Vm86Memory (vi
, 0x449);
117 VgaSetWritePlaneMask(Vm86InfoPtr vi
, int mask
)
119 asm volatile ("outb %b0,%w1" : : "a" (2), "d" (0x3c4));
120 asm volatile ("outb %b0,%w1" : : "a" (mask
), "d" (0x3c5));
124 VgaSetReadPlaneMap(Vm86InfoPtr vi
, int map
)
126 asm volatile ("outb %b0,%w1" : : "a" (4), "d" (0x3ce));
127 asm volatile ("outb %b0,%w1" : : "a" (map
), "d" (0x3cf));
131 VgaSetPalette(Vm86InfoPtr vi
, int first
, int number
, U8
*entries
)
141 if(first
< 0 || number
< 0 || first
+ number
> 256) {
142 ErrorF("Cannot set %d, %d palette entries\n", first
, number
);
146 mark
= Vm86MarkMemory (vi
);
147 palette_base
= Vm86AllocateMemory (vi
, 3 * 256);
149 palette_scratch
= &LM(vi
, palette_base
);
151 vi
->vms
.regs
.eax
= 0x1012;
152 vi
->vms
.regs
.ebx
= first
;
153 vi
->vms
.regs
.ecx
= number
;
154 vi
->vms
.regs
.es
= POINTER_SEGMENT(palette_base
);
155 vi
->vms
.regs
.edx
= POINTER_OFFSET(palette_base
);
160 palette_scratch
[j
++] = entries
[i
++] >> 2;
161 palette_scratch
[j
++] = entries
[i
++] >> 2;
162 palette_scratch
[j
++] = entries
[i
++] >> 2;
165 code
= Vm86DoInterrupt(vi
, 0x10);
166 Vm86ReleaseMemory (vi
, mark
);
174 VgaGetPalette(Vm86InfoPtr vi
, int first
, int number
, U8
*entries
)
184 if(first
< 0 || number
< 0 || first
+ number
> 256) {
185 ErrorF("Cannot get %d, %d palette entries\n", first
, number
);
189 mark
= Vm86MarkMemory (vi
);
190 palette_base
= Vm86AllocateMemory (vi
, 3 * 256);
192 palette_scratch
= &LM(vi
, palette_base
);
194 vi
->vms
.regs
.eax
= 0x1017;
195 vi
->vms
.regs
.ebx
= first
;
196 vi
->vms
.regs
.ecx
= number
;
197 vi
->vms
.regs
.es
= POINTER_SEGMENT(palette_base
);
198 vi
->vms
.regs
.edx
= POINTER_OFFSET(palette_base
);
200 code
= VbeDoInterrupt10(vi
);
208 entries
[i
++] = palette_scratch
[j
++] << 2;
209 entries
[i
++] = palette_scratch
[j
++] << 2;
210 entries
[i
++] = palette_scratch
[j
++] << 2;
214 Vm86ReleaseMemory (vi
, mark
);
219 #define VGA_FB(vm) ((vm) < 8 ? 0xb8000 : 0xa0000)
222 VgaSetWindow (Vm86InfoPtr vi
, int vmode
, int bytes
, int mode
, int *size
)
224 *size
= 0x10000 - bytes
;
225 return &LM(vi
,VGA_FB(vmode
) + bytes
);
229 VgaMapFramebuffer (Vm86InfoPtr vi
, int vmode
, int *size
, CARD32
*ret_phys
)
231 if (VGA_FB(vmode
) == 0xa0000)
235 *ret_phys
= VGA_FB(vmode
);
236 return &LM(vi
,VGA_FB(vmode
));
240 VgaUnmapFramebuffer (Vm86InfoPtr vi
)