* libcurses++, libc++ and liblightOS++ are installed into the crosscompiler directory
[lightOS.git] / kernel / x86 / vbe.cpp
blob93391719a9bc010a179f2d82f78545212d9c5142
1 /*
2 lightOS kernel
3 Copyright (C) 2006-2009 Jörg Pfähler
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <cstring>
20 #include <kernel/log.hpp>
21 #include <kernel/x86/vbe.hpp>
22 #include <kernel/context.hpp>
23 #include <kernel/x86/arch.hpp>
24 #include <kernel/x86/v86.hpp>
25 using namespace std;
26 using namespace kernel;
28 #ifdef _LIGHTOS_V86
30 vbe *vbe::inst = 0;
32 vbe::vbe()
34 KERNEL_CONTEXT_START;
36 major = 0;
37 minor = 0;
39 infoBlock *info = (infoBlock*)0x200;
40 info->signature[0] = 'V';
41 info->signature[1] = 'B';
42 info->signature[2] = 'E';
43 info->signature[3] = '2';
45 v86 &v = v86::instance();
47 if (v.int86(0x10, 0x4F00, 0, 0, 0, 0, 0, 0x200, 0) == false)
49 ERROR("VBE: Virtual-8086-mode call failed" << endl);
50 return;
53 state86 State = v.get_state();
54 if (State.eax != 0x4F)
56 ERROR("VBE: not supported (" << hex << "0x" << State.eax << ")" << endl);
57 return;
60 // Save the information
61 major = info->version >> 8;
62 minor = info->version & 0xFF;
63 videoMemory = info->totalMemory * 64 * 1024;
65 oemName = (char*)(((info->oemName >> 12) & 0xFFFF0) + (info->oemName & 0xFFFF));
66 vendorName = (char*)(((info->oemVendorName >> 12) & 0xFFFF0) + (info->oemVendorName & 0xFFFF));
67 productName = (char*)(((info->oemProductName >> 12) & 0xFFFF0) + (info->oemProductName & 0xFFFF));
68 productRevision = (char*)(((info->oemProductRevision >> 12) & 0xFFFF0) + (info->oemProductRevision & 0xFFFF));
70 modeInfo *ModeInfo = (modeInfo*)0x500;
71 unsigned short *videoMode = (unsigned short*)(((info->videoMode >> 12) & 0xFFFF0) + (info->videoMode & 0xFFFF));
73 // Save the list of video modes
74 for (;*videoMode != 0xFFFF;*videoMode++)
76 if (v.int86(0x10, 0x4F01, 0, *videoMode, 0, 0, 0, 0x500, 0) == false)
78 ERROR("VBE: Virtual-8086-mode call failed" << endl);
79 return;
82 // Skip not supported modes
83 if ((ModeInfo->attributes & 0x80) == 0 ||
84 ModeInfo->xResolution < 800 ||
85 ModeInfo->yResolution < 600)continue;
86 if (ModeInfo->bitsPerPixel != 16 &&
87 ModeInfo->bitsPerPixel != 32)continue;
89 // Save in the list of video modes
90 modeInfo *p = new modeInfo;
91 memcpy(p, ModeInfo, sizeof(modeInfo));
92 modes.push_back(*videoMode);
93 modesInfo.push_back(p);
95 KERNEL_CONTEXT_END;
98 bool vbe::getModeInfo(unsigned int index, videoMode &mode) const
100 if (index >= modes.size())return false;
102 modeInfo *Info = modesInfo[index];
103 mode.width = Info->xResolution;
104 mode.height = Info->yResolution;
105 mode.bpp = Info->bitsPerPixel;
106 mode.framebuffer = (void*)Info->physicalBase;
107 return true;
110 bool vbe::setMode(unsigned int index)
112 if (index >= modes.size())return false;
114 unsigned short mode = modes[index];
115 v86 &v = v86::instance();
116 if (v.int86(0x10, 0x4F02, (mode & 0x1FF) | 0x4000, 0, 0, 0, 0, 0x200, 0) == false)return false;
118 return true;
121 vbe::~vbe()
125 #endif