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