@@ -3,9 +3,11 @@ class Emulator {
33 this . cpu = new CPU ( ) ;
44 this . renderer = new Renderer ( 10 ) ;
55 this . keyboard = new Keyboard ( ) ;
6+ this . sound = new Sound ( ) ;
67
78 this . cpu . renderer = this . renderer ;
89 this . cpu . keyboard = this . keyboard ;
10+ this . cpu . sound = this . sound ;
911
1012 this . registersWidget = new RegistersWidget ( 'registers-container' ) ;
1113 this . memoryWidget = new MemoryWidget ( 'memory-container' ) ;
@@ -34,6 +36,21 @@ class Emulator {
3436 this . cpu . speed = parseInt ( e . target . value ) ;
3537 speedValue . textContent = e . target . value ;
3638 } ) ;
39+
40+ const volumeSlider = document . getElementById ( 'volume-slider' ) ;
41+ const volumeValue = document . getElementById ( 'volume-value' ) ;
42+ volumeSlider . addEventListener ( 'input' , ( e ) => {
43+ const volume = parseInt ( e . target . value ) / 100 ;
44+ this . sound . setVolume ( volume ) ;
45+ volumeValue . textContent = e . target . value ;
46+ } ) ;
47+
48+ const frequencySlider = document . getElementById ( 'frequency-slider' ) ;
49+ const frequencyValue = document . getElementById ( 'frequency-value' ) ;
50+ frequencySlider . addEventListener ( 'input' , ( e ) => {
51+ this . sound . setFrequency ( parseInt ( e . target . value ) ) ;
52+ frequencyValue . textContent = e . target . value ;
53+ } ) ;
3754 }
3855
3956 async loadROMFromSelect ( event ) {
@@ -129,9 +146,11 @@ class Emulator {
129146
130147 reset ( ) {
131148 this . running = false ;
149+ this . sound . stop ( ) ;
132150 this . cpu = new CPU ( ) ;
133151 this . cpu . renderer = this . renderer ;
134152 this . cpu . keyboard = this . keyboard ;
153+ this . cpu . sound = this . sound ;
135154 this . renderer . clear ( ) ;
136155 this . renderer . render ( ) ;
137156 this . updateWidgets ( ) ;
0 commit comments