Root/
Source at commit 1163 created 13 years 12 days ago. By mozodojo, mistakes fixes in new _CST SSDT code (P.S. If you have better variables/keys naming option you welcome to change them) | |
---|---|
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 | #ifndef OPTION_ROM␊ |
50 | #endif␊ |
51 | ␊ |
52 | //==========================================================================␊ |
53 | // getVESAModeWithProperties␊ |
54 | //␊ |
55 | // Return the VESA mode that matches the properties specified.␊ |
56 | // If a mode is not found, then return the "best" available mode.␊ |
57 | ␊ |
58 | unsigned short␊ |
59 | getVESAModeWithProperties( unsigned short width,␊ |
60 | ␉␉␉␉␉␉ unsigned short height,␊ |
61 | ␉␉␉␉␉␉ unsigned char bitsPerPixel,␊ |
62 | ␉␉␉␉␉␉ unsigned short attributesSet,␊ |
63 | ␉␉␉␉␉␉ unsigned short attributesClear,␊ |
64 | ␉␉␉␉␉␉ VBEModeInfoBlock * outModeInfo,␊ |
65 | ␉␉␉␉␉␉ unsigned short * vesaVersion )␊ |
66 | {␊ |
67 | VBEInfoBlock vbeInfo;␊ |
68 | unsigned short * modePtr;␊ |
69 | VBEModeInfoBlock modeInfo;␊ |
70 | unsigned char modeBitsPerPixel;␊ |
71 | unsigned short matchedMode = modeEndOfList;␊ |
72 | int err;␊ |
73 | ␉␊ |
74 | // Clear output mode info.␊ |
75 | ␉␊ |
76 | bzero( outModeInfo, sizeof(*outModeInfo) );␊ |
77 | ␉␊ |
78 | // Get VBE controller info containing the list of supported modes.␊ |
79 | ␉␊ |
80 | bzero( &vbeInfo, sizeof(vbeInfo) );␊ |
81 | strcpy( (char*)&vbeInfo, "VBE2" );␊ |
82 | err = getVBEInfo( &vbeInfo );␊ |
83 | if ( err != errSuccess )␊ |
84 | {␊ |
85 | return modeEndOfList;␊ |
86 | }␊ |
87 | ␉␊ |
88 | // Report the VESA major/minor version number.␊ |
89 | ␉␊ |
90 | if (vesaVersion) *vesaVersion = vbeInfo.VESAVersion;␊ |
91 | ␉␊ |
92 | // Loop through the mode list, and find the matching mode.␊ |
93 | ␉␊ |
94 | for ( modePtr = VBEDecodeFP( unsigned short *, vbeInfo.VideoModePtr );␊ |
95 | ␉␉ *modePtr != modeEndOfList; modePtr++ )␊ |
96 | {␊ |
97 | // Get mode information.␊ |
98 | ␉␉␊ |
99 | bzero( &modeInfo, sizeof(modeInfo) );␊ |
100 | err = getVBEModeInfo( *modePtr, &modeInfo );␊ |
101 | if ( err != errSuccess )␊ |
102 | {␊ |
103 | continue;␊ |
104 | }␊ |
105 | ␉␉␊ |
106 | #if DEBUG␊ |
107 | printf("Mode %x: %dx%dx%d mm:%d attr:%x\n",␊ |
108 | *modePtr, modeInfo.XResolution, modeInfo.YResolution,␊ |
109 | modeInfo.BitsPerPixel, modeInfo.MemoryModel,␊ |
110 | modeInfo.ModeAttributes);␊ |
111 | #endif␊ |
112 | ␉␉␊ |
113 | // Filter out unwanted modes based on mode attributes.␊ |
114 | ␉␉␊ |
115 | if ( ( ( modeInfo.ModeAttributes & attributesSet ) != attributesSet )␊ |
116 | ␉␉␉|| ( ( modeInfo.ModeAttributes & attributesClear ) != 0 ) )␊ |
117 | {␊ |
118 | continue;␊ |
119 | }␊ |
120 | ␉␉␊ |
121 | // Pixel depth in bits.␊ |
122 | ␉␉␊ |
123 | modeBitsPerPixel = modeInfo.BitsPerPixel;␊ |
124 | ␉␉␊ |
125 | if ( ( modeBitsPerPixel == 4 ) && ( modeInfo.MemoryModel == 0 ) )␊ |
126 | {␊ |
127 | // Text mode, 16 colors.␊ |
128 | }␊ |
129 | else if ( ( modeBitsPerPixel == 8 ) && ( modeInfo.MemoryModel == 4 ) )␊ |
130 | {␊ |
131 | // Packed pixel, 256 colors.␊ |
132 | }␊ |
133 | else if ( ( ( modeBitsPerPixel == 16 ) || ( modeBitsPerPixel == 15 ) )␊ |
134 | ␉␉␉␉ && ( modeInfo.MemoryModel == 6 )␊ |
135 | ␉␉␉␉ && ( modeInfo.RedMaskSize == 5 )␊ |
136 | ␉␉␉␉ && ( modeInfo.GreenMaskSize == 5 )␊ |
137 | ␉␉␉␉ && ( modeInfo.BlueMaskSize == 5 ) )␊ |
138 | {␊ |
139 | // Direct color, 16 bpp (1:5:5:5).␊ |
140 | modeInfo.BitsPerPixel = modeBitsPerPixel = 16;␊ |
141 | }␊ |
142 | else if ( ( modeBitsPerPixel == 32 )␊ |
143 | ␉␉␉␉ && ( modeInfo.MemoryModel == 6 )␊ |
144 | ␉␉␉␉ && ( modeInfo.RedMaskSize == 8 )␊ |
145 | ␉␉␉␉ && ( modeInfo.GreenMaskSize == 8 )␊ |
146 | ␉␉␉␉ && ( modeInfo.BlueMaskSize == 8 ) )␊ |
147 | {␊ |
148 | // Direct color, 32 bpp (8:8:8:8).␊ |
149 | }␊ |
150 | else␊ |
151 | {␊ |
152 | continue; // Not a supported mode.␊ |
153 | }␊ |
154 | ␉␉␊ |
155 | // Modes larger than the specified dimensions are skipped.␊ |
156 | ␉␉␊ |
157 | if ( ( modeInfo.XResolution > width ) ||␊ |
158 | ␉␉␉( modeInfo.YResolution > height ) )␊ |
159 | {␊ |
160 | continue;␊ |
161 | }␊ |
162 | ␉␉␊ |
163 | // Perfect match, we're done looking.␊ |
164 | ␉␉␊ |
165 | if ( ( modeInfo.XResolution == width ) &&␊ |
166 | ␉␉␉( modeInfo.YResolution == height ) &&␊ |
167 | ␉␉␉( modeBitsPerPixel == bitsPerPixel ) )␊ |
168 | {␊ |
169 | matchedMode = *modePtr;␊ |
170 | bcopy( &modeInfo, outModeInfo, sizeof(modeInfo) );␊ |
171 | break;␊ |
172 | }␊ |
173 | ␉␉␊ |
174 | // Save the next "best" mode in case a perfect match is not found.␊ |
175 | ␉␉␊ |
176 | if ( modeInfo.XResolution == outModeInfo->XResolution &&␊ |
177 | ␉␉␉modeInfo.YResolution == outModeInfo->YResolution &&␊ |
178 | ␉␉␉modeBitsPerPixel <= outModeInfo->BitsPerPixel )␊ |
179 | {␊ |
180 | continue; // Saved mode has more depth.␊ |
181 | }␊ |
182 | if ( modeInfo.XResolution < outModeInfo->XResolution ||␊ |
183 | ␉␉␉modeInfo.YResolution < outModeInfo->YResolution ||␊ |
184 | ␉␉␉modeBitsPerPixel < outModeInfo->BitsPerPixel )␊ |
185 | {␊ |
186 | continue; // Saved mode has more resolution.␊ |
187 | }␊ |
188 | ␉␉␊ |
189 | matchedMode = *modePtr;␊ |
190 | bcopy( &modeInfo, outModeInfo, sizeof(modeInfo) );␊ |
191 | }␊ |
192 | ␉␊ |
193 | return matchedMode;␊ |
194 | }␊ |
195 | ␊ |
196 | //==========================================================================␊ |
197 | // setupPalette␊ |
198 | ␊ |
199 | static void setupPalette( VBEPalette * p, const unsigned char * g )␊ |
200 | {␊ |
201 | int i;␊ |
202 | unsigned char * source = (unsigned char *) g;␊ |
203 | ␉␊ |
204 | for (i = 0; i < 256; i++)␊ |
205 | {␊ |
206 | (*p)[i] = 0;␊ |
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␊ |
210 | }␊ |
211 | }␊ |
212 | ␊ |
213 | //==========================================================================␊ |
214 | // Simple decompressor for boot images encoded in RLE format.␊ |
215 | ␊ |
216 | char * decodeRLE( const void * rleData, int rleBlocks, int outBytes )␊ |
217 | {␊ |
218 | char *out, *cp;␊ |
219 | ␉␊ |
220 | struct RLEBlock {␊ |
221 | unsigned char count;␊ |
222 | unsigned char value;␊ |
223 | } * bp = (struct RLEBlock *) rleData;␊ |
224 | ␉␊ |
225 | out = cp = malloc( outBytes );␊ |
226 | if ( out == NULL ) return NULL;␊ |
227 | ␉␊ |
228 | while ( rleBlocks-- )␊ |
229 | {␊ |
230 | memset( cp, bp->value, bp->count );␊ |
231 | cp += bp->count;␊ |
232 | bp++;␊ |
233 | }␊ |
234 | ␉␊ |
235 | return out;␊ |
236 | }␊ |
237 | ␊ |
238 | //==========================================================================␊ |
239 | // setVESAGraphicsMode␊ |
240 | ␊ |
241 | int setVESAGraphicsMode( unsigned short width, unsigned short height, unsigned char bitsPerPixel, unsigned short refreshRate )␊ |
242 | {␊ |
243 | VBEModeInfoBlock minfo;␊ |
244 | unsigned short mode;␊ |
245 | unsigned short vesaVersion;␊ |
246 | int err = errFuncNotSupported;␊ |
247 | ␉␊ |
248 | do {␊ |
249 | mode = getVESAModeWithProperties( width, height, bitsPerPixel,␊ |
250 | ␉␉␉␉␉␉␉␉␉␉ maColorModeBit |␊ |
251 | ␉␉␉␉␉␉␉␉␉␉ maModeIsSupportedBit |␊ |
252 | ␉␉␉␉␉␉␉␉␉␉ maGraphicsModeBit |␊ |
253 | ␉␉␉␉␉␉␉␉␉␉ maLinearFrameBufferAvailBit,␊ |
254 | ␉␉␉␉␉␉␉␉␉␉ 0,␊ |
255 | ␉␉␉␉␉␉␉␉␉␉ &minfo, &vesaVersion );␊ |
256 | if ( mode == modeEndOfList )␊ |
257 | {␊ |
258 | break;␊ |
259 | }␊ |
260 | ␉␉␊ |
261 | ␉␉//␊ |
262 | ␉␉// FIXME : generateCRTCTiming() causes crash.␊ |
263 | ␉␉//␊ |
264 | ␉␉␊ |
265 | ␉␉// if ( (vesaVersion >> 8) >= 3 && refreshRate >= 60 &&␊ |
266 | ␉␉// (gBootMode & kBootModeSafe) == 0 )␊ |
267 | ␉␉// {␊ |
268 | ␉␉// VBECRTCInfoBlock timing;␊ |
269 | ␉␉// ␊ |
270 | ␉␉// // Generate CRTC timing for given refresh rate.␊ |
271 | ␉␉// ␊ |
272 | ␉␉// generateCRTCTiming( minfo.XResolution, minfo.YResolution,␊ |
273 | ␉␉// refreshRate, kCRTCParamRefreshRate,␊ |
274 | ␉␉// &timing );␊ |
275 | ␉␉// ␊ |
276 | ␉␉// // Find the actual pixel clock supported by the hardware.␊ |
277 | ␉␉// ␊ |
278 | ␉␉// getVBEPixelClock( mode, &timing.PixelClock );␊ |
279 | ␉␉// ␊ |
280 | ␉␉// // Re-compute CRTC timing based on actual pixel clock.␊ |
281 | ␉␉// ␊ |
282 | ␉␉// generateCRTCTiming( minfo.XResolution, minfo.YResolution,␊ |
283 | ␉␉// timing.PixelClock, kCRTCParamPixelClock,␊ |
284 | ␉␉// &timing );␊ |
285 | ␉␉// ␊ |
286 | ␉␉// // Set the video mode and use specified CRTC timing.␊ |
287 | ␉␉// ␊ |
288 | ␉␉// err = setVBEMode( mode | kLinearFrameBufferBit |␊ |
289 | ␉␉// kCustomRefreshRateBit, &timing );␊ |
290 | ␉␉// }␊ |
291 | ␉␉// else␊ |
292 | ␉␉// {␊ |
293 | ␉␉// // Set the mode with default refresh rate.␊ |
294 | ␉␉// ␊ |
295 | ␉␉// err = setVBEMode( mode | kLinearFrameBufferBit, NULL );␊ |
296 | ␉␉// }␊ |
297 | ␉␉␊ |
298 | // Set the mode with default refresh rate.␊ |
299 | ␉␉␊ |
300 | err = setVBEMode( mode | kLinearFrameBufferBit, NULL );␊ |
301 | ␉␉␊ |
302 | if ( err != errSuccess )␊ |
303 | {␊ |
304 | break;␊ |
305 | }␊ |
306 | ␉␉␊ |
307 | // Set 8-bit color palette.␊ |
308 | ␉␉␊ |
309 | if ( minfo.BitsPerPixel == 8 )␊ |
310 | {␊ |
311 | VBEPalette palette;␊ |
312 | setupPalette( &palette, appleClut8 );␊ |
313 | if ((err = setVBEPalette(palette)) != errSuccess)␊ |
314 | {␊ |
315 | break;␊ |
316 | }␊ |
317 | }␊ |
318 | ␉␉␊ |
319 | // Is this required for buggy Video BIOS implementations?␊ |
320 | // On which adapter?␊ |
321 | ␉␉␊ |
322 | if ( minfo.BytesPerScanline == 0 )␊ |
323 | ␉␉␉minfo.BytesPerScanline = ( minfo.XResolution *␊ |
324 | ␉␉␉␉␉␉␉␉␉ minfo.BitsPerPixel ) >> 3;␊ |
325 | ␉␉␊ |
326 | // Update KernBootStruct using info provided by the selected␊ |
327 | // VESA mode.␊ |
328 | ␉␉␊ |
329 | bootArgs->Video.v_display = GRAPHICS_MODE;␊ |
330 | ␉␉//␉␉setVideoMode(GRAPHICS_MODE, 0);␊ |
331 | bootArgs->Video.v_width = minfo.XResolution;␊ |
332 | bootArgs->Video.v_height = minfo.YResolution;␊ |
333 | bootArgs->Video.v_depth = minfo.BitsPerPixel;␊ |
334 | bootArgs->Video.v_rowBytes = minfo.BytesPerScanline;␊ |
335 | bootArgs->Video.v_baseAddr = VBEMakeUInt32(minfo.PhysBasePtr);␊ |
336 | ␉␉␊ |
337 | }␊ |
338 | while ( 0 );␊ |
339 | ␉␊ |
340 | return err;␊ |
341 | }␊ |
342 | ␊ |
343 | ␊ |
344 | #ifndef OPTION_ROM␊ |
345 | ␊ |
346 | ␊ |
347 | //==========================================================================␊ |
348 | // LookUpCLUTIndex␊ |
349 | ␊ |
350 | unsigned long lookUpCLUTIndex( unsigned char index,␊ |
351 | ␉␉␉␉␉␉␉ unsigned char depth )␊ |
352 | {␊ |
353 | long result, red, green, blue;␊ |
354 | ␉␊ |
355 | red = appleClut8[index * 3 + 0];␊ |
356 | green = appleClut8[index * 3 + 1];␊ |
357 | blue = appleClut8[index * 3 + 2];␊ |
358 | ␉␊ |
359 | switch (depth) {␊ |
360 | case 16 :␊ |
361 | result = ((red & 0xF8) << 7) | ␊ |
362 | ␉␉␉((green & 0xF8) << 2) |␊ |
363 | ␉␉␉((blue & 0xF8) >> 3);␊ |
364 | result |= (result << 16);␊ |
365 | break;␊ |
366 | ␉␉␉␊ |
367 | case 32 :␊ |
368 | result = (red << 16) | (green << 8) | blue;␊ |
369 | break;␊ |
370 | ␉␉␉␊ |
371 | default :␊ |
372 | result = index | (index << 8);␊ |
373 | result |= (result << 16);␊ |
374 | break;␊ |
375 | }␊ |
376 | ␉␊ |
377 | return result;␊ |
378 | }␊ |
379 | ␊ |
380 | //==========================================================================␊ |
381 | // drawColorRectangle␊ |
382 | ␊ |
383 | void * stosl(void * dst, long val, long len)␊ |
384 | {␊ |
385 | asm volatile ( "rep; stosl"␊ |
386 | ␉␉␉␉ : "=c" (len), "=D" (dst)␊ |
387 | ␉␉␉␉ : "0" (len), "1" (dst), "a" (val)␊ |
388 | ␉␉␉␉ : "memory" );␊ |
389 | ␉␊ |
390 | return dst;␊ |
391 | }␊ |
392 | ␊ |
393 | void drawColorRectangle( unsigned short x,␊ |
394 | ␉␉␉␉␉␉unsigned short y,␊ |
395 | ␉␉␉␉␉␉unsigned short width,␊ |
396 | ␉␉␉␉␉␉unsigned short height,␊ |
397 | ␉␉␉␉␉␉unsigned char colorIndex )␊ |
398 | {␊ |
399 | long pixelBytes;␊ |
400 | long color = lookUpCLUTIndex( colorIndex, VIDEO(depth) );␊ |
401 | char * vram;␊ |
402 | ␉␊ |
403 | pixelBytes = VIDEO(depth) / 8;␊ |
404 | vram = (char *) VIDEO(baseAddr) +␊ |
405 | ␉VIDEO(rowBytes) * y + pixelBytes * x;␊ |
406 | ␉␊ |
407 | width = MIN(width, VIDEO(width) - x);␊ |
408 | height = MIN(height, VIDEO(height) - y);␊ |
409 | ␉␊ |
410 | while ( height-- )␊ |
411 | {␊ |
412 | int rem = ( pixelBytes * width ) % 4;␊ |
413 | if ( rem ) bcopy( &color, vram, rem );␊ |
414 | stosl( vram + rem, color, pixelBytes * width / 4 );␊ |
415 | vram += VIDEO(rowBytes);␊ |
416 | }␊ |
417 | }␊ |
418 | ␊ |
419 | void␊ |
420 | loadImageScale (void *input, int iw, int ih, int ip, void *output, int ow, int oh, int op, int or)␊ |
421 | {␊ |
422 | ␉int x,y, off;␊ |
423 | ␉int red=0x7f, green=0x7f, blue=0x7f;␊ |
424 | ␉for (x=0;x<ow;x++)␊ |
425 | ␉␉for (y=0;y<oh;y++)␊ |
426 | ␉␉{␊ |
427 | ␉␉␉off=(x*iw)/ow+((y*ih)/oh)*iw;␊ |
428 | ␉␉␉switch (ip)␊ |
429 | ␉␉␉{␊ |
430 | ␉␉␉␉case 16:␊ |
431 | ␉␉␉␉{␊ |
432 | ␉␉␉␉␉uint16_t val;␊ |
433 | ␉␉␉␉␉val=((uint16_t *)input)[off];␊ |
434 | ␉␉␉␉␉red=(val>>7)&0xf8;␊ |
435 | ␉␉␉␉␉green=(val>>2)&0xf8;␊ |
436 | ␉␉␉␉␉blue=(val<<3)&0xf8;␊ |
437 | ␉␉␉␉␉break;␉␉␊ |
438 | ␉␉␉␉}␊ |
439 | ␉␉␉␉case 32:␊ |
440 | ␉␉␉␉{␊ |
441 | ␉␉␉␉␉uint32_t val;␊ |
442 | ␉␉␉␉␉val=((uint32_t *)input)[off];␊ |
443 | ␉␉␉␉␉red=(val>>16)&0xff;␊ |
444 | ␉␉␉␉␉green=(val>>8)&0xff;␊ |
445 | ␉␉␉␉␉blue=(val)&0xff;␊ |
446 | ␉␉␉␉␉break;␊ |
447 | ␉␉␉␉}␉␉␉␉␊ |
448 | ␉␉␉}␊ |
449 | ␉␉␉char *ptr=(char *)output+x*(op/8)+y*or;␊ |
450 | ␉␉␉switch (op)␊ |
451 | ␉␉␉{␊ |
452 | ␉␉␉␉case 16:␊ |
453 | ␉␉␉␉␉*((uint16_t *)ptr) = ((red & 0xF8) << 7) | ␊ |
454 | ␉␉␉␉␉((green & 0xF8) << 2) |␊ |
455 | ␉␉␉␉␉((blue & 0xF8) >> 3);␊ |
456 | ␉␉␉␉␉break;␊ |
457 | ␉␉␉␉case 32 :␊ |
458 | ␉␉␉␉␉*((uint32_t *)ptr) = (red << 16) | (green << 8) | blue;␊ |
459 | ␉␉␉␉␉break;␊ |
460 | ␉␉␉}␊ |
461 | ␉␉}␊ |
462 | }␊ |
463 | ␊ |
464 | DECLARE_IOHIBERNATEPROGRESSALPHA␊ |
465 | ␊ |
466 | void drawPreview(void *src, uint8_t * saveunder)␊ |
467 | {␊ |
468 | ␉uint8_t * screen;␊ |
469 | ␉uint32_t rowBytes, pixelShift;␊ |
470 | ␉uint32_t x, y;␊ |
471 | ␉int32_t blob;␊ |
472 | ␉uint32_t alpha, in, color, result;␊ |
473 | ␉uint8_t * out;␊ |
474 | ␉void *uncomp;␊ |
475 | ␉int origwidth, origheight, origbpx;␊ |
476 | ␉uint32_t saveindex[kIOHibernateProgressCount] = { 0 };␊ |
477 | ␉␊ |
478 | ␉if (src && (uncomp=DecompressData(src, &origwidth, &origheight, &origbpx)))␊ |
479 | ␉{␊ |
480 | ␉␉if (!setVESAGraphicsMode(origwidth, origheight, origbpx, 0))␊ |
481 | ␉␉␉if (initGraphicsMode () != errSuccess)␊ |
482 | ␉␉␉␉return;␊ |
483 | ␉␉screen = (uint8_t *) VIDEO (baseAddr);␊ |
484 | ␉␉rowBytes = VIDEO (rowBytes);␊ |
485 | ␉␉loadImageScale (uncomp, origwidth, origheight, origbpx, screen, VIDEO(width), VIDEO(height), VIDEO(depth), VIDEO (rowBytes));␊ |
486 | ␉}␊ |
487 | ␉else␊ |
488 | ␉{␊ |
489 | ␉␉if (initGraphicsMode () != errSuccess)␊ |
490 | ␉␉␉return;␊ |
491 | ␉␉screen = (uint8_t *) VIDEO (baseAddr);␊ |
492 | ␉␉rowBytes = VIDEO (rowBytes);␊ |
493 | ␉␉// Set the screen to 75% grey.␊ |
494 | drawColorRectangle(0, 0, VIDEO(width), VIDEO(height), 0x01 /* color index */);␊ |
495 | ␉}␊ |
496 | ␉␊ |
497 | ␉␊ |
498 | ␉pixelShift = VIDEO (depth) >> 4;␊ |
499 | ␉if (pixelShift < 1) return;␊ |
500 | ␉␊ |
501 | ␉screen += ((VIDEO (width) ␊ |
502 | ␉␉␉␉- kIOHibernateProgressCount * (kIOHibernateProgressWidth + kIOHibernateProgressSpacing)) << (pixelShift - 1))␊ |
503 | ␉+ (VIDEO (height) - kIOHibernateProgressOriginY - kIOHibernateProgressHeight) * rowBytes;␊ |
504 | ␉␊ |
505 | ␉for (y = 0; y < kIOHibernateProgressHeight; y++)␊ |
506 | ␉{␊ |
507 | ␉␉out = screen + y * rowBytes;␊ |
508 | ␉␉for (blob = 0; blob < kIOHibernateProgressCount; blob++)␊ |
509 | ␉␉{␊ |
510 | ␉␉␉color = blob ? kIOHibernateProgressDarkGray : kIOHibernateProgressMidGray;␊ |
511 | ␉␉␉for (x = 0; x < kIOHibernateProgressWidth; x++)␊ |
512 | ␉␉␉{␊ |
513 | ␉␉␉␉alpha = gIOHibernateProgressAlpha[y][x];␊ |
514 | ␉␉␉␉result = color;␊ |
515 | ␉␉␉␉if (alpha)␊ |
516 | ␉␉␉␉{␊ |
517 | ␉␉␉␉␉if (0xff != alpha)␊ |
518 | ␉␉␉␉␉{␊ |
519 | ␉␉␉␉␉␉if (1 == pixelShift)␊ |
520 | ␉␉␉␉␉␉{␊ |
521 | ␉␉␉␉␉␉␉in = *((uint16_t *)out) & 0x1f;␉// 16␊ |
522 | ␉␉␉␉␉␉␉in = (in << 3) | (in >> 2);␊ |
523 | ␉␉␉␉␉␉}␊ |
524 | ␉␉␉␉␉␉else␊ |
525 | ␉␉␉␉␉␉␉in = *((uint32_t *)out) & 0xff;␉// 32␊ |
526 | ␉␉␉␉␉␉saveunder[blob * kIOHibernateProgressSaveUnderSize + saveindex[blob]++] = in;␊ |
527 | ␉␉␉␉␉␉result = ((255 - alpha) * in + alpha * result + 0xff) >> 8;␊ |
528 | ␉␉␉␉␉}␊ |
529 | ␉␉␉␉␉if (1 == pixelShift)␊ |
530 | ␉␉␉␉␉{␊ |
531 | ␉␉␉␉␉␉result >>= 3;␊ |
532 | ␉␉␉␉␉␉*((uint16_t *)out) = (result << 10) | (result << 5) | result;␉// 16␊ |
533 | ␉␉␉␉␉}␊ |
534 | ␉␉␉␉␉else␊ |
535 | ␉␉␉␉␉␉*((uint32_t *)out) = (result << 16) | (result << 8) | result;␉// 32␊ |
536 | ␉␉␉␉}␊ |
537 | ␉␉␉␉out += (1 << pixelShift);␊ |
538 | ␉␉␉}␊ |
539 | ␉␉␉out += (kIOHibernateProgressSpacing << pixelShift);␊ |
540 | ␉␉}␊ |
541 | ␉}␊ |
542 | }␊ |
543 | void updateProgressBar(uint8_t * saveunder, int32_t firstBlob, int32_t select)␊ |
544 | {␊ |
545 | ␉uint8_t * screen;␊ |
546 | ␉uint32_t rowBytes, pixelShift;␊ |
547 | ␉uint32_t x, y;␊ |
548 | ␉int32_t blob, lastBlob;␊ |
549 | ␉uint32_t alpha, in, color, result;␊ |
550 | ␉uint8_t * out;␊ |
551 | ␉uint32_t saveindex[kIOHibernateProgressCount] = { 0 };␊ |
552 | ␉␊ |
553 | ␉pixelShift = VIDEO(depth) >> 4;␊ |
554 | ␉if (pixelShift < 1) return;␊ |
555 | ␉screen = (uint8_t *) VIDEO (baseAddr);␊ |
556 | ␉rowBytes = VIDEO (rowBytes);␊ |
557 | ␉␊ |
558 | ␉screen += ((VIDEO (width) ␊ |
559 | ␉␉␉␉- kIOHibernateProgressCount * (kIOHibernateProgressWidth + kIOHibernateProgressSpacing)) << (pixelShift - 1))␊ |
560 | ␉+ (VIDEO (height) - kIOHibernateProgressOriginY - kIOHibernateProgressHeight) * rowBytes;␊ |
561 | ␉␊ |
562 | ␉lastBlob = (select < kIOHibernateProgressCount) ? select : (kIOHibernateProgressCount - 1);␊ |
563 | ␉␊ |
564 | ␉screen += (firstBlob * (kIOHibernateProgressWidth + kIOHibernateProgressSpacing)) << pixelShift;␊ |
565 | ␉␊ |
566 | ␉for (y = 0; y < kIOHibernateProgressHeight; y++)␊ |
567 | ␉{␊ |
568 | ␉␉out = screen + y * rowBytes;␊ |
569 | ␉␉for (blob = firstBlob; blob <= lastBlob; blob++)␊ |
570 | ␉␉{␊ |
571 | ␉␉␉color = (blob < select) ? kIOHibernateProgressLightGray : kIOHibernateProgressMidGray;␊ |
572 | ␉␉␉for (x = 0; x < kIOHibernateProgressWidth; x++)␊ |
573 | ␉␉␉{␊ |
574 | ␉␉␉␉alpha = gIOHibernateProgressAlpha[y][x];␊ |
575 | ␉␉␉␉result = color;␊ |
576 | ␉␉␉␉if (alpha)␊ |
577 | ␉␉␉␉{␊ |
578 | ␉␉␉␉␉if (0xff != alpha)␊ |
579 | ␉␉␉␉␉{␊ |
580 | ␉␉␉␉␉␉in = saveunder[blob * kIOHibernateProgressSaveUnderSize + saveindex[blob]++];␊ |
581 | ␉␉␉␉␉␉result = ((255 - alpha) * in + alpha * result + 0xff) / 255;␊ |
582 | ␉␉␉␉␉}␊ |
583 | ␉␉␉␉␉if (1 == pixelShift)␊ |
584 | ␉␉␉␉␉{␊ |
585 | ␉␉␉␉␉␉result >>= 3;␊ |
586 | ␉␉␉␉␉␉*((uint16_t *)out) = (result << 10) | (result << 5) | result;␉// 16␊ |
587 | ␉␉␉␉␉}␊ |
588 | ␉␉␉␉␉else␊ |
589 | ␉␉␉␉␉␉*((uint32_t *)out) = (result << 16) | (result << 8) | result;␉// 32␊ |
590 | ␉␉␉␉}␊ |
591 | ␉␉␉␉out += (1 << pixelShift);␊ |
592 | ␉␉␉}␊ |
593 | ␉␉␉out += (kIOHibernateProgressSpacing << pixelShift);␊ |
594 | ␉␉}␊ |
595 | ␉}␊ |
596 | }␊ |
597 | #endif␊ |
598 | ␊ |
599 | ␊ |
600 | //==========================================================================␊ |
601 | // setVESATextMode␊ |
602 | ␊ |
603 | static int␊ |
604 | setVESATextMode( unsigned short cols,␊ |
605 | ␉␉␉␉unsigned short rows,␊ |
606 | ␉␉␉␉unsigned char bitsPerPixel )␊ |
607 | {␊ |
608 | VBEModeInfoBlock minfo;␊ |
609 | unsigned short mode = modeEndOfList;␊ |
610 | ␉␊ |
611 | if ( (cols != 80) || (rows != 25) ) // not 80x25 mode␊ |
612 | {␊ |
613 | mode = getVESAModeWithProperties( cols, rows, bitsPerPixel,␊ |
614 | ␉␉␉␉␉␉␉␉␉␉ maColorModeBit |␊ |
615 | ␉␉␉␉␉␉␉␉␉␉ maModeIsSupportedBit,␊ |
616 | ␉␉␉␉␉␉␉␉␉␉ maGraphicsModeBit,␊ |
617 | ␉␉␉␉␉␉␉␉␉␉ &minfo, NULL );␊ |
618 | }␊ |
619 | ␉␊ |
620 | if ( ( mode == modeEndOfList ) || ( setVBEMode(mode, NULL) != errSuccess ) )␊ |
621 | {␊ |
622 | video_mode( 2 ); // VGA BIOS, 80x25 text mode.␊ |
623 | minfo.XResolution = 80;␊ |
624 | minfo.YResolution = 25;␊ |
625 | }␊ |
626 | ␉␊ |
627 | // Update KernBootStruct using info provided by the selected␊ |
628 | // VESA mode.␊ |
629 | ␉␊ |
630 | bootArgs->Video.v_display = VGA_TEXT_MODE;␊ |
631 | bootArgs->Video.v_baseAddr = 0xb8000;␊ |
632 | bootArgs->Video.v_width = minfo.XResolution;␊ |
633 | bootArgs->Video.v_height = minfo.YResolution;␊ |
634 | bootArgs->Video.v_depth = 8;␊ |
635 | bootArgs->Video.v_rowBytes = 0x8000;␊ |
636 | ␉␊ |
637 | return errSuccess; // always return success␊ |
638 | }␊ |
639 | ␊ |
640 | //==========================================================================␊ |
641 | // getNumberArrayFromProperty␊ |
642 | ␊ |
643 | int␊ |
644 | getNumberArrayFromProperty( const char * propKey,␊ |
645 | ␉␉␉␉␉␉ unsigned long numbers[],␊ |
646 | ␉␉␉␉␉␉ unsigned long maxArrayCount )␊ |
647 | {␊ |
648 | char * propStr;␊ |
649 | unsigned long count = 0;␊ |
650 | ␉␊ |
651 | propStr = newStringForKey( (char *) propKey , &bootInfo->bootConfig );␊ |
652 | if ( propStr )␊ |
653 | {␊ |
654 | char * delimiter = propStr;␊ |
655 | char * p = propStr;␊ |
656 | ␉␉␊ |
657 | while ( count < maxArrayCount && *p != '\0' )␊ |
658 | {␊ |
659 | unsigned long val = strtoul( p, &delimiter, 10 );␊ |
660 | if ( p != delimiter )␊ |
661 | {␊ |
662 | numbers[count++] = val;␊ |
663 | p = delimiter;␊ |
664 | }␊ |
665 | while ( ( *p != '\0' ) && !isdigit(*p) )␊ |
666 | p++;␊ |
667 | }␊ |
668 | ␉␉␊ |
669 | free( propStr );␊ |
670 | }␊ |
671 | ␉␊ |
672 | return count;␊ |
673 | }␊ |
674 | ␊ |
675 | int initGraphicsMode ()␊ |
676 | {␊ |
677 | ␉unsigned long params[4];␊ |
678 | ␉int count;␊ |
679 | ␉␊ |
680 | ␉params[3] = 0;␊ |
681 | ␉count = getNumberArrayFromProperty( kGraphicsModeKey, params, 4 );␊ |
682 | ␉␊ |
683 | ␉// Try to find a resolution if "Graphics Mode" setting is not available.␊ |
684 | ␉if ( count < 3 )␊ |
685 | ␉{␊ |
686 | ␉␉params[0] = DEFAULT_SCREEN_WIDTH;␊ |
687 | ␉␉params[1] = DEFAULT_SCREEN_HEIGHT;␊ |
688 | ␉␉params[2] = 32;␊ |
689 | ␉}␊ |
690 | ␉␊ |
691 | ␉// Map from pixel format to bits per pixel.␊ |
692 | ␉␊ |
693 | ␉if ( params[2] == 256 ) params[2] = 8;␊ |
694 | ␉if ( params[2] == 555 ) params[2] = 16;␊ |
695 | ␉if ( params[2] == 888 ) params[2] = 32;␊ |
696 | ␉␊ |
697 | ␉return setVESAGraphicsMode( params[0], params[1], params[2], params[3] );␉␊ |
698 | }␊ |
699 | ␊ |
700 | //==========================================================================␊ |
701 | // setVideoMode␊ |
702 | //␊ |
703 | // Set the video mode to VGA_TEXT_MODE or GRAPHICS_MODE.␊ |
704 | ␊ |
705 | void␊ |
706 | setVideoMode( int mode, int drawgraphics)␊ |
707 | {␊ |
708 | unsigned long params[4];␊ |
709 | int count;␊ |
710 | int err = errSuccess;␊ |
711 | ␉␊ |
712 | if ( mode == GRAPHICS_MODE )␊ |
713 | {␊ |
714 | ␉␉if ( (err=initGraphicsMode ()) == errSuccess ) {␊ |
715 | ␉␉␉if (gVerboseMode) {␊ |
716 | ␉␉␉␉// Tell the kernel to use text mode on a linear frame buffer display␊ |
717 | ␉␉␉␉bootArgs->Video.v_display = FB_TEXT_MODE;␊ |
718 | ␉␉␉} else {␊ |
719 | ␉␉␉␉bootArgs->Video.v_display = GRAPHICS_MODE;␊ |
720 | ␉␉␉}␊ |
721 | ␉␉}␊ |
722 | }␊ |
723 | ␉␊ |
724 | if ( (mode == VGA_TEXT_MODE) || (err != errSuccess) )␊ |
725 | {␊ |
726 | count = getNumberArrayFromProperty( kTextModeKey, params, 2 );␊ |
727 | if ( count < 2 )␊ |
728 | {␊ |
729 | params[0] = 80; // Default text mode is 80x25.␊ |
730 | params[1] = 25;␊ |
731 | }␊ |
732 | ␉␉␊ |
733 | ␉␉setVESATextMode( params[0], params[1], 4 );␊ |
734 | bootArgs->Video.v_display = VGA_TEXT_MODE;␊ |
735 | }␊ |
736 | ␉␊ |
737 | currentIndicator = 0;␊ |
738 | }␊ |
739 | ␊ |
740 | //==========================================================================␊ |
741 | // Return the current video mode, VGA_TEXT_MODE or GRAPHICS_MODE.␊ |
742 | ␊ |
743 | inline int getVideoMode(void)␊ |
744 | {␊ |
745 | return bootArgs->Video.v_display;␊ |
746 | }␊ |
747 | ␊ |
748 | //==========================================================================␊ |
749 | // Display and clear the activity indicator.␊ |
750 | ␊ |
751 | static char indicator[] = {'-', '\\', '|', '/', '-', '\\', '|', '/', '\0'};␊ |
752 | ␊ |
753 | // To prevent a ridiculously fast-spinning indicator,␊ |
754 | // ensure a minimum of 1/9 sec between animation frames.␊ |
755 | #define MIN_TICKS 2␊ |
756 | ␊ |
757 | void␊ |
758 | spinActivityIndicator(int sectors)␊ |
759 | {␊ |
760 | static unsigned long lastTickTime = 0, currentTickTime;␊ |
761 | #ifndef OPTION_ROM␊ |
762 | ␉if (previewTotalSectors && previewSaveunder)␊ |
763 | ␉{␊ |
764 | ␉␉int blob, lastBlob;␊ |
765 | ␉␉␊ |
766 | ␉␉lastBlob = (previewLoadedSectors * kIOHibernateProgressCount) / previewTotalSectors;␊ |
767 | ␉␉previewLoadedSectors+=sectors;␊ |
768 | ␉␉blob = (previewLoadedSectors * kIOHibernateProgressCount) / previewTotalSectors;␊ |
769 | ␉␉␊ |
770 | ␉␉if (blob!=lastBlob)␊ |
771 | ␉␉␉updateProgressBar (previewSaveunder, lastBlob, blob);␊ |
772 | ␉␉return;␊ |
773 | ␉}␊ |
774 | #endif␊ |
775 | ␉currentTickTime = time18(); // late binding␊ |
776 | ␉if (currentTickTime < lastTickTime + MIN_TICKS)␊ |
777 | ␉{␊ |
778 | ␉␉return;␊ |
779 | ␉}␊ |
780 | ␉else␊ |
781 | ␉{␊ |
782 | ␉␉lastTickTime = currentTickTime;␊ |
783 | ␉}␊ |
784 | ␉␊ |
785 | ␉if (getVideoMode() == VGA_TEXT_MODE)␊ |
786 | ␉{␊ |
787 | ␉␉if (currentIndicator >= sizeof(indicator))␊ |
788 | ␉␉{␊ |
789 | ␉␉␉currentIndicator = 0;␊ |
790 | ␉␉}␊ |
791 | ␉␉putc(indicator[currentIndicator++]);␊ |
792 | ␉␉putc('\b');␊ |
793 | ␉}␊ |
794 | }␊ |
795 | ␊ |
796 | void␊ |
797 | clearActivityIndicator( void )␊ |
798 | {␊ |
799 | if ( getVideoMode() == VGA_TEXT_MODE )␊ |
800 | {␊ |
801 | ␉␉putc(' ');␊ |
802 | ␉␉putc('\b');␊ |
803 | }␊ |
804 | }␊ |
805 | ␊ |
806 |