Skip to content

Commit 528f648

Browse files
authored
Modernise the serial class (#423)
1 parent 413b7a5 commit 528f648

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

serial.js

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
11
"use strict";
22

3-
export function Serial(acia) {
4-
const self = this;
3+
const table = [19200, 9600, 4800, 2400, 1200, 300, 150, 75];
54

6-
function reset() {
7-
self.reg = 0;
8-
self.transmitRate = 0;
9-
self.receiveRate = 0;
5+
export class Serial {
6+
constructor(acia) {
7+
this.acia = acia;
8+
this.reset();
109
}
1110

12-
const table = [19200, 9600, 4800, 2400, 1200, 300, 150, 75];
11+
reset() {
12+
this.reg = 0;
13+
this.transmitRate = 0;
14+
this.receiveRate = 0;
15+
}
1316

14-
function write(addr, val) {
17+
write(addr, val) {
1518
val &= 0xff;
16-
self.reg = val;
17-
self.transmitRate = val & 0x07;
18-
self.receiveRate = (val >>> 3) & 0x07;
19-
acia.setSerialReceive(table[self.receiveRate]);
20-
acia.setMotor(!!(val & 0x80));
21-
acia.selectRs423(!!(val & 0x40));
19+
this.reg = val;
20+
this.transmitRate = val & 0x07;
21+
this.receiveRate = (val >>> 3) & 0x07;
22+
this.acia.setSerialReceive(table[this.receiveRate]);
23+
this.acia.setMotor(!!(val & 0x80));
24+
this.acia.selectRs423(!!(val & 0x40));
2225
}
2326

24-
function read() {
25-
write(0, 0xfe);
27+
read() {
28+
this.write(0, 0xfe);
2629
return 0;
2730
}
28-
29-
self.reset = reset;
30-
self.write = write;
31-
self.read = read;
32-
33-
reset();
3431
}

0 commit comments

Comments
 (0)