-
Notifications
You must be signed in to change notification settings - Fork 5
/
clipboard.js
79 lines (75 loc) · 2.58 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
69
70
71
72
73
74
75
76
77
78
79
"use strict";
function ClipboardDevice(pc_emulator, io_port, read_func, write_func, get_boot_time) {
pc_emulator.register_ioport_read(io_port, 16, 4, this.ioport_readl.bind(this));
pc_emulator.register_ioport_write(io_port, 16, 4, this.ioport_writel.bind(this));
pc_emulator.register_ioport_read(io_port + 8, 1, 1, this.ioport_readb.bind(this));
pc_emulator.register_ioport_write(io_port + 8, 1, 1, this.ioport_writeb.bind(this));
this.cur_pos = 0;
this.doc_str = "";
this.read_func = read_func;
this.write_func = write_func;
this.get_boot_time = get_boot_time;
}
ClipboardDevice.prototype.log = function () {
};
ClipboardDevice.prototype.ioport_writeb = function (io_port, byte_value) {
this.doc_str += String.fromCharCode(byte_value);
};
ClipboardDevice.prototype.ioport_readb = function (io_port) {
var doc_str, retval_byte;
doc_str = this.doc_str;
if (this.cur_pos < doc_str.length) {
retval_byte = doc_str.charCodeAt(this.cur_pos) & 0xff;
} else {
retval_byte = 0;
}
this.cur_pos++;
return retval_byte;
};
ClipboardDevice.prototype.ioport_writel = function (io_port, dword_value) {
var text;
io_port = (io_port >> 2) & 3;
switch (io_port) {
case 0:
this.doc_str = this.doc_str.substr(0, dword_value >>> 0);
break;
case 1:
this.cur_pos = dword_value >>> 0;
break;
case 2:
text = String.fromCharCode(dword_value & 0xff) +
String.fromCharCode((dword_value >> 8) & 0xff) +
String.fromCharCode((dword_value >> 16) & 0xff) +
String.fromCharCode((dword_value >> 24) & 0xff);
this.doc_str += text;
break;
case 3:
this.write_func(this.doc_str);
break;
}
};
ClipboardDevice.prototype.ioport_readl = function (io_port) {
var retval_dword;
io_port = (io_port >> 2) & 3;
switch (io_port) {
case 0:
this.doc_str = this.read_func();
return this.doc_str.length >> 0;
case 1:
return this.cur_pos >> 0;
case 2:
retval_dword = this.ioport_readb(0);
retval_dword |= this.ioport_readb(0) << 8;
retval_dword |= this.ioport_readb(0) << 16;
retval_dword |= this.ioport_readb(0) << 24;
return retval_dword;
default:
case 3:
if (this.get_boot_time) {
return this.get_boot_time() >> 0;
} else {
return 0;
}
}
};
self.ClipboardDevice = ClipboardDevice;