/
swp00.cpp
1846 lines (1521 loc) · 57.7 KB
/
swp00.cpp
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
// license:BSD-3-Clause
// copyright-holders:Olivier Galibert
// Yamaha SWP00, rompler/dsp combo
#include "emu.h"
#include "swp00.h"
/*
Used in the MU50, the SWP00 is the combination of a rompler called
AWM2 (Advanced Wave Memory 2) and an effects DSP called MEG
(Multiple Effects Generator). It is the simpler variant of those, a
simplification and integration of the SWP20/SWD/MEG/EQ combo use in
the MU80.
Its clock is 33.9MHz and the output is at 44100Hz stereo (768 cycles
per sample pair) per dac output.
AWM2:
The AWM2 is in charge of handling the individual channels. It
manages reading the rom, decoding the samples, applying volume and
envelopes and lfos and filtering the result. The channels are
volume-modulated and summed into 7 outputs which are then processed
by the MEG.
As all the SWPs, the sound data can be four formats (8 bits, 12
bits, 16 bits, and a 8-bits log format with roughly 10 bits of
dynamic). It's interesting to note that the 8-bits format is not
used by the MU50. The rom bus is 24 bits address and 8 bits data
wide. It applies a single, Chamberlin-configuration LPF to the
sample data. Envelopes are handled semi-automatically, and the
final result volume-modulated (global volume, pan, tremolo, dispatch
in dry/reverb/chorus/variation) in 7 output channels.
MEG:
The MEG in this case is an internal DSP with a fixed program in four
selectable variants. It has 192 steps of program, and can issue a
memory access to the effects DRAM every 3 cycles. The programs are
internal and as far as we know not dumpable. We managed a
reimplementation though.
The program does the effects "reverb", "chorus" and "variation" and
mixing between all those. The four variants only in practice impact
the variation segment, in addresses 109-191 roughly.
Each instruction is associated with a dynamically changeable 10-bit
constant used as a fixed point value (either 1.9 or 3.7 depending on
the instruction). Every third instruction (pc multiple of 3) is
also associated with a 16-bits offset for the potential memory
access.
Interface:
The interface is 8-bits wide but would have wanted to be 16-bits, with
11 address bits. There are three address formats depending on the
part of the chip one speaks to:
000 0sss ssss Global controls
001 1ppp pppl MEG, offsets (16-bits values, l=high/low byte, pc 00-bd, divided by 3)
01p pppp pppl MEG, constants (16-bits values, l=high/low byte, pc 00-bf)
sss sscc cccs AWM2, channel/slot combination (slot = 8-b and 20-37)
*/
DEFINE_DEVICE_TYPE(SWP00, swp00_device, "swp00", "Yamaha SWP00 (TC170C120SF / XQ036A00) sound chip")
swp00_device::swp00_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: device_t(mconfig, SWP00, tag, owner, clock),
device_sound_interface(mconfig, *this),
device_rom_interface(mconfig, *this)
{
}
void swp00_device::device_add_mconfig(machine_config &config)
{
}
const std::array<u32, 4> swp00_device::lfo_shape_centered_saw = { 0x00000000, 0x00000000, 0xfff00000, 0xfff00000 }; // --////--
const std::array<u32, 4> swp00_device::lfo_shape_centered_tri = { 0x00000000, 0x0007ffff, 0xfff7ffff, 0xfff00000 }; // --/\/\--
const std::array<u32, 4> swp00_device::lfo_shape_offset_saw = { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }; // __////__
const std::array<u32, 4> swp00_device::lfo_shape_offset_tri = { 0x00000000, 0x00000000, 0x000fffff, 0x000fffff }; // __/\/\__
const std::array<s32, 16> swp00_device::panmap = {
0x000, 0x040, 0x080, 0x0c0,
0x100, 0x140, 0x180, 0x1c0,
0x200, 0x240, 0x280, 0x2c0,
0x300, 0x340, 0x380, 0xfff
};
const std::array<u8, 4> swp00_device::dpcm_offset = { 7, 6, 4, 0 };
bool swp00_device::istep(s32 &value, s32 limit, s32 step)
{
// fprintf(stderr, "istep(%x, %x, %x)\n", value, limit, step);
if(value < limit) {
value += step;
if(value >= limit) {
value = limit;
return true;
}
return false;
}
if(value > limit) {
value -= step;
if(value <= limit) {
value = limit;
return true;
}
return false;
}
return true;
}
s32 swp00_device::fpadd(s32 value, s32 step)
{
s32 e = value >> 24;
s32 m = value & 0xffffff;
m += step << e;
if(m & 0xfe000000)
return 0xfffffff;
while(m & 0x01000000) {
m <<= 1;
e ++;
}
if(e >= 16)
return 0xfffffff;
return (e << 24) | (m & 0xffffff);
}
s32 swp00_device::fpsub(s32 value, s32 step)
{
s32 e = value >> 24;
s32 m = (value & 0xffffff) | 0xfe000000;
m = e < 0xc ? m - (step << e) : (m >> (e - 0xb)) - (step << 0xb);
if(m >= 0)
return 0;
if(e >= 0xc)
e = 0xb;
while(m < 0xfe000000) {
if(!e)
return 0;
e --;
m >>= 1;
}
while(e != 0xf && (m >= 0xff000000)) {
e ++;
m <<= 1;
}
return (e << 24) | (m & 0xffffff);
}
bool swp00_device::fpstep(s32 &value, s32 limit, s32 step)
{
// value, limit and step are 4.24 but step has its exponent and
// top four bits zero
if(value == limit)
return true;
if(value < limit) {
value = fpadd(value, step);
if(value >= limit) {
value = limit;
return true;
}
return false;
}
value = fpsub(value, step);
if(value <= limit) {
value = limit;
return true;
}
return false;
}
// sample is signed 24.8
s32 swp00_device::fpapply(s32 value, s32 sample)
{
if(value >= 0x10000000)
return 0;
return (s64(sample) - ((s64(sample) * ((value >> 9) & 0x7fff)) >> 16)) >> (value >> 24);
}
// sample is signed 24.8
s32 swp00_device::lpffpapply(s32 value, s32 sample)
{
return ((((value >> 7) & 0x7fff) | 0x8000) * s64(sample)) >> (31 - (value >> 22));
}
// Some tables we need. Maybe they're in roms inside the chip,
// maybe they're logic. Probably slightly inexact too, would need
// a complicated hardware setup to really test them.
const std::array<s32, 0x80> swp00_device::attack_linear_step = {
0x00027, 0x0002b, 0x0002f, 0x00033, 0x00037, 0x0003d, 0x00042, 0x00048,
0x0004d, 0x00056, 0x0005e, 0x00066, 0x0006f, 0x0007a, 0x00085, 0x00090,
0x0009b, 0x000ac, 0x000bd, 0x000cc, 0x000de, 0x000f4, 0x00109, 0x00120,
0x00135, 0x00158, 0x00179, 0x00199, 0x001bc, 0x001e7, 0x00214, 0x00240,
0x0026b, 0x002af, 0x002f2, 0x00332, 0x00377, 0x003d0, 0x0042c, 0x00480,
0x004dc, 0x0055e, 0x005e9, 0x0066e, 0x006f4, 0x007a4, 0x00857, 0x0090b,
0x009c3, 0x00acb, 0x00bd6, 0x00ce6, 0x00e00, 0x00f5e, 0x010d2, 0x01234,
0x0139e, 0x015d0, 0x017f3, 0x01a20, 0x01c4a, 0x01f52, 0x02232, 0x0250f,
0x027ff, 0x02c72, 0x03109, 0x0338b, 0x039c4, 0x04038, 0x04648, 0x04c84,
0x05262, 0x05c1c, 0x065af, 0x06f5c, 0x07895, 0x0866f, 0x09470, 0x0a19e,
0x0ae4c, 0x0c566, 0x0db8d, 0x0f00f, 0x10625, 0x12937, 0x14954, 0x16c17,
0x1886e, 0x1c71c, 0x20000, 0x239e1, 0x2647c, 0x2aaab, 0x2ecfc, 0x3241f,
0x35e51, 0x3a83b, 0x40000, 0x4325c, 0x47dc1, 0x4c8f9, 0x50505, 0x55555,
0x58160, 0x5d174, 0x60606, 0x62b2e, 0x67b24, 0x6a63c, 0x6d3a0, 0x6eb3e,
0x71c72, 0x73616, 0x75075, 0x76b98, 0x78788, 0x78788, 0x7a44c, 0x7a44c,
0x7a44c, 0x7a44c, 0x7a44c, 0x7a44c, 0x7a44c, 0x7a44c, 0x7a44c, 0x7a44c,
};
const std::array<s32, 0x20> swp00_device::decay_linear_step = {
0x15083, 0x17ad2, 0x1a41a, 0x1cbe7, 0x1f16d, 0x22ef1, 0x26a44, 0x2a1e4,
0x2da35, 0x34034, 0x3a197, 0x40000, 0x45b82, 0x4b809, 0x51833, 0x57262,
0x5d9f7, 0x6483f, 0x6b15c, 0x71c72, 0x77976, 0x7d119, 0x83127, 0x88889,
0x8d3dd, 0x939a8, 0x991f2, 0x9d89e, 0xa0a0a, 0xa57eb, 0xa72f0, 0xac769,
};
void swp00_device::device_start()
{
m_stream = stream_alloc(0, 2, 44100);
save_item(NAME(m_waverom_access));
save_item(NAME(m_waverom_val));
save_item(NAME(m_meg_control));
save_item(NAME(m_buffer_offset));
save_item(NAME(m_rev_vol));
save_item(NAME(m_cho_vol));
save_item(NAME(m_var_vol));
save_item(NAME(m_var_lfo_phase));
save_item(NAME(m_var_lfo_h_1));
save_item(NAME(m_var_lfo_h_2));
save_item(NAME(m_var_lfo1a));
save_item(NAME(m_var_lfo2a));
save_item(NAME(m_var_lfo3a));
save_item(NAME(m_var_lfo4a));
save_item(NAME(m_var_filter_1));
save_item(NAME(m_var_filter_2));
save_item(NAME(m_var_filter_3));
save_item(NAME(m_var_filter2_1));
save_item(NAME(m_var_filter2_2a));
save_item(NAME(m_var_filter2_2b));
save_item(NAME(m_var_filter2_3a));
save_item(NAME(m_var_filter2_3b));
save_item(NAME(m_var_filter2_4));
save_item(NAME(m_var_filterp_l_1));
save_item(NAME(m_var_filterp_l_2));
save_item(NAME(m_var_filterp_l_3));
save_item(NAME(m_var_filterp_l_4));
save_item(NAME(m_var_filterp_l_5));
save_item(NAME(m_var_filterp_l_6));
save_item(NAME(m_var_filterp_r_1));
save_item(NAME(m_var_filterp_r_2));
save_item(NAME(m_var_filterp_r_3));
save_item(NAME(m_var_filterp_r_4));
save_item(NAME(m_var_filterp_r_5));
save_item(NAME(m_var_filterp_r_6));
save_item(NAME(m_var_filter3_1));
save_item(NAME(m_var_filter3_2));
save_item(NAME(m_var_h1));
save_item(NAME(m_var_h2));
save_item(NAME(m_var_h3));
save_item(NAME(m_var_h4));
save_item(NAME(m_cho_lfo_phase));
save_item(NAME(m_cho_filter_l_1));
save_item(NAME(m_cho_filter_l_2));
save_item(NAME(m_cho_filter_l_3));
save_item(NAME(m_cho_filter_r_1));
save_item(NAME(m_cho_filter_r_2));
save_item(NAME(m_cho_filter_r_3));
save_item(NAME(m_rev_filter_1));
save_item(NAME(m_rev_filter_2));
save_item(NAME(m_rev_filter_3));
save_item(NAME(m_rev_hist_a));
save_item(NAME(m_rev_hist_b));
save_item(NAME(m_rev_hist_c));
save_item(NAME(m_rev_hist_d));
save_item(NAME(m_rev_buffer));
save_item(NAME(m_cho_buffer));
save_item(NAME(m_var_buffer));
save_item(NAME(m_offset));
save_item(NAME(m_const));
save_item(NAME(m_lpf_info));
save_item(NAME(m_lpf_speed));
save_item(NAME(m_lfo_famod_depth));
save_item(NAME(m_rev_level));
save_item(NAME(m_dry_level));
save_item(NAME(m_cho_level));
save_item(NAME(m_var_level));
save_item(NAME(m_glo_level));
save_item(NAME(m_panning));
save_item(NAME(m_attack_speed));
save_item(NAME(m_attack_level));
save_item(NAME(m_decay_speed));
save_item(NAME(m_decay_level));
save_item(NAME(m_pitch));
save_item(NAME(m_sample_start));
save_item(NAME(m_sample_end));
save_item(NAME(m_sample_dpcm_and_format));
save_item(NAME(m_sample_address));
save_item(NAME(m_lfo_step));
save_item(NAME(m_lfo_pmod_depth));
save_item(NAME(m_lfo_phase));
save_item(NAME(m_sample_pos));
save_item(NAME(m_envelope_level));
save_item(NAME(m_glo_level_cur));
save_item(NAME(m_pan_l));
save_item(NAME(m_pan_r));
save_item(NAME(m_lpf_feedback));
save_item(NAME(m_lpf_target_value));
save_item(NAME(m_lpf_value));
save_item(NAME(m_lpf_timer));
save_item(NAME(m_lpf_ha));
save_item(NAME(m_lpf_hb));
save_item(NAME(m_active));
save_item(NAME(m_decay));
save_item(NAME(m_decay_done));
save_item(NAME(m_lpf_done));
save_item(NAME(m_dpcm_current));
save_item(NAME(m_dpcm_next));
save_item(NAME(m_dpcm_address));
save_item(NAME(m_dpcm_sum));
for(int i=0; i != 128; i++) {
u32 v = 0;
switch(i >> 3) {
default: v = ((i & 7) + 8) << (1 + (i >> 3)); break;
case 0xb: v = ((i & 7) + 4) << 13; break;
case 0xc: v = ((i & 6) + 6) << 14; break;
case 0xd: v = ((i & 4) + 7) << 15; break;
case 0xe: v = 15 << 15; break;
case 0xf: v = 31 << 15; break;
}
m_global_step[i] = v;
}
// Delta-packed samples decompression.
for(int i=0; i<128; i++) {
s16 base = ((i & 0x1f) << (3+(i >> 5))) + (((1 << (i >> 5))-1) << 8);
m_dpcm[i | 0x80] = - base;
m_dpcm[i] = + base;
}
}
void swp00_device::device_reset()
{
m_waverom_access = 0;
m_waverom_val = 0;
m_meg_control = 0;
m_buffer_offset = 0;
m_rev_vol = 0;
m_cho_vol = 0;
m_var_vol = 0;
m_var_lfo_phase = 0;
m_var_lfo_h_1 = 0;
m_var_lfo_h_2 = 0;
m_var_lfo1a = 0;
m_var_lfo2a = 0;
m_var_lfo3a = 0;
m_var_lfo4a = 0;
m_var_filter_1 = 0;
m_var_filter_2 = 0;
m_var_filter_3 = 0;
m_var_filter2_1 = 0;
m_var_filter2_2a = 0;
m_var_filter2_2b = 0;
m_var_filter2_3a = 0;
m_var_filter2_3b = 0;
m_var_filter2_4 = 0;
m_var_filter3_1 = 0;
m_var_filter3_2 = 0;
m_var_filterp_l_1 = 0;
m_var_filterp_l_2 = 0;
m_var_filterp_l_3 = 0;
m_var_filterp_l_4 = 0;
m_var_filterp_l_5 = 0;
m_var_filterp_l_6 = 0;
m_var_filterp_r_1 = 0;
m_var_filterp_r_2 = 0;
m_var_filterp_r_3 = 0;
m_var_filterp_r_4 = 0;
m_var_filterp_r_5 = 0;
m_var_filterp_r_6 = 0;
m_var_h1 = 0;
m_var_h2 = 0;
m_var_h3 = 0;
m_var_h4 = 0;
m_cho_lfo_phase = 0;
m_cho_filter_l_1 = 0;
m_cho_filter_l_2 = 0;
m_cho_filter_l_3 = 0;
m_cho_filter_r_1 = 0;
m_cho_filter_r_2 = 0;
m_cho_filter_r_3 = 0;
m_rev_filter_1 = 0;
m_rev_filter_2 = 0;
m_rev_filter_3 = 0;
m_rev_hist_a = 0;
m_rev_hist_b = 0;
m_rev_hist_c = 0;
m_rev_hist_d = 0;
std::fill(m_rev_buffer.begin(), m_rev_buffer.end(), 0);
std::fill(m_cho_buffer.begin(), m_cho_buffer.end(), 0);
std::fill(m_var_buffer.begin(), m_var_buffer.end(), 0);
std::fill(m_offset.begin(), m_offset.end(), 0);
std::fill(m_const.begin(), m_const.end(), 0);
std::fill(m_lpf_info.begin(), m_lpf_info.end(), 0);
std::fill(m_lpf_speed.begin(), m_lpf_speed.end(), 0);
std::fill(m_lfo_famod_depth.begin(), m_lfo_famod_depth.end(), 0);
std::fill(m_rev_level.begin(), m_rev_level.end(), 0);
std::fill(m_dry_level.begin(), m_dry_level.end(), 0);
std::fill(m_cho_level.begin(), m_cho_level.end(), 0);
std::fill(m_var_level.begin(), m_var_level.end(), 0);
std::fill(m_glo_level.begin(), m_glo_level.end(), 0);
std::fill(m_panning.begin(), m_panning.end(), 0);
std::fill(m_attack_speed.begin(), m_attack_speed.end(), 0);
std::fill(m_attack_level.begin(), m_attack_level.end(), 0);
std::fill(m_decay_speed.begin(), m_decay_speed.end(), 0);
std::fill(m_decay_level.begin(), m_decay_level.end(), 0);
std::fill(m_pitch.begin(), m_pitch.end(), 0);
std::fill(m_sample_start.begin(), m_sample_start.end(), 0);
std::fill(m_sample_end.begin(), m_sample_end.end(), 0);
std::fill(m_sample_dpcm_and_format.begin(), m_sample_dpcm_and_format.end(), 0);
std::fill(m_sample_address.begin(), m_sample_address.end(), 0);
std::fill(m_lfo_step.begin(), m_lfo_step.end(), 0);
std::fill(m_lfo_pmod_depth.begin(), m_lfo_pmod_depth.end(), 0);
std::fill(m_lfo_phase.begin(), m_lfo_phase.end(), 0);
std::fill(m_sample_pos.begin(), m_sample_pos.end(), 0);
std::fill(m_envelope_level.begin(), m_envelope_level.end(), 0);
std::fill(m_glo_level_cur.begin(), m_glo_level_cur.end(), 0);
std::fill(m_pan_l.begin(), m_pan_l.end(), 0);
std::fill(m_pan_r.begin(), m_pan_r.end(), 0);
std::fill(m_lpf_feedback.begin(), m_lpf_feedback.end(), 0);
std::fill(m_lpf_target_value.begin(), m_lpf_target_value.end(), 0);
std::fill(m_lpf_value.begin(), m_lpf_value.end(), 0);
std::fill(m_lpf_timer.begin(), m_lpf_timer.end(), 0);
std::fill(m_lpf_ha.begin(), m_lpf_ha.end(), 0);
std::fill(m_lpf_hb.begin(), m_lpf_hb.end(), 0);
std::fill(m_active.begin(), m_active.end(), false);
std::fill(m_decay.begin(), m_decay.end(), false);
std::fill(m_decay_done.begin(), m_decay_done.end(), false);
std::fill(m_lpf_done.begin(), m_lpf_done.end(), false);
std::fill(m_dpcm_current.begin(), m_dpcm_current.end(), false);
std::fill(m_dpcm_next.begin(), m_dpcm_next.end(), false);
std::fill(m_dpcm_address.begin(), m_dpcm_address.end(), false);
std::fill(m_dpcm_sum.begin(), m_dpcm_sum.end(), 0);
}
void swp00_device::rom_bank_pre_change()
{
m_stream->update();
}
void swp00_device::map(address_map &map)
{
map(0x000, 0x7ff).rw(FUNC(swp00_device::snd_r), FUNC(swp00_device::snd_w));
// 00-01: control
rchan(map, 0x08).w(FUNC(swp00_device::slot8_w)); // always 80
rchan(map, 0x09).w(FUNC(swp00_device::slot9_w)); // always 00
rchan(map, 0x0a).rw(FUNC(swp00_device::sample_start_r<1>), FUNC(swp00_device::sample_start_w<1>));
rchan(map, 0x0b).rw(FUNC(swp00_device::sample_start_r<0>), FUNC(swp00_device::sample_start_w<0>));
// 0c-0f: meg offsets
// 10-1b: meg values
rchan(map, 0x20).rw(FUNC(swp00_device::lpf_info_r<1>), FUNC(swp00_device::lpf_info_w<1>));
rchan(map, 0x21).rw(FUNC(swp00_device::lpf_info_r<0>), FUNC(swp00_device::lpf_info_w<0>));
rchan(map, 0x22).rw(FUNC(swp00_device::lpf_speed_r), FUNC(swp00_device::lpf_speed_w));
rchan(map, 0x23).rw(FUNC(swp00_device::lfo_famod_depth_r), FUNC(swp00_device::lfo_famod_depth_w));
rchan(map, 0x24).rw(FUNC(swp00_device::lfo_step_r), FUNC(swp00_device::lfo_step_w));
rchan(map, 0x25).rw(FUNC(swp00_device::lfo_pmod_depth_r), FUNC(swp00_device::lfo_pmod_depth_w));
rchan(map, 0x26).rw(FUNC(swp00_device::attack_speed_r), FUNC(swp00_device::attack_speed_w));
rchan(map, 0x27).rw(FUNC(swp00_device::attack_level_r), FUNC(swp00_device::attack_level_w));
rchan(map, 0x28).rw(FUNC(swp00_device::decay_speed_r), FUNC(swp00_device::decay_speed_w));
rchan(map, 0x29).rw(FUNC(swp00_device::decay_level_r), FUNC(swp00_device::decay_level_w));
rchan(map, 0x2a).rw(FUNC(swp00_device::rev_level_r), FUNC(swp00_device::rev_level_w));
rchan(map, 0x2b).rw(FUNC(swp00_device::dry_level_r), FUNC(swp00_device::dry_level_w));
rchan(map, 0x2c).rw(FUNC(swp00_device::cho_level_r), FUNC(swp00_device::cho_level_w));
rchan(map, 0x2d).rw(FUNC(swp00_device::var_level_r), FUNC(swp00_device::var_level_w));
rchan(map, 0x2e).rw(FUNC(swp00_device::glo_level_r), FUNC(swp00_device::glo_level_w));
rchan(map, 0x2f).rw(FUNC(swp00_device::panning_r), FUNC(swp00_device::panning_w));
rchan(map, 0x30).rw(FUNC(swp00_device::sample_dpcm_and_format_r), FUNC(swp00_device::sample_dpcm_and_format_w));
rchan(map, 0x31).rw(FUNC(swp00_device::sample_address_r<2>), FUNC(swp00_device::sample_address_w<2>));
rchan(map, 0x32).rw(FUNC(swp00_device::sample_address_r<1>), FUNC(swp00_device::sample_address_w<1>));
rchan(map, 0x33).rw(FUNC(swp00_device::sample_address_r<0>), FUNC(swp00_device::sample_address_w<0>));
rchan(map, 0x34).rw(FUNC(swp00_device::pitch_r<1>), FUNC(swp00_device::pitch_w<1>));
rchan(map, 0x35).rw(FUNC(swp00_device::pitch_r<0>), FUNC(swp00_device::pitch_w<0>));
rchan(map, 0x36).rw(FUNC(swp00_device::sample_end_r<1>), FUNC(swp00_device::sample_end_w<1>));
rchan(map, 0x37).rw(FUNC(swp00_device::sample_end_r<0>), FUNC(swp00_device::sample_end_w<0>));
rctrl(map, 0x00); // 01 at startup
rctrl(map, 0x01).rw(FUNC(swp00_device::state_r), FUNC(swp00_device::state_adr_w));
rctrl(map, 0x02).rw(FUNC(swp00_device::waverom_access_r), FUNC(swp00_device::waverom_access_w));
rctrl(map, 0x03).r(FUNC(swp00_device::waverom_val_r));
rctrl(map, 0x04).rw(FUNC(swp00_device::meg_control_r), FUNC(swp00_device::meg_control_w));
rctrl(map, 0x08).w(FUNC(swp00_device::keyon_w<3>));
rctrl(map, 0x09).w(FUNC(swp00_device::keyon_w<2>));
rctrl(map, 0x0a).w(FUNC(swp00_device::keyon_w<1>));
rctrl(map, 0x0b).w(FUNC(swp00_device::keyon_w<0>));
rctrl(map, 0x0c); // 00 at startup
rctrl(map, 0x0d); // 00 at startup
rctrl(map, 0x0e); // 00 at startup
map(0x180, 0x1ff).rw(FUNC(swp00_device::offset_r), FUNC(swp00_device::offset_w));
map(0x200, 0x37f).rw(FUNC(swp00_device::const_r), FUNC(swp00_device::const_w));
}
// Voice control
void swp00_device::slot8_w(offs_t offset, u8 data)
{
if(data == 0x80)
return;
logerror("slot8[%02x] = %02x\n", offset >> 1, data);
}
void swp00_device::slot9_w(offs_t offset, u8 data)
{
if(data == 0x00)
return;
logerror("slot9[%02x] = %02x\n", offset >> 1, data);
}
template<int sel> void swp00_device::lpf_info_w(offs_t offset, u8 data)
{
int chan = offset >> 1;
u16 old = m_lpf_info[chan];
m_stream->update();
m_lpf_info[chan] = (m_lpf_info[chan] & ~(0xff << (8*sel))) | (data << (8*sel));
if(m_lpf_info[chan] == old)
return;
// if(!sel)
// logerror("lpf_info[%02x] = %04x\n", chan, m_lpf_info[chan]);
u32 fb = m_lpf_info[chan] >> 11;
u32 level = m_lpf_info[chan] & 0x7ff;
if(fb < 4 && level > 0x7c0)
level = 0x7c0;
if(level)
level |= 0x800;
m_lpf_feedback[chan] = (fb + 4) << 21;
m_lpf_target_value[chan] = level << 14;
}
template<int sel> u8 swp00_device::lpf_info_r(offs_t offset)
{
int chan = offset >> 1;
return m_lpf_info[chan] >> (8*sel);
}
void swp00_device::lpf_speed_w(offs_t offset, u8 data)
{
int chan = offset >> 1;
if(m_lpf_speed[chan] == data)
return;
m_stream->update();
m_lpf_speed[chan] = data;
// logerror("lpf_speed[%02x] = %02x\n", chan, m_lpf_speed[chan]);
}
u8 swp00_device::lpf_speed_r(offs_t offset)
{
int chan = offset >> 1;
return m_lpf_speed[chan];
}
void swp00_device::lfo_famod_depth_w(offs_t offset, u8 data)
{
int chan = offset >> 1;
if(m_lfo_famod_depth[chan] == data)
return;
m_stream->update();
m_lfo_famod_depth[chan] = data;
// logerror("lfo_famod_depth[%02x] = %02x\n", chan, m_lfo_famod_depth[chan]);
}
u8 swp00_device::lfo_famod_depth_r(offs_t offset)
{
int chan = offset >> 1;
return m_lfo_famod_depth[chan];
}
void swp00_device::rev_level_w(offs_t offset, u8 data)
{
int chan = offset >> 1;
if(m_rev_level[chan] == data)
return;
m_stream->update();
m_rev_level[chan] = data;
// logerror("rev_level[%02x] = %02x\n", chan, m_rev_level[chan]);
}
u8 swp00_device::rev_level_r(offs_t offset)
{
int chan = offset >> 1;
return m_rev_level[chan];
}
void swp00_device::dry_level_w(offs_t offset, u8 data)
{
int chan = offset >> 1;
if(m_dry_level[chan] == data)
return;
m_stream->update();
m_dry_level[chan] = data;
// logerror("dry_level[%02x] = %02x\n", chan, m_dry_level[chan]);
}
u8 swp00_device::dry_level_r(offs_t offset)
{
int chan = offset >> 1;
return m_dry_level[chan];
}
void swp00_device::cho_level_w(offs_t offset, u8 data)
{
int chan = offset >> 1;
if(m_cho_level[chan] == data)
return;
m_stream->update();
m_cho_level[chan] = data;
// logerror("cho_level[%02x] = %02x\n", chan, m_cho_level[chan]);
}
u8 swp00_device::cho_level_r(offs_t offset)
{
int chan = offset >> 1;
return m_cho_level[chan];
}
void swp00_device::var_level_w(offs_t offset, u8 data)
{
int chan = offset >> 1;
if(m_var_level[chan] == data)
return;
m_stream->update();
m_var_level[chan] = data;
// logerror("var_level[%02x] = %02x\n", chan, m_var_level[chan]);
}
u8 swp00_device::var_level_r(offs_t offset)
{
int chan = offset >> 1;
return m_var_level[chan];
}
void swp00_device::glo_level_w(offs_t offset, u8 data)
{
int chan = offset >> 1;
if(m_glo_level[chan] == data)
return;
m_glo_level[chan] = data;
// logerror("glo_level[%02x] = %02x\n", chan, m_glo_level[chan]);
}
u8 swp00_device::glo_level_r(offs_t offset)
{
int chan = offset >> 1;
return m_glo_level[chan];
}
void swp00_device::panning_w(offs_t offset, u8 data)
{
int chan = offset >> 1;
if(m_panning[chan] == data)
return;
m_stream->update();
m_panning[chan] = data;
// logerror("panning[%02x] = %02x\n", chan, m_panning[chan]);
}
u8 swp00_device::panning_r(offs_t offset)
{
int chan = offset >> 1;
return m_panning[chan];
}
void swp00_device::attack_speed_w(offs_t offset, u8 data)
{
int chan = offset >> 1;
if(m_attack_speed[chan] == data)
return;
m_stream->update();
m_attack_speed[chan] = data;
logerror("attack_speed[%02x] = %02x\n", chan, m_attack_speed[chan]);
}
u8 swp00_device::attack_speed_r(offs_t offset)
{
int chan = offset >> 1;
return m_attack_speed[chan];
}
void swp00_device::attack_level_w(offs_t offset, u8 data)
{
int chan = offset >> 1;
if(m_attack_level[chan] == data)
return;
m_stream->update();
m_attack_level[chan] = data;
logerror("attack_level[%02x] = %02x\n", chan, m_attack_level[chan]);
}
u8 swp00_device::attack_level_r(offs_t offset)
{
int chan = offset >> 1;
return m_attack_level[chan];
}
void swp00_device::decay_speed_w(offs_t offset, u8 data)
{
int chan = offset >> 1;
if(m_decay_speed[chan] == data)
return;
m_stream->update();
m_decay_speed[chan] = data;
if(data & 0x80)
m_decay[chan] = true;
logerror("decay_speed[%02x] = %02x\n", chan, m_decay_speed[chan]);
}
u8 swp00_device::decay_speed_r(offs_t offset)
{
int chan = offset >> 1;
return m_decay_speed[chan];
}
void swp00_device::decay_level_w(offs_t offset, u8 data)
{
int chan = offset >> 1;
if(m_decay_level[chan] == data)
return;
m_stream->update();
m_decay_level[chan] = data;
logerror("decay_level[%02x] = %02x\n", chan, m_decay_level[chan]);
}
u8 swp00_device::decay_level_r(offs_t offset)
{
int chan = offset >> 1;
return m_decay_level[chan];
}
template<int sel> void swp00_device::pitch_w(offs_t offset, u8 data)
{
int chan = offset >> 1;
u16 old = m_pitch[chan];
m_stream->update();
m_pitch[chan] = (m_pitch[chan] & ~(0xff << (8*sel))) | (data << (8*sel));
if(m_pitch[chan] == old)
return;
// if(!sel)
// logerror("pitch[%02x] = %04x\n", chan, m_pitch[chan]);
}
template<int sel> u8 swp00_device::pitch_r(offs_t offset)
{
int chan = offset >> 1;
return m_pitch[chan] >> (8*sel);
}
template<int sel> void swp00_device::sample_start_w(offs_t offset, u8 data)
{
int chan = offset >> 1;
m_stream->update();
m_sample_start[chan] = (m_sample_start[chan] & ~(0xff << (8*sel))) | (data << (8*sel));
// if(!sel)
// logerror("sample_start[%02x] = %04x\n", chan, m_sample_start[chan]);
}
template<int sel> u8 swp00_device::sample_start_r(offs_t offset)
{
int chan = offset >> 1;
return m_sample_start[chan] >> (8*sel);
}
template<int sel> void swp00_device::sample_end_w(offs_t offset, u8 data)
{
int chan = offset >> 1;
m_stream->update();
m_sample_end[chan] = (m_sample_end[chan] & ~(0xff << (8*sel))) | (data << (8*sel));
// if(!sel)
// logerror("sample_end[%02x] = %04x\n", chan, m_sample_end[chan]);
}
template<int sel> u8 swp00_device::sample_end_r(offs_t offset)
{
int chan = offset >> 1;
return m_sample_end[chan] >> (8*sel);
}
void swp00_device::sample_dpcm_and_format_w(offs_t offset, u8 data)
{
int chan = offset >> 1;
m_stream->update();
m_sample_dpcm_and_format[chan] = data;
// logerror("sample_dpcm_and_format[%02x] = %02x\n", chan, m_sample_dpcm_and_format[chan]);
}
u8 swp00_device::sample_dpcm_and_format_r(offs_t offset)
{
int chan = offset >> 1;
return m_sample_dpcm_and_format[chan];
}
template<int sel> void swp00_device::sample_address_w(offs_t offset, u8 data)
{
int chan = offset >> 1;
m_stream->update();
m_sample_address[chan] = (m_sample_address[chan] & ~(0xff << (8*sel))) | (data << (8*sel));
// if(!sel)
// logerror("sample_address[%02x] = %04x\n", chan, m_sample_address[chan]);
}
template<int sel> u8 swp00_device::sample_address_r(offs_t offset)
{
int chan = offset >> 1;
return m_sample_address[chan] >> (8*sel);
}
void swp00_device::lfo_step_w(offs_t offset, u8 data)
{
int chan = offset >> 1;
if(m_lfo_step[chan] == data)
return;
m_stream->update();
m_lfo_step[chan] = data;
// logerror("lfo_step[%02x] = %02x\n", chan, m_lfo_step[chan]);
}
u8 swp00_device::lfo_step_r(offs_t offset)
{
int chan = offset >> 1;
return m_lfo_step[chan];
}
void swp00_device::lfo_pmod_depth_w(offs_t offset, u8 data)
{
int chan = offset >> 1;
if(m_lfo_pmod_depth[chan] == data)
return;
m_stream->update();
m_lfo_pmod_depth[chan] = data;
// logerror("lfo_pmod_depth[%02x] = %02x\n", chan, m_lfo_pmod_depth[chan]);
}
u8 swp00_device::lfo_pmod_depth_r(offs_t offset)
{
int chan = offset >> 1;
return m_lfo_pmod_depth[chan];
}
void swp00_device::keyon(int chan)
{
m_stream->update();
logerror("keyon %02x a=%02x/%02x d=%02x/%02x glo=%02x pan=%02x [%x %x %x %x]\n", chan, m_attack_speed[chan], m_attack_level[chan], m_decay_speed[chan], m_decay_level[chan], m_glo_level[chan], m_panning[chan], m_sample_start[chan], m_sample_end[chan], m_sample_address[chan], m_sample_dpcm_and_format[chan]);
m_lfo_phase[chan] = 0;
m_sample_pos[chan] = -m_sample_start[chan] << 15;
m_active[chan] = true;
m_decay[chan] = false;
m_decay_done[chan] = false;
m_dpcm_current[chan] = 0;
m_dpcm_next[chan] = 0;
m_dpcm_address[chan] = m_sample_address[chan] - m_sample_start[chan];
m_dpcm_sum[chan] = 0;
m_lpf_value[chan] = m_lpf_target_value[chan];
m_lpf_timer[chan] = 0x4000000;
m_lpf_ha[chan] = 0;
m_lpf_hb[chan] = 0;
m_glo_level_cur[chan] = m_glo_level[chan] << 4;
m_pan_l[chan] = panmap[m_panning[chan] >> 4];
m_pan_r[chan] = panmap[m_panning[chan] & 15];
if(m_decay_speed[chan] & 0x80) {
m_envelope_level[chan] = 0;
m_decay[chan] = true;
} else if((m_attack_speed[chan] & 0x80) || m_attack_level[chan])
m_envelope_level[chan] = m_attack_level[chan] << 20;
else
m_envelope_level[chan] = 0x8000000;
}
template<int sel> void swp00_device::keyon_w(u8 data)
{
for(int i=0; i < 8; i++)
if(BIT(data, i))
keyon(8*sel+i);
}
void swp00_device::offset_w(offs_t offset, u8 data)
{
m_stream->update();
if(offset & 1)
m_offset[offset >> 1] = (m_offset[offset >> 1] & 0xff00) | data;
else
m_offset[offset >> 1] = (m_offset[offset >> 1] & 0x00ff) | (data << 8);
if(0)
if(offset & 1)
logerror("offset[%02x] = %04x\n", 3*(offset >> 1), m_offset[offset >> 1]);
}
u8 swp00_device::offset_r(offs_t offset)
{
if(offset & 1)
return m_offset[offset >> 1];
else
return m_offset[offset >> 1] >> 8;
}
void swp00_device::const_w(offs_t offset, u8 data)
{
m_stream->update();
if(offset & 1)
m_const[offset >> 1] = (m_const[offset >> 1] & 0xff00) | data;
else
m_const[offset >> 1] = (m_const[offset >> 1] & 0x00ff) | (data << 8);
if(0)
if(offset & 1)
logerror("const[%02x] = %04x\n", offset >> 1, m_const[offset >> 1]);
}
u8 swp00_device::const_r(offs_t offset)
{
if(offset & 1)
return m_const[offset >> 1];
else
return m_const[offset >> 1] >> 8;
}
void swp00_device::waverom_access_w(u8 data)
{
m_waverom_access = data;
}
u8 swp00_device::waverom_access_r()
{
return 0x00; // non-zero = busy reading the rom
}
u8 swp00_device::waverom_val_r()
{
u8 val = read_byte(m_sample_address[0x1f]);
logerror("waverom read adr=%08x -> %02x\n", m_sample_address[0x1f], val);