-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreen-device.js
43 lines (35 loc) · 1.01 KB
/
screen-device.js
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
const eraseScreen = () => {
process.stdout.write('\x1b[2J');
}
const moveTo = (x, y) => {
process.stdout.write(`\x1b[${y};${x}H`);
}
const setBold = () => {
process.stdout.write('\x1b[1m');
}
const setRegular = () => {
process.stdout.write('\x1b[0m');
}
const createScreenDevice = () => {
return {
getUint8: () => 0,
getUint16: () => 0,
setUint16: (address, data) => {
const characterValue = data & 0x00ff;
const character = String.fromCharCode(characterValue);
const command = (data & 0xff00) >> 8;
if(command === 0xff) {
eraseScreen();
} else if(command === 0x01) {
setBold();
} else if(command === 0x02) {
setRegular();
}
const x = (address % 16) + 1;
const y = Math.floor(address / 16) + 1;
moveTo(x, y);
process.stdout.write(character);
}
}
};
module.exports = createScreenDevice;