Skip to content

Commit ed0ed07

Browse files
authored
Reset PS/2 runtime state when soft-resetting CPU (copy#1301)
- Moved assignment of all member variables from constructor to new method PS2.reset(). - Added call to PS2.reset() in PS2 constructor.
1 parent a921961 commit ed0ed07

File tree

2 files changed

+39
-30
lines changed

2 files changed

+39
-30
lines changed

src/cpu.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,10 @@ CPU.prototype.reboot_internal = function()
741741
{
742742
this.devices.virtio_net.reset();
743743
}
744+
if(this.devices.ps2)
745+
{
746+
this.devices.ps2.reset();
747+
}
744748

745749
this.load_bios();
746750
};

src/ps2.js

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,40 @@ export function PS2(cpu, bus)
2525
/** @const @type {BusConnector} */
2626
this.bus = bus;
2727

28+
this.reset();
29+
30+
this.bus.register("keyboard-code", function(code)
31+
{
32+
this.kbd_send_code(code);
33+
}, this);
34+
35+
this.bus.register("mouse-click", function(data)
36+
{
37+
this.mouse_send_click(data[0], data[1], data[2]);
38+
}, this);
39+
40+
this.bus.register("mouse-delta", function(data)
41+
{
42+
this.mouse_send_delta(data[0], data[1]);
43+
}, this);
44+
45+
this.bus.register("mouse-wheel", function(data)
46+
{
47+
this.wheel_movement -= data[0];
48+
this.wheel_movement -= data[1] * 2; // X Wheel Movement
49+
this.wheel_movement = Math.min(7, Math.max(-8, this.wheel_movement));
50+
this.send_mouse_packet(0, 0);
51+
}, this);
52+
53+
cpu.io.register_read(0x60, this, this.port60_read);
54+
cpu.io.register_read(0x64, this, this.port64_read);
55+
56+
cpu.io.register_write(0x60, this, this.port60_write);
57+
cpu.io.register_write(0x64, this, this.port64_write);
58+
}
59+
60+
PS2.prototype.reset = function()
61+
{
2862
/** @type {boolean} */
2963
this.enable_mouse_stream = false;
3064

@@ -110,42 +144,13 @@ export function PS2(cpu, bus)
110144
/** @type {boolean} */
111145
this.next_byte_is_aux = false;
112146

113-
this.bus.register("keyboard-code", function(code)
114-
{
115-
this.kbd_send_code(code);
116-
}, this);
117-
118-
this.bus.register("mouse-click", function(data)
119-
{
120-
this.mouse_send_click(data[0], data[1], data[2]);
121-
}, this);
122-
123-
this.bus.register("mouse-delta", function(data)
124-
{
125-
this.mouse_send_delta(data[0], data[1]);
126-
}, this);
127-
128-
this.bus.register("mouse-wheel", function(data)
129-
{
130-
this.wheel_movement -= data[0];
131-
this.wheel_movement -= data[1] * 2; // X Wheel Movement
132-
this.wheel_movement = Math.min(7, Math.max(-8, this.wheel_movement));
133-
this.send_mouse_packet(0, 0);
134-
}, this);
135-
136147
this.command_register = 1 | 4;
137148
// TODO: What should be the initial value?
138149
this.controller_output_port = 0;
139150
this.read_output_register = false;
140151
this.read_command_register = false;
141152
this.read_controller_output_port = false;
142-
143-
cpu.io.register_read(0x60, this, this.port60_read);
144-
cpu.io.register_read(0x64, this, this.port64_read);
145-
146-
cpu.io.register_write(0x60, this, this.port60_write);
147-
cpu.io.register_write(0x64, this, this.port64_write);
148-
}
153+
};
149154

150155
PS2.prototype.get_state = function()
151156
{

0 commit comments

Comments
 (0)