-
Notifications
You must be signed in to change notification settings - Fork 0
/
LEDSTOR2.S
1606 lines (1513 loc) · 58.8 KB
/
LEDSTOR2.S
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
; Tim Follin's Atari ST driver for "LED Storm", annotated in 2017.
; "o_" offsets are offsets into the data area specified by a6_base
; They are usually referenced by x(A6,D?.W) addressing,
; where D6 is an offset of 0/1/2 (per-channel) most byte values
; D5 is an offset of 0/2/4, the 16-bit values (eg pitch)
; D4 is an offset of 0/4/7, the 32-bit values (eg addresses for loops/stacks)
o_vibrato = -$78 ; raw YM delta to apply in vibrato, in YM period space
o_vibrato_dir = -$74 ; current vibrato direction
o_vibrato_cntr = -$70
o_vibrato_spd = -$6c
o_arp_cntr = -$68
o_arp_spd_up = -$64
o_arp_delta = -$60
o_last_note = -$5c
o_slide_delta = -$58
o_slide_target_note = -$54
o_raw_period_adj = -$50 ; raw delta to apply to notes in YM period space
o_next_note_cntr = -$4c
o_vibrato_startdir = -$48 ; whether vibrato is going up or down at note start
o_reset_adsr_on_note = -$44
o_start_adsr_step = -$40
o_instr_volume = -$3c
o_loop_cnt = -$38
o_note_transpose = -$34
o_skip_transpose = -$30 ; Don't apply transpose (on next note only) e.g. for fixed freq instruments
o_default_note_time = -$2c ; if set, notes don't take a time
o_fixed_mixer = -$28 ; Fixed mixer value when fixed values enabled.
o_unknown_1 = -$24 ; set at init, not changed?
o_instr_mixer = -$20
o_mute_cntr = -$1c ; counts down to point where instrument mute happens
o_mute_time = -$18 ; time after which instrument is muted
o_volume = -$14
o_channel_stop = -$10 ; if set, do no channel update
o_fixed_period_time = -$c ; set at init. if set used fixed YM values
o_skip_update_counter = -$8 ; if nonzero suppress update + count down
o_nomute = -$4
o_arp_spd_down = $58 ; number of frames to do arp jumps down
o_mixer = $5c
o_adsr_step = $60
o_env_counter = $64 ; counter to the next envelope volume update
o_attack_spd = $68 ; number of steps for attack
o_decay_spd = $6c ; number of steps for decay
o_instr_min_volume = $70 ; drop to this level in the release
o_vibrato_delay = $74 ; set at init
o_vibrato_delay_cntr = $78 ; counts down to vibrato start
; o4, these use d4 as the offset (channel number * 4)
o4_command_ptr = 0 ; address of next command/note to read
o4_loop_addr = $10
o4_cmd_stack = $30
; o5, these use d5 as the base offset (channel number * 2)
o5_fixed_period_hi = $40 ; Fixed period to apply (high part)
o5_fixed_period_lo = $41
o5_ym_period_hi = $48 ; Current period value (during vibrato)
o5_ym_period_lo = $49
follin_init:
CLR.L D0
MOVE.W tune_id,D0 ; tune ID
ASL.W #1,D0
CLR.L D1
MOVE.W D0,D1
ADDI.L #channel_a_start_table,D1 ; channel_a_start_table
MOVEA.L D1,A0
BSR get_ch_cmd_start
MOVE.L D1,tune_base_a
CLR.L D1
MOVE.W D0,D1
ADDI.L #channel_b_start_table,D1
MOVEA.L D1,A0
BSR get_ch_cmd_start
MOVE.L D1,tune_base_b
CLR.L D1
MOVE.W D0,D1
ADDI.L #channel_c_start_table,D1
MOVEA.L D1,A0
BSR get_ch_cmd_start
MOVE.L D1,tune_base_c
MOVE.B #-1,D0
MOVE.B D0,a6_base-$10
MOVE.B D0,a6_base-$10+1
MOVE.B D0,a6_base-$10+2
shared_init:
MOVE.B D0,a6_base-$24
MOVE.B D0,a6_base-$24+1
MOVE.B D0,a6_base-$24+2
CLR.L a6_base-$34 ; o_note_transpose
CLR.L a6_base-$2c ; o_default_note_time
CLR.L a6_base-$30 ; o_skip_transpose
CLR.L a6_base-$68 ; o_arp_cntr
CLR.L a6_base-$64 ; o_arp_spd_up
CLR.L a6_base+$58 ; o_arp_spd_down
CLR.L a6_base-$58 ; o_slide_delta
CLR.L a6_base+$74 ; o_vibrato_delay
CLR.L a6_base-$c ; o_fixed_period_time
CLR.L a6_base-$38 ; o_loop_cnt
CLR.L a6_base-$50 ; o_raw_period_adj
CLR.L a6_base-$4c ; o_next_note_cntr
MOVE.B #1,D0
MOVE.B D0,a6_base-$4c ; o_next_note_cntr
MOVE.B D0,a6_base-$4c+1
MOVE.B D0,a6_base-$4c+2
MOVE.B D0,a6_base-$44 ; o_reset_adsr_on_note
MOVE.B D0,a6_base-$44+1
MOVE.B D0,a6_base-$44+2
MOVE.B #9,D1
MOVE.B D1,a6_base+$5c ; o_mixer
ASL.B #1,D1
MOVE.B D1,a6_base+$5c+1
ASL.B #1,D1
MOVE.B D1,a6_base+$5c+2
MOVE.L #channel_a_stack_start,a6_base+$30 ; o4_cmd_stack
MOVE.L #channel_b_stack_start,a6_base+$30+4
MOVE.L #channel_c_stack_start,a6_base+$30+8
follin_end:
RTS
; "Stop"
follin_stop:
CLR.B D2
MOVE.B #8,D0
BSR write_ym_reg
CLR.B D2
MOVE.B #9,D0
BSR write_ym_reg
CLR.B D2
MOVE.B #$A,D0
BSR write_ym_reg
CLR.L D0
MOVE.B D0,a6_base-$10 ; o_channel_stop
MOVE.B D0,a6_base-$10+1
MOVE.B D0,a6_base-$10+2
MOVE.B #-1,D0
BRA shared_init
; Initialise sfx.
; The sfx is a list of channel IDs and "tune" starts to use,
; followed by $ff.
follin_sfx_init:
ASL.B #1,D0
ANDI.L #$1F,D0
LEA sfx_table,A0
MOVE.B 0(A0,D0.W),tmp_swap_2
MOVE.B 1(A0,D0.W),tmp_swap_1
CLR.L D0
MOVE.W tmp_swap_1,D0
SUBI.L #0,D0
ADDI.L #tune_start_table,D0
MOVEA.L D0,A0
CLR.L D0
channel_tune_reset_loop:
MOVE.B (A0),D0 ; some sort of command byte
BMI follin_end
LSR.B #1,D0 ; shift down
LEA a6_base-$10,A1 ; o_channel_stop
MOVE.B #-1,0(A1,D0.W)
LEA a6_base-$4c,A1
MOVE.B #1,0(A1,D0.W) ; o_next_note_cntr
MOVE.B (A0)+,D0 ; d0 is now the channel
ASL.B #1,D0
LEA tune_base_a,A1
; lookup "tune" start
MOVE.B (A0)+,tmp_swap_2
MOVE.B (A0)+,tmp_swap_1
CLR.L D1
MOVE.W tmp_swap_1,D1
SUBI.L #0,D1
ADDI.L #tune_start_table,D1
MOVE.L D1,0(A1,D0.W) ; set tune ptr
BRA channel_tune_reset_loop
; The main update function.
; This should be called at a rate of 50Hz
; It updates each channel in turn, writing to the YM
; as it goes.
follin_update:
CLR.B channel_delay_mask
LEA tune_base_a,A6
LEA mixer_mute_table,A5
CLR.L D6
CLR.L D5
CLR.L D4
; per-channel loop:
L0023: MOVE.B D6,D5 ; d6 = 0/1/2
ASL.W #1,D5 ; d5 = 0/2/4
MOVE.B D5,D4
ASL.W #1,D4 ; d4 = 0/4/8
BSR update_channel
ADDQ.B #1,D6
CMP.B #3,D6
BNE L0023
RTS
write_ym_period:
MOVE.B o5_ym_period_lo(A6,D5.W),D2
MOVE.B D6,D0
ASL.B #1,D0
BSR write_ym_reg
MOVE.B o5_ym_period_hi(A6,D5.W),D2
MOVE.B D6,D0
ASL.B #1,D0
ADDQ.B #1,D0
; d0 = register index
; d2 = register value
write_ym_reg:
MOVE.L D2,temp_d2_store
CMP.B #7,D0
BEQ write_mixer
MOVE.B D0,$FF8800.L
MOVE.B D2,$FF8802.L
MOVE.L temp_d2_store,D2
MOVE.L D2,D0
RTS
write_mixer:
MOVE.B D0,$FF8800.L
MOVE.B $FF8800.L,D1
ANDI.B #-$40,D1 ; preserve top bits
ANDI.B #$3F,D2
OR.B D2,D1
MOVE.B D1,$FF8802.L
MOVE.L temp_d2_store,D2
MOVE.L D2,D0
RTS
generate_mixer:
MOVE.B a6_base+$5c,D2 ; = $5C(A6)
OR.B a6_base+$5c+1,D2
OR.B a6_base+$5c+2,D2
MOVE.B #7,D0
BRA write_ym_reg
; Read 2 bytes from A0 which constitute an offset into the tune data
; A0: address of little-endian value for offset into tune data
; D1: absolute address of resulting data
get_ch_cmd_start:
MOVE.B (A0)+,tmp_swap_2 ; get offset as little-endian
MOVE.B (A0)+,tmp_swap_1
CLR.L D1
MOVE.W tmp_swap_1,D1
SUBI.W #0,D1
ADDI.L #tune_start_table,D1
RTS
update_channel:
MOVE.B o_channel_stop(A6,D6.W),D7
OR.B D7,channel_delay_mask
TST.B o_channel_stop(A6,D6.W)
BPL channel_done
; Apply ADSR
TST.B o_adsr_step(A6,D6.W)
BNE L002A
; Step 0 -- attack
SUBQ.B #1,o_env_counter(A6,D6.W)
BPL L002C
MOVE.B o_attack_spd(A6,D6.W),o_env_counter(A6,D6.W)
ADDQ.B #1,o_volume(A6,D6.W)
CMPI.B #$F,o_volume(A6,D6.W)
BNE L002C
; move to step 1
MOVE.B #1,o_adsr_step(A6,D6.W)
MOVE.B o_decay_spd(A6,D6.W),o_env_counter(A6,D6.W)
BRA L002C
L002A: CMPI.B #1,o_adsr_step(A6,D6.W)
BNE L002C
; Step 1 -- decay
SUBQ.B #1,o_env_counter(A6,D6.W)
BPL L002C
MOVE.B o_decay_spd(A6,D6.W),o_env_counter(A6,D6.W)
MOVE.B o_volume(A6,D6.W),D0
; Clip to min volume
CMP.B o_instr_min_volume(A6,D6.W),D0
BEQ L002B
SUBQ.B #1,o_volume(A6,D6.W)
BPL L002C
L002B: MOVE.B #2,o_adsr_step(A6,D6.W) ; Step 2 is effectively "sustain"
; -$14 is now the volume?
L002C:
; Set the volume register
MOVE.B o_volume(A6,D6.W),D2
MOVE.B D6,D0
ADDQ.B #8,D0 ; 8 + channel: volume
BSR write_ym_reg
; Period adjust
TST.B o_fixed_period_time(A6,D6.W)
BEQ period_update
TST.B o_skip_update_counter(A6,D6.W)
BEQ period_update
SUBQ.B #1,o_skip_update_counter(A6,D6.W)
BNE period_update_complete
; o_skip_update_counter has counted down, force
; an initial period+mixer update
BSR write_ym_period
MOVE.B o_instr_mixer(A6,D6.W),o_mixer(A6,D6.W)
BSR generate_mixer
period_update:
TST.B o_vibrato_delay(A6,D6.W)
BEQ apply_arp
TST.B o_vibrato_delay_cntr(A6,D6.W)
BEQ apply_vibrato
SUBQ.B #1,o_vibrato_delay_cntr(A6,D6.W)
BNE apply_arp
apply_vibrato:
MOVE.W o5_ym_period_hi(A6,D5.W),D0
CLR.L D1
MOVE.B o_vibrato(A6,D6.W),D1 ; -$78 period adjust
TST.B o_vibrato_dir(A6,D6.W) ; -$74 period direction
; Decide whether to go up or down
BEQ apply_vibrato_down
ADD.W D1,D0 ; apply period adjust
BRA L0030
apply_vibrato_down:
SUB.W D1,D0
L0030: MOVE.W D0,o5_ym_period_hi(A6,D5.W)
BSR write_ym_period
SUBQ.B #1,o_vibrato_cntr(A6,D6.W)
BNE apply_slide ; don't apply any further modulation
MOVE.B o_vibrato_spd(A6,D6.W),D0
BEQ apply_slide ; if speed = 0, skip all this
; the vibrato counter is doubled from the original here, so it goes up a half,
; down a full, up a full (i.e. oscillates around the base level)
ASL.B #1,D0 ; double the counter, and reapply
MOVE.B D0,o_vibrato_cntr(A6,D6.W)
EORI.B #-1,o_vibrato_dir(A6,D6.W) ; change direction
BRA apply_slide
apply_arp:
; This effect works a bit like vibrato but is
; applied to whole notes and can have different up/down delays
TST.B o_arp_cntr(A6,D6.W)
BEQ apply_slide
SUBQ.B #1,o_arp_cntr(A6,D6.W)
BNE apply_slide
MOVE.B o_arp_spd_up(A6,D6.W),o_arp_cntr(A6,D6.W)
MOVE.B o_arp_delta(A6,D6.W),D1
MOVE.B o_last_note(A6,D6.W),D0 ; get the base note
EORI.B #-1,o_vibrato_dir(A6,D6.W)
BEQ L0032
ADD.B D1,D0 ; apply arp offset
BRA slide_updated
L0032: MOVE.B o_arp_spd_down(A6,D6.W),o_arp_cntr(A6,D6.W)
SUB.B D1,D0
BRA slide_updated
; Next effect, I think this is "slide" from the previous note
; to the target note. Like arp, this works in note space.
apply_slide:
TST.B o_slide_delta(A6,D6.W)
BEQ period_update_complete
MOVE.B o_slide_delta(A6,D6.W),D2
MOVE.B o_last_note(A6,D6.W),D0
; Do we need to go up or down?
CMP.B o_slide_target_note(A6,D6.W),D0
BEQ period_update_complete ; neither, slide is done
BCS L0034
SUB.B D2,D0 ; go down
CMP.B o_slide_target_note(A6,D6.W),D0 ; check for overshoot
BCC slide_updated
BRA clip_slide
L0034: ADD.B D2,D0
CMP.B o_slide_target_note(A6,D6.W),D0
BCS slide_updated
clip_slide:
; This fires in the case that the slide jump overshoots
; the target note.
MOVE.B o_slide_target_note(A6,D6.W),D0
slide_updated:
; lookup the final note value in the period table again
; (this is why it's incompatible with vibrato)
MOVE.B D0,o_last_note(A6,D6.W)
ANDI.W #$FF,D0
ASL.B #1,D0
LEA note_table,A2
MOVE.W 0(A2,D0.W),D0
CLR.W D1
MOVE.B o_raw_period_adj(A6,D6.W),D1
ADD.W D1,D0
MOVE.W D0,o5_ym_period_hi(A6,D5.W) ; this also writes to lo value
BSR write_ym_period
period_update_complete:
; Reduce time to next note
SUBQ.B #1,o_next_note_cntr(A6,D6.W)
MOVE.B o_next_note_cntr(A6,D6.W),D0
CMP.B o_nomute(A6,D6.W),D0 ; -4 forces mute if 0
BEQ force_mute
TST.B o_mute_cntr(A6,D6.W) ; withhold mute until counter is down to 0
BNE no_mute
force_mute:
MOVE.B 1(A5,D5.W),o_mixer(A6,D6.W) ; look up alternative mixer values
BSR generate_mixer
ADDQ.B #1,o_mute_cntr(A6,D6.W) ; inc mystery counter to 1 again (then immediately zeroed)
no_mute:SUBQ.B #1,o_mute_cntr(A6,D6.W) ; count down to mute
TST.B o_next_note_cntr(A6,D6.W)
BNE channel_done
; This is the main command processing loop.
; The first byte is either a command if (top bit is set
; or value is 0),
; or a new note value to play.
MOVEA.L o4_command_ptr(A6,D4.W),A0
fetch_cmd:
CLR.L D0
MOVE.B (A0)+,D0
BEQ L003B ;0 is a command
BPL not_a_command ;test top bit
L003B: ANDI.W #$1F,D0 ;command mask is 31
ASL.W #2,D0 ;jump table lookup
LEA jmptable,A1
MOVEA.L 0(A1,D0.W),A1 ;look up jump address
CMPA.L #note_table,A1 ;safety check
BEQ error_lockup ;should this be BGE to be more effective?
JMP (A1) ;process command. Commands jump back to fetch_cmd.
; A rather brutal but effective way of detecting something is wrong.
error_lockup:
JMP error_lockup
not_a_command:
; if it's not a command it must be a note
; d0 is the note value.
MOVE.B D0,D2
TST.B o_skip_transpose(A6,D6.W) ; if o_skip_transpose is non-zero, force transpose to 0
BEQ .apply_transpose ; go set note
CLR.B D0 ; use 0 for transpose
MOVE.B D0,o_skip_transpose(A6,D6.W) ; clear the flag for next time
BRA .skip_transpose
.apply_transpose:
MOVE.B o_note_transpose(A6,D6.W),D0 ; note transpose?
.skip_transpose:
ADD.B D2,D0 ; apply transpose
TST.B o_slide_delta(A6,D6.W)
BEQ .apply_note
; If we're applying slide, save this new note as the slide target,
; and use the previous note as the current note position.
MOVE.B D0,o_slide_target_note(A6,D6.W)
MOVE.B o_last_note(A6,D6.W),D0 ; use previous note
.apply_note:
; Look up the note value and poke it into the YM.
ANDI.W #$FF,D0
MOVE.B D0,o_last_note(A6,D6.W) ; last note
ASL.B #1,D0
LEA note_table,A2 ; look up note (d0)
MOVE.W 0(A2,D0.W),D0
; Apply fine-tune direct period adjust. This can only
; be a positive value...
CLR.W D1
MOVE.B o_raw_period_adj(A6,D6.W),D1
ADD.W D1,D0
MOVE.W D0,o5_ym_period_hi(A6,D5.W)
BSR write_ym_period
; set delay to next note
; If the default note time is 0, the next command byte
; is time-to-next-cmd/note
MOVE.B o_default_note_time(A6,D6.W),D0
TST.B D0
BNE .no_extra_note_time
MOVE.B (A0)+,D0 ; extra value
.no_extra_note_time:
MOVE.B D0,o_next_note_cntr(A6,D6.W)
MOVE.L A0,o4_command_ptr(A6,D4.W)
; Retrigger the note envelope
MOVE.B o_arp_spd_up(A6,D6.W),o_arp_cntr(A6,D6.W)
MOVE.B o_mute_time(A6,D6.W),o_mute_cntr(A6,D6.W)
MOVE.B o_instr_mixer(A6,D6.W),o_mixer(A6,D6.W)
BSR generate_mixer
MOVE.B o_vibrato_delay(A6,D6.W),D0
BEQ .set_vibrato_dir ; No vibrato?
MOVE.B D0,o_vibrato_delay_cntr(A6,D6.W)
MOVE.B o_vibrato_spd(A6,D6.W),o_vibrato_cntr(A6,D6.W)
MOVE.B o_vibrato_startdir(A6,D6.W),D0
.set_vibrato_dir:
MOVE.B D0,o_vibrato_dir(A6,D6.W)
; Retrigger ADSR check
TST.B o_reset_adsr_on_note(A6,D6.W)
BEQ skip_adsr_reset
; Copy the instrument settings into current values
MOVE.B o_start_adsr_step(A6,D6.W),o_adsr_step(A6,D6.W)
; Get the right speed for the starting ADSR step
MOVE.B o_attack_spd(A6,D6.W),D0
TST.B o_adsr_step(A6,D6.W)
BEQ .in_attack ; if in attack, we're done
MOVE.B o_decay_spd(A6,D6.W),D0
.in_attack:
MOVE.B D0,o_env_counter(A6,D6.W)
MOVE.B o_instr_volume(A6,D6.W),o_volume(A6,D6.W)
skip_adsr_reset:
TST.B o_fixed_period_time(A6,D6.W)
BEQ channel_done
; Write fixed period to YM
MOVE.B o_fixed_period_time(A6,D6.W),o_skip_update_counter(A6,D6.W)
MOVE.B o_fixed_mixer(A6,D6.W),o_mixer(A6,D6.W)
BSR generate_mixer
; Write fixed period values to YM.
MOVE.B o5_fixed_period_lo(A6,D5.W),D2 ; write the period again?
MOVE.B D6,D0
ASL.B #1,D0
BSR write_ym_reg
MOVE.B o5_fixed_period_hi(A6,D5.W),D2
MOVE.B D6,D0
ASL.B #1,D0
ADDQ.B #1,D0
BSR write_ym_reg
channel_done:
RTS
; =============================================================================
cmd_0_start_loop: ; START LOOP
MOVE.B (A0)+,o_loop_cnt(A6,D6.W) ; Byte 1: loop counter
MOVE.L A0,o4_loop_addr(A6,D4.W) ; Save this loop address
BRA fetch_cmd
; =============================================================================
cmd_1_end_loop: ; END LOOP
SUBQ.B #1,o_loop_cnt(A6,D6.W) ; decrement looper
BEQ fetch_cmd ; loop done, go to next command, or ...
MOVEA.L o4_loop_addr(A6,D4.W),A0 ; ... restore command position to start of loop
BRA fetch_cmd
; =============================================================================
cmd_2_default_note_time:
MOVE.B (A0)+,o_default_note_time(A6,D6.W)
BRA fetch_cmd
; =============================================================================
cmd_3_stop:
ADDQ.B #1,o_channel_stop(A6,D6.W) ; add to channel delay?
BRA channel_done
; =============================================================================
cmd_10_jump: ; jump to position
MOVE.B (A0)+,tmp_swap_2 ; fetch new offset-address (little-endian)
MOVE.B (A0)+,tmp_swap_1
CLR.L D0
MOVE.W tmp_swap_1,D0 ; swizzle
SUBI.L #0,D0
ADDI.L #tune_start_table,D0 ; generate absolute address
MOVEA.L D0,A0
BRA fetch_cmd
; =============================================================================
cmd_4_gosub:
BSR get_ch_cmd_start ; read 2 bytes and generate an addr in d1
MOVEA.L o4_cmd_stack(A6,D4.W),A1
MOVE.L A0,-(A1) ; save current cmd pointer on stack
MOVE.L A1,o4_cmd_stack(A6,D4.W) ; save stack position
MOVEA.L D1,A0 ; change cmd pointer
BRA fetch_cmd
; =============================================================================
cmd_5_return: ; pop cmd stack
MOVEA.L o4_cmd_stack(A6,D4.W),A1 ; restore command position
MOVEA.L (A1)+,A0
MOVE.L A1,o4_cmd_stack(A6,D4.W)
BRA fetch_cmd
; =============================================================================
cmd_6_set_transpose:
MOVE.B (A0)+,o_note_transpose(A6,D6.W)
BRA fetch_cmd
; =============================================================================
cmd_8_direct_write:
; Write directly to a register.
; Used for things like noise frequency
MOVE.B (A0)+,D0
MOVE.B (A0)+,D2
CMP.B #7,D0 ; Mixer reg? Special case
BNE .not_mixer
; Mixer value needs to be saved since it's needed elsewhere
MOVE.B D2,D0
MOVE.B D0,o_mixer(A6,D6.W) ; save written mixer
MOVE.B D0,o_instr_mixer(A6,D6.W) ; save written mixer
BSR generate_mixer
BRA fetch_cmd
.not_mixer:
BSR write_ym_reg
BRA fetch_cmd
; =============================================================================
cmd_9_set_adsr: ; Set instrument envelope
MOVE.B (A0),D0 ; 4:4
LSR.B #4,D0
MOVE.B D0,o_instr_volume(A6,D6.W)
MOVE.B (A0)+,D0
ANDI.B #$F,D0
MOVE.B D0,o_instr_min_volume(A6,D6.W)
MOVE.B (A0),D0 ; 4:4
LSR.B #4,D0
MOVE.B D0,o_attack_spd(A6,D6.W)
MOVE.B (A0)+,o_decay_spd(A6,D6.W)
ANDI.B #$F,o_decay_spd(A6,D6.W)
MOVE.B (A0)+,o_start_adsr_step(A6,D6.W) ;byte
BRA fetch_cmd
; =============================================================================
; The rest of the routine is the commands which provide control flow and
; persistent state setup.
; =============================================================================
cmd_a_set_adsr_reset:
; Controls whether a new note resets envelope
; (used for custom pitch effects after initial envelope trigger)
MOVE.B (A0)+,o_reset_adsr_on_note(A6,D6.W)
BRA fetch_cmd
; =============================================================================
cmd_b_set_arpeggio:
MOVE.B (A0)+,o_arp_delta(A6,D6.W)
MOVE.B (A0)+,o_arp_spd_up(A6,D6.W)
MOVE.B (A0)+,o_arp_spd_down(A6,D6.W)
BRA fetch_cmd
; =============================================================================
cmd_c_set_slide:
MOVE.B (A0)+,o_slide_delta(A6,D6.W)
BRA fetch_cmd
; =============================================================================
cmd_d_set_vibrato:
MOVE.B (A0)+,o_vibrato_delay(A6,D6.W)
MOVE.B (A0)+,o_vibrato(A6,D6.W)
MOVE.B (A0)+,o_vibrato_spd(A6,D6.W)
MOVE.B (A0)+,o_vibrato_startdir(A6,D6.W)
BRA fetch_cmd
; =============================================================================
cmd_e_skip_transpose:
; Skips transposing the *next note only*
MOVE.B #-1,o_skip_transpose(A6,D6.W)
BRA fetch_cmd
; =============================================================================
cmd_f_set_fixfreq:
; This turns fixed period on and off
MOVE.B (A0)+,o_fixed_period_time(A6,D6.W)
BNE .fixedfreq_on
; Fixed period is turned off, go back to dynamic
MOVE.B o_instr_mixer(A6,D6.W),o_mixer(A6,D6.W)
BSR generate_mixer
BRA fetch_cmd
.fixedfreq_on:
MOVE.B (A0)+,o_fixed_mixer(A6,D6.W) ; mixer value
MOVE.B (A0)+,o5_fixed_period_hi(A6,D5.W) ; I think this might be fixed period
MOVE.B (A0)+,o5_fixed_period_lo(A6,D5.W)
BRA fetch_cmd
; =============================================================================
cmd_7_set_raw_detune:
; Add a fixed value to the note's YM period
MOVE.B (A0)+,o_raw_period_adj(A6,D6.W)
BRA fetch_cmd
; =============================================================================
cmd_12_set_nomute:
MOVE.B (A0)+,o_nomute(A6,D6.W)
BRA fetch_cmd
; =============================================================================
cmd_11_set_mute_time:
; This had to be located in Hatari since Easy Rider missed it
; Set time before full mute is applied
move.b (a0)+,o_mute_time(A6,D6.W)
bra fetch_cmd
; These are the stack areas used by gosub/return
DCB.L 4,0
channel_a_stack_start: ; Channel A stack pos
DCB.L 4,0
channel_b_stack_start: ; Channel B stack pos
DCB.L 4,0
channel_c_stack_start: ; Channel C stack pos
; Mystery unused bytes
DC.B $00,$00,$00,$00
DCB.W 4,0
channel_delay_mask:
DC.B $FF,$00
jmptable:
; Jump table to the commands.
DC.L cmd_0_start_loop ;+ 1 byte set loop
DC.L cmd_1_end_loop ;+ 0 byte
DC.L cmd_2_default_note_time ;+ 1 byte set_note_encoding
DC.L cmd_3_stop ;+ 0 byte
DC.L cmd_4_gosub ;+ 2 byte gosub_pos
DC.L cmd_5_return ;+ 0 byte return
DC.L cmd_6_set_transpose ;+ 1 byte set_transpose
DC.L cmd_7_set_raw_detune ;+ 1 byte set_period_adjust
DC.L cmd_8_direct_write ;+ 2 bytes direct reg write
DC.L cmd_9_set_adsr ;+ 3 byte
DC.L cmd_a_set_adsr_reset ;+ 1 byte
DC.L cmd_b_set_arpeggio ;+ 3 bytes
DC.L cmd_c_set_slide ;+ 1 byte
DC.L cmd_d_set_vibrato ;+ 4 bytes vibrato
DC.L cmd_e_skip_transpose ;+ 0
DC.L cmd_f_set_fixfreq ;+ 1 byte (if 0), else 4 bytes
DC.L cmd_10_jump ;+ 2 bytes jump_to_pos
DC.L cmd_11_set_mute_time ;+ 1 byte
DC.L cmd_12_set_nomute ;+ 1 byte
; Runtime variable area.
; In the update function, these are all referenced relative to "a6_base"
DC.B $00,$00
L70EC4 DCB.W 3,0
L70ECA DC.B $01,$00,$00,$00,$00,$00,$00,$00
L70ED2 DC.B $FD,$F5,$E8,$00,$00,$00,$00,$00
L70EDA: DC.B $00,$00,$01,$00
L70EDE: DC.B $00,$00,$02,$00
L70EE2 DC.B $00,$00,$05,$00,$48,$15,$37,$00
L70EEA: DC.B 0,0,0,0
L70EEE DC.B $00,$37,$01,$00,$00,$00,$00,$00
L70EF6 DC.B $07,$09,$03,$00,$00,$00,$00,$00
L70EFE DC.B $01,$01,$00,$00,$01,$01,$01,$00
L70F06 DC.B $0B,$0F,$0D,$00,$03,$00,$0A,$00
L70F0E: DC.B $00,$FB,$FE,$00
L70F12: DC.B $00,$00,$00,$00
L70F16: DC.B $00,$00,$04,$00
DC.B $00,$02,$20,$00
L70F1E DC.B $FF
L70F1F DC.B $FF
L70F20 DC.B $FF
DC.B $00,$08,$10,$20,$00
L70F26 DC.B $FC,$FC,$FE,$00,$FF,$FF,$FF,$00
L70F2E DC.B $0A,$0E,$0C,$00
L703F2 DC.B $FF
L703F3 DC.B $FF
L703F4 DC.B $FF
DC.B $00
L70F36 DC.B $00,$02,$00,$00,$00,$00,$00,$00
L70F3E DC.B $FF,$FF,$FF,$00
; This is the base area used for the runtime variables
a6_base:
L70F42:
tune_base_a DC.B $00,$07,$1F,$13 ; +0
tune_base_b DC.B $00,$07,$1F,$C3 ; +4
tune_base_c DC.B $00,$07,$1F,$73 ; +8
DCB.W 2,0
DC.B $00,$07,$1E,$8C,$00,$07,$1C,$2F
DC.B $00,$07,$1F,$6E,$00,$00,$00,$00
DCB.W 8,0
DC.B $00,$07,$0E,$48,$00,$07,$0E,$58
DC.B $00,$07,$0E,$60,$00,$00,$00,$00
DC.B $00,$00,$01,$00,$AA,$AA,$00,$00
DC.B $00,$35,$02,$38,$00,$8E,$00,$00
DC.B 0,0,0,0,0,0,0,0
DC.B 0,0
DC.B $02,$00
;a6_base+$5c
DC.B $08,$02,$20,$00,$02,$01 ; mixer info
DC.B $01,$00,$00,$00,$01,$00,$00,$00
DC.B $00,$00,$00,$01,$0A,$00,$00,$00
DC.W 0
DCB.W 390,0
tune_id: DC.B $00,$02
temp_d2_store: DC.B $00,$06
DC.B $89,$0A
tmp_swap_1: DC.B $0C
tmp_swap_2: DC.B $4A
DC.B $00,$00
; The second of these values appears to be used as alternative mixer values for
; muting.
; The first value seems to be unused.
mixer_mute_table:
DC.B $36,$09 ; %1001 force mute on noise and square
DC.B $2D,$12
DC.B $1B,$24
; Standard YM note -> period table.
; For each byte pair, the first byte is the high period value, the second
; is the low value. So the first note here (C#0) is $0eee.
; The table has 24*4 = 96 entries, or 8 octaves of 12 notes.
; (You can see the period halve for each octave.)
note_table:
DC.B $0E,$EE,$0E,$18,$0D,$4D,$0C,$8E ; Octave 0
DC.B $0B,$DA,$0B,$2F,$0A,$8F,$09,$F7
DC.B $09,$68,$08,$E1,$08,$61,$07,$E9
DC.B $07,$77,$07,$0C,$06,$A7,$06,$47 ; Octave 1
DC.B $05,$ED,$05,$98,$05,$47,$04,$FC
DC.B $04,$B4,$04,$70,$04,$31,$03,$F4
DC.B $03,$BC,$03,$86,$03,$53,$03,$24 ; Octave 2
DC.B $02,$F6,$02,$CC,$02,$A4,$02,$7E
DC.B $02,$5A,$02,$38,$02,$18,$01,$FA
DC.B $01,$DE,$01,$C3,$01,$AA,$01,$92 ; Octave 3
DC.B $01,$7B,$01,$66,$01,$52,$01,$3F
DC.B $01,$2D,$01,$1C,$01,$0C,$00,$FD
DC.B $00,$EF,$00,$E1,$00,$D5,$00,$C9 ; Octave 4
DC.B $00,$BE,$00,$B3,$00,$A9,$00,$9F
DC.B $00,$96,$00,$8E,$00,$86,$00,$7F
DC.B $00,$77,$00,$71,$00,$6A,$00,$64 ; Octave 5
DC.B $00,$5F,$00,$59,$00,$54,$00,$50
DC.B $00,$4B,$00,$47,$00,$43,$00,$3F
DC.B $00,$3C,$00,$38,$00,$35,$00,$32 ; Octave 6
DC.B $00,$2F,$00,$2D,$00,$2A,$00,$28
DC.B $00,$26,$00,$24,$00,$22,$00,$20
DC.B $00,$1E,$00,$1C,$00,$1B,$00,$19 ; Octave 7
DC.B $00,$18,$00,$16,$00,$15,$00,$14
DC.B $00,$13,$00,$12,$00,$11,$00,$10
; All the data after this is the tune.
tune_start_table:
DC.B $40,$16,$07,$0B ;Mystery header, seemingly unused.
; Offsets from tune_start_table to the data for each tune's channel, in low-endian byte-pairs.
; It looks like the valid start slots here are 0-6 (entries 7/8/9 look like dummy values)
channel_a_start_table:
DC.B $63,$02
DC.B $DA,$07 ;start 0 = $263 = 715F5
DC.B $98,$0A
DC.B $62,$02
DC.B $62,$02
DC.B $62,$02
DC.B $8B,$15
DC.B $07,$00
DC.B $08,$00
DC.B $09,$00
channel_b_start_table:
DC.B $4E,$03 ;start 0 = $34e
DC.B $60,$08
DC.B $01,$0B
DC.B $66,$0C
DC.B $68,$0E
DC.B $B8,$11
DC.B $B1,$15
DC.B $07,$00
DC.B $08,$00
DC.B $09,$00
channel_c_start_table
DC.B $45,$05
DC.B $C6,$08 ;start 0 = $545
DC.B $3D,$0B
DC.B $DB,$0C
DC.B $28,$0F
DC.B $50,$12
DC.B $D4,$15
DC.B $07,$00
DC.B $08,$00
DC.B $09,$00
; Lookup into SFX data, done in the same way as tunes.
sfx_table:
DC.B $56,$00,$5A,$00,$5E,$00,$62,$00
DC.B $6C,$00,$70,$00,$74,$00,$78,$00
DC.B $7C,$00,$80,$00,$84,$00,$00,$88
DC.B $00,$FF,$00,$A4,$00,$FF,$00,$C8
DC.B $00,$FF,$00,$E3,$00,$02,$04,$01
DC.B $04,$27,$01,$FF,$00,$4E,$01,$FF
DC.B $00,$70,$01,$FF,$00,$B3,$01,$FF
DC.B $00,$D8,$01,$FF,$00,$F6,$01,$FF
DC.B $00,$22,$02,$FF,$00,$39,$02,$FF
DC.B $8D,$01,$07,$00,$01,$91,$FF,$92
DC.B $FF,$8A,$01,$88,$07,$08,$89,$F0
DC.B $03,$01,$3C,$01,$80,$08,$41,$0A
DC.B $8A,$00,$81,$83,$8D,$00,$00,$00
DC.B $00,$91,$FF,$92,$FF,$8A,$01,$88
DC.B $07,$01,$88,$06,$1F,$89,$C0,$01
DC.B $01,$50,$0E,$89,$90,$01,$01,$50
DC.B $0E,$89,$00,$00,$01,$1E,$02,$83
DC.B $8D,$01,$01,$00,$00,$91,$FF,$92
DC.B $FF,$8A,$01,$88,$07,$08,$89,$CC
DC.B $00,$01,$50,$0A,$89,$00,$00,$01
DC.B $5A,$02,$83,$8D,$01,$01,$00,$01
DC.B $91,$FF,$92,$FF,$8A,$01,$88,$07
DC.B $08,$89,$EE,$00,$01,$4B,$1E,$88
DC.B $07,$01,$88,$06,$1F,$89,$E0,$07
DC.B $01,$5A,$80,$83,$8D,$01,$01,$00
DC.B $01,$91,$FF,$92,$FF,$8A,$01,$89
DC.B $BB,$00,$01,$88,$07,$12,$32,$0A
DC.B $88,$07,$10,$4B,$1E,$88,$07,$02
DC.B $89,$B0,$07,$01,$5A,$80,$83,$8D
DC.B $01,$01,$00,$01,$8B,$00,$00,$00
DC.B $91,$FF,$92,$FF,$8A,$01,$88,$07
DC.B $24,$89,$88,$00,$01,$32,$14,$88
DC.B $07,$20,$4B,$1E,$88,$07,$04,$89
DC.B $80,$07,$01,$5A,$80,$83,$8D,$00
DC.B $00,$00,$00,$91,$14,$92,$FF,$8A
DC.B $01,$88,$07,$08,$89,$EE,$00,$01
DC.B $80,$03,$3C,$32,$81,$91,$FF,$48
DC.B $32,$89,$00,$00,$01,$48,$04,$83
DC.B $8D,$00,$00,$00,$00,$91,$FF,$92
DC.B $FF,$8B,$00,$00,$00,$8A,$01,$88
DC.B $07,$01,$89,$EE,$00,$01,$88,$06
DC.B $0F,$50,$04,$88,$06,$1E,$50,$14
DC.B $89,$E0,$01,$02,$88,$06,$1B,$50
DC.B $04,$8A,$00,$88,$06,$19,$50,$04
DC.B $88,$06,$17,$50,$04,$88,$06,$15
DC.B $50,$04,$8A,$01,$89,$00,$00,$01
DC.B $1E,$04,$83,$8D,$00,$00,$00,$00
DC.B $8B,$00,$00,$00,$91,$06,$92,$FF
DC.B $8A,$01,$88,$07,$08,$89,$F0,$01
DC.B $01,$46,$0C,$91,$FF,$4D,$06,$48
DC.B $0C,$89,$00,$00,$01,$48,$04,$83
DC.B $8D,$01,$01,$00,$00,$91,$FF,$92
DC.B $FF,$8A,$01,$88,$07,$08,$89,$D0
DC.B $01,$01,$80,$05,$50,$06,$81,$89
DC.B $00,$00,$01,$50,$04,$83,$8D,$00
DC.B $00,$00,$00,$91,$FF,$92,$FF,$8A
DC.B $01,$88,$07,$08,$89,$C0,$03,$01
DC.B $8B,$07,$02,$02,$80,$08,$2D,$04
DC.B $8A,$00,$31,$04,$32,$04,$39,$04
DC.B $3D,$04,$3E,$04,$81,$8B,$00,$00
DC.B $00,$83,$8D,$01,$19,$00,$00,$91
DC.B $FF,$92,$FF,$8A,$01,$88,$07,$08
DC.B $89,$CC,$00,$01,$19,$0C,$90,$34
DC.B $02,$8D,$00,$00,$00,$00,$91,$FF
DC.B $92,$FF,$8A,$01,$88,$07,$08,$89
DC.B $CC,$00,$01,$14,$04,$20,$04,$2C
DC.B $04,$38,$04,$16,$04,$22,$04,$2E
DC.B $04,$3A,$04,$89,$00,$00,$01,$14
DC.B $04,$83,$83
; This is the channel data for channel A of tune 0, at offset $263
;tune_0_channel_a:
DC.B $91,$FF,$92,$FF,$8A
DC.B $01,$89,$DD,$00,$01,$88,$07,$08
DC.B $84,$1C,$07,$86,$03,$84,$2E,$07
DC.B $80,$02,$86,$02,$84,$2E,$07,$86
DC.B $FD,$84,$2E,$07,$81,$86,$00,$82
DC.B $02,$89,$F0,$02,$01,$80,$07,$84
DC.B $B4,$07,$84,$D5,$06,$84,$E6,$06
DC.B $84,$D5,$06,$84,$E6,$06,$84,$D5
DC.B $06,$84,$D5,$06,$8B,$F4,$01,$01
DC.B $81,$80,$02,$84,$C7,$07,$84,$D5
DC.B $06,$84,$E6,$06,$84,$D5,$06,$84
DC.B $E6,$06,$84,$D5,$06,$84,$D5,$06
DC.B $81,$84,$C7,$07,$86,$07,$84,$99
DC.B $06,$84,$99,$06,$84,$AA,$06,$86
DC.B $05,$84,$99,$06,$84,$99,$06,$84
DC.B $AA,$06,$80,$04,$86,$03,$84,$B4
DC.B $07,$86,$01,$84,$C7,$07,$81,$80
DC.B $02,$86,$FF,$84,$B4,$07,$86,$01
DC.B $84,$C7,$07,$81,$80,$04,$86,$03
DC.B $84,$B4,$07,$86,$01,$84,$C7,$07
DC.B $81,$8B,$00,$00,$00,$80,$02,$86
DC.B $F7,$84,$B4,$07,$86,$F5,$84,$C7
DC.B $07,$86,$F3,$84,$B4,$07,$86,$F5
DC.B $84,$C7,$07,$81,$88,$07,$09,$82
DC.B $00,$32,$0F,$88,$07,$08,$89,$BB
DC.B $00,$01,$82,$04,$80,$03,$86,$05
DC.B $84,$2E,$07,$86,$03,$84,$2E,$07
DC.B $81,$89,$B0,$0F,$01,$80,$02,$86
DC.B $05,$84,$4F,$07,$86,$03,$84,$4F
DC.B $07,$81,$88,$07,$09,$83
;tune 0 channel B start
DC.B $91,$FF
DC.B $92,$FF
DC.B $8A,$01
DC.B $88,$07,$12
DC.B $32,$0F
DC.B $88,$07,$10
DC.B $89,$AA
DC.B $00,$01