use the -newos toolchain even if -elf is present.
[newos.git] / apps / window_server / vga.cpp
blobe87c7b1b289732acce9d5fe80fdcdf6391591e0c
1 /* $Id$
2 **
3 ** Copyright 1998 Brian J. Swetland
4 ** All rights reserved.
5 **
6 ** Redistribution and use in source and binary forms, with or without
7 ** modification, are permitted provided that the following conditions
8 ** are met:
9 ** 1. Redistributions of source code must retain the above copyright
10 ** notice, this list of conditions, and the following disclaimer.
11 ** 2. Redistributions in binary form must reproduce the above copyright
12 ** notice, this list of conditions, and the following disclaimer in the
13 ** documentation and/or other materials provided with the distribution.
14 ** 3. The name of the author may not be used to endorse or promote products
15 ** derived from this software without specific prior written permission.
17 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include "vga.h"
30 #include <i386/io.h>
32 const int MiscOutputReg = 0x3c2;
33 const int DataReg = 0x3c0;
34 const int AddressReg = 0x3c0;
36 const char mode13[][32] = {
37 { 0x03, 0x01, 0x0f, 0x00, 0x0e }, /* 0x3c4, index 0-4*/
38 { 0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0xbf, 0x1f,
39 0x00, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
40 0x9c, 0x0e, 0x8f, 0x28, 0x40, 0x96, 0xb9, 0xa3,
41 0xff }, /* 0x3d4, index 0-0x18*/
42 { 0, 0, 0, 0, 0, 0x40, 0x05, 0x0f, 0xff }, /* 0x3ce, index 0-8*/
43 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
44 0x41, 0, 0x0f, 0, 0 } /* 0x3c0, index 0-0x14*/
47 #define Vga256 0x13 // 320x200x256
48 #define TextMode 0x03 // 80x25 text mode
49 #define PaletteMask 0x3C6 // bit mask register
50 #define PaletteRegisterRead 0x3C7 // read index
51 #define PaletteRegisterWrite 0x3C8 // write index
52 #define PaletteData 0x3C9 // send/receive data here
53 #define RomCharSegment 0xF000
54 #define RomCharOffset 0xFA6E
55 #define CharWidth 8
56 #define CharHeight 8
58 void SetPalette(int color, int red, int green, int blue)
61 outb(0xFF, PaletteMask);
62 outb(color, PaletteRegisterWrite);
63 outb(red, PaletteData);
64 outb(green, PaletteData);
65 outb(blue, PaletteData);
68 int InitVGA()
70 int i;
72 outb_p(0x63, MiscOutputReg);
73 outb_p(0x00, 0x3da);
75 for (i=0; i < 5; i++) {
76 outb_p(i, 0x3c4);
77 outb_p(mode13[0][i], 0x3c4+1);
80 outw_p(0x0e11, 0x3d4);
82 for (i=0; i < 0x19; i++) {
83 outb_p(i, 0x3d4);
84 outb_p(mode13[1][i], (0x3d4 + 1));
87 for (i=0; i < 0x9; i++) {
88 outb_p(i, 0x3ce);
89 outb_p(mode13[2][i], (0x3ce + 1));
92 inb_p(0x3da);
94 for (i=0; i < 0x15; i++) {
95 inw(DataReg);
96 outb_p(i, AddressReg);
97 outb_p(mode13[3][i], DataReg);
100 outb_p(0x20, 0x3c0);
102 return 1;