@@ -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
150155PS2 . prototype . get_state = function ( )
151156{
0 commit comments