-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunused.c
2121 lines (2016 loc) · 71.2 KB
/
unused.c
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
signed int sub_401980(int a1) {
int v1; // eax@1
signed int v2; // ebx@1
int v3; // edi@1
int v4; // eax@5
int v5; // ebp@12
int v6; // edi@12
signed int result; // eax@20
const char *v8; // edx@22
int v9; // [sp-4h] [bp-38h]@22
int v10; // [sp+10h] [bp-24h]@1
char Dest; // [sp+14h] [bp-20h]@6
const char v12[8]; // [sp+1Ch] [bp-18h]@9
char v13; // [sp+24h] [bp-10h]@26
char ArgList; // [sp+2Ch] [bp-8h]@24
v2 = *(_BYTE * )(a1 + 4) - dword_40DEE0 - 64;
v3 = -1;
v1 = *(_DWORD * )(a1 + 8);
v10 = *(_DWORD * ) & note_parameter_lookuptable[4 * *(_BYTE * )(a1 + 5)];
if (v1 != -1)
v3 = note_duration_lookuptable[v1];
if (exact_gate_time && v3 != -1 && (v4 = v1 - v3) != 0)
sprintf(&Dest, ", gtp%u", v4);
else
Dest = 0;
if (v3 == -1)
sprintf((char *) v12, "TIE ");
else
sprintf((char *) v12, "N%02u ", v3);
if (compression_flag) {
v6 = dword_40DF1C - v2;
v5 = dword_40DEF0 - v10;
}
else {
v6 = -1;
v5 = -1;
}
if (dword_40DF00)
dword_40DF00 = 0;
else
byte_40DF28 = 0;
if (v6 || v5 || Dest) {
dword_40DF1C = v2;
if (v2 >= 24) {
v9 = v2 / 12 - 2;
v8 = (&off_40C358)[4 * v2 % 12];
}
else {
v9 = v2 / -12 + 2;
v8 = (&off_40C388)[4 * v2 % 12];
}
sprintf(&ArgList, v8, v9);
if (v5 || Dest) {
dword_40DEF0 = v10;
sprintf(&v13, ", v%03u", v10);
}
else {
v13 = 0;
}
result = sub_402840((signed int *) a1, v12, "%s%s%s", &ArgList, &v13, &Dest);
}
else {
result = sub_402840((signed int *) a1, v12, 0);
}
dword_40DF08 = v6;
dword_40DF0C = v5;
return result;
}
// 40C1D0: using guessed type int note_duration_lookuptable[];
// 40CEDC: using guessed type int exact_gate_time;
// 40CEE0: using guessed type int compression_flag;
// 40DEE0: using guessed type int dword_40DEE0;
// 40DEF0: using guessed type int dword_40DEF0;
// 40DF00: using guessed type int dword_40DF00;
// 40DF08: using guessed type int dword_40DF08;
// 40DF0C: using guessed type int dword_40DF0C;
// 40DF1C: using guessed type int dword_40DF1C;
// 40DF28: using guessed type char byte_40DF28;
//----- (00401B40) --------------------------------------------------------
signed int sub_401B40(int a1) {
signed int v1; // ecx@1
int v2; // esi@1
signed int result; // eax@6
v1 = *(_BYTE * )(a1 + 5) - dword_40DEE0;
v2 = dword_40DF1C - v1;
if (dword_40DF1C == v1 || !dword_40DF08)
byte_40DF28 = 0;
if (dword_40DF1C == v1 && compression_flag) {
result = sub_402840((signed int *) a1, "EOT ", 0);
dword_40DF08 = v2;
}
else {
dword_40DF1C = v1;
if (v1 >= 24) {
result = sub_402840((signed int *) a1, "EOT ", (&off_40C358)[4 * v1 % 12], v1 / 12 - 2);
dword_40DF08 = v2;
}
else {
result = sub_402840((signed int *) a1, "EOT ", (&off_40C388)[4 * v1 % 12], v1 / -12 + 2);
dword_40DF08 = v2;
}
}
return result;
}
// 40CEE0: using guessed type int compression_flag;
// 40DEE0: using guessed type int dword_40DEE0;
// 40DF08: using guessed type int dword_40DF08;
// 40DF1C: using guessed type int dword_40DF1C;
// 40DF28: using guessed type char byte_40DF28;
//----- (00401C10) --------------------------------------------------------
signed int sub_401C10(int a1) {
signed int v1; // eax@1
signed int result; // eax@5
v1 = *(_BYTE * )(a1 + 5);
if (v1 >= 42) {
if (v1 < 64)
v1 -= 30;
}
switch (v1) {
default:
result = sub_402A10(*(_DWORD *) a1);
break;
case 1:
result = sub_402840((signed int *) a1, "MOD ", "%u", *(_DWORD * )(a1 + 8));
break;
case 7:
result = sub_402840((signed int *) a1, "VOL ", "%u*%s_mvl/mxv", *(_DWORD * )(a1 + 8), *(_DWORD *) ArgList);
break;
case 10:
result = sub_402840((signed int *) a1, "PAN ", "c_v%+d", *(_DWORD * )(a1 + 8) - 64);
break;
case 12:
case 16:
result = sub_402060(a1);
break;
case 13:
dword_40DF18 = *(_DWORD * )(a1 + 8);
result = sub_402A10(*(_DWORD *) a1);
break;
case 14:
*(_DWORD *) dword_40DF10 = *(_DWORD * )(a1 + 8);
result = sub_402A10(*(_DWORD *) a1);
break;
case 15:
dword_40DF14 = *(_DWORD * )(a1 + 8);
result = sub_402A10(*(_DWORD *) a1);
break;
case 17:
fprintf(output_file_fp, "%s_%u_L%u:\n", *(_DWORD *) ArgList, sfile_num_tracks, *(_DWORD * )(a1 + 8));
sub_402A10(*(_DWORD *) a1);
result = reset_something();
break;
case 20:
result = sub_402840((signed int *) a1, "BENDR ", "%u", *(_DWORD * )(a1 + 8));
break;
case 21:
result = sub_402840((signed int *) a1, "LFOS ", "%u", *(_DWORD * )(a1 + 8));
break;
case 22:
result = sub_402840((signed int *) a1, "MODT ", "%u", *(_DWORD * )(a1 + 8));
break;
case 24:
result = sub_402840((signed int *) a1, "TUNE ", "c_v%+d", *(_DWORD * )(a1 + 8) - 64);
break;
case 26:
result = sub_402840((signed int *) a1, "LFODL ", "%u", *(_DWORD * )(a1 + 8));
break;
case 29:
case 31:
result = sub_401E60(a1);
break;
case 30:
dword_40DEF8 = *(_DWORD * )(a1 + 8);
result = sub_401FD0((signed int *) a1);
break;
case 33:
case 39:
fprintf_and_reset("PRIO , %u", *(_DWORD * )(a1 + 8));
result = sub_402A10(*(_DWORD *) a1);
break;
}
return result;
}
// 40DEB8: using guessed type int sfile_num_tracks;
// 40DEF8: using guessed type int dword_40DEF8;
// 40DF14: using guessed type int dword_40DF14;
// 40DF18: using guessed type int dword_40DF18;
//----- (00401E60) --------------------------------------------------------
signed int sub_401E60(int a1) {
signed int result; // eax@2
switch (dword_40DEF8) {
default:
result = sub_402A10(*(_DWORD *) a1);
break;
case 1:
result = sub_402840((signed int *) a1, "XCMD ", "xWAVE , %u", *(_DWORD * )(a1 + 8));
break;
case 2:
result = sub_402840((signed int *) a1, "XCMD ", "xTYPE , %u", *(_DWORD * )(a1 + 8));
break;
case 4:
result = sub_402840((signed int *) a1, "XCMD ", "xATTA , %u", *(_DWORD * )(a1 + 8));
break;
case 5:
result = sub_402840((signed int *) a1, "XCMD ", "xDECA , %u", *(_DWORD * )(a1 + 8));
break;
case 6:
result = sub_402840((signed int *) a1, "XCMD ", "xSUST , %u", *(_DWORD * )(a1 + 8));
break;
case 7:
result = sub_402840((signed int *) a1, "XCMD ", "xRELE , %u", *(_DWORD * )(a1 + 8));
break;
case 8:
result = sub_402840((signed int *) a1, "XCMD ", "xIECV , %u", *(_DWORD * )(a1 + 8));
break;
case 9:
result = sub_402840((signed int *) a1, "XCMD ", "xIECL , %u", *(_DWORD * )(a1 + 8));
break;
case 10:
result = sub_402840((signed int *) a1, "XCMD ", "xLENG , %u", *(_DWORD * )(a1 + 8));
break;
case 11:
result = sub_402840((signed int *) a1, "XCMD ", "xSWEE , %u", *(_DWORD * )(a1 + 8));
break;
}
return result;
}
// 40DEF8: using guessed type int dword_40DEF8;
//----- (00401FD0) --------------------------------------------------------
int sub_401FD0(signed int *a1) {
int result; // eax@3
if (dword_40DEF8 == 100) {
fprintf(output_file_fp, "%s_%u_LOOP:\n", *(_DWORD *) ArgList, sfile_num_tracks);
sub_402A10(*a1);
result = reset_something();
}
else {
if (dword_40DEF8 == 101) {
fprintf_and_reset("GOTO");
sub_4029C0("%s_%u_LOOP", *(_DWORD *) ArgList, sfile_num_tracks);
result = sub_402A10(*a1);
}
else {
result = sub_402A10(*a1);
}
}
return result;
}
// 40DEB8: using guessed type int sfile_num_tracks;
// 40DEF8: using guessed type int dword_40DEF8;
//----- (00402060) --------------------------------------------------------
signed int sub_402060(int a1) {
int v1; // esi@2
char Dest; // [sp+4h] [bp-10h]@8
switch (dword_40DF18) {
case 0:
v1 = a1;
fprintf_and_reset("MEMACC, mem_set, 0x%02X, %u", *(_DWORD *) dword_40DF10, *(_DWORD * )(a1 + 8));
break;
case 1:
v1 = a1;
fprintf_and_reset("MEMACC, mem_add, 0x%02X, %u", *(_DWORD *) dword_40DF10, *(_DWORD * )(a1 + 8));
break;
case 2:
v1 = a1;
fprintf_and_reset("MEMACC, mem_sub, 0x%02X, %u", *(_DWORD *) dword_40DF10, *(_DWORD * )(a1 + 8));
break;
case 3:
v1 = a1;
fprintf_and_reset("MEMACC, mem_mem_set, 0x%02X, 0x%02X", *(_DWORD *) dword_40DF10, *(_DWORD * )(a1 + 8));
break;
case 4:
v1 = a1;
fprintf_and_reset("MEMACC, mem_mem_add, 0x%02X, 0x%02X", *(_DWORD *) dword_40DF10, *(_DWORD * )(a1 + 8));
break;
case 5:
v1 = a1;
fprintf_and_reset("MEMACC, mem_mem_sub, 0x%02X, 0x%02X", *(_DWORD *) dword_40DF10, *(_DWORD * )(a1 + 8));
break;
case 6:
v1 = a1;
sprintf(&Dest, "%u", *(_DWORD * )(a1 + 8));
sub_402740((int) "beq", (int) &Dest, (int) "L");
break;
case 7:
v1 = a1;
sprintf(&Dest, "%u", *(_DWORD * )(a1 + 8));
sub_402740((int) "bne", (int) &Dest, (int) "L");
break;
case 8:
v1 = a1;
sprintf(&Dest, "%u", *(_DWORD * )(a1 + 8));
sub_402740((int) "bhi", (int) &Dest, (int) "L");
break;
case 9:
v1 = a1;
sprintf(&Dest, "%u", *(_DWORD * )(a1 + 8));
sub_402740((int) "bhs", (int) &Dest, (int) "L");
break;
case 10:
v1 = a1;
sprintf(&Dest, "%u", *(_DWORD * )(a1 + 8));
sub_402740((int) "bls", (int) &Dest, (int) "L");
break;
case 11:
v1 = a1;
sprintf(&Dest, "%u", *(_DWORD * )(a1 + 8));
sub_402740((int) "blo", (int) &Dest, (int) "L");
break;
case 12:
v1 = a1;
sprintf(&Dest, "0x%02X", *(_DWORD * )(a1 + 8));
sub_402740((int) "mem_beq", (int) &Dest, (int) "L");
break;
case 13:
v1 = a1;
sprintf(&Dest, "0x%02X", *(_DWORD * )(a1 + 8));
sub_402740((int) "mem_bne", (int) &Dest, (int) "L");
break;
case 14:
v1 = a1;
sprintf(&Dest, "0x%02X", *(_DWORD * )(a1 + 8));
sub_402740((int) "mem_bhi", (int) &Dest, (int) "L");
break;
case 15:
v1 = a1;
sprintf(&Dest, "0x%02X", *(_DWORD * )(a1 + 8));
sub_402740((int) "mem_bhs", (int) &Dest, (int) "L");
break;
case 16:
v1 = a1;
sprintf(&Dest, "0x%02X", *(_DWORD * )(a1 + 8));
sub_402740((int) "mem_bls", (int) &Dest, (int) "L");
break;
case 17:
v1 = a1;
sprintf(&Dest, "0x%02X", *(_DWORD * )(a1 + 8));
sub_402740((int) "mem_blo", (int) &Dest, (int) "L");
break;
case 70:
v1 = a1;
sprintf(&Dest, "%u", *(_DWORD * )(a1 + 8));
sub_402740((int) "beq", (int) &Dest, (int) "B");
break;
case 71:
v1 = a1;
sprintf(&Dest, "%u", *(_DWORD * )(a1 + 8));
sub_402740((int) "bne", (int) &Dest, (int) "B");
break;
case 72:
v1 = a1;
sprintf(&Dest, "%u", *(_DWORD * )(a1 + 8));
sub_402740((int) "bhi", (int) &Dest, (int) "B");
break;
case 73:
v1 = a1;
sprintf(&Dest, "%u", *(_DWORD * )(a1 + 8));
sub_402740((int) "bhs", (int) &Dest, (int) "B");
break;
case 74:
v1 = a1;
sprintf(&Dest, "%u", *(_DWORD * )(a1 + 8));
sub_402740((int) "bls", (int) &Dest, (int) "B");
break;
case 75:
v1 = a1;
sprintf(&Dest, "%u", *(_DWORD * )(a1 + 8));
sub_402740((int) "blo", (int) &Dest, (int) "B");
break;
case 76:
v1 = a1;
sprintf(&Dest, "0x%02X", *(_DWORD * )(a1 + 8));
sub_402740((int) "mem_beq", (int) &Dest, (int) "B");
break;
case 77:
v1 = a1;
sprintf(&Dest, "0x%02X", *(_DWORD * )(a1 + 8));
sub_402740((int) "mem_bne", (int) &Dest, (int) "B");
break;
case 78:
v1 = a1;
sprintf(&Dest, "0x%02X", *(_DWORD * )(a1 + 8));
sub_402740((int) "mem_bhi", (int) &Dest, (int) "B");
break;
case 79:
v1 = a1;
sprintf(&Dest, "0x%02X", *(_DWORD * )(a1 + 8));
sub_402740((int) "mem_bhs", (int) &Dest, (int) "B");
break;
case 80:
v1 = a1;
sprintf(&Dest, "0x%02X", *(_DWORD * )(a1 + 8));
sub_402740((int) "mem_bls", (int) &Dest, (int) "B");
break;
case 81:
v1 = a1;
sprintf(&Dest, "0x%02X", *(_DWORD * )(a1 + 8));
sub_402740((int) "mem_blo", (int) &Dest, (int) "B");
break;
default:
v1 = a1;
break;
}
return sub_402A10(*(_DWORD *) v1);
}
// 40DF18: using guessed type int dword_40DF18;
//----- (00402740) --------------------------------------------------------
int sub_402740(int ArgList, int a2, int a3) {
fprintf_and_reset("MEMACC, mem_%s, 0x%02X, %s", ArgList, *(_DWORD *) dword_40DF10, a2);
return sub_4029C0("%s_%u_%s%u", *(_DWORD * )
::ArgList, sfile_num_tracks, a3, dword_40DF14);
}
// 40DEB8: using guessed type int sfile_num_tracks;
// 40DF14: using guessed type int dword_40DF14;
//----- (00402790) --------------------------------------------------------
int sub_402790(int a1) {
signed int v1; // eax@2
int v2; // edx@3
int result; // eax@9
dword_40DEFC = *(_BYTE * )(a1 + 5) + 1;
fprintf(output_file_fp, "%s_%u_B%u:\n", *(_DWORD *) ArgList, sfile_num_tracks, dword_40DEFC);
if (sfile_num_tracks == 1) {
v1 = 0;
if (!*(_DWORD *) a1) {
v2 = a1 + 16;
while (*(_BYTE *) v2 != 21) {
v2 += 12;
++v1;
if (*(_DWORD * )(v2 - 16))
goto LABEL_8;
}
v1 = -1;
}
LABEL_8:
if (v1 < 0) {
sub_402A10(*(_DWORD *) a1);
result = reset_something();
}
else {
sub_402830((signed int *) a1);
result = reset_something();
}
}
else {
sub_402A10(*(_DWORD *) a1);
result = reset_something();
}
return result;
}
// 40DEB8: using guessed type int sfile_num_tracks;
// 40DEFC: using guessed type int dword_40DEFC;
//----- (00402830) --------------------------------------------------------
signed int sub_402830(signed int *a1) {
return sub_402A10(*a1);
}
//----- (00402840) --------------------------------------------------------
signed int sub_402840(signed int *a1, const char *a2, const char *Format, ...) {
va_list va; // [sp+18h] [bp+10h]@1
va_start(va, Format);
fprintf(output_file_fp, "\t.byte\t\t");
if (Format) {
if (strcmp(a2, &byte_40DF28) || !compression_flag) {
fprintf(output_file_fp, "%s, ", a2);
strcpy(&byte_40DF28, a2);
}
else {
fprintf(output_file_fp, " ");
}
vfprintf(output_file_fp, Format, va);
}
else {
fprintf(output_file_fp, "%s", a2);
strcpy(&byte_40DF28, a2);
}
fprintf(output_file_fp, "\n");
return sub_402A10(*a1);
}
// 40CEE0: using guessed type int compression_flag;
// 40DF28: using guessed type char byte_40DF28;
//----- (00402960) --------------------------------------------------------
// 40DF00: using guessed type int dword_40DF00;
// 40DF08: using guessed type int dword_40DF08;
// 40DF0C: using guessed type int dword_40DF0C;
//----- (004029C0) --------------------------------------------------------
int sub_4029C0(const char *Format, ...) {
va_list va; // [sp+8h] [bp+8h]@1
va_start(va, Format);
fprintf(output_file_fp, "\t .word\t");
vfprintf(output_file_fp, Format, va);
return fprintf(output_file_fp, "\n");
}
//----- (00402A10) --------------------------------------------------------
signed int sub_402A10(signed int a1) {
signed int result; // eax@1
result = a1;
if (a1) {
fprintf(output_file_fp, "\t.byte\tW%02u\n", a1);
result = -1;
dword_40DF0C = -1;
dword_40DF08 = -1;
dword_40DF00 = -1;
}
return result;
}
// 40DF00: using guessed type int dword_40DF00;
// 40DF08: using guessed type int dword_40DF08;
// 40DF0C: using guessed type int dword_40DF0C;
//----- (00402A50) --------------------------------------------------------
// 40DEB4: using guessed type int midi_format_short;
// 40DED8: using guessed type int midi_header_end;
// 40DEE8: using guessed type int midi_time_div;
// 40DEEC: using guessed type int midi_number_of_tracks;
//----- (004030E0) --------------------------------------------------------
// 40CEE0: using guessed type int compression_flag;
// 40DEB0: using guessed type char midi_channel;
// 40DEB8: using guessed type int sfile_num_tracks;
// 40DED8: using guessed type int midi_header_end;
// 40DEE5: using guessed type char negative_one_thing;
// 40DEEC: using guessed type int midi_number_of_tracks;
//----- (004032B0) --------------------------------------------------------
//----- (00403310) --------------------------------------------------------
//----- (004033C0) --------------------------------------------------------
// 40DECC: using guessed type int midi_absolute_time;
// 40DEDC: using guessed type char last_control_event_byte;
//----- (00403410) --------------------------------------------------------
//----- (00403440) --------------------------------------------------------
//----- (004034D0) --------------------------------------------------------
//----- (00403590) --------------------------------------------------------
//----- (00403690) --------------------------------------------------------
//----- (004036E0) --------------------------------------------------------
//----- (00403700) --------------------------------------------------------
// 403700: using guessed type _DWORD assert_a_leq_b(_DWORD, _DWORD);
//----- (00403720) --------------------------------------------------------
// 403700: using guessed type _DWORD assert_a_leq_b(_DWORD, _DWORD);
//----- (00403770) --------------------------------------------------------
// 40CED8: using guessed type int clock_per_beat_flag;
// 40DECC: using guessed type int midi_absolute_time;
//----- (00403AD0) --------------------------------------------------------
//----- (00403B70) --------------------------------------------------------
// 40CEE8: using guessed type int sfile_num_blocks;
//----- (00403BA0) --------------------------------------------------------
// 403700: using guessed type _DWORD assert_a_leq_b(_DWORD, _DWORD);
// 40DEE4: using guessed type char starts_at_zero_thing;
// 40DEE5: using guessed type char negative_one_thing;
//----- (00403C20) --------------------------------------------------------
// 40DEB0: using guessed type char midi_channel;
// 40DECC: using guessed type int midi_absolute_time;
// 40DEE4: using guessed type char starts_at_zero_thing;
// 40DEE5: using guessed type char negative_one_thing;
//----- (00404070) --------------------------------------------------------
// 40DEDC: using guessed type char last_control_event_byte;
//----- (004040F0) --------------------------------------------------------
// 40DEB0: using guessed type char midi_channel;
//----- (004042F0) --------------------------------------------------------
//----- (004043A0) --------------------------------------------------------
Event *swap_event_buffers(Event **first, Event **second) {
Event *first_copy; // eax@1
first_copy = *first;
*first = *second;
*second = first_copy;
return first_copy;
}
//----- (004043C0) --------------------------------------------------------
int merge_buffers_maybe(Event *control_events, Event *meta_events, Event *buffer, int amount) {
int current_event; // esi@1
Event *meta_event; // ebx@2
Event *control_event; // ebp@2
int max_events; // edi@2
Event *event_out; // ecx@4
signed int compare_result; // eax@4
int control_event_time; // edx@5
int meta_event_time; // edx@6
Event *control_event2; // ebx@10
Event *output_control_events; // ebp@11
int control_events_num; // ST00_4@12
Event *meta_event2; // ebx@13
Event *output_meta_events; // ebp@14
int meta_events_num; // ST00_4@15
Event *last_event; // ecx@16
Event *last_meta; // ebx@16
Event *last_control; // edi@16
signed int last_compare_res; // eax@16
int result; // eax@17
int current_meta_event; // [sp+10h] [bp-8h]@1
int current_control_event; // [sp+14h] [bp-4h]@1
current_event = 0;
current_meta_event = 0;
current_control_event = 0;
if (track_end(control_events)) {
max_events = amount;
}
else {
control_event = control_events;
meta_event = meta_events;
max_events = amount;
do {
if (track_end(meta_event))
break;
assert_a_leq_b(current_event, amount);
compare_result = compare_event_maybe(control_event, meta_event);
event_out = &buffer[current_event];
if (compare_result > 0) {
meta_event_time = meta_event->time; // Copy meta event into the output buffer
++meta_event;
event_out->time = meta_event_time;
++current_meta_event;
*(_DWORD * ) & event_out->type = *((_DWORD *) meta_event - 2);// Could just do this before the increment of meta_event
event_out->param2 = *((_DWORD *) meta_event - 1);
}
else {
control_event_time = control_event->time;// Copy control event into the output buffer
++control_event;
event_out->time = control_event_time;
++current_control_event;
*(_DWORD * ) & event_out->type = *((_DWORD *) control_event - 2);
event_out->param2 = *((_DWORD *) control_event - 1);
}
++current_event;
}
while (!track_end(control_event));
}
control_event2 = &control_events[current_control_event];
if (!track_end(&control_events[current_control_event])) {
output_control_events = &buffer[current_event];
do {
++control_event2;
control_events_num = current_event;
++output_control_events;
++current_event;
assert_a_leq_b(control_events_num, max_events);
++current_control_event;
output_control_events[-1].time = control_event2[-1].time;
*((_DWORD *) output_control_events - 2) = *((_DWORD *) control_event2 - 2);
*((_DWORD *) output_control_events - 1) = *((_DWORD *) control_event2 - 1);
}
while (!track_end(control_event2));
}
meta_event2 = &meta_events[current_meta_event];
if (!track_end(&meta_events[current_meta_event])) {
output_meta_events = &buffer[current_event];
do {
++meta_event2;
meta_events_num = current_event;
++output_meta_events;
++current_event;
assert_a_leq_b(meta_events_num, max_events);
++current_meta_event;
output_meta_events[-1].time = meta_event2[-1].time;
*((_DWORD *) output_meta_events - 2) = *((_DWORD *) meta_event2 - 2);
*((_DWORD *) output_meta_events - 1) = *((_DWORD *) meta_event2 - 1);
}
while (!track_end(meta_event2));
}
assert_a_leq_b(current_event, max_events);
last_meta = &meta_events[current_meta_event];
last_control = &control_events[current_control_event];
last_compare_res = compare_event_maybe(&control_events[current_control_event], &meta_events[current_meta_event]);
last_event = &buffer[current_event];
if (last_compare_res <= 0) {
last_event->time = last_meta->time;
result = *(_DWORD * ) & last_meta->type;
*(_DWORD * ) & last_event->type = result;
last_event->param2 = last_meta->param2;
}
else {
last_event->time = last_control->time;
result = *(_DWORD * ) & last_control->type;
*(_DWORD * ) & last_event->type = result;
last_event->param2 = last_control->param2;
}
return result;
}
// 403700: using guessed type _DWORD assert_a_leq_b(_DWORD, _DWORD);
//----- (00404590) --------------------------------------------------------
int sub_404590(int a1) {
int v1; // edi@2
int v2; // ebx@3
int v3; // edx@3
int v4; // ebx@3
int v5; // ebp@4
int v6; // ecx@6
int v7; // eax@6
int v8; // ecx@7
int v9; // ebx@7
int v10; // edx@7
int result; // eax@8
int v12; // ebx@8
int v13; // edi@9
Event *v14; // ebp@10
int v15; // ecx@12
int v16; // eax@12
int v17; // edx@13
int v18; // [sp+10h] [bp-10h]@1
Event control_event; // [sp+14h] [bp-Ch]@3
int v20; // [sp+18h] [bp-8h]@3
int v21; // [sp+1Ch] [bp-4h]@3
v18 = 0;
if (!track_end((Event *) a1)) {
v1 = a1;
do {
v3 = *(_DWORD * )(v1 + 4);
v4 = *(_DWORD * )(v1 + 8);
control_event.time = *(_DWORD *) v1;
v20 = v3;
v21 = v4;
v2 = v18 - 1;
if (v18 - 1 >= 0) {
v5 = a1 + 12 * v2;
do {
if (compare_event_maybe(&control_event, (Event *) v5) >= 0)
break;
v6 = v5 + 12;
v7 = *(_DWORD *) v5;
v5 -= 12;
--v2;
*(_DWORD *) v6 = v7;
*(_DWORD * )(v6 + 4) = *(_DWORD * )(v5 + 16);
*(_DWORD * )(v6 + 8) = *(_DWORD * )(v5 + 20);
}
while (v2 >= 0);
}
v8 = a1 + 12 * v2 + 12;
v9 = v20;
v10 = v21;
v1 += 12;
*(_DWORD *) v8 = control_event.time;
*(_DWORD * )(v8 + 4) = v9;
++v18;
*(_DWORD * )(v8 + 8) = v10;
}
while (!track_end((Event *) v1));
}
v12 = 0;
result = track_end((Event *) a1);
if (!result) {
v13 = a1;
do {
v14 = (Event * )(a1 + 12 * v12);
if (!compare_event_maybe((Event *) v13, (Event * )(a1 + 12 * v12))) {
do {
++v14;
++v12;
}
while (!compare_event_maybe((Event *) v13, v14));
v15 = a1 + 12 * v12;
v16 = *(_DWORD * )(v15 - 12);
v15 -= 12;
*(_DWORD *) v13 = v16;
*(_DWORD * )(v13 + 4) = *(_DWORD * )(v15 + 4);
*(_DWORD * )(v13 + 8) = *(_DWORD * )(v15 + 8);
}
v17 = a1 + 12 * v12++;
v13 += 12;
*(_DWORD *) v13 = *(_DWORD *) v17;
*(_DWORD * )(v13 + 4) = *(_DWORD * )(v17 + 4);
*(_DWORD * )(v13 + 8) = *(_DWORD * )(v17 + 8);
result = track_end((Event *) v13);
}
while (!result);
}
return result;
}
//----- (004046C0) --------------------------------------------------------
int convert_event_times(Event *event) {
int event_parameter; // ebx@1
int counter; // edi@1
int converted_time; // eax@4
int current_event; // eax@10
int v5; // eax@10
counter = 0;
event_parameter = (int) &event->param2;
do {
*(_DWORD * )(event_parameter - 8) = 24 * clock_per_beat_flag * *(_DWORD * )(event_parameter - 8) / midi_time_div;
if (is_music_note_event((Event * )(event_parameter - 8))) {
if (*(_DWORD *) event_parameter != -1) {
converted_time = 24 * *(_DWORD *) event_parameter * clock_per_beat_flag / midi_time_div;// Work out note duration, presumably
*(_DWORD *) event_parameter = converted_time;
if (!converted_time)
*(_DWORD *) event_parameter = 1;
if (!exact_gate_time) {
if (*(_DWORD *) event_parameter < 96)
*(_DWORD *) event_parameter = note_duration_lookuptable[*(_DWORD *) event_parameter];
}
}
*(_BYTE * )(event_parameter - 3) = note_parameter_lookuptable[4 * *(_BYTE * )(event_parameter - 3)];
}
v5 = counter;
event_parameter += 12;
++counter;
current_event = track_end(&event[v5]);
}
while (!current_event);
return current_event;
}
// 40C1D0: using guessed type int note_duration_lookuptable[];
// 40CED8: using guessed type int clock_per_beat_flag;
// 40CEDC: using guessed type int exact_gate_time;
// 40DEE8: using guessed type int midi_time_div;
//----- (00404770) --------------------------------------------------------
int adjust_times_something(Event *events_buffer, Event *control_events, int max_events) {
int counter; // ebx@1
Event *event; // edi@1
Event *current_control_event; // ebp@3
int const24int; // edx@4
int adjusted; // ecx@4
Event *event_ptr; // ecx@8
int result; // eax@10
int ev_time; // eax@10
Event *ev_ptr; // ecx@10
int index; // eax@10
int ev_param1; // edx@10
char control_event[4]; // [sp+10h] [bp-10h]@1
const __int16 const24; // [sp+14h] [bp-Ch]@1
int adjustment; // [sp+18h] [bp-8h]@1
int new_length; // [sp+1Ch] [bp-4h]@1
counter = 0;
new_length = 0;
*(_DWORD *) control_event = 0;
event = events_buffer;
const24 = 24;
adjustment = 384 * clock_per_beat_flag >> 2; // 96 * clock_per_beat_flag
do {
assert_a_leq_b(counter, max_events);
if (compare_event_maybe((Event *) control_event, event) < 0) {
current_control_event = &control_events[counter];
do {
const24int = *(_DWORD * ) & const24;
++current_control_event;
++counter;
adjusted = adjustment;
current_control_event[-1].time = *(_DWORD *) control_event;
*((_DWORD *) current_control_event - 2) = const24int;// set type
*((_DWORD *) current_control_event - 1) = adjusted;// param2
assert_a_leq_b(counter, max_events);
*(_DWORD *) control_event += adjustment;
}
while (compare_event_maybe((Event *) control_event, event) < 0);
}
if (event->type == 24) {
if (sfile_num_tracks == 1) {
if (event->param2 != adjustment) // If not adjusted
{
event_ptr = &control_events[counter++];
event_ptr->time = event->time;
*(_DWORD * ) & event_ptr->type = *(_DWORD * ) & event->type;
event_ptr->param2 = event->param2;
event_ptr->type = 21;
assert_a_leq_b(counter, max_events);
}
}
adjustment = event->param2;
*(_DWORD *) control_event = adjustment + event->time;
}
ev_time = event->time;
ev_ptr = &control_events[counter++];
++event;
ev_ptr->time = ev_time;
index = new_length;
ev_param1 = *((_DWORD *) event - 2);
++new_length;
*(_DWORD * ) & ev_ptr->type = ev_param1;
ev_ptr->param2 = *((_DWORD *) event - 1);
result = track_end(&events_buffer[index]);
}
while (!result);
return result;
}
// 403700: using guessed type _DWORD assert_a_leq_b(_DWORD, _DWORD);
// 40CED8: using guessed type int clock_per_beat_flag;
// 40DEB8: using guessed type int sfile_num_tracks;
//----- (004048B0) --------------------------------------------------------
int mystery1(Event *merged_events, Event *control_events, int max_events) {
signed int v3; // ebx@1
int v4; // esi@1
int v5; // eax@3
int v6; // edx@5
Event *v7; // ecx@7
int v8; // eax@9
int result; // eax@9
int v10; // eax@9
int v11; // [sp+10h] [bp-Ch]@1
int v12; // [sp+14h] [bp-8h]@1
int v13; // [sp+18h] [bp-4h]@1
dword_40DEE0 = 0;
v12 = 0;
v13 = 0;
v11 = 127;
v3 = 1;
sub_4049D0(
(int) merged_events,
(int) control_events,
(
unsigned __int8)negative_one_thing,
(unsigned __int8)starts_at_zero_thing,
(int) &v12,
(int) &v11);
v4 = (int) merged_events;
do {
assert_a_leq_b(v3, max_events);
if (is_music_note_event((Event *) v4)) {
v5 = *(_BYTE * )(v4 + 4) - 64;
if (v12 > v5 || v11 < v5) {
v6 = 3 * v3++;
sub_4049D0(v4, (int) ((char *) control_events + 4 * v6), v5, v5, (int) &v12, (int) &v11);
assert_a_leq_b(v3, max_events);
}
}
else {
if (*(_BYTE * )(v4 + 4) == 24) {
v7 = &control_events[v3];
v7->time = *(_DWORD *) v4;
v7->type = *(_BYTE * )(v4 + 4);
v7->param1 = dword_40DEE0;
goto LABEL_9;
}
}
v7 = &control_events[v3];
v7->time = *(_DWORD *) v4;
*(_DWORD * ) & v7->type = *(_DWORD * )(v4 + 4);
LABEL_9:
v8 = *(_DWORD * )(v4 + 8);