Annotation of ntddk/src/video/miniport/wdvga/modeset.c, revision 1.1.1.1

1.1       root        1: /*++
                      2: 
                      3: Copyright (c) 1992  Microsoft Corporation
                      4: 
                      5: Module Name:
                      6: 
                      7:     modeset.c
                      8: 
                      9: Abstract:
                     10: 
                     11:     This is the modeset code for the WD VGA miniport driver.
                     12: 
                     13: Environment:
                     14: 
                     15:     kernel mode only
                     16: 
                     17: Notes:
                     18: 
                     19: Revision History:
                     20: 
                     21: --*/
                     22: #include "dderror.h"
                     23: #include "devioctl.h"
                     24: #include "miniport.h"
                     25: 
                     26: #include "ntddvdeo.h"
                     27: #include "video.h"
                     28: #include "wdvga.h"
                     29: #include "modeset.h"
                     30: 
                     31: VOID
                     32: VgaZeroVideoMemory(
                     33:     PHW_DEVICE_EXTENSION HwDeviceExtension
                     34:     );
                     35: 
                     36: 
                     37: VP_STATUS
                     38: VgaInterpretCmdStream(
                     39:     PHW_DEVICE_EXTENSION HwDeviceExtension,
                     40:     PUSHORT pusCmdStream
                     41:     )
                     42: 
                     43: /*++
                     44: 
                     45: Routine Description:
                     46: 
                     47:     Interprets the appropriate command array to set up VGA registers for the
                     48:     requested mode. Typically used to set the VGA into a particular mode by
                     49:     programming all of the registers
                     50: 
                     51: Arguments:
                     52: 
                     53:     HwDeviceExtension - Pointer to the miniport driver's device extension.
                     54: 
                     55:     pusCmdStream - array of commands to be interpreted.
                     56: 
                     57: Return Value:
                     58: 
                     59:     The status of the operation (can only fail on a bad command); TRUE for
                     60:     success, FALSE for failure.
                     61: 
                     62: --*/
                     63: 
                     64: {
                     65:     ULONG ulCmd;
                     66:     ULONG ulPort;
                     67:     UCHAR jValue;
                     68:     USHORT usValue;
                     69:     ULONG culCount;
                     70:     ULONG ulIndex;
                     71:     ULONG ulBase;
                     72: 
                     73:     if (pusCmdStream == NULL) {
                     74: 
                     75:         VideoDebugPrint((1, "VgaInterpretCmdStream - Invalid pusCmdStream\n"));
                     76:         return TRUE;
                     77:     }
                     78: 
                     79:     ulBase = (ULONG)HwDeviceExtension->IOAddress;
                     80: 
                     81:     //
                     82:     // Now set the adapter to the desired mode.
                     83:     //
                     84: 
                     85:     while ((ulCmd = *pusCmdStream++) != EOD) {
                     86: 
                     87:         //
                     88:         // Determine major command type
                     89:         //
                     90: 
                     91:         switch (ulCmd & 0xF0) {
                     92: 
                     93:             //
                     94:             // Basic input/output command
                     95:             //
                     96: 
                     97:             case INOUT:
                     98: 
                     99:                 //
                    100:                 // Determine type of inout instruction
                    101:                 //
                    102: 
                    103:                 if (!(ulCmd & IO)) {
                    104: 
                    105:                     //
                    106:                     // Out instruction. Single or multiple outs?
                    107:                     //
                    108: 
                    109:                     if (!(ulCmd & MULTI)) {
                    110: 
                    111:                         //
                    112:                         // Single out. Byte or word out?
                    113:                         //
                    114: 
                    115:                         if (!(ulCmd & BW)) {
                    116: 
                    117:                             //
                    118:                             // Single byte out
                    119:                             //
                    120: 
                    121:                             ulPort = *pusCmdStream++;
                    122:                             jValue = (UCHAR) *pusCmdStream++;
                    123:                             VideoPortWritePortUchar((PUCHAR)(ulBase+ulPort),
                    124:                                     jValue);
                    125: 
                    126:                         } else {
                    127: 
                    128:                             //
                    129:                             // Single word out
                    130:                             //
                    131: 
                    132:                             ulPort = *pusCmdStream++;
                    133:                             usValue = *pusCmdStream++;
                    134:                             VideoPortWritePortUshort((PUSHORT)(ulBase+ulPort),
                    135:                                     usValue);
                    136: 
                    137:                         }
                    138: 
                    139:                     } else {
                    140: 
                    141:                         //
                    142:                         // Output a string of values
                    143:                         // Byte or word outs?
                    144:                         //
                    145: 
                    146:                         if (!(ulCmd & BW)) {
                    147: 
                    148:                             //
                    149:                             // String byte outs. Do in a loop; can't use
                    150:                             // VideoPortWritePortBufferUchar because the data
                    151:                             // is in USHORT form
                    152:                             //
                    153: 
                    154:                             ulPort = ulBase + *pusCmdStream++;
                    155:                             culCount = *pusCmdStream++;
                    156: 
                    157:                             while (culCount--) {
                    158:                                 jValue = (UCHAR) *pusCmdStream++;
                    159:                                 VideoPortWritePortUchar((PUCHAR)ulPort,
                    160:                                         jValue);
                    161: 
                    162:                             }
                    163: 
                    164:                         } else {
                    165: 
                    166:                             //
                    167:                             // String word outs
                    168:                             //
                    169: 
                    170:                             ulPort = *pusCmdStream++;
                    171:                             culCount = *pusCmdStream++;
                    172:                             VideoPortWritePortBufferUshort((PUSHORT)
                    173:                                     (ulBase + ulPort), pusCmdStream, culCount);
                    174:                             pusCmdStream += culCount;
                    175: 
                    176:                         }
                    177:                     }
                    178: 
                    179:                 } else {
                    180: 
                    181:                     // In instruction
                    182:                     //
                    183:                     // Currently, string in instructions aren't supported; all
                    184:                     // in instructions are handled as single-byte ins
                    185:                     //
                    186:                     // Byte or word in?
                    187:                     //
                    188: 
                    189:                     if (!(ulCmd & BW)) {
                    190:                         //
                    191:                         // Single byte in
                    192:                         //
                    193: 
                    194:                         ulPort = *pusCmdStream++;
                    195:                         jValue = VideoPortReadPortUchar((PUCHAR)ulBase+ulPort);
                    196: 
                    197:                     } else {
                    198: 
                    199:                         //
                    200:                         // Single word in
                    201:                         //
                    202: 
                    203:                         ulPort = *pusCmdStream++;
                    204:                         usValue = VideoPortReadPortUshort((PUSHORT)
                    205:                                 (ulBase+ulPort));
                    206: 
                    207:                     }
                    208: 
                    209:                 }
                    210: 
                    211:                 break;
                    212: 
                    213:             //
                    214:             // Higher-level input/output commands
                    215:             //
                    216: 
                    217:             case METAOUT:
                    218: 
                    219:                 //
                    220:                 // Determine type of metaout command, based on minor
                    221:                 // command field
                    222:                 //
                    223:                 switch (ulCmd & 0x0F) {
                    224: 
                    225:                     //
                    226:                     // Indexed outs
                    227:                     //
                    228: 
                    229:                     case INDXOUT:
                    230: 
                    231:                         ulPort = ulBase + *pusCmdStream++;
                    232:                         culCount = *pusCmdStream++;
                    233:                         ulIndex = *pusCmdStream++;
                    234: 
                    235:                         while (culCount--) {
                    236: 
                    237:                             usValue = (USHORT) (ulIndex +
                    238:                                       (((ULONG)(*pusCmdStream++)) << 8));
                    239:                             VideoPortWritePortUshort((PUSHORT)ulPort, usValue);
                    240: 
                    241:                             ulIndex++;
                    242: 
                    243:                         }
                    244: 
                    245:                         break;
                    246: 
                    247:                     //
                    248:                     // Masked out (read, AND, XOR, write)
                    249:                     //
                    250: 
                    251:                     case MASKOUT:
                    252: 
                    253:                         ulPort = *pusCmdStream++;
                    254:                         jValue = VideoPortReadPortUchar((PUCHAR)ulBase+ulPort);
                    255:                         jValue &= *pusCmdStream++;
                    256:                         jValue ^= *pusCmdStream++;
                    257:                         VideoPortWritePortUchar((PUCHAR)ulBase + ulPort,
                    258:                                 jValue);
                    259:                         break;
                    260: 
                    261:                     //
                    262:                     // Attribute Controller out
                    263:                     //
                    264: 
                    265:                     case ATCOUT:
                    266: 
                    267:                         ulPort = ulBase + *pusCmdStream++;
                    268:                         culCount = *pusCmdStream++;
                    269:                         ulIndex = *pusCmdStream++;
                    270: 
                    271:                         while (culCount--) {
                    272: 
                    273:                             // Write Attribute Controller index
                    274:                             VideoPortWritePortUchar((PUCHAR)ulPort,
                    275:                                     (UCHAR)ulIndex);
                    276: 
                    277:                             // Write Attribute Controller data
                    278:                             jValue = (UCHAR) *pusCmdStream++;
                    279:                             VideoPortWritePortUchar((PUCHAR)ulPort, jValue);
                    280: 
                    281:                             ulIndex++;
                    282: 
                    283:                         }
                    284: 
                    285:                         break;
                    286: 
                    287:                     //
                    288:                     // None of the above; error
                    289:                     //
                    290:                     default:
                    291: 
                    292:                         return FALSE;
                    293: 
                    294:                 }
                    295: 
                    296: 
                    297:                 break;
                    298: 
                    299:             //
                    300:             // NOP
                    301:             //
                    302: 
                    303:             case NCMD:
                    304: 
                    305:                 break;
                    306: 
                    307:             //
                    308:             // Unknown command; error
                    309:             //
                    310: 
                    311:             default:
                    312: 
                    313:                 return FALSE;
                    314: 
                    315:         }
                    316: 
                    317:     }
                    318: 
                    319:     return TRUE;
                    320: 
                    321: } // end VgaInterpretCmdStream()
                    322: 
                    323: 
                    324: VP_STATUS
                    325: VgaSetMode(
                    326:     PHW_DEVICE_EXTENSION HwDeviceExtension,
                    327:     PVIDEO_MODE Mode,
                    328:     ULONG ModeSize
                    329:     )
                    330: 
                    331: /*++
                    332: 
                    333: Routine Description:
                    334: 
                    335:     This routine sets the VGA into the requested mode.
                    336: 
                    337: Arguments:
                    338: 
                    339:     HwDeviceExtension - Pointer to the miniport driver's device extension.
                    340: 
                    341:     Mode - Pointer to the structure containing the information about the
                    342:         font to be set.
                    343: 
                    344:     ModeSize - Length of the input buffer supplied by the user.
                    345: 
                    346: Return Value:
                    347: 
                    348:     ERROR_INSUFFICIENT_BUFFER if the input buffer was not large enough
                    349:         for the input data.
                    350: 
                    351:     ERROR_INVALID_PARAMETER if the mode number is invalid.
                    352: 
                    353:     NO_ERROR if the operation completed successfully.
                    354: 
                    355: --*/
                    356: 
                    357: {
                    358: 
                    359:     PVIDEOMODE pRequestedMode;
                    360:     VP_STATUS status;
                    361:     UCHAR temp;
                    362:     UCHAR dummy;
                    363:     UCHAR bIsColor;
                    364:     VIDEO_X86_BIOS_ARGUMENTS biosArguments;
                    365:     UCHAR frequencySetting;
                    366: 
                    367:     //
                    368:     // Check if the size of the data in the input buffer is large enough.
                    369:     //
                    370: 
                    371:     if (ModeSize < sizeof(VIDEO_MODE)) {
                    372: 
                    373:         return ERROR_INSUFFICIENT_BUFFER;
                    374: 
                    375:     }
                    376: 
                    377:     //
                    378:     // Extract the clear memory bit.
                    379:     //
                    380: 
                    381:     if (Mode->RequestedMode & VIDEO_MODE_NO_ZERO_MEMORY) {
                    382: 
                    383:         Mode->RequestedMode &= ~VIDEO_MODE_NO_ZERO_MEMORY;
                    384: 
                    385:     }  else {
                    386: 
                    387:         VgaZeroVideoMemory(HwDeviceExtension);
                    388: 
                    389:     }
                    390: 
                    391:     //
                    392:     // Check to see if we are requesting a valid mode
                    393:     //
                    394: 
                    395:     if ( (Mode->RequestedMode >= NumVideoModes) ||
                    396:          (!ModesVGA[Mode->RequestedMode].ValidMode) ) {
                    397: 
                    398:         return ERROR_INVALID_PARAMETER;
                    399: 
                    400:     }
                    401: 
                    402:     pRequestedMode = &ModesVGA[Mode->RequestedMode];
                    403: 
                    404:     //
                    405:     // Make sure we unlock extended registers since the BIOS on some machines
                    406:     // does not do it properly.
                    407:     //
                    408: 
                    409:     VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
                    410:                GRAPH_ADDRESS_PORT, 0x0F);
                    411: 
                    412:     VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
                    413:                GRAPH_DATA_PORT, 0x05);
                    414: 
                    415: #ifdef INT10_MODE_SET
                    416: 
                    417:     //
                    418:     // First set up the frequency so the modeset grabs it properly.
                    419:     //
                    420: 
                    421:     if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
                    422:             MISC_OUTPUT_REG_READ_PORT) & 0x01) {
                    423: 
                    424:         bIsColor = TRUE;
                    425: 
                    426:     } else {
                    427: 
                    428:         bIsColor = FALSE;
                    429: 
                    430:     }
                    431: 
                    432:     if (bIsColor) {
                    433: 
                    434:         VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
                    435:                                     CRTC_ADDRESS_PORT_COLOR, 0x2b);
                    436: 
                    437:         temp = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
                    438:                                           CRTC_DATA_PORT_COLOR);
                    439: 
                    440:     } else {
                    441: 
                    442:         VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
                    443:                                     CRTC_ADDRESS_PORT_MONO, 0x2b);
                    444: 
                    445:         temp = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
                    446:                                           CRTC_DATA_PORT_MONO);
                    447: 
                    448:     }
                    449: 
                    450:     //
                    451:     // Adjust the frequency setting register and write it back out.
                    452:     // Also support Diamond changes to frequency settings
                    453:     //
                    454: 
                    455:     temp &= pRequestedMode->FrequencyMask;
                    456: 
                    457:     frequencySetting = pRequestedMode->FrequencySetting;
                    458: 
                    459:     
                    460:     if ( (HwDeviceExtension->BoardID == SPEEDSTAR31) &&
                    461:          (pRequestedMode->hres == 1024) ) {
                    462: 
                    463:         //
                    464:         // Diamond has inversed the refresh rates of interlaced and 72 Hz
                    465:         // on the 1024 modes
                    466:         //
                    467: 
                    468:         if (pRequestedMode->Frequency == 72) {
                    469: 
                    470:             frequencySetting = 0x00;
                    471: 
                    472:         } else {
                    473: 
                    474:             if (pRequestedMode->Frequency == 44) {
                    475: 
                    476:                 frequencySetting = 0x30;
                    477: 
                    478:             }
                    479:         }
                    480:     }
                    481: 
                    482:     temp |= frequencySetting;
                    483: 
                    484:     if (bIsColor) {
                    485: 
                    486:         VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
                    487:                                     CRTC_DATA_PORT_COLOR, temp);
                    488: 
                    489:     } else {
                    490: 
                    491:         VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
                    492:                                     CRTC_DATA_PORT_MONO, temp);
                    493: 
                    494:     }
                    495: 
                    496:     //
                    497:     // Set the mode
                    498:     //
                    499: 
                    500:     VideoPortZeroMemory(&biosArguments, sizeof(VIDEO_X86_BIOS_ARGUMENTS));
                    501: 
                    502:     biosArguments.Eax = pRequestedMode->Int10ModeNumber;
                    503: 
                    504:     status = VideoPortInt10(HwDeviceExtension, &biosArguments);
                    505: 
                    506:     if (status != NO_ERROR) {
                    507: 
                    508:         return status;
                    509: 
                    510:     }
                    511: 
                    512:     if (pRequestedMode->CmdStrings != NULL) {
                    513: 
                    514:         VgaInterpretCmdStream(HwDeviceExtension, pRequestedMode->CmdStrings);
                    515: 
                    516:     }
                    517: 
                    518:     if (!(pRequestedMode->fbType & VIDEO_MODE_GRAPHICS)) {
                    519: 
                    520:         //
                    521:         // Fix to make sure we always set the colors in text mode to be
                    522:         // intensity, and not flashing
                    523:         // For this zero out the Mode Control Regsiter bit 3 (index 0x10
                    524:         // of the Attribute controller).
                    525:         //
                    526: 
                    527:         if (bIsColor) {
                    528: 
                    529:             dummy = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
                    530:                     INPUT_STATUS_1_COLOR);
                    531:         } else {
                    532: 
                    533:             dummy = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
                    534:                     INPUT_STATUS_1_MONO);
                    535:         }
                    536: 
                    537:         VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
                    538:                 ATT_ADDRESS_PORT, (0x10 | VIDEO_ENABLE));
                    539:         temp = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
                    540:                 ATT_DATA_READ_PORT);
                    541: 
                    542:         temp &= 0xF7;
                    543: 
                    544:         if (bIsColor) {
                    545: 
                    546:             dummy = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
                    547:                     INPUT_STATUS_1_COLOR);
                    548:         } else {
                    549: 
                    550:             dummy = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
                    551:                     INPUT_STATUS_1_MONO);
                    552:         }
                    553: 
                    554:         VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
                    555:                 ATT_ADDRESS_PORT, (0x10 | VIDEO_ENABLE));
                    556:         VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
                    557:                 ATT_DATA_WRITE_PORT, temp);
                    558: 
                    559:     }
                    560: 
                    561: #else
                    562:     VgaInterpretCmdStream(HwDeviceExtension, pRequestedMode->CmdStrings);
                    563: #endif
                    564: 
                    565:     //
                    566:     // Make sure we unlock extended registers since the BIOS on some machines
                    567:     // does not do it properly.
                    568:     //
                    569: 
                    570:     VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
                    571:                GRAPH_ADDRESS_PORT, 0x0F);
                    572: 
                    573:     VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
                    574:                GRAPH_DATA_PORT, 0x05);
                    575: 
                    576:     //
                    577:     // Update the location of the physical frame buffer within video memory.
                    578:     //
                    579: 
                    580:     HwDeviceExtension->PhysicalFrameLength =
                    581:             MemoryMaps[pRequestedMode->MemMap].MaxSize;
                    582: 
                    583:     HwDeviceExtension->PhysicalFrameBase.LowPart =
                    584:             MemoryMaps[pRequestedMode->MemMap].Start;
                    585: 
                    586:     //
                    587:     // Store the new mode value.
                    588:     //
                    589: 
                    590:     HwDeviceExtension->CurrentMode = pRequestedMode;
                    591:     HwDeviceExtension->ModeIndex = Mode->RequestedMode;
                    592: 
                    593:     return NO_ERROR;
                    594: 
                    595: } //end VgaSetMode()
                    596: 
                    597: 
                    598: VP_STATUS
                    599: VgaQueryAvailableModes(
                    600:     PHW_DEVICE_EXTENSION HwDeviceExtension,
                    601:     PVIDEO_MODE_INFORMATION ModeInformation,
                    602:     ULONG ModeInformationSize,
                    603:     PULONG OutputSize
                    604:     )
                    605: 
                    606: /*++
                    607: 
                    608: Routine Description:
                    609: 
                    610:     This routine returns the list of all available available modes on the
                    611:     card.
                    612: 
                    613: Arguments:
                    614: 
                    615:     HwDeviceExtension - Pointer to the miniport driver's device extension.
                    616: 
                    617:     ModeInformation - Pointer to the output buffer supplied by the user.
                    618:         This is where the list of all valid modes is stored.
                    619: 
                    620:     ModeInformationSize - Length of the output buffer supplied by the user.
                    621: 
                    622:     OutputSize - Pointer to a buffer in which to return the actual size of
                    623:         the data in the buffer. If the buffer was not large enough, this
                    624:         contains the minimum required buffer size.
                    625: 
                    626: Return Value:
                    627: 
                    628:     ERROR_INSUFFICIENT_BUFFER if the output buffer was not large enough
                    629:         for the data being returned.
                    630: 
                    631:     NO_ERROR if the operation completed successfully.
                    632: 
                    633: --*/
                    634: 
                    635: {
                    636:     PVIDEO_MODE_INFORMATION videoModes = ModeInformation;
                    637:     ULONG i;
                    638: 
                    639:     //
                    640:     // Find out the size of the data to be put in the buffer and return
                    641:     // that in the status information (whether or not the information is
                    642:     // there). If the buffer passed in is not large enough return an
                    643:     // appropriate error code.
                    644:     //
                    645: 
                    646:     if (ModeInformationSize < (*OutputSize =
                    647:             HwDeviceExtension->NumAvailableModes *
                    648:             sizeof(VIDEO_MODE_INFORMATION)) ) {
                    649: 
                    650:         return ERROR_INSUFFICIENT_BUFFER;
                    651: 
                    652:     }
                    653: 
                    654:     //
                    655:     // For each mode supported by the card, store the mode characteristics
                    656:     // in the output buffer.
                    657:     //
                    658: 
                    659:     for (i = 0; i < NumVideoModes; i++) {
                    660: 
                    661:         if (ModesVGA[i].ValidMode) {
                    662: 
                    663:             videoModes->Length = sizeof(VIDEO_MODE_INFORMATION);
                    664:             videoModes->ModeIndex  = i;
                    665:             videoModes->VisScreenWidth = ModesVGA[i].hres;
                    666:             videoModes->ScreenStride = ModesVGA[i].wbytes;
                    667:             videoModes->VisScreenHeight = ModesVGA[i].vres;
                    668:             videoModes->NumberOfPlanes = ModesVGA[i].numPlanes;
                    669:             videoModes->BitsPerPlane = ModesVGA[i].bitsPerPlane;
                    670:             videoModes->Frequency = ModesVGA[i].Frequency;
                    671:             videoModes->XMillimeter = 330;        // temporary hardcoded constant
                    672:             videoModes->YMillimeter = 240;        // temporary hardcoded constant
                    673:             videoModes->NumberRedBits = 6;
                    674:             videoModes->NumberGreenBits = 6;
                    675:             videoModes->NumberBlueBits = 6;
                    676:             videoModes->AttributeFlags = ModesVGA[i].fbType;
                    677:             videoModes->AttributeFlags |= ModesVGA[i].Interlaced ?
                    678:                  VIDEO_MODE_INTERLACED : 0;
                    679: 
                    680:             videoModes->RedMask = 0;
                    681:             videoModes->GreenMask = 0;
                    682:             videoModes->BlueMask = 0;
                    683:             videoModes->AttributeFlags |= VIDEO_MODE_PALETTE_DRIVEN |
                    684:                     VIDEO_MODE_MANAGED_PALETTE;
                    685: 
                    686:             videoModes++;
                    687: 
                    688:         }
                    689:     }
                    690: 
                    691:     return NO_ERROR;
                    692: 
                    693: } // end VgaGetAvailableModes()
                    694: 
                    695: VP_STATUS
                    696: VgaQueryNumberOfAvailableModes(
                    697:     PHW_DEVICE_EXTENSION HwDeviceExtension,
                    698:     PVIDEO_NUM_MODES NumModes,
                    699:     ULONG NumModesSize,
                    700:     PULONG OutputSize
                    701:     )
                    702: 
                    703: /*++
                    704: 
                    705: Routine Description:
                    706: 
                    707:     This routine returns the number of available modes for this particular
                    708:     video card.
                    709: 
                    710: Arguments:
                    711: 
                    712:     HwDeviceExtension - Pointer to the miniport driver's device extension.
                    713: 
                    714:     NumModes - Pointer to the output buffer supplied by the user. This is
                    715:         where the number of modes is stored.
                    716: 
                    717:     NumModesSize - Length of the output buffer supplied by the user.
                    718: 
                    719:     OutputSize - Pointer to a buffer in which to return the actual size of
                    720:         the data in the buffer.
                    721: 
                    722: Return Value:
                    723: 
                    724:     ERROR_INSUFFICIENT_BUFFER if the output buffer was not large enough
                    725:         for the data being returned.
                    726: 
                    727:     NO_ERROR if the operation completed successfully.
                    728: 
                    729: --*/
                    730: 
                    731: {
                    732:     //
                    733:     // Find out the size of the data to be put in the the buffer and return
                    734:     // that in the status information (whether or not the information is
                    735:     // there). If the buffer passed in is not large enough return an
                    736:     // appropriate error code.
                    737:     //
                    738: 
                    739:     if (NumModesSize < (*OutputSize = sizeof(VIDEO_NUM_MODES)) ) {
                    740: 
                    741:         return ERROR_INSUFFICIENT_BUFFER;
                    742: 
                    743:     }
                    744: 
                    745:     //
                    746:     // Store the number of modes into the buffer.
                    747:     //
                    748: 
                    749:     NumModes->NumModes = NumVideoModes;
                    750:     NumModes->ModeInformationLength = sizeof(VIDEO_MODE_INFORMATION);
                    751: 
                    752:     return NO_ERROR;
                    753: 
                    754: } // end VgaGetNumberOfAvailableModes()
                    755: 
                    756: VP_STATUS
                    757: VgaQueryCurrentMode(
                    758:     PHW_DEVICE_EXTENSION HwDeviceExtension,
                    759:     PVIDEO_MODE_INFORMATION ModeInformation,
                    760:     ULONG ModeInformationSize,
                    761:     PULONG OutputSize
                    762:     )
                    763: 
                    764: /*++
                    765: 
                    766: Routine Description:
                    767: 
                    768:     This routine returns a description of the current video mode.
                    769: 
                    770: Arguments:
                    771: 
                    772:     HwDeviceExtension - Pointer to the miniport driver's device extension.
                    773: 
                    774:     ModeInformation - Pointer to the output buffer supplied by the user.
                    775:         This is where the current mode information is stored.
                    776: 
                    777:     ModeInformationSize - Length of the output buffer supplied by the user.
                    778: 
                    779:     OutputSize - Pointer to a buffer in which to return the actual size of
                    780:         the data in the buffer. If the buffer was not large enough, this
                    781:         contains the minimum required buffer size.
                    782: 
                    783: Return Value:
                    784: 
                    785:     ERROR_INSUFFICIENT_BUFFER if the output buffer was not large enough
                    786:         for the data being returned.
                    787: 
                    788:     NO_ERROR if the operation completed successfully.
                    789: 
                    790: --*/
                    791: 
                    792: {
                    793:     //
                    794:     // Find out the size of the data to be put in the the buffer and return
                    795:     // that in the status information (whether or not the information is
                    796:     // there). If the buffer passed in is not large enough return an
                    797:     // appropriate error code.
                    798:     //
                    799: 
                    800:     if (ModeInformationSize < (*OutputSize = sizeof(VIDEO_MODE_INFORMATION))) {
                    801: 
                    802:         return ERROR_INSUFFICIENT_BUFFER;
                    803: 
                    804:     }
                    805: 
                    806:     //
                    807:     // Store the characteristics of the current mode into the buffer.
                    808:     //
                    809: 
                    810:     ModeInformation->Length = sizeof(VIDEO_MODE_INFORMATION);
                    811:     ModeInformation->ModeIndex = HwDeviceExtension->ModeIndex;
                    812:     ModeInformation->VisScreenWidth = HwDeviceExtension->CurrentMode->hres;
                    813:     ModeInformation->ScreenStride = HwDeviceExtension->CurrentMode->wbytes;
                    814:     ModeInformation->VisScreenHeight = HwDeviceExtension->CurrentMode->vres;
                    815:     ModeInformation->NumberOfPlanes = HwDeviceExtension->CurrentMode->numPlanes;
                    816:     ModeInformation->BitsPerPlane = HwDeviceExtension->CurrentMode->bitsPerPlane;
                    817:     ModeInformation->Frequency = HwDeviceExtension->CurrentMode->Frequency;
                    818:     ModeInformation->XMillimeter = 330;        // temporary hardcoded constant
                    819:     ModeInformation->YMillimeter = 240;        // temporary hardcoded constant
                    820:     ModeInformation->NumberRedBits = 6;
                    821:     ModeInformation->NumberGreenBits = 6;
                    822:     ModeInformation->NumberBlueBits = 6;
                    823:     ModeInformation->RedMask = 0;
                    824:     ModeInformation->GreenMask = 0;
                    825:     ModeInformation->BlueMask = 0;
                    826:     ModeInformation->AttributeFlags = HwDeviceExtension->CurrentMode->fbType |
                    827:              VIDEO_MODE_PALETTE_DRIVEN | VIDEO_MODE_MANAGED_PALETTE;
                    828:     ModeInformation->AttributeFlags |= HwDeviceExtension->CurrentMode->Interlaced ?
                    829:              VIDEO_MODE_INTERLACED : 0;
                    830: 
                    831:     return NO_ERROR;
                    832: 
                    833: } // end VgaQueryCurrentMode()
                    834: 
                    835: 
                    836: VOID
                    837: VgaZeroVideoMemory(
                    838:     PHW_DEVICE_EXTENSION HwDeviceExtension
                    839:     )
                    840: /*++
                    841: 
                    842: Routine Description:
                    843: 
                    844:     This routine zeros the first 256K on the VGA.
                    845: 
                    846: Arguments:
                    847: 
                    848:     HwDeviceExtension - Pointer to the miniport driver's device extension.
                    849: 
                    850: 
                    851: Return Value:
                    852: 
                    853:     None.
                    854: 
                    855: --*/
                    856: {
                    857:     UCHAR temp;
                    858: 
                    859:     //
                    860:     // Map font buffer at A0000
                    861:     //
                    862: 
                    863:     VgaInterpretCmdStream(HwDeviceExtension, EnableA000Data);
                    864: 
                    865:     //
                    866:     // Enable all planes.
                    867:     //
                    868:     VideoPortWritePortUchar(HwDeviceExtension->IOAddress + SEQ_ADDRESS_PORT,
                    869:             IND_MAP_MASK);
                    870: 
                    871:     temp = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
                    872:             SEQ_DATA_PORT) | (UCHAR)0x0F;
                    873: 
                    874:     VideoPortWritePortUchar(HwDeviceExtension->IOAddress + SEQ_DATA_PORT,
                    875:             temp);
                    876: 
                    877:     //
                    878:     // Zero the memory.
                    879:     //
                    880: 
                    881:     VideoPortZeroMemory(HwDeviceExtension->VideoMemoryAddress,
                    882:             0xFFFF);
                    883: 
                    884:     VgaInterpretCmdStream(HwDeviceExtension, DisableA000Color);
                    885: 
                    886: }
                    887: 
                    888: 
                    889: VOID
                    890: VgaValidateModes(
                    891:     PHW_DEVICE_EXTENSION HwDeviceExtension
                    892:     )
                    893: 
                    894: /*++
                    895: 
                    896: Routine Description:
                    897: 
                    898:     Determines which modes are valid and which are not.
                    899: 
                    900: Arguments:
                    901: 
                    902:     HwDeviceExtension - Pointer to the miniport driver's device extension.
                    903: 
                    904: Return Value:
                    905: 
                    906:     None.
                    907: 
                    908: --*/
                    909: {
                    910: 
                    911:     ULONG i;
                    912: 
                    913:     HwDeviceExtension->NumAvailableModes = 0;
                    914: 
                    915:     for (i = 0; i < NumVideoModes; i++) {
                    916: 
                    917:         if (HwDeviceExtension->AdapterMemorySize >=
                    918:             ModesVGA[i].numPlanes * ModesVGA[i].sbytes) {
                    919:    
                    920:             ModesVGA[i].ValidMode = TRUE;
                    921:             HwDeviceExtension->NumAvailableModes++;
                    922:    
                    923:         }
                    924: 
                    925:         //
                    926:         // Older boards do not support 72HZ in 1024x768 modes.
                    927:         // So disable those.
                    928:         //
                    929: 
                    930:         if ( (HwDeviceExtension->BoardID < WD90C31) &&
                    931:              (ModesVGA[i].hres == 1024) &&
                    932:              (ModesVGA[i].vres == 768) &&
                    933:              (ModesVGA[i].Frequency == 72) &&
                    934:              (ModesVGA[i].ValidMode) ) {
                    935: 
                    936:             ModesVGA[i].ValidMode = FALSE;
                    937:             HwDeviceExtension->NumAvailableModes--;
                    938:    
                    939:         }
                    940:     }
                    941: }

unix.superglobalmegacorp.com

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