-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathApu.js
1450 lines (1131 loc) · 27.9 KB
/
Apu.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import {Register8bit} from './Register.js';
/**
* RP2A03(NTSC)
* Audio Processing Unit implementation. Consists of
* - Pulse 1/2 channel
* - Triangle channel
* - Noise channel
* - DMC channel
*
* Refer to https://wiki.nesdev.com/w/index.php/APU
*/
function Apu() {
// other devices
this.cpu = null; // set by .setCpu()
//
this.audio = null; // set by .setAudio()
// APU units, CPU memory address mapped registers
this.pulse1 = new ApuPulse(true); // 0x4000 - 0x4003
this.pulse2 = new ApuPulse(false); // 0x4004 - 0x4007
this.triangle = new ApuTriangle(); // 0x4008 - 0x400B
this.noise = new ApuNoise(); // 0x400C - 0x400F
this.dmc = new ApuDmc(this); // 0x4010 - 0x4013
this.status = new ApuStatusRegister(); // 0x4015
this.frame = new ApuFrameRegister(); // 0x4017
//
this.cycle = 0;
this.step = 0;
this.samplePeriod = 0; // set by .setAudio()
//
this.frameIrqActive = false;
this.dmcIrqActive = false;
}
Object.assign(Apu.prototype, {
isApu: true,
// public methods
/**
*
*/
setCpu: function(cpu) {
this.cpu = cpu;
},
/**
*
*/
setAudio: function(audio) {
this.audio = audio;
// CPU clock frequency 1.789773 MHz
this.samplePeriod = (1789773 / this.audio.getSampleRate()) | 0;
},
/**
*
*/
bootup: function() {
this.status.store(0x00);
},
/**
*
*/
reset: function() {
},
/**
* Expects being called with CPU clock
*/
runCycle: function() {
this.cycle++;
// Sampling at sample rate timing
// @TODO: Fix me, more precise timing
if((this.cycle % this.samplePeriod) === 0)
this.sample();
// Timers
// Clocked on every CPU cycles for triangle and 2CPU cycles for others
if((this.cycle % 2) === 0) {
this.pulse1.driveTimer();
this.pulse2.driveTimer();
this.noise.driveTimer();
this.dmc.driveTimer();
}
this.triangle.driveTimer();
// 240Hz Frame sequencer
// @TODO: Fix me, more precise timing
if((this.cycle % 7457) === 0) {
if(this.frame.isFiveStepMode() === true) {
// Five-step sequence
//
// 0 1 2 3 4 function
// ----------- -----------------------------
// - - - - - IRQ (if bit 6 is clear)
// l - l - - Length counter and sweep
// e e e e - Envelope and linear counter
if(this.step < 4) {
this.pulse1.driveEnvelope();
this.pulse2.driveEnvelope();
this.triangle.driveLinear();
this.noise.driveEnvelope();
}
if(this.step === 0 || this.step === 2) {
this.pulse1.driveLength();
this.pulse1.driveSweep();
this.pulse2.driveLength();
this.pulse2.driveSweep();
this.triangle.driveLength();
this.noise.driveLength();
}
this.step = (this.step + 1) % 5;
} else {
// Four-step sequence
//
// 0 1 2 3 function
// --------- -----------------------------
// - - - f IRQ (if bit 6 is clear)
// - l - l Length counter and sweep
// e e e e Envelope and linear counter
this.pulse1.driveEnvelope();
this.pulse2.driveEnvelope();
this.triangle.driveLinear();
this.noise.driveEnvelope();
if(this.step === 1 || this.step === 3) {
this.pulse1.driveLength();
this.pulse1.driveSweep();
this.pulse2.driveLength();
this.pulse2.driveSweep();
this.triangle.driveLength();
this.noise.driveLength();
}
if(this.step === 3 && this.frame.disabledIrq() === false)
this.frameIrqActive = true;
// Seems like keep invoking IRQ once frame IRQ flag is on
// until IRQ flag is cleared or it's disabled...?
// @TODO: check sending IRQ timing
if(this.frameIrqActive === true && this.frame.disabledIrq() === false)
this.cpu.interrupt(this.cpu.INTERRUPTS.IRQ);
this.step = (this.step + 1) % 4;
}
// @TODO: check sending IRQ timing
if(this.dmcIrqActive === true)
this.cpu.interrupt(this.cpu.INTERRUPTS.IRQ);
}
},
// load/store CPU memory address mapped register methods called by CPU
/**
*
*/
loadRegister: function(address) {
switch(address) {
case 0x4015:
// Loading status register
//
// bit
// 7: DMC interrupt
// 6: Frame interrupt
// 4: DMC remaining bytes > 0
// 3: Noise length counter > 0
// 2: Triangle length couter > 0
// 1: Pulse2 length counter > 0
// 0: Pulse1 length counter > 0
var value = 0;
value |= (this.dmcIrqActive === true ? 1 : 0) << 7;
value |= (this.frameIrqActive === true &&
this.frame.disabledIrq() === false ? 1 : 0) << 6;
value |= (this.dmc.remainingBytes > 0 ? 1 : 0) << 4;
value |= (this.noise.lengthCounter > 0 ? 1 : 0) << 3;
value |= (this.triangle.lengthCounter > 0 ? 1 : 0) << 2;
value |= (this.pulse2.lengthCounter > 0 ? 1 : 0) << 1;
value |= (this.pulse1.lengthCounter > 0 ? 1 : 0) << 0;
// Loading status register clears the frame IRQ flag
this.frameIrqActive = false;
return value;
}
return 0;
},
/**
*
*/
storeRegister: function(address, value) {
switch(address) {
case 0x4000:
case 0x4001:
case 0x4002:
case 0x4003:
this.pulse1.storeRegister(address, value);
break;
case 0x4004:
case 0x4005:
case 0x4006:
case 0x4007:
this.pulse2.storeRegister(address, value);
break;
case 0x4008:
case 0x4009:
case 0x400A:
case 0x400B:
this.triangle.storeRegister(address, value);
break;
case 0x400C:
case 0x400D:
case 0x400E:
case 0x400F:
this.noise.storeRegister(address, value);
break;
case 0x4010:
case 0x4011:
case 0x4012:
case 0x4013:
this.dmc.storeRegister(address, value);
break;
case 0x4015:
// Storing status register
//
// bit: Enable(1) / Disable(0)
// 4: DMC unit
// 3: Noise unit
// 2: Triangle unit
// 1: Pulse2 unit
// 0: Pulse1 unit
//
// Writing a zero to any of channel enables bits will
// set its length counter/remaining bytes to zero.
this.status.store(value);
this.dmc.setEnable((value & 0x10) === 0x10);
this.noise.setEnable((value & 0x8) === 0x8);
this.triangle.setEnable((value & 0x4) === 0x4);
this.pulse2.setEnable((value & 0x2) === 0x2);
this.pulse1.setEnable((value & 0x1) === 0x1);
// Storing status register clears the DMC interrupt flag
this.dmcIrqActive = false;
break;
case 0x4017:
// Storing frame counter register
this.frame.store(value);
// If interrupt inhibit flag is set, the frame IRQ flag is cleared.
if(this.frame.disabledIrq() === true)
this.frameIrqActive = false;
break;
}
},
// private method
/**
*
*/
sample: function() {
// Calculates the audio output within the range of 0.0 to 1.0.
// Refer to https://wiki.nesdev.com/w/index.php/APU_Mixer
var pulse1 = this.pulse1.output();
var pulse2 = this.pulse2.output();
var triangle = this.triangle.output();
var noise = this.noise.output();
var dmc = this.dmc.output();
var pulseOut = 0;
var tndOut = 0;
if(pulse1 !== 0 || pulse2 !== 0)
pulseOut = 95.88 / ((8128 / (pulse1 + pulse2)) + 100);
if(triangle !== 0 || noise !== 0 || dmc !== 0)
tndOut = 159.79 / (1 / (triangle / 8227 + noise / 12241 + dmc / 22638) + 100);
this.audio.push(pulseOut + tndOut);
},
// dump
/**
*
*/
dump: function() {
}
});
/**
*
*/
function ApuUnit(apu) {
this.apu = apu;
}
// Refer to https://wiki.nesdev.com/w/index.php/APU_Length_Counter
ApuUnit.LENGTH_TABLE = [
0x0A, 0xFE, 0x14, 0x02, 0x28, 0x04, 0x50, 0x06,
0xA0, 0x08, 0x3C, 0x0A, 0x0E, 0x0C, 0x1A, 0x0E,
0x0C, 0x10, 0x18, 0x12, 0x30, 0x14, 0x60, 0x16,
0xC0, 0x18, 0x48, 0x1A, 0x10, 0x1C, 0x20, 0x1E
];
/**
* Apu Pulse channel. Consists of
* - Timer
* - Length counter
* - Envelope
* - Sweep
*/
function ApuPulse(isChannel1) {
this.isChannel1 = isChannel1;
// CPU memory address mapped registers
// 0x4000 / 0x4004
//
// bit:
// 7-6: Duty cycle
// 5: Length counter halt
// 4: Enable envelope
// 3-0: Envelope divider period
// 0x4001 / 0x4005
//
// bit:
// 7: Enable sweep
// 6-4: Period
// 3: Negate
// 2-0: Shift amount per period
// 0x4002 / 0x4006
//
// bit:
// 7-0: Timer low 8-bit
// 0x4003 / 0x4007
//
// bit:
// 7-3: Length counter index
// 2-0: Timer high 3-bit
this.register0 = new Register8bit(); // 0x4000 / 0x4004
this.register1 = new Register8bit(); // 0x4001 / 0x4005
this.register2 = new Register8bit(); // 0x4002 / 0x4006
this.register3 = new Register8bit(); // 0x4003 / 0x4007
//
this.enabled = false;
//
this.timerCounter = 0;
this.timerPeriod = 0;
this.timerSequence = 0;
this.envelopeStartFlag = true;
this.envelopeCounter = 0;
this.envelopeDecayLevelCounter = 0;
this.lengthCounter = 0;
this.sweepReloadFlag = false;
this.sweepCycle = 0;
this.sweepCounter = 0;
}
Object.assign(ApuPulse.prototype, {
isApuPulse: true,
//
LENGTH_TABLE: ApuUnit.LENGTH_TABLE,
DUTY_TABLE: [
[0, 1, 0, 0, 0, 0, 0, 0],
[0, 1, 1, 0, 0, 0, 0, 0],
[0, 1, 1, 1, 1, 0, 0, 0],
[1, 0, 0, 1, 1, 1, 1, 1],
],
//
/**
*
*/
storeRegister: function(address, value) {
switch(address) {
case 0x4000:
case 0x4004:
this.register0.store(value);
break;
case 0x4001:
case 0x4005:
this.register1.store(value);
// Side effect
// - Sets the sweep reload flag
this.sweepReloadFlag = true;
break;
case 0x4002:
case 0x4006:
this.register2.store(value);
this.timerPeriod = this.getTimer();
break;
case 0x4003:
case 0x4007:
this.register3.store(value);
// Side effects
// - If the enabled flag is set, the length counter is reloaded
// - The envelope is restarted
// - The sequencer is immediately restarted at the first value of the current
// sequence. The period divider is not reset.
if(this.enabled === true)
this.lengthCounter = this.LENGTH_TABLE[this.getLengthCounterIndex()];
this.timerPeriod = this.getTimer();
this.timerSequence = 0;
this.envelopeStartFlag = true;
break;
}
},
//
/**
*
*/
setEnable: function(enabled) {
this.enabled = enabled;
// When the enabled bit is cleared (via $4015), the length counter is forced to 0
if(enabled === false)
this.lengthCounter = 0;
},
/**
*
*/
getDuty: function() {
return this.register0.loadBits(6, 2);
},
/**
*
*/
enabledEnvelopeLoop: function() {
return this.register0.isBitSet(5);
},
/**
*
*/
disabledEnvelope: function() {
return this.register0.isBitSet(4);
},
/**
*
*/
getEnvelopePeriod: function() {
return this.register0.loadBits(0, 4);
},
/**
*
*/
enabledSweep: function() {
return this.register1.isBitSet(7);
},
/**
*
*/
getSweepPeriod: function() {
return this.register1.loadBits(4, 3);
},
/**
*
*/
negatedSweep: function() {
return this.register1.isBitSet(3);
},
/**
*
*/
getSweepShiftAmount: function() {
return this.register1.loadBits(0, 3);
},
/**
*
*/
getTimerLow: function() {
return this.register2.load();
},
/**
*
*/
getTimerHigh: function() {
return this.register3.loadBits(0, 3);
},
/**
*
*/
getTimer: function() {
return ((this.getTimerHigh() << 8) | this.getTimerLow());
},
/**
*
*/
getLengthCounterIndex: function() {
return this.register3.loadBits(3, 5);
},
//
/**
*
*/
driveTimer: function() {
if(this.timerCounter > 0) {
this.timerCounter--;
} else {
this.timerCounter = this.timerPeriod;
this.timerSequence++;
// 8-step sequencer
if(this.timerSequence === 8)
this.timerSequence = 0;
}
},
/**
*
*/
driveLength: function() {
if(this.disabledEnvelope() === false && this.lengthCounter > 0)
this.lengthCounter--;
},
/**
*
*/
driveEnvelope: function() {
if(this.envelopeStartFlag === true) {
this.envelopeCounter = this.getEnvelopePeriod();
this.envelopeDecayLevelCounter = 0xF;
this.envelopeStartFlag = false;
return;
}
if(this.envelopeCounter > 0) {
this.envelopeCounter--;
} else {
this.envelopeCounter = this.getEnvelopePeriod();
if(this.envelopeDecayLevelCounter > 0)
this.envelopeDecayLevelCounter--;
else if(this.envelopeDecayLevelCounter === 0 && this.enabledEnvelopeLoop() === true)
this.envelopeDecayLevelCounter = 0xF;
}
},
/**
*
*/
driveSweep: function() {
if(this.sweepCounter === 0 && this.enabledSweep() === true &&
this.getSweepShiftAmount() !== 0 &&
this.timerPeriod >= 8 && this.timerPeriod <= 0x7FF) {
var change = this.timerPeriod >> this.getSweepShiftAmount();
// In negated mode, Pulse 1 adds the ones' complement while
// Pulse 2 adds the twos' complement
if(this.negatedSweep() === true) {
change = -change;
if(this.isChannel1 === true)
change--;
}
this.timerPeriod += change;
}
if(this.sweepReloadFlag === true || this.sweepCounter === 0) {
this.sweepReloadFlag = false;
this.sweepCounter = this.getSweepPeriod();
} else {
this.sweepCounter--;
}
},
/**
*
*/
output: function() {
if(this.lengthCounter === 0 || this.timerPeriod < 8 || this.timerPeriod > 0x7FF ||
this.DUTY_TABLE[this.getDuty()][this.timerSequence] === 0)
return 0;
// 4-bit output
return (this.disabledEnvelope() === true ? this.getEnvelopePeriod() : this.envelopeDecayLevelCounter) & 0xF;
}
});
/**
* Apu Triangle channel. Consists of
* - Timer
* - Length counter
* - Linear counter
*/
function ApuTriangle() {
// CPU memory address mapped registers
// 0x4008
//
// bit:
// 7: Length counter halt
// 6-0: Linear counter period
// 0x4009
//
// Unused
// 0x400A
//
// bit:
// 7-0: Timer low 8-bit
// 0x400B
//
// bit:
// 7-3: Length counter index
// 2-0: Timer high 3-bit
this.register0 = new Register8bit(); // 0x4008
this.register1 = new Register8bit(); // 0x4009
this.register2 = new Register8bit(); // 0x400A
this.register3 = new Register8bit(); // 0x400B
//
this.enabled = false;
//
this.timerCounter = 0;
this.timerSequence = 0;
this.lengthCounter = 0;
this.linearReloadFlag = false;
this.linearCounter = 0;
}
Object.assign(ApuTriangle.prototype, {
isApuTriangle: true,
//
LENGTH_TABLE: ApuUnit.LENGTH_TABLE,
SEQUENCE_TABLE: [
15, 14, 13, 12, 11, 10, 9, 8,
7, 6, 5, 4, 3, 2, 1, 0,
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15
],
//
/**
*
*/
storeRegister: function(address, value) {
switch(address) {
case 0x4008:
this.register0.store(value);
break;
case 0x4009:
this.register1.store(value);
break;
case 0x400A:
this.register2.store(value);
break;
case 0x400B:
this.register3.store(value);
// Side effects
// - If the enabled flag is set, the length counter is reloaded
// - Sets the linear counter reload flag
// - The sequencer is immediately restarted at the first value of the current
// sequence. The period divider is not reset.
if(this.enabled === true)
this.lengthCounter = this.LENGTH_TABLE[this.getLengthCounterIndex()];
this.timerSequence = 0;
this.linearReloadFlag = true;
break;
}
},
//
/**
*
*/
setEnable: function(enabled) {
this.enabled = enabled;
// When the enabled bit is cleared (via $4015), the length counter is forced to 0
if(enabled === false)
this.lengthCounter = 0;
},
/**
*
*/
getLinearCounter: function() {
return this.register0.loadBits(0, 7);
},
/**
*
*/
disabledLengthCounter: function() {
return this.register0.isBitSet(7);
},
/**
*
*/
getLengthCounterIndex: function() {
return this.register3.loadBits(3, 5);
},
/**
*
*/
getTimerLow: function() {
return this.register2.load();
},
/**
*
*/
getTimerHigh: function() {
return this.register3.loadBits(0, 3);
},
/**
*
*/
getTimer: function() {
return (this.getTimerHigh() << 8) | this.getTimerLow();
},
//
/**
*
*/
driveTimer: function() {
if(this.timerCounter > 0) {
this.timerCounter--;
} else {
this.timerCounter = this.getTimer();
// The sequencer is clocked by the timer as long as
// both the linear counter and the length counter are nonzero.
if(this.lengthCounter > 0 && this.linearCounter > 0) {
this.timerSequence++;
// 32-step sequencer
if(this.timerSequence === 32)
this.timerSequence = 0;
}
}
},
/**
*
*/
driveLinear: function() {
if(this.linearReloadFlag === true)
this.linearCounter = this.getLinearCounter();
else if(this.linearCounter > 0)
this.linearCounter--;
if(this.disabledLengthCounter() === false)
this.linearReloadFlag = false;
},
/**
*
*/
driveLength: function() {
if(this.disabledLengthCounter() === false && this.lengthCounter > 0)
this.lengthCounter--;
},
/**
*
*/
output: function() {
if(this.enabled === false || this.lengthCounter === 0 ||
this.linearCounter === 0 || this.getTimer() < 2)
return 0;
// 4-bit output
return this.SEQUENCE_TABLE[this.timerSequence] & 0xF;
}
});
/**
* Apu Noise channel. Consists of
* - Timer
* - Length counter
* - Envelope
* - Linear feedback shift register
*/
function ApuNoise() {
// CPU memory address mapped registers
// 0x400C
//
// bit:
// 5: Length counter halt
// 4: Disable envelope
// 3-0: Envelope
// 0x400D
//
// Unused
// 0x400E
//
// bit:
// 7: Loop noise
// 3-0: Noise period
// 0x400F
//
// bit:
// 7-3: Length counter index
this.register0 = new Register8bit(); // 0x400C
this.register1 = new Register8bit(); // 0x400D
this.register2 = new Register8bit(); // 0x400E
this.register3 = new Register8bit(); // 0x400F
//
this.enabled = false;
//
this.timerCounter = 0;
this.timerPeriod = 0;
this.envelopeStartFlag = false;
this.envelopeCounter = 0;
this.envelopeDecayLevelCounter = 0;
this.lengthCounter = 0;
this.shiftRegister = 1; // 15-bit register
}
Object.assign(ApuNoise.prototype, {
isApuNoise: true,
//
LENGTH_TABLE: ApuUnit.LENGTH_TABLE,
TIMER_TABLE: [
0x004, 0x008, 0x010, 0x020,
0x040, 0x060, 0x080, 0x0A0,
0x0CA, 0x0FE, 0x17C, 0x1FC,
0x2FA, 0x3F8, 0x7F2, 0xFE4
],
//
/**
*
*/
storeRegister: function(address, value) {
switch(address) {
case 0x400C:
this.register0.store(value);
break;
case 0x400D:
this.register1.store(value);
break;
case 0x400E:
this.register2.store(value);
this.timerPeriod = this.TIMER_TABLE[this.getTimerIndex()]
break;
case 0x400F:
this.register3.store(value);
// Side effects
// - If the enabled flag is set, the length counter is reloaded
// - The envelope is restarted