-
Notifications
You must be signed in to change notification settings - Fork 0
/
iloaders.inc
8318 lines (7365 loc) · 265 KB
/
iloaders.inc
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
{
function check_byte(var data; _byte: Byte; size: Longint): Boolean;
procedure import_old_a2m_event1(patt,line,chan: Byte; old_chunk: tOLD_CHUNK;
processing_whole_song: Boolean);
procedure replace_old_adsr(patterns: Byte);
procedure import_old_a2m_patterns1(block: Byte; count: Byte);
procedure import_old_a2m_event2(patt,line,chan: Byte; old_chunk: tOLD_CHUNK);
procedure import_old_a2m_patterns2(block: Byte; count: Byte);
procedure import_old_flags;
procedure import_old_songdata(old_songdata: pOLD_FIXED_SONGDATA);
procedure import_old_instruments(old_songdata: pOLD_FIXED_SONGDATA;
new_songdata: pFIXED_SONGDATA;
instr,count: Byte);
procedure import_single_old_instrument(old_songdata: pOLD_FIXED_SONGDATA;
pos,instr: Byte);
function insert_command(cmd,cmd2: Word; patterns: Byte; chan: Byte; exceptions: tByteSet): Boolean;
procedure a2m_file_loader;
procedure a2t_file_loader;
procedure a2p_file_loader;
function dec2hex(dec: Byte): Byte;
function truncate_string(str: String): String;
procedure amd_file_loader;
procedure import_cff_event(patt,line,chan,byte0,byte1,byte2: Byte);
procedure import_cff_patterns(var data; patterns: Byte);
procedure cff_file_loader;
procedure import_standard_instrument(inst: Byte; var data);
procedure dfm_file_loader;
procedure import_hsc_event(patt,line,chan: Byte; event: Word);
procedure import_hsc_patterns(var data; patterns: Byte);
procedure import_hsc_instrument(inst: Byte; var data);
procedure hsc_file_loader;
procedure mtk_file_loader;
procedure rad_file_loader;
procedure fix_s3m_commands(patterns: Byte);
procedure fix_single_pattern(patt: Byte);
procedure s3m_file_loader;
procedure fix_fmk_commands(patterns: Byte);
procedure import_fin_instrument(inst: Byte; var data);
procedure fmk_file_loader;
procedure import_sat_instrument(inst: Byte; var data);
function import_sat_instrument_name(var data; inst: Byte): String;
procedure sat_file_loader;
function _sal(op1,op2: Word): Byte;
function _sar(op1,op2: Word): Byte;
procedure import_sa2_effect(effect,def1,def2: Byte;
var out1,out2: Byte);
procedure sa2_file_loader;
}
function check_byte(var data; _byte: Byte; size: Longint): Boolean;
var
result: Boolean;
begin
asm
mov edi,[data]
mov ecx,size
jecxz @@1
mov al,_byte
repnz scasb
jnz @@1
mov result,TRUE
jmp @@2
@@1: mov result,FALSE
@@2:
end;
check_byte := result;
end;
var
adsr_carrier: array[1..9] of Boolean;
procedure import_old_a2m_event1(patt,line,chan: Byte; old_chunk: tOLD_CHUNK;
processing_whole_song: Boolean);
const
fx_Arpeggio = $00;
fx_FSlideUp = $01;
fx_FSlideDown = $02;
fx_FSlideUpFine = $03;
fx_FSlideDownFine = $04;
fx_TonePortamento = $05;
fx_TPortamVolSlide = $06;
fx_Vibrato = $07;
fx_VibratoVolSlide = $08;
fx_SetOpIntensity = $09;
fx_SetInsVolume = $0a;
fx_PatternBreak = $0b;
fx_PatternJump = $0c;
fx_SetTempo = $0d;
fx_SetTimer = $0e;
fx_Extended = $0f;
fx_ex_DefAMdepth = $00;
fx_ex_DefVibDepth = $01;
fx_ex_DefWaveform = $02;
fx_ex_ManSlideUp = $03;
fx_ex_ManSlideDown = $04;
fx_ex_VSlideUp = $05;
fx_ex_VSlideDown = $06;
fx_ex_VSlideUpFine = $07;
fx_ex_VSlideDownFine = $08;
fx_ex_RetrigNote = $09;
fx_ex_SetAttckRate = $0a;
fx_ex_SetDecayRate = $0b;
fx_ex_SetSustnLevel = $0c;
fx_ex_SetReleaseRate = $0d;
fx_ex_SetFeedback = $0e;
fx_ex_ExtendedCmd = $0f;
var
chunk: tCHUNK;
begin
FillChar(chunk,SizeOf(chunk),0);
chunk.note := old_chunk.note;
chunk.instr_def := old_chunk.instr_def;
chunk.effect_def := old_chunk.effect_def;
chunk.effect := old_chunk.effect;
Case old_chunk.effect_def of
fx_Arpeggio: chunk.effect_def := ef_Arpeggio;
fx_FSlideUp: chunk.effect_def := ef_FSlideUp;
fx_FSlideDown: chunk.effect_def := ef_FSlideDown;
fx_FSlideUpFine: chunk.effect_def := ef_FSlideUpFine;
fx_FSlideDownFine: chunk.effect_def := ef_FSlideDownFine;
fx_TonePortamento: chunk.effect_def := ef_TonePortamento;
fx_TPortamVolSlide: chunk.effect_def := ef_TPortamVolSlide;
fx_Vibrato: chunk.effect_def := ef_Vibrato;
fx_VibratoVolSlide: chunk.effect_def := ef_VibratoVolSlide;
fx_SetInsVolume: chunk.effect_def := ef_SetInsVolume;
fx_PatternJump: chunk.effect_def := ef_PositionJump;
fx_PatternBreak: chunk.effect_def := ef_PatternBreak;
fx_SetTempo: chunk.effect_def := ef_SetSpeed;
fx_SetTimer: chunk.effect_def := ef_SetTempo;
fx_SetOpIntensity:
If (old_chunk.effect DIV 16 <> 0) then
begin
chunk.effect_def := ef_SetCarrierVol;
chunk.effect := 3+(old_chunk.effect DIV 16)*4;
end
else If (old_chunk.effect MOD 16 <> 0) then
begin
chunk.effect_def := ef_SetModulatorVol;
chunk.effect := 3+(old_chunk.effect MOD 16)*4;
end
else chunk.effect_def := 0;
fx_Extended:
Case old_chunk.effect DIV 16 of
fx_ex_DefAMdepth:
begin
chunk.effect_def := ef_Extended;
chunk.effect := ef_ex_SetTremDepth*16+old_chunk.effect MOD 16;
end;
fx_ex_DefVibDepth:
begin
chunk.effect_def := ef_Extended;
chunk.effect := ef_ex_SetVibDepth*16+old_chunk.effect MOD 16;
end;
fx_ex_DefWaveform:
begin
chunk.effect_def := ef_SetWaveform;
Case old_chunk.effect MOD 16 of
0..3: chunk.effect := (old_chunk.effect MOD 16)*16+$0f;
4..7: chunk.effect := $0f0+(old_chunk.effect MOD 16)-4;
end;
end;
fx_ex_VSlideUp:
begin
chunk.effect_def := ef_VolSlide;
chunk.effect := (old_chunk.effect MOD 16)*16;
end;
fx_ex_VSlideDown:
begin
chunk.effect_def := ef_VolSlide;
chunk.effect := old_chunk.effect MOD 16;
end;
fx_ex_VSlideUpFine:
begin
chunk.effect_def := ef_VolSlideFine;
chunk.effect := (old_chunk.effect MOD 16)*16;
end;
fx_ex_VSlideDownFine:
begin
chunk.effect_def := ef_VolSlideFine;
chunk.effect := old_chunk.effect MOD 16;
end;
fx_ex_ManSlideUp:
begin
chunk.effect_def := ef_Extended2;
chunk.effect := ef_ex2_FineTuneUp*16+old_chunk.effect MOD 16;
end;
fx_ex_ManSlideDown:
begin
chunk.effect_def := ef_Extended2;
chunk.effect := ef_ex2_FineTuneDown*16+old_chunk.effect MOD 16;
end;
fx_ex_RetrigNote:
begin
chunk.effect_def := ef_RetrigNote;
chunk.effect := SUCC(old_chunk.effect MOD 16);
end;
fx_ex_SetAttckRate:
begin
chunk.effect_def := ef_Extended;
chunk.effect := old_chunk.effect MOD 16;
If NOT adsr_carrier[chan] then
Inc(chunk.effect,ef_ex_SetAttckRateM*16)
else Inc(chunk.effect,ef_ex_SetAttckRateC*16);
end;
fx_ex_SetDecayRate:
begin
chunk.effect_def := ef_Extended;
chunk.effect := old_chunk.effect MOD 16;
If NOT adsr_carrier[chan] then
Inc(chunk.effect,ef_ex_SetDecayRateM*16)
else Inc(chunk.effect,ef_ex_SetDecayRateC*16);
end;
fx_ex_SetSustnLevel:
begin
chunk.effect_def := ef_Extended;
chunk.effect := old_chunk.effect MOD 16;
If NOT adsr_carrier[chan] then
Inc(chunk.effect,ef_ex_SetSustnLevelM*16)
else Inc(chunk.effect,ef_ex_SetSustnLevelC*16);
end;
fx_ex_SetReleaseRate:
begin
chunk.effect_def := ef_Extended;
chunk.effect := old_chunk.effect MOD 16;
If NOT adsr_carrier[chan] then
Inc(chunk.effect,ef_ex_SetRelRateM*16)
else Inc(chunk.effect,ef_ex_SetRelRateC*16);
end;
fx_ex_SetFeedback:
begin
chunk.effect_def := ef_Extended;
chunk.effect := ef_ex_SetFeedback*16+old_chunk.effect MOD 16;
end;
fx_ex_ExtendedCmd:
If (old_chunk.effect MOD 16 in [0..9]) then
begin
chunk.effect_def := ef_Extended;
chunk.effect := ef_ex_ExtendedCmd2*16;
Case old_chunk.effect MOD 16 of
0: Inc(chunk.effect,ef_ex_cmd2_RSS);
1: Inc(chunk.effect,ef_ex_cmd2_LockVol);
2: Inc(chunk.effect,ef_ex_cmd2_UnlockVol);
3: Inc(chunk.effect,ef_ex_cmd2_LockVP);
4: Inc(chunk.effect,ef_ex_cmd2_UnlockVP);
5: begin
If processing_whole_song then chunk.effect_def := 255
else chunk.effect_def := 0;
chunk.effect := 0;
adsr_carrier[chan] := TRUE;
end;
6: begin
If processing_whole_song then chunk.effect_def := 255
else chunk.effect_def := 0;
If processing_whole_song then chunk.effect := 1
else chunk.effect := 0;
adsr_carrier[chan] := FALSE;
end;
7: Inc(chunk.effect,ef_ex_cmd2_VSlide_car);
8: Inc(chunk.effect,ef_ex_cmd2_VSlide_mod);
9: Inc(chunk.effect,ef_ex_cmd2_VSlide_def);
end;
end
else begin
chunk.effect_def := 0;
chunk.effect := 0;
end;
end;
end;
put_chunk(patt,line,chan,chunk);
end;
procedure replace_old_adsr(patterns: Byte);
var
chunk,chunk2: tCHUNK;
temp2,temp3: Byte;
patt_break: Byte;
order,patt: Byte;
patts: String;
begin
patts := '';
FillChar(adsr_carrier,SizeOf(adsr_carrier),0);
order := 0; patt := BYTE_NULL;
Repeat
If (songdata.pattern_order[order] >= $80) then Inc(order)
else
begin
patt := songdata.pattern_order[order];
patt_break := BYTE_NULL;
For temp2 := 0 to $3f do
For temp3 := 1 to 9 do
begin
get_chunk(patt,temp2,temp3,chunk);
chunk2 := chunk;
If (chunk.effect_def in [ef_PositionJump,ef_PatternBreak]) then
patt_break := temp2;
If (chunk.effect_def in [$ff,ef_Extended]) then
begin
If (chunk.effect_def = $ff) then
begin
chunk2.effect_def := 0;
chunk2.effect := 0;
If (temp2 <= patt_break) then
Case chunk.effect of
0: adsr_carrier[temp3] := TRUE;
1: adsr_carrier[temp3] := FALSE;
end;
end;
If (chunk.effect_def = ef_Extended) then
Case chunk.effect DIV 16 of
ef_ex_SetAttckRateM,
ef_ex_SetAttckRateC:
If adsr_carrier[temp3] then
chunk2.effect := ef_ex_SetAttckRateC*16+chunk.effect MOD 16
else chunk2.effect := ef_ex_SetAttckRateM*16+chunk.effect MOD 16;
ef_ex_SetDecayRateM,
ef_ex_SetDecayRateC:
If adsr_carrier[temp3] then
chunk2.effect := ef_ex_SetDecayRateC*16+chunk.effect MOD 16
else chunk2.effect := ef_ex_SetDecayRateM*16+chunk.effect MOD 16;
ef_ex_SetSustnLevelM,
ef_ex_SetSustnLevelC:
If adsr_carrier[temp3] then
chunk2.effect := ef_ex_SetSustnLevelC*16+chunk.effect MOD 16
else chunk2.effect := ef_ex_SetSustnLevelM*16+chunk.effect MOD 16;
ef_ex_SetRelRateM,
ef_ex_SetRelRateC:
If adsr_carrier[temp3] then
chunk2.effect := ef_ex_SetRelRateC*16+chunk.effect MOD 16
else chunk2.effect := ef_ex_SetRelRateM*16+chunk.effect MOD 16;
end;
If (Pos(CHR(songdata.pattern_order[order]),patts) = 0) then
If (chunk.effect_def <> chunk2.effect_def) or
(chunk.effect <> chunk2.effect) then
put_chunk(patt,temp2,temp3,chunk2);
end;
end;
Inc(order);
patts := patts+CHR(patt);
end;
until (patt >= patterns) or (order > $7f);
end;
procedure import_old_a2m_patterns1(block: Byte; count: Byte);
procedure get_old_chunk(pattern,line,channel: Byte; var chunk: tOLD_CHUNK);
begin chunk := old_hash_buffer[pattern][line][channel]; end;
var
patt,line,chan: Byte;
chunk: tOLD_CHUNK;
begin { import_old_a2m_patterns1 }
For patt := 0 to max(PRED(count),15) do
For line := 0 to $3f do
For chan := 1 to 9 do
begin
get_old_chunk(patt,line,chan,chunk);
import_old_a2m_event1(block*16+patt,line,chan,chunk,TRUE);
end;
end;
procedure import_old_a2m_event2(patt,line,chan: Byte; old_chunk: tOLD_CHUNK);
const
ef_ManualFSlide = 22;
var
chunk: tCHUNK;
begin
FillChar(chunk,SizeOf(chunk),0);
chunk.note := old_chunk.note;
chunk.instr_def := old_chunk.instr_def;
If (old_chunk.effect_def <> ef_ManualFSlide) then
begin
chunk.effect_def := old_chunk.effect_def;
chunk.effect := old_chunk.effect;
end
else If (old_chunk.effect DIV 16 <> 0) then
begin
chunk.effect_def := ef_Extended2;
chunk.effect := ef_ex2_FineTuneUp*16+old_chunk.effect DIV 16;
end
else begin
chunk.effect_def := ef_Extended2;
chunk.effect := ef_ex2_FineTuneDown*16+old_chunk.effect MOD 16;
end;
put_chunk(patt,line,chan,chunk);
end;
procedure import_old_a2m_patterns2(block: Byte; count: Byte);
procedure get_old_chunk(pattern,line,channel: Byte; var chunk: tOLD_CHUNK);
begin chunk := hash_buffer[pattern][channel][line]; end;
var
patt,line,chan: Byte;
chunk: tOLD_CHUNK;
begin { import_old_a2m_patterns2 }
For patt := 0 to max(PRED(count),7) do
For line := 0 to $3f do
For chan := 1 to 18 do
begin
get_old_chunk(patt,line,chan,chunk);
import_old_a2m_event2(block*8+patt,line,chan,chunk);
end;
end;
procedure import_old_flags;
var
temp: Byte;
begin
If (songdata.common_flag OR 2 = songdata.common_flag) then
For temp := 1 to 20 do
songdata.lock_flags[temp] := songdata.lock_flags[temp] OR $10;
If (songdata.common_flag OR 4 = songdata.common_flag) then
For temp := 1 to 20 do
songdata.lock_flags[temp] := songdata.lock_flags[temp] OR $20;
If (songdata.common_flag OR $20 = songdata.common_flag) then
For temp := 1 to 20 do
songdata.lock_flags[temp] := songdata.lock_flags[temp] AND NOT 3;
end;
procedure import_old_songdata(old_songdata: pOLD_FIXED_SONGDATA);
var
temp: Byte;
begin
songdata.songname := old_songdata^.songname;
songdata.composer := old_songdata^.composer;
For temp := 1 to 250 do
begin
songdata.instr_names[temp] := old_songdata^.instr_names[temp];
songdata.instr_data[temp].fm_data := old_songdata^.instr_data[temp].fm_data;
songdata.instr_data[temp].panning := old_songdata^.instr_data[temp].panning;
songdata.instr_data[temp].fine_tune := old_songdata^.instr_data[temp].fine_tune;
songdata.instr_data[temp].perc_voice := 0;
end;
Move(old_songdata^.pattern_order,
songdata.pattern_order,
SizeOf(old_songdata^.pattern_order));
songdata.tempo := old_songdata^.tempo;
songdata.speed := old_songdata^.speed;
songdata.common_flag := old_songdata^.common_flag;
import_old_flags;
end;
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_BEGIN}
procedure import_single_old_instrument(old_songdata: pOLD_FIXED_SONGDATA;
pos,instr: Byte);
begin
songdata.instr_names[pos] := Copy(songdata.instr_names[pos],1,9)+
Copy(old_songdata^.instr_names[instr],10,22);
songdata.instr_data[pos].fm_data := old_songdata^.instr_data[instr].fm_data;
songdata.instr_data[pos].panning := old_songdata^.instr_data[instr].panning;
songdata.instr_data[pos].fine_tune := old_songdata^.instr_data[instr].fine_tune;
songdata.instr_data[pos].perc_voice := 0;
end;
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_END}
function insert_command(cmd,cmd2: Word; patterns: Byte; chan: Byte; exceptions: tByteSet): Boolean;
var
chunk: tCHUNK;
temp2,temp3: Byte;
patt_break: Byte;
order,patt: Byte;
patts: String;
begin
patts := '';
order := 0;
patt := BYTE_NULL;
insert_command := FALSE;
Repeat
If (Pos(CHR(songdata.pattern_order[order]),patts) <> 0) or
(songdata.pattern_order[order] >= $80) then Inc(order)
else
begin
patt := songdata.pattern_order[order];
patt_break := songdata.patt_len;
For temp3 := 1 to songdata.nm_tracks do
For temp2 := 0 to PRED(songdata.patt_len) do
begin
get_chunk(patt,temp2,temp3,chunk);
If (chunk.effect_def in [ef_PositionJump,ef_PatternBreak]) or
(chunk.effect_def2 in [ef_PositionJump,ef_PatternBreak]) then
patt_break := temp2;
If (temp3 = chan) and (temp2 <= patt_break) then
If (cmd2 = 0) then
If (chunk.effect_def+chunk.effect = 0) or
(chunk.effect_def SHL 8 + chunk.effect = cmd) or
(chunk.effect_def in exceptions) then
begin
chunk.effect_def := HI(cmd);
chunk.effect := LO(cmd);
put_chunk(patt,temp2,temp3,chunk);
insert_command := TRUE;
EXIT;
end
else If (chunk.effect_def2+chunk.effect2 = 0) or
(chunk.effect_def2 SHL 8 + chunk.effect2 = cmd2) or
(chunk.effect_def2 in exceptions) then
begin
chunk.effect_def2 := HI(cmd);
chunk.effect2 := LO(cmd);
put_chunk(patt,temp2,temp3,chunk);
insert_command := TRUE;
EXIT;
end
else
else If ((chunk.effect_def+chunk.effect = 0) or
(chunk.effect_def SHL 8 + chunk.effect = cmd) or
(chunk.effect_def in exceptions)) and
((chunk.effect_def2+chunk.effect2 = 0) or
(chunk.effect_def2 SHL 8 + chunk.effect2 = cmd2) or
(chunk.effect_def2 in exceptions)) then
begin
chunk.effect_def := HI(cmd);
chunk.effect := LO(cmd);
chunk.effect_def2 := HI(cmd2);
chunk.effect2 := LO(cmd2);
put_chunk(patt,temp2,temp3,chunk);
insert_command := TRUE;
EXIT;
end;
end;
Inc(order);
patts := patts+CHR(patt);
end;
until (patt >= patterns) or (order > $7f);
end;
procedure a2m_file_loader;
type
tOLD_HEADER = Record
ident: array[1..10] of Char;
crc32: Longint;
ffver: Byte;
patts: Byte;
b0len: Word;
b1len: Word;
b2len: Word;
b3len: Word;
b4len: Word;
b5len: Word;
b6len: Word;
b7len: Word;
b8len: Word;
end;
type
tHEADER = Record
ident: array[1..10] of Char;
crc32: Longint;
ffver: Byte;
patts: Byte;
b0len: Longint;
b1len: array[0..15] of Longint;
end;
const
id = '_A2module_';
const
old_a2m_header_size = 26;
var
f: File;
header: tHEADER;
header2: tOLD_HEADER;
temp,temp2: Longint;
crc: Longint;
xlen: array[0..6] of Word;
begin
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_BEGIN}
{$IFDEF GO32V2}
_last_debug_str_ := _debug_str_;
_debug_str_ := 'ILOADERS.INC:a2m_file_loader';
{$ENDIF}
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_END}
{$i-}
Assign(f,songdata_source);
ResetF(f);
{$i+}
If (IOresult <> 0) then
begin
CloseF(f);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_BEGIN}
Dialog('ERROR READiNG DATA - DiSK ERROR?$'+
'LOADiNG STOPPED$',
'~O~KAY$',' A2M LOADER ',1);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_END}
EXIT;
end;
FillChar(buf1,SizeOf(buf1),0);
BlockReadF(f,header,SizeOf(header),temp);
If NOT ((temp = SizeOf(header)) and (header.ident = id)) then
begin
CloseF(f);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_BEGIN}
Dialog('ERROR READiNG DATA - FiLE CORRUPTED$'+
'LOADiNG STOPPED$',
'~O~KAY$',' A2M LOADER ',1);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_END}
EXIT;
end;
{@ADT2PLAY_COMPILER_DIRECTIVE:INSERT> load_flag := $7f;}
If NOT (header.ffver in [1..FFVER_A2M]) then
begin
CloseF(f);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_BEGIN}
Dialog('UNKNOWN FiLE FORMAT VERSiON$'+
'LOADiNG STOPPED$',
'~O~KAY$',' A2M LOADER ',1);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_END}
EXIT;
end;
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_BEGIN}
If (play_status <> isStopped) then
begin
fade_out_playback(FALSE);
stop_playing;
end;
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_END}
init_old_songdata;
If (header.ffver in [1..4]) then
begin
FillChar(adsr_carrier,SizeOf(adsr_carrier),BYTE(FALSE));
ResetF(f);
BlockReadF(f,header2,SizeOf(header2),temp);
If NOT ((temp = SizeOf(header2)) and (header2.ident = id)) then
begin
CloseF(f);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_BEGIN}
Dialog('ERROR READiNG DATA - FiLE CORRUPTED$'+
'LOADiNG STOPPED$',
'~O~KAY$',' A2M LOADER ',1);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_END}
EXIT;
end;
xlen[0] := header2.b2len;
xlen[1] := header2.b3len;
xlen[2] := header2.b4len;
SeekF(f,old_a2m_header_size);
If (IOresult <> 0) then
begin
CloseF(f);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_BEGIN}
Dialog('ERROR READiNG DATA - FiLE CORRUPTED$'+
'LOADiNG STOPPED$',
'~O~KAY$',' A2M LOADER ',1);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_END}
EXIT;
end;
crc := DWORD_NULL;
BlockReadF(f,buf1,header2.b0len,temp);
If NOT (temp = header2.b0len) then
begin
CloseF(f);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_BEGIN}
Dialog('ERROR READiNG DATA - FiLE CORRUPTED$'+
'LOADiNG STOPPED$',
'~O~KAY$',' A2M LOADER ',1);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_END}
EXIT;
end;
crc := Update32(buf1,temp,crc);
BlockReadF(f,buf1,header2.b1len,temp);
If NOT (temp = header2.b1len) then
begin
CloseF(f);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_BEGIN}
Dialog('ERROR READiNG DATA - FiLE CORRUPTED$'+
'LOADiNG STOPPED$',
'~O~KAY$',' A2M LOADER ',1);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_END}
EXIT;
end;
crc := Update32(buf1,temp,crc);
For temp2 := 0 to 2 do
If ((header2.patts-1) DIV 16 > temp2) then
begin
BlockReadF(f,buf1,xlen[temp2],temp);
If NOT (temp = xlen[temp2]) then
begin
CloseF(f);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_BEGIN}
Dialog('ERROR READiNG DATA - FiLE CORRUPTED$'+
'LOADiNG STOPPED$',
'~O~KAY$',' A2M LOADER ',1);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_END}
EXIT;
end;
crc := Update32(buf1,temp,crc);
end;
crc := Update32(header2.b0len,2,crc);
crc := Update32(header2.b1len,2,crc);
For temp2 := 0 to 2 do
crc := Update32(xlen[temp2],2,crc);
If (crc <> header2.crc32) then
begin
CloseF(f);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_BEGIN}
Dialog('CRC FAiLED - FiLE CORRUPTED$'+
'LOADiNG STOPPED$',
'~O~KAY$',' A2M LOADER ',1);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_END}
EXIT;
end;
init_songdata;
load_flag := 0;
songdata.patt_len := 64;
If adjust_tracks then songdata.nm_tracks := 9
else If (songdata.nm_tracks < 9) then songdata.nm_tracks := 9;
SeekF(f,old_a2m_header_size);
If (IOresult <> 0) then
begin
CloseF(f);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_BEGIN}
Dialog('ERROR READiNG DATA - FiLE CORRUPTED$'+
'LOADiNG STOPPED$',
'~O~KAY$',' A2M LOADER ',1);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_END}
EXIT;
end;
BlockReadF(f,buf1,header2.b0len,temp);
If NOT (temp = header2.b0len) then
begin
CloseF(f);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_BEGIN}
Dialog('ERROR READiNG DATA - FiLE CORRUPTED$'+
'LOADiNG STOPPED$',
'~O~KAY$',' A2M LOADER ',1);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_END}
EXIT;
end;
Case header2.ffver of
4: Move(buf1,old_songdata,header2.b0len);
3: LZSS_decompress(buf1,old_songdata,header2.b0len);
2: LZW_decompress(buf1,old_songdata);
1: SIXPACK_decompress(buf1,old_songdata,header2.b0len);
end;
For temp := 1 to 250 do
old_songdata.instr_data[temp].panning := 0;
BlockReadF(f,buf1,header2.b1len,temp);
If NOT (temp = header2.b1len) then
begin
CloseF(f);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_BEGIN}
Dialog('ERROR READiNG DATA - FiLE CORRUPTED$'+
'LOADiNG STOPPED$',
'~O~KAY$',' A2M LOADER ',1);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_END}
EXIT;
end;
Case header2.ffver of
4: Move(buf1,old_hash_buffer,header2.b1len);
3: LZSS_decompress(buf1,old_hash_buffer,header2.b1len);
2: LZW_decompress(buf1,old_hash_buffer);
1: SIXPACK_decompress(buf1,old_hash_buffer,header2.b1len);
end;
import_old_a2m_patterns1(0,16);
For temp2 := 0 to 2 do
If ((header2.patts-1) DIV 16 > temp2) then
begin
BlockReadF(f,buf1,xlen[temp2],temp);
If NOT (temp = xlen[temp2]) then
begin
CloseF(f);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_BEGIN}
Dialog('ERROR READiNG DATA - FiLE CORRUPTED$'+
'LOADiNG STOPPED$',
'~O~KAY$',' A2M LOADER ',1);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_END}
EXIT;
end;
Case header2.ffver of
4: Move(buf1,old_hash_buffer,xlen[temp2]);
3: LZSS_decompress(buf1,old_hash_buffer,xlen[temp2]);
2: LZW_decompress(buf1,old_hash_buffer);
1: SIXPACK_decompress(buf1,old_hash_buffer,xlen[temp2]);
end;
import_old_a2m_patterns1(SUCC(temp2),16);
end;
replace_old_adsr(header2.patts);
import_old_songdata(Addr(old_songdata));
end;
If (header.ffver in [5..8]) then
begin
ResetF(f);
BlockReadF(f,header2,SizeOf(header2),temp);
If NOT ((temp = SizeOf(header2)) and (header2.ident = id)) then
begin
CloseF(f);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_BEGIN}
Dialog('ERROR READiNG DATA - FiLE CORRUPTED$'+
'LOADiNG STOPPED$',
'~O~KAY$',' A2M LOADER ',1);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_END}
EXIT;
end;
xlen[0] := header2.b2len;
xlen[1] := header2.b3len;
xlen[2] := header2.b4len;
xlen[3] := header2.b5len;
xlen[4] := header2.b6len;
xlen[5] := header2.b7len;
xlen[6] := header2.b8len;
crc := DWORD_NULL;
BlockReadF(f,buf1,header2.b0len,temp);
If NOT (temp = header2.b0len) then
begin
CloseF(f);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_BEGIN}
Dialog('ERROR READiNG DATA - FiLE CORRUPTED$'+
'LOADiNG STOPPED$',
'~O~KAY$',' A2M LOADER ',1);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_END}
EXIT;
end;
crc := Update32(buf1,temp,crc);
BlockReadF(f,buf1,header2.b1len,temp);
If NOT (temp = header2.b1len) then
begin
CloseF(f);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_BEGIN}
Dialog('ERROR READiNG DATA - FiLE CORRUPTED$'+
'LOADiNG STOPPED$',
'~O~KAY$',' A2M LOADER ',1);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_END}
EXIT;
end;
crc := Update32(buf1,temp,crc);
For temp2 := 0 to 6 do
If ((header2.patts-1) DIV 8 > temp2) then
begin
BlockReadF(f,buf1,xlen[temp2],temp);
If NOT (temp = xlen[temp2]) then
begin
CloseF(f);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_BEGIN}
Dialog('ERROR READiNG DATA - FiLE CORRUPTED$'+
'LOADiNG STOPPED$',
'~O~KAY$',' A2M LOADER ',1);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_END}
EXIT;
end;
crc := Update32(buf1,temp,crc);
end;
crc := Update32(header2.b0len,2,crc);
crc := Update32(header2.b1len,2,crc);
For temp2 := 0 to 6 do
crc := Update32(xlen[temp2],2,crc);
If (crc <> header2.crc32) then
begin
CloseF(f);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_BEGIN}
Dialog('CRC FAiLED - FiLE CORRUPTED$'+
'LOADiNG STOPPED$',
'~O~KAY$',' A2M LOADER ',1);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_END}
EXIT;
end;
init_songdata;
load_flag := 0;
songdata.patt_len := 64;
If adjust_tracks then songdata.nm_tracks := 18
else If (songdata.nm_tracks < 18) then songdata.nm_tracks := 18;
SeekF(f,SizeOf(header2));
If (IOresult <> 0) then
begin
CloseF(f);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_BEGIN}
Dialog('ERROR READiNG DATA - FiLE CORRUPTED$'+
'LOADiNG STOPPED$',
'~O~KAY$',' A2M LOADER ',1);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_END}
EXIT;
end;
BlockReadF(f,buf1,header2.b0len,temp);
If NOT (temp = header2.b0len) then
begin
CloseF(f);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_BEGIN}
Dialog('ERROR READiNG DATA - FiLE CORRUPTED$'+
'LOADiNG STOPPED$',
'~O~KAY$',' A2M LOADER ',1);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_END}
EXIT;
end;
Case header2.ffver of
8: Move(buf1,old_songdata,header2.b0len);
7: LZSS_decompress(buf1,old_songdata,header2.b0len);
6: LZW_decompress(buf1,old_songdata);
5: SIXPACK_decompress(buf1,old_songdata,header2.b0len);
end;
BlockReadF(f,buf1,header2.b1len,temp);
If NOT (temp = header2.b1len) then
begin
CloseF(f);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_BEGIN}
Dialog('ERROR READiNG DATA - FiLE CORRUPTED$'+
'LOADiNG STOPPED$',
'~O~KAY$',' A2M LOADER ',1);
{@ADT2PLAY_COMPILER_DIRECTIVE:SKIP_END}
EXIT;
end;