-
Notifications
You must be signed in to change notification settings - Fork 0
/
MT15.asm
2235 lines (1714 loc) · 49.8 KB
/
MT15.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
; ---------------------------------------------------------------------------
Sysex_address_t struc ; (sizeof=0x3)
byte_0 db ?
byte_1 db ?
byte_2 db ?
Sysex_address_t ends
PatchTemporaryArea_BenderRange_msg_t struc ; (sizeof=0x4)
address Sysex_address_t <?,?,?>
; byte_0 - always 0x03
; byte_1 - always 0x00
; byte_2 - sizeof(PatchTemporaryArea)*PartIndex + 0x04
Bender_Range db ? ; allowed range: 0-24 (0x00-0x18)
PatchTemporaryArea_BenderRange_msg_t ends
; ---------------------------------------------------------------------------
struct1_t struc ; (sizeof=0x36)
unknown1 db 18 dup(?)
byte_12 db ?
unknown2 db 2 dup(?)
byte_15 db ?
unknown3 db 3 dup(?)
byte_19 db ?
unknown4 db 14 dup(?)
byte_28 db ?
unknown5 db 12 dup(?)
byte_35 db ?
unknown6 db 14 dup(?)
byte_44 db ?
byte_45 db ?
byte_46 db ?
struct1_t ends
; ---------------------------------------------------------------------------
struct2_t struc ; (sizeof=0x23)
unknown1 db 3 dup(?)
byte_3 db ?
byte_4 db ?
unknown2 db ?
byte_6 db ?
unknown3 db 13 dup(?)
word_14 dw ?
unknown4 db 6 dup(?)
word_1C dw ?
unknown5 db 4 dup(?)
byte_22 db ?
struct2_t ends
; ---------------------------------------------------------------------------
struct3_t struc ; (sizeof=0x47)
unknown1 db 18 dup(?)
byte_12 db ?
unknown2 db 49 dup(?)
byte_44 db ?
byte_45 db ?
byte_46 db ?
struct3_t ends
; ---------------------------------------------------------------------------
; ===========================================================================
;isubs call count
; write_midi_cmd isub1 write_midi_data isub3 send_midi_sysex_msg pit_based_delay
;MT15.DRV 1.0 2 0 73 1 4 -
;MT15.DRV 1.1 2 0 73 0 5 2
IFNDEF VERSION
.ERR <you need to choose driver version option!!!>
ENDIF
%OUT ====================================
%OUT Unified_MT15 driver version
IF VERSION EQ 10
%OUT 4D Sports Driving 1.0
ELSEIF VERSION EQ 11
%OUT 4D Sports Driving 1.1
ELSE
.ERR <"!!!unknown driver version!!!">
ENDIF
%OUT "===================================="
;-----------------------------
IFNDEF EQUAL_BINARY
.ERR <you need to set binary compatiblity option!!!>
ENDIF
;UASM generates functional identical but different opcodes for some mnemonics
;
; can happen with every other assembler/compiler - except the very original one
; there are several functional identical opcodes - the assembler is free to decide which one to use
;
; example: "and ax,0xf"
; ORG : 25 0F 00
; UASM: 83 E0 0F
;-----------------------------
IFNDEF REMOVE_DEAD_CODE
.ERR <you need to set dead code removal option!!!>
ENDIF
;-----------------------------
IFNDEF REPLACE_WITH_C_CODE
.ERR <you need to set replace with c-code option!!!>
ENDIF
;-----------------------------
IF EQUAL_BINARY EQ 1
IF REMOVE_DEAD_CODE EQ 1
.ERR <"EQUAL_BINARY and REMOVE_DEAD_CODE are not compatible">
ENDIF
IF REPLACE_WITH_C_CODE EQ 1
.ERR <"EQUAL_BINARY and REPLACE_WITH_C_CODE are not compatible">
ENDIF
ENDIF
; -------------------------
IF EQUAL_BINARY EQ 1
%OUT Equal binary result
ENDIF
IF REMOVE_DEAD_CODE EQ 1
%OUT Remove dead code
ENDIF
PPI_PORT_B = 61h
PIT_CHAN2_DATA = 42h ; Channel 2 data port (read/write)
PIT_MODE_CMD = 43h ; write only, a read is ignored
; MIDI
; https://github.com/torvalds/linux/blob/master/include/sound/mpu401.h
; http://midi.teragonaudio.com/tech/mpu.htm
; http://www.piclist.com/techref/io/serial/midi/mpu.html
; http://www.gweep.net/~prefect/eng/reference/protocol/midispec.html
; http://cd.textfiles.com/audio11000/MSDOS/MIDI/MPPDEMO/MPUDEMO.C
; https://android.googlesource.com/kernel/msm/+/android-6.0.1_r0.121/sound/oss/mpu401.c
; http://manuals.opensound.com/sources/oss_uart401.c.html
; https://www.vogons.org/viewtopic.php?t=61245
MPU_401_BASE = 330h
MPU_401_DATA = (MPU_401_BASE+0)
MPU_401_STATUS_CMD = (MPU_401_BASE+1) ; write => COMMAND-Port, read => STATUS-Port
; status bit mask
MPU_401_OUTPUT_READY = 40h ; bit 6
MPU_401_INPUT_AVAIL = 80h ; bit 7
; how to display message on MPU 401
; http://www.youngmonkey.ca/nose/audio_tech/synth/Roland-MT32.html
; http://www.vcfed.org/forum/showthread.php?27856-output-to-MT-32-display
SYSEX_START = 0F0h
SYSEX_END = 0F7h
CHECKSUM_MASK = 7Fh
SYSEX_ROLAND_ID = 41h
SYSEX_DEVICE_ID = 10h
SYSEX_MODEL_ID_MT32 = 16h
SYSEX_SEND_CMD = 12h
; Segment type: Pure code
seg000 segment byte public 'CODE'
assume cs:seg000
assume es:nothing, ss:nothing, ds:nothing
jump_table: ; 3 bytes per jump
; interface function + offset in the drv binary
;tsub00: 0x00
;tsub01: 0x03
;tsub02: 0x06
;tsub03: 0x09
;tsub04: 0x0C
;tsub05: 0x0F
;tsub06: 0x12
;tsub07: 0x15
;tsub08: 0x18
;tsub09: 0x1B
;tsub10: 0x1E
;tsub11: 0x21
;tsub12: 0x24
;tsub13: 0x27
;tsub14: 0x2A
;tsub15: 0x2D
;tsub16: 0x30
;tsub17: 0x33
;tsub18: 0x36
;tsub19: 0x39
;tsub20: 0x3C
;tsub21: 0x3F
;tsub22: 0x42
; all isubs ported
jmp near ptr tsub0 ; ported
; ---------------------------------------------------------------------------
jmp near ptr tsub1 ; ported
; ---------------------------------------------------------------------------
jmp near ptr tsub2 ; ported
; ---------------------------------------------------------------------------
jmp near ptr tsub3 ; ported
; ---------------------------------------------------------------------------
jmp near ptr tsub4 ; ported
; ---------------------------------------------------------------------------
jmp near ptr tsub5 ; ported
; ---------------------------------------------------------------------------
jmp near ptr tsub6 ; ported
; ---------------------------------------------------------------------------
jmp near ptr tsub7 ; ported
; ---------------------------------------------------------------------------
jmp near ptr tsub8 ; ported
; ---------------------------------------------------------------------------
jmp near ptr tsub9 ; ported
; ---------------------------------------------------------------------------
jmp near ptr tsub10 ; ported
; ---------------------------------------------------------------------------
jmp near ptr tsub11 ; ported
; ---------------------------------------------------------------------------
jmp near ptr tsub12 ; ported
; ---------------------------------------------------------------------------
jmp near ptr tsub13 ; ported
; ---------------------------------------------------------------------------
jmp near ptr tsub14 ; ported
; ---------------------------------------------------------------------------
jmp near ptr tsub15 ; ported
; ---------------------------------------------------------------------------
jmp near ptr tsub16 ; ported
; ---------------------------------------------------------------------------
jmp near ptr tsub17 ; ported
; ---------------------------------------------------------------------------
jmp near ptr tsub18 ; ported
; ---------------------------------------------------------------------------
jmp near ptr tsub19 ; ported
; ---------------------------------------------------------------------------
jmp near ptr tsub20 ; ported
; ---------------------------------------------------------------------------
jmp near ptr tsub21 ; ported
; ---------------------------------------------------------------------------
jmp near ptr tsub22 ; ported
; ---------------------------------------------------------------------------
; LOCAL-DATA
public C msg_buffer
public C byte_14A_buffer
public C word_172_buffer_index1
public C word_174_buffer_index2
public C display_start_adress
public C display_text
public C patch_memory_address_byte1
public C patch_memory_address_byte2
public C timbre_memory_address_byte1
public C timbre_memory_address_byte2
public C sounds_left
patch_memory_address_byte1 db 0
patch_memory_address_byte2 db 0
timbre_memory_address_byte1 db 0
timbre_memory_address_byte2 db 0
sounds_left db 0
MSG_BUFFER_CONTENT_SIZE = (256 - size Sysex_address_t)
Msg_buffer_t struc
address Sysex_address_t <?,?,?>
content db MSG_BUFFER_CONTENT_SIZE dup(?)
Msg_buffer_t ends
msg_buffer Msg_buffer_t <<0,0,0>,<MSG_BUFFER_CONTENT_SIZE dup(0)>> ; 256 bytes ; general sysex msg content buffer
byte_14A_buffer db 28h dup(0) ; 40 bytes
word_172_buffer_index1 dw 0
word_174_buffer_index2 dw 0
display_start_adress db 20h, 0, 0
; 20 byte string
IF VERSION EQ 10
display_text db ' (C) 1990 DSI '
ELSEIF VERSION EQ 11
display_text db ' (C)1990,1991 DSI '
ENDIF
IF ((EQUAL_BINARY EQ 1) AND (REMOVE_DEAD_CODE EQ 0))
; complete unknown 4 bytes - from display_text end?
db 7Fh
db 0
db 0
db 0
ENDIF
IF VERSION EQ 11
public C bender_range_msg
; MT32 sysex msg content
bender_range_msg PatchTemporaryArea_BenderRange_msg_t <<3, 0, 4>, 0>
; 03 00 (0x10*(Part-1)) -> Base Adress of "Patch Temporary Area Part (Part)"
; + 00 04 -> Address Offset of "Bender range"
; xx -> Value in range 0-24
; Address = PatchTemporaryArea.BaseAdresss(Part) + BenderRange.AddressOffset
; Part = 1-8
; Value = 0-24
; 03 00 04 18 <- get_msg_PatchTemporaryArea_BenderRange(1, 24, msg);
; 03 00 44 00 <- get_msg_PatchTemporaryArea_BenderRange(5, 0, msg);
; 0 1 2 3
; only [2] and [3] getting changed
; Sysex message size 8, data: F0 41 10 16 12 03 00 F7 <-- invalid msg, checksum error
; Sysex message size 11, data: F0 41 10 16 12 03 00 04 18 61 F7
; Sysex message size 11, data: F0 41 10 16 12 03 00 14 00 69 F7
; Sysex message size 11, data: F0 41 10 16 12 03 00 24 00 59 F7
; Sysex message size 11, data: F0 41 10 16 12 03 00 34 00 49 F7
; Sysex message size 11, data: F0 41 10 16 12 03 00 44 00 39 F7
; Sysex message size 11, data: F0 41 10 16 12 03 00 44 02 37 F7
; Sysex message size 11, data: F0 41 10 16 12 03 00 54 00 29 F7
; Sysex message size 11, data: F0 41 10 16 12 03 00 54 70 39 F7 <-- invalid range, gets clampt to 0x18
; Sysex message size 11, data: F0 41 10 16 12 03 00 64 00 19 F7
; Sysex message size 11, data: F0 41 10 16 12 03 00 74 02 07 F7
ENDIF
MT32_Patch_memory_address_byte0 = 5
MT32_Timbre_memory_address_byte0 = 8
mt32_patch_memory_timbre_group_Memory = 2
mt32_patch_memory_t struc ; (sizeof=0x08)
timbre_group db ? ; 0:group A, 1:group B, 2:Memory, 3:Rhythm
timbre_number db ? ; 0-63
key_shift db ? ; 0-48 [-24...+24]
fine_tune db ? ; 0-100 [-50...+50]
bender_range db ? ; 0-24
assign_mode db ? ; 0:POLY1, 1:POLY2, 2:POLY3, 3:POLY4
reverb_switch db ? ; 0-1 (OFF,ON)
dummy db ?
mt32_patch_memory_t ends
mt32_timbre_memory_t struc
data db 246 dup (?)
mt32_timbre_memory_t ends
mt32_plb_sound_t struc
patch_memory_data mt32_patch_memory_t <?>
;--
;[ only exists if mt32_patch_memory_t::timbre_group == mt32_patch_memory_timbre_group_Memory ]
timbre_memory_data mt32_timbre_memory_t <?>
;] --
mt32_plb_sound_t ends
MT32_plb_t struc
sound_count db ?
content mt32_plb_sound_t 5 dup(<?>)
MT32_plb_t ends
; CODE
; =============== S U B R O U T I N E =======================================
IF VERSION EQ 11
IF REPLACE_WITH_C_CODE EQ 1
pit_based_delay proc near
extrn _c_pit_based_delay:near
push ax
push cx
push dx
push ax
call _c_pit_based_delay
add sp,2
pop dx
pop cx
pop ax
retn
pit_based_delay endp
ELSE
; void __usercall pit_based_delay(__int16 ax_@<ax>)
; void pit_delay(uint16_t ticks_to_wait_)
pit_based_delay proc near
push ax
push cx
neg ax
IF EQUAL_BINARY
db 05, 0ffh, 0ffh
ELSE
add ax, 0FFFFh
ENDIF
mov cx, ax
mov al, 0B6h
out PIT_MODE_CMD, al
mov al, 0FFh
out PIT_CHAN2_DATA, al
out PIT_CHAN2_DATA, al
in al, PPI_PORT_B
or al, 1
out PPI_PORT_B, al
pit_based_delay_0:
mov al, 80h
out PIT_MODE_CMD, al
in al, PIT_CHAN2_DATA
xchg al, ah
in al, PIT_CHAN2_DATA
xchg al, ah
cmp ax, cx
jnb short pit_based_delay_0
in al, PPI_PORT_B
and al, 0FEh
out PPI_PORT_B, al
pop cx
pop ax
retn
pit_based_delay endp
ENDIF
ENDIF
; =============== S U B R O U T I N E =======================================
IF REPLACE_WITH_C_CODE EQ 1
write_midi_cmd proc near
extrn _c_write_midi_cmd:near
push si
push bx
push cx
push dx
push ax ; can't push byte - only words
call _c_write_midi_cmd
add sp,2
pop dx
pop cx
pop bx
pop si
retn
write_midi_cmd endp
ELSE
; __int16 __usercall write_midi_cmd<ax>(__int8 mpu_command_value_@<al>)
write_midi_cmd proc near
push cx
push dx
push ax
mov dx, MPU_401_STATUS_CMD
mov cx, 0FFFFh
write_midi_cmd_0:
in al, dx
test al, 40h
jz short write_midi_cmd_1
dec cx
cmp cx, 1
jge short write_midi_cmd_0
pop ax
mov ax, 0FFFFh
jmp short write_midi_cmd_5
; ---------------------------------------------------------------------------
nop
write_midi_cmd_1:
cli
pop ax
out dx, al
mov cx, 0FFFFh
write_midi_cmd_2:
in al, dx
rol al, 1
jnb short write_midi_cmd_3
dec cx
cmp cx, 1
jge short write_midi_cmd_2
mov ax, 0FFFFh
jmp short write_midi_cmd_5
; ---------------------------------------------------------------------------
nop
write_midi_cmd_3:
mov dx, MPU_401_DATA
in al, dx
cmp al, 0FEh
jz short write_midi_cmd_4
mov ax, 0FFFFh
jmp short write_midi_cmd_5
; ---------------------------------------------------------------------------
nop
write_midi_cmd_4:
mov ax, 0
write_midi_cmd_5:
sti
pop dx
pop cx
retn
write_midi_cmd endp
ENDIF
; =============== S U B R O U T I N E =======================================
IF REMOVE_DEAD_CODE EQ 0
isub1 proc near
push cx
push dx
mov dx, MPU_401_STATUS_CMD
mov cx, 65535
isub1_0:
in al, dx
rol al, 1
jnb short isub1_1
dec cx
cmp cx, 1
jge short isub1_0
mov ax, 0FFFFh
jmp short isub1_2
; ---------------------------------------------------------------------------
nop
isub1_1:
mov dx, MPU_401_DATA
mov ah, 0
in al, dx
mov ax, 0
isub1_2:
pop dx
pop cx
retn
isub1 endp
ENDIF
; =============== S U B R O U T I N E =======================================
IF REPLACE_WITH_C_CODE EQ 1
write_midi_data proc near
extrn _c_write_midi_data:near
push bx
push cx
push dx
push ax ; can't push byte - only words
call _c_write_midi_data
add sp,2
pop dx
pop cx
pop bx
retn
write_midi_data endp
else
; __int16 __usercall write_midi_data<ax>(__int8 mpu_command_@<al>)
write_midi_data proc near
push cx
push dx
push ax
write_midi_data_0:
mov dx, MPU_401_STATUS_CMD
mov cx, 0FFFFh
write_midi_data_1:
in al, dx
test al, MPU_401_OUTPUT_READY
jz short write_midi_data_2
rol al, 1
jnb short write_midi_data_4
jmp short write_midi_data_0
IF REMOVE_DEAD_CODE EQ 0
; ---------------------------------------------------------------------------
dec cx
cmp cx, 1
jge short write_midi_data_1
pop ax
mov ax, 0FFFFh
jmp short write_midi_data_3
; ---------------------------------------------------------------------------
nop
ENDIF
write_midi_data_2:
mov dx, MPU_401_DATA
pop ax
out dx, al
mov ax, 0
IF REMOVE_DEAD_CODE EQ 0
write_midi_data_3:
ENDIF
pop dx
pop cx
retn
; ---------------------------------------------------------------------------
write_midi_data_4:
push si
mov si, cs:word_172_buffer_index1 ; initial = 0, or?
mov dx, MPU_401_DATA
in al, dx
mov cs:byte_14A_buffer[si], al
inc si
cmp si, lengthof byte_14A_buffer
jnz short write_midi_data_5
xor si, si
write_midi_data_5:
mov cs:word_172_buffer_index1, si
pop si
jmp short write_midi_data_0
write_midi_data endp
endif
; =============== S U B R O U T I N E =======================================
; only used by version 1.0
IF ( VERSION EQ 10 ) OR ( (VERSION EQ 11 ) AND ( ( REMOVE_DEAD_CODE EQ 0 ) AND (REPLACE_WITH_C_CODE EQ 0) ) )
IF REPLACE_WITH_C_CODE EQ 1
isub3 proc near
extrn _c_isub3:near
push ax ; al
push cx ; cl
xor bh,bh
mov bl,dl
push bx ; dl
xchg dh,dl
push dx ; dh
call _c_isub3
add sp,8
retn
isub3 endp
ELSE
; __int16 __usercall isub3<ax>(__int8 al_@<al>, __int8 cl_@<cl>, __int8 dl_@<dl>, __int8 dh_@<dh>)
isub3 proc near
push ax
mov al, cl
or al, 0B0h ; mpu_command_@
call write_midi_data
mov al, 64h ; mpu_command_@
call write_midi_data
mov al, dl ; mpu_command_@
call write_midi_data
mov al, cl
or al, 0B0h ; mpu_command_@
call write_midi_data
mov al, 65h ; mpu_command_@
call write_midi_data
mov al, dh ; mpu_command_@
call write_midi_data
mov al, cl
or al, 0B0h ; mpu_command_@
call write_midi_data
mov al, 6 ; mpu_command_@
call write_midi_data
pop ax ; mpu_command_@
call write_midi_data
retn
isub3 endp
ENDIF
ENDIF
; =============== S U B R O U T I N E =======================================
IF REPLACE_WITH_C_CODE EQ 1
send_midi_sysex_msg proc near
extrn _c_send_midi_sysex_msg:near
push si
push cx
push es
push bx
call _c_send_midi_sysex_msg
add sp,6
pop si
retn
send_midi_sysex_msg endp
ELSE
; void __usercall send_midi_sysex_msg(__int16 segment_@<es>, __int16 offset_@<bx>, __int16 size_@<cx>)
send_midi_sysex_msg proc near
push si
mov si, bx
; [F0 41 10 16 12]
mov al, SYSEX_START ; mpu_command_@
call write_midi_data
mov al, SYSEX_ROLAND_ID ; mpu_command_@
call write_midi_data
mov al, SYSEX_DEVICE_ID ; mpu_command_@
call write_midi_data
mov al, SYSEX_MODEL_ID_MT32 ; mpu_command_@
call write_midi_data
mov al, SYSEX_SEND_CMD ; mpu_command_@
call write_midi_data
mov dx, 0
send_midi_sysex_msg_0:
mov al, es:[si] ; mpu_command_@
xor ah, ah
add dx, ax
call write_midi_data
IF VERSION EQ 10
push cx
mov cx, 100
send_midi_sysex_msg_1:
in al, PPI_PORT_B
loop send_midi_sysex_msg_1
pop cx
ELSEIF VERSION EQ 11
mov ax, 400 ; ax_@
call pit_based_delay
ENDIF
inc si
loop send_midi_sysex_msg_0
mov al, dl
neg al
and al, CHECKSUM_MASK
call write_midi_data
mov al, SYSEX_END ; mpu_command_@
call write_midi_data
pop si
IF VERSION EQ 11
mov ax, 65000 ; ax_@
call pit_based_delay
ENDIF
retn
send_midi_sysex_msg endp
ENDIF
; =============== S U B R O U T I N E =======================================
IF REPLACE_WITH_C_CODE EQ 1
tsub20 proc far
extrn _c_tsub20:far
push si
call _c_tsub20
pop si
retf
tsub20 endp
ELSE
; int __cdecl __far tsub20()
tsub20 proc far
push si
mov ax, 0FFFFh
mov si, cs:word_174_buffer_index2
cmp si, cs:word_172_buffer_index1
jz short tsub20_1
mov ah, 0
mov al, cs:byte_14A_buffer[si]
inc si
cmp si, lengthof byte_14A_buffer
jnz short tsub20_0
mov si, 0
tsub20_0:
mov cs:word_174_buffer_index2, si
tsub20_1:
pop si
retf
tsub20 endp
ENDIF
; =============== S U B R O U T I N E =======================================
; Attributes: bp-based frame
IF REPLACE_WITH_C_CODE EQ 1
tsub21 proc far
extrn _c_tsub21:far
; this sub-call is needed because calls change the stack - but the only real call is in stunts
size_ = word ptr 6
buffer_ = dword ptr 8
push bp
mov bp, sp
les bx, [bp+buffer_] ; segment_@ + offset_@
mov cx, [bp+size_] ; size_@
pop bp
push es
push bx
push cx
call _c_tsub21
add sp,6
retf
tsub21 endp
ELSE
; int __cdecl __far tsub21(__int16 size_, __int8 far *buffer_)
tsub21 proc far
size_ = word ptr 6
buffer_ = dword ptr 8
push bp
mov bp, sp
les bx, [bp+buffer_] ; segment_@ + offset_@
mov cx, [bp+size_] ; size_@
call send_midi_sysex_msg
pop bp
retf
tsub21 endp
ENDIF
; =============== S U B R O U T I N E =======================================
; Attributes: bp-based frame
IF REPLACE_WITH_C_CODE EQ 1
tsub22 proc far
extrn _c_tsub22:far
mt32_plb = dword ptr 6
push bp
mov bp, sp
pushf
push si
push di
push ds
push es
lds si, [bp+mt32_plb]
push ds
push si
call _c_tsub22
add sp,4
pop es
pop ds
pop di
pop si
popf
pop bp
retf
tsub22 endp
ELSE
; tsub22 sends the 05(Patch Memory) and 08(Timbre Memory) sysex messages - based on MT32.PLB content
; void __cdecl tsub22(mt32_plb_t far* mt32_plb_)
tsub22 proc far
mt32_plb = dword ptr 6
push bp
mov bp, sp
pushf
push si
push di
push ds
push es
xor al, al
mov cs:patch_memory_address_byte1, al
mov cs:patch_memory_address_byte2, al
mov cs:timbre_memory_address_byte1, al
mov cs:timbre_memory_address_byte2, al
lds si, [bp+mt32_plb] ; ds=seg, si=ofs
push cs
pop es ; segment_@
mov al, [si] ; ds:[si] ; => 5 => 5 sounds
inc si
mov cs:sounds_left, al ; sound-count ==> 5 sounds
; sounds_left = mt32_plb->sound_count;
;----
or al, al
jnz short tsub22_0
; if( sounds_left != 0 ) // could not happen with stunts MT32.PLB
; {
; goto tsub22_0;
; }
;----
jmp tsub22_3
; ---------------------------------------------------------------------------
tsub22_0:
; -----
mov di, offset msg_buffer
mov byte ptr es:[di], MT32_Patch_memory_address_byte0
inc di
mov al, cs:patch_memory_address_byte1
mov es:[di], al
inc di
mov al, cs:patch_memory_address_byte2
mov es:[di], al
inc di
;msg_buffer -> filled with 0 at start
;
; msg_buffer.address.byte_0 = MT32_Patch_memory_address_byte0;
; msg_buffer.address.byte_1 = patch_memory_address_byte1;
; msg_buffer.address.byte_2 = patch_memory_address_byte2;
; ----
mov al, [si] ; -> 02 - mt32_plb_sound_t.patch_memory_data.timbre_group = 02 == mt32_patch_memory_timbre_group_Memory ---> 5 times hit
push ax
; ----
mov cx, sizeof mt32_patch_memory_t
cld
rep movsb ; Move byte at address DS:SI to address ES:DI
; memcpy(msg_buffer[3], mt32_plb[1], sizeof(mt32_patch_memory_t));
; ----
mov bx, offset msg_buffer ; offset_@
mov cx, sizeof Sysex_address_t + sizeof mt32_patch_memory_t ; size_@ = 11