Annotation of Examples/DriverKit/S3/S3_reloc.tproj/vgaModes.c, revision 1.1.1.1

1.1       root        1: #import <driverkit/i386/ioPorts.h>
                      2: #import "vgaModes.h"
                      3: 
                      4: static const VGAMode VGAMode_3 = {
                      5:     0x67, 0x00,
                      6:     { 0x01, 0x00, 0x03, 0x00, 0x02 },
                      7:     {                                  
                      8:        0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f, 0x00, 0x4f,
                      9:        0x0d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x9c, 0x8e, 0x8f, 0x28,
                     10:        0x1f, 0x96, 0xb9, 0xa3, 0xff,
                     11:     },
                     12:     {
                     13:        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39,
                     14:        0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x0c, 0x00, 0x0f, 0x08,
                     15:     },
                     16:     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0e, 0x00, 0xff },
                     17: };
                     18: 
                     19: static const VGAMode VGAMode_12 = {
                     20:     0xE3, 0x00,
                     21:     { 0x03, 0x01, 0x0f, 0x00, 0x06 },
                     22:     {
                     23:        0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0x0b, 0x3e, 0x00, 0x40,
                     24:        0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0xea, 0x8c, 0xdf, 0x28,
                     25:        0x00, 0xe7, 0x04, 0xe3, 0xff,
                     26:     },
                     27:     {
                     28:        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39,
                     29:        0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x01, 0x00, 0x0f, 0x00,
                     30:     },
                     31:     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0f, 0xff },
                     32: };
                     33: 
                     34: int
                     35: VGASetMode(unsigned int mode)
                     36: {
                     37:     switch (mode) {
                     38:     case 0x03:
                     39:        VGASetModeData(&VGAMode_3);
                     40:        break;
                     41:     case 0x12:
                     42:        VGASetModeData(&VGAMode_12);
                     43:        break;
                     44:     default:
                     45:        return -1;
                     46:     }
                     47:     return 0;
                     48: }
                     49: 
                     50: int
                     51: VGASetModeData(const VGAMode *modeData)
                     52: {
                     53:     int k;
                     54:     
                     55:     /* NOTE: The attribute registers are a little weird. For most registers,
                     56:      * there is a separate index and data port. The attribute register set
                     57:      * has just one port that gets used for both. You write an index to the
                     58:      * port, then use the same port for data. The VGA automatically toggles
                     59:      * the sense of the port (between index and data) with an internal
                     60:      * flip-flop.  You set the state of the flip-flop by doing an inb() on
                     61:      * the input status 1 port.
                     62:      *
                     63:      * The other weird thing is that the attribute index register also
                     64:      * contains a palette access bit. This bit determines whether the
                     65:      * CPU or the VGA has control of the palette. While the CPU owns the
                     66:      * palette, the display is effectively off.
                     67:      */
                     68: 
                     69:     /* Turn the video off while we are doing this.... */
                     70: 
                     71:     inb(VGA_INPUT_STATUS_1);   /* Set the attribute flip-flop to "index". */
                     72:     outb(VGA_ATTR_INDEX, 0x00);        /* Gives palette to CPU, turning off video. */
                     73:     
                     74:     /* Set the misc. output register. */
                     75:     outb(VGA_MISC_OUTPUT, modeData->miscOutput);
                     76:     
                     77:     /* Set the feature control register */
                     78:     outb(VGA_FEATURE_CTRL, modeData->featureCtrl);
                     79: 
                     80:     /* Load the sequencer registers. */
                     81:     for (k = 0; k < VGA_SEQ_COUNT; k++) {
                     82:        outb(VGA_SEQ_INDEX, k);
                     83:        outb(VGA_SEQ_DATA, modeData->seqx[k]);
                     84:     }
                     85:     outb(VGA_SEQ_INDEX, 0x00);
                     86:     outb(VGA_SEQ_DATA, 0x03);  /* Low order two bits are reset bits. */
                     87:     
                     88:     /* Load the CRTC registers.  CRTC registers 0-7 are locked by a bit
                     89:      * in register 0x11. We need to unlock these registers before we can
                     90:      * start setting them. */
                     91:     outb(VGA_CRTC_INDEX, 0x11);
                     92:     outb(VGA_CRTC_DATA, 0x00);         /* Unlocks registers 0-7. */
                     93:     for (k = 0; k < VGA_CRTC_COUNT; k++) {
                     94:        outb(VGA_CRTC_INDEX, k);
                     95:        outb(VGA_CRTC_DATA, modeData->crtc[k]);
                     96:     }
                     97: 
                     98:     /* Load the attribute registers. */
                     99:     inb(VGA_INPUT_STATUS_1);   /* Set the attribute flip-flop to "index" */
                    100:     for (k = 0; k < VGA_ATTR_COUNT; k++) {
                    101:        outb(VGA_ATTR_INDEX, k);
                    102:        outb(VGA_ATTR_DATA, modeData->attr[k]);
                    103:     }
                    104: 
                    105:     /* Load graphics registers. */
                    106:     for (k = 0; k < VGA_GRFX_COUNT; k++) {
                    107:        outb(VGA_GRFX_INDEX, k);
                    108:        outb(VGA_GRFX_DATA, modeData->grfx[k]);
                    109:     }    
                    110: 
                    111:     /* Re-enable video. */
                    112:     inb(VGA_INPUT_STATUS_1);   /* Set the attribute flip-flop to "index" */
                    113:     outb(VGA_ATTR_INDEX, 0x20);        /* Give the palette back to the VGA */
                    114:     
                    115:     return 0;
                    116: }

unix.superglobalmegacorp.com

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