Annotation of Examples/DriverKit/S3/S3_reloc.tproj/S3.m, revision 1.1

1.1     ! root        1: /* Copyright (c) 1993 by NeXT Computer, Inc.
        !             2:  * All rights reserved.
        !             3:  *
        !             4:  * S3.m -- driver for S3 86C805 and 86C928 Graphics Accelerators
        !             5:  *
        !             6:  * Created by Peter Graffagnino 1/31/93
        !             7:  * Modified by Derek B Clegg   21 May 1993
        !             8:  */
        !             9: #import <driverkit/i386/IOEISADeviceDescription.h>
        !            10: #import "S3.h"
        !            11: 
        !            12: @implementation S3
        !            13: 
        !            14: /* Put the display into linear framebuffer mode. This typically happens
        !            15:  * when the window server starts running.
        !            16:  */
        !            17: - (void)enterLinearMode
        !            18: {
        !            19:     /* Set up the chip to use the selected mode. */
        !            20:     [self initializeMode];
        !            21: 
        !            22:     /* Set the gamma-corrected gray-scale palette if necessary. */
        !            23:     [self setGammaTable];
        !            24: 
        !            25:     /* Enter linear mode. */
        !            26:     if ([self enableLinearFrameBuffer] == nil) {
        !            27:        IOLog("%s: Failed to enter linear mode.\n", [self name]);
        !            28:        return;
        !            29:     }
        !            30: }
        !            31: 
        !            32: /* Get the device out of whatever advanced linear mode it was using and back
        !            33:  * into a state where it can be used as a standard VGA device.
        !            34:  */
        !            35: - (void)revertToVGAMode
        !            36: {
        !            37:     /* Reset the VGA parameters. */
        !            38:     [self resetVGA];
        !            39: 
        !            40:     /* Let the superclass do whatever work it needs to do. */
        !            41:     [super revertToVGAMode];
        !            42: }
        !            43: 
        !            44: /* Set the brightness to `level'.
        !            45:  */
        !            46: - setBrightness:(int)level token:(int)t
        !            47: {
        !            48:     if (level < EV_SCREEN_MIN_BRIGHTNESS || level > EV_SCREEN_MAX_BRIGHTNESS) {
        !            49:        IOLog("QVision: Invalid brightness level `%d'.\n", level);
        !            50:        return nil;
        !            51:     }
        !            52:     brightnessLevel = level;
        !            53:     [self setGammaTable];
        !            54:     return self;
        !            55: }
        !            56: 
        !            57: /* Set the transfer tables.
        !            58:  */
        !            59: - setTransferTable:(const unsigned int *)table count:(int)numEntries
        !            60: {
        !            61:     int k;
        !            62:     IOBitsPerPixel bpp;
        !            63:     IOColorSpace cspace;
        !            64: 
        !            65:     if (redTransferTable != 0)
        !            66:        IOFree(redTransferTable, 3 * transferTableCount);
        !            67: 
        !            68:     transferTableCount = numEntries;
        !            69: 
        !            70:     redTransferTable = IOMalloc(3 * numEntries);
        !            71:     greenTransferTable = redTransferTable + numEntries;
        !            72:     blueTransferTable = greenTransferTable + numEntries;
        !            73: 
        !            74:     bpp = [self displayInfo]->bitsPerPixel;
        !            75:     cspace = [self displayInfo]->colorSpace;
        !            76: 
        !            77:     if (bpp == IO_8BitsPerPixel && cspace == IO_OneIsWhiteColorSpace) {
        !            78:        for (k = 0; k < numEntries; k++) {
        !            79:            redTransferTable[k] = greenTransferTable[k] =
        !            80:                blueTransferTable[k] = table[k] & 0xFF;
        !            81:        }
        !            82:     } else if (cspace == IO_RGBColorSpace &&
        !            83:               (bpp == IO_8BitsPerPixel ||
        !            84:                bpp == IO_15BitsPerPixel ||
        !            85:                bpp == IO_24BitsPerPixel)) {
        !            86:        for (k = 0; k < numEntries; k++) {
        !            87:            redTransferTable[k] = (table[k] >> 24) & 0xFF;
        !            88:            greenTransferTable[k] = (table[k] >> 16) & 0xFF;
        !            89:            blueTransferTable[k] = (table[k] >> 8) & 0xFF;
        !            90:        }
        !            91:     } else {
        !            92:        IOFree(redTransferTable, 3 * numEntries);
        !            93:        redTransferTable = 0;
        !            94:     }
        !            95:     [self setGammaTable];
        !            96:     return self;
        !            97: }
        !            98: 
        !            99: - initFromDeviceDescription:deviceDescription
        !           100: {
        !           101:     IODisplayInfo *displayInfo;
        !           102:     const IORange *range;
        !           103:     const S3Mode *s3mode;
        !           104:     const char *s;
        !           105: 
        !           106:     if ([super initFromDeviceDescription:deviceDescription] == nil)
        !           107:        return [super free];
        !           108: 
        !           109:     if ([self determineConfiguration] == nil)
        !           110:        return [super free];
        !           111: 
        !           112:     if ([self selectMode] == nil)
        !           113:        return [super free];
        !           114: 
        !           115:     range = [deviceDescription memoryRangeList];
        !           116:     if (range == 0) {
        !           117:        IOLog("%s: No memory range set.\n", [self name]);
        !           118:        return [super free];
        !           119:     }
        !           120:     videoRamAddress = range[0].start;
        !           121: 
        !           122:     redTransferTable = greenTransferTable = blueTransferTable = 0;
        !           123:     transferTableCount = 0;
        !           124:     brightnessLevel = EV_SCREEN_MAX_BRIGHTNESS;
        !           125: 
        !           126:     displayInfo = [self displayInfo];
        !           127:     s3mode = displayInfo->parameters;
        !           128:     displayInfo->flags = 0;
        !           129: 
        !           130:     /* Some S3 805 cards have a lot of flicker when write-posting or
        !           131:      * read-ahead is enabled.  We disable both, but provide a way to
        !           132:      * turn them on from the config table.  It's a good idea to enable
        !           133:      * both if possible, since it speeds up the display a good deal.
        !           134:      */
        !           135: 
        !           136:     writePostingEnabled = [self booleanForStringKey:"WritePostingEnabled"
        !           137:                       withDefault:(adapter == S3_805 ? NO : YES)];
        !           138:     readAheadCacheEnabled = [self booleanForStringKey:"ReadAheadCacheEnabled"
        !           139:                         withDefault:(adapter == S3_805 ? NO : YES)];
        !           140: 
        !           141:     /* Turn on s/w gamma correction.  (This is only necessary for the 555/16
        !           142:      * modes.) */
        !           143: 
        !           144:     if ([self hasTransferTable])
        !           145:        displayInfo->flags |= IO_DISPLAY_HAS_TRANSFER_TABLE;
        !           146: 
        !           147:     if ([self needsSoftwareGammaCorrection])
        !           148:        displayInfo->flags |= IO_DISPLAY_NEEDS_SOFTWARE_GAMMA_CORRECTION;
        !           149: 
        !           150:     if (adapter == S3_805) {
        !           151:        /* On the 805, always turn the cache off. */
        !           152:        displayInfo->flags |= IO_DISPLAY_CACHE_OFF;
        !           153:     } else {
        !           154:        s = [self valueForStringKey:"DisplayCacheMode"];
        !           155:        if (s != 0) {
        !           156:            if (strcmp(s, "Off") == 0)
        !           157:                displayInfo->flags |= IO_DISPLAY_CACHE_OFF;
        !           158:            else if (strcmp(s, "WriteThrough") == 0)
        !           159:                displayInfo->flags |= IO_DISPLAY_CACHE_WRITETHROUGH;
        !           160:            else if (strcmp(s, "CopyBack") == 0)
        !           161:                displayInfo->flags |= IO_DISPLAY_CACHE_COPYBACK;
        !           162:            else
        !           163:                IOLog("%s: Unrecognized value for key `DisplayCacheMode': "
        !           164:                      "`%s'.\n", [self name], s);
        !           165:        }
        !           166:     }
        !           167: 
        !           168:     displayInfo->frameBuffer =
        !           169:         (void *)[self mapFrameBufferAtPhysicalAddress:videoRamAddress
        !           170:             length:s3mode->memSize];
        !           171:     if (displayInfo->frameBuffer == 0)
        !           172:        return [super free];
        !           173: 
        !           174:     IOLog("%s: Initialized `%s' @ %d Hz.\n", [self name], s3mode->name, 
        !           175:          displayInfo->refreshRate);
        !           176: 
        !           177:     return self;
        !           178: }
        !           179: @end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.