-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVESABIOS.C
108 lines (81 loc) · 2.15 KB
/
VESABIOS.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include "386asm.h"
#include "vesabios.h"
#include "types.h"
bool vesa_getBiosInfo(vesa_BiosInfo *biosInfo) {
vesa_BiosInfo _far *farOut = (vesa_BiosInfo _far *) biosInfo;
u16 result = 0;
if (biosInfo == NULL) {
return false;
}
memset(biosInfo, 0, sizeof(vesa_BiosInfo));
strcpy(biosInfo->signature, "VBE2");
_asm {
les di, farOut
mov ax, 0x4F00
int 0x10
mov result, ax
}
if (result != 0x004F) {
return false;
}
return vesa_isValidVesaBios(biosInfo);
}
bool vesa_isValidVesaBios(const vesa_BiosInfo *biosInfo) {
if (biosInfo == NULL)
return false;
if (biosInfo->modeListPtr == (void _far *) NULL)
return false;
if (biosInfo->version.major == 0 && biosInfo->version.minor == 0)
return false;
if (0 != memcmp(biosInfo->signature, "VESA", 4)) {
return false;
}
return true;
}
size_t vesa_getModeCount(const vesa_BiosInfo *biosInfo) {
size_t count = 0;
if (!vesa_isValidVesaBios(biosInfo)) {
return 0;
}
while (biosInfo->modeListPtr[count] != 0xFFFF) {
count++;
}
return count;
}
bool vesa_getModeInfoByModeId(vesa_ModeInfo *modeInfo, u16 modeId) {
vesa_ModeInfo _far *modeInfoFarPtr = (vesa_ModeInfo _far *) modeInfo;
u16 result = 0;
if (modeInfo == NULL) {
return false;
}
_asm {
les di, modeInfoFarPtr
mov ax, 0x4F01
mov cx, modeId
int 0x10
mov result, ax
}
if (result != 0x004F) {
return false;
}
return true;
}
bool vesa_getModeInfoByIndex(const vesa_BiosInfo *biosInfo, vesa_ModeInfo *modeInfo, size_t index) {
if (modeInfo == NULL || biosInfo == NULL) {
return false;
}
if (index >= vesa_getModeCount(biosInfo)) {
return false;
}
return vesa_getModeInfoByModeId(modeInfo, biosInfo->modeListPtr[index]);
}
u32 vesa_getVRAMSize(const vesa_BiosInfo *biosInfo) {
if (biosInfo == NULL) {
return 0;
}
/* totalMemory is in 64KB blocks. */
return biosInfo->totalMemory * 0x10000UL;
}