This repository was archived by the owner on Jul 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathindex.js
More file actions
68 lines (64 loc) · 2.12 KB
/
index.js
File metadata and controls
68 lines (64 loc) · 2.12 KB
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
'use strict';
const { ioPort } = require('../../core/driver-utils');
const constants = require('./constants');
const vbeDispiIoportIndex = ioPort(constants.VBE_DISPI_IOPORT_INDEX);
const vbeDispiIoportData = ioPort(constants.VBE_DISPI_IOPORT_DATA);
function writeBgaRegister(index, data) {
vbeDispiIoportIndex.write16(index >>> 0);
vbeDispiIoportData.write16(data >>> 0);
}
function readBgaRegister(index) {
vbeDispiIoportIndex.write16(index >>> 0);
return vbeDispiIoportData.read16();
}
function bgaAvailable() {
const bgaVersion = readBgaRegister(constants.VBE_DISPI_INDEX_ID);
for (const i of [0, 1, 2, 3, 4, 5]) {
if (bgaVersion === constants[`VBE_DISPI_ID${i}`]) {
return true;
}
}
return false;
}
if (bgaAvailable()) {
const driver = {
init(device) {
const buf = new Uint8Array(device.bars[0].resource.buffer());
const renderer = new runtime.graphics.GraphicsRenderer('bga');
renderer.onenablegraphics = (width, height, bitDepth) => {
writeBgaRegister(constants.VBE_DISPI_INDEX_ENABLE, constants.VBE_DISPI_DISABLED);
writeBgaRegister(constants.VBE_DISPI_INDEX_XRES, width);
writeBgaRegister(constants.VBE_DISPI_INDEX_YRES, height);
writeBgaRegister(constants.VBE_DISPI_INDEX_BPP, bitDepth);
writeBgaRegister(constants.VBE_DISPI_INDEX_ENABLE, constants.VBE_DISPI_ENABLED | constants.VBE_DISPI_LFB_ENABLED);
};
renderer.ongetpixel = (x, y) => {
const where = ((y * runtime.graphics.screen.width) + x) * (runtime.graphics.screen.bitDepth / 8);
return {
get r() {
return buf[where + 2];
},
get g() {
return buf[where + 1];
},
get b() {
return buf[where];
},
set r(val) {
buf[where + 2] = val;
},
set g(val) {
buf[where + 1] = val;
},
set b(val) {
buf[where] = val;
},
};
};
renderer.constants = constants;
runtime.graphics.addRenderer(renderer);
},
reset() {},
};
runtime.pci.addDriver(0x1234, 0x1111, driver);
}