Root/
Source at commit HEAD created 5 years 6 days ago. By ifabio, Few update to kernelPatcher (Credits to CrazyBirdy) | |
---|---|
1 | /*␊ |
2 | * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.␊ |
3 | *␊ |
4 | * @APPLE_LICENSE_HEADER_START@␊ |
5 | * ␊ |
6 | * Portions Copyright (c) 1999-2003 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 2.0 (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␊ |
12 | * this file.␊ |
13 | * ␊ |
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␊ |
20 | * under the License.␊ |
21 | * ␊ |
22 | * @APPLE_LICENSE_HEADER_END@␊ |
23 | *␊ |
24 | * Copyright 1993 NeXT, Inc. All rights reserved.␊ |
25 | *␊ |
26 | */␊ |
27 | ␊ |
28 | #include "boot.h"␊ |
29 | #include "vbe.h"␊ |
30 | #include "appleClut8.h"␊ |
31 | #include "gui.h"␊ |
32 | #include "IOHibernatePrivate.h"␊ |
33 | ␊ |
34 | /*␊ |
35 | * for spinning disk␊ |
36 | */␊ |
37 | static int currentIndicator = 0;␊ |
38 | ␊ |
39 | int previewTotalSectors = 0;␊ |
40 | int previewLoadedSectors = 0;␊ |
41 | uint8_t *previewSaveunder = 0;␊ |
42 | ␊ |
43 | #define VIDEO(x) (bootArgs->Video.v_ ## x)␊ |
44 | ␊ |
45 | //==========================================================================␊ |
46 | // getVBEVideoRam␊ |
47 | ␊ |
48 | uint32_t getVBEVideoRam()␊ |
49 | {␊ |
50 | ␉VBEInfoBlock vbeInfo;␊ |
51 | ␉int err, small;␊ |
52 | ␊ |
53 | ␉bzero( &vbeInfo, sizeof(vbeInfo) );␊ |
54 | ␉strcpy( (char*)&vbeInfo, "VBE2" );␊ |
55 | ␉err = getVBEInfo( &vbeInfo );␊ |
56 | ␉if (err != errSuccess)␊ |
57 | ␉␉return 0;␊ |
58 | ␊ |
59 | ␉if ( strncmp( (char *)vbeInfo.VESASignature, "VESA", 4 ) )␊ |
60 | ␉␉return 0;␊ |
61 | ␊ |
62 | ␉small = (vbeInfo.TotalMemory < 16);␊ |
63 | ␊ |
64 | ␉return vbeInfo.TotalMemory * 64 * 1024;␊ |
65 | }␊ |
66 | ␊ |
67 | //==========================================================================␊ |
68 | // getVBEInfoString␊ |
69 | ␊ |
70 | char *getVBEInfoString()␊ |
71 | {␊ |
72 | ␉VBEInfoBlock vbeInfo;␊ |
73 | ␉int err, small;␊ |
74 | ␉char* buff = NULL;␊ |
75 | ␊ |
76 | ␉bzero( &vbeInfo, sizeof(vbeInfo) );␊ |
77 | ␉strcpy( (char*)&vbeInfo, "VBE2" );␊ |
78 | ␉err = getVBEInfo( &vbeInfo );␊ |
79 | ␉if (err != errSuccess)␊ |
80 | ␉{␊ |
81 | ␉␉return 0;␊ |
82 | ␉}␊ |
83 | ␊ |
84 | ␉if ( strncmp( (char *)vbeInfo.VESASignature, "VESA", 4 ) )␊ |
85 | ␉{␊ |
86 | ␉␉return 0;␊ |
87 | ␉}␊ |
88 | ␊ |
89 | ␉buff = malloc(sizeof(char) * 256);␊ |
90 | ␉if (!buff)␊ |
91 | ␉{␊ |
92 | ␉␉return 0;␊ |
93 | ␉}␊ |
94 | ␊ |
95 | ␉small = (vbeInfo.TotalMemory < 16);␊ |
96 | ␊ |
97 | ␉snprintf(buff, 256,␊ |
98 | ␉␉"VESA v%d.%d %d%s (%s)\n",␊ |
99 | ␉␉vbeInfo.VESAVersion >> 8,␊ |
100 | ␉␉vbeInfo.VESAVersion & 0xf,␊ |
101 | ␉␉small ? (vbeInfo.TotalMemory * 64) : (vbeInfo.TotalMemory / 16),␊ |
102 | ␉␉small ? "KB" : "MB",␊ |
103 | ␉␉VBEDecodeFP(const char *, vbeInfo.OEMStringPtr) );␊ |
104 | ␊ |
105 | ␉return buff;␊ |
106 | }␊ |
107 | ␊ |
108 | //==========================================================================␊ |
109 | //␊ |
110 | ␊ |
111 | void printVBEModeInfo()␊ |
112 | {␊ |
113 | ␉VBEInfoBlock vbeInfo;␊ |
114 | ␉unsigned short * modePtr;␊ |
115 | ␉VBEModeInfoBlock modeInfo;␊ |
116 | ␉int err;␊ |
117 | ␉int line;␊ |
118 | ␉char* vbeInfoString = NULL;␊ |
119 | ␊ |
120 | ␉bzero( &vbeInfo, sizeof(vbeInfo) );␊ |
121 | ␉strcpy( (char*)&vbeInfo, "VBE2" );␊ |
122 | ␉err = getVBEInfo( &vbeInfo );␊ |
123 | ␉if ( err != errSuccess ) {␊ |
124 | ␉␉return;␊ |
125 | ␉}␊ |
126 | ␊ |
127 | ␉line = 0;␊ |
128 | ␊ |
129 | ␉// Activate and clear page 1␊ |
130 | ␉setActiveDisplayPage(1);␊ |
131 | ␉clearScreenRows(0, 24);␊ |
132 | ␉setCursorPosition( 0, 0, 1 );␊ |
133 | ␊ |
134 | ␉vbeInfoString = getVBEInfoString();␊ |
135 | ␉if (!vbeInfoString) {␊ |
136 | ␉␉printf("Error: getVBEInfoString failed\n");␊ |
137 | ␉␉return;␊ |
138 | ␉}␊ |
139 | ␉printf("%s", vbeInfoString);␊ |
140 | ␉free(vbeInfoString);␊ |
141 | ␉vbeInfoString = NULL;␊ |
142 | ␊ |
143 | ␉printf("Video modes supported:\n", VBEDecodeFP(const char *, vbeInfo.OEMStringPtr));␊ |
144 | ␊ |
145 | ␉// Loop through the mode list, and find the matching mode.␊ |
146 | ␊ |
147 | ␉for ( modePtr = VBEDecodeFP( unsigned short *, vbeInfo.VideoModePtr );␊ |
148 | *modePtr != modeEndOfList; modePtr++ )␊ |
149 | ␉{␊ |
150 | ␉␉// Get mode information.␊ |
151 | ␊ |
152 | ␉␉bzero( &modeInfo, sizeof(modeInfo) );␊ |
153 | ␉␉err = getVBEModeInfo( *modePtr, &modeInfo );␊ |
154 | ␉␉if ( err != errSuccess )␊ |
155 | ␉␉{␊ |
156 | ␉␉␉continue;␊ |
157 | ␉␉}␊ |
158 | ␊ |
159 | ␉␉printf("Mode %x: %dx%dx%d mm:%d attr:%x\n",␊ |
160 | ␉␉␉*modePtr, modeInfo.XResolution, modeInfo.YResolution,␊ |
161 | ␉␉␉modeInfo.BitsPerPixel, modeInfo.MemoryModel,␊ |
162 | ␉␉␉modeInfo.ModeAttributes);␊ |
163 | ␊ |
164 | ␉␉if (line++ >= 20)␊ |
165 | ␉␉{␊ |
166 | ␉␉␉pause();␊ |
167 | ␉␉␉line = 0;␊ |
168 | ␉␉␉clearScreenRows(0, 24);␊ |
169 | ␉␉␉setCursorPosition( 0, 0, 1 );␊ |
170 | ␉␉}␊ |
171 | ␉}␊ |
172 | ␊ |
173 | ␉if (line != 0)␊ |
174 | ␉{␊ |
175 | ␉␉pause();␊ |
176 | ␉}␊ |
177 | ␊ |
178 | ␉setActiveDisplayPage(0);␊ |
179 | }␊ |
180 | ␊ |
181 | //==============================================================================␊ |
182 | ␊ |
183 | char *getVBEModeInfoString()␊ |
184 | {␊ |
185 | ␉VBEInfoBlock vbeInfo;␊ |
186 | ␉unsigned short * modePtr;␊ |
187 | ␉VBEModeInfoBlock modeInfo;␊ |
188 | ␉int err;␊ |
189 | ␊ |
190 | ␉bzero( &vbeInfo, sizeof(vbeInfo) );␊ |
191 | ␉strcpy( (char*)&vbeInfo, "VBE2" );␊ |
192 | ␉err = getVBEInfo( &vbeInfo );␊ |
193 | ␉if ( err != errSuccess )␊ |
194 | ␉{␊ |
195 | ␉␉return 0;␊ |
196 | ␉}␊ |
197 | ␊ |
198 | ␉char *buff=malloc(sizeof(char)*3072);␊ |
199 | ␉if(!buff)␊ |
200 | ␉{␊ |
201 | ␉␉return 0;␊ |
202 | ␉}␊ |
203 | ␊ |
204 | ␉int bufflen = 0;␊ |
205 | ␊ |
206 | ␉// Loop through the mode list, and find the matching mode.␊ |
207 | ␉for ( modePtr = VBEDecodeFP( unsigned short *, vbeInfo.VideoModePtr );␊ |
208 | ␉␉(*modePtr != modeEndOfList) && (bufflen < 3072); /* prevent buffer overrun */␊ |
209 | ␉␉modePtr++ )␊ |
210 | ␉{␊ |
211 | ␉␉// Get mode information.␊ |
212 | ␊ |
213 | ␉␉bzero( &modeInfo, sizeof(modeInfo) );␊ |
214 | ␉␉err = getVBEModeInfo( *modePtr, &modeInfo );␊ |
215 | ␉␉if ( err != errSuccess )␊ |
216 | ␉␉{␊ |
217 | ␉␉␉continue;␊ |
218 | ␉␉}␊ |
219 | ␊ |
220 | ␉␉bufflen += ␊ |
221 | ␉␉␉snprintf(buff+bufflen, 3072-bufflen, "Mode %x: %dx%dx%d mm:%d attr:%x\n",␊ |
222 | ␉␉␉*modePtr, modeInfo.XResolution, modeInfo.YResolution,␊ |
223 | ␉␉␉modeInfo.BitsPerPixel, modeInfo.MemoryModel,␊ |
224 | ␉␉␉modeInfo.ModeAttributes);␊ |
225 | ␉}␊ |
226 | ␉return buff;␊ |
227 | }␊ |
228 | ␊ |
229 | //==========================================================================␊ |
230 | // getVESAModeWithProperties␊ |
231 | //␊ |
232 | // Return the VESA mode that matches the properties specified.␊ |
233 | // If a mode is not found, then return the "best" available mode.␊ |
234 | ␊ |
235 | static unsigned short getVESAModeWithProperties( unsigned short␉width,␊ |
236 | unsigned short␉height,␊ |
237 | unsigned char␉bitsPerPixel,␊ |
238 | unsigned short␉attributesSet,␊ |
239 | unsigned short␉attributesClear,␊ |
240 | VBEModeInfoBlock␉*outModeInfo,␊ |
241 | unsigned short␉*vesaVersion␊ |
242 | ␉␉␉)␊ |
243 | {␊ |
244 | ␉VBEInfoBlock vbeInfo;␊ |
245 | ␉unsigned short * modePtr;␊ |
246 | ␉VBEModeInfoBlock modeInfo;␊ |
247 | ␉unsigned char modeBitsPerPixel;␊ |
248 | ␉unsigned short matchedMode = modeEndOfList;␊ |
249 | ␉int err;␊ |
250 | ␊ |
251 | ␉// Clear output mode info.␊ |
252 | ␊ |
253 | ␉bzero( outModeInfo, sizeof(*outModeInfo) );␊ |
254 | ␊ |
255 | ␉// Get VBE controller info containing the list of supported modes.␊ |
256 | ␊ |
257 | ␉bzero( &vbeInfo, sizeof(vbeInfo) );␊ |
258 | ␉strcpy( (char*)&vbeInfo, "VBE2" );␊ |
259 | ␉err = getVBEInfo( &vbeInfo );␊ |
260 | ␉if ( err != errSuccess )␊ |
261 | ␉{␊ |
262 | ␉␉return modeEndOfList;␊ |
263 | ␉}␊ |
264 | ␊ |
265 | ␉// Report the VESA major/minor version number.␊ |
266 | ␊ |
267 | ␉if (vesaVersion)␊ |
268 | ␉{␊ |
269 | ␉␉*vesaVersion = vbeInfo.VESAVersion;␊ |
270 | ␉}␊ |
271 | ␊ |
272 | ␉// Loop through the mode list, and find the matching mode.␊ |
273 | ␊ |
274 | ␉for ( modePtr = VBEDecodeFP( unsigned short *, vbeInfo.VideoModePtr ); *modePtr != modeEndOfList; modePtr++ )␊ |
275 | ␉{␊ |
276 | ␉␉// Get mode information.␊ |
277 | ␊ |
278 | ␉␉bzero( &modeInfo, sizeof(modeInfo) );␊ |
279 | ␊ |
280 | ␉␉err = getVBEModeInfo( *modePtr, &modeInfo );␊ |
281 | ␉␉if ( err != errSuccess )␊ |
282 | ␉␉{␊ |
283 | ␉␉␉continue;␊ |
284 | ␉␉}␊ |
285 | ␊ |
286 | #if DEBUG␊ |
287 | ␉␉printf("Mode %x: %dx%dx%d mm:%d attr:%x\n",␊ |
288 | ␉␉␉*modePtr, modeInfo.XResolution, modeInfo.YResolution,␊ |
289 | ␉␉␉modeInfo.BitsPerPixel, modeInfo.MemoryModel,␊ |
290 | ␉␉␉modeInfo.ModeAttributes);␊ |
291 | #endif␊ |
292 | ␊ |
293 | ␉␉// Filter out unwanted modes based on mode attributes.␊ |
294 | ␊ |
295 | ␉␉if (((modeInfo.ModeAttributes & attributesSet) != attributesSet) || ((modeInfo.ModeAttributes & attributesClear) != 0))␊ |
296 | ␉␉{␊ |
297 | ␉␉␉continue;␊ |
298 | ␉␉}␊ |
299 | ␊ |
300 | ␉␉// Pixel depth in bits.␊ |
301 | ␊ |
302 | ␉␉modeBitsPerPixel = modeInfo.BitsPerPixel;␊ |
303 | ␊ |
304 | ␉␉if ((modeBitsPerPixel == 4) && (modeInfo.MemoryModel == 0))␊ |
305 | ␉␉{␊ |
306 | ␉␉␉// Text mode, 16 colors.␊ |
307 | ␉␉}␊ |
308 | ␉␉␉else if ((modeBitsPerPixel == 8) && (modeInfo.MemoryModel == 4))␊ |
309 | ␉␉{␊ |
310 | ␉␉␉// Packed pixel, 256 colors.␊ |
311 | ␉␉}␊ |
312 | ␉␉else if (((modeBitsPerPixel == 16) || (modeBitsPerPixel == 15)) && (modeInfo.MemoryModel == 6) && (modeInfo.RedMaskSize == 5) &&␊ |
313 | ␉␉␉(modeInfo.GreenMaskSize == 5) && (modeInfo.BlueMaskSize == 5))␊ |
314 | ␉␉{␊ |
315 | ␉␉␉// Direct color, 16 bpp (1:5:5:5).␊ |
316 | ␉␉␉modeInfo.BitsPerPixel = modeBitsPerPixel = 16;␊ |
317 | ␉␉}␊ |
318 | ␉␉else if ((modeBitsPerPixel == 32) && (modeInfo.MemoryModel == 6) && (modeInfo.RedMaskSize == 8) &&␊ |
319 | ␉␉␉(modeInfo.GreenMaskSize == 8) && (modeInfo.BlueMaskSize == 8))␊ |
320 | ␉␉{␊ |
321 | ␉␉␉// Direct color, 32 bpp (8:8:8:8).␊ |
322 | ␉␉}␊ |
323 | ␉␉else␊ |
324 | ␉␉{␊ |
325 | ␉␉␉continue;␉// Not a supported mode.␊ |
326 | ␉␉}␊ |
327 | ␊ |
328 | ␉␉// Modes larger than the specified dimensions are skipped.␊ |
329 | ␊ |
330 | ␉␉if ((modeInfo.XResolution > width) || (modeInfo.YResolution > height))␊ |
331 | ␉␉{␊ |
332 | ␉␉␉continue;␊ |
333 | ␉␉}␊ |
334 | ␊ |
335 | ␉␉// Perfect match, we're done looking.␊ |
336 | ␊ |
337 | ␉␉if (modeInfo.XResolution == width && modeInfo.YResolution == height && modeBitsPerPixel == bitsPerPixel)␊ |
338 | ␉␉{␊ |
339 | ␉␉␉matchedMode = *modePtr;␊ |
340 | ␉␉␉bcopy(&modeInfo, outModeInfo, sizeof(modeInfo));␊ |
341 | ␉␉␉break;␊ |
342 | ␉␉}␊ |
343 | ␊ |
344 | ␉␉// Save the next "best" mode in case a perfect match is not found.␊ |
345 | ␊ |
346 | ␉␉if (modeInfo.XResolution == outModeInfo->XResolution && modeInfo.YResolution == outModeInfo->YResolution &&␊ |
347 | ␉␉␉modeBitsPerPixel <= outModeInfo->BitsPerPixel)␊ |
348 | ␉␉{␊ |
349 | ␉␉␉continue;␉// Saved mode has more depth.␊ |
350 | ␉␉}␊ |
351 | ␊ |
352 | ␉␉if (modeInfo.XResolution < outModeInfo->XResolution || modeInfo.YResolution < outModeInfo->YResolution ||␊ |
353 | ␉␉␉modeBitsPerPixel < outModeInfo->BitsPerPixel)␊ |
354 | ␉␉{␊ |
355 | ␉␉␉continue;␉// Saved mode has more resolution.␊ |
356 | ␉␉}␊ |
357 | ␊ |
358 | ␉␉matchedMode = *modePtr;␊ |
359 | ␉␉bcopy(&modeInfo, outModeInfo, sizeof(modeInfo));␊ |
360 | ␉}␊ |
361 | ␊ |
362 | ␉return matchedMode;␊ |
363 | }␊ |
364 | ␊ |
365 | //==========================================================================␊ |
366 | // setupPalette␊ |
367 | ␊ |
368 | static void setupPalette( VBEPalette *p, const unsigned char *g )␊ |
369 | {␊ |
370 | int i;␊ |
371 | unsigned char * source = (unsigned char *) g;␊ |
372 | ␊ |
373 | for (i = 0; i < 256; i++)␊ |
374 | {␊ |
375 | (*p)[i] = 0;␊ |
376 | (*p)[i] |= ((unsigned long)((*source++) >> 2)) << 16; // Red␊ |
377 | (*p)[i] |= ((unsigned long)((*source++) >> 2)) << 8; // Green␊ |
378 | (*p)[i] |= ((unsigned long)((*source++) >> 2)); // Blue␊ |
379 | }␊ |
380 | }␊ |
381 | ␊ |
382 | //==========================================================================␊ |
383 | // Simple decompressor for boot images encoded in RLE format.␊ |
384 | ␊ |
385 | char *decodeRLE( const void *rleData, int rleBlocks, int outBytes )␊ |
386 | {␊ |
387 | char *out, *cp;␊ |
388 | ␊ |
389 | struct RLEBlock {␊ |
390 | unsigned char count;␊ |
391 | unsigned char value;␊ |
392 | } * bp = (struct RLEBlock *) rleData;␊ |
393 | ␊ |
394 | out = cp = malloc( outBytes );␊ |
395 | if ( out == NULL ) return NULL;␊ |
396 | ␊ |
397 | while ( rleBlocks-- )␊ |
398 | {␊ |
399 | memset( cp, bp->value, bp->count );␊ |
400 | cp += bp->count;␊ |
401 | bp++;␊ |
402 | }␊ |
403 | ␊ |
404 | return out;␊ |
405 | }␊ |
406 | ␊ |
407 | //==========================================================================␊ |
408 | // setVESAGraphicsMode␊ |
409 | ␊ |
410 | static int setVESAGraphicsMode( unsigned short width, unsigned short height, unsigned char bitsPerPixel, unsigned short refreshRate )␊ |
411 | {␊ |
412 | ␉VBEModeInfoBlock minfo;␊ |
413 | ␉unsigned short mode = 280; // Default to 1024 * 768 * 32 (1920 * 1200 * 32 would be 330)␊ |
414 | ␉unsigned short vesaVersion;␊ |
415 | ␉int err = errFuncNotSupported;␊ |
416 | ␊ |
417 | ␉do {␊ |
418 | ␉␉mode = getVESAModeWithProperties( width, height, bitsPerPixel,␊ |
419 | maColorModeBit | maModeIsSupportedBit | maGraphicsModeBit | maLinearFrameBufferAvailBit,␊ |
420 | 0, &minfo, &vesaVersion );␊ |
421 | ␉␉if ( mode == modeEndOfList )␊ |
422 | ␉␉{␊ |
423 | ␉␉␉break;␊ |
424 | ␉␉}␊ |
425 | ␊ |
426 | ␉␉// Set the mode with default refresh rate.␊ |
427 | ␊ |
428 | ␉␉err = setVBEMode(mode | kLinearFrameBufferBit, NULL);␊ |
429 | ␊ |
430 | ␉␉if (err != errSuccess)␊ |
431 | ␉␉{␊ |
432 | ␉␉␉break;␊ |
433 | ␉␉}␊ |
434 | ␊ |
435 | ␉␉// Is this required for buggy Video BIOS implementations? If so for which adapter?␊ |
436 | ␊ |
437 | ␉␉if ( minfo.BitsPerPixel == 8 )␊ |
438 | ␉{␊ |
439 | ␉␉␉VBEPalette palette;␊ |
440 | ␊ |
441 | ␉␉␉// A switch is needed for the two clut way...␊ |
442 | ␉␉␉if ( ( MacOSVerCurrent >= MacOSVer2Int("10.10") ) && ( FlagBlackOption ) ) // Yosemite and Up!␊ |
443 | ␉␉␉{␊ |
444 | ␉␉␉␉setupPalette( &palette, AppleLogoBlackClut );␊ |
445 | ␉␉␉}␊ |
446 | ␉␉␉else␊ |
447 | ␉␉␉{␊ |
448 | ␉␉␉␉setupPalette( &palette, AppleLogoClut );␊ |
449 | ␉␉␉}␊ |
450 | ␊ |
451 | ␉␉␉if ((err = setVBEPalette(palette)) != errSuccess)␊ |
452 | ␉␉␉{␊ |
453 | ␉␉␉␉break;␊ |
454 | ␉␉␉}␊ |
455 | ␉␉}␊ |
456 | ␊ |
457 | ␉␉// Is this required for buggy Video BIOS implementations?␊ |
458 | ␉␉// On which adapter?␊ |
459 | ␊ |
460 | ␉␉if ( minfo.BytesPerScanline == 0 )␊ |
461 | ␉␉{␊ |
462 | ␉ minfo.BytesPerScanline = ( minfo.XResolution * minfo.BitsPerPixel ) >> 3;␊ |
463 | ␉␉}␊ |
464 | ␊ |
465 | ␉␉// Update KernBootStruct using info provided by the selected␊ |
466 | ␉␉// VESA mode.␊ |
467 | ␊ |
468 | ␉␉bootArgs->Video.v_display␉= GRAPHICS_MODE;␊ |
469 | ␉␉bootArgs->Video.v_width␉␉= minfo.XResolution;␉␉/* 1920 or 1600 */␊ |
470 | ␉␉bootArgs->Video.v_height␉= minfo.YResolution;␉␉/* 1200 or 900 */␊ |
471 | ␉␉bootArgs->Video.v_depth␉␉= minfo.BitsPerPixel;␉␉/* 32 */␊ |
472 | ␉␉bootArgs->Video.v_rowBytes␉= minfo.BytesPerScanline;␉/* 7680 or 6400 */␊ |
473 | ␉␉bootArgs->Video.v_baseAddr␉= VBEMakeUInt32(minfo.PhysBasePtr);␊ |
474 | ␊ |
475 | ␉} while ( 0 );␊ |
476 | ␊ |
477 | ␉return err;␊ |
478 | }␊ |
479 | ␊ |
480 | //==============================================================================␊ |
481 | ␊ |
482 | int convertImage( unsigned short width, unsigned short height, const unsigned char *imageData, unsigned char **newImageData )␊ |
483 | {␊ |
484 | ␉int index = 0;␊ |
485 | ␉int size = (width * height); // 16384␊ |
486 | ␉int depth = VIDEO(depth);␊ |
487 | ␊ |
488 | ␉unsigned char *img = 0;␊ |
489 | ␉unsigned long *img32;␊ |
490 | ␊ |
491 | ␉switch (depth)␊ |
492 | ␉{␊ |
493 | ␉␉case 32:␊ |
494 | ␉␉␉img32 = malloc(size * 4);␊ |
495 | ␊ |
496 | ␉␉␉if (!img32)␊ |
497 | ␉␉␉{␊ |
498 | ␉␉␉␉break;␊ |
499 | ␉␉␉}␊ |
500 | ␊ |
501 | ␉␉␉for (; index < size; index++)␊ |
502 | ␉␉␉{␊ |
503 | ␉␉␉␉img32[index] = lookUpCLUTIndex(imageData[index]);␊ |
504 | ␉␉␉}␊ |
505 | ␊ |
506 | ␉␉␉img = (unsigned char *)img32;␊ |
507 | ␉␉␉break;␊ |
508 | ␉}␊ |
509 | ␊ |
510 | ␉*newImageData = img;␊ |
511 | ␊ |
512 | ␉return 0;␊ |
513 | }␊ |
514 | ␊ |
515 | //==============================================================================␊ |
516 | ␊ |
517 | int loadPngImage(const char *filename, uint16_t *width, uint16_t *height, uint8_t **imageData)␊ |
518 | {␊ |
519 | uint8_t *pngData = NULL;␊ |
520 | int pngFile = 0, pngSize;␊ |
521 | PNG_info_t *info;␊ |
522 | int error = 0;␊ |
523 | ␊ |
524 | pngFile = open_bvdev("bt(0,0)", filename, 0);␊ |
525 | if (pngFile == -1) {␊ |
526 | error = -1;␊ |
527 | goto failed;␊ |
528 | }␊ |
529 | pngSize = file_size(pngFile);␊ |
530 | if (!pngSize) {␊ |
531 | error = -1;␊ |
532 | goto failed;␊ |
533 | }␊ |
534 | pngData = malloc(pngSize);␊ |
535 | if (read(pngFile, (char *) pngData, pngSize) != pngSize) {␊ |
536 | error = -1;␊ |
537 | goto failed;␊ |
538 | }␊ |
539 | ␊ |
540 | PNG_error = -1;␊ |
541 | info = PNG_decode(pngData, pngSize);␊ |
542 | if (PNG_error != 0) {␊ |
543 | error = PNG_error;␊ |
544 | goto failed;␊ |
545 | } else if ((info->width > 0xffff) || (info->height > 0xffff)) {␊ |
546 | error = -1;␊ |
547 | goto failed;␊ |
548 | } else if ((info->width * info->height * 4) != info->image->size) {␊ |
549 | error = -1;␊ |
550 | goto failed;␊ |
551 | }␊ |
552 | ␉uint8_t *result = malloc(info->width*4*info->height);␊ |
553 | *width = info->width;␊ |
554 | *height = info->height;␊ |
555 | ␉memcpy(result, info->image->data, info->width*4*info->height);␊ |
556 | ␉*imageData = result;␊ |
557 | ␊ |
558 | failed:␊ |
559 | ␉png_alloc_free_all();␊ |
560 | if (pngData)␊ |
561 | free(pngData);␊ |
562 | if (pngFile != -1)␊ |
563 | close(pngFile);␊ |
564 | ␊ |
565 | return error;␊ |
566 | }␊ |
567 | ␊ |
568 | //==============================================================================␊ |
569 | ␊ |
570 | int loadEmbeddedPngImage(uint8_t *pngData, int pngSize, uint16_t *width, uint16_t *height, uint8_t **imageData)␊ |
571 | {␊ |
572 | PNG_info_t *info;␊ |
573 | int error = 0;␊ |
574 | ␉␊ |
575 | PNG_error = -1;␊ |
576 | info = PNG_decode(pngData, pngSize);␊ |
577 | ␉if (PNG_error != 0) {␊ |
578 | error = PNG_error;␊ |
579 | goto failed;␊ |
580 | } else if ((info->width > 0xffff) || (info->height > 0xffff)) {␊ |
581 | error = -1;␊ |
582 | goto failed;␊ |
583 | } else if ((info->width * info->height * 4) != info->image->size) {␊ |
584 | error = -1;␊ |
585 | goto failed;␊ |
586 | }␊ |
587 | ␉uint8_t *result = malloc(info->width*4*info->height);␊ |
588 | ␉*width = info->width;␊ |
589 | *height = info->height;␊ |
590 | ␉memcpy(result, info->image->data, info->width*4*info->height);␊ |
591 | ␉*imageData = result;␊ |
592 | ␊ |
593 | failed:␊ |
594 | ␉png_alloc_free_all();␊ |
595 | ␊ |
596 | return error;␊ |
597 | }␊ |
598 | ␊ |
599 | //==============================================================================␊ |
600 | ␊ |
601 | void blendImage(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t *data)␊ |
602 | {␊ |
603 | uint16_t drawWidth;␊ |
604 | uint8_t *vram = (uint8_t *) VIDEO(baseAddr) + VIDEO(rowBytes) * y + 4 * x;␊ |
605 | ␊ |
606 | drawWidth = MIN(width, VIDEO(width) - x);␊ |
607 | height = MIN(height, VIDEO(height) - y);␊ |
608 | while (height--) {␊ |
609 | ␉␉switch (VIDEO (depth))␊ |
610 | ␉␉{␊ |
611 | ␉␉␉case 32: /* Optimized version*/␊ |
612 | ␉␉␉{␊ |
613 | ␉␉␉␉uint32_t s; uint32_t* d; // Source (img) and destination (bkgd) pixels␊ |
614 | ␉␉␉␉uint32_t a; // Alpha␊ |
615 | ␉␉␉␉uint32_t dstrb, dstg, srcrb, srcg, drb, dg, rb, g, tempB; // Intermediate variables␊ |
616 | ␉␉␉␉uint16_t pos;␊ |
617 | ␊ |
618 | ␉␉␉␉for (pos = 0; pos < drawWidth * 4; pos += 4) {␊ |
619 | ␉␉␉␉␉// Fast pseudo-vector alpha blending, adapted from: http://www.stereopsis.com/doubleblend.html␊ |
620 | ␉␉␉␉␉s = *((uint32_t*) (data + pos));␊ |
621 | ␉␉␉␉␉d = (uint32_t*) (vram + pos);␊ |
622 | ␊ |
623 | ␉␉␉␉␉// Flip B and R in source␊ |
624 | ␉␉␉␉␉// TODO: use XCHG and inline assembly to do this in a faster, saner way␊ |
625 | ␉␉␉␉␉tempB = (s & 0xFF0000); // save B␊ |
626 | ␉␉␉␉␉s = (s & 0xFF00FFFF) | ((s & 0xFF) << 16); // put R in B␊ |
627 | ␉␉␉␉␉s = (s & 0xFFFFFF00) | (tempB >> 16); // put B in R␊ |
628 | ␊ |
629 | ␉␉␉␉␉a = (s >> 24) + 1;␊ |
630 | ␊ |
631 | ␉␉␉␉␉dstrb = *d & 0xFF00FF; dstg = *d & 0xFF00;␊ |
632 | ␉␉␉␉␉srcrb = s & 0xFF00FF; srcg = s & 0xFF00;␊ |
633 | ␊ |
634 | ␉␉␉␉␉drb = srcrb - dstrb;␊ |
635 | ␉␉␉␉␉dg = srcg - dstg;␊ |
636 | ␉␉␉␉␉drb *= a; dg *= a;␊ |
637 | ␉␉␉␉␉drb >>= 8; dg >>= 8;␊ |
638 | ␊ |
639 | ␉␉␉␉␉rb = (drb + dstrb) & 0xFF00FF;␊ |
640 | ␉␉␉␉␉g = (dg + dstg) & 0xFF00;␊ |
641 | ␊ |
642 | ␉␉␉␉␉*d = rb | g;␊ |
643 | ␉␉␉␉}␊ |
644 | ␉␉␉}␊ |
645 | ␉␉␉break;␊ |
646 | ␊ |
647 | ␉␉␉default: /*Universal version*/␊ |
648 | ␉␉␉{␊ |
649 | ␉␉␉␉uint32_t s; ␊ |
650 | ␉␉␉␉uint32_t a; // Alpha␊ |
651 | ␉␉␉␉uint32_t dr, dg, db, sr, sg, sb; // Intermediate variables␊ |
652 | ␉␉␉␉uint16_t pos;␊ |
653 | ␉␉␉␉int bpp = (VIDEO (depth) + 7)/8;␊ |
654 | ␊ |
655 | ␉␉␉␉for (pos = 0; pos < drawWidth; pos ++) {␊ |
656 | ␉␉␉␉␉// Fast pseudo-vector alpha blending, adapted from: http://www.stereopsis.com/doubleblend.html␊ |
657 | ␉␉␉␉␉s = *((uint32_t*) (data + 4*pos));␊ |
658 | ␉␉␉␉␉␊ |
659 | ␉␉␉␉␉sb = (s & 0xFF0000) >> 16;␊ |
660 | ␉␉␉␉␉sg = (s & 0xFF00) >> 8;␊ |
661 | ␉␉␉␉␉sr = (s & 0xFF);␊ |
662 | ␉␉␉␉␉␊ |
663 | ␉␉␉␉␉a = (s >> 24) + 1;␊ |
664 | ␊ |
665 | ␉␉␉␉␉switch (VIDEO (depth))␊ |
666 | ␉␉␉␉␉{␊ |
667 | ␉␉␉␉␉␉case 24:␊ |
668 | ␉␉␉␉␉␉␉db = ((*(uint32_t *)(vram + bpp*pos))&0xff);␊ |
669 | ␉␉␉␉␉␉␉dg = ((*(uint32_t *)(vram + bpp*pos))&0xff00)>>8;␊ |
670 | ␉␉␉␉␉␉␉dr = ((*(uint32_t *)(vram + bpp*pos))&0xff0000)>>16;␊ |
671 | ␉␉␉␉␉␉␉break;␊ |
672 | ␉␉␉␉␉␉case 16://16-bit seems to be 15-bit␊ |
673 | /*␉␉␉␉␉␉␉db = ((*(uint16_t *)(vram + bpp*pos))&0x1f)<<3;␊ |
674 | ␉␉␉␉␉␉␉dg = ((*(uint16_t *)(vram + bpp*pos))&0x07e0)>>3;␊ |
675 | ␉␉␉␉␉␉␉dr = ((*(uint16_t *)(vram + bpp*pos))&0xf800)>>8;␊ |
676 | ␉␉␉␉␉␉␉break;␉␉␉␉␉␉␉*/␊ |
677 | ␉␉␉␉␉␉case 15:␊ |
678 | ␉␉␉␉␉␉␉db = ((*(uint16_t *)(vram + bpp*pos))&0x1f)<<3;␊ |
679 | ␉␉␉␉␉␉␉dg = ((*(uint16_t *)(vram + bpp*pos))&0x03e0)>>2;␊ |
680 | ␉␉␉␉␉␉␉dr = ((*(uint16_t *)(vram + bpp*pos))&0x7c00)>>7;␊ |
681 | ␉␉␉␉␉␉␉break;␊ |
682 | ␉␉␉␉␉␉default:␊ |
683 | ␉␉␉␉␉␉␉return;␊ |
684 | ␉␉␉␉␉}␊ |
685 | ␊ |
686 | ␉␉␉␉␉dr = (((sr - dr) * a) >> 8) + dr;␊ |
687 | ␉␉␉␉␉dg = (((sg - dg) * a) >> 8) + dg;␊ |
688 | ␉␉␉␉␉db = (((sb - db) * a) >> 8) + db;␊ |
689 | ␉␉␉␉␉switch (VIDEO (depth))␊ |
690 | ␉␉␉␉␉{␊ |
691 | ␉␉␉␉␉␉case 24:␊ |
692 | ␉␉␉␉␉␉␉*(uint32_t *)(vram + bpp*pos) = (*(uint32_t *)(vram + bpp*pos) &0xff000000)␊ |
693 | ␉␉␉␉␉␉␉| (db&0xff) | ((dg&0xff)<<8) | ((dr&0xff)<<16);␊ |
694 | ␉␉␉␉␉␉␉break;␊ |
695 | ␉␉␉␉␉␉case 16:␊ |
696 | //␉␉␉␉␉␉␉*(uint16_t *)(vram + bpp*pos) = ((db&0xf8)>>3) | ((dg&0xfc)<<3) | ((dr&0xf8)<<8);␊ |
697 | //␉␉␉␉␉␉␉break;␉␉␉␉␉␉␉␊ |
698 | ␉␉␉␉␉␉case 15:␊ |
699 | ␉␉␉␉␉␉␉*(uint16_t *)(vram + bpp*pos) = ((db&0xf8)>>3) | ((dg&0xf8)<<2) | ((dr&0xf8)<<7);␊ |
700 | ␉␉␉␉␉␉␉break;␉␉␉␉␉␉␉␉␉␉␉␉␉␉␊ |
701 | ␉␉␉␉␉}␊ |
702 | ␊ |
703 | ␉␉␉␉}␊ |
704 | ␉␉␉}␊ |
705 | ␉␉␉break;␊ |
706 | }␊ |
707 | vram += VIDEO(rowBytes);␊ |
708 | data += width * 4;␊ |
709 | }␊ |
710 | }␊ |
711 | ␊ |
712 | //==============================================================================␊ |
713 | // ProgressBar␊ |
714 | void drawCheckerBoard()␊ |
715 | {␊ |
716 | uint32_t *vram = (uint32_t *) VIDEO(baseAddr);␊ |
717 | uint16_t x, y;␊ |
718 | uint8_t color;␊ |
719 | ␊ |
720 | for (y = 0; y < VIDEO(height); y++, vram += VIDEO(width)) {␊ |
721 | for (x = 0; x < VIDEO(width); x++) {␊ |
722 | color = 204 + 51 * (((x / 8) % 2) == ((y / 8) % 2));␊ |
723 | vram[x] = (color << 16) | (color << 8) | color;␊ |
724 | }␊ |
725 | }␊ |
726 | }␊ |
727 | ␊ |
728 | //==========================================================================␊ |
729 | // LookUpCLUTIndex␊ |
730 | ␊ |
731 | unsigned long lookUpCLUTIndex( unsigned char index )␊ |
732 | {␊ |
733 | ␉long colorIndex = (index * 3);␊ |
734 | ␉long red;␊ |
735 | ␉long green;␊ |
736 | ␉long blue;␊ |
737 | ␊ |
738 | ␉if ( ( MacOSVerCurrent >= MacOSVer2Int("10.10") ) && ( FlagBlackOption ) ) // Yosemite and Up!␊ |
739 | ␉{␊ |
740 | ␉␉// BlackMode␊ |
741 | ␉␉red = AppleLogoBlackClut[ colorIndex ];␊ |
742 | ␉␉green = AppleLogoBlackClut[ colorIndex++ ];␊ |
743 | ␉␉blue = AppleLogoBlackClut[ colorIndex++ ];␊ |
744 | ␉}␊ |
745 | ␉else␊ |
746 | ␉{␊ |
747 | ␉␉red = AppleLogoClut[ colorIndex ];␊ |
748 | ␉␉green = AppleLogoClut[ colorIndex++ ];␊ |
749 | ␉␉blue = AppleLogoClut[ colorIndex++ ];␊ |
750 | ␉}␊ |
751 | ␊ |
752 | ␉return (red << 16) | (green << 8) | blue;␊ |
753 | }␊ |
754 | ␊ |
755 | //==========================================================================␊ |
756 | ␊ |
757 | void *stosl(void *dst, long val, long len)␊ |
758 | {␊ |
759 | ␉asm volatile ( "rep; stosl"␊ |
760 | ␉␉␉␉ : "=c" (len), "=D" (dst)␊ |
761 | ␉␉␉␉ : "0" (len), "1" (dst), "a" (val)␊ |
762 | ␉␉␉␉ : "memory" );␊ |
763 | ␊ |
764 | ␉return dst;␊ |
765 | }␊ |
766 | ␊ |
767 | //==============================================================================␊ |
768 | ␊ |
769 | void setBackgroundColor( uint32_t color )␊ |
770 | {␊ |
771 | ␉long␉pixelBytes = VIDEO(depth) / 8;␊ |
772 | ␉char␉*vram = (char *) VIDEO(baseAddr) + VIDEO(rowBytes) + pixelBytes;␊ |
773 | ␊ |
774 | ␉int width = VIDEO(width);␊ |
775 | ␉int height = VIDEO(height);␊ |
776 | ␊ |
777 | ␉int rem = ( pixelBytes * width ) % 4;␊ |
778 | ␉int length = pixelBytes * width / 4;␊ |
779 | ␊ |
780 | ␉bcopy( &color, vram, rem );␊ |
781 | ␊ |
782 | ␉while ( height-- )␊ |
783 | ␉{␊ |
784 | ␉␉stosl( vram + rem, color, length );␊ |
785 | ␉␉vram += VIDEO(rowBytes);␊ |
786 | ␉}␊ |
787 | }␊ |
788 | ␊ |
789 | //==========================================================================␊ |
790 | // drawDataRectangle␊ |
791 | ␊ |
792 | void drawDataRectangle( unsigned short x, unsigned short y, unsigned short width, unsigned short height, unsigned char *data )␊ |
793 | {␊ |
794 | ␉unsigned short drawWidth;␊ |
795 | ␊ |
796 | ␉long pixelBytes = VIDEO(depth) / 8;␊ |
797 | ␊ |
798 | ␉unsigned char * vram = (unsigned char *) VIDEO(baseAddr) + VIDEO(rowBytes) * y + pixelBytes * x;␊ |
799 | ␊ |
800 | ␉drawWidth = MIN(width, VIDEO(width) - x);␊ |
801 | ␉height = MIN(height, VIDEO(height) - y);␊ |
802 | ␊ |
803 | ␉while ( height-- )␊ |
804 | ␉{␊ |
805 | ␉␉bcopy( data, vram, width * pixelBytes );␊ |
806 | ␉␉vram += VIDEO(rowBytes);␊ |
807 | ␉␉data += width * pixelBytes;␊ |
808 | ␉}␊ |
809 | }␊ |
810 | ␊ |
811 | //==============================================================================␊ |
812 | ␊ |
813 | void loadImageScale (void *input, int iw, int ih, int ip, void *output, int ow, int oh, int op, int or)␊ |
814 | {␊ |
815 | ␉int x, y, off;␊ |
816 | ␉int red = 0x7f, green = 0x7f, blue = 0x7f;␊ |
817 | ␉for ( x = 0; x < ow; x++)␊ |
818 | ␉␉for ( y = 0; y < oh; y++ )␊ |
819 | ␉␉{␊ |
820 | ␉␉␉off = ( x * iw ) / ow +( ( y * ih ) / oh ) * iw;␊ |
821 | ␉␉␉switch (ip)␊ |
822 | ␉␉␉{␊ |
823 | ␉␉␉␉case 16:␊ |
824 | ␉␉␉␉{␊ |
825 | ␉␉␉␉␉uint16_t val;␊ |
826 | ␉␉␉␉␉val=((uint16_t *)input)[off];␊ |
827 | ␉␉␉␉␉red=(val>>7)&0xf8;␊ |
828 | ␉␉␉␉␉green=(val>>2)&0xf8;␊ |
829 | ␉␉␉␉␉blue=(val<<3)&0xf8;␊ |
830 | ␉␉␉␉␉break;␊ |
831 | ␉␉␉␉}␊ |
832 | ␉␉␉␉case 32:␊ |
833 | ␉␉␉␉{␊ |
834 | ␉␉␉␉␉uint32_t val;␊ |
835 | ␉␉␉␉␉val=((uint32_t *)input)[off];␊ |
836 | ␉␉␉␉␉red=(val>>16)&0xff;␊ |
837 | ␉␉␉␉␉green=(val>>8)&0xff;␊ |
838 | ␉␉␉␉␉blue=(val)&0xff;␊ |
839 | ␉␉␉␉␉break;␊ |
840 | ␉␉␉␉}␊ |
841 | ␉␉␉}␊ |
842 | ␉␉␉char *ptr=(char *)output+x*(op/8)+y*or;␊ |
843 | ␉␉␉switch (op)␊ |
844 | ␉␉␉{␊ |
845 | ␉␉␉␉case 16:␊ |
846 | ␉␉␉␉␉*((uint16_t *)ptr) = ((red & 0xF8) << 7) | ␊ |
847 | ␉␉␉␉␉((green & 0xF8) << 2) |␊ |
848 | ␉␉␉␉␉((blue & 0xF8) >> 3);␊ |
849 | ␉␉␉␉␉break;␊ |
850 | ␉␉␉␉case 32 :␊ |
851 | ␉␉␉␉␉*((uint32_t *)ptr) = (red << 16) | (green << 8) | blue;␊ |
852 | ␉␉␉␉␉break;␊ |
853 | ␉␉␉}␊ |
854 | ␉␉}␊ |
855 | }␊ |
856 | ␊ |
857 | //==============================================================================␊ |
858 | ␊ |
859 | DECLARE_IOHIBERNATEPROGRESSALPHA␊ |
860 | ␊ |
861 | void drawPreview(void *src, uint8_t *saveunder)␊ |
862 | {␊ |
863 | ␉uint8_t *screen;␊ |
864 | ␉uint32_t rowBytes, pixelShift;␊ |
865 | ␉uint32_t x, y;␊ |
866 | ␉int32_t blob;␊ |
867 | ␉uint32_t alpha, in, color, result;␊ |
868 | ␉uint8_t *out;␊ |
869 | ␉void *uncomp;␊ |
870 | ␉int origwidth, origheight, origbpx;␊ |
871 | ␉uint32_t saveindex[kIOHibernateProgressCount] = { 0 };␊ |
872 | ␊ |
873 | ␉if (src && (uncomp=DecompressData(src, &origwidth, &origheight, &origbpx)))␊ |
874 | ␉{␊ |
875 | ␉␉if (!setVESAGraphicsMode(origwidth, origheight, origbpx, 0))␊ |
876 | ␉␉␉if (initGraphicsMode () != errSuccess)␊ |
877 | ␉␉␉{␊ |
878 | ␉␉␉␉return;␊ |
879 | ␉␉␉}␊ |
880 | ␊ |
881 | ␉␉screen = (uint8_t *) VIDEO (baseAddr);␊ |
882 | ␉␉rowBytes = VIDEO (rowBytes);␊ |
883 | ␉␉loadImageScale (uncomp, origwidth, origheight, origbpx, screen, VIDEO(width), VIDEO(height), VIDEO(depth), VIDEO (rowBytes));␊ |
884 | ␉}␊ |
885 | ␉else␊ |
886 | ␉{␊ |
887 | ␉␉if (initGraphicsMode () != errSuccess)␊ |
888 | ␉␉{␊ |
889 | ␉␉␉return;␊ |
890 | ␉␉}␊ |
891 | ␊ |
892 | ␉␉screen = (uint8_t *) VIDEO (baseAddr);␊ |
893 | ␉␉rowBytes = VIDEO (rowBytes);␊ |
894 | ␊ |
895 | ␉␉if ( ( MacOSVerCurrent >= MacOSVer2Int("10.10") ) && ( FlagBlackOption ) ) // Yosemite and Up!␊ |
896 | ␉␉{␊ |
897 | ␉␉␉// BlackMode␊ |
898 | ␉␉␉setBackgroundColor(0xff000000);␊ |
899 | ␉␉}␊ |
900 | ␉␉else␊ |
901 | ␉␉{␊ |
902 | ␉␉␉// Set the screen to 75% grey.␊ |
903 | ␉␉␉setBackgroundColor(0xffbfbfbf);␊ |
904 | ␉␉}␊ |
905 | ␉}␊ |
906 | ␊ |
907 | ␉pixelShift = VIDEO (depth) >> 4;␊ |
908 | ␉if (pixelShift < 1)␊ |
909 | ␉{␊ |
910 | ␉␉return;␊ |
911 | ␉}␊ |
912 | ␊ |
913 | ␉screen += ((VIDEO (width) ␊ |
914 | ␉␉␉␉- kIOHibernateProgressCount * (kIOHibernateProgressWidth + kIOHibernateProgressSpacing)) << (pixelShift - 1))␊ |
915 | ␉+ (VIDEO (height) - kIOHibernateProgressOriginY - kIOHibernateProgressHeight) * rowBytes;␊ |
916 | ␊ |
917 | ␉for (y = 0; y < kIOHibernateProgressHeight; y++)␊ |
918 | ␉{␊ |
919 | ␉␉out = screen + y * rowBytes;␊ |
920 | ␉␉for (blob = 0; blob < kIOHibernateProgressCount; blob++)␊ |
921 | ␉␉{␊ |
922 | ␉␉␉color = blob ? kIOHibernateProgressDarkGray : kIOHibernateProgressMidGray;␊ |
923 | ␉␉␉for (x = 0; x < kIOHibernateProgressWidth; x++)␊ |
924 | ␉␉␉{␊ |
925 | ␉␉␉␉alpha = gIOHibernateProgressAlpha[y][x];␊ |
926 | ␉␉␉␉result = color;␊ |
927 | ␉␉␉␉if (alpha)␊ |
928 | ␉␉␉␉{␊ |
929 | ␉␉␉␉␉if (0xff != alpha)␊ |
930 | ␉␉␉␉␉{␊ |
931 | ␉␉␉␉␉␉if (1 == pixelShift)␊ |
932 | ␉␉␉␉␉␉{␊ |
933 | ␉␉␉␉␉␉␉in = *((uint16_t *)out) & 0x1f;␉// 16␊ |
934 | ␉␉␉␉␉␉␉in = (in << 3) | (in >> 2);␊ |
935 | ␉␉␉␉␉␉}␊ |
936 | ␉␉␉␉␉␉else␊ |
937 | ␉␉␉␉␉␉{␊ |
938 | ␉␉␉␉␉␉␉in = *((uint32_t *)out) & 0xff;␉// 32␊ |
939 | ␉␉␉␉␉␉}␊ |
940 | ␊ |
941 | ␉␉␉␉␉␉saveunder[blob * kIOHibernateProgressSaveUnderSize + saveindex[blob]++] = in;␊ |
942 | ␉␉␉␉␉␉result = ((255 - alpha) * in + alpha * result + 0xff) >> 8;␊ |
943 | ␉␉␉␉␉}␊ |
944 | ␉␉␉␉␉if (1 == pixelShift)␊ |
945 | ␉␉␉␉␉{␊ |
946 | ␉␉␉␉␉␉result >>= 3;␊ |
947 | ␉␉␉␉␉␉*((uint16_t *)out) = (result << 10) | (result << 5) | result;␉// 16␊ |
948 | ␉␉␉␉␉}␊ |
949 | ␉␉␉␉␉else␊ |
950 | ␉␉␉␉␉{␊ |
951 | ␉␉␉␉␉␉*((uint32_t *)out) = (result << 16) | (result << 8) | result;␉// 32␊ |
952 | ␉␉␉␉␉}␊ |
953 | ␊ |
954 | ␉␉␉␉}␊ |
955 | ␉␉␉␉out += (1 << pixelShift);␊ |
956 | ␉␉␉}␊ |
957 | ␉␉␉out += (kIOHibernateProgressSpacing << pixelShift);␊ |
958 | ␉␉}␊ |
959 | ␉}␊ |
960 | }␊ |
961 | ␊ |
962 | //==============================================================================␊ |
963 | ␊ |
964 | void updateProgressBar(uint8_t *saveunder, int32_t firstBlob, int32_t select)␊ |
965 | {␊ |
966 | ␉uint8_t␉␉*screen;␊ |
967 | ␉uint32_t␉rowBytes, pixelShift;␊ |
968 | ␉uint32_t␉x, y;␊ |
969 | ␉int32_t␉␉blob, lastBlob;␊ |
970 | ␉uint32_t␉alpha, in, color, result;␊ |
971 | ␉uint8_t␉␉*out;␊ |
972 | ␉uint32_t saveindex[kIOHibernateProgressCount] = { 0 };␊ |
973 | ␊ |
974 | ␉pixelShift = VIDEO(depth) >> 4;␊ |
975 | ␉if (pixelShift < 1) return;␊ |
976 | ␉screen = (uint8_t *) VIDEO (baseAddr);␊ |
977 | ␉rowBytes = VIDEO (rowBytes);␊ |
978 | ␊ |
979 | ␉screen += ((VIDEO (width) ␊ |
980 | ␉␉␉␉- kIOHibernateProgressCount * (kIOHibernateProgressWidth + kIOHibernateProgressSpacing)) << (pixelShift - 1))␊ |
981 | ␉+ (VIDEO (height) - kIOHibernateProgressOriginY - kIOHibernateProgressHeight) * rowBytes;␊ |
982 | ␊ |
983 | ␉lastBlob = (select < kIOHibernateProgressCount) ? select : (kIOHibernateProgressCount - 1);␊ |
984 | ␊ |
985 | ␉screen += (firstBlob * (kIOHibernateProgressWidth + kIOHibernateProgressSpacing)) << pixelShift;␊ |
986 | ␊ |
987 | ␉for (y = 0; y < kIOHibernateProgressHeight; y++)␊ |
988 | ␉{␊ |
989 | ␉␉out = screen + y * rowBytes;␊ |
990 | ␉␉for (blob = firstBlob; blob <= lastBlob; blob++)␊ |
991 | ␉␉{␊ |
992 | ␉␉␉color = (blob < select) ? kIOHibernateProgressLightGray : kIOHibernateProgressMidGray;␊ |
993 | ␉␉␉for (x = 0; x < kIOHibernateProgressWidth; x++)␊ |
994 | ␉␉␉{␊ |
995 | ␉␉␉␉alpha = gIOHibernateProgressAlpha[y][x];␊ |
996 | ␉␉␉␉result = color;␊ |
997 | ␉␉␉␉if (alpha)␊ |
998 | ␉␉␉␉{␊ |
999 | ␉␉␉␉␉if (0xff != alpha)␊ |
1000 | ␉␉␉␉␉{␊ |
1001 | ␉␉␉␉␉␉in = saveunder[blob * kIOHibernateProgressSaveUnderSize + saveindex[blob]++];␊ |
1002 | ␉␉␉␉␉␉result = ((255 - alpha) * in + alpha * result + 0xff) / 255;␊ |
1003 | ␉␉␉␉␉}␊ |
1004 | ␊ |
1005 | ␉␉␉␉␉if (1 == pixelShift)␊ |
1006 | ␉␉␉␉␉{␊ |
1007 | ␉␉␉␉␉␉result >>= 3;␊ |
1008 | ␉␉␉␉␉␉*((uint16_t *)out) = (result << 10) | (result << 5) | result;␉// 16␊ |
1009 | ␉␉␉␉␉}␊ |
1010 | ␉␉␉␉␉else␊ |
1011 | ␉␉␉␉␉{␊ |
1012 | ␉␉␉␉␉␉*((uint32_t *)out) = (result << 16) | (result << 8) | result;␉// 32␊ |
1013 | ␉␉␉␉␉}␊ |
1014 | ␉␉␉␉}␊ |
1015 | ␉␉␉␉out += (1 << pixelShift);␊ |
1016 | ␉␉␉}␊ |
1017 | ␉␉␉out += (kIOHibernateProgressSpacing << pixelShift);␊ |
1018 | ␉␉}␊ |
1019 | ␉}␊ |
1020 | }␊ |
1021 | ␊ |
1022 | //==========================================================================␊ |
1023 | // setVESATextMode␊ |
1024 | ␊ |
1025 | static int setVESATextMode( unsigned short cols, unsigned short rows, unsigned char bitsPerPixel )␊ |
1026 | {␊ |
1027 | ␉VBEModeInfoBlock minfo;␊ |
1028 | ␉unsigned short mode = modeEndOfList;␊ |
1029 | ␊ |
1030 | ␉if ( (cols != 80) || (rows != 25) ) // not 80x25 mode␊ |
1031 | ␉{␊ |
1032 | ␉␉mode = getVESAModeWithProperties( cols, rows, bitsPerPixel,␊ |
1033 | maColorModeBit |␊ |
1034 | maModeIsSupportedBit,␊ |
1035 | maGraphicsModeBit,␊ |
1036 | &minfo, NULL );␊ |
1037 | ␉}␊ |
1038 | ␊ |
1039 | ␉if ( ( mode == modeEndOfList ) || ( setVBEMode(mode, NULL) != errSuccess ) )␊ |
1040 | ␉{␊ |
1041 | ␉␉video_mode( 2 ); // VGA BIOS, 80x25 text mode.␊ |
1042 | ␉␉minfo.XResolution = 80;␊ |
1043 | ␉␉minfo.YResolution = 25;␊ |
1044 | ␉}␊ |
1045 | ␊ |
1046 | ␉// Update KernBootStruct using info provided by the selected␊ |
1047 | ␉// VESA mode.␊ |
1048 | ␊ |
1049 | ␉bootArgs->Video.v_display = VGA_TEXT_MODE;␊ |
1050 | ␉bootArgs->Video.v_baseAddr = 0xb8000;␊ |
1051 | ␉bootArgs->Video.v_width = minfo.XResolution;␊ |
1052 | ␉bootArgs->Video.v_height = minfo.YResolution;␊ |
1053 | ␉bootArgs->Video.v_depth = 8;␊ |
1054 | ␉bootArgs->Video.v_rowBytes = 0x8000;␊ |
1055 | ␊ |
1056 | ␉return errSuccess; // always return success␊ |
1057 | }␊ |
1058 | ␊ |
1059 | //==========================================================================␊ |
1060 | // getNumberArrayFromProperty␊ |
1061 | ␊ |
1062 | static int getNumberArrayFromProperty( const char *propKey,␊ |
1063 | unsigned long numbers[],␊ |
1064 | unsigned long maxArrayCount )␊ |
1065 | {␊ |
1066 | ␉char␉␉*propStr;␊ |
1067 | ␉unsigned long␉count = 0;␊ |
1068 | ␊ |
1069 | ␉propStr = newStringForKey((char *)propKey , &bootInfo->chameleonConfig);␊ |
1070 | ␊ |
1071 | ␉if (propStr)␊ |
1072 | ␉{␊ |
1073 | ␉␉char *delimiter = propStr;␊ |
1074 | ␉␉char *p = propStr;␊ |
1075 | ␊ |
1076 | ␉␉while ((count < maxArrayCount) && (*p != '\0'))␊ |
1077 | ␉␉{␊ |
1078 | ␉␉␉unsigned long val = strtoul(p, &delimiter, 10);␊ |
1079 | ␉␉␉if (p != delimiter)␊ |
1080 | ␉␉␉{␊ |
1081 | ␉␉␉␉numbers[count++] = val;␊ |
1082 | ␉␉␉␉p = delimiter;␊ |
1083 | ␉␉␉}␊ |
1084 | ␉␉␉while ((*p != '\0') && !isdigit(*p))␊ |
1085 | ␉␉␉␉p++;␊ |
1086 | ␉␉}␊ |
1087 | ␊ |
1088 | ␉␉free(propStr);␊ |
1089 | ␉}␊ |
1090 | ␊ |
1091 | ␉return count;␊ |
1092 | }␊ |
1093 | ␊ |
1094 | //==============================================================================␊ |
1095 | ␊ |
1096 | int initGraphicsMode ()␊ |
1097 | {␊ |
1098 | ␉unsigned long params[4];␊ |
1099 | ␉int count;␊ |
1100 | ␊ |
1101 | ␉params[3] = 0;␊ |
1102 | ␉count = getNumberArrayFromProperty( kGraphicsModeKey, params, 4 );␊ |
1103 | ␊ |
1104 | ␉// Try to find a resolution if "Graphics Mode" setting is not available.␊ |
1105 | ␉if ( count < 3 )␊ |
1106 | ␉{␊ |
1107 | ␉␉// Use the default resolution if we don't have an initialized GUI.␊ |
1108 | ␉␉if (gui.screen.width == 0 || gui.screen.height == 0)␊ |
1109 | ␉␉{␊ |
1110 | ␉␉␉gui.screen.width = DEFAULT_SCREEN_WIDTH;␊ |
1111 | ␉␉␉gui.screen.height = DEFAULT_SCREEN_HEIGHT;␊ |
1112 | ␉␉}␊ |
1113 | ␊ |
1114 | ␉␉params[0] = gui.screen.width;␊ |
1115 | ␉␉params[1] = gui.screen.height;␊ |
1116 | ␉␉params[2] = 32;␊ |
1117 | ␉}␊ |
1118 | ␊ |
1119 | ␉// Map from pixel format to bits per pixel.␊ |
1120 | ␊ |
1121 | ␉if ( params[2] == 256 )␊ |
1122 | ␉␉params[2] = 8;␊ |
1123 | ␊ |
1124 | ␉if ( params[2] == 555 )␊ |
1125 | ␉␉params[2] = 16;␊ |
1126 | ␊ |
1127 | ␉if ( params[2] == 888 )␊ |
1128 | ␉␉params[2] = 32;␊ |
1129 | ␊ |
1130 | ␉return setVESAGraphicsMode( params[0], params[1], params[2], params[3] );␊ |
1131 | }␊ |
1132 | ␊ |
1133 | //==========================================================================␊ |
1134 | // setVideoMode␊ |
1135 | //␊ |
1136 | // Set the video mode to VGA_TEXT_MODE or GRAPHICS_MODE.␊ |
1137 | ␊ |
1138 | void setVideoMode( int mode )␊ |
1139 | {␊ |
1140 | ␉unsigned long params[4];␊ |
1141 | ␉int err = errSuccess;␊ |
1142 | ␊ |
1143 | ␉if ( mode == GRAPHICS_MODE )␊ |
1144 | ␉{␊ |
1145 | ␉␉if ( (err = initGraphicsMode()) == errSuccess )␊ |
1146 | ␉␉{␊ |
1147 | ␉␉␉// Tell the kernel to use text mode on a linear frame buffer display␊ |
1148 | ␉␉␉bootArgs->Video.v_display = (gVerboseMode) ? /* 2 */ FB_TEXT_MODE : /* 1 */ GRAPHICS_MODE;␊ |
1149 | ␉␉}␊ |
1150 | ␉}␊ |
1151 | ␊ |
1152 | ␉if ( (mode == VGA_TEXT_MODE) || (err != errSuccess) )␊ |
1153 | ␉{␊ |
1154 | ␉␉params[0] = 80; // Default text mode is 80x25.␊ |
1155 | ␉␉params[1] = 25;␊ |
1156 | ␊ |
1157 | ␉␉setVESATextMode(params[0], params[1], 4);␊ |
1158 | ␉␉bootArgs->Video.v_display = VGA_TEXT_MODE;␊ |
1159 | ␉}␊ |
1160 | }␊ |
1161 | ␊ |
1162 | //==============================================================================␊ |
1163 | void getGraphicModeParams(unsigned long params[])␊ |
1164 | {␊ |
1165 | ␉params[3] = 0;␊ |
1166 | ␊ |
1167 | ␉VBEModeInfoBlock minfo;␊ |
1168 | ␊ |
1169 | ␉unsigned short vesaVersion;␊ |
1170 | ␉unsigned short mode = modeEndOfList;␊ |
1171 | ␊ |
1172 | ␉getNumberArrayFromProperty(kGraphicsModeKey, params, 4);␊ |
1173 | ␊ |
1174 | ␉mode = getVESAModeWithProperties(params[0], params[1], params[2],␊ |
1175 | ␉␉␉␉␉␉␉␉␉ maColorModeBit |␊ |
1176 | ␉␉␉␉␉␉␉␉␉ maModeIsSupportedBit |␊ |
1177 | ␉␉␉␉␉␉␉␉␉ maGraphicsModeBit |␊ |
1178 | ␉␉␉␉␉␉␉␉␉ maLinearFrameBufferAvailBit,␊ |
1179 | ␉␉␉␉␉␉␉␉␉ 0,␊ |
1180 | ␉␉␉␉␉␉␉␉␉ &minfo, &vesaVersion);␊ |
1181 | ␊ |
1182 | ␉params[0] = minfo.XResolution;␊ |
1183 | ␉params[1] = minfo.YResolution;␊ |
1184 | ␉params[2] = 32;␊ |
1185 | }␊ |
1186 | ␉␊ |
1187 | //==========================================================================␊ |
1188 | // Return the current video mode, VGA_TEXT_MODE or GRAPHICS_MODE.␊ |
1189 | ␊ |
1190 | int getVideoMode(void)␊ |
1191 | {␊ |
1192 | return bootArgs->Video.v_display;␊ |
1193 | }␊ |
1194 | ␊ |
1195 | //==========================================================================␊ |
1196 | // Display and clear the activity indicator.␊ |
1197 | ␊ |
1198 | // BASIC Indicator␊ |
1199 | static char indicator[] = {'-', '\\', '|', '/', '\0'};␊ |
1200 | ␊ |
1201 | // To prevent a ridiculously fast-spinning indicator,␊ |
1202 | // ensure a minimum of 1/9 sec between animation frames.␊ |
1203 | #define MIN_TICKS 2␊ |
1204 | ␊ |
1205 | //==============================================================================␊ |
1206 | ␊ |
1207 | void spinActivityIndicator(int sectors)␊ |
1208 | {␊ |
1209 | static unsigned long lastTickTime = 0, currentTickTime;␊ |
1210 | ␊ |
1211 | ␉if (previewTotalSectors && previewSaveunder)␊ |
1212 | ␉{␊ |
1213 | ␉␉int blob, lastBlob;␊ |
1214 | ␊ |
1215 | ␉␉lastBlob = (previewLoadedSectors * kIOHibernateProgressCount) / previewTotalSectors;␊ |
1216 | ␉␉previewLoadedSectors+=sectors;␊ |
1217 | ␉␉blob = (previewLoadedSectors * kIOHibernateProgressCount) / previewTotalSectors;␊ |
1218 | ␉␉␊ |
1219 | ␉␉if (blob!=lastBlob)␊ |
1220 | ␉␉{␊ |
1221 | ␉␉␉updateProgressBar (previewSaveunder, lastBlob, blob);␊ |
1222 | ␉␉}␊ |
1223 | ␉␉return;␊ |
1224 | ␉}␊ |
1225 | ␊ |
1226 | ␉currentTickTime = time18(); // late binding␊ |
1227 | ␉if (currentTickTime < lastTickTime + MIN_TICKS)␊ |
1228 | ␉{␊ |
1229 | ␉␉return;␊ |
1230 | ␉}␊ |
1231 | ␉else␊ |
1232 | ␉{␊ |
1233 | ␉␉lastTickTime = currentTickTime;␊ |
1234 | ␉}␊ |
1235 | ␊ |
1236 | ␉if (getVideoMode() == VGA_TEXT_MODE)␊ |
1237 | ␉{␊ |
1238 | ␉␉if (currentIndicator >= sizeof(indicator))␊ |
1239 | ␉␉{␊ |
1240 | ␉␉␉currentIndicator = 0;␊ |
1241 | ␉␉}␊ |
1242 | ␉␉putchar(indicator[currentIndicator++]);␊ |
1243 | ␉␉putchar('\b');␊ |
1244 | ␉}␊ |
1245 | }␊ |
1246 | ␊ |
1247 | //==============================================================================␊ |
1248 | ␊ |
1249 | void clearActivityIndicator( void )␊ |
1250 | {␊ |
1251 | ␉if ( getVideoMode() == VGA_TEXT_MODE )␊ |
1252 | ␉{␊ |
1253 | ␉␉putchar(' ');␊ |
1254 | ␉␉putchar('\b');␊ |
1255 | ␉}␊ |
1256 | }␊ |
1257 | ␊ |
1258 | //==============================================================================␊ |
1259 |