]>
git.saurik.com Git - apple/boot.git/blob - i386/libsaio/vbe.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright 1993 NeXT, Inc.
26 * All rights reserved.
28 #include "io_inline.h"
32 #include "kernBootStruct.h"
33 #include "appleClut8.h"
36 * Graphics mode settings.
39 unsigned char * frame_buffer
;
40 unsigned short screen_width
;
41 unsigned short screen_height
;
42 unsigned char bits_per_pixel
;
43 unsigned short screen_rowbytes
;
46 * Various inline routines for video I/O
49 outi (int port
, int index
, int val
)
51 outw (port
, (val
<< 8) | index
);
55 outib (int port
, int index
, int val
)
62 ini (int port
, int index
)
65 return inb (port
+ 1);
69 rmwi (int port
, int index
, int clear
, int set
)
72 outb (port
+ 1, (inb (port
+ 1) & ~clear
) | set
);
78 void setupPalette(VBEPalette
* p
, const unsigned char * g
);
86 static char *models
[] = { "Text",
97 set_linear_video_mode(unsigned short mode
)
100 VBEModeInfoBlock minfo
;
106 * See if VESA is around.
108 err
= getVBEInfo(&vinfo
);
109 if (err
!= errSuccess
)
111 printf("VESA not available.\n");
117 * See if this mode is supported.
119 err
= getVBEModeInfo(mode
, &minfo
);
120 if ( !((err
== errSuccess
) &&
121 (minfo
.ModeAttributes
& maModeIsSupportedBit
) &&
122 (minfo
.ModeAttributes
& maGraphicsModeBit
) /* &&
123 (minfo.ModeAttributes & maLinearFrameBufferAvailBit)*/) )
125 printf("Mode %d is not supported.\n", mode
);
126 err
= errFuncNotSupported
;
134 err
= setVBEMode(mode
| kLinearFrameBufferBit
);
135 if ( err
!= errSuccess
)
137 if (vinfo
.VESAVersion
< MIN_VESA_VERSION
)
139 printf("Video Card is VESA %d.%d. It must be at least VESA %d.%d\n",
140 vinfo
.VESAVersion
>> 8,
141 vinfo
.VESAVersion
& 0xff,
142 MIN_VESA_VERSION
>> 8,
143 MIN_VESA_VERSION
& 0xff);
147 printf("Error #%d in set video mode.\n", err
);
155 err
= getVBEModeInfo(mode
, &minfo
);
156 if ( err
!= errSuccess
)
158 printf("Error #%d in get mode info.\n", err
);
165 if (( vinfo
.VESAVersion
>= MIN_VESA_VERSION
) &&
166 ( minfo
.BitsPerPixel
== 8 ))
168 setupPalette(&palette
, appleClut8
);
169 if ((err
= setVBEPalette(palette
)) != errSuccess
)
171 printf("Error #%d in setting palette.\n", err
);
177 in_linear_mode
= YES
;
178 screen_width
= minfo
.XResolution
;
179 screen_height
= minfo
.YResolution
;
180 bits_per_pixel
= minfo
.BitsPerPixel
;
181 screen_rowbytes
= minfo
.BytesPerScanline
;
183 /* The S3 video card reports 15 bits... the video console driver
184 * Can't deal.. set it to 16.
186 if (bits_per_pixel
> 8 && bits_per_pixel
< 16)
189 frame_buffer
= (unsigned char *) ADDRESS(minfo
.PhysBasePtr_low
,
192 minfo
.PhysBasePtr_high
);
199 void setupPalette(VBEPalette
* p
, const unsigned char * g
)
202 unsigned char * source
= (unsigned char *) g
;
204 for (i
= 0; i
< 256; i
++)
207 (*p
)[i
] |= ((unsigned long)((*source
++) >> 2)) << 16; // Red
208 (*p
)[i
] |= ((unsigned long)((*source
++) >> 2)) << 8; // Green
209 (*p
)[i
] |= ((unsigned long)((*source
++) >> 2)); // Blue
213 int getVBEInfo(void *vinfo_p
)
216 bb
.eax
.rr
= funcGetControllerInfo
;
217 bb
.es
= SEG(vinfo_p
);
218 bb
.edi
.rr
= OFF(vinfo_p
);
223 int getVBEModeInfo(int mode
, void *minfo_p
)
226 bb
.eax
.rr
= funcGetModeInfo
;
228 bb
.es
= SEG(minfo_p
);
229 bb
.edi
.rr
= OFF(minfo_p
);
234 int getVBEDACFormat(unsigned char *format
)
237 bb
.eax
.rr
= funcGetSetPaletteFormat
;
238 bb
.ebx
.r
.l
= subfuncGet
;
240 *format
= bb
.ebx
.r
.h
;
244 int setVBEDACFormat(unsigned char format
)
247 bb
.eax
.rr
= funcGetSetPaletteFormat
;
248 bb
.ebx
.r
.l
= subfuncSet
;
254 int setVBEMode(unsigned short mode
)
257 bb
.eax
.rr
= funcSetMode
;
263 int setVBEPalette(void *palette
)
266 bb
.eax
.rr
= funcGetSetPaletteData
;
267 bb
.ebx
.r
.l
= subfuncSet
;
270 bb
.es
= SEG(palette
);
271 bb
.edi
.rr
= OFF(palette
);
276 int getVBEPalette(void *palette
)
279 bb
.eax
.rr
= funcGetSetPaletteData
;
280 bb
.ebx
.r
.l
= subfuncGet
;
283 bb
.es
= SEG(palette
);
284 bb
.edi
.rr
= OFF(palette
);
289 int getVBECurrentMode(unsigned short *mode
)
292 bb
.eax
.rr
= funcGetCurrentMode
;