-
Notifications
You must be signed in to change notification settings - Fork 0
/
s3mcore.asm
1635 lines (1484 loc) · 45.9 KB
/
s3mcore.asm
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
; S3M player core functions
;
; (c) 1997 Firehawk/Dawn
;
; include player device interface
include s3mdev.asm
public _s3m_synchroval, _s3m_synchrocount, _s3m_loopcount
;#### DPMI_MALLOC
;#### in: ecx=bytes to allocate
;#### out: ax=descriptor, ebx=handle, CF=1 if failure
dpmi_malloc:
push edx
mov ds:[tempsize], ecx
; descriptor
xor ax, ax
mov cx, 1
int 31h
jc @@malloc_failed
mov ds:[tempsel], ax
; memory block
mov ax, 501h
mov bx, word ptr [tempsize+2]
mov cx, word ptr [tempsize]
int 31h
jc @@malloc_failed
mov word ptr [temphandle+2], si
mov word ptr [temphandle], di
; base
mov ax, 7
mov dx, cx
mov cx, bx
mov bx, ds:[tempsel]
int 31h
jc @@malloc_failed
; limit
dec ds:[tempsize]
mov ax, 8
mov bx, ds:[tempsel]
mov cx, word ptr [tempsize+2]
mov dx, word ptr [tempsize]
int 31h
jc @@malloc_failed
; return values to caller
mov ax, ds:[tempsel]
mov ebx, ds:[temphandle]
pop edx
clc
ret
@@malloc_failed:
pop edx
stc
ret
;#### DPMI_FREE
;#### in: ax=descriptor, ebx=handle
;#### out: -
dpmi_free:
push ebx
; descriptor
mov bx, ax
mov ax, 1
int 31h
jc @@free_failed
; block
pop esi
mov edi, esi
shr esi, 16
and edi, 0ffffh
mov ax, 502h
int 31h
jc @@free_failed
clc
ret
@@free_failed:
stc
ret
;#### S3M_LOADER
;#### in: es:esi=far pointer to module
;#### out: CF=1 on error
s3m_loader:
; store code dataselector for furher use (interrupt)
mov ds:[codedatasel], ds
; intialize some variables
mov _s3m_synchroval, 0
mov _s3m_synchrocount, 0
mov _s3m_loopcount, 0
mov ds:[frame], -1
mov ds:[row], 0
mov ds:[pattern], 0
mov ds:[order], 0
mov ds:[speed], 6
mov ds:[tempo], 07dh
mov ds:[globalvol], 64
; initialize order list
xor ebp, ebp
@@initialize_orders:
mov ds:[orderlist+ebp], 255
inc ebp
cmp ebp, 255
jnz @@initialize_orders
; initialize channels
xor ebp, ebp
@@initialize_channels:
mov ds:[chn_mapping+ebp], 255
mov ds:[chn_sample+ebp], 0
mov ds:[chn_panning+ebp], 7
mov ds:[chn_flags+ebp], 0
mov ds:[chn_volume+ebp], 0
mov ds:[chn_period+ebp], 0
inc ebp
cmp ebp, 32
jnz @@initialize_channels
mov ds:[moduleoffset], esi
cmp es:[esi+s3m.hdr_songtag], 'MRCS'
jnz @@loader_failure
cmp es:[esi+s3m.hdr_songtype], 16
jnz @@loader_failure
mov al, es:[esi+s3m.hdr_globalvol]
mov ds:[globalvol], al
mov al, es:[esi+s3m.hdr_initspeed]
mov ds:[speed], al
mov al, es:[esi+s3m.hdr_inittempo]
mov ds:[tempo], al
mov ax, es:[esi+s3m.hdr_insnum]
mov ds:[insnum], ax
mov ax, es:[esi+s3m.hdr_patnum]
mov ds:[patnum], ax
mov ax, es:[esi+s3m.hdr_flags]
mov ds:[s3mflags], ax
mov ds:[highestchannel], 0
mov cx, 32
xor ebx, ebx
@@loader_remaploop:
mov ds:[chn_mapping+ebx], 255
mov al, es:[esi+s3m.hdr_chanset+ebx]
cmp al, 16
jae @@loader_noremap
mov ds:[highestchannel], bl
mov ds:[chn_mapping+ebx], bl
cmp al, 7
ja @@loader_panright
mov ds:[chn_panning+ebx], 03h
jmp @@loader_noremap
@@loader_panright:
mov ds:[chn_panning+ebx], 0ch
@@loader_noremap:
inc ebx
dec cx
jnz @@loader_remaploop
inc ds:[highestchannel]
xor ebx, ebx
mov cx, es:[esi+s3m.hdr_ordnum]
mov ebp, 60h
@@loader_orderloop:
mov al, es:[esi+ebp]
inc ebp
mov ds:[orderlist+ebx], al
inc ebx
dec cx
jnz @@loader_orderloop
mov al, ds:[orderlist]
mov ds:[pattern], al
cmp es:[esi+s3m.hdr_defpanning], 0fch
jnz @@loader_nodefpan
movzx ebx, es:[esi+s3m.hdr_insnum]
movzx ecx, es:[esi+s3m.hdr_patnum]
add ebx, ecx
shl ebx, 1
movzx ecx, es:[esi+s3m.hdr_ordnum]
add ebx, ecx
add ebx, 060h
add ebx, esi
mov ecx, 32
xor ebp, ebp
@@loader_defpanloop:
mov al, es:[ebx+ebp]
and al, 0fh
mov ds:[chn_panning+ebp], al
inc ebp
dec ecx
jnz @@loader_defpanloop
@@loader_nodefpan:
test es:[esi+s3m.hdr_mastervol], 128
jnz @@loader_usestereo
mov ecx, 32
xor ebp, ebp
@@loader_panmonoloop:
mov ds:[chn_panning+ebp], 07h
inc ebp
dec ecx
jnz @@loader_panmonoloop
@@loader_usestereo:
movzx ebp, es:[esi+s3m.hdr_ordnum]
add ebp, 60h
add ebp, esi
xor ebx, ebx
@@loader_getinstruments:
movzx edi, word ptr es:[ebp+ebx*2]
shl edi, 4
mov al, es:[esi+edi.ins_type]
cmp al, 1
jnz @@loader_nosample
movzx eax, byte ptr es:[esi+edi.ins_memseg]
shl eax, 16
mov ax, word ptr es:[esi+edi.ins_memseg+1]
shl eax, 4
mov ds:[smp_mempos+ebx*4], eax ;temp ptr. to sample
mov eax, es:[esi+edi.ins_length]
mov ds:[smp_length+ebx*4], eax
mov eax, es:[esi+edi.ins_loopbeg]
mov ds:[smp_loopbeg+ebx*4], eax
mov eax, es:[esi+edi.ins_loopend]
mov ds:[smp_loopend+ebx*4], eax
mov al, es:[esi+edi.ins_volume]
mov ds:[smp_volume+ebx], al
mov al, es:[esi+edi.ins_flags]
mov ds:[smp_flags+ebx], al
mov eax, es:[esi+edi.ins_c2spd]
mov ds:[smp_c2spd+ebx*4], eax
mov al, es:[esi+edi.ins_type]
mov ds:[smp_type+ebx], al
@@loader_nosample:
inc ebx
movzx eax, es:[esi+s3m.hdr_insnum]
cmp ebx, eax
jnz @@loader_getinstruments
;swap module offset register
mov edx, esi
;allocate memory for pattern
movzx ecx, es:[edx+s3m.hdr_patnum]
imul ecx, ecx, 64*32*5
call dpmi_malloc
jc @@loader_failure
mov ds:[pattsel], ax
mov ds:[patthandle], ebx
;clear pattern
push gs
movzx ecx, es:[edx+s3m.hdr_patnum]
imul ecx, ecx, 64*32
mov gs, ds:[pattsel]
xor ebx, ebx
@@loader_inipatt:
mov byte ptr gs:[ebx], 255
mov dword ptr gs:[ebx+1], 00ffff00h
add ebx, 5
dec ecx
jnz @@loader_inipatt
pop gs
push gs
movzx ebp, es:[edx+s3m.hdr_insnum]
shl ebp, 1
movzx eax, es:[edx+s3m.hdr_ordnum]
add ebp, eax
add ebp, 60h
add ebp, edx ;!!!!!!!!!!!
xor ebx, ebx
mov gs, ds:[pattsel]
@@loader_getpatterns:
movzx esi, word ptr es:[ebp+ebx*2]
shl esi, 4
imul edi, ebx, 64*32*5
push ebp
push ebx
add esi, 2
xor ecx, ecx ; ecx=row
@@loader_noteloop:
mov al, es:[edx+esi] ; al=noteinfo
inc esi
cmp al, 0 ; al=0, rowend
jz @@loader_rowok
movzx ebx, al
and ebx, 31
imul ebx, ebx, 5 ; ebx=channel*5
test al, 32
jz @@loader_testvol
mov ah, es:[edx+esi] ;note
mov gs:[edi+ebx], ah
inc esi
mov ah, es:[edx+esi] ;instr
mov gs:[edi+ebx+1], ah
inc esi
@@loader_testvol:
test al, 64
jz @@loader_testfx
mov ah, es:[edx+esi] ;vol
mov gs:[edi+ebx+2], ah
inc esi
@@loader_testfx:
test al, 128
jz @@loader_noteok
mov ah, es:[edx+esi] ;fx
mov gs:[edi+ebx+3], ah
inc esi
mov ah, es:[edx+esi] ;infobyte
mov gs:[edi+ebx+4], ah
inc esi
@@loader_noteok:
jmp @@loader_noteloop
@@loader_rowok:
add edi, 32*5
inc ecx
cmp ecx, 64
jnz @@loader_noteloop
pop ebx
pop ebp
inc ebx
movzx eax, es:[edx+s3m.hdr_patnum]
cmp ebx, eax
jnz @@loader_getpatterns
pop gs
xor ebp, ebp
@@loader_uploadsample:
cmp ds:[smp_type+ebp], 1
jnz @@loader_skipsample
mov esi, ds:[smp_mempos+ebp*4]
add esi, edx
push edx
call s3m_sd_loadsample
pop edx
@@loader_skipsample:
inc ebp
movzx eax, es:[edx+s3m.hdr_insnum]
cmp ebp, eax
jnz @@loader_uploadsample
; send pannings to device??
; TODO
movzx eax, ds:[orderlist]
mov ds:[pattern], al
imul eax, eax, 64*32*5
mov ds:[rowoffset], eax
; done..
clc
ret
@@loader_failure:
stc
ret
;#### S3M_TRACKFRAME
;#### in: -
;#### out: -
s3m_trackframe:
push ds
push es
mov es, cs:[pattsel]
mov ds, cs:[codedatasel]
inc ds:[frame]
mov al, ds:[speed]
cmp ds:[frame], al
jb @@trackframe_patternok
mov ds:[frame], 0
cmp ds:[plr_pattdelay], 0 ;!!
jnz @@trackframe_calcnewrow ;!!
inc ds:[row]
@@trackframe_calcnewrow:
add ds:[rowoffset], 32*5
@@trackframe_testpattern:
cmp ds:[row], 64
jb @@trackframe_patternok
@@trackframe_nextpattern:
mov ds:[plr_pattlooprow], 0
mov ds:[plr_pattloopnbr], 0
mov ds:[row], 0
inc ds:[order]
movzx ebx, ds:[order]
mov al, ds:[orderlist+ebx]
mov ds:[pattern], al
cmp ds:[pattern], 254
jz @@trackframe_nextpattern
cmp ds:[pattern], 255
jnz @@trackframe_patternok
mov ds:[order], -1
inc _s3m_loopcount
jmp @@trackframe_nextpattern
@@trackframe_patternok:
cmp ds:[frame], 0
jnz @@trackframe_processfx
cmp ds:[plr_pattdelay], 0 ;!!
jz @@trackframe_nodelay ;!!
dec ds:[plr_pattdelay] ;!!
jmp @@trackframe_skipupdate ;!!
@@trackframe_nodelay:
movzx eax, ds:[pattern]
imul eax, eax, 64*32*5
mov ds:[rowoffset], eax
movzx eax, ds:[row]
imul eax, eax, 32*5
add ds:[rowoffset], eax
mov esi, ds:[rowoffset]
mov ds:[plr_flags], 0
xor ebp, ebp
@@trackframe_loopchannels:
push ebp
cmp ds:[chn_mapping+ebp], 255
jz @@trackframe_skipchannel
mov ds:[chn_flags+ebp], 0
; skip the whole thing if the effect is SDx
cmp byte ptr es:[esi+3], 19 ;S..
jnz @@trackframe_check
mov al, es:[esi+4]
shr al, 4
cmp al, 0dh ;Dx
jz @@trackframe_checkeffect
@@trackframe_check:
movzx eax, byte ptr es:[esi+1]
cmp al, 0
jz @@trackframe_checkvolume
dec eax
mov ds:[chn_sample+ebp], al
mov al, ds:[smp_volume+eax]
mov ds:[chn_volume+ebp], al
or ds:[chn_flags+ebp], CHN_NEWVOLUME
@@trackframe_checkvolume:
mov al, es:[esi+2]
cmp al, 255
jz @@trackframe_checknote
mov ds:[chn_volume+ebp], al
or ds:[chn_flags+ebp], CHN_NEWVOLUME
@@trackframe_checknote:
movzx eax, byte ptr es:[esi]
cmp al, 0ffh
jz @@trackframe_checkeffect
cmp al, 0feh
jz @@trackframe_noteoff
mov ah, es:[esi+3]
cmp ah, 7 ; tone portamento
jz @@trackframe_checkeffect
cmp ah, 12 ; porta+volslide
jz @@trackframe_checkeffect
mov ecx, eax
and eax, 0fh ;note
shr ecx, 4 ;octave
and ecx, 0fh
imul ecx, ecx, 12
add ecx, eax
mov ds:[chn_arpnote+ebp], cl
mov al, cl
movzx eax, al
movzx eax, ds:[periodtab+eax*2]
imul eax, eax, 8363
movzx ecx, byte ptr ds:[chn_sample+ebp]
mov ecx, ds:[smp_c2spd+ecx*4]
xor edx, edx
div ecx
mov ds:[chn_period+ebp*2], ax
mov ds:[chn_vibratopos+ebp], 0
or ds:[chn_flags+ebp], CHN_NEWPITCH+CHN_TRIGSAMPLE
jmp @@trackframe_checkeffect
@@trackframe_noteoff:
or ds:[chn_flags+ebp], CHN_NOTEOFF
@@trackframe_checkeffect:
movzx eax, byte ptr es:[esi+3]
cmp al, 255
jz @@trackframe_skipchannel
cmp al, 0
jz @@trackframe_skipchannel
dec eax
mov edi, ds:[effect_jump_f0+eax*4]
mov bl, es:[esi+4]
call edi
@@trackframe_skipchannel:
add esi, 5
pop ebp
inc ebp
movzx eax, ds:[highestchannel]
cmp ebp, eax
jb @@trackframe_loopchannels
@@trackframe_skipupdate:
pop es
pop ds
ret
@@trackframe_processfx:
mov esi, ds:[rowoffset]
xor ebp, ebp
@@trackframe_loopchannelsfx:
push ebp
mov ds:[chn_flags+ebp], 0 ; clear channel flags
movzx eax, byte ptr es:[esi+3]
cmp al, 255
jz @@trackframe_skipchannelfx
cmp al, 0
jz @@trackframe_skipchannelfx
dec eax
mov edi, ds:[effect_jump_fn+eax*4]
mov bl, es:[esi+4]
call edi
@@trackframe_skipchannelfx:
add esi, 5
pop ebp
inc ebp
movzx eax, ds:[highestchannel]
cmp ebp, eax
jb @@trackframe_loopchannelsfx
pop es
pop ds
ret
;#### EFFECT_F0_?
;#### in: bl=infobyte
;#### out: -
effect_f0_a:
mov ds:[speed], bl
ret
effect_f0_b:
test ds:[plr_flags], PLR_PATTJUMP
jnz @@effect_f0_b_out
and ebx, 0ffh
mov ds:[order], bl
mov al, ds:[orderlist+ebx]
mov ds:[pattern], al
mov ds:[row], -1
or ds:[plr_flags], PLR_PATTJUMP
mov ds:[plr_pattlooprow], 0 ;!!
mov ds:[plr_pattloopnbr], 0 ;!!
@@effect_f0_b_out:
ret
effect_f0_c:
mov al, bl
and eax, 0fh
shr ebx, 4
and ebx, 0fh
imul ebx, ebx, 10
add eax, ebx
mov ds:[row], al
dec ds:[row]
cmp ds:[row], 62
jna @@effect_f0_c_order
mov ds:[row], -1
@@effect_f0_c_order:
mov ds:[plr_pattlooprow], 0 ;!!
mov ds:[plr_pattloopnbr], 0 ;!!
test ds:[plr_flags], PLR_PATTJUMP+PLR_PATTBREAK
jnz @@effect_f0_c_out
inc ds:[order]
movzx ebx, ds:[order]
mov al, ds:[orderlist+ebx]
mov ds:[pattern], al
cmp ds:[pattern], 254
jz @@effect_f0_c_order
cmp ds:[pattern], 255
jnz @@effect_f0_c_out
mov ds:[order], -1
jmp @@effect_f0_c_order
@@effect_f0_c_out:
or ds:[plr_flags], PLR_PATTBREAK
ret
effect_f0_d:
cmp bl, 0
jz @@effect_f0_d_fine
mov ds:[chn_volslide+ebp], bl
@@effect_f0_d_fine:
mov al, ds:[chn_volslide+ebp]
mov bl, al
and bl, 0fh
cmp bl, 0fh
jz @@effect_f0_d_fine_up
mov bl, al
shr bl, 4
cmp bl, 0fh
jnz @@effect_f0_d_checkold
@@effect_f0_d_fine_down:
and al, 0fh
sub ds:[chn_volume+ebp], al
cmp ds:[chn_volume+ebp], 0
jge @@effect_f0_d_fine_ok
mov ds:[chn_volume+ebp], 0
jmp @@effect_f0_d_fine_ok
@@effect_f0_d_fine_up:
shr al, 4
add ds:[chn_volume+ebp], al
cmp ds:[chn_volume+ebp], 63
jle @@effect_f0_d_fine_ok
mov ds:[chn_volume+ebp], 63
jmp @@effect_f0_d_fine_ok
@@effect_f0_d_checkold:
test ds:[s3mflags], 64
jz @@effect_f0_d_out
call effect_fn_d
@@effect_f0_d_fine_ok:
or ds:[chn_flags+ebp], CHN_NEWVOLUME
@@effect_f0_d_out:
ret
effect_f0_e:
cmp bl, 0
jz @@effect_f0_e_fineslide
mov ds:[chn_portaspeed+ebp], bl
@@effect_f0_e_fineslide:
mov al, ds:[chn_portaspeed+ebp]
mov bl, al
and bx, 0fh
test bl, 0e0h
jz @@effect_f0_e_extrafine
@@effect_f0_e_fine:
test al, 0f0h
jnz @@effect_f0_e_out
shl bl, 2
@@effect_f0_e_extrafine:
add ds:[chn_period+ebp*2], bx
cmp word ptr ds:[chn_period+ebp*2], 27392
jle @@effect_f0_e_fine_ok
;too large period, stop voice
mov ds:[chn_period+ebp*2], 27392
or ds:[chn_flags+ebp], CHN_NOTEOFF
@@effect_f0_e_fine_ok:
or ds:[chn_flags+ebp], CHN_NEWPITCH
@@effect_f0_e_out:
ret
effect_f0_f:
cmp bl, 0
jz @@effect_f0_f_fineslide
mov ds:[chn_portaspeed+ebp], bl
@@effect_f0_f_fineslide:
mov al, ds:[chn_portaspeed+ebp]
mov bl, al
and bx, 0fh
test bl, 0e0h
jz @@effect_f0_f_extrafine
@@effect_f0_f_fine:
test al, 0f0h
jnz @@effect_f0_f_out
shl bl, 2
@@effect_f0_f_extrafine:
sub ds:[chn_period+ebp*2], bx
cmp word ptr ds:[chn_period+ebp*2], 56
jge @@effect_f0_f_fine_ok
; period too small, stop voice
mov ds:[chn_period+ebp*2], 56
or ds:[chn_flags+ebp], CHN_NOTEOFF
@@effect_f0_f_fine_ok:
or ds:[chn_flags+ebp], CHN_NEWPITCH
@@effect_f0_f_out:
ret
effect_f0_g:
mov al, es:[esi]
cmp al, 254
jae @@effect_f0_g_speed
mov cl, al
and eax, 0fh ;note
shr cl, 4
and ecx, 0fh ;octave
imul ecx, ecx, 12
add eax, ecx
movzx eax, al
movzx eax, ds:[periodtab+eax*2]
imul eax, eax, 8363
movzx ecx, byte ptr ds:[chn_sample+ebp]
mov ecx, ds:[smp_c2spd+ecx*4]
xor edx, edx
div ecx
mov ds:[chn_portaperiod+ebp*2], ax
@@effect_f0_g_speed:
mov al, bl
cmp al, 0
jz @@effect_f0_g_out
mov ds:[chn_portaspeed+ebp], al
@@effect_f0_g_out:
ret
effect_f0_h:
; and ds:[chn_flags+ebp], not chn_newfreq
mov al, bl
and al, 0fh ;depth
shr bl, 4 ;speed
cmp al, 0
jz @@effect_f0_h_chkspeed
mov ds:[chn_vibratodep+ebp], al
@@effect_f0_h_chkspeed:
cmp bl, 0
jz @@effect_f0_h_out
mov ds:[chn_vibratospd+ebp], bl
@@effect_f0_h_out:
ret
effect_f0_i:
;tremor
ret
effect_f0_j:
mov al, bl
cmp al, 0
jz @@effect_f0_j_playarp
mov ds:[chn_arpchord+ebp], al
@@effect_f0_j_playarp:
mov al, ds:[chn_arpnote+ebp]
movzx eax, al
shl eax, 1
movzx eax, ds:[periodtab+eax]
imul eax, eax, 8363
movzx ecx, ds:[chn_sample+ebp]
mov ecx, ds:[smp_c2spd+ecx*4]
xor edx, edx
div ecx
movzx ebx, ax
mov ds:[chn_fxperiod+ebp*2], bx
or ds:[chn_flags+ebp], CHN_PITCHEFFECT
ret
effect_f0_k:
call effect_f0_d
ret
effect_f0_l:
push bx
mov al, es:[esi]
cmp al, 254
jae @@effect_f0_l_d
mov cl, al
and eax, 0fh ;note
shr cl, 4
and ecx, 0fh ;octave
imul ecx, ecx, 12
add eax, ecx
movzx eax, al
movzx eax, ds:[periodtab+eax*2]
imul eax, eax, 8363
movzx ecx, byte ptr ds:[chn_sample+ebp]
mov ecx, ds:[smp_c2spd+ecx*4]
xor edx, edx
div ecx
mov ds:[chn_portaperiod+ebp*2], ax
@@effect_f0_l_d:
pop bx
call effect_f0_d
ret
effect_f0_m:
; not used
ret
effect_f0_n:
; not used
ret
effect_f0_o:
or ds:[chn_flags+ebp], CHN_USEOFFSET
cmp bl, 0
jz @@effect_f0_o_out
and ebx, 0ffh
shl ebx, 8
movzx eax, ds:[chn_sample+ebp]
; cmp ebx, ds:[smp_loopend+eax*4]
cmp ebx, ds:[smp_length+eax*4]
jbe @@effect_f0_o_ok
mov ebx, ds:[smp_loopend+eax*4]
@@effect_f0_o_ok:
mov ds:[chn_offset+ebp*4], ebx
@@effect_f0_o_out:
ret
effect_f0_p:
; not used
ret
effect_f0_q:
;store retrig parameters if bl!=0
cmp bl, 0
jz @@effect_f0_q_oldparam
mov ds:[chn_retrdelay+ebp], bl
mov ds:[chn_retrvolchg+ebp], bl
and ds:[chn_retrdelay+ebp], 0fh
shr ds:[chn_retrvolchg+ebp], 4
; run retrig right away if necessary
@@effect_f0_q_oldparam:
call effect_fn_q
ret
effect_f0_r:
; tremolo
ret
effect_f0_s:
; special commands S0x-SFx
movzx eax, bl
shr eax, 4
mov edi, ds:[effect_jump_s0+eax*4]
and bl, 0fh
call edi
ret
effect_f0_t:
cmp bl, 0
jz @@effect_f0_t_out
mov ds:[tempo], bl
or ds:[plr_flags], PLR_NEWBPM
@@effect_f0_t_out:
ret
effect_f0_u:
; fine vibrato
ret
effect_f0_v:
; set global volume
mov ds:[globalvol], bl
ret
effect_f0_w:
; used for synchronizing to music
mov _s3m_synchroval, bl
inc _s3m_synchrocount
ret
effect_f0_x:
; not used
ret
effect_f0_y:
; not used
ret
effect_f0_z:
; not used
ret
;#### EFFECT_FN_?
;#### in: bl=infobyte
;#### out: -
effect_fn_a:
; nothing here
ret
effect_fn_b:
; nothing here
ret
effect_fn_c:
; nothing here
ret
effect_fn_d:
mov al, ds:[chn_volslide+ebp]
mov bl, al
and bl, 0fh
cmp bl, 0
jz @@effect_fn_d_slide_up
mov bl, al
shr bl, 4
cmp bl, 0
jnz @@effect_fn_d_out
@@effect_fn_d_slide_down:
and al, 0fh
sub ds:[chn_volume+ebp], al
cmp ds:[chn_volume+ebp], 0
jge @@effect_fn_d_ok
mov ds:[chn_volume+ebp], 0
jmp @@effect_fn_d_ok
@@effect_fn_d_slide_up:
shr al, 4
add ds:[chn_volume+ebp], al
cmp ds:[chn_volume+ebp], 63
jle @@effect_fn_d_ok
mov ds:[chn_volume+ebp], 63
@@effect_fn_d_ok:
mov bl, ds:[chn_volume+ebp]
or ds:[chn_flags+ebp], CHN_NEWVOLUME
@@effect_fn_d_out:
ret
effect_fn_e:
movzx ax, byte ptr ds:[chn_portaspeed+ebp]
cmp ax, 0e0h
jae @@effect_fn_e_out
shl ax, 2
add ds:[chn_period+ebp*2], ax
cmp word ptr ds:[chn_period+ebp*2], 27392
jle @@effect_fn_e_ok
;too large period, stop voice
mov ds:[chn_period+ebp*2], 27392
or ds:[chn_flags+ebp], CHN_NOTEOFF
@@effect_fn_e_ok:
or ds:[chn_flags+ebp], CHN_NEWPITCH
@@effect_fn_e_out:
ret
effect_fn_f:
movzx ax, byte ptr ds:[chn_portaspeed+ebp]
cmp ax, 0e0h
jae @@effect_fn_f_out
shl ax, 2
sub ds:[chn_period+ebp*2], ax
cmp word ptr ds:[chn_period+ebp*2], 56
jge @@effect_fn_f_ok
;too small period, stop voice
mov ds:[chn_period+ebp*2], 56
or ds:[chn_flags+ebp], CHN_NOTEOFF
@@effect_fn_f_ok:
or ds:[chn_flags+ebp], CHN_NEWPITCH
@@effect_fn_f_out:
ret
effect_fn_g:
movzx bx, byte ptr ds:[chn_portaspeed+ebp]
shl bx, 2
mov ax, word ptr ds:[chn_portaperiod+ebp*2]
cmp word ptr ds:[chn_period+ebp*2], ax
jb @@effect_f0_g_incperiod
sub word ptr ds:[chn_period+ebp*2], bx
cmp word ptr ds:[chn_period+ebp*2], ax
jnl @@effect_f0_g_ok
mov word ptr ds:[chn_period+ebp*2], ax
jmp @@effect_f0_g_ok
@@effect_f0_g_incperiod:
add word ptr ds:[chn_period+ebp*2], bx
cmp word ptr ds:[chn_period+ebp*2], ax
jng @@effect_f0_g_ok
mov word ptr ds:[chn_period+ebp*2], ax
@@effect_f0_g_ok:
or ds:[chn_flags+ebp], CHN_NEWPITCH
ret
effect_fn_h:
mov al, ds:[chn_vibratopos+ebp]
and eax, 31 ;quotient of divide by 32
movzx ebx, ds:[vibratotab+eax] ;sine
movzx eax, ds:[chn_vibratodep+ebp] ;depth
imul ebx, eax
shr ebx, 7
shl ebx, 2 ;bx=delta
and ebx, 0ffffh
cmp ds:[chn_vibratopos+ebp], 32
jb @@effect_fn_h_addfreq
neg bx
@@effect_fn_h_addfreq:
add bx, ds:[chn_period+ebp*2]
mov ds:[chn_fxperiod+ebp*2], bx
or ds:[chn_flags+ebp], CHN_PITCHEFFECT
@@player_fx_Hxy_incpos:
mov al, ds:[chn_vibratospd+ebp]
add ds:[chn_vibratopos+ebp], al
cmp ds:[chn_vibratopos+ebp], 64
jb @@effect_fn_h_out
sub ds:[chn_vibratopos+ebp], 64
@@effect_fn_h_out:
ret
effect_fn_i:
; tremor
ret
effect_fn_j:
movzx ax, byte ptr ds:[frame]
mov bl, 3
div bl ;ah=frame mod 3
cmp ah, 0
jz @@effect_fn_j_firsttone
cmp ah, 1
jz @@effect_fn_j_secondtone
@@effect_fn_j_thirdtone:
mov al, ds:[chn_arpchord+ebp]
and al, 0fh
add al, ds:[chn_arpnote+ebp]
jmp @@effect_fn_j_playtone
@@effect_fn_j_secondtone:
mov al, ds:[chn_arpchord+ebp]