Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
54 pj 1
 
2
#include "timing.h"
3
#include "vgaregs.h"
4
 
5
 
6
/*
7
 * Setup VGA registers for SVGA mode timing. Adapted from XFree86,
8
 * vga256/vga/vgaHW.c vgaHWInit().
9
 *
10
 * Note that VGA registers are set up in a way that is common for
11
 * SVGA modes. This is not particularly useful for standard VGA
12
 * modes, since VGA does not have a clean packed-pixel mode.
13
 */
14
 
15
void __svgalib_setup_VGA_registers(unsigned char *moderegs, ModeTiming * modetiming,
16
                         ModeInfo * modeinfo)
17
{
18
    int i;
19
/* Sync Polarities */
20
    if ((modetiming->flags & (PHSYNC | NHSYNC)) &&
21
        (modetiming->flags & (PVSYNC | NVSYNC))) {
22
        /*
23
         * If both horizontal and vertical polarity are specified,
24
         * set them as specified.
25
         */
26
        moderegs[VGA_MISCOUTPUT] = 0x23;
27
        if (modetiming->flags & NHSYNC)
28
            moderegs[VGA_MISCOUTPUT] |= 0x40;
29
        if (modetiming->flags & NVSYNC)
30
            moderegs[VGA_MISCOUTPUT] |= 0x80;
31
    } else {
32
        /*
33
         * Otherwise, calculate the polarities according to
34
         * monitor standards.
35
         */
36
        if (modetiming->VDisplay < 400)
37
            moderegs[VGA_MISCOUTPUT] = 0xA3;
38
        else if (modetiming->VDisplay < 480)
39
            moderegs[VGA_MISCOUTPUT] = 0x63;
40
        else if (modetiming->VDisplay < 768)
41
            moderegs[VGA_MISCOUTPUT] = 0xE3;
42
        else
43
            moderegs[VGA_MISCOUTPUT] = 0x23;
44
    }
45
 
46
/* Sequencer */
47
    moderegs[VGA_SR0] = 0x00;
48
    if (modeinfo->bitsPerPixel == 4)
49
        moderegs[VGA_SR0] = 0x02;
50
    moderegs[VGA_SR1] = 0x01;
51
    moderegs[VGA_SR2] = 0x0F;   /* Bitplanes. */
52
    moderegs[VGA_SR3] = 0x00;
53
    moderegs[VGA_SR4] = 0x0E;
54
    if (modeinfo->bitsPerPixel == 4)
55
        moderegs[VGA_SR4] = 0x06;
56
 
57
/* CRTC Timing */
58
    moderegs[VGA_CR0] = (modetiming->CrtcHTotal / 8) - 5;
59
    moderegs[VGA_CR1] = (modetiming->CrtcHDisplay / 8) - 1;
60
    moderegs[VGA_CR2] = (modetiming->CrtcHSyncStart / 8) - 1;
61
    moderegs[VGA_CR3] = ((modetiming->CrtcHSyncEnd / 8) & 0x1F) | 0x80;
62
    moderegs[VGA_CR4] = (modetiming->CrtcHSyncStart / 8);
63
    moderegs[VGA_CR5] = (((modetiming->CrtcHSyncEnd / 8) & 0x20) << 2)
64
        | ((modetiming->CrtcHSyncEnd / 8) & 0x1F);
65
    moderegs[VGA_CR6] = (modetiming->CrtcVTotal - 2) & 0xFF;
66
    moderegs[VGA_CR7] = (((modetiming->CrtcVTotal - 2) & 0x100) >> 8)
67
        | (((modetiming->CrtcVDisplay - 1) & 0x100) >> 7)
68
        | ((modetiming->CrtcVSyncStart & 0x100) >> 6)
69
        | (((modetiming->CrtcVSyncStart) & 0x100) >> 5)
70
        | 0x10
71
        | (((modetiming->CrtcVTotal - 2) & 0x200) >> 4)
72
        | (((modetiming->CrtcVDisplay - 1) & 0x200) >> 3)
73
        | ((modetiming->CrtcVSyncStart & 0x200) >> 2);
74
    moderegs[VGA_CR8] = 0x00;
75
    moderegs[VGA_CR9] = ((modetiming->CrtcVSyncStart & 0x200) >> 4) | 0x40;
76
    if (modetiming->flags & DOUBLESCAN)
77
        moderegs[VGA_CR9] |= 0x80;
78
    moderegs[VGA_CRA] = 0x00;
79
    moderegs[VGA_CRB] = 0x00;
80
    moderegs[VGA_CRC] = 0x00;
81
    moderegs[VGA_CRD] = 0x00;
82
    moderegs[VGA_CRE] = 0x00;
83
    moderegs[VGA_CRF] = 0x00;
84
    moderegs[VGA_CR10] = modetiming->CrtcVSyncStart & 0xFF;
85
    moderegs[VGA_CR11] = (modetiming->CrtcVSyncEnd & 0x0F) | 0x20;
86
    moderegs[VGA_CR12] = (modetiming->CrtcVDisplay - 1) & 0xFF;
87
    moderegs[VGA_CR13] = modeinfo->lineWidth >> 4;      /* Just a guess. */
88
    moderegs[VGA_CR14] = 0x00;
89
    moderegs[VGA_CR15] = modetiming->CrtcVSyncStart & 0xFF;
90
    moderegs[VGA_CR16] = (modetiming->CrtcVSyncStart + 1) & 0xFF;
91
    moderegs[VGA_CR17] = 0xC3;
92
    if (modeinfo->bitsPerPixel == 4)
93
        moderegs[VGA_CR17] = 0xE3;
94
    moderegs[VGA_CR18] = 0xFF;
95
 
96
/* Graphics Controller */
97
    moderegs[VGA_GR0] = 0x00;
98
    moderegs[VGA_GR1] = 0x00;
99
    moderegs[VGA_GR2] = 0x00;
100
    moderegs[VGA_GR3] = 0x00;
101
    moderegs[VGA_GR4] = 0x00;
102
    moderegs[VGA_GR5] = 0x40;
103
    if (modeinfo->bitsPerPixel == 4)
104
        moderegs[VGA_GR5] = 0x02;
105
    moderegs[VGA_GR6] = 0x05;
106
    moderegs[VGA_GR7] = 0x0F;
107
    moderegs[VGA_GR8] = 0xFF;
108
 
109
/* Attribute Controller */
110
    for (i = 0; i < 16; i++)
111
        moderegs[VGA_AR0 + i] = i;
112
    moderegs[VGA_AR10] = 0x41;
113
    if (modeinfo->bitsPerPixel == 4)
114
        moderegs[VGA_AR10] = 0x01;      /* was 0x81 */
115
    /* Attribute register 0x11 is the overscan color.
116
       Should have no affect in svga modes.           */
117
    moderegs[VGA_AR11] = 0x00;
118
    moderegs[VGA_AR12] = 0x0F;
119
    moderegs[VGA_AR13] = 0x00;
120
    moderegs[VGA_AR14] = 0x00;
121
}
122