forked from premmore388/More-s-OS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
78 lines (66 loc) · 1.57 KB
/
Copy pathmain.js
File metadata and controls
78 lines (66 loc) · 1.57 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
69
70
71
72
73
74
75
76
77
78
import { writeFile } from 'node:fs/promises';
let ctors;
let rev;
let combine;
let save2file;
let message;
message = 'Hello from More !';
save2file = async (msg, filename) => {
const buf = mkos(msg);
await writeFile(filename, buf, { encoding: 'binary' });
return true;
};
combine = (a, b) =>
((a & 0xff) << 8)
| (b & 0xff);
rev = val => {
const a = val & 0xff;
const b = (val & 0xff00) >> 8;
return String.fromCharCode(a) + String.fromCharCode(b);
};
ctors = {
copy2ax: val => "\xb8" + rev(val),
copy2bx: val => "\xbb" + rev(val),
copy2cx: val => "\xb9" + rev(val),
copy2sp: () => "\x89\xc4",
biosinterrupt: () => "\xcd\x10",
interruptoff: () => "\xfa",
halt: () => "\x90\xf4",
jmp: () => "\xeb\xfc",
padding: amt => "\x90".repeat(amt),
magic: () => rev(0xaa55),
print: str => str
.concat('\r\n')
.split('')
.map(x => ctors.copy2ax(combine(0x0e, x.charCodeAt(0)))
.concat(ctors.biosinterrupt()))
.join('')
};
let mkos;
let part1;
let part2;
let exitval;
let file;
mkos = msg =>
part1(msg)
+ part2(510 - part1(msg).length);
part1 = msg =>
ctors.copy2ax(0xfbff)
+ ctors.copy2sp()
+ ctors.copy2bx(0x0000)
+ ctors.print(msg)
+ ctors.halt()
+ ctors.jmp();
part2 = amt =>
ctors.padding(amt)
+ ctors.magic();
file = process.argv[2];
if (!file) {
console.error('Usage: ' + process.argv[1], '<filename>');
process.exit(1);
}
exitval = await save2file(message, file);
if (exitval)
console.log('ok');
else
console.error('failed');