-
Notifications
You must be signed in to change notification settings - Fork 5
/
clipboard.js
68 lines (68 loc) · 2.13 KB
/
clipboard.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
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
/*
add by hao :
clipboard.js 是剪切板交互io的核心代码,对应设备/dev/clipboard
*/
function clipboard_device(Ng, Zf, rh, lh, sh) {
Ng.register_ioport_read(Zf, 16, 4, this.ioport_readl.bind(this));
Ng.register_ioport_write(Zf, 16, 4, this.ioport_writel.bind(this));
Ng.register_ioport_read(Zf + 8, 1, 1, this.ioport_readb.bind(this));
Ng.register_ioport_write(Zf + 8, 1, 1, this.ioport_writeb.bind(this));
this.cur_pos = 0;
this.doc_str = "";
this.read_func = rh;
this.write_func = lh;
this.get_boot_time = sh;
}
clipboard_device.prototype.ioport_writeb = function(mem8_loc, x) {
this.doc_str += String.fromCharCode(x);
};
clipboard_device.prototype.ioport_readb = function(mem8_loc) {
var c, na, x;
na = this.doc_str;
if (this.cur_pos < na.length) {
x = na.charCodeAt(this.cur_pos) & 0xff;
} else {
x = 0;
}
this.cur_pos++;
return x;
};
clipboard_device.prototype.ioport_writel = function(mem8_loc, x) {
var na;
mem8_loc = (mem8_loc >> 2) & 3;
switch (mem8_loc) {
case 0:
this.doc_str = this.doc_str.substr(0, x >>> 0);
break;
case 1:
return this.cur_pos = x >>> 0;
case 2:
na = String.fromCharCode(x & 0xff) + String.fromCharCode((x >> 8) & 0xff) + String.fromCharCode((x >> 16) & 0xff) + String.fromCharCode((x >> 24) & 0xff);
this.doc_str += na;
break;
case 3:
this.write_func(this.doc_str);
}
};
clipboard_device.prototype.ioport_readl = function(mem8_loc) {
var x;
mem8_loc = (mem8_loc >> 2) & 3;
switch (mem8_loc) {
case 0:
this.doc_str = this.read_func();
return this.doc_str.length >> 0;
case 1:
return this.cur_pos >> 0;
case 2:
x = this.ioport_readb(0);
x |= this.ioport_readb(0) << 8;
x |= this.ioport_readb(0) << 16;
x |= this.ioport_readb(0) << 24;
return x;
case 3:
if (this.get_boot_time)
return this.get_boot_time() >> 0;
else
return 0;
}
};