root / Whitix / branches / scheduler / video / switch.c

Revision 559, 2.5 kB (checked in by mwhitworth, 7 months ago)

Merge hybrid/modular branch (to date) with trunk.

Line 
1/*  This file is part of Whitix.
2 *
3 *  Whitix is free software; you can redistribute it and/or modify
4 *  it under the terms of the GNU General Public License as published by
5 *  the Free Software Foundation; either version 2 of the License, or
6 *  (at your option) any later version.
7 *
8 *  Whitix is distributed in the hope that it will be useful,
9 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 *  GNU General Public License for more details.
12 *
13 *  You should have received a copy of the GNU General Public License
14 *  along with Whitix; if not, write to the Free Software
15 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
16 *
17 */
18
19#include <console.h>
20#include <fs/devfs.h>
21#include <fs/vfs.h>
22#include <init.h>
23#include <error.h>
24#include <malloc.h>
25#include <i386/ioports.h>
26#include <task.h>
27
28/* TODO: Document. */
29
30#define VGA_ATT_INDEX           0x3C0
31#define VGA_ATT_WRITE           0x3C0
32
33#define VGA_SEQ_INDEX           0x3C4
34#define VGA_SEQ_DATA            0x3C5
35
36#define VGA_GFX_INDEX           0x3CE
37#define VGA_GFX_DATA            0x3CF
38
39#define VGA_CRT_INDEXC          0x3D4
40#define VGA_CRT_DATAC           0x3D5
41
42/* VGA: Switch back to text mode, so we can display the error message (most likely). */
43
44BYTE attribRegisters[0x15]={
45        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07,
46        0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
47        0x0C, 0x00, 0x0F, 0x08, 0x00,
48};
49
50BYTE seqRegisters[5]={
51        0x03, 0x00, 0x03, 0x00, 0x02,
52};
53
54BYTE gfxRegisters[9]={
55        0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0E, 0x0F, 0xFF,
56};
57
58BYTE crtcRegisters[0x19]={
59        0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81, 0xBF, 0x1F, 0x00, 0x4F,
60        0x0D, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x9C, 0x8E, 0x8F, 0x28,
61        0x1F, 0x96, 0xB9, 0xA3, 0xFF,
62};
63
64void ConsoleSwitchToText()
65{
66        int i;
67       
68        /* TODO: No need to switch back if we haven't even established multiple consoles yet. */
69
70        /* Are we already in text mode? */
71        if (!(consoles[currConsole].flags & CONSOLE_GRAPHICS))
72                return;
73
74        inb(0x3DA);
75
76        for (i=0; i<0x15; i++)
77        {
78                outb(VGA_ATT_INDEX, i);
79                outb(VGA_ATT_WRITE, attribRegisters[i]);
80        }
81
82        for (i=0; i<5; i++)
83        {
84                outb(VGA_SEQ_INDEX, i);
85                outb(VGA_SEQ_INDEX, seqRegisters[i]);
86        }
87
88        for (i=0; i<9; i++)
89        {
90                outb(VGA_GFX_INDEX, i);
91                outb(VGA_GFX_DATA, gfxRegisters[i]);
92        }
93
94        outw(VGA_CRT_INDEXC, 0x0011);
95
96        for (i=0; i<0x19; i++)
97        {
98                outb(VGA_CRT_INDEXC, i);
99                outb(VGA_CRT_DATAC, crtcRegisters[i]);
100        }
101
102        outb(0x3C2, 0x67);
103        outb(0x3C0, 0x20);     
104        inb(0x3DA);
105
106        consoles[currConsole].flags &= ~CONSOLE_GRAPHICS;
107}
Note: See TracBrowser for help on using the browser.