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;␊ |
414 | ␉unsigned short vesaVersion;␊ |
415 | ␉int err = errFuncNotSupported;␊ |
416 | ␊ |
417 | ␉do {␊ |
418 | ␉␉mode = getVESAModeWithProperties( width, height, bitsPerPixel,␊ |
419 | maColorModeBit |␊ |
420 | maModeIsSupportedBit |␊ |
421 | maGraphicsModeBit |␊ |
422 | maLinearFrameBufferAvailBit,␊ |
423 | 0,␊ |
424 | &minfo, &vesaVersion );␊ |
425 | ␉␉if ( mode == modeEndOfList )␊ |
426 | ␉␉{␊ |
427 | ␉␉␉break;␊ |
428 | ␉␉}␊ |
429 | ␊ |
430 | //␊ |
431 | // FIXME : generateCRTCTiming() causes crash.␊ |
432 | //␊ |
433 | ␊ |
434 | // if ( (vesaVersion >> 8) >= 3 && refreshRate >= 60 &&␊ |
435 | // (gBootMode & kBootModeSafe) == 0 )␊ |
436 | // {␊ |
437 | // VBECRTCInfoBlock timing;␊ |
438 | // ␊ |
439 | // // Generate CRTC timing for given refresh rate.␊ |
440 | // ␊ |
441 | // generateCRTCTiming( minfo.XResolution, minfo.YResolution,␊ |
442 | // refreshRate, kCRTCParamRefreshRate,␊ |
443 | // &timing );␊ |
444 | // ␊ |
445 | // // Find the actual pixel clock supported by the hardware.␊ |
446 | // ␊ |
447 | // getVBEPixelClock( mode, &timing.PixelClock );␊ |
448 | // ␊ |
449 | // // Re-compute CRTC timing based on actual pixel clock.␊ |
450 | // ␊ |
451 | // generateCRTCTiming( minfo.XResolution, minfo.YResolution,␊ |
452 | // timing.PixelClock, kCRTCParamPixelClock,␊ |
453 | // &timing );␊ |
454 | // ␊ |
455 | // // Set the video mode and use specified CRTC timing.␊ |
456 | // ␊ |
457 | // err = setVBEMode( mode | kLinearFrameBufferBit |␊ |
458 | // kCustomRefreshRateBit, &timing );␊ |
459 | // }␊ |
460 | // else␊ |
461 | // {␊ |
462 | // // Set the mode with default refresh rate.␊ |
463 | // ␊ |
464 | // err = setVBEMode( mode | kLinearFrameBufferBit, NULL );␊ |
465 | // }␊ |
466 | ␊ |
467 | // Set the mode with default refresh rate.␊ |
468 | ␊ |
469 | ␉␉err = setVBEMode(mode | kLinearFrameBufferBit, NULL);␊ |
470 | ␊ |
471 | ␉␉if (err != errSuccess)␊ |
472 | ␉␉{␊ |
473 | ␉␉␉break;␊ |
474 | ␉␉}␊ |
475 | ␊ |
476 | // Set 8-bit color palette.␊ |
477 | ␊ |
478 | if ( minfo.BitsPerPixel == 8 )␊ |
479 | {␊ |
480 | VBEPalette palette;␊ |
481 | setupPalette( &palette, appleClut8 );␊ |
482 | if ((err = setVBEPalette(palette)) != errSuccess)␊ |
483 | {␊ |
484 | break;␊ |
485 | }␊ |
486 | }␊ |
487 | ␊ |
488 | ␉␉// Is this required for buggy Video BIOS implementations?␊ |
489 | ␉␉// On which adapter?␊ |
490 | ␊ |
491 | ␉␉if ( minfo.BytesPerScanline == 0 )␊ |
492 | ␉␉{␊ |
493 | ␉ minfo.BytesPerScanline = ( minfo.XResolution * minfo.BitsPerPixel ) >> 3;␊ |
494 | ␉␉}␊ |
495 | ␊ |
496 | ␉␉// Update KernBootStruct using info provided by the selected␊ |
497 | ␉␉// VESA mode.␊ |
498 | ␊ |
499 | ␉␉bootArgs->Video.v_display␉= GRAPHICS_MODE;␊ |
500 | ␉␉bootArgs->Video.v_width␉␉= minfo.XResolution;␉␉/* 1920 or 1600 */␊ |
501 | ␉␉bootArgs->Video.v_height␉= minfo.YResolution;␉␉/* 1200 or 900 */␊ |
502 | ␉␉bootArgs->Video.v_depth␉␉= minfo.BitsPerPixel;␉␉/* 32 */␊ |
503 | ␉␉bootArgs->Video.v_rowBytes␉= minfo.BytesPerScanline;␉/* 7680 or 6400 */␊ |
504 | ␉␉bootArgs->Video.v_baseAddr␉= VBEMakeUInt32(minfo.PhysBasePtr);␊ |
505 | ␊ |
506 | ␉} while ( 0 );␊ |
507 | ␊ |
508 | ␉return err;␊ |
509 | }␊ |
510 | ␊ |
511 | //==============================================================================␊ |
512 | ␊ |
513 | int convertImage( unsigned short width, unsigned short height, const unsigned char *imageData, unsigned char **newImageData )␊ |
514 | {␊ |
515 | int cnt;␊ |
516 | unsigned char *img = 0;␊ |
517 | unsigned short *img16;␊ |
518 | unsigned long *img32;␊ |
519 | ␊ |
520 | switch ( VIDEO(depth) ) {␊ |
521 | case 16 :␊ |
522 | img16 = malloc(width * height * 2);␊ |
523 | if ( !img16 ) break;␊ |
524 | for (cnt = 0; cnt < (width * height); cnt++)␊ |
525 | img16[cnt] = lookUpCLUTIndex(imageData[cnt], 16);␊ |
526 | img = (unsigned char *)img16;␊ |
527 | break;␊ |
528 | ␊ |
529 | case 32 :␊ |
530 | img32 = malloc(width * height * 4);␊ |
531 | if ( !img32 ) break;␊ |
532 | for (cnt = 0; cnt < (width * height); cnt++)␊ |
533 | img32[cnt] = lookUpCLUTIndex(imageData[cnt], 32);␊ |
534 | img = (unsigned char *)img32;␊ |
535 | break;␊ |
536 | ␊ |
537 | default :␊ |
538 | img = malloc(width * height);␊ |
539 | bcopy(imageData, img, width * height);␊ |
540 | break;␊ |
541 | }␊ |
542 | *newImageData = img;␊ |
543 | return 0;␊ |
544 | }␊ |
545 | ␊ |
546 | //==============================================================================␊ |
547 | ␊ |
548 | int loadPngImage(const char *filename, uint16_t *width, uint16_t *height, uint8_t **imageData)␊ |
549 | {␊ |
550 | uint8_t *pngData = NULL;␊ |
551 | int pngFile = 0, pngSize;␊ |
552 | PNG_info_t *info;␊ |
553 | int error = 0;␊ |
554 | ␊ |
555 | pngFile = open_bvdev("bt(0,0)", filename, 0);␊ |
556 | if (pngFile == -1) {␊ |
557 | error = -1;␊ |
558 | goto failed;␊ |
559 | }␊ |
560 | pngSize = file_size(pngFile);␊ |
561 | if (!pngSize) {␊ |
562 | error = -1;␊ |
563 | goto failed;␊ |
564 | }␊ |
565 | pngData = malloc(pngSize);␊ |
566 | if (read(pngFile, (char *) pngData, pngSize) != pngSize) {␊ |
567 | error = -1;␊ |
568 | goto failed;␊ |
569 | }␊ |
570 | ␊ |
571 | PNG_error = -1;␊ |
572 | info = PNG_decode(pngData, pngSize);␊ |
573 | if (PNG_error != 0) {␊ |
574 | error = PNG_error;␊ |
575 | goto failed;␊ |
576 | } else if ((info->width > 0xffff) || (info->height > 0xffff)) {␊ |
577 | error = -1;␊ |
578 | goto failed;␊ |
579 | } else if ((info->width * info->height * 4) != info->image->size) {␊ |
580 | error = -1;␊ |
581 | goto failed;␊ |
582 | }␊ |
583 | ␉uint8_t *result = malloc(info->width*4*info->height);␊ |
584 | *width = info->width;␊ |
585 | *height = info->height;␊ |
586 | ␉memcpy(result, info->image->data, info->width*4*info->height);␊ |
587 | ␉*imageData = result;␊ |
588 | ␊ |
589 | failed:␊ |
590 | ␉png_alloc_free_all();␊ |
591 | if (pngData)␊ |
592 | free(pngData);␊ |
593 | if (pngFile != -1)␊ |
594 | close(pngFile);␊ |
595 | ␊ |
596 | return error;␊ |
597 | }␊ |
598 | ␊ |
599 | //==============================================================================␊ |
600 | ␊ |
601 | int loadEmbeddedPngImage(uint8_t *pngData, int pngSize, uint16_t *width, uint16_t *height, uint8_t **imageData)␊ |
602 | {␊ |
603 | PNG_info_t *info;␊ |
604 | int error = 0;␊ |
605 | ␉␊ |
606 | PNG_error = -1;␊ |
607 | info = PNG_decode(pngData, pngSize);␊ |
608 | ␉if (PNG_error != 0) {␊ |
609 | error = PNG_error;␊ |
610 | goto failed;␊ |
611 | } else if ((info->width > 0xffff) || (info->height > 0xffff)) {␊ |
612 | error = -1;␊ |
613 | goto failed;␊ |
614 | } else if ((info->width * info->height * 4) != info->image->size) {␊ |
615 | error = -1;␊ |
616 | goto failed;␊ |
617 | }␊ |
618 | ␉uint8_t *result = malloc(info->width*4*info->height);␊ |
619 | ␉*width = info->width;␊ |
620 | *height = info->height;␊ |
621 | ␉memcpy(result, info->image->data, info->width*4*info->height);␊ |
622 | ␉*imageData = result;␊ |
623 | ␊ |
624 | failed:␊ |
625 | ␉png_alloc_free_all();␊ |
626 | ␊ |
627 | return error;␊ |
628 | }␊ |
629 | ␊ |
630 | //==============================================================================␊ |
631 | ␊ |
632 | void blendImage(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t *data)␊ |
633 | {␊ |
634 | uint16_t drawWidth;␊ |
635 | uint8_t *vram = (uint8_t *) VIDEO(baseAddr) + VIDEO(rowBytes) * y + 4 * x;␊ |
636 | ␊ |
637 | drawWidth = MIN(width, VIDEO(width) - x);␊ |
638 | height = MIN(height, VIDEO(height) - y);␊ |
639 | while (height--) {␊ |
640 | ␉␉switch (VIDEO (depth))␊ |
641 | ␉␉{␊ |
642 | ␉␉␉case 32: /* Optimized version*/␊ |
643 | ␉␉␉{␊ |
644 | ␉␉␉␉uint32_t s; uint32_t* d; // Source (img) and destination (bkgd) pixels␊ |
645 | ␉␉␉␉uint32_t a; // Alpha␊ |
646 | ␉␉␉␉uint32_t dstrb, dstg, srcrb, srcg, drb, dg, rb, g, tempB; // Intermediate variables␊ |
647 | ␉␉␉␉uint16_t pos;␊ |
648 | ␊ |
649 | ␉␉␉␉for (pos = 0; pos < drawWidth * 4; pos += 4) {␊ |
650 | ␉␉␉␉␉// Fast pseudo-vector alpha blending, adapted from: http://www.stereopsis.com/doubleblend.html␊ |
651 | ␉␉␉␉␉s = *((uint32_t*) (data + pos));␊ |
652 | ␉␉␉␉␉d = (uint32_t*) (vram + pos);␊ |
653 | ␊ |
654 | ␉␉␉␉␉// Flip B and R in source␊ |
655 | ␉␉␉␉␉// TODO: use XCHG and inline assembly to do this in a faster, saner way␊ |
656 | ␉␉␉␉␉tempB = (s & 0xFF0000); // save B␊ |
657 | ␉␉␉␉␉s = (s & 0xFF00FFFF) | ((s & 0xFF) << 16); // put R in B␊ |
658 | ␉␉␉␉␉s = (s & 0xFFFFFF00) | (tempB >> 16); // put B in R␊ |
659 | ␊ |
660 | ␉␉␉␉␉a = (s >> 24) + 1;␊ |
661 | ␊ |
662 | ␉␉␉␉␉dstrb = *d & 0xFF00FF; dstg = *d & 0xFF00;␊ |
663 | ␉␉␉␉␉srcrb = s & 0xFF00FF; srcg = s & 0xFF00;␊ |
664 | ␊ |
665 | ␉␉␉␉␉drb = srcrb - dstrb;␊ |
666 | ␉␉␉␉␉dg = srcg - dstg;␊ |
667 | ␉␉␉␉␉drb *= a; dg *= a;␊ |
668 | ␉␉␉␉␉drb >>= 8; dg >>= 8;␊ |
669 | ␊ |
670 | ␉␉␉␉␉rb = (drb + dstrb) & 0xFF00FF;␊ |
671 | ␉␉␉␉␉g = (dg + dstg) & 0xFF00;␊ |
672 | ␊ |
673 | ␉␉␉␉␉*d = rb | g;␊ |
674 | ␉␉␉␉}␊ |
675 | ␉␉␉}␊ |
676 | ␉␉␉break;␊ |
677 | ␊ |
678 | ␉␉␉default: /*Universal version*/␊ |
679 | ␉␉␉{␊ |
680 | ␉␉␉␉uint32_t s; ␊ |
681 | ␉␉␉␉uint32_t a; // Alpha␊ |
682 | ␉␉␉␉uint32_t dr, dg, db, sr, sg, sb; // Intermediate variables␊ |
683 | ␉␉␉␉uint16_t pos;␊ |
684 | ␉␉␉␉int bpp = (VIDEO (depth) + 7)/8;␊ |
685 | ␊ |
686 | ␉␉␉␉for (pos = 0; pos < drawWidth; pos ++) {␊ |
687 | ␉␉␉␉␉// Fast pseudo-vector alpha blending, adapted from: http://www.stereopsis.com/doubleblend.html␊ |
688 | ␉␉␉␉␉s = *((uint32_t*) (data + 4*pos));␊ |
689 | ␉␉␉␉␉␊ |
690 | ␉␉␉␉␉sb = (s & 0xFF0000) >> 16;␊ |
691 | ␉␉␉␉␉sg = (s & 0xFF00) >> 8;␊ |
692 | ␉␉␉␉␉sr = (s & 0xFF);␊ |
693 | ␉␉␉␉␉␊ |
694 | ␉␉␉␉␉a = (s >> 24) + 1;␊ |
695 | ␊ |
696 | ␉␉␉␉␉switch (VIDEO (depth))␊ |
697 | ␉␉␉␉␉{␊ |
698 | ␉␉␉␉␉␉case 24:␊ |
699 | ␉␉␉␉␉␉␉db = ((*(uint32_t *)(vram + bpp*pos))&0xff);␊ |
700 | ␉␉␉␉␉␉␉dg = ((*(uint32_t *)(vram + bpp*pos))&0xff00)>>8;␊ |
701 | ␉␉␉␉␉␉␉dr = ((*(uint32_t *)(vram + bpp*pos))&0xff0000)>>16;␊ |
702 | ␉␉␉␉␉␉␉break;␊ |
703 | ␉␉␉␉␉␉case 16://16-bit seems to be 15-bit␊ |
704 | /*␉␉␉␉␉␉␉db = ((*(uint16_t *)(vram + bpp*pos))&0x1f)<<3;␊ |
705 | ␉␉␉␉␉␉␉dg = ((*(uint16_t *)(vram + bpp*pos))&0x07e0)>>3;␊ |
706 | ␉␉␉␉␉␉␉dr = ((*(uint16_t *)(vram + bpp*pos))&0xf800)>>8;␊ |
707 | ␉␉␉␉␉␉␉break;␉␉␉␉␉␉␉*/␊ |
708 | ␉␉␉␉␉␉case 15:␊ |
709 | ␉␉␉␉␉␉␉db = ((*(uint16_t *)(vram + bpp*pos))&0x1f)<<3;␊ |
710 | ␉␉␉␉␉␉␉dg = ((*(uint16_t *)(vram + bpp*pos))&0x03e0)>>2;␊ |
711 | ␉␉␉␉␉␉␉dr = ((*(uint16_t *)(vram + bpp*pos))&0x7c00)>>7;␊ |
712 | ␉␉␉␉␉␉␉break;␊ |
713 | ␉␉␉␉␉␉default:␊ |
714 | ␉␉␉␉␉␉␉return;␊ |
715 | ␉␉␉␉␉}␊ |
716 | ␊ |
717 | ␉␉␉␉␉dr = (((sr - dr) * a) >> 8) + dr;␊ |
718 | ␉␉␉␉␉dg = (((sg - dg) * a) >> 8) + dg;␊ |
719 | ␉␉␉␉␉db = (((sb - db) * a) >> 8) + db;␊ |
720 | ␉␉␉␉␉switch (VIDEO (depth))␊ |
721 | ␉␉␉␉␉{␊ |
722 | ␉␉␉␉␉␉case 24:␊ |
723 | ␉␉␉␉␉␉␉*(uint32_t *)(vram + bpp*pos) = (*(uint32_t *)(vram + bpp*pos) &0xff000000)␊ |
724 | ␉␉␉␉␉␉␉| (db&0xff) | ((dg&0xff)<<8) | ((dr&0xff)<<16);␊ |
725 | ␉␉␉␉␉␉␉break;␊ |
726 | ␉␉␉␉␉␉case 16:␊ |
727 | //␉␉␉␉␉␉␉*(uint16_t *)(vram + bpp*pos) = ((db&0xf8)>>3) | ((dg&0xfc)<<3) | ((dr&0xf8)<<8);␊ |
728 | //␉␉␉␉␉␉␉break;␉␉␉␉␉␉␉␊ |
729 | ␉␉␉␉␉␉case 15:␊ |
730 | ␉␉␉␉␉␉␉*(uint16_t *)(vram + bpp*pos) = ((db&0xf8)>>3) | ((dg&0xf8)<<2) | ((dr&0xf8)<<7);␊ |
731 | ␉␉␉␉␉␉␉break;␉␉␉␉␉␉␉␉␉␉␉␉␉␉␊ |
732 | ␉␉␉␉␉}␊ |
733 | ␊ |
734 | ␉␉␉␉}␊ |
735 | ␉␉␉}␊ |
736 | ␉␉␉break;␊ |
737 | }␊ |
738 | vram += VIDEO(rowBytes);␊ |
739 | data += width * 4;␊ |
740 | }␊ |
741 | }␊ |
742 | ␊ |
743 | //==============================================================================␊ |
744 | ␊ |
745 | void drawCheckerBoard()␊ |
746 | {␊ |
747 | uint32_t *vram = (uint32_t *) VIDEO(baseAddr);␊ |
748 | uint16_t x, y;␊ |
749 | uint8_t color;␊ |
750 | ␊ |
751 | for (y = 0; y < VIDEO(height); y++, vram += VIDEO(width)) {␊ |
752 | for (x = 0; x < VIDEO(width); x++) {␊ |
753 | color = 204 + 51 * (((x / 8) % 2) == ((y / 8) % 2));␊ |
754 | vram[x] = (color << 16) | (color << 8) | color;␊ |
755 | }␊ |
756 | }␊ |
757 | }␊ |
758 | ␊ |
759 | //==========================================================================␊ |
760 | // LookUpCLUTIndex␊ |
761 | ␊ |
762 | unsigned long lookUpCLUTIndex( unsigned char index, unsigned char depth )␊ |
763 | {␊ |
764 | ␉long result;␊ |
765 | ␊ |
766 | ␉long colorIndex = (index * 3);␊ |
767 | ␉long red = appleClut8[ colorIndex ];␊ |
768 | ␉long green = appleClut8[ colorIndex++ ];␊ |
769 | ␉long blue = appleClut8[ colorIndex++ ];␊ |
770 | ␊ |
771 | ␉switch (depth)␊ |
772 | ␉{␊ |
773 | ␉␉case 16 :␊ |
774 | ␉␉␉result = ((red & 0xF8) << 7) | ␊ |
775 | ␉␉␉␉((green & 0xF8) << 2) |␊ |
776 | ␉␉␉␉((blue & 0xF8) >> 3);␊ |
777 | ␉␉␉result |= (result << 16);␊ |
778 | ␉␉␉break;␊ |
779 | ␊ |
780 | ␉␉case 32 :␊ |
781 | ␉␉␉result = (red << 16) | (green << 8) | blue;␊ |
782 | ␉␉␉break;␊ |
783 | ␊ |
784 | ␉␉default :␊ |
785 | ␉␉␉result = index | (index << 8);␊ |
786 | ␉␉␉result |= (result << 16);␊ |
787 | ␉␉␉break;␊ |
788 | ␉}␊ |
789 | ␊ |
790 | ␉return result;␊ |
791 | }␊ |
792 | ␊ |
793 | //==========================================================================␊ |
794 | // drawColorRectangle␊ |
795 | ␊ |
796 | void *stosl(void *dst, long val, long len)␊ |
797 | {␊ |
798 | ␉asm volatile ( "rep; stosl"␊ |
799 | ␉␉␉␉ : "=c" (len), "=D" (dst)␊ |
800 | ␉␉␉␉ : "0" (len), "1" (dst), "a" (val)␊ |
801 | ␉␉␉␉ : "memory" );␊ |
802 | ␊ |
803 | ␉return dst;␊ |
804 | }␊ |
805 | ␊ |
806 | //==============================================================================␊ |
807 | ␊ |
808 | void drawColorRectangle( unsigned short x,␊ |
809 | unsigned short y,␊ |
810 | unsigned short width,␊ |
811 | unsigned short height,␊ |
812 | unsigned char colorIndex )␊ |
813 | {␊ |
814 | ␉long␉pixelBytes;␊ |
815 | ␉long␉color = lookUpCLUTIndex( colorIndex, VIDEO(depth) );␊ |
816 | ␉char␉*vram;␊ |
817 | ␊ |
818 | ␉pixelBytes = VIDEO(depth) / 8;␊ |
819 | ␉vram = (char *) VIDEO(baseAddr) + VIDEO(rowBytes) * y + pixelBytes * x;␊ |
820 | ␊ |
821 | ␉width = MIN(width, VIDEO(width) - x);␊ |
822 | ␉height = MIN(height, VIDEO(height) - y);␊ |
823 | ␊ |
824 | ␉while ( height-- )␊ |
825 | ␉{␊ |
826 | ␉␉int rem = ( pixelBytes * width ) % 4;␊ |
827 | ␉␉if ( rem )␊ |
828 | ␉␉{␊ |
829 | ␉␉␉bcopy( &color, vram, rem );␊ |
830 | ␉␉}␊ |
831 | ␊ |
832 | ␉␉stosl( vram + rem, color, pixelBytes * width / 4 );␊ |
833 | ␉␉vram += VIDEO(rowBytes);␊ |
834 | ␉}␊ |
835 | }␊ |
836 | ␊ |
837 | //==========================================================================␊ |
838 | // drawDataRectangle␊ |
839 | ␊ |
840 | void drawDataRectangle( unsigned short x, unsigned short y, unsigned short width, unsigned short height, unsigned char *data )␊ |
841 | {␊ |
842 | ␉unsigned short drawWidth;␊ |
843 | ␊ |
844 | ␉long pixelBytes = VIDEO(depth) / 8;␊ |
845 | ␊ |
846 | ␉unsigned char * vram = (unsigned char *) VIDEO(baseAddr) + VIDEO(rowBytes) * y + pixelBytes * x;␊ |
847 | ␊ |
848 | ␉drawWidth = MIN(width, VIDEO(width) - x);␊ |
849 | ␉height = MIN(height, VIDEO(height) - y);␊ |
850 | ␊ |
851 | ␉while ( height-- )␊ |
852 | ␉{␊ |
853 | ␉␉bcopy( data, vram, drawWidth * pixelBytes );␊ |
854 | ␉␉vram += VIDEO(rowBytes);␊ |
855 | ␉␉data += width * pixelBytes;␊ |
856 | ␉}␊ |
857 | }␊ |
858 | ␊ |
859 | //==============================================================================␊ |
860 | ␊ |
861 | void loadImageScale (void *input, int iw, int ih, int ip, void *output, int ow, int oh, int op, int or)␊ |
862 | {␊ |
863 | ␉int x, y, off;␊ |
864 | ␉int red = 0x7f, green = 0x7f, blue = 0x7f;␊ |
865 | ␉for ( x = 0; x < ow; x++)␊ |
866 | ␉␉for ( y = 0; y < oh; y++ )␊ |
867 | ␉␉{␊ |
868 | ␉␉␉off = ( x * iw ) / ow +( ( y * ih ) / oh ) * iw;␊ |
869 | ␉␉␉switch (ip)␊ |
870 | ␉␉␉{␊ |
871 | ␉␉␉␉case 16:␊ |
872 | ␉␉␉␉{␊ |
873 | ␉␉␉␉␉uint16_t val;␊ |
874 | ␉␉␉␉␉val=((uint16_t *)input)[off];␊ |
875 | ␉␉␉␉␉red=(val>>7)&0xf8;␊ |
876 | ␉␉␉␉␉green=(val>>2)&0xf8;␊ |
877 | ␉␉␉␉␉blue=(val<<3)&0xf8;␊ |
878 | ␉␉␉␉␉break;␊ |
879 | ␉␉␉␉}␊ |
880 | ␉␉␉␉case 32:␊ |
881 | ␉␉␉␉{␊ |
882 | ␉␉␉␉␉uint32_t val;␊ |
883 | ␉␉␉␉␉val=((uint32_t *)input)[off];␊ |
884 | ␉␉␉␉␉red=(val>>16)&0xff;␊ |
885 | ␉␉␉␉␉green=(val>>8)&0xff;␊ |
886 | ␉␉␉␉␉blue=(val)&0xff;␊ |
887 | ␉␉␉␉␉break;␊ |
888 | ␉␉␉␉}␊ |
889 | ␉␉␉}␊ |
890 | ␉␉␉char *ptr=(char *)output+x*(op/8)+y*or;␊ |
891 | ␉␉␉switch (op)␊ |
892 | ␉␉␉{␊ |
893 | ␉␉␉␉case 16:␊ |
894 | ␉␉␉␉␉*((uint16_t *)ptr) = ((red & 0xF8) << 7) | ␊ |
895 | ␉␉␉␉␉((green & 0xF8) << 2) |␊ |
896 | ␉␉␉␉␉((blue & 0xF8) >> 3);␊ |
897 | ␉␉␉␉␉break;␊ |
898 | ␉␉␉␉case 32 :␊ |
899 | ␉␉␉␉␉*((uint32_t *)ptr) = (red << 16) | (green << 8) | blue;␊ |
900 | ␉␉␉␉␉break;␊ |
901 | ␉␉␉}␊ |
902 | ␉␉}␊ |
903 | }␊ |
904 | ␊ |
905 | //==============================================================================␊ |
906 | ␊ |
907 | DECLARE_IOHIBERNATEPROGRESSALPHA␊ |
908 | ␊ |
909 | void drawPreview(void *src, uint8_t *saveunder)␊ |
910 | {␊ |
911 | ␉uint8_t *screen;␊ |
912 | ␉uint32_t rowBytes, pixelShift;␊ |
913 | ␉uint32_t x, y;␊ |
914 | ␉int32_t blob;␊ |
915 | ␉uint32_t alpha, in, color, result;␊ |
916 | ␉uint8_t *out;␊ |
917 | ␉void *uncomp;␊ |
918 | ␉int origwidth, origheight, origbpx;␊ |
919 | ␉uint32_t saveindex[kIOHibernateProgressCount] = { 0 };␊ |
920 | ␊ |
921 | ␉if (src && (uncomp=DecompressData(src, &origwidth, &origheight, &origbpx)))␊ |
922 | ␉{␊ |
923 | ␉␉if (!setVESAGraphicsMode(origwidth, origheight, origbpx, 0))␊ |
924 | ␉␉␉if (initGraphicsMode () != errSuccess)␊ |
925 | ␉␉␉{␊ |
926 | ␉␉␉␉return;␊ |
927 | ␉␉␉}␊ |
928 | ␊ |
929 | ␉␉screen = (uint8_t *) VIDEO (baseAddr);␊ |
930 | ␉␉rowBytes = VIDEO (rowBytes);␊ |
931 | ␉␉loadImageScale (uncomp, origwidth, origheight, origbpx, screen, VIDEO(width), VIDEO(height), VIDEO(depth), VIDEO (rowBytes));␊ |
932 | ␉}␊ |
933 | ␉else␊ |
934 | ␉{␊ |
935 | ␉␉if (initGraphicsMode () != errSuccess)␊ |
936 | ␉␉{␊ |
937 | ␉␉␉return;␊ |
938 | ␉␉}␊ |
939 | ␊ |
940 | ␉␉screen = (uint8_t *) VIDEO (baseAddr);␊ |
941 | ␉␉rowBytes = VIDEO (rowBytes);␊ |
942 | ␊ |
943 | ␉␉// Set the screen to 75% grey.␊ |
944 | ␉␉drawColorRectangle(0, 0, VIDEO(width), VIDEO(height), 0x01 /* color index */);␊ |
945 | ␉}␊ |
946 | ␊ |
947 | ␉pixelShift = VIDEO (depth) >> 4;␊ |
948 | ␉if (pixelShift < 1)␊ |
949 | ␉{␊ |
950 | ␉␉return;␊ |
951 | ␉}␊ |
952 | ␊ |
953 | ␉screen += ((VIDEO (width) ␊ |
954 | ␉␉␉␉- kIOHibernateProgressCount * (kIOHibernateProgressWidth + kIOHibernateProgressSpacing)) << (pixelShift - 1))␊ |
955 | ␉+ (VIDEO (height) - kIOHibernateProgressOriginY - kIOHibernateProgressHeight) * rowBytes;␊ |
956 | ␊ |
957 | ␉for (y = 0; y < kIOHibernateProgressHeight; y++)␊ |
958 | ␉{␊ |
959 | ␉␉out = screen + y * rowBytes;␊ |
960 | ␉␉for (blob = 0; blob < kIOHibernateProgressCount; blob++)␊ |
961 | ␉␉{␊ |
962 | ␉␉␉color = blob ? kIOHibernateProgressDarkGray : kIOHibernateProgressMidGray;␊ |
963 | ␉␉␉for (x = 0; x < kIOHibernateProgressWidth; x++)␊ |
964 | ␉␉␉{␊ |
965 | ␉␉␉␉alpha = gIOHibernateProgressAlpha[y][x];␊ |
966 | ␉␉␉␉result = color;␊ |
967 | ␉␉␉␉if (alpha)␊ |
968 | ␉␉␉␉{␊ |
969 | ␉␉␉␉␉if (0xff != alpha)␊ |
970 | ␉␉␉␉␉{␊ |
971 | ␉␉␉␉␉␉if (1 == pixelShift)␊ |
972 | ␉␉␉␉␉␉{␊ |
973 | ␉␉␉␉␉␉␉in = *((uint16_t *)out) & 0x1f;␉// 16␊ |
974 | ␉␉␉␉␉␉␉in = (in << 3) | (in >> 2);␊ |
975 | ␉␉␉␉␉␉}␊ |
976 | ␉␉␉␉␉␉else␊ |
977 | ␉␉␉␉␉␉{␊ |
978 | ␉␉␉␉␉␉␉in = *((uint32_t *)out) & 0xff;␉// 32␊ |
979 | ␉␉␉␉␉␉}␊ |
980 | ␊ |
981 | ␉␉␉␉␉␉saveunder[blob * kIOHibernateProgressSaveUnderSize + saveindex[blob]++] = in;␊ |
982 | ␉␉␉␉␉␉result = ((255 - alpha) * in + alpha * result + 0xff) >> 8;␊ |
983 | ␉␉␉␉␉}␊ |
984 | ␉␉␉␉␉if (1 == pixelShift)␊ |
985 | ␉␉␉␉␉{␊ |
986 | ␉␉␉␉␉␉result >>= 3;␊ |
987 | ␉␉␉␉␉␉*((uint16_t *)out) = (result << 10) | (result << 5) | result;␉// 16␊ |
988 | ␉␉␉␉␉}␊ |
989 | ␉␉␉␉␉else␊ |
990 | ␉␉␉␉␉{␊ |
991 | ␉␉␉␉␉␉*((uint32_t *)out) = (result << 16) | (result << 8) | result;␉// 32␊ |
992 | ␉␉␉␉␉}␊ |
993 | ␊ |
994 | ␉␉␉␉}␊ |
995 | ␉␉␉␉out += (1 << pixelShift);␊ |
996 | ␉␉␉}␊ |
997 | ␉␉␉out += (kIOHibernateProgressSpacing << pixelShift);␊ |
998 | ␉␉}␊ |
999 | ␉}␊ |
1000 | }␊ |
1001 | ␊ |
1002 | //==============================================================================␊ |
1003 | ␊ |
1004 | void updateProgressBar(uint8_t *saveunder, int32_t firstBlob, int32_t select)␊ |
1005 | {␊ |
1006 | ␉uint8_t␉␉*screen;␊ |
1007 | ␉uint32_t␉rowBytes, pixelShift;␊ |
1008 | ␉uint32_t␉x, y;␊ |
1009 | ␉int32_t␉␉blob, lastBlob;␊ |
1010 | ␉uint32_t␉alpha, in, color, result;␊ |
1011 | ␉uint8_t␉␉*out;␊ |
1012 | ␉uint32_t saveindex[kIOHibernateProgressCount] = { 0 };␊ |
1013 | ␊ |
1014 | ␉pixelShift = VIDEO(depth) >> 4;␊ |
1015 | ␉if (pixelShift < 1) return;␊ |
1016 | ␉screen = (uint8_t *) VIDEO (baseAddr);␊ |
1017 | ␉rowBytes = VIDEO (rowBytes);␊ |
1018 | ␊ |
1019 | ␉screen += ((VIDEO (width) ␊ |
1020 | ␉␉␉␉- kIOHibernateProgressCount * (kIOHibernateProgressWidth + kIOHibernateProgressSpacing)) << (pixelShift - 1))␊ |
1021 | ␉+ (VIDEO (height) - kIOHibernateProgressOriginY - kIOHibernateProgressHeight) * rowBytes;␊ |
1022 | ␊ |
1023 | ␉lastBlob = (select < kIOHibernateProgressCount) ? select : (kIOHibernateProgressCount - 1);␊ |
1024 | ␊ |
1025 | ␉screen += (firstBlob * (kIOHibernateProgressWidth + kIOHibernateProgressSpacing)) << pixelShift;␊ |
1026 | ␊ |
1027 | ␉for (y = 0; y < kIOHibernateProgressHeight; y++)␊ |
1028 | ␉{␊ |
1029 | ␉␉out = screen + y * rowBytes;␊ |
1030 | ␉␉for (blob = firstBlob; blob <= lastBlob; blob++)␊ |
1031 | ␉␉{␊ |
1032 | ␉␉␉color = (blob < select) ? kIOHibernateProgressLightGray : kIOHibernateProgressMidGray;␊ |
1033 | ␉␉␉for (x = 0; x < kIOHibernateProgressWidth; x++)␊ |
1034 | ␉␉␉{␊ |
1035 | ␉␉␉␉alpha = gIOHibernateProgressAlpha[y][x];␊ |
1036 | ␉␉␉␉result = color;␊ |
1037 | ␉␉␉␉if (alpha)␊ |
1038 | ␉␉␉␉{␊ |
1039 | ␉␉␉␉␉if (0xff != alpha)␊ |
1040 | ␉␉␉␉␉{␊ |
1041 | ␉␉␉␉␉␉in = saveunder[blob * kIOHibernateProgressSaveUnderSize + saveindex[blob]++];␊ |
1042 | ␉␉␉␉␉␉result = ((255 - alpha) * in + alpha * result + 0xff) / 255;␊ |
1043 | ␉␉␉␉␉}␊ |
1044 | ␊ |
1045 | ␉␉␉␉␉if (1 == pixelShift)␊ |
1046 | ␉␉␉␉␉{␊ |
1047 | ␉␉␉␉␉␉result >>= 3;␊ |
1048 | ␉␉␉␉␉␉*((uint16_t *)out) = (result << 10) | (result << 5) | result;␉// 16␊ |
1049 | ␉␉␉␉␉}␊ |
1050 | ␉␉␉␉␉else␊ |
1051 | ␉␉␉␉␉{␊ |
1052 | ␉␉␉␉␉␉*((uint32_t *)out) = (result << 16) | (result << 8) | result;␉// 32␊ |
1053 | ␉␉␉␉␉}␊ |
1054 | ␉␉␉␉}␊ |
1055 | ␉␉␉␉out += (1 << pixelShift);␊ |
1056 | ␉␉␉}␊ |
1057 | ␉␉␉out += (kIOHibernateProgressSpacing << pixelShift);␊ |
1058 | ␉␉}␊ |
1059 | ␉}␊ |
1060 | }␊ |
1061 | ␊ |
1062 | //==========================================================================␊ |
1063 | // setVESATextMode␊ |
1064 | ␊ |
1065 | static int setVESATextMode( unsigned short cols, unsigned short rows, unsigned char bitsPerPixel )␊ |
1066 | {␊ |
1067 | ␉VBEModeInfoBlock minfo;␊ |
1068 | ␉unsigned short mode = modeEndOfList;␊ |
1069 | ␊ |
1070 | ␉if ( (cols != 80) || (rows != 25) ) // not 80x25 mode␊ |
1071 | ␉{␊ |
1072 | ␉␉mode = getVESAModeWithProperties( cols, rows, bitsPerPixel,␊ |
1073 | maColorModeBit |␊ |
1074 | maModeIsSupportedBit,␊ |
1075 | maGraphicsModeBit,␊ |
1076 | &minfo, NULL );␊ |
1077 | ␉}␊ |
1078 | ␊ |
1079 | ␉if ( ( mode == modeEndOfList ) || ( setVBEMode(mode, NULL) != errSuccess ) )␊ |
1080 | ␉{␊ |
1081 | ␉␉video_mode( 2 ); // VGA BIOS, 80x25 text mode.␊ |
1082 | ␉␉minfo.XResolution = 80;␊ |
1083 | ␉␉minfo.YResolution = 25;␊ |
1084 | ␉}␊ |
1085 | ␊ |
1086 | ␉// Update KernBootStruct using info provided by the selected␊ |
1087 | ␉// VESA mode.␊ |
1088 | ␊ |
1089 | ␉bootArgs->Video.v_display = VGA_TEXT_MODE;␊ |
1090 | ␉bootArgs->Video.v_baseAddr = 0xb8000;␊ |
1091 | ␉bootArgs->Video.v_width = minfo.XResolution;␊ |
1092 | ␉bootArgs->Video.v_height = minfo.YResolution;␊ |
1093 | ␉bootArgs->Video.v_depth = 8;␊ |
1094 | ␉bootArgs->Video.v_rowBytes = 0x8000;␊ |
1095 | ␊ |
1096 | ␉return errSuccess; // always return success␊ |
1097 | }␊ |
1098 | ␊ |
1099 | //==========================================================================␊ |
1100 | // getNumberArrayFromProperty␊ |
1101 | ␊ |
1102 | static int getNumberArrayFromProperty( const char *propKey,␊ |
1103 | unsigned long numbers[],␊ |
1104 | unsigned long maxArrayCount )␊ |
1105 | {␊ |
1106 | ␉char␉␉*propStr;␊ |
1107 | ␉unsigned long␉count = 0;␊ |
1108 | ␊ |
1109 | ␉propStr = newStringForKey((char *)propKey , &bootInfo->chameleonConfig);␊ |
1110 | ␊ |
1111 | ␉if (propStr)␊ |
1112 | ␉{␊ |
1113 | ␉␉char *delimiter = propStr;␊ |
1114 | ␉␉char *p = propStr;␊ |
1115 | ␊ |
1116 | ␉␉while ((count < maxArrayCount) && (*p != '\0'))␊ |
1117 | ␉␉{␊ |
1118 | ␉␉␉unsigned long val = strtoul(p, &delimiter, 10);␊ |
1119 | ␉␉␉if (p != delimiter)␊ |
1120 | ␉␉␉{␊ |
1121 | ␉␉␉␉numbers[count++] = val;␊ |
1122 | ␉␉␉␉p = delimiter;␊ |
1123 | ␉␉␉}␊ |
1124 | ␉␉␉while ((*p != '\0') && !isdigit(*p))␊ |
1125 | ␉␉␉␉p++;␊ |
1126 | ␉␉}␊ |
1127 | ␊ |
1128 | ␉␉free(propStr);␊ |
1129 | ␉}␊ |
1130 | ␊ |
1131 | ␉return count;␊ |
1132 | }␊ |
1133 | ␊ |
1134 | //==============================================================================␊ |
1135 | ␊ |
1136 | int initGraphicsMode ()␊ |
1137 | {␊ |
1138 | ␉unsigned long params[4];␊ |
1139 | ␉int count;␊ |
1140 | ␊ |
1141 | ␉params[3] = 0;␊ |
1142 | ␉count = getNumberArrayFromProperty( kGraphicsModeKey, params, 4 );␊ |
1143 | ␊ |
1144 | ␉// Try to find a resolution if "Graphics Mode" setting is not available.␊ |
1145 | ␉if ( count < 3 )␊ |
1146 | ␉{␊ |
1147 | ␉␉// Use the default resolution if we don't have an initialized GUI.␊ |
1148 | ␉␉if (gui.screen.width == 0 || gui.screen.height == 0)␊ |
1149 | ␉␉{␊ |
1150 | ␉␉␉gui.screen.width = DEFAULT_SCREEN_WIDTH;␊ |
1151 | ␉␉␉gui.screen.height = DEFAULT_SCREEN_HEIGHT;␊ |
1152 | ␉␉}␊ |
1153 | ␊ |
1154 | ␉␉params[0] = gui.screen.width;␊ |
1155 | ␉␉params[1] = gui.screen.height;␊ |
1156 | ␉␉params[2] = 32;␊ |
1157 | ␉}␊ |
1158 | ␊ |
1159 | ␉// Map from pixel format to bits per pixel.␊ |
1160 | ␊ |
1161 | ␉if ( params[2] == 256 )␊ |
1162 | ␉␉params[2] = 8;␊ |
1163 | ␊ |
1164 | ␉if ( params[2] == 555 )␊ |
1165 | ␉␉params[2] = 16;␊ |
1166 | ␊ |
1167 | ␉if ( params[2] == 888 )␊ |
1168 | ␉␉params[2] = 32;␊ |
1169 | ␊ |
1170 | ␉return setVESAGraphicsMode( params[0], params[1], params[2], params[3] );␊ |
1171 | }␊ |
1172 | ␊ |
1173 | //==========================================================================␊ |
1174 | // setVideoMode␊ |
1175 | //␊ |
1176 | // Set the video mode to VGA_TEXT_MODE or GRAPHICS_MODE.␊ |
1177 | ␊ |
1178 | void setVideoMode( int mode, int drawgraphics)␊ |
1179 | {␊ |
1180 | ␉unsigned long params[4];␊ |
1181 | ␉int count;␊ |
1182 | ␉int err = errSuccess;␊ |
1183 | ␊ |
1184 | ␉if ( mode == GRAPHICS_MODE )␊ |
1185 | ␉{␊ |
1186 | ␉␉if ( (err = initGraphicsMode()) == errSuccess )␊ |
1187 | ␉␉{␊ |
1188 | ␉␉␉if (gVerboseMode)␊ |
1189 | ␉␉␉{␊ |
1190 | ␉␉␉␉// Tell the kernel to use text mode on a linear frame buffer display␊ |
1191 | ␉␉␉␉bootArgs->Video.v_display = FB_TEXT_MODE;␊ |
1192 | ␉␉␉}␊ |
1193 | ␉␉␉else␊ |
1194 | ␉␉␉{␊ |
1195 | ␉␉␉␉bootArgs->Video.v_display = GRAPHICS_MODE;␊ |
1196 | ␉␉␉}␊ |
1197 | ␉␉}␊ |
1198 | ␉}␊ |
1199 | ␊ |
1200 | ␉if ( (mode == VGA_TEXT_MODE) || (err != errSuccess) )␊ |
1201 | ␉{␊ |
1202 | ␉␉count = getNumberArrayFromProperty(kTextModeKey, params, 2);␊ |
1203 | ␉␉if ( count < 2 )␊ |
1204 | ␉␉{␊ |
1205 | ␉␉␉params[0] = 80; // Default text mode is 80x25.␊ |
1206 | ␉␉␉params[1] = 25;␊ |
1207 | ␉␉}␊ |
1208 | ␊ |
1209 | ␉␉setVESATextMode(params[0], params[1], 4);␊ |
1210 | ␉␉bootArgs->Video.v_display = VGA_TEXT_MODE;␊ |
1211 | ␉}␊ |
1212 | ␊ |
1213 | ␉currentIndicator = 0;␊ |
1214 | }␊ |
1215 | ␊ |
1216 | //==============================================================================␊ |
1217 | void getGraphicModeParams(unsigned long params[])␊ |
1218 | {␊ |
1219 | ␉params[3] = 0;␊ |
1220 | ␊ |
1221 | ␉VBEModeInfoBlock minfo;␊ |
1222 | ␊ |
1223 | ␉unsigned short vesaVersion;␊ |
1224 | ␉unsigned short mode = modeEndOfList;␊ |
1225 | ␊ |
1226 | ␉getNumberArrayFromProperty(kGraphicsModeKey, params, 4);␊ |
1227 | ␊ |
1228 | ␉mode = getVESAModeWithProperties(params[0], params[1], params[2],␊ |
1229 | ␉␉␉␉␉␉␉␉␉ maColorModeBit |␊ |
1230 | ␉␉␉␉␉␉␉␉␉ maModeIsSupportedBit |␊ |
1231 | ␉␉␉␉␉␉␉␉␉ maGraphicsModeBit |␊ |
1232 | ␉␉␉␉␉␉␉␉␉ maLinearFrameBufferAvailBit,␊ |
1233 | ␉␉␉␉␉␉␉␉␉ 0,␊ |
1234 | ␉␉␉␉␉␉␉␉␉ &minfo, &vesaVersion);␊ |
1235 | ␊ |
1236 | ␉params[0] = minfo.XResolution;␊ |
1237 | ␉params[1] = minfo.YResolution;␊ |
1238 | ␉params[2] = 32;␊ |
1239 | }␊ |
1240 | ␉␊ |
1241 | //==========================================================================␊ |
1242 | // Return the current video mode, VGA_TEXT_MODE or GRAPHICS_MODE.␊ |
1243 | ␊ |
1244 | int getVideoMode(void)␊ |
1245 | {␊ |
1246 | return bootArgs->Video.v_display;␊ |
1247 | }␊ |
1248 | ␊ |
1249 | //==========================================================================␊ |
1250 | // Display and clear the activity indicator.␊ |
1251 | ␊ |
1252 | // BASIC Indicator␊ |
1253 | static char indicator[] = {'-', '\\', '|', '/', '\0'};␊ |
1254 | ␊ |
1255 | // To prevent a ridiculously fast-spinning indicator,␊ |
1256 | // ensure a minimum of 1/9 sec between animation frames.␊ |
1257 | #define MIN_TICKS 2␊ |
1258 | ␊ |
1259 | //==============================================================================␊ |
1260 | ␊ |
1261 | void spinActivityIndicator(int sectors)␊ |
1262 | {␊ |
1263 | static unsigned long lastTickTime = 0, currentTickTime;␊ |
1264 | ␊ |
1265 | ␉if (previewTotalSectors && previewSaveunder)␊ |
1266 | ␉{␊ |
1267 | ␉␉int blob, lastBlob;␊ |
1268 | ␊ |
1269 | ␉␉lastBlob = (previewLoadedSectors * kIOHibernateProgressCount) / previewTotalSectors;␊ |
1270 | ␉␉previewLoadedSectors+=sectors;␊ |
1271 | ␉␉blob = (previewLoadedSectors * kIOHibernateProgressCount) / previewTotalSectors;␊ |
1272 | ␉␉␊ |
1273 | ␉␉if (blob!=lastBlob)␊ |
1274 | ␉␉{␊ |
1275 | ␉␉␉updateProgressBar (previewSaveunder, lastBlob, blob);␊ |
1276 | ␉␉}␊ |
1277 | ␉␉return;␊ |
1278 | ␉}␊ |
1279 | ␊ |
1280 | ␉currentTickTime = time18(); // late binding␊ |
1281 | ␉if (currentTickTime < lastTickTime + MIN_TICKS)␊ |
1282 | ␉{␊ |
1283 | ␉␉return;␊ |
1284 | ␉}␊ |
1285 | ␉else␊ |
1286 | ␉{␊ |
1287 | ␉␉lastTickTime = currentTickTime;␊ |
1288 | ␉}␊ |
1289 | ␊ |
1290 | ␉if (getVideoMode() == VGA_TEXT_MODE)␊ |
1291 | ␉{␊ |
1292 | ␉␉if (currentIndicator >= sizeof(indicator))␊ |
1293 | ␉␉{␊ |
1294 | ␉␉␉currentIndicator = 0;␊ |
1295 | ␉␉}␊ |
1296 | ␉␉putchar(indicator[currentIndicator++]);␊ |
1297 | ␉␉putchar('\b');␊ |
1298 | ␉}␊ |
1299 | }␊ |
1300 | ␊ |
1301 | //==============================================================================␊ |
1302 | ␊ |
1303 | void clearActivityIndicator( void )␊ |
1304 | {␊ |
1305 | ␉if ( getVideoMode() == VGA_TEXT_MODE )␊ |
1306 | ␉{␊ |
1307 | ␉␉putchar(' ');␊ |
1308 | ␉␉putchar('\b');␊ |
1309 | ␉}␊ |
1310 | }␊ |
1311 | ␊ |
1312 | //==============================================================================␊ |
1313 | |