home *** CD-ROM | disk | FTP | other *** search
/ Large Pack of OldSkool DOS MOD Trackers / funk108a.zip / FUNK_S.ZIP / FUNKLITE.ASM < prev    next >
Assembly Source File  |  1995-07-16  |  214KB  |  6,568 lines

  1. ;=1.08a=;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;                                                                          ;
  3. ; FunkLite - By Super Real Darwin!                                         ;
  4. ;            Designed & Coded By Jason Nunn (JsNO)                         ;
  5. ;                                                                          ;
  6. ; The Playback routines..                                                  ;
  7. ;                                                                          ;
  8. ; Snail: 32 Rothdale Road, Moil, Darwin, NT, Australia                     ;
  9. ; Email: jsno@amigar.apana.org.au                                          ;
  10. ; BBS  : ■ Amiga Retreat BBS (3:850/105)                                   ;
  11. ;          (089)451516                                                     ;
  12. ;                                                                          ;
  13. ; =====================================================================    ;
  14. ;                                                                          ;
  15. ; Funktracker processes sound exclusively in backround. Unlike many        ;
  16. ; playback routines that require mixxer calls to be dotted through out     ;
  17. ; ones code, funktracker processes music totally in backround without any  ;
  18. ; foreground processing required.                                          ;
  19. ;                                                                          ;
  20. ; These is the attachment that contents all code necessary to play a FNK   ;
  21. ; module. Refer to the EXAMPLE.ASM for a demo of how to use.               ;
  22. ;                                                                          ;
  23. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  24.  
  25. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  26. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  27. ;                                                                          ;
  28. ; Global                                                                   ;
  29. ;                                                                          ;
  30. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  31. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  32.  
  33. ; Subjective quality Scale (on my Pentium)
  34. ;
  35. ;              SHITHOUSE           GOOD               EXCELLENT
  36. ;              │                   │                  │
  37. ;
  38. ;        SB2.0│*******
  39. ;        SBPRO│*********************
  40. ;          GUS│************************************
  41. ;         SB16│************************************************
  42. ;        PAS16│**********************************************
  43. ;
  44. ; ■ PAS16 doesn't sound quite as good as the SB16
  45.  
  46. SB_CARD               = 0
  47. SBPRO_CARD            = 1
  48. GUS_VARB_CARD         = 2  ;<<---Channel panning can vary according to sample
  49. SB15EM_CARD           = 3
  50. SB16_CARD             = 4
  51. GUS_FIXB_CARD         = 5  ;<<- fixed DAC/669 style left-right-left-right balances
  52. RIPPED_CARD           = 6
  53. PAS16_CARD            = 7
  54.  
  55. struc tinit_settings
  56.   card_type           db ?
  57.   PORT_no             dd ?
  58.   IRQ_no              db ?
  59.   DMA_no              db ?
  60.   IRQ_no2             db ?
  61.   DMA_no2             db ?
  62.   DAC_Samplerate      db 4
  63. ends
  64. init_settings         tinit_settings <>
  65.  
  66. struc tDAC_ssetings            ; these struc variables control the DMA
  67.   DAC_sr              dd ?     ; a sample rate for each card. The idea
  68.   DAC_mix_buffer_size dd ?     ; is to maintain a 0.02 of a second
  69.   DMA_length          dd ?     ; tick when processing DAC DMA transfers.
  70.   DMA_real_sr         dd ?     ; both tracker and DAC mixxer run of the same interrupt.
  71. ends
  72.  
  73. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  74. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  75. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  76. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  77. ;                                                                          ;
  78. ; Tracker Data                                                             ;
  79. ;                                                                          ;
  80. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  81. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  82. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  83. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  84.  
  85. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  86. ; Structures                               ;
  87. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  88. STOP                   = 0
  89. PLAY                   = 1
  90.  
  91. struc tfunk_sb
  92.   sname                db 19 dup(?)
  93.   start                dd ?
  94.   length               dd ?
  95.   volume               db ?    ; (0 to FF)
  96.   balance              db ?    ; (0 to FF)
  97.   pt_and_sop           db ?
  98.   vv_waveform          db ?
  99.   rl_and_as            db ?
  100. ends
  101.  
  102. struc tfunk_hr
  103.   sig                  dd ?
  104.   info                 dd ?
  105.   LZH_check_size       dd ?
  106.   LZH_check_sum        dd ?    ;this field is no longer used for "checksum"
  107.   loop_order           db ?    ; if FFh then no loop
  108.   order_list           db 256 dup(?)
  109.   break_list           db 128 dup(?)
  110.   funk_sb              tfunk_sb 64 dup(<>)
  111. ends
  112.  
  113. struc tfunk_chan
  114. ;─control system─────────────────
  115.   channel_kill         db PLAY
  116.   command              db ?
  117.   com_val              db ?
  118.   comspd_count         db ?    ; crtl rapid speed delay
  119.   sample               db ?    ; thenis serves no purpose
  120.   start                dd ?
  121.   length               dd ?
  122.   funkctrl             db ?
  123.   port_type            db ?
  124.   sample_ofs_parm      db ?
  125.   vib_waveform         db ?
  126.   vol_vib_waveform     db ?
  127.   retrig_spd_count     db ?
  128.   retrig_count         db ?
  129.   retrig_limit         db ?
  130.   arp_speed            db ?
  131.   balance              db ?    ; 0 to 15
  132. ;─note system────────────────────
  133.   note_command         db ?
  134.   note_com_val         db ?
  135.   note_comspd_count    db ?    ; note rapid speed delay
  136.   note                 db ?
  137.   ifreq                dd ?    ; real_freq = FACTOR / invert_freq
  138.   ifreq_vibrato        dd ?    ; used by vibrato, tremola, freqadetc
  139.   ifreq_portdest       dd ?    ; used by porta
  140.   rfreq                dd ?    ; the real frequency
  141.   rfreq_adjust         dd ?
  142.   rfreq_portdest       dd ?
  143.   vib_ptr              db ?
  144.   note_beat_count      db ?    ; used by arpeggio and retrig, fanin, fanout
  145. ;─volume system──────────────────
  146.   volume_command       db ?
  147.   volume_com_val       db ?
  148.   volume_comspd_count  db ?    ; volume rapid speed delay
  149.   volume               db ?
  150.   volume_vibrato       db ?
  151.   volume_portdest      db ?
  152.   rvolume              db ?
  153.   vol_vib_ptr          db ?
  154.   volume_beat_count    db ?    ; used by reverb, crest, though
  155. ;─card dependant─────────────────
  156.   CARD_sample_ptr      dd ?
  157.   CARD_freq            dd ?
  158.   CARD_freq_attract    dd ?
  159.   CARD_volume          dd ?
  160. ends
  161.  
  162. struc tfunk_info
  163.   trek_status          db ?
  164.   sequence_ofs         db ?
  165.   pattern_ofs          db ?
  166.   sequence_ofs_old     db ?    ;for display purposes
  167.   pattern_ofs2_old     db ?
  168.   tempo                db ?
  169.   tempo_count          db ?
  170.   no_of_patterns       db ?
  171.   no_of_sequences      db ?
  172.   master_volume        db ?
  173.   sample_ptrs          dd 64 dup(?)
  174.   sample_block_size    dd ?
  175.   funk_pd_size         db 80h
  176.   sample_memory_lim    dd 00100000h
  177. ends
  178.  
  179. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  180. ; var                                      ;
  181. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  182.  
  183. note_table:
  184.   dd 13696,12928,12192,11520,10848,10240, 9664, 9120, 8608, 8128, 7680
  185.   dd  7248, 6848, 6464, 6096, 5760, 5424, 5120, 4832, 4560, 4304, 4064
  186.   dd  3840, 3624, 3424, 3232, 3048, 2880, 2712, 2560, 2416, 2280, 2152
  187.   dd  2032, 1920, 1808, 1712, 1616, 1520, 1440, 1360, 1280, 1208, 1144
  188.   dd  1080, 1016,  960,  904,  856,  808,  760,  720,  680,  640,  600
  189.   dd   568,  536,  504,  480,  448,    0,    0,    0,    0
  190. com_ifreq_inc:
  191.   db  001,004,006,010,012,016,020,024
  192.   db  031,047,063,083,107,139,187,251
  193. com_rfreq_inc:
  194.   dd  00016,00032,00048,00064,00096,00128,00160,00192
  195.   dd  00244,00255,00383,00511,00639,00767,00895,01024
  196. com_volume_inc:
  197.   db  001,002,003,004,005,006,007,008
  198.   db  010,012,016,020,024,032,048,064
  199.  
  200. com_sine_table:
  201.   db   -6, -19, -31, -43, -55, -66, -76, -86
  202.   db  -95,-103,-110,-116,-120,-124,-127,-128
  203.   db -128,-127,-124,-121,-116,-110,-103, -95
  204.   db  -86, -77, -66, -55, -44, -32, -19,  -7
  205.   db    6,  18,  30,  42,  54,  65,  76,  85
  206.   db   94, 102, 109, 115, 120, 124, 126, 127
  207.   db  127, 126, 124, 121, 116, 110, 104,  96
  208.   db   87,  77,  67,  56,  44,  32,  20,   8
  209. com_triangle_table:
  210.   db   -4, -12, -20, -28, -36, -44, -52, -60
  211.   db  -68, -76, -84, -92,-100,-108,-116,-124
  212.   db -124,-116,-108,-100, -92, -84, -76, -68
  213.   db  -60, -52, -44, -36, -28, -20, -12,  -4
  214.   db    4,  12,  20,  28,  36,  44,  52,  60
  215.   db   68,  76,  84,  92, 100, 108, 116, 124
  216.   db  123, 115, 107,  99,  91,  83,  75,  67
  217.   db   59,  51,  43,  35,  27,  19,  11,   3
  218. com_square_table:
  219.   db -064,-128,-128,-127,-127,-128,-128,-127
  220.   db -127,-128,-128,-127,-127,-128,-128,-127
  221.   db -127,-128,-128,-127,-127,-128,-128,-127
  222.   db -127,-128,-128,-127,-127,-128,-128,-064
  223.   db  095, 127, 127, 126, 126, 127, 127, 126
  224.   db  126, 127, 127, 126, 126, 127, 127, 126
  225.   db  126, 127, 127, 126, 126, 127, 127, 126
  226.   db  126, 127, 127, 126, 126, 127, 127, 095
  227. com_sawtooth_table:
  228.   db   -1,  -5,  -9, -13, -17, -21, -25, -29
  229.   db  -33, -37, -41, -45, -49, -53, -57, -61
  230.   db  -65, -69, -73, -77, -81, -85, -89, -93
  231.   db  -97,-101,-105,-109,-113,-117,-121,-125
  232.   db  127, 123, 119, 115, 111, 107, 103,  99
  233.   db   95,  91,  87,  83,  79,  75,  71,  67
  234.   db   63,  59,  55,  51,  47,  43,  39,  35
  235.   db   31,  27,  23,  19,  15,  11,   7,   3
  236. com_random_table:
  237.   db  168, 167, 167, 165, 201, 201, 202, 201
  238.   db  244, 244, 244, 244,  85,  82,  85,  85
  239.   db   44,  44,  44,  44, 114, 114, 114, 114
  240.   db   77,  77,  73,  77, 116, 116, 116, 116
  241.   db   87,  87,  87,  87,  31,  31,  31,  31
  242.   db  198, 198, 198, 198, 105, 104, 105, 105
  243.   db  103, 105, 103, 103, 166, 166, 165, 166
  244.   db  171, 172, 171, 171, 217, 217, 217, 217
  245.  
  246. funk_info             tfunk_info <>
  247. funk_chan1            tfunk_chan <>
  248. funk_chan2            tfunk_chan <>
  249. funk_chan3            tfunk_chan <>
  250. funk_chan4            tfunk_chan <>
  251. funk_chan5            tfunk_chan <>
  252. funk_chan6            tfunk_chan <>
  253. funk_chan7            tfunk_chan <>
  254. funk_chan8            tfunk_chan <>
  255.  
  256. CARD_freq_convert     dd ?
  257. CARD_volume_convert   dd ?
  258.  
  259. funk_hr_ptr           dd ?
  260. funk_sd_ptr           dd ?
  261.  
  262. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  263. ;  GET   IRQ vector             ;
  264. ;  expects  BL = IRQ (0..15)    ;
  265. ;  returns  CX = selector       ;
  266. ;           EDX = offset        ;
  267. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  268. proc getirqvector
  269.                 push    eax ebx
  270.                 and     bl,0fh
  271.                 cmp     bl,8
  272.                 jb      @@J2
  273.                 add     bl,60h
  274. @@J2:           add     bl,8h
  275.                 mov     ax,204h
  276.                 int     31h
  277.                 pop     ebx eax
  278.                 ret
  279. endp
  280.  
  281. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  282. ;SET   IRQ vector               ;
  283. ;  expects  BL = IRQ (0..15)    ;
  284. ;           CX = selector       ;
  285. ;           EDX = offset        ;
  286. ;  returns Nothing              ;
  287. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  288. proc setirqvector
  289.                 push    eax ebx
  290.                 and     bl,0fh
  291.                 cmp     bl,8
  292.                 jb      @@J1
  293.                 add     bl,60h
  294. @@J1:           add     bl,8h
  295.                 mov     ax,205h
  296.                 int     31h
  297.                 pop     ebx eax
  298.                 ret
  299. endp
  300.  
  301. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  302. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  303. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  304. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  305. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  306. ;                                                                          ;
  307. ; Tracker Code                                                             ;
  308. ;                                                                          ;
  309. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  310. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  311. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  312. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  313. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  314.  
  315. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  316. ;                                                                          ;
  317. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  318.  
  319. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  320. ;                                  ;
  321. ; ebx = ifreq, returns = eax       ;
  322. ;                                  ;
  323. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  324. proc ifreq_to_rfreq_vib
  325.   add    ebx,[dword edi+tfunk_chan.ifreq_vibrato]
  326.   js     @@zero
  327.   jz     @@zero
  328.   jmp    @@set_r
  329. @@zero:
  330.   mov    ebx,1
  331. @@set_r:
  332. proc ifreq_to_rfreq
  333.   xor    edx,edx
  334.   mov    eax,1b4f4d0h
  335.   div    ebx
  336.   add    eax,[dword edi+tfunk_chan.rfreq_adjust]  ; add 669 freq adjustment
  337.   ret
  338. endp
  339. endp
  340.  
  341. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  342. ;                                  ;
  343. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  344. proc vol_to_realvol
  345.   mov    bl,[byte edi+tfunk_chan.volume]
  346.   mov    [byte edi+tfunk_chan.rvolume],bl
  347.   ret
  348. endp
  349.  
  350. proc vol_to_realvol_vib
  351.   movzx  ebx,[byte edi+tfunk_chan.volume]
  352.   add    ebx,1000
  353.   movzx  eax,[byte edi+tfunk_chan.volume_vibrato]
  354.   or     al,al
  355.   js     @@sub
  356.   add    ebx,eax
  357.   cmp    ebx,1000+0ffh
  358.   ja     @@adjust_add
  359.   jmp    @@done
  360. @@adjust_add:
  361.   mov    ebx,1000+0ffh
  362.   jmp    @@done
  363. @@sub:
  364.   neg    al
  365.   sub    ebx,eax
  366.   cmp    ebx,1000
  367.   jb     @@adjust_sub
  368.   jmp    @@done
  369. @@adjust_sub:
  370.   mov    ebx,1000
  371. @@done:
  372.   sub    ebx,1000
  373.   mov    [byte edi+tfunk_chan.rvolume],bl
  374.   ret
  375. endp
  376.  
  377. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  378. ;                                  ;
  379. ; bl = note, returns bx = ifreq    ;
  380. ;                                  ;
  381. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  382. macro @note_2_ifreq
  383.   and    ebx,111111b
  384.   lea    ebx,[ebx*4]
  385.   mov    ebx,[dword ebx+note_table]
  386. endm
  387.  
  388. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  389. ;                                  ;
  390. ; misc. vibrato function used by   ;
  391. ; frequency and volume functions   ;
  392. ;                                  ;
  393. ; al = waveform                    ;
  394. ; ah = amplitude                   ;
  395. ; cl = speed                       ;
  396. ; ebx = ptr to vibrato table       ;
  397. ; returns al = value, ebx = ptr    ;
  398. ;                                  ;
  399. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  400. proc com_vib_func
  401.   inc    ah
  402.   cmp    al,1
  403.   je     @@vib_triangle
  404.   cmp    al,2
  405.   je     @@vib_square
  406.   cmp    al,3
  407.   je     @@vib_sawtooth
  408.   cmp    al,4
  409.   je     @@vib_random
  410. @@vib_sine:
  411.   mov    al,[byte ebx+com_sine_table]
  412.   jmp    @@get_func_value
  413. @@vib_triangle:
  414.   mov    al,[byte ebx+com_triangle_table]
  415.   jmp    @@get_func_value
  416. @@vib_square:
  417.   mov    al,[byte ebx+com_square_table]
  418.   jmp    @@get_func_value
  419. @@vib_sawtooth:
  420.   mov    al,[byte ebx+com_sawtooth_table]
  421.   jmp    @@get_func_value
  422. @@vib_random:
  423.   mov    al,[byte ebx+com_random_table]
  424. @@get_func_value:
  425.   imul   ah
  426.   shr    eax,4
  427.   not    cl
  428.   and    cl,1111b
  429.   add    bl,cl
  430.   inc    bl
  431.   and    bl,111111b
  432.   ret
  433. endp
  434.  
  435. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  436. ;                                  ;
  437. ; for NOTE 3D: reload samples      ;
  438. ; attributes                       ;
  439. ;                                  ;
  440. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  441. proc reload_sample_attr
  442.   movzx  eax,[word esi]                            ;extract sample no
  443.   xchg   al,ah
  444.   shr    eax,4
  445.   and    eax,03fh
  446.   mov    [byte edi+tfunk_chan.sample],al
  447.   shl    eax,5
  448.   add    eax,[funk_hr_ptr]
  449.   add    eax,offset (tfunk_hr).funk_sb
  450. proc reload_sample2
  451.   mov    bl,[byte eax+tfunk_sb.balance]           ; get balance
  452.   mov    [byte edi+tfunk_chan.balance],bl
  453.   mov    bl,[byte eax+tfunk_sb.pt_and_sop]        ; get both port type and sample ofs parm
  454.   mov    dl,bl
  455.   shr    bl,4
  456.   and    dl,1111b
  457.   mov    [byte edi+tfunk_chan.port_type],bl
  458.   mov    [byte edi+tfunk_chan.sample_ofs_parm],dl
  459.   mov    bl,[byte eax+tfunk_sb.vv_waveform]       ; get both vibrato wf & tremola wf
  460.   mov    dl,bl
  461.   shr    bl,4
  462.   and    dl,1111b
  463.   mov    [byte edi+tfunk_chan.vib_waveform],bl
  464.   mov    [byte edi+tfunk_chan.vol_vib_waveform],dl
  465.   mov    bl,[byte eax+tfunk_sb.rl_and_as]         ; get both retrig speed & arp speed
  466.   mov    dl,bl
  467.   shr    bl,4
  468.   and    dl,1111b
  469.   mov    [byte edi+tfunk_chan.retrig_limit],bl
  470.   mov    [byte edi+tfunk_chan.arp_speed],dl
  471.   mov    dl,[byte eax+tfunk_sb.volume]
  472.   ret
  473. endp
  474. endp
  475.  
  476. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  477. ;                                  ;
  478. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  479. proc decode_sample
  480.   movzx  eax,[word esi]                            ;extract sample no
  481.   xchg   al,ah
  482.   shr    eax,4
  483.   and    eax,03fh
  484.   mov    [byte edi+tfunk_chan.sample],al
  485. proc do_retrig_sample
  486.   movzx  eax,al
  487.   push   eax
  488.   shl    eax,5
  489.   add    eax,[funk_hr_ptr]
  490.   add    eax,offset (tfunk_hr).funk_sb
  491.   mov    [byte edi+tfunk_chan.funkctrl],10b       ; set funkctrl
  492.   mov    ebx,[dword eax+tfunk_sb.start]
  493.   cmp    ebx,0ffffffffh
  494.   je     @@dont_loop
  495.   mov    [byte edi+tfunk_chan.funkctrl],11b       ; set funkctrl
  496. @@dont_loop:
  497.   mov    [dword edi+tfunk_chan.start],ebx
  498.   mov    ebx,[dword eax+tfunk_sb.length]
  499.   mov    [dword edi+tfunk_chan.length],ebx
  500.   call   reload_sample2
  501.   pop    eax
  502.   lea    eax,[eax*4]
  503.   mov    eax,[dword eax+funk_info.sample_ptrs]
  504.   add    [dword edi+tfunk_chan.start],eax
  505.   add    [dword edi+tfunk_chan.length],eax
  506.   mov    [dword edi+tfunk_chan.CARD_sample_ptr],eax
  507.   ret
  508. endp
  509. endp
  510.  
  511. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  512. ;                                  ;
  513. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  514. proc do_full_note
  515.   mov    [byte edi+tfunk_chan.note],bl
  516.   mov    bl,[byte edi+tfunk_chan.note]
  517.   mov    [byte edi+tfunk_chan.volume],dl
  518.   @note_2_ifreq
  519.   mov    [dword edi+tfunk_chan.ifreq],ebx
  520.   call   ifreq_to_rfreq
  521.   mov    [dword edi+tfunk_chan.rfreq],eax
  522.   call   vol_to_realvol
  523.   call   [dword CARD_freq_convert]
  524.   call   [dword CARD_volume_convert]
  525.   ret
  526. endp
  527.  
  528. proc load_attr_active
  529.   mov    [byte edi+tfunk_chan.volume],dl
  530.   call   vol_to_realvol
  531.   call   [dword CARD_volume_convert]
  532.   ret
  533. endp
  534.  
  535. proc normal_decode_system
  536.   mov    bl,[byte esi]                            ;extract note value
  537.   shr    bl,2
  538.   cmp    bl,3dh                                   ; of ReLOad samples then ...
  539.   je     @@ReLOad_samples
  540.   push   ebx
  541.   call   decode_sample
  542.   pop    ebx
  543.   cmp    bl,3eh                                   ; of SAMPLE ONLY slot
  544.   je     @@no_note_change                         ; then dont change note
  545.   mov    [byte edi+tfunk_chan.note_command],0fh
  546.   mov    [byte edi+tfunk_chan.volume_command],0fh
  547.   call   do_full_note
  548. @@no_note_change:
  549.   ret
  550. @@ReLOad_samples:
  551.   call   reload_sample_attr
  552.   call   load_attr_active
  553.   ret
  554. endp
  555.  
  556. proc normal_decode_note
  557.   mov    bl,[byte esi]                            ;extract note value
  558.   shr    bl,2
  559.   cmp    bl,3dh                                   ; of ReLOad samples then ...
  560.   je     @@ReLOad_samples
  561.   push   ebx
  562.   call   decode_sample
  563.   pop    ebx
  564.   cmp    bl,3eh                                   ; of SAMPLE ONLY slot
  565.   je     @@no_note_change                         ; then dont change note
  566.   mov    [byte edi+tfunk_chan.volume_command],0fh
  567.   call   do_full_note
  568. @@no_note_change:
  569.   ret
  570. @@ReLOad_samples:
  571.   call   reload_sample_attr
  572.   call   load_attr_active
  573.   ret
  574. endp
  575.  
  576. proc normal_decode_volume
  577.   mov    bl,[byte esi]                            ;extract note value
  578.   shr    bl,2
  579.   cmp    bl,3dh                                   ; of ReLOad samples then ...
  580.   je     @@ReLOad_samples
  581.   push   ebx
  582.   call   decode_sample
  583.   pop    ebx
  584.   cmp    bl,3eh                                   ; of SAMPLE ONLY slot
  585.   je     @@no_note_change                         ; then dont change note
  586.   mov    [byte edi+tfunk_chan.note_command],0fh
  587.   call   do_full_note
  588. @@no_note_change:
  589.   ret
  590. @@ReLOad_samples:
  591.   call   reload_sample_attr
  592.   call   load_attr_active
  593.   ret
  594. endp
  595.  
  596. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  597. ;                                  ;
  598. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  599. proc comc_decode
  600.   mov    bl,[byte esi]                            ;extract note value
  601.   shr    bl,2
  602.   cmp    bl,3dh                                   ; of ReLOad samples then ...
  603.   je     @@ReLOad_samples
  604.   push   ebx
  605.   call   decode_sample
  606.   pop    ebx
  607.   cmp    bl,3eh                                   ; of SAMPLE ONLY slot
  608.   je     @@cc_no_note_change                      ; then dont change note
  609.   mov    [byte edi+tfunk_chan.volume_command],0fh
  610.   mov    [byte edi+tfunk_chan.volume],dl
  611.   mov    [byte edi+tfunk_chan.note],bl
  612.   @note_2_ifreq
  613.   mov    [dword edi+tfunk_chan.ifreq_portdest],ebx
  614.   call   ifreq_to_rfreq
  615.   mov    [dword edi+tfunk_chan.rfreq_portdest],eax
  616.   call   vol_to_realvol
  617.   call   [dword CARD_freq_convert]
  618.   call   [dword CARD_volume_convert]
  619. @@cc_no_note_change:
  620.   ret
  621. @@ReLOad_samples:
  622.   call   reload_sample_attr
  623.   call   load_attr_active
  624.   ret
  625. endp
  626.  
  627. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  628. ;                                  ;
  629. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  630. proc comi_decode
  631.   mov    bl,[byte esi]                            ;extract note value
  632.   shr    bl,2
  633.   cmp    bl,3dh                                   ; of ReLOad samples then ...
  634.   je     @@ReLOad_samples
  635.   push   ebx
  636.   call   decode_sample
  637.   pop    ebx
  638.   cmp    bl,3eh                                   ; of SAMPLE ONLY slot
  639.   je     @@no_note_change                         ; then dont change note
  640.   mov    [byte edi+tfunk_chan.note_command],0fh
  641.   mov    [byte edi+tfunk_chan.volume_portdest],dl
  642.   mov    [byte edi+tfunk_chan.note],bl
  643.   @note_2_ifreq
  644.   mov    [dword edi+tfunk_chan.ifreq],ebx
  645.   call   ifreq_to_rfreq
  646.   mov    [dword edi+tfunk_chan.rfreq],eax
  647.   call   vol_to_realvol
  648.   call   [dword CARD_freq_convert]
  649.   call   [dword CARD_volume_convert]
  650.   ret
  651. @@no_note_change:
  652.   mov    [byte edi+tfunk_chan.note_command],0fh
  653.   mov    [byte edi+tfunk_chan.volume_portdest],dl
  654.   call   vol_to_realvol
  655.   call   [dword CARD_freq_convert]
  656.   call   [dword CARD_volume_convert]
  657.   ret
  658. @@ReLOad_samples:
  659.   call   reload_sample_attr
  660.   jmp    @@no_note_change
  661. endp
  662.  
  663. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  664. ;                                                                          ;
  665. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  666.  
  667. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  668. ;0Com A: port up                   ;
  669. ;                                  ;
  670. ; com_val : 0000   0000            ;
  671. ;                 \rate/           ;
  672. ;                                  ;
  673. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  674. proc com_port_up_log
  675.   mov    bl,[byte edi+tfunk_chan.note_com_val]
  676.   and    ebx,1111b
  677.   movzx  eax,[byte ebx+com_ifreq_inc]
  678.   sub    [dword edi+tfunk_chan.ifreq],eax
  679.   cmp    [dword edi+tfunk_chan.ifreq],300
  680.   ja     @@done
  681.   mov    [byte edi+tfunk_chan.note_command],0fh
  682.   mov    [dword edi+tfunk_chan.ifreq],300
  683. @@done:
  684.   mov    ebx,[dword edi+tfunk_chan.ifreq]
  685.   call   ifreq_to_rfreq
  686.   mov    [dword edi+tfunk_chan.rfreq],eax
  687.   call   [dword CARD_freq_convert]
  688.   ret
  689. endp
  690.  
  691. proc com_port_up_lin
  692.   mov    bl,[byte edi+tfunk_chan.note_com_val]
  693.   and    ebx,1111b
  694.   lea    ebx,[ebx*4]
  695.   mov    eax,[dword ebx+com_rfreq_inc]
  696.   add    [dword edi+tfunk_chan.rfreq],eax
  697.   cmp    [dword edi+tfunk_chan.rfreq],174deh
  698.   jb     @@done
  699.   mov    [byte edi+tfunk_chan.note_command],0fh
  700.   mov    [dword edi+tfunk_chan.rfreq],174deh
  701. @@done:
  702.   call   [dword CARD_freq_convert]
  703.   ret
  704. endp
  705.  
  706. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  707. ;1Com B: port down                 ;
  708. ;                                  ;
  709. ; com_val : 0000   0000            ;
  710. ;                 \rate/           ;
  711. ;                                  ;
  712. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  713. proc com_port_dn_log
  714.   mov    bl,[byte edi+tfunk_chan.note_com_val]
  715.   and    ebx,1111b
  716.   movzx  eax,[byte ebx+com_ifreq_inc]
  717.   add    [dword edi+tfunk_chan.ifreq],eax
  718.   cmp    [dword edi+tfunk_chan.ifreq],20000
  719.   jb     @@done
  720.   mov    [byte edi+tfunk_chan.note_command],0fh
  721.   mov    [dword edi+tfunk_chan.ifreq],20000
  722. @@done:
  723.   mov    ebx,[dword edi+tfunk_chan.ifreq]
  724.   call   ifreq_to_rfreq
  725.   mov    [dword edi+tfunk_chan.rfreq],eax
  726.   call   [dword CARD_freq_convert]
  727.   ret
  728. endp
  729.  
  730. proc com_port_dn_lin
  731.   mov    bl,[byte edi+tfunk_chan.note_com_val]
  732.   and    ebx,1111b
  733.   lea    ebx,[ebx*4]
  734.   mov    eax,[dword ebx+com_rfreq_inc]
  735.   sub    [dword edi+tfunk_chan.rfreq],eax
  736.   cmp    [dword edi+tfunk_chan.rfreq],1431
  737.   ja     @@done
  738.   mov    [byte edi+tfunk_chan.note_command],0fh
  739.   mov    [dword edi+tfunk_chan.rfreq],1431
  740. @@done:
  741.   call   [dword CARD_freq_convert]
  742.   ret
  743. endp
  744.  
  745. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  746. ;2Com C: port to note              ;
  747. ;                                  ;
  748. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  749. proc com_porta_log
  750.   mov    eax,[dword edi+tfunk_chan.ifreq_portdest]
  751.   cmp    [dword edi+tfunk_chan.ifreq],eax
  752.   jne    @@not_same
  753.   mov    [byte edi+tfunk_chan.note_command],0fh
  754.   ret
  755. @@not_same:
  756.   ja     @@do_portup
  757.   call   com_port_dn_log
  758.   mov    eax,[dword edi+tfunk_chan.ifreq_portdest]
  759.   cmp    [dword edi+tfunk_chan.ifreq],eax
  760.   jb     @@done
  761.   mov    [byte edi+tfunk_chan.note_command],0fh
  762.   mov    [dword edi+tfunk_chan.ifreq],eax
  763.   jmp    @@done
  764. @@do_portup:
  765.   call   com_port_up_log
  766.   mov    eax,[dword edi+tfunk_chan.ifreq_portdest]
  767.   cmp    [dword edi+tfunk_chan.ifreq],eax
  768.   ja     @@done
  769.   mov    [byte edi+tfunk_chan.note_command],0fh
  770.   mov    [dword edi+tfunk_chan.ifreq],eax
  771. @@done:
  772.   mov    ebx,[dword edi+tfunk_chan.ifreq]
  773.   call   ifreq_to_rfreq
  774.   mov    [dword edi+tfunk_chan.rfreq],eax
  775.   call   [dword CARD_freq_convert]
  776.   ret
  777. endp
  778.  
  779. proc com_porta_lin
  780.   mov    eax,[dword edi+tfunk_chan.rfreq_portdest]
  781.   cmp    [dword edi+tfunk_chan.rfreq],eax
  782.   jne    @@not_same
  783.   mov    [byte edi+tfunk_chan.note_command],0fh
  784.   ret
  785. @@not_same:
  786.   jb     @@do_portup
  787.   call   com_port_dn_lin
  788.   mov    eax,[dword edi+tfunk_chan.rfreq_portdest]
  789.   cmp    [dword edi+tfunk_chan.rfreq],eax
  790.   ja     @@done
  791.   mov    [byte edi+tfunk_chan.note_command],0fh
  792.   mov    [dword edi+tfunk_chan.rfreq],eax
  793.   jmp    @@done
  794. @@do_portup:
  795.   call   com_port_up_lin
  796.   mov    eax,[dword edi+tfunk_chan.rfreq_portdest]
  797.   cmp    [dword edi+tfunk_chan.rfreq],eax
  798.   jb     @@done
  799.   mov    [byte edi+tfunk_chan.note_command],0fh
  800.   mov    [dword edi+tfunk_chan.rfreq],eax
  801. @@done:
  802.   call   [dword CARD_freq_convert]
  803.   ret
  804. endp
  805.  
  806. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  807. ;                                                                          ;
  808. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  809. proc note_system_rapid_p1
  810.   mov    eax,[dword edi+tfunk_chan.note_command]
  811.   cmp    al,02h
  812.   jbe    @@do_rp1
  813.   ret
  814. @@do_rp1:
  815.   shr    ah,4
  816.   cmp    [byte edi+tfunk_chan.note_comspd_count],ah
  817.   jae    @@speed_match
  818.   inc    [byte edi+tfunk_chan.note_comspd_count]
  819.   ret
  820. @@speed_match:
  821.   mov    [byte edi+tfunk_chan.note_comspd_count],0
  822.   cmp    [byte edi+tfunk_chan.port_type],1
  823.   je     @@line_porta
  824.   or     al,al
  825.   je     @@command_a_i
  826.   cmp    al,01h
  827.   je     @@command_b_i
  828.   cmp    al,02h
  829.   je     @@command_c_i
  830.   ret
  831. @@line_porta:
  832.   or     al,al
  833.   je     @@command_a_r
  834.   cmp    al,01h
  835.   je     @@command_b_r
  836.   cmp    al,02h
  837.   je     @@command_c_r
  838.   ret
  839. @@command_a_i:
  840.   call   com_port_up_log
  841.   ret
  842. @@command_a_r:
  843.   call   com_port_up_lin
  844.   ret
  845. @@command_b_i:
  846.   call   com_port_dn_log
  847.   ret
  848. @@command_b_r:
  849.   call   com_port_dn_lin
  850.   ret
  851. @@command_c_i:
  852.   call   com_porta_log
  853.   ret
  854. @@command_c_r:
  855.   call   com_porta_lin
  856.   ret
  857. endp
  858.  
  859. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  860. ;3Com D: vibrato                   ;
  861. ;                                  ;
  862. ; com_val :   0000   0000          ;
  863. ;           \speed/ \amplitude/    ;
  864. ;                                  ;
  865. ;vib_waveform = 0   : sine         ;
  866. ;               1   : triangle     ;
  867. ;               2   : square       ;
  868. ;               3   : sawtooth     ;
  869. ;               4   : random       ;
  870. ;                                  ;
  871. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  872. proc com_vibrato
  873.   mov    ah,[byte edi+tfunk_chan.note_com_val]
  874.   mov    cl,ah
  875.   and    ah,00001111b
  876.   shr    cl,4
  877. proc com_vibrato_minor
  878.   movzx  ebx,[byte edi+tfunk_chan.vib_ptr]
  879.   mov    al,[byte edi+tfunk_chan.vib_waveform]
  880.   call   com_vib_func
  881.   mov    [byte edi+tfunk_chan.vib_ptr],bl
  882.   movsx  eax,al
  883.   shl    eax,1
  884.   mov    [dword edi+tfunk_chan.ifreq_vibrato],eax
  885.   mov    ebx,[dword edi+tfunk_chan.ifreq]
  886.   call   ifreq_to_rfreq_vib
  887.   mov    [dword edi+tfunk_chan.rfreq],eax
  888.   call   [dword CARD_freq_convert]
  889.   ret
  890. endp
  891. endp
  892.  
  893. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  894. ;4Com E: vibrato Fanin             ;
  895. ;                                  ;
  896. ; com_val :   0000   0000          ;
  897. ;           \speed/ \fanin value/  ;
  898. ;                                  ;
  899. ;vib_waveform = 0   : sine         ;
  900. ;               1   : triangle     ;
  901. ;               2   : square       ;
  902. ;               3   : sawtooth     ;
  903. ;               4   : random       ;
  904. ;                                  ;
  905. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  906. proc com_vib_fanin
  907.   mov    ah,[byte edi+tfunk_chan.note_com_val]
  908.   mov    cl,ah
  909.   and    ah,00001111b
  910.   and    cl,11110000b
  911.   shr    cl,2
  912.   cmp    [byte edi+tfunk_chan.note_beat_count],0fh
  913.   jae    @@do_vibrato
  914.   cmp    [byte edi+tfunk_chan.note_comspd_count],cl
  915.   jae    @@inc_fan
  916.   inc    [byte edi+tfunk_chan.note_comspd_count]
  917.   jmp    @@do_vibrato
  918. @@inc_fan:
  919.   mov    [byte edi+tfunk_chan.note_comspd_count],0
  920.   inc    [byte edi+tfunk_chan.note_beat_count]
  921. @@do_vibrato:
  922.   mov    cl,[byte edi+tfunk_chan.note_beat_count]
  923.   call   com_vibrato_minor
  924.   ret
  925. endp
  926.  
  927. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  928. ;5Com F: vibrato Fanout            ;
  929. ;                                  ;
  930. ; com_val :   0000   0000          ;
  931. ;           \speed/ \fanin value/  ;
  932. ;                                  ;
  933. ;vib_waveform = 0   : sine         ;
  934. ;               1   : triangle     ;
  935. ;               2   : square       ;
  936. ;               3   : sawtooth     ;
  937. ;               4   : random       ;
  938. ;                                  ;
  939. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  940. proc com_vib_fanout
  941.   mov    ah,[byte edi+tfunk_chan.note_com_val]
  942.   mov    cl,ah
  943.   and    ah,00001111b
  944.   and    cl,11110000b
  945.   shr    cl,2
  946.   cmp    [byte edi+tfunk_chan.note_beat_count],0
  947.   je     @@do_vibrato
  948.   cmp    [byte edi+tfunk_chan.note_comspd_count],cl
  949.   jae    @@dec_fan
  950.   inc    [byte edi+tfunk_chan.note_comspd_count]
  951.   jmp    @@do_vibrato
  952. @@dec_fan:
  953.   mov    [byte edi+tfunk_chan.note_comspd_count],0
  954.   dec    [byte edi+tfunk_chan.note_beat_count]
  955. @@do_vibrato:
  956.   mov    cl,[byte edi+tfunk_chan.note_beat_count]
  957.   call   com_vibrato_minor
  958.   ret
  959. endp
  960.  
  961. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  962. ;6Com G: volume sld up             ;
  963. ;                                  ;
  964. ; com_val : 0000   0000            ;
  965. ;                 \rate/           ;
  966. ;                                  ;
  967. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  968. proc com_vol_up
  969.   mov    bl,[byte edi+tfunk_chan.volume_com_val]
  970.   and    ebx,1111b
  971.   mov    al,[byte ebx+com_volume_inc]
  972.   mov    ah,[byte edi+tfunk_chan.volume]
  973.   add    ah,al
  974.   jnc    @@adjust
  975.   mov    [byte edi+tfunk_chan.volume_command],0fh
  976.   mov    [byte edi+tfunk_chan.volume],255
  977.   jmp    @@done
  978. @@adjust:
  979.   mov    [byte edi+tfunk_chan.volume],ah
  980. @@done:
  981.   call   vol_to_realvol
  982.   call   [dword CARD_volume_convert]
  983.   ret
  984. endp
  985.  
  986. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  987. ;7Com H: volume slide down         ;
  988. ;                                  ;
  989. ; com_val : 0000   0000            ;
  990. ;                 \rate/           ;
  991. ;                                  ;
  992. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  993. proc com_vol_dn
  994.   mov    bl,[byte edi+tfunk_chan.volume_com_val]
  995.   and    ebx,1111b
  996.   mov    al,[byte ebx+com_volume_inc]
  997.   mov    ah,[byte edi+tfunk_chan.volume]
  998.   sub    ah,al
  999.   jnc    @@adjust
  1000.   mov    [byte edi+tfunk_chan.volume_command],0fh
  1001.   mov    [byte edi+tfunk_chan.volume],0
  1002.   jmp    @@done
  1003. @@adjust:
  1004.   mov    [byte edi+tfunk_chan.volume],ah
  1005. @@done:
  1006.   call   vol_to_realvol
  1007.   call   [dword CARD_volume_convert]
  1008.   ret
  1009. endp
  1010.  
  1011. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1012. ;8Com I: volume porta (Rapid ctrl) ;
  1013. ;                                  ;
  1014. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1015. proc com_vol_porta
  1016.   mov    al,[byte edi+tfunk_chan.volume_portdest]
  1017.   cmp    [byte edi+tfunk_chan.volume],al
  1018.   jne    @@not_same
  1019.   mov    [byte edi+tfunk_chan.volume_command],0fh
  1020.   jmp    @@done
  1021. @@not_same:
  1022.   jb     @@do_portup
  1023.   call   com_vol_dn
  1024.   mov    al,[byte edi+tfunk_chan.volume_portdest]
  1025.   cmp    [byte edi+tfunk_chan.volume],al
  1026.   ja     @@done
  1027.   mov    [byte edi+tfunk_chan.volume_command],0fh
  1028.   mov    [byte edi+tfunk_chan.volume],al
  1029.   jmp    @@done
  1030. @@do_portup:
  1031.   call   com_vol_up
  1032.   mov    al,[byte edi+tfunk_chan.volume_portdest]
  1033.   cmp    [byte edi+tfunk_chan.volume],al
  1034.   jb     @@done
  1035.   mov    [byte edi+tfunk_chan.volume_command],0fh
  1036.   mov    [byte edi+tfunk_chan.volume],al
  1037. @@done:
  1038.   call   vol_to_realvol
  1039.   call   [dword CARD_volume_convert]
  1040.   ret
  1041. endp
  1042.  
  1043. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1044. ;                                                                          ;
  1045. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1046. proc volume_system_rapid_p1
  1047.   mov    eax,[dword edi+tfunk_chan.volume_command]
  1048.   cmp    al,06h
  1049.   jae    @@do_rp1
  1050.   ret
  1051. @@do_rp1:
  1052.   cmp    al,08h
  1053.   jbe    @@do_rp2
  1054.   ret
  1055. @@do_rp2:
  1056.   shr    ah,4
  1057.   cmp    [byte edi+tfunk_chan.volume_comspd_count],ah
  1058.   jae    @@speed_match
  1059.   inc    [byte edi+tfunk_chan.volume_comspd_count]
  1060.   ret
  1061. @@speed_match:
  1062.   mov    [byte edi+tfunk_chan.volume_comspd_count],0
  1063.   cmp    al,06h
  1064.   je     @@command_g
  1065.   cmp    al,07h
  1066.   je     @@command_h
  1067.   cmp    al,08h
  1068.   je     @@command_i
  1069.   ret
  1070. @@command_g:
  1071.   call   com_vol_up
  1072.   ret
  1073. @@command_h:
  1074.   call   com_vol_dn
  1075.   ret
  1076. @@command_i:
  1077.   call   com_vol_porta
  1078.   ret
  1079. endp
  1080.  
  1081. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1082. ;9Com J: Volume Reverb             ;
  1083. ;                                  ;
  1084. ; A simulated echo effect          ;
  1085. ;                                  ;
  1086. ; com_val : 0000   0000            ;
  1087. ;                                  ;
  1088. ;                                  ;
  1089. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1090. proc com_reverb
  1091.   mov    cl,[byte edi+tfunk_chan.volume_com_val]
  1092.   mov    ch,cl
  1093.   mov    dl,cl
  1094.   and    ch,00001111b
  1095.   and    cl,11110000b
  1096.   shr    cl,2
  1097.   cmp    [byte edi+tfunk_chan.volume_comspd_count],cl
  1098.   jae    @@echo
  1099.   inc    [byte edi+tfunk_chan.volume_comspd_count]
  1100. @@do_slide:
  1101.   cmp    [byte edi+tfunk_chan.volume],0
  1102.   je     @@done
  1103.   movzx  ecx,ch
  1104.   mov    al,[byte ecx+com_volume_inc]
  1105.   mov    ah,[byte edi+tfunk_chan.volume]
  1106.   sub    ah,al
  1107.   jnc    @@adjust
  1108.   mov    [byte edi+tfunk_chan.volume],0
  1109.   jmp    @@done
  1110. @@adjust:
  1111.   mov    [byte edi+tfunk_chan.volume],ah
  1112. @@done:
  1113.   call   vol_to_realvol
  1114.   call   [dword CARD_volume_convert]
  1115.   ret
  1116. @@echo:
  1117.   mov    [byte edi+tfunk_chan.volume_comspd_count],0
  1118.   neg    dl
  1119.   shr    dl,4
  1120.   sub    [byte edi+tfunk_chan.volume_beat_count],dl
  1121.   jc     @@end
  1122.   mov    al,[byte edi+tfunk_chan.volume_beat_count]
  1123.   mov    [byte edi+tfunk_chan.volume],al
  1124.   jmp    @@done
  1125. @@end:
  1126.   mov    [byte edi+tfunk_chan.volume_command],0fh
  1127.   mov    [byte edi+tfunk_chan.volume],0
  1128.   call   vol_to_realvol
  1129.   call   [dword CARD_volume_convert]
  1130.   ret
  1131. endp
  1132.  
  1133. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1134. ;ACom K: tremola                   ;
  1135. ;                                  ;
  1136. ; com_val :  0000    0000          ;
  1137. ;                   \rate/         ;
  1138. ;                                  ;
  1139. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1140. proc com_tremola
  1141.   mov    ah,[byte edi+tfunk_chan.volume_com_val]
  1142.   mov    cl,ah
  1143.   and    ah,00001111b
  1144.   shr    cl,4
  1145.   movzx  ebx,[byte edi+tfunk_chan.vol_vib_ptr]
  1146.   mov    al,[byte edi+tfunk_chan.vol_vib_waveform]
  1147.   call   com_vib_func
  1148.   mov    [byte edi+tfunk_chan.vol_vib_ptr],bl
  1149.   mov    [byte edi+tfunk_chan.volume_vibrato],al
  1150.   call   vol_to_realvol_vib
  1151.   call   [dword CARD_volume_convert]
  1152.   ret
  1153. endp
  1154.  
  1155. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1156. ;BCom L: arpeggio                  ;
  1157. ;                                  ;
  1158. ; com_val :  0000    0000          ;
  1159. ;            \N1/    \N2/          ;
  1160. ;                                  ;
  1161. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1162. proc com_arpeggio
  1163.   mov    al,[byte edi+tfunk_chan.note_com_val]
  1164.   mov    bh,[byte edi+tfunk_chan.arp_speed]
  1165.   cmp    [byte edi+tfunk_chan.note_comspd_count],bh
  1166.   jae    @@speed_match
  1167.   inc    [byte edi+tfunk_chan.note_comspd_count]
  1168.   ret
  1169. @@speed_match:
  1170.   mov    [byte edi+tfunk_chan.note_comspd_count],0
  1171.   mov    bl,[byte edi+tfunk_chan.note]
  1172.   cmp    [byte edi+tfunk_chan.note_beat_count],1   ; arp_type 1
  1173.   je     @@arp1_t1
  1174.   cmp    [byte edi+tfunk_chan.note_beat_count],2
  1175.   je     @@arp1_t2
  1176.   jmp    @@done
  1177. @@arp1_t1:
  1178.   shr    al,4
  1179.   jmp    @@arp_it
  1180. @@arp1_t2:
  1181.   and    al,1111b
  1182. @@arp_it:
  1183.   add    bl,al
  1184.   cmp    bl,59
  1185.   jbe    @@done
  1186.   mov    bl,[byte edi+tfunk_chan.note]
  1187. @@done:
  1188.   @note_2_ifreq
  1189.   mov    [dword edi+tfunk_chan.ifreq],ebx
  1190.   call   ifreq_to_rfreq
  1191.   mov    [dword edi+tfunk_chan.rfreq],eax
  1192.   call   [dword CARD_freq_convert]
  1193.   cmp    [byte edi+tfunk_chan.note_beat_count],2
  1194.   je     @@clr_b
  1195.   inc    [byte edi+tfunk_chan.note_beat_count]
  1196.   ret
  1197. @@clr_b:
  1198.   mov    [byte edi+tfunk_chan.note_beat_count],0
  1199.   ret
  1200. endp
  1201.  
  1202. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1203. ;CCom M: sample offset             ;
  1204. ;                                  ;
  1205. ; This is a all present sample     ;
  1206. ; offset that is effective all the ;
  1207. ; time for a given channel         ;
  1208. ;                                  ;
  1209. ;                                  ;
  1210. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1211. proc com_sample_offset
  1212.   movzx  eax,[byte edi+tfunk_chan.com_val]
  1213.   mov    cl,[byte edi+tfunk_chan.sample_ofs_parm]
  1214.   shl    eax,cl
  1215.   add    [dword edi+tfunk_chan.CARD_sample_ptr],eax
  1216.   ret
  1217. endp
  1218.  
  1219. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1220. ;DCom N: volume                    ;
  1221. ;                                  ;
  1222. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1223. proc com_volume
  1224.   mov    al,[byte edi+tfunk_chan.volume_com_val]
  1225.   mov    [byte edi+tfunk_chan.volume],al
  1226.   call   vol_to_realvol
  1227.   call   [dword CARD_volume_convert]
  1228.   ret
  1229. endp
  1230.  
  1231. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1232. ;ECom O0: misc control             ;
  1233. ;                                  ;
  1234. ;value  control set                ;
  1235. ;------------------                ;
  1236. ;0     vibrato sine                ;
  1237. ;1     vibrato triangle            ;
  1238. ;2     vibrato square              ;
  1239. ;3     vibrato sawtooth            ;
  1240. ;4     vibrato random              ;
  1241. ;5     tremola sine                ;
  1242. ;6     tremola triangle            ;
  1243. ;7     tremola square              ;
  1244. ;8     tremola sawtooth            ;
  1245. ;9     tremola random              ;
  1246. ;a     halt note system            ;
  1247. ;b     halt volume system          ;
  1248. ;c     halt all systems            ;
  1249. ;d     invert funkcrtl             ;
  1250. ;e     algorithmic porting         ;
  1251. ;f     linear porting              ;
  1252. ;                                  ;
  1253. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1254. proc com_misccrtl
  1255.   mov    al,[byte edi+tfunk_chan.com_val]
  1256.   and    al,00001111b
  1257.   or     al,al
  1258.   jz     @@vib_sine
  1259.   cmp    al,01h
  1260.   je     @@vib_triangle
  1261.   cmp    al,02h
  1262.   je     @@vib_square
  1263.   cmp    al,03h
  1264.   je     @@vib_sawtooth
  1265.   cmp    al,04h
  1266.   je     @@vib_random
  1267.   cmp    al,05h
  1268.   je     @@trm_sine
  1269.   cmp    al,06h
  1270.   je     @@trm_triangle
  1271.   cmp    al,07h
  1272.   je     @@trm_square
  1273.   cmp    al,08h
  1274.   je     @@trm_sawtooth
  1275.   cmp    al,09h
  1276.   je     @@trm_random
  1277.   cmp    al,0ah
  1278.   je     @@halt_note_sys
  1279.   cmp    al,0bh
  1280.   je     @@halt_vol_sys
  1281.   cmp    al,0ch
  1282.   je     @@halt_all_sys
  1283.   cmp    al,0dh
  1284.   je     @@invert_funk
  1285.   cmp    al,0eh
  1286.   je     @@log_porta
  1287.   cmp    al,0fh
  1288.   je     @@lin_porta
  1289.   ret
  1290. @@vib_sine:
  1291.   mov    [byte edi+tfunk_chan.vib_waveform],0
  1292.   ret
  1293. @@vib_triangle:
  1294.   mov    [byte edi+tfunk_chan.vib_waveform],1
  1295.   ret
  1296. @@vib_square:
  1297.   mov    [byte edi+tfunk_chan.vib_waveform],2
  1298.   ret
  1299. @@vib_sawtooth:
  1300.   mov    [byte edi+tfunk_chan.vib_waveform],3
  1301.  ret
  1302. @@vib_random:
  1303.   mov    [byte edi+tfunk_chan.vib_waveform],4
  1304.   ret
  1305. @@trm_sine:
  1306.   mov    [byte edi+tfunk_chan.vol_vib_waveform],0
  1307.   ret
  1308. @@trm_triangle:
  1309.   mov    [byte edi+tfunk_chan.vol_vib_waveform],1
  1310.   ret
  1311. @@trm_square:
  1312.   mov    [byte edi+tfunk_chan.vol_vib_waveform],2
  1313.   ret
  1314. @@trm_sawtooth:
  1315.   mov    [byte edi+tfunk_chan.vol_vib_waveform],3
  1316.   ret
  1317. @@trm_random:
  1318.   mov    [byte edi+tfunk_chan.vol_vib_waveform],4
  1319.   ret
  1320. @@halt_note_sys:
  1321.   mov    [byte edi+tfunk_chan.note_command],0fh
  1322.   ret
  1323. @@halt_vol_sys:
  1324.   mov    [byte edi+tfunk_chan.volume_command],0fh
  1325.   ret
  1326. @@halt_all_sys:
  1327.   mov    [byte edi+tfunk_chan.note_command],0fh
  1328.   mov    [byte edi+tfunk_chan.volume_command],0fh
  1329.   ret
  1330. @@invert_funk:
  1331.   xor    [byte edi+tfunk_chan.funkctrl],1b
  1332.   mov    [byte edi+tfunk_chan.start],0
  1333.   ret
  1334. @@log_porta:
  1335.   mov    [byte edi+tfunk_chan.port_type],0
  1336.   ret
  1337. @@lin_porta:
  1338.   mov    [byte edi+tfunk_chan.port_type],1
  1339.   ret
  1340. endp
  1341.  
  1342. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1343. ; Com O1: volume cut               ;
  1344. ;                                  ;
  1345. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1346. proc com_volume_cut
  1347.   mov    al,[byte edi+tfunk_chan.volume_com_val]
  1348.   and    al,1111b
  1349.   cmp    [byte edi+tfunk_chan.volume_comspd_count],al
  1350.   jae    @@speed_match
  1351.   inc    [byte edi+tfunk_chan.volume_comspd_count]
  1352.   ret
  1353. @@speed_match:
  1354.   mov    [byte edi+tfunk_chan.volume_command],0fh
  1355.   mov    [byte edi+tfunk_chan.volume],0
  1356.   call   vol_to_realvol
  1357.   call   [dword CARD_volume_convert]
  1358.   ret
  1359. endp
  1360.  
  1361. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1362. ; Com O2: real frequency adjust    ;
  1363. ;                                  ;
  1364. ; - this adjustment is independant ;
  1365. ; and is post added                ;
  1366. ; - this is a real frequency       ;
  1367. ; adjustment                       ;
  1368. ;                                  ;
  1369. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1370. proc com_real_freqad
  1371.   mov    al,[byte edi+tfunk_chan.com_val]
  1372.   and    eax,1111b
  1373.   shl    eax,3
  1374.   mov    [dword edi+tfunk_chan.rfreq_adjust],eax
  1375.   ret
  1376. endp
  1377.  
  1378. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1379. ; Com O3: set arpeggio speed       ;
  1380. ;                                  ;
  1381. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1382. proc com_arp_speed_set
  1383.   mov    al,[byte edi+tfunk_chan.com_val]
  1384.   and    al,1111b
  1385.   mov    [byte edi+tfunk_chan.arp_speed],al
  1386.   ret
  1387. endp
  1388.  
  1389. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1390. ; Com O4: fine port_up             ;
  1391. ;                                  ;
  1392. ; com_val :        0000            ;
  1393. ;                 \rate/           ;
  1394. ;                                  ;
  1395. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1396. proc com_fine_port_up
  1397.   cmp    [byte edi+tfunk_chan.port_type],1
  1398.   je     @@line_porta
  1399.   call   com_port_up_log
  1400.   ret
  1401. @@line_porta:
  1402.   call   com_port_up_lin
  1403.   ret
  1404. endp
  1405.  
  1406. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1407. ; Com O5: fine port_dn             ;
  1408. ;                                  ;
  1409. ; com_val :        0000            ;
  1410. ;                 \rate/           ;
  1411. ;                                  ;
  1412. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1413. proc com_fine_port_dn
  1414.   cmp    [byte edi+tfunk_chan.port_type],1
  1415.   je     @@line_porta
  1416.   call   com_port_dn_log
  1417.   ret
  1418. @@line_porta:
  1419.   call   com_port_dn_lin
  1420.   ret
  1421. endp
  1422.  
  1423. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1424. ; Com O6: fine vol sld up          ;
  1425. ;                                  ;
  1426. ; com_val :        0000            ;
  1427. ;                 \rate/           ;
  1428. ;                                  ;
  1429. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1430.  
  1431. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1432. ; Com O7: fine vol sld dn          ;
  1433. ;                                  ;
  1434. ; com_val :        0000            ;
  1435. ;                 \rate/           ;
  1436. ;                                  ;
  1437. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1438.  
  1439. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1440. ; Com O8: volume crest             ;
  1441. ;                                  ;
  1442. ; com_val :        0000            ;
  1443. ;                 \speed/ (prehand);
  1444. ;                                  ;
  1445. ; volume slides up then down,      ;
  1446. ; starting at current frequency    ;
  1447. ;                                  ;
  1448. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1449. proc com_vol_crest
  1450.   mov    bl,[byte edi+tfunk_chan.volume_com_val]
  1451.   and    ebx,1111b
  1452.   mov    dl,[byte ebx+com_volume_inc]
  1453.   cmp    [byte edi+tfunk_chan.volume_beat_count],1
  1454.   je     @@wait_a_bit
  1455.   cmp    [byte edi+tfunk_chan.volume_beat_count],2
  1456.   je     @@slide_down
  1457.   add    [byte edi+tfunk_chan.volume],dl
  1458.   jc     @@second_phase
  1459. @@done:
  1460.   call   vol_to_realvol
  1461.   call   [dword CARD_volume_convert]
  1462.   ret
  1463. @@second_phase:
  1464.   mov    [byte edi+tfunk_chan.volume_comspd_count],0
  1465.   inc    [byte edi+tfunk_chan.volume_beat_count]
  1466.   mov    [byte edi+tfunk_chan.volume],0ffh
  1467.   jmp    @@done
  1468. @@wait_a_bit:
  1469.   inc    bl
  1470.   neg    bl
  1471.   and    bl,1111b
  1472.   cmp    [byte edi+tfunk_chan.volume_comspd_count],bl
  1473.   jae    @@speed_match
  1474.   inc    [byte edi+tfunk_chan.volume_comspd_count]
  1475.   ret
  1476. @@speed_match:
  1477.   mov    [byte edi+tfunk_chan.volume_comspd_count],0
  1478.   inc    [byte edi+tfunk_chan.volume_beat_count]
  1479.   ret
  1480. @@slide_down:
  1481.   shr    dl,2
  1482.   inc    dl
  1483.   mov    al,[byte edi+tfunk_chan.volume_portdest]
  1484.   sub    [byte edi+tfunk_chan.volume],dl
  1485.   jc     @@end
  1486.   cmp    [byte edi+tfunk_chan.volume],al
  1487.   ja     @@done
  1488. @@end:
  1489.   mov    [byte edi+tfunk_chan.volume_command],0fh
  1490.   mov    [byte edi+tfunk_chan.volume],al
  1491.   jmp    @@done
  1492. endp
  1493.  
  1494. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1495. ; Com O9: volume trough            ;
  1496. ;                                  ;
  1497. ; com_val :        0000            ;
  1498. ;                 \speed/ (prehand);
  1499. ;                                  ;
  1500. ; volume slides down then up,      ;
  1501. ; starting at current frequency    ;
  1502. ;                                  ;
  1503. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1504. proc com_vol_trough
  1505.   mov    bl,[byte edi+tfunk_chan.volume_com_val]
  1506.   and    ebx,1111b
  1507.   mov    dl,[byte ebx+com_volume_inc]
  1508.   cmp    [byte edi+tfunk_chan.volume_beat_count],1
  1509.   je     @@wait_a_bit
  1510.   cmp    [byte edi+tfunk_chan.volume_beat_count],2
  1511.   je     @@slide_down
  1512.   shr    dl,2
  1513.   inc    dl
  1514.   sub    [byte edi+tfunk_chan.volume],dl
  1515.   jc     @@second_phase
  1516. @@done:
  1517.   call   vol_to_realvol
  1518.   call   [dword CARD_volume_convert]
  1519.   ret
  1520. @@second_phase:
  1521.   mov    [byte edi+tfunk_chan.volume_comspd_count],0
  1522.   inc    [byte edi+tfunk_chan.volume_beat_count]
  1523.   mov    [byte edi+tfunk_chan.volume],0
  1524.   jmp    @@done
  1525. @@wait_a_bit:
  1526.   inc    bl
  1527.   neg    bl
  1528.   and    bl,1111b
  1529.   cmp    [byte edi+tfunk_chan.volume_comspd_count],bl
  1530.   jae    @@speed_match
  1531.   inc    [byte edi+tfunk_chan.volume_comspd_count]
  1532.   ret
  1533. @@speed_match:
  1534.   mov    [byte edi+tfunk_chan.volume_comspd_count],0
  1535.   inc    [byte edi+tfunk_chan.volume_beat_count]
  1536.   ret
  1537. @@slide_down:
  1538.   mov    al,[byte edi+tfunk_chan.volume_portdest]
  1539.   add    [byte edi+tfunk_chan.volume],dl
  1540.   jc     @@end
  1541.   cmp    [byte edi+tfunk_chan.volume],al
  1542.   jb     @@done
  1543. @@end:
  1544.   mov    [byte edi+tfunk_chan.volume_command],0fh
  1545.   mov    [byte edi+tfunk_chan.volume],al
  1546.   jmp    @@done
  1547. endp
  1548.  
  1549. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1550. ; Com OA: master volume set        ;
  1551. ;                                  ;
  1552. ; master effects all volumes, good ;
  1553. ; for fading songs in and out      ;
  1554. ;                                  ;
  1555. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1556. proc com_master_set
  1557.   mov    al,[byte edi+tfunk_chan.com_val]
  1558.   and    al,1111b
  1559.   mov    [byte funk_info.master_volume],al
  1560.   push   edi
  1561.   lea    edi,[funk_chan1]
  1562.   mov    cl,8
  1563. @@sync_volume:
  1564.   push   ecx
  1565.   call   [dword CARD_volume_convert]
  1566.   add    edi,size tfunk_chan
  1567.   pop    ecx
  1568.   dec    cl
  1569.   jnz    @@sync_volume
  1570.   pop    edi
  1571.   ret
  1572. endp
  1573.  
  1574. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1575. ; Com OB: expand loop              ;
  1576. ;                                  ;
  1577. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1578. proc com_expand_loop
  1579.   mov    al,[byte edi+tfunk_chan.com_val]
  1580.   and    eax,1111b
  1581.   inc    al
  1582.   mov    cl,[byte edi+tfunk_chan.sample_ofs_parm]
  1583.   shl    eax,cl
  1584.   sub    [dword edi+tfunk_chan.start],eax
  1585.   or     [byte edi+tfunk_chan.funkctrl],10000000b
  1586.   ret
  1587. endp
  1588.  
  1589. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1590. ; Com OC: colapse loop             ;
  1591. ;                                  ;
  1592. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1593. proc com_colapse_loop
  1594.   mov    al,[byte edi+tfunk_chan.com_val]
  1595.   and    eax,1111b
  1596.   inc    al
  1597.   mov    cl,[byte edi+tfunk_chan.sample_ofs_parm]
  1598.   shl    eax,cl
  1599.   add    [dword edi+tfunk_chan.start],eax
  1600.   or     [byte edi+tfunk_chan.funkctrl],10000000b
  1601.   ret
  1602. endp
  1603.  
  1604. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1605. ; Com OD: note retrig              ;
  1606. ;                                  ;
  1607. ; com_val : ????   0000            ;
  1608. ;                 \speed/ (prehand);
  1609. ;                                  ;
  1610. ; command only handled on full     ;
  1611. ; or sample only slots             ;
  1612. ;                                  ;
  1613. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1614. proc com_note_retrig
  1615.   mov    al,[byte edi+tfunk_chan.com_val]
  1616.   and    al,00001111b
  1617.   cmp    [byte edi+tfunk_chan.retrig_spd_count],al
  1618.   jae    @@speed_match
  1619.   inc    [byte edi+tfunk_chan.retrig_spd_count]
  1620.   ret
  1621. @@speed_match:
  1622.   mov    [byte edi+tfunk_chan.retrig_spd_count],0
  1623.  
  1624.   mov    al,[byte edi+tfunk_chan.retrig_limit]
  1625.   cmp    [byte edi+tfunk_chan.retrig_count],al
  1626.   jae    @@done
  1627.   inc    [byte edi+tfunk_chan.retrig_count]
  1628.   mov    al,[byte edi+tfunk_chan.sample]
  1629.   call   do_retrig_sample
  1630.   ret
  1631. @@done:
  1632.   mov    [byte edi+tfunk_chan.command],0fh
  1633.   ret
  1634. endp
  1635.  
  1636. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1637. ; Com OE: set channel balance      ;
  1638. ;                                  ;
  1639. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1640. proc com_balance
  1641.   mov    al,[byte edi+tfunk_chan.com_val]
  1642.   shl    al,4
  1643.   mov    [byte edi+tfunk_chan.balance],al
  1644.   ret
  1645. endp
  1646.  
  1647. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1648. ; Com OF: tempo                    ;
  1649. ;                                  ;
  1650. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1651. proc com_tempo
  1652.   mov    al,[byte edi+tfunk_chan.com_val]
  1653.   and    al,1111b
  1654.   mov    [byte funk_info.tempo],al
  1655.   ret
  1656. endp
  1657.  
  1658. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1659. ;                                                                          ;
  1660. ; Command control for null slots only                                      ;
  1661. ;                                                                          ;
  1662. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1663. proc com_null_ctrl
  1664.   mov    eax,[dword edi+tfunk_chan.command]
  1665.   and    eax,1111111100001111b
  1666.   cmp    al,0fh
  1667.   je     @@command_idle
  1668.   or     al,al                                    ; com a
  1669.   je     @@ns_basic
  1670.   cmp    al,01h                                   ; com b
  1671.   je     @@ns_basic
  1672.   cmp    al,02h                                   ; com c
  1673.   je     @@ns_basic
  1674.   cmp    al,03h                                   ; com d
  1675.   je     @@ns_basic
  1676.   cmp    al,04h                                   ; com e
  1677.   je     @@command_e
  1678.   cmp    al,05h                                   ; com f
  1679.   je     @@command_f
  1680.   cmp    al,06h                                   ; com g
  1681.   je     @@vs_basic
  1682.   cmp    al,07h                                   ; com h
  1683.   je     @@vs_basic
  1684.   cmp    al,08h                                   ; com i
  1685.   je     @@vs_basic
  1686.   cmp    al,09h                                   ; com j
  1687.   je     @@command_j
  1688.   cmp    al,0ah                                   ; com k
  1689.   je     @@vs_basic
  1690.   cmp    al,0bh                                   ; com l
  1691.   je     @@command_l
  1692.   cmp    al,0dh                                   ; com n
  1693.   je     @@command_n
  1694.   mov    ebx,eax
  1695.   and    bh,11110000b
  1696.   cmp    ebx,0000eh                               ; com o0
  1697.   je     @@command_o0
  1698.   cmp    ebx,0100eh                               ; com o1
  1699.   je     @@vs_basic
  1700.   cmp    ebx,0200eh                               ; com o2
  1701.   je     @@command_o2
  1702.   cmp    ebx,0300eh                               ; com o3
  1703.   je     @@command_o3
  1704.   cmp    ebx,0400eh                               ; com o4
  1705.   je     @@command_o4
  1706.   cmp    ebx,0500eh                               ; com o5
  1707.   je     @@command_o5
  1708.   cmp    ebx,0600eh                               ; com o6
  1709.   je     @@command_o6
  1710.   cmp    ebx,0700eh                               ; com o7
  1711.   je     @@command_o7
  1712.   cmp    ebx,0800eh                               ; com o8
  1713.   je     @@command_o8o9
  1714.   cmp    ebx,0900eh                               ; com o9
  1715.   je     @@command_o8o9
  1716.   cmp    ebx,0a00eh                               ; com oa
  1717.   je     @@command_oa
  1718.   cmp    ebx,0b00eh                               ; com ob
  1719.   je     @@command_ob
  1720.   cmp    ebx,0c00eh                               ; com oc
  1721.   je     @@command_oc
  1722.   cmp    ebx,0e00eh                               ; com oe
  1723.   je     @@command_oe
  1724.   cmp    ebx,0f00eh                               ; com of
  1725.   je     @@command_of
  1726.   ret
  1727. @@ns_basic:
  1728.   mov    [word edi+tfunk_chan.note_command],ax
  1729.   mov    [byte edi+tfunk_chan.note_comspd_count],0
  1730.   ret
  1731. @@vs_basic:
  1732.   mov    [word edi+tfunk_chan.volume_command],ax
  1733.   mov    [byte edi+tfunk_chan.volume_comspd_count],0
  1734.   ret
  1735. @@command_e:
  1736.   mov    [byte edi+tfunk_chan.note_beat_count],0
  1737.   jmp    @@set_vib_fan
  1738. @@command_f:
  1739.   mov    [byte edi+tfunk_chan.note_beat_count],0fh
  1740. @@set_vib_fan:
  1741.   cmp    [byte edi+tfunk_chan.note_command],03h  ; if vibrato command
  1742.   jne    @@dont_set_vib
  1743.   mov    bl,[byte edi+tfunk_chan.note_com_val]
  1744.   shr    bl,4
  1745.   mov    [byte edi+tfunk_chan.note_beat_count],bl
  1746. @@dont_set_vib:
  1747.   mov    [word edi+tfunk_chan.note_command],ax
  1748.   mov    [byte edi+tfunk_chan.note_comspd_count],0
  1749.   ret
  1750. @@command_j:
  1751.   mov    [word edi+tfunk_chan.volume_command],ax
  1752.   mov    [byte edi+tfunk_chan.volume_comspd_count],0
  1753.   mov    al,[byte edi+tfunk_chan.volume]
  1754.   mov    [byte edi+tfunk_chan.volume_beat_count],al
  1755.   ret
  1756. @@command_l:
  1757.   mov    [word edi+tfunk_chan.note_command],ax
  1758.   mov    [byte edi+tfunk_chan.note_comspd_count],0
  1759.   mov    [byte edi+tfunk_chan.note_beat_count],1
  1760.   ret
  1761. @@command_n:
  1762.   mov    [word edi+tfunk_chan.volume_command],ax
  1763.   call   com_volume
  1764.   ret
  1765. @@command_o0:
  1766.   call   com_misccrtl
  1767.   ret
  1768. @@command_o2:
  1769.   call   com_real_freqad
  1770.   call   [dword CARD_volume_convert]
  1771.   ret
  1772. @@command_o3:
  1773.   call   com_arp_speed_set
  1774.   ret
  1775. @@command_o4:
  1776.   mov    [word edi+tfunk_chan.note_command],ax
  1777.   call   com_fine_port_up
  1778.   ret
  1779. @@command_o5:
  1780.   mov    [word edi+tfunk_chan.note_command],ax
  1781.   call   com_fine_port_dn
  1782.   ret
  1783. @@command_o6:
  1784.   mov    [word edi+tfunk_chan.volume_command],ax
  1785.   call   com_vol_up
  1786.   ret
  1787. @@command_o7:
  1788.   mov    [word edi+tfunk_chan.volume_command],ax
  1789.   call   com_vol_dn
  1790.   ret
  1791. @@command_o8o9:
  1792.   mov    [word edi+tfunk_chan.volume_command],ax
  1793.   mov    [byte edi+tfunk_chan.volume_comspd_count],0
  1794.   mov    [byte edi+tfunk_chan.volume_beat_count],0
  1795.   mov    al,[byte edi+tfunk_chan.volume]
  1796.   mov    [byte edi+tfunk_chan.volume_portdest],al
  1797.   ret
  1798. @@command_oa:
  1799.   call   com_master_set
  1800.   ret
  1801. @@command_ob:
  1802.   call   com_expand_loop
  1803.   ret
  1804. @@command_oc:
  1805.   call   com_colapse_loop
  1806.   ret
  1807. @@command_oe:
  1808.   call   com_balance
  1809.   ret
  1810. @@command_of:
  1811.   call   com_tempo
  1812.   ret
  1813. @@command_idle:
  1814.   ret
  1815. endp
  1816.  
  1817. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1818. ;                                                                          ;
  1819. ; Command control for full slots                                           ;
  1820. ;                                                                          ;
  1821. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1822. proc com_full_ctrl
  1823.   mov    eax,[dword edi+tfunk_chan.command]
  1824.   and    eax,1111111100001111b
  1825.   cmp    al,0fh
  1826.   je     @@command_idle
  1827.   or     al,al                                    ; com a
  1828.   je     @@ns_basic
  1829.   cmp    al,01h                                   ; com b
  1830.   je     @@ns_basic
  1831.   cmp    al,02h                                   ; com c
  1832.   je     @@command_c
  1833.   cmp    al,03h                                   ; com d
  1834.   je     @@ns_basic
  1835.   cmp    al,04h                                   ; com e
  1836.   je     @@command_e
  1837.   cmp    al,05h                                   ; com f
  1838.   je     @@command_f
  1839.   cmp    al,06h                                   ; com g
  1840.   je     @@vs_basic
  1841.   cmp    al,07h                                   ; com h
  1842.   je     @@vs_basic
  1843.   cmp    al,08h                                   ; com i
  1844.   je     @@command_i
  1845.   cmp    al,09h                                   ; com j
  1846.   je     @@command_j
  1847.   cmp    al,0ah                                   ; com k
  1848.   je     @@vs_basic
  1849.   cmp    al,0bh                                   ; com l
  1850.   je     @@command_l
  1851.   cmp    al,0ch                                   ; com m
  1852.   je     @@command_m
  1853.   cmp    al,0dh                                   ; com n
  1854.   je     @@command_n
  1855.   mov    ebx,eax
  1856.   and    bh,11110000b
  1857.   cmp    ebx,0000eh                               ; com o0
  1858.   je     @@command_o0
  1859.   cmp    ebx,0100eh                               ; com o1
  1860.   je     @@vs_basic
  1861.   cmp    ebx,0200eh                               ; com o2
  1862.   je     @@command_o2
  1863.   cmp    ebx,0300eh                               ; com o3
  1864.   je     @@command_o3
  1865.   cmp    ebx,0400eh                               ; com o4
  1866.   je     @@command_o4
  1867.   cmp    ebx,0500eh                               ; com o5
  1868.   je     @@command_o5
  1869.   cmp    ebx,0600eh                               ; com o6
  1870.   je     @@command_o6
  1871.   cmp    ebx,0700eh                               ; com o7
  1872.   je     @@command_o7
  1873.   cmp    ebx,0800eh                               ; com o8
  1874.   je     @@command_o8o9
  1875.   cmp    ebx,0900eh                               ; com o9
  1876.   je     @@command_o8o9
  1877.   cmp    ebx,0a00eh                               ; com oa
  1878.   je     @@command_oa
  1879.   cmp    ebx,0b00eh                               ; com ob
  1880.   je     @@command_ob
  1881.   cmp    ebx,0c00eh                               ; com oc
  1882.   je     @@command_oc
  1883.   cmp    ebx,0d00eh                               ; com od
  1884.   je     @@command_od
  1885.   cmp    ebx,0e00eh                               ; com oe
  1886.   je     @@command_oe
  1887.   cmp    ebx,0f00eh                               ; com of
  1888.   je     @@command_of
  1889.   ret
  1890. @@ns_basic:
  1891.   mov    [word edi+tfunk_chan.note_command],ax
  1892.   mov    [byte edi+tfunk_chan.note_comspd_count],0
  1893.   call   normal_decode_note
  1894.   ret
  1895. @@vs_basic:
  1896.   mov    [word edi+tfunk_chan.volume_command],ax
  1897.   mov    [byte edi+tfunk_chan.volume_comspd_count],0
  1898.   call   normal_decode_volume
  1899.   ret
  1900. @@command_c:
  1901.   mov    [word edi+tfunk_chan.note_command],ax
  1902.   mov    [byte edi+tfunk_chan.note_comspd_count],0
  1903.   call   comc_decode
  1904.   ret
  1905. @@command_e:
  1906.   mov    [byte edi+tfunk_chan.note_beat_count],0
  1907.   jmp    @@set_vib_fan
  1908. @@command_f:
  1909.   mov    [byte edi+tfunk_chan.note_beat_count],0fh
  1910. @@set_vib_fan:
  1911.   cmp    [byte edi+tfunk_chan.note_command],03h  ; if vibrato command
  1912.   jne    @@dont_set_vib
  1913.   mov    bl,[byte edi+tfunk_chan.note_com_val]
  1914.   shr    bl,4
  1915.   mov    [byte edi+tfunk_chan.note_beat_count],bl
  1916. @@dont_set_vib:
  1917.   mov    [word edi+tfunk_chan.note_command],ax
  1918.   mov    [byte edi+tfunk_chan.note_comspd_count],0
  1919.   call   normal_decode_note
  1920.   ret
  1921. @@command_i:
  1922.   mov    [word edi+tfunk_chan.volume_command],ax
  1923.   mov    [byte edi+tfunk_chan.volume_comspd_count],0
  1924.   call   comi_decode
  1925.   ret
  1926. @@command_j:
  1927.   mov    [word edi+tfunk_chan.volume_command],ax
  1928.   mov    [byte edi+tfunk_chan.volume_comspd_count],0
  1929.   call   normal_decode_volume
  1930.   mov    al,[byte edi+tfunk_chan.volume]
  1931.   mov    [byte edi+tfunk_chan.volume_beat_count],al
  1932.   ret
  1933. @@command_l:
  1934.   mov    [word edi+tfunk_chan.note_command],ax
  1935.   mov    [byte edi+tfunk_chan.note_comspd_count],0
  1936.   mov    [byte edi+tfunk_chan.note_beat_count],1
  1937.   call   normal_decode_note
  1938.   ret
  1939. @@command_m:
  1940.   call   normal_decode_system
  1941.   call   com_sample_offset
  1942.   ret
  1943. @@command_n:
  1944.   mov    [word edi+tfunk_chan.volume_command],ax
  1945.   call   normal_decode_volume
  1946.   call   com_volume
  1947.   ret
  1948. @@command_o0:
  1949.   call   normal_decode_system
  1950.   call   com_misccrtl
  1951.   ret
  1952. @@command_o2:
  1953.   call   com_real_freqad
  1954.   call   normal_decode_system
  1955.   ret
  1956. @@command_o3:
  1957.   call   normal_decode_system
  1958.   call   com_arp_speed_set
  1959.   ret
  1960. @@command_o4:
  1961.   mov    [word edi+tfunk_chan.note_command],ax
  1962.   call   normal_decode_note
  1963.   call   com_fine_port_up
  1964.   ret
  1965. @@command_o5:
  1966.   mov    [word edi+tfunk_chan.note_command],ax
  1967.   call   normal_decode_note
  1968.   call   com_fine_port_dn
  1969.   ret
  1970. @@command_o6:
  1971.   mov    [word edi+tfunk_chan.volume_command],ax
  1972.   call   normal_decode_volume
  1973.   call   com_vol_up
  1974.   ret
  1975. @@command_o7:
  1976.   mov    [word edi+tfunk_chan.volume_command],ax
  1977.   call   normal_decode_volume
  1978.   call   com_vol_dn
  1979.   ret
  1980. @@command_o8o9:
  1981.   mov    [word edi+tfunk_chan.volume_command],ax
  1982.   mov    [byte edi+tfunk_chan.volume_comspd_count],0
  1983.   mov    [byte edi+tfunk_chan.volume_beat_count],0
  1984.   call   normal_decode_volume
  1985.   mov    al,[byte edi+tfunk_chan.volume]
  1986.   mov    [byte edi+tfunk_chan.volume_portdest],al
  1987.   ret
  1988. @@command_oa:
  1989.   call   com_master_set
  1990.   call   normal_decode_system
  1991.   ret
  1992. @@command_ob:
  1993.   call   normal_decode_system
  1994.   call   com_expand_loop
  1995.   ret
  1996. @@command_oc:
  1997.   call   normal_decode_system
  1998.   call   com_colapse_loop
  1999.   ret
  2000. @@command_od:
  2001.   mov    [byte edi+tfunk_chan.retrig_count],1
  2002.   mov    [byte edi+tfunk_chan.retrig_spd_count],0
  2003.   call   normal_decode_system
  2004.   ret
  2005. @@command_oe:
  2006.   call   normal_decode_system
  2007.   call   com_balance
  2008.   ret
  2009. @@command_of:
  2010.   call   normal_decode_system
  2011.   call   com_tempo
  2012.   ret
  2013. @@command_idle:
  2014.   call   normal_decode_system
  2015.   ret
  2016. endp
  2017.  
  2018. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2019. ;                                                                          ;
  2020. ; Command control for rapid "on the fly"                                   ;
  2021. ; Rapid commands that have a speed parameter                               ;
  2022. ;                                                                          ;
  2023. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2024. proc com_rapid_ctrl
  2025.   lea    edi,[funk_chan1]
  2026.   mov    cl,8
  2027. @@play_slot:
  2028.   push   ecx
  2029.  
  2030.   call   note_system_rapid_p1
  2031.   call   volume_system_rapid_p1
  2032.  
  2033.   mov    eax,[dword edi+tfunk_chan.note_command]
  2034.   cmp    al,03h                                   ; command d
  2035.   je     @@command_d
  2036.   cmp    al,04h                                   ; command e
  2037.   je     @@command_e
  2038.   cmp    al,05h                                   ; command f
  2039.   je     @@command_f
  2040.   cmp    al,0bh                                   ; command l
  2041.   je     @@command_l
  2042.   jmp    @@do_vol_com
  2043. @@command_d:
  2044.   call   com_vibrato
  2045.   jmp    @@do_vol_com
  2046. @@command_e:
  2047.   call   com_vib_fanin
  2048.   jmp    @@do_vol_com
  2049. @@command_f:
  2050.   call   com_vib_fanout
  2051.   jmp    @@do_vol_com
  2052. @@command_l:
  2053.   call   com_arpeggio
  2054. @@do_vol_com:
  2055.   mov    eax,[dword edi+tfunk_chan.volume_command]
  2056.   cmp    al,09h                                   ; command j
  2057.   je     @@command_j
  2058.   cmp    al,0Ah                                   ; command k
  2059.   je     @@command_k
  2060.   and    eax,1111000000001111b
  2061.   cmp    eax,0100eh                               ; command o1
  2062.   je     @@command_o1
  2063.   cmp    eax,0800eh                               ; command o8
  2064.   je     @@command_o8
  2065.   cmp    eax,0900eh                               ; command o9
  2066.   je     @@command_o9
  2067.   jmp    @@system_final
  2068. @@command_j:
  2069.   call   com_reverb
  2070.   jmp    @@system_final
  2071. @@command_k:
  2072.   call   com_tremola
  2073.   jmp    @@system_final
  2074. @@command_o1:
  2075.   call   com_volume_cut
  2076.   jmp    @@system_final
  2077. @@command_o8:
  2078.   call   com_vol_crest
  2079.   jmp    @@system_final
  2080. @@command_o9:
  2081.   call   com_vol_trough
  2082. @@system_final:
  2083.   mov    eax,[dword edi+tfunk_chan.command]
  2084.   and    eax,1111000000001111b
  2085.   cmp    eax,0d00eh                               ; command od
  2086.   jne    @@end_command
  2087.   call   com_note_retrig
  2088. @@end_command:
  2089.   pop    ecx
  2090.   add    edi,size tfunk_chan
  2091.   dec    cl
  2092.   jnz    @@play_slot
  2093.   ret
  2094. endp
  2095.  
  2096. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2097. ;                                                                          ;
  2098. ; ESI = current pattern                                                    ;
  2099. ;                                                                          ;
  2100. ; format:                                                                  ;
  2101. ;                                                                          ;
  2102. ; 00000000 11111111 22222222                                               ;
  2103. ; \    /\     /\  / \      /                                               ;
  2104. ;  note  sample com  command value                                         ;
  2105. ;                                                                          ;
  2106. ; - if note:  = 3D, then reload sample attrs                               ;
  2107. ;             = 3F, then it's a null slot                                  ;
  2108. ;             = 3E, then sample only slot                                  ;
  2109. ;                                                                          ;
  2110. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2111. proc trekk_slot
  2112.   movzx  eax,[byte funk_info.pattern_ofs]         ;24 * al
  2113.   mov    ebx,eax
  2114.   shl    eax,4
  2115.   shl    ebx,3
  2116.   add    eax,ebx
  2117.   add    esi,eax
  2118.  
  2119.   lea    edi,[funk_chan1]
  2120.   mov    cl,8
  2121. @@play_slot:
  2122.   push   ecx esi
  2123.   mov    ax,[word esi+1]                          ;extract command and value
  2124.   and    al,00001111b
  2125.   mov    [word edi+tfunk_chan.command],ax
  2126.  
  2127.   mov    al,[byte esi]
  2128.   shr    al,2
  2129.   cmp    al,03Fh                                  ;IF FULL SLOT or SAMPLE
  2130.   jne    @@full_cont                              ;ONLY SLOT
  2131.   call   com_null_ctrl
  2132.   jmp    @@next_channel
  2133. @@full_cont:
  2134.   call   com_full_ctrl
  2135. @@next_channel:
  2136.   pop    esi ecx
  2137.   add    edi,size tfunk_chan
  2138.   add    esi,3
  2139.   dec    cl
  2140.   jnz    @@play_slot
  2141.   ret
  2142. endp
  2143.  
  2144. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2145. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2146. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2147. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2148. ;                                                                          ;
  2149. ; The actual tracker thingy :) ....0.02 second tick (or roughly)           ;
  2150. ;                                                                          ;
  2151. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2152. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2153. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2154. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2155. proc funk_tracker
  2156.   cmp    [byte funk_info.trek_status],STOP
  2157.   je     @@dont_play
  2158.   call   com_rapid_ctrl
  2159.   mov    al,[byte funk_info.tempo]
  2160.   cmp    [byte funk_info.tempo_count],al
  2161.   jb     @@tempo_miss
  2162.   mov    [byte funk_info.tempo_count],0
  2163.   xor    ebx,ebx
  2164.   mov    bl,[byte funk_info.sequence_ofs]
  2165.   mov    edi,[funk_hr_ptr]
  2166.   movzx  esi,[byte ebx+edi+tfunk_hr.order_list]
  2167.   mov    eax,esi                                  ; bx * 600h
  2168.   shl    eax,10
  2169.   shl    esi,9
  2170.   add    esi,eax
  2171.   add    esi,edi
  2172.   add    esi,size tfunk_hr
  2173.   call   trekk_slot
  2174.   mov    edi,[funk_hr_ptr]
  2175.   xor    ebx,ebx
  2176.   mov    bl,[byte funk_info.sequence_ofs]
  2177.   movzx  ebx,[byte ebx+edi+tfunk_hr.order_list]
  2178.   mov    al,[byte ebx+edi+tfunk_hr.break_list]
  2179.   cmp    [byte funk_info.pattern_ofs],al          ;if done last pattern then...
  2180.   je     @@change_pattern                         ;jump if no pattern cross
  2181.   inc    [byte funk_info.pattern_ofs]             ;add the trek slot ofs
  2182.   ret
  2183. @@change_pattern:
  2184.   mov    cl,[byte funk_info.no_of_sequences]
  2185.   cmp    [byte funk_info.sequence_ofs],cl
  2186.   jb     @@dont_loop_seq_ofs
  2187.   cmp    [byte edi+tfunk_hr.loop_order],0FFh
  2188.   jne    @@set_loop_rippp
  2189.   mov    [byte funk_info.trek_status],STOP
  2190. @@set_loop_rippp:
  2191.   mov    dl,[byte edi+tfunk_hr.loop_order]
  2192.   dec    dl
  2193.   mov    [byte funk_info.sequence_ofs],dl
  2194. @@dont_loop_seq_ofs:
  2195.   inc    [byte funk_info.sequence_ofs]
  2196.   mov    [byte funk_info.pattern_ofs],0
  2197.   ret
  2198. @@tempo_miss:
  2199.   inc    [byte funk_info.tempo_count]
  2200. @@dont_play:
  2201.   ret
  2202. endp
  2203.  
  2204. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2205. ;                                                                          ;
  2206. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2207. proc stop_all_voices
  2208.   cli
  2209.   lea    edi,[funk_chan1]
  2210.   xor    cl,cl
  2211. @@play_slot:
  2212.   push   ecx
  2213.   mov    [byte edi+tfunk_chan.funkctrl],0
  2214.   mov    [byte edi+tfunk_chan.volume],0
  2215.   mov    [byte edi+tfunk_chan.rvolume],0
  2216.   call   [dword CARD_volume_convert]
  2217.   pop    ecx
  2218.   add    edi,size tfunk_chan
  2219.   inc    cl
  2220.   cmp    cl,8
  2221.   jb     @@play_slot
  2222.   sti
  2223.   ret
  2224. endp
  2225.  
  2226. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2227. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2228. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2229. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2230. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2231. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2232. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2233. ;                                                                          ;
  2234. ; MPU-401 UART Code (Midi keyboard code)                                   ;
  2235. ;                                                                          ;
  2236. ; (NB/ most of the MPU code is from the CT SDK kit V2.0)                   ;
  2237. ;                                                                          ;
  2238. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2239. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2240. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2241. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2242. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2243. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2244. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2245. MPU_addr              dd 330h
  2246.  
  2247. struc tMIDI
  2248.   midi_status         db STOP
  2249.   midi_buffer         db 32 dup(?)  ; 32 byte circulur buffer
  2250.   midi_buffer_head    dd 0
  2251.   midi_buffer_tail    dd 0
  2252.   base                db 0
  2253.   byte1               db 0
  2254.   byte2               db 0
  2255.   byte3               db 0
  2256. ends
  2257. MIDI                  tMIDI <>
  2258.  
  2259. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2260. ;                                                                          ;
  2261. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2262. proc MIDI_queue_in
  2263.   mov    ebx,[MIDI.midi_buffer_head]
  2264.   mov    [byte ebx+MIDI.midi_buffer],al
  2265.   inc    [MIDI.midi_buffer_head]
  2266.   and    [MIDI.midi_buffer_head],31
  2267.   ret
  2268. endp
  2269.  
  2270. proc MIDI_queue_out_pol
  2271. @@wait:
  2272.   mov    ebx,[MIDI.midi_buffer_tail]
  2273.   cmp    ebx,[MIDI.midi_buffer_head]
  2274.   je     @@wait
  2275.   mov    al,[byte ebx+MIDI.midi_buffer]
  2276.   inc    [MIDI.midi_buffer_tail]
  2277.   and    [MIDI.midi_buffer_tail],31
  2278.   ret
  2279. endp
  2280.  
  2281. proc MIDI_queue_out_sig
  2282.   mov    ebx,[MIDI.midi_buffer_tail]
  2283.   cmp    ebx,[MIDI.midi_buffer_head]
  2284.   je     @@ignore
  2285.   mov    al,[byte ebx+MIDI.midi_buffer]
  2286.   inc    [MIDI.midi_buffer_tail]
  2287.   and    [MIDI.midi_buffer_tail],31
  2288.   clc
  2289.   ret
  2290. @@ignore:
  2291.   stc
  2292.   ret
  2293. endp
  2294.  
  2295. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2296. ; ResetMPU401                                                              ;
  2297. ;     Reset MPU-401 (for SB16 only)                                        ;
  2298. ; Entry   :                                                                ;
  2299. ;     none.                                                                ;
  2300. ; Exit    :                                                                ;
  2301. ;     EAX = 0 if successful else 1.                                        ;
  2302. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2303. proc MPU401_Reset
  2304.   cli
  2305.   mov    edx,[MPU_addr]
  2306.   inc    edx
  2307.   xor    ecx,ecx
  2308. @@Busy1:
  2309.   in     al,dx
  2310.   test   al,40h
  2311.   jz     @@ok1
  2312.   dec    cx
  2313.   jnz    @@Busy1
  2314.   jmp    @@fail
  2315. @@ok1:
  2316.   mov    al,0FFh
  2317.   out    dx,al
  2318.   sub    ecx,ecx
  2319. @@Empty1:
  2320.   in     al,dx
  2321.   test   al,80h
  2322.   jnz    @@NesLoop1
  2323.  
  2324.   dec    edx
  2325.   in     al,dx
  2326.   cmp    al,0FEh
  2327.   mov    eax,00h
  2328.   je     @@ResetOK1
  2329.   inc    edx
  2330. @@NesLoop1:
  2331.   dec    cx
  2332.   jnz    @@Empty1
  2333. @@fail:
  2334.   mov    eax,01H
  2335. @@ResetOK1:
  2336.   sti
  2337.   ret
  2338. endp
  2339.  
  2340. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2341. ; EnterUARTModeMPU401                                                      ;
  2342. ;     Set MPU-401 to UART mode.                                            ;
  2343. ; Entry   :                                                                ;
  2344. ;     none.                                                                ;
  2345. ; Exit    :                                                                ;
  2346. ;     EAX = 0 if successful else 1.                                        ;
  2347. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2348. proc MPU401_EUARTM
  2349.   cli
  2350.   mov    edx,[MPU_addr]
  2351.   inc    edx
  2352. @@Busy2:
  2353.   in     al,dx
  2354.   test   al,40h
  2355.   jnz    @@Busy2
  2356.   mov    al,3Fh
  2357.   out    dx,al
  2358.   sub    ecx,ecx
  2359. @@Empty2:
  2360.   in     al,dx
  2361.   test   al,80h
  2362.   jnz    @@NesLoop2
  2363.   dec    edx
  2364.   in     al,dx
  2365.   cmp    al,0FEh
  2366.   je     @@InUartMode2
  2367.   inc    edx
  2368. @@NesLoop2:
  2369.   dec    cx
  2370.   jnz    @@Empty2
  2371.   mov    eax,01h
  2372.   jmp    @@exit
  2373. @@InUartMode2:
  2374.   mov    eax,00h
  2375. @@exit:
  2376.   sti
  2377.   ret
  2378. endp
  2379.  
  2380. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2381. ; WriteMPU401                                                              ;
  2382. ;     Write a byte of MIDI data to MPU-401                                 ;
  2383. ; Entry :                                                                  ;
  2384. ;     al      = output data.                                               ;
  2385. ; Exit :                                                                   ;
  2386. ;     none.                                                                ;
  2387. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2388. proc MPU401_Write
  2389.   cli
  2390.   push   edx
  2391.   mov    edx,[MPU_addr]
  2392.   inc    edx
  2393.   push   eax
  2394. @@Busy3:
  2395.   in     al,dx
  2396.   test   al,40h
  2397.   jnz    @@Busy3
  2398.   dec    edx
  2399.   pop    eax
  2400.   out    dx,al
  2401.   pop    edx
  2402.   sti
  2403.   ret
  2404. endp
  2405.  
  2406. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2407. ; ReadMPU401                                                               ;
  2408. ;     Read a byte of MIDI data from MPU-401                                ;
  2409. ; Entry :                                                                  ;
  2410. ;     none.                                                                ;
  2411. ; Exit :                                                                   ;
  2412. ;     al      = input data.                                                ;
  2413. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2414. proc MPU401_Read
  2415.   cli
  2416.   push   edx
  2417.   mov    edx,[MPU_addr]
  2418.   inc    edx
  2419. @@Busy4:
  2420.   in     al,dx
  2421.   test   al,80H
  2422.   jnz    @@Busy4
  2423.   dec    edx
  2424.   in     al,dx
  2425.   pop    edx
  2426.   sti
  2427.   ret
  2428. endp
  2429.  
  2430. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2431. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2432. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2433. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2434. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2435. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2436. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2437. ;                                                                          ;
  2438. ; DMA routines (From DOS32)                                                ;
  2439. ; INPUT:        AL    Mode Register  ( bits 0..1 ignored )                 ;
  2440. ;               AH    channel    0..7                                      ;
  2441. ;               EBX   Physical Base Address                                ;
  2442. ;               ECX   Bytes to transfer                                    ;
  2443. ;                                                                          ;
  2444. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2445. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2446. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2447. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2448. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2449. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2450. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2451. proc DMA_Setup
  2452.   xor     edx,edx
  2453.   and     ah,7
  2454.   mov     [@@DMA_channel],ah
  2455.   and     al,NOT 3
  2456.   mov     [@@mode],al
  2457.   movzx   edi,[byte @@DMA_channel]
  2458.   mov     eax,edi
  2459.   shr     edi,2
  2460.   and     al,0011b
  2461.   or      al,0100b
  2462.   mov     dl,[edi+@@DMA_SNGL]
  2463.   out     dx,al
  2464.   call    @@pause
  2465.   and     al,03h
  2466.   or      al,[@@Mode]
  2467.   mov     dl,[edi+@@DMA_MODE]
  2468.   out     dx,al
  2469.   call    @@pause
  2470.   mov     dl,[edi+@@DMA_CLRFF]
  2471.   out     dx,al
  2472.   call    @@pause
  2473.   movzx   edi,[@@DMA_channel]
  2474.   mov     eax,ecx
  2475.   mov     ecx,edi
  2476.   shr     ecx,2
  2477.   shr     eax,cl
  2478.   mov     dl,[edi+@@DMA_CNT]
  2479.   out     dx,al
  2480.   call    @@pause
  2481.   shr     eax,8
  2482.   out     dx,al
  2483.   call    @@pause
  2484.   shr     ebx,cl
  2485.   mov     al,BL
  2486.   mov     dl,[edi+@@DMA_ADDR]
  2487.   out     dx,al
  2488.   call    @@pause
  2489.   mov     al,BH
  2490.   out     dx,al
  2491.   call    @@pause
  2492.   shr     ebx,15
  2493.   xor     cl,1
  2494.   shr     ebx,cl
  2495.   mov     al,BL
  2496.   mov     dl,[edi+@@DMA_PAGE]
  2497.   out     dx,al
  2498.   call    @@pause
  2499.   mov     eax,edi
  2500.   shr     edi,2
  2501.   and     al,03h
  2502.   mov     dl,[edi+@@DMA_SNGL]
  2503.   out     dx,al
  2504.   call    @@pause
  2505.   ret
  2506. @@Mode                db  ?
  2507. @@DMA_Channel         db  ?
  2508. @@DMA_STAT            db 008h,0D0h
  2509. @@DMA_CMD             db 008h,0D0h
  2510. @@DMA_REQ             db 009h,0D2h
  2511. @@DMA_SNGL            db 00Ah,0D4h
  2512. @@DMA_MODE            db 00Bh,0D6h
  2513. @@DMA_CLRFF           db 00Ch,0D8h
  2514. @@DMA_MCLR            db 00Dh,0DAh
  2515. @@DMA_CLRM            db 00Eh,0DCh
  2516. @@DMA_WRTALL          db 00Fh,0DEh
  2517. @@DMA_PAGE            db 087h,083h,081h,082h,08Fh,08Bh,089h,08Ah
  2518. @@DMA_ADDR            db 000h,002h,004h,006h,0C0h,0C4h,0C8h,0CCh
  2519. @@DMA_CNT             db 001h,003h,005h,007h,0C2h,0C6h,0CAh,0CEh
  2520. proc @@pause
  2521.   jmp    @@j
  2522. @@j:
  2523.   ret
  2524. endp
  2525. endp
  2526.  
  2527. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2528. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2529. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2530. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2531. ;                                                                          ;
  2532. ; DAC INDEPENDANT CODE                                                     ;
  2533. ;                                                                          ;
  2534. ; These routines are general DAC routines used by all DAC soundcards.      ;
  2535. ;                                                                          ;
  2536. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2537. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2538. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2539. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2540. DAC_old_irq_ofs       dd 0
  2541. DAC_old_irq_sel       dw 0
  2542. DAC_mix_buffer_size   dd ?
  2543. DAC_sampling_rate     dd ?
  2544. DMA_length            dd 4000h
  2545.  
  2546. DAC_mb_offs           = 0
  2547. DAC_mb_right_offs     = 1000h
  2548. DAC_mb2_offs          = 2000h
  2549. DAC_mix_buffer        dd DAC_mb_offs
  2550. DAC_mix_buffer_right  dd DAC_mb_right_offs
  2551. DAC_mix_buffer2       dd DAC_mb2_offs
  2552. DAC_PHYSICAL_PAGE     dd DAC_mb2_offs
  2553. DAC_shift_value       db 0
  2554. DAC_double_buf1       dd 0
  2555. DAC_double_buf2       dd 0
  2556.  
  2557. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2558. ;                                                                          ;
  2559. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2560. proc DACi_freq_convert
  2561.   mov    eax,[dword edi+tfunk_chan.rfreq]
  2562.   mov    edx,eax
  2563.   shl    eax,16
  2564.   shr    edx,16
  2565.   div    [dword DAC_sampling_rate]
  2566.   mov    [dword edi+tfunk_chan.CARD_freq],eax
  2567.   ret
  2568. endp
  2569.  
  2570. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2571. ;                                                                          ;
  2572. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2573. proc DACi_volume_convert
  2574.   xor    eax,eax
  2575.   cmp    [byte edi+tfunk_chan.channel_kill],STOP
  2576.   je     @@transt
  2577.   mov    al,[byte funk_info.master_volume]
  2578.   cmp    al,0
  2579.   je     @@transt
  2580.   xor    ecx,ecx
  2581.   mov    cl,[byte edi+tfunk_chan.rvolume]
  2582.   inc    al
  2583.   mul    ecx
  2584.   mov    cl,[byte DAC_shift_value]
  2585.   shr    eax,cl
  2586. @@transt:
  2587.   mov    [byte edi+tfunk_chan.CARD_volume],al
  2588.   ret
  2589. endp
  2590.  
  2591. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2592. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2593. ;                                                                          ;
  2594. ; unit channel DAC buffer Mixer                                            ;
  2595. ;                                                                          ;
  2596. ; ebx = channel ptr, edi = buffer                                          ;
  2597. ;                                                                          ;
  2598. ; 00                                                                       ;
  2599. ; ||_____ 1=loop sample                                                    ;
  2600. ; |                                                                        ;
  2601. ; |______ DAC sample play                                                  ;
  2602. ;                                                                          ;
  2603. ; =====================================================================    ;
  2604. ;                                                                          ;
  2605. ; This is the heart of DAC mixxing. Here we actually mix a given channel   ;
  2606. ; to the mixing buffer. This code does frequency transformations and volume;
  2607. ; manipulation (it's what the DSP cards do interally). If a Card does this ;
  2608. ; in hardware, then it is refered to as a "DSP" card rather than a "DAC"   ;
  2609. ; card. An example of a "DSP" card is the Gravis Ultrasound card.          ;
  2610. ;                                                                          ;
  2611. ; The frequency transformer belongs to Tom Verbeure...thanks tom!          ;
  2612. ;                                                                          ;
  2613. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2614. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2615. proc DAC_channel_mixxer
  2616.   mov    ch,[byte ebx+tfunk_chan.funkctrl]
  2617.   mov    cl,[byte ebx+tfunk_chan.CARD_volume]
  2618.   mov    edx,[dword ebx+tfunk_chan.CARD_freq]
  2619.   mov    ebp,edx
  2620.   shl    edx,16
  2621.   shr    ebp,16
  2622.   mov    esi,[dword ebx+tfunk_chan.CARD_sample_ptr]
  2623.   mov    eax,[dword DAC_mix_buffer_size]
  2624. @@mix_loop:
  2625.   push   eax
  2626.   test   ch,10b
  2627.   jnz    @@run_sample
  2628.   xor    al,al
  2629.   jmp    @@trans_sample
  2630. @@run_sample:
  2631.   mov    al,[byte esi]
  2632. @@trans_sample:
  2633.   imul   cl
  2634.   add    [word edi],ax
  2635.   add    edi,2
  2636.   add    [dword ebx+tfunk_chan.CARD_freq_attract],edx
  2637.   adc    esi,ebp
  2638.   cmp    esi,[dword ebx+tfunk_chan.length]
  2639.   jb     @@comp_end
  2640.   test   ch,01b
  2641.   jnz    @@loop_back
  2642.   and    ch,01b
  2643.   jmp    @@comp_end
  2644. @@loop_back:
  2645.   mov    esi,[dword ebx+tfunk_chan.start]
  2646. @@comp_end:
  2647.   pop    eax
  2648.   dec    eax
  2649.   jnz    @@mix_loop
  2650.   mov    [byte ebx+tfunk_chan.funkctrl],ch
  2651.   mov    [dword ebx+tfunk_chan.CARD_sample_ptr],esi
  2652.   ret
  2653. endp
  2654.  
  2655. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2656. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2657. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2658. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2659. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2660. ;                                                                          ;
  2661. ; SB DEPENDANT CODE                                                        ;
  2662. ;                                                                          ;
  2663. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2664. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2665. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2666. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2667. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2668. SB_INTR_8BITDMA        = 1
  2669. SB_INTR_16BITDMA       = 2
  2670. SB_INTR_MPU401         = 4
  2671.  
  2672. SB_BASE                dd ?
  2673. SB_MIXER               dd ?
  2674. SB_RESET               dd ?
  2675. SB_READ_DATA           dd ?
  2676. SB_WRITE_DATA          dd ?
  2677. SB_DATA_AVAIL          dd ?
  2678. SB_DATA_AVAIL16        dd ?
  2679.  
  2680. SB_trig                dd ?
  2681.  
  2682. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2683. ;                                                                          ;
  2684. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2685. proc SB_detect_port
  2686.   mov    eax,[dword init_settings.PORT_no]
  2687.   mov    [dword SB_BASE],0
  2688.   mov    [dword SB_MIXER],4h
  2689.   mov    [dword SB_RESET],6h
  2690.   mov    [dword SB_READ_DATA],0ah
  2691.   mov    [dword SB_WRITE_DATA],0ch
  2692.   mov    [dword SB_DATA_AVAIL],0eh
  2693.   mov    [dword SB_DATA_AVAIL16],0fh
  2694.   add    [dword SB_BASE],eax
  2695.   add    [dword SB_MIXER],eax
  2696.   add    [dword SB_RESET],eax
  2697.   add    [dword SB_READ_DATA],eax
  2698.   add    [dword SB_WRITE_DATA],eax
  2699.   add    [dword SB_DATA_AVAIL],eax
  2700.   add    [dword SB_DATA_AVAIL16],eax
  2701.   lea    eax,[DACi_freq_convert]
  2702.   mov    [dword CARD_freq_convert],eax
  2703.   lea    eax,[DACi_volume_convert]
  2704.   mov    [dword CARD_volume_convert],eax
  2705.   mov    al,1
  2706.   mov    edx,[dword SB_RESET]
  2707.   out    dx,al
  2708.   in     al,dx
  2709.   in     al,dx
  2710.   in     al,dx
  2711.   in     al,dx
  2712.   xor    al,al
  2713.   mov    edx,[dword SB_RESET]
  2714.   out    dx,al
  2715.   mov    cl,64h
  2716. @@DataWait:
  2717.   mov    edx,[dword SB_DATA_AVAIL]
  2718.   in     al,dx
  2719.   test   al,80h
  2720.   jnz    @@YesData
  2721.   dec    cl
  2722.   jnz    @@DataWait
  2723.   jmp    @@exit
  2724. @@YesData:
  2725.   mov    edx,[dword SB_READ_DATA]
  2726.   in     al,dx
  2727.   cmp    al,0AAh
  2728.   je     @@YepSB
  2729.   dec    cl
  2730.   jnz    @@DataWait
  2731.   jmp    @@exit
  2732. @@YepSB:
  2733.   clc
  2734.   ret
  2735. @@exit:
  2736.   stc
  2737.   ret
  2738. endp
  2739.  
  2740. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2741. ;                                                                          ;
  2742. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2743. proc SB_write_dac
  2744.   push   eax
  2745.   mov    edx,[dword SB_WRITE_DATA]
  2746. @@Wait_Ready:
  2747.   in     al,dx
  2748.   and    al,80h
  2749.   jnz    @@Wait_Ready
  2750.   pop    eax
  2751.   out    dx,al
  2752.   ret
  2753. endp
  2754.  
  2755. proc SB_read_dac
  2756.   mov    edx,[dword SB_DATA_AVAIL]
  2757. @@Wait_Ready:
  2758.   in     al,dx
  2759.   or     al,al
  2760.   jns    @@Wait_Ready
  2761.   sub    edx,4
  2762.   in     al,dx
  2763.   ret
  2764. endp
  2765.  
  2766. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2767. ;  al = addr  ah = data      SBPRO mixxer                                  ;
  2768. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2769. proc SB_write_mixer
  2770.   mov    edx,[dword SB_MIXER]
  2771.   push   edx
  2772.   out    dx,al
  2773.   pop    edx
  2774.   inc    edx
  2775.   mov    al,ah
  2776.   out    dx,al
  2777.   ret
  2778. endp
  2779.  
  2780. proc SB_read_mixer
  2781.   mov    edx,[dword SB_MIXER]
  2782.   push   edx
  2783.   out    dx,al
  2784.   pop    edx
  2785.   inc    edx
  2786.   in     al,dx
  2787.   ret
  2788. endp
  2789.  
  2790. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2791. ;                                                                          ;
  2792. ; DMA trigs                                                                ;
  2793. ;                                                                          ;
  2794. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2795. proc SB_trig_compatable
  2796.   mov    al,14h                                        ;DMA_8_BIT_DAC
  2797.   call   SB_write_dac
  2798.   mov    eax,[dword DMA_length]
  2799.   dec    eax
  2800.   call   SB_write_dac
  2801.   mov    al,ah
  2802.   call   SB_write_dac
  2803.   ret
  2804. endp
  2805.  
  2806. proc SB_trig_advanced
  2807.   mov    al,91h
  2808.   call   SB_write_dac
  2809.   ret
  2810. endp
  2811.  
  2812. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2813. ;                                                                          ;
  2814. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2815. proc SB_virtualmixxer
  2816.   cld
  2817.   push   ds es
  2818.   pushad
  2819.   mov    ax,DGROUP
  2820.   mov    ds,ax
  2821.   mov    es,ax
  2822.   mov    edx,[dword SB_DATA_AVAIL]
  2823.   in     al,dx
  2824.   call   [dword SB_trig]
  2825.   mov    esi,[dword DAC_mix_buffer]
  2826.   mov    edi,[dword DAC_mix_buffer2]
  2827.   add    edi,[DAC_double_buf1]
  2828.   mov    eax,[DAC_double_buf1]
  2829.   xchg   eax,[DAC_double_buf2]
  2830.   mov    [DAC_double_buf1],eax
  2831.   mov    ecx,[dword DAC_mix_buffer_size]
  2832.   shr    ecx,1
  2833. @@trans8:
  2834.   mov    eax,[esi]
  2835.   mov    al,ah
  2836.   mov    [edi],al
  2837.   mov    eax,[esi+2]
  2838.   mov    al,ah
  2839.   mov    [edi+1],al
  2840.   add    esi,4
  2841.   add    edi,2
  2842.   dec    ecx
  2843.   jnz    @@trans8
  2844.   call   funk_tracker
  2845.   mov    ecx,[dword DAC_mix_buffer_size]
  2846.   shr    ecx,1
  2847.   mov    edi,[dword DAC_mix_buffer]
  2848.   mov    eax,80008000h
  2849.   rep    stosd
  2850.   lea    ebx,[funk_chan1]
  2851.   mov    edi,[dword DAC_mix_buffer]
  2852.   call   DAC_channel_mixxer
  2853.   lea    ebx,[funk_chan2]
  2854.   mov    edi,[dword DAC_mix_buffer]
  2855.   call   DAC_channel_mixxer
  2856.   lea    ebx,[funk_chan3]
  2857.   mov    edi,[dword DAC_mix_buffer]
  2858.   call   DAC_channel_mixxer
  2859.   lea    ebx,[funk_chan4]
  2860.   mov    edi,[dword DAC_mix_buffer]
  2861.   call   DAC_channel_mixxer
  2862.   lea    ebx,[funk_chan5]
  2863.   mov    edi,[dword DAC_mix_buffer]
  2864.   call   DAC_channel_mixxer
  2865.   lea    ebx,[funk_chan6]
  2866.   mov    edi,[dword DAC_mix_buffer]
  2867.   call   DAC_channel_mixxer
  2868.   lea    ebx,[funk_chan7]
  2869.   mov    edi,[dword DAC_mix_buffer]
  2870.   call   DAC_channel_mixxer
  2871.   lea    ebx,[funk_chan8]
  2872.   mov    edi,[dword DAC_mix_buffer]
  2873.   call   DAC_channel_mixxer
  2874.   mov    al,20h
  2875.   out    20h,al
  2876.   popad
  2877.   pop    es ds
  2878.   iretd
  2879. endp
  2880.  
  2881. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2882. ;                                                                          ;
  2883. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2884. proc SBPRO_virtualmixxer
  2885.   cld
  2886.   push   ds es
  2887.   pushad
  2888.   mov    ax,DGROUP
  2889.   mov    ds,ax
  2890.   mov    es,ax
  2891.   mov    edx,[dword SB_DATA_AVAIL]
  2892.   in     al,dx
  2893.   call   [dword SB_trig]
  2894.   mov    esi,[dword DAC_mix_buffer]
  2895.   mov    edi,[dword DAC_mix_buffer2]
  2896.   add    edi,[DAC_double_buf1]
  2897.   mov    eax,[DAC_double_buf1]
  2898.   xchg   eax,[DAC_double_buf2]
  2899.   mov    [DAC_double_buf1],eax
  2900.   mov    ecx,[dword DAC_mix_buffer_size]
  2901.   shr    ecx,1
  2902. @@trans8:
  2903.   mov    eax,[esi+DAC_mb_right_offs]
  2904.   mov    al,ah
  2905.   mov    ah,[byte esi+1+DAC_mb_offs]
  2906.   mov    [edi],ax
  2907.   mov    eax,[esi+2+DAC_mb_right_offs]
  2908.   mov    al,ah
  2909.   mov    ah,[byte esi+3+DAC_mb_offs]
  2910.   mov    [edi+2],ax
  2911.   add    esi,4
  2912.   add    edi,4
  2913.   dec    ecx
  2914.   jnz    @@trans8
  2915.   call   funk_tracker
  2916.   mov    ecx,[dword DAC_mix_buffer_size]
  2917.   shr    ecx,1
  2918.   mov    edi,[dword DAC_mix_buffer]
  2919.   mov    eax,80008000h
  2920.   rep    stosd
  2921.   mov    ecx,[dword DAC_mix_buffer_size]
  2922.   shr    ecx,1
  2923.   mov    edi,[dword DAC_mix_buffer_right]
  2924.   rep    stosd
  2925.   lea    ebx,[funk_chan1]
  2926.   mov    edi,[dword DAC_mix_buffer]
  2927.   call   DAC_channel_mixxer
  2928.   lea    ebx,[funk_chan2]
  2929.   mov    edi,[dword DAC_mix_buffer_right]
  2930.   call   DAC_channel_mixxer
  2931.   lea    ebx,[funk_chan3]
  2932.   mov    edi,[dword DAC_mix_buffer]
  2933.   call   DAC_channel_mixxer
  2934.   lea    ebx,[funk_chan4]
  2935.   mov    edi,[dword DAC_mix_buffer_right]
  2936.   call   DAC_channel_mixxer
  2937.   lea    ebx,[funk_chan5]
  2938.   mov    edi,[dword DAC_mix_buffer]
  2939.   call   DAC_channel_mixxer
  2940.   lea    ebx,[funk_chan6]
  2941.   mov    edi,[dword DAC_mix_buffer_right]
  2942.   call   DAC_channel_mixxer
  2943.   lea    ebx,[funk_chan7]
  2944.   mov    edi,[dword DAC_mix_buffer]
  2945.   call   DAC_channel_mixxer
  2946.   lea    ebx,[funk_chan8]
  2947.   mov    edi,[dword DAC_mix_buffer_right]
  2948.   call   DAC_channel_mixxer
  2949.   mov    al,20h
  2950.   out    20h,al
  2951.   popad
  2952.   pop    es ds
  2953.   iretd
  2954. endp
  2955.  
  2956. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2957. ;                                                                          ;
  2958. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2959. proc SB16_virtualmixxer
  2960.   cld
  2961.   push   ds es
  2962.   pushad
  2963.   mov    ax,DGROUP
  2964.   mov    ds,ax
  2965.   mov    es,ax
  2966. @@Poll:
  2967.   mov    edx,[SB_MIXER]
  2968.   mov    al,82h
  2969.   out    dx,al
  2970.   inc    edx
  2971.   in     al,dx
  2972.   test   al,02h
  2973.   jnz    @@SB16_DSP_ISA
  2974.   test   al,04h
  2975.   jnz    @@MPU_401_ISA
  2976.   jmp    @@chainpreviousISR
  2977. @@SB16_DSP_ISA:
  2978.   mov    edx,[dword SB_DATA_AVAIL16]
  2979.   in     al,dx
  2980.   mov    esi,[dword DAC_mix_buffer]
  2981.   mov    edx,[dword DAC_mix_buffer_right]
  2982.   mov    edi,[dword DAC_mix_buffer2]
  2983.   add    edi,[DAC_double_buf1]
  2984.   mov    eax,[DAC_double_buf1]
  2985.   xchg   eax,[DAC_double_buf2]
  2986.   mov    [DAC_double_buf1],eax
  2987.   mov    ecx,[dword DAC_mix_buffer_size]
  2988.   xor    ebx,ebx
  2989. @@trans16:
  2990.   mov    eax,[edx+ebx]
  2991.   shl    eax,16
  2992.   mov    ax,[word esi+ebx]
  2993.   mov    [edi+ebx*2],eax
  2994.   add    ebx,2
  2995.   dec    ecx
  2996.   jnz    @@trans16
  2997.   call   funk_tracker
  2998.   mov    ecx,[dword DAC_mix_buffer_size]
  2999.   shr    ecx,1
  3000.   mov    edi,[dword DAC_mix_buffer]
  3001.   xor    eax,eax
  3002.   rep    stosd
  3003.   mov    ecx,[dword DAC_mix_buffer_size]
  3004.   shr    ecx,1
  3005.   mov    edi,[dword DAC_mix_buffer_right]
  3006.   rep    stosd
  3007.   lea    ebx,[funk_chan1]
  3008.   mov    edi,[dword DAC_mix_buffer]
  3009.   call   DAC_channel_mixxer
  3010.   lea    ebx,[funk_chan2]
  3011.   mov    edi,[dword DAC_mix_buffer_right]
  3012.   call   DAC_channel_mixxer
  3013.   lea    ebx,[funk_chan3]
  3014.   mov    edi,[dword DAC_mix_buffer]
  3015.   call   DAC_channel_mixxer
  3016.   lea    ebx,[funk_chan4]
  3017.   mov    edi,[dword DAC_mix_buffer_right]
  3018.   call   DAC_channel_mixxer
  3019.   lea    ebx,[funk_chan5]
  3020.   mov    edi,[dword DAC_mix_buffer]
  3021.   call   DAC_channel_mixxer
  3022.   lea    ebx,[funk_chan6]
  3023.   mov    edi,[dword DAC_mix_buffer_right]
  3024.   call   DAC_channel_mixxer
  3025.   lea    ebx,[funk_chan7]
  3026.   mov    edi,[dword DAC_mix_buffer]
  3027.   call   DAC_channel_mixxer
  3028.   lea    ebx,[funk_chan8]
  3029.   mov    edi,[dword DAC_mix_buffer_right]
  3030.   call   DAC_channel_mixxer
  3031.   jmp    @@Poll
  3032. @@MPU_401_ISA:
  3033.   call   MPU401_Read
  3034.   call   MIDI_queue_in
  3035.   jmp    @@Poll
  3036. @@chainpreviousISR:
  3037. @@ExitISR:
  3038.   mov    al,20h
  3039.   out    20h,al
  3040.   popad
  3041.   pop    es ds
  3042.   iretd
  3043. endp
  3044.  
  3045. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3046. ;                                                                          ;
  3047. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3048.  
  3049. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3050. ;                                          ;
  3051. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3052. label SB_sample_settings tDAC_ssetings
  3053.   tDAC_ssetings <11025,00222,222,11200>
  3054.   tDAC_ssetings <16538,00332,332,16538>
  3055.   tDAC_ssetings <22050,00442,442,22050>
  3056.   tDAC_ssetings <33075,00662,662,33075>
  3057.   tDAC_ssetings <44100,00882,882,44100>
  3058.  
  3059. proc SB_init_compatable
  3060.   mov    eax,offset SB_trig_compatable
  3061.   mov    [SB_trig],eax
  3062.  
  3063.   movzx  eax,[byte init_settings.DAC_Samplerate]
  3064.   mov    ecx,size tDAC_ssetings
  3065.   mul    ecx
  3066.  
  3067.   mov    [byte DAC_shift_value],7
  3068.   mov    ebx,[dword eax+SB_sample_settings.DAC_sr]
  3069.   mov    [dword DAC_sampling_rate],ebx
  3070.   mov    ebx,[dword eax+SB_sample_settings.DAC_mix_buffer_size]
  3071.   mov    [dword DAC_mix_buffer_size],ebx
  3072.   mov    ebx,[dword eax+SB_sample_settings.DMA_length]
  3073.   mov    [dword DMA_length],ebx
  3074.   mov    eax,[dword eax+SB_sample_settings.DMA_real_sr]
  3075.   push   eax
  3076.   mov    bl,[byte init_settings.IRQ_no]
  3077.   lea    edx,[SB_virtualmixxer]
  3078.   mov    cx,cs
  3079.   call   setirqvector
  3080.   xor    edx,edx                                       ;set sampling rate
  3081.   mov    eax,1000000
  3082.   pop    ecx
  3083.   div    ecx
  3084.   neg    al
  3085.   push   eax
  3086.   mov  al,40h                          ;TIME_CONSTANT
  3087.   call SB_write_dac
  3088.   pop  eax
  3089.   call SB_write_dac
  3090.   mov  al,0D1h                        ;SPEAKER_ON
  3091.   call SB_write_dac
  3092.   cli
  3093.   in     al,21h
  3094.   mov    bl,1
  3095.   mov    cl,[byte init_settings.IRQ_no]
  3096.   shl    bl,cl
  3097.   not    bl
  3098.   and    al,bl
  3099.   out    21h,al
  3100.   mov    al,01011000b                                  ;DMA remote-init
  3101.   mov    ah,[byte init_settings.DMA_no]
  3102.   mov    ebx,[dword DAC_PHYSICAL_PAGE]
  3103.   mov    ecx,[dword DMA_length]
  3104.   dec    ecx
  3105.   call   DMA_setup
  3106.   call   SB_trig_compatable
  3107.   sti
  3108.   ret
  3109. endp
  3110.  
  3111. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3112. ;                                          ;
  3113. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3114.  
  3115. label SBPRO_sample_settings tDAC_ssetings       ; NB/ SBPRO can't do more than 22050
  3116.   tDAC_ssetings <11025,00222,0444,23000>
  3117.   tDAC_ssetings <16538,00332,0664,35000>
  3118.   tDAC_ssetings <22050,00442,0884,88200>
  3119.   tDAC_ssetings <22050,00442,0884,88200>
  3120.   tDAC_ssetings <22050,00442,0884,88200>
  3121.  
  3122. proc sb_init_advanced
  3123.   mov    eax,offset SB_trig_advanced
  3124.   mov    [SB_trig],eax
  3125.  
  3126.   movzx  eax,[byte init_settings.DAC_Samplerate]
  3127.   mov    ecx,size tDAC_ssetings
  3128.   mul    ecx
  3129.   cmp    [byte init_settings.card_type],SBPRO_CARD
  3130.   je     @@set_for_SBPRO
  3131.   mov    [byte DAC_shift_value],7
  3132.   mov    ebx,[dword eax+SB_sample_settings.DAC_sr]
  3133.   mov    [dword DAC_sampling_rate],ebx
  3134.   mov    ebx,[dword eax+SB_sample_settings.DAC_mix_buffer_size]
  3135.   mov    [dword DAC_mix_buffer_size],ebx
  3136.   mov    [DAC_double_buf2],ebx
  3137.   mov    ebx,[dword eax+SB_sample_settings.DMA_length]
  3138.   mov    [dword DMA_length],ebx
  3139.   mov    eax,[dword eax+SB_sample_settings.DMA_real_sr]
  3140.   push   eax
  3141.   mov    bl,[byte init_settings.IRQ_no]
  3142.   lea    edx,[SB_virtualmixxer]
  3143.   mov    cx,cs
  3144.   call   setirqvector
  3145.   xor    edx,edx                                       ;set sampling rate
  3146.   mov    eax,256000000
  3147.   pop    ecx
  3148.   div    ecx
  3149.   mov    ebx,0ffffh
  3150.   sub    ebx,eax
  3151.   shr    ebx,8
  3152.   push   ebx
  3153.   jmp    @@done_set
  3154. @@set_for_SBPRO:
  3155.   push   eax
  3156.   mov    [byte DAC_shift_value],6
  3157. ;-SETUP_PRO MIXXER SETTINGS---------
  3158.   mov    eax,00000h                                    ;reset mixxer first
  3159.   call   SB_write_mixer
  3160.   mov    eax,0020eh
  3161.   call   SB_write_mixer
  3162.   mov    eax,0ff22h                                    ;set Master volume
  3163.   call   SB_write_mixer
  3164.   mov    eax,0ff04h                                    ;set DSP volume
  3165.   call   SB_write_mixer
  3166. ;-SETUP_PRO MIXXER SETTINGS---------
  3167.   pop    eax
  3168.   mov    ebx,[dword eax+SBPRO_sample_settings.DAC_sr]
  3169.   mov    [dword DAC_sampling_rate],ebx
  3170.   mov    ebx,[dword eax+SBPRO_sample_settings.DAC_mix_buffer_size]
  3171.   mov    [dword DAC_mix_buffer_size],ebx
  3172.   lea    ebx,[ebx*2]
  3173.   mov    [DAC_double_buf2],ebx
  3174.   mov    ebx,[dword eax+SBPRO_sample_settings.DMA_length]
  3175.   mov    [dword DMA_length],ebx
  3176.   mov    eax,[dword eax+SBPRO_sample_settings.DMA_real_sr]
  3177.   push   eax
  3178.   mov    bl,[byte init_settings.IRQ_no]
  3179.   lea    edx,[SBPRO_virtualmixxer]
  3180.   mov    cx,cs
  3181.   call   setirqvector
  3182.   xor    edx,edx                                       ;set sampling rate
  3183.   mov    eax,256000000
  3184.   pop    ecx
  3185.   div    ecx
  3186.   mov    ebx,0ffffh
  3187.   sub    ebx,eax
  3188.   shr    ebx,8
  3189.   push   ebx
  3190. @@done_set:
  3191.   mov    al,40h                                        ;TIME_CONSTANT
  3192.   call   SB_write_dac
  3193.   pop    eax
  3194.   call   SB_write_dac
  3195.   mov    al,0D1h                                       ;SPEAKER_ON
  3196.   call   SB_write_dac
  3197.   cli
  3198.   in     al,21h
  3199.   mov    bl,1
  3200.   mov    cl,[byte init_settings.IRQ_no]
  3201.   shl    bl,cl
  3202.   not    bl
  3203.   and    al,bl
  3204.   out    21h,al
  3205.   mov    al,01011000b                                  ;DMA remote-init
  3206.   mov    ah,[byte init_settings.DMA_no]
  3207.   mov    ebx,[dword DAC_PHYSICAL_PAGE]
  3208.   mov    ecx,[dword DMA_length]
  3209.   lea    ecx,[ecx*2]
  3210.   dec    ecx
  3211.   call   DMA_setup
  3212.   mov    al,48h                                        ;DMA_8_BIT_DAC (FAST)
  3213.   call   SB_write_dac
  3214.   mov    eax,[dword DMA_length]
  3215.   dec    eax
  3216.   call   SB_write_dac
  3217.   mov    al,ah
  3218.   call   SB_write_dac
  3219.   mov    al,91h
  3220.   call   SB_write_dac
  3221.   sti
  3222.   ret
  3223. endp
  3224.  
  3225. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3226. ;                                          ;
  3227. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3228. proc SB08_init
  3229.   mov    bl,[byte init_settings.IRQ_no]
  3230.   call   getirqvector
  3231.   mov    [dword DAC_old_irq_ofs],edx
  3232.   mov    [word DAC_old_irq_sel],cx
  3233.  
  3234.   cmp    [byte init_settings.card_type],SB_CARD
  3235.   je     @@set_advanced
  3236.   cmp    [byte init_settings.card_type],SBPRO_CARD
  3237.   je     @@set_advanced
  3238.   cmp    [byte init_settings.card_type],SB15EM_CARD
  3239.   je     @@set_compatable
  3240.   ret
  3241. @@set_compatable:
  3242.   call   sb_init_compatable
  3243.   ret
  3244. @@set_advanced:
  3245.   call   sb_init_advanced
  3246.   ret
  3247. endp
  3248.  
  3249.  
  3250. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3251. ;                                          ;
  3252. ; SB1.X, SB2,0 + SBPRO deinit              ;
  3253. ;                                          ;
  3254. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3255. proc sbsub1_deinit
  3256.   mov    bl,1
  3257.   mov    cl,[byte init_settings.IRQ_no]
  3258.   shl    bl,cl
  3259.   in     al,21h
  3260.   or     al,bl
  3261.   out    21h,al
  3262.   mov    bl,[byte init_settings.IRQ_no]
  3263.   mov    edx,[dword DAC_old_irq_ofs]
  3264.   mov    cx,[word DAC_old_irq_sel]
  3265.   call   setirqvector
  3266.   ret
  3267. endp
  3268.  
  3269. proc SB08_deinit
  3270.   call   SB_detect_port
  3271.   cmp    [byte init_settings.card_type],SBPRO_CARD
  3272.   jne    @@dont_reset
  3273.   mov    eax,110eh                                     ;set for mono
  3274.   call   SB_write_mixer
  3275. @@dont_reset:
  3276.   mov    al,0D0h                                       ;HALT_DMA
  3277.   call   SB_write_dac
  3278.   cli
  3279.   call   sbsub1_deinit
  3280.   sti
  3281.   ret
  3282. endp
  3283.  
  3284. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3285. ;                                          ;
  3286. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3287. label SB16_sample_settings tDAC_ssetings
  3288.   tDAC_ssetings <11025,00222,0444,011400>
  3289.   tDAC_ssetings <16538,00332,0664,017400>
  3290.   tDAC_ssetings <22050,00442,0884,088200>
  3291.   tDAC_ssetings <33075,00662,1324,165000>
  3292.   tDAC_ssetings <44100,00882,1764,176400>
  3293.  
  3294. proc SB16_init
  3295.   mov    bl,[byte init_settings.IRQ_no]
  3296.   call   getirqvector
  3297.   mov    [dword DAC_old_irq_ofs],edx
  3298.   mov    [word DAC_old_irq_sel],cx
  3299.   mov    bl,[byte init_settings.IRQ_no]
  3300.   lea    edx,[SB16_virtualmixxer]
  3301.   mov    cx,cs
  3302.   call   setirqvector
  3303.   mov    [byte DAC_shift_value],6
  3304.   movzx  eax,[byte init_settings.DAC_Samplerate]
  3305.   mov    ecx,size tDAC_ssetings
  3306.   mul    ecx
  3307.   mov    ebx,[dword eax+SB16_sample_settings.DAC_sr]
  3308.   mov    [dword DAC_sampling_rate],ebx
  3309.   mov    ebx,[dword eax+SB16_sample_settings.DAC_mix_buffer_size]
  3310.   mov    [dword DAC_mix_buffer_size],ebx
  3311.   lea    ebx,[ebx*4]
  3312.   mov    [DAC_double_buf2],ebx
  3313.   mov    ebx,[dword eax+SB16_sample_settings.DMA_length]
  3314.   mov    [dword DMA_length],ebx
  3315.   mov    eax,[dword eax+SB16_sample_settings.DMA_real_sr]
  3316.   push   eax
  3317.   mov    bl,[byte init_settings.IRQ_no]
  3318.   lea    edx,[SB16_virtualmixxer]
  3319.   mov    cx,cs
  3320.   call   setirqvector
  3321.   cli
  3322.   in     al,21h
  3323.   mov    bl,1
  3324.   mov    cl,[byte init_settings.IRQ_no]
  3325.   shl    bl,cl
  3326.   not    bl
  3327.   and    al,bl
  3328.   out    21h,al
  3329.   mov    al,01011000b
  3330.   mov    ah,[byte init_settings.DMA_no]
  3331.   mov    ebx,[dword DAC_PHYSICAL_PAGE]
  3332.   mov    ecx,[dword DMA_length]
  3333.   lea    ecx,[ecx*4]
  3334.   dec    ecx
  3335.   call   DMA_setup
  3336.   mov    al,41h
  3337.   call   SB_write_dac
  3338.   pop    eax
  3339.   xchg   al,ah
  3340.   call   SB_write_dac
  3341.   mov    al,ah
  3342.   call   SB_write_dac
  3343.   mov    al,0b6h
  3344.   call   SB_write_dac
  3345.   mov    al,030h
  3346.   call   SB_write_dac
  3347.   mov    eax,[dword DMA_length]
  3348.   dec    eax
  3349.   call   SB_write_dac
  3350.   mov    al,ah
  3351.   call   SB_write_dac
  3352.   sti
  3353.   ret
  3354. endp
  3355.  
  3356. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3357. ;                                          ;
  3358. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3359. proc SB16_deinit
  3360.   cli
  3361.   mov    al,0d9h
  3362.   call   SB_write_dac
  3363.   call   sbsub1_deinit
  3364.   sti
  3365.   ret
  3366. endp
  3367.  
  3368. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3369. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3370. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3371. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3372. ;                                                                          ;
  3373. ; GUS DEPENDANT CODE                                                       ;
  3374. ;                                                                          ;
  3375. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3376. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3377. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3378. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3379. ;GUS CONST
  3380. GUS_irq_table          db 0,0,1,2,0,3,0,4,0,0,0,5,6,0,0,7
  3381. GUS_dma_table          db 0,1,0,2,0,3,4,5
  3382.  
  3383. ;Gravis only
  3384. gus_base               dd 0
  3385. gus_status             dd 6
  3386. gus_timercontrol       dd 8
  3387. gus_timerdata          dd 9
  3388. gus_irqdmacontrol      dd 0bh
  3389. gus_midictrl           dd 100h
  3390. gus_mididata           dd 101h
  3391. gus_voice              dd 102h
  3392. gus_command            dd 103h
  3393. gus_datalo             dd 104h
  3394. gus_datahi             dd 105h
  3395. gus_GF1_status         dd 106h
  3396. gus_dram               dd 107h
  3397. DMA_state              db ?
  3398.  
  3399. gus_volume_table:
  3400. db 020h,040h,060h,080h,090h,094h,098h,09ch
  3401. db 0A0h,0A2h,0A4h,0A6h,0A8h,0AAh,0ACh,0AEh
  3402. db 0B0h,0B1h,0B2h,0B3h,0B4h,0B5h,0B6h,0B7h
  3403. db 0B8h,0B9h,0BAh,0BBh,0BCh,0BDh,0BEh,0BFh
  3404. db 0C0h,0C0h,0C1h,0C1h,0C2h,0C2h,0C3h,0C3h
  3405. db 0C4h,0C4h,0C5h,0C5h,0C6h,0C6h,0C7h,0C7h
  3406. db 0C8h,0C8h,0C9h,0C9h,0CAh,0CAh,0CBh,0CBh
  3407. db 0CCh,0CCh,0CDh,0CDh,0CEh,0CEh,0CFh,0CFh
  3408. db 0D0h,0D0h,0D0h,0D0h,0D1h,0D1h,0D1h,0D1h
  3409. db 0D2h,0D2h,0D2h,0D2h,0D3h,0D3h,0D3h,0D3h
  3410. db 0D4h,0D4h,0D4h,0D4h,0D5h,0D5h,0D5h,0D5h
  3411. db 0D6h,0D6h,0D6h,0D6h,0D7h,0D7h,0D7h,0D7h
  3412. db 0D8h,0D8h,0D8h,0D8h,0D9h,0D9h,0D9h,0D9h
  3413. db 0DAh,0DAh,0DAh,0DAh,0DBh,0DBh,0DBh,0DBh
  3414. db 0DCh,0DCh,0DCh,0DCh,0DDh,0DDh,0DDh,0DDh
  3415. db 0DEh,0DEh,0DEh,0DEh,0DFh,0DFh,0DFh,0DFh
  3416. db 0E0h,0E0h,0E0h,0E0h,0E0h,0E1h,0E1h,0E1h
  3417. db 0E1h,0E2h,0E2h,0E2h,0E2h,0E3h,0E3h,0E3h
  3418. db 0E3h,0E4h,0E4h,0E4h,0E4h,0E5h,0E5h,0E5h
  3419. db 0E5h,0E6h,0E6h,0E6h,0E6h,0E7h,0E7h,0E7h
  3420. db 0E7h,0E8h,0E8h,0E8h,0E8h,0E9h,0E9h,0E9h
  3421. db 0E9h,0EAh,0EAh,0EAh,0EAh,0EAh,0EBh,0EBh
  3422. db 0EBh,0EBh,0ECh,0ECh,0ECh,0ECh,0EDh,0EDh
  3423. db 0EDh,0EDh,0EEh,0EEh,0EEh,0EEh,0EFh,0EFh
  3424. db 0EFh,0EFh,0F0h,0F0h,0F0h,0F0h,0F1h,0F1h
  3425. db 0F1h,0F1h,0F2h,0F2h,0F2h,0F2h,0F3h,0F3h
  3426. db 0F3h,0F3h,0F4h,0F4h,0F4h,0F4h,0F4h,0F5h
  3427. db 0F5h,0F5h,0F5h,0F6h,0F6h,0F6h,0F6h,0F6h
  3428. db 0F7h,0F7h,0F7h,0F7h,0F8h,0F8h,0F8h,0F8h
  3429. db 0F9h,0F9h,0F9h,0F9h,0F9h,0F9h,0FAh,0FAh
  3430. db 0FAh,0FAh,0FBh,0FBh,0FBh,0FBh,0FBh,0FBh
  3431. db 0FBh,0FCh,0FCh,0FCh,0FCh,0FCh,0FCh,0FCh
  3432.  
  3433. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3434. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3435. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3436. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3437. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3438. ;                                                                          ;
  3439. ; GUS Code                                                                 ;
  3440. ;                                                                          ;
  3441. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3442. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3443. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3444. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3445. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3446.  
  3447. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3448. ;                                                                          ;
  3449. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3450. proc GUSi_freq_convert
  3451.   mov    eax,[dword edi+tfunk_chan.rfreq]
  3452.   xor    edx,edx
  3453.   mov    ecx,43
  3454.   div    ecx
  3455.   mov    [dword edi+tfunk_chan.CARD_freq],eax
  3456.   ret
  3457. endp
  3458.  
  3459. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3460. ;                                                                          ;
  3461. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3462. proc GUSi_volume_convert
  3463.   xor    eax,eax
  3464.   cmp    [byte edi+tfunk_chan.channel_kill],STOP
  3465.   je     @@transt
  3466.   mov    al,[byte funk_info.master_volume]
  3467.   cmp    al,0
  3468.   je     @@transt
  3469.   xor    ecx,ecx
  3470.   mov    cl,[byte edi+tfunk_chan.rvolume]
  3471.   inc    al
  3472.   mul    ecx
  3473.   shr    eax,4
  3474. @@transt:
  3475.   mov    al,[byte eax+gus_volume_table]
  3476.   mov    [byte edi+tfunk_chan.CARD_volume],al
  3477.   ret
  3478. endp
  3479.  
  3480. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3481. ;                                                                          ;
  3482. ; GUS interface routines                                                   ;
  3483. ;                                                                          ;
  3484. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3485. proc GUS_set_freq
  3486.   mov    edx,[dword gus_command]
  3487.   mov    al,1
  3488.   out    dx,al
  3489.   inc    edx
  3490.   mov    eax,[dword edi+tfunk_chan.CARD_freq]
  3491.   out    dx,ax
  3492.   ret
  3493. endp
  3494.  
  3495. ; cl = volume to set
  3496. proc GUS_set_volume
  3497.   cmp    cl,[byte gus_volume_table]
  3498.   jae    @@cont
  3499.   ret
  3500. @@cont:
  3501.   mov    edx,[dword gus_command]
  3502.   MOV    al,89h
  3503.   OUT    dx,al
  3504.   INC    edx
  3505.   IN     ax,dx
  3506.   mov    bl,ah
  3507.   cmp    bl,4
  3508.   jae    @@dont_level1
  3509.   mov    bl,4
  3510. @@dont_level1:
  3511.   xor    ch,ch
  3512.   cmp    bl,cl
  3513.   je     @@end
  3514.   jb     @@set_ramp_to_up
  3515.   mov    ch,040h
  3516.   xchg   bl,cl
  3517. @@set_ramp_to_up:
  3518. ;bl = ramp start
  3519. ;cl = ramp end
  3520. ;ch = ramp direction
  3521.   DEC    edx
  3522.   MOV    al,0dh
  3523.   OUT    dx,al
  3524.   ADD    edx,2
  3525.   MOV    al,3
  3526.   OUT    dx,al
  3527.   SUB    edx,2
  3528.   MOV    al,7
  3529.   OUT    dx,al
  3530.   ADD    edx,2
  3531.   MOV    al,bl
  3532.   OUT    dx,al
  3533.   SUB    edx,2
  3534.   MOV    al,8
  3535.   OUT    dx,al
  3536.   ADD    edx,2
  3537.   mov    al,cl
  3538.   OUT    dx,al
  3539.   SUB    edx,2
  3540.   MOV    al,6
  3541.   OUT    dx,al
  3542.   ADD    edx,2
  3543.   MOV    al,3fh
  3544.   OUT    dx,al
  3545.   sub    edx,2
  3546.   MOV    al,0dh
  3547.   OUT    dx,al
  3548.   ADD    edx,2
  3549.   MOV    al,ch
  3550.   OUT    dx,al
  3551. @@loopramp:
  3552.   sub    edx,2
  3553.   mov    al,8dh
  3554.   out    dx,al
  3555.   add    edx,2
  3556.   in     al,dx
  3557.   test   al,1
  3558.   jz     @@loopramp
  3559. @@end:
  3560.   ret
  3561. endp
  3562.  
  3563. proc GUS_load_channel
  3564.   mov    cl,[byte gus_volume_table]
  3565.   call   GUS_set_volume
  3566.   mov    edx,[dword gus_command]
  3567.   xor    al,al
  3568.   out    dx,al
  3569.   add    edx,2
  3570.   mov    al,3
  3571.   out    dx,al
  3572.   mov    eax,[funk_hr_ptr]
  3573.   cmp    [word eax+tfunk_hr.LZH_check_sum],"vF"
  3574.   jne    @@no_varbalance
  3575.   sub    edx,2
  3576.   mov    al,0ch
  3577.   out    dx,al
  3578.   add    edx,2
  3579.   mov    al,[byte edi+tfunk_chan.balance]
  3580.   shr    al,4
  3581.   out    dx,al
  3582. @@no_varbalance:
  3583.   call   GUS_set_freq
  3584.   mov    edx,[dword gus_command]
  3585. ;Send sample begin
  3586.   mov    al,0ah
  3587.   out    dx,al
  3588.   inc    edx
  3589.   mov    eax,[dword edi+tfunk_chan.CARD_sample_ptr]
  3590.   add    eax,32
  3591.   shr    eax,7
  3592.   out    dx,ax
  3593.   dec    edx
  3594.   mov    al,0bh
  3595.   out    dx,al
  3596.   inc    edx
  3597.   mov    eax,[dword edi+tfunk_chan.CARD_sample_ptr]
  3598.   add    eax,32
  3599.   shl    eax,9
  3600.   out    dx,ax
  3601.   dec    edx
  3602. ;Send sample start
  3603.   mov    al,2
  3604.   out    dx,al
  3605.   inc    edx
  3606.   mov    eax,[dword edi+tfunk_chan.start]
  3607.   add    eax,32
  3608.   shr    eax,7
  3609.   out    dx,ax
  3610.   dec    edx
  3611.   mov    al,3
  3612.   out    dx,al
  3613.   inc    edx
  3614.   mov    eax,[dword edi+tfunk_chan.start]
  3615.   add    eax,32
  3616.   shl    eax,9
  3617.   out    dx,ax
  3618.   dec    edx
  3619. ;Send sample end
  3620.   mov    al,4
  3621.   out    dx,al
  3622.   inc    edx
  3623.   mov    eax,[dword edi+tfunk_chan.length]
  3624.   sub    eax,32
  3625.   shr    eax,7
  3626.   out    dx,ax
  3627.   dec    edx
  3628.   mov    al,5
  3629.   out    dx,al
  3630.   inc    edx
  3631.   mov    eax,[dword edi+tfunk_chan.length]
  3632.   sub    eax,32
  3633.   shl    eax,9
  3634.   out    dx,ax
  3635.   mov    cl,[byte edi+tfunk_chan.CARD_volume]
  3636.   call   GUS_set_volume
  3637.   ret
  3638. endp
  3639.  
  3640. proc GUS_set_start
  3641.   mov    edx,[dword gus_command]
  3642. ;Send sample start
  3643.   mov    al,2
  3644.   out    dx,al
  3645.   inc    edx
  3646.   mov    eax,[dword edi+tfunk_chan.start]
  3647.   add    eax,32
  3648.   shr    eax,7
  3649.   out    dx,ax
  3650.   dec    edx
  3651.   mov    al,3
  3652.   out    dx,al
  3653.   inc    edx
  3654.   mov    eax,[dword edi+tfunk_chan.start]
  3655.   add    eax,32
  3656.   shl    eax,9
  3657.   out    dx,ax
  3658.   ret
  3659. endp
  3660.  
  3661. proc GUS_fire_channel
  3662.   cmp    [dword edi+tfunk_chan.length],64
  3663.   jae    @@cont
  3664.   ret
  3665. @@cont:
  3666.   mov    edx,[dword gus_command]
  3667.   xor    al,al
  3668.   out    dx,al
  3669.   test   [byte edi+tfunk_chan.funkctrl],1b
  3670.   jz     @@dont_loop
  3671.   mov    al,8
  3672. @@dont_loop:
  3673.   add    edx,2
  3674.   out    dx,al
  3675.   mov    [byte edi+tfunk_chan.funkctrl],0
  3676.   ret
  3677. endp
  3678.  
  3679. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3680. ;                                                                          ;
  3681. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3682. proc GUS_update
  3683.   lea    edi,[funk_chan1]
  3684.   xor    cl,cl
  3685. @@play_slot:
  3686.   push   ecx
  3687.   mov    al,cl
  3688.   mov    edx,[dword gus_voice]
  3689.   out    dx,al
  3690.   test   [byte edi+tfunk_chan.funkctrl],10b
  3691.   jnz    @@fire_channel
  3692.   call   GUS_set_freq
  3693.   mov    cl,[byte edi+tfunk_chan.CARD_volume]
  3694.   call   GUS_set_volume
  3695.   test   [byte edi+tfunk_chan.funkctrl],10000000b
  3696.   jz     @@done
  3697.   and    [byte edi+tfunk_chan.funkctrl],01111111b
  3698.   call   GUS_set_start
  3699.   jmp    @@done
  3700. @@fire_channel:
  3701.   call   GUS_load_channel
  3702. @@done:
  3703.   pop    ecx
  3704.   add    edi,size tfunk_chan
  3705.   inc    cl
  3706.   cmp    cl,8
  3707.   jb     @@play_slot
  3708.  
  3709.   lea    edi,[funk_chan1]
  3710.   xor    cl,cl
  3711. @@play_slot2:
  3712.   mov    al,cl
  3713.   mov    edx,[dword gus_voice]
  3714.   out    dx,al
  3715.   test   [byte edi+tfunk_chan.funkctrl],10b
  3716.   jz     @@done2
  3717.   call   GUS_fire_channel
  3718. @@done2:
  3719.   add    edi,size tfunk_chan
  3720.   inc    cl
  3721.   cmp    cl,8
  3722.   jb     @@play_slot2
  3723.   ret
  3724. endp
  3725.  
  3726. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3727. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3728. ;                                                                         ;
  3729. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3730. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3731. proc GUS_mixxer
  3732.   cld
  3733.   push   ds es
  3734.   pushad
  3735.   mov    ax,DGROUP
  3736.   mov    ds,ax
  3737.   mov    es,ax
  3738. @@next_irq:
  3739.   mov    edx,[dword gus_status]
  3740.   in     al,dx
  3741.   mov    [byte @@irq_state],al
  3742.   test   [byte @@irq_state],10000000b
  3743.   jnz    @@DMA_interrupt
  3744.   call   funk_tracker
  3745.   call   GUS_update
  3746.   mov    edx,[dword gus_command]
  3747.   mov    al,45h
  3748.   out    dx,al
  3749.   add    edx,2
  3750.   xor    al,al
  3751.   out    dx,al
  3752.   mov    al,8
  3753.   out    dx,al
  3754.   jmp    @@end
  3755. @@DMA_interrupt:
  3756.   mov    edx,[dword gus_command]
  3757.   mov    al,041h
  3758.   out    dx,al
  3759.   add    edx,2
  3760.   in     al,dx
  3761.   or     [byte DMA_state],1
  3762.   test   [byte @@irq_state],11101111b
  3763.   jz     @@next_irq
  3764. @@end:
  3765.   mov    al,20h
  3766.   out    20h,al
  3767.   out    0a0h,al
  3768.   popad
  3769.   pop    es ds
  3770.   iretd
  3771. @@irq_state:
  3772.   db     ?
  3773. endp
  3774.  
  3775. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3776. ;                                                                          ;
  3777. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3778. proc gus_delay
  3779.   mov    edx,[dword gus_dram]
  3780.   in     al,dx
  3781.   in     al,dx
  3782.   in     al,dx
  3783.   in     al,dx
  3784.   in     al,dx
  3785.   in     al,dx
  3786.   in     al,dx
  3787.   ret
  3788. endp
  3789.  
  3790. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3791. ; esi                                                                      ;
  3792. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3793. proc GUS_mem_in
  3794.   mov    edx,[dword gus_command]
  3795.   mov    al,43h
  3796.   out    dx,al
  3797.   inc    edx
  3798.   mov    eax,esi
  3799.   out    dx,ax
  3800.   dec    edx
  3801.   mov    al,44h
  3802.   out    dx,al
  3803.   add    edx,2
  3804.   mov    eax,esi
  3805.   shr    eax,16
  3806.   out    dx,al
  3807.   add    edx,2
  3808.   in     al,dx
  3809.   ret
  3810. endp
  3811.  
  3812. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3813. ; edi                                                                      ;
  3814. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3815. proc GUS_mem_out
  3816.   push   eax
  3817.   mov    edx,[dword gus_Command]
  3818.   mov    al,43h
  3819.   out    dx,al
  3820.   inc    edx
  3821.   mov    eax,edi
  3822.   out    dx,ax
  3823.   dec    edx
  3824.   mov    al,44h
  3825.   out    dx,al
  3826.   add    edx,2
  3827.   mov    eax,edi
  3828.   shr    eax,16
  3829.   out    dx,al
  3830.   add    edx,2
  3831.   pop    eax
  3832.   out    dx,al
  3833.   ret
  3834. endp
  3835.  
  3836. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3837. ;                                                                          ;
  3838. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3839. proc GUS_find_mem
  3840.   xor    bl,bl
  3841.   mov    edi,100h
  3842. @@fm_loop:
  3843.   mov    al,0AAh
  3844.   call   GUS_mem_out
  3845.   mov    ecx,0FFFFh
  3846. @@bw_loop:
  3847.   nop
  3848.   dec    ecx
  3849.   jnz    @@bw_loop
  3850.   mov    esi,edi
  3851.   call   GUS_mem_in
  3852.   cmp    al,0AAh
  3853.   jnz    @@exit
  3854.   add    edi,40000h
  3855.   inc    bl
  3856.   cmp    bl,4
  3857.   jbe    @@fm_loop
  3858. @@exit:
  3859.   sub    edi,100h
  3860.   jz     @@standard
  3861.   mov    [dword funk_info.sample_memory_lim],edi
  3862.   ret
  3863. @@standard:
  3864.   mov    [dword funk_info.sample_memory_lim],40000h
  3865.   ret
  3866. endp
  3867.  
  3868. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3869. ;                                                                          ;
  3870. ; NB/this 'total reset' routine is from adam's dos32 routines              ;
  3871. ;                                                                          ;
  3872. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3873. proc GUS_total_reset
  3874.   cmp    [byte init_settings.IRQ_no],0
  3875.   je     @@zero_irq1
  3876.   movzx  edx,[byte init_settings.IRQ_no]
  3877.   mov    dl,[byte edx+GUS_irq_table]
  3878.   or     dl,dl
  3879.   jz     @@invalid_setting
  3880. @@Zero_irq1:
  3881.   mov    [byte @@irq_control],dl
  3882.   movzx  edx,[byte init_settings.IRQ_no2]
  3883.   or     dl,dl
  3884.   jz     @@Zero_irq2
  3885.   mov    dl,[byte edx+GUS_irq_table]
  3886.   or     dl,dl
  3887.   jz     @@invalid_setting
  3888.   shl    dl,3
  3889. @@Zero_irq2:
  3890.   or     [byte @@irq_control],dl
  3891.   mov    al,[byte init_settings.IRQ_no]
  3892.   cmp    al,[byte init_settings.IRQ_no2]
  3893.   jne    @@diff_irqs
  3894.   cmp    [byte init_settings.IRQ_no],0
  3895.   je     @@diff_irqs
  3896.   and    [byte @@irq_control],0111b
  3897.   or     [byte @@irq_control],40h
  3898. @@diff_irqs:
  3899.   movzx  edx,[byte init_settings.DMA_no]
  3900.   or     dl,dl
  3901.   jz     @@Zero_dma2
  3902.   mov    dl,[byte edx+GUS_dma_table]
  3903.   or     dl,dl
  3904.   jz     @@invalid_setting
  3905. @@Zero_dma1:
  3906.   mov    [byte @@dma_control],dl
  3907.   movzx  edx,[byte init_settings.DMA_no2]
  3908.   or     dl,dl
  3909.   jz     @@Zero_dma2
  3910.   mov    dl,[byte edx+GUS_dma_table]
  3911.   or     dl,dl
  3912.   jz     @@invalid_setting
  3913.   shl    dl,3
  3914. @@Zero_dma2:
  3915.   or     [byte @@dma_control],dl
  3916.   mov    al,[byte init_settings.DMA_no]
  3917.   cmp    al,[byte init_settings.DMA_no2]
  3918.   jne    @@diff_dmas
  3919.   and    cl,cl
  3920.   jz     @@diff_irqs
  3921.   and    [byte @@dma_control],0111b
  3922.   or     [byte @@dma_control],40h
  3923. @@diff_dmas:
  3924.   cli
  3925.   mov    ecx,200h
  3926.   loop   $
  3927.   mov    edx,[dword GUS_base]
  3928.   add    edx,0fh
  3929.   mov    al,5
  3930.   out    dx,al
  3931.   mov    edx,[dword GUS_base]
  3932.   mov    al,00001011b
  3933.   out    dx,al
  3934.   mov    edx,[dword GUS_irqdmacontrol]
  3935.   xor    al,al
  3936.   out    dx,al
  3937.   mov    edx,[dword GUS_base]
  3938.   add    edx,0fh
  3939.   xor    al,al
  3940.   out    dx,al
  3941.   mov    edx,[dword GUS_base]
  3942.   mov    al,00001011b
  3943.   out    dx,al
  3944.   mov    edx,[dword GUS_irqdmacontrol]
  3945.   mov    al,[byte @@dma_control]
  3946.   or     al,80h
  3947.   out    dx,al
  3948.   mov    edx,[dword GUS_base]
  3949.   mov    al,01001011b
  3950.   out    dx,al
  3951.   mov    edx,[dword gus_irqdmacontrol]
  3952.   mov    al,[byte @@irq_control]
  3953.   out    dx,al
  3954.   mov    edx,[dword GUS_base]
  3955.   mov    al,00001011b
  3956.   out    dx,al
  3957.   mov    edx,[dword gus_irqdmacontrol]
  3958.   mov    al,[byte @@dma_control]
  3959.   out    dx,al
  3960.   mov    edx,[dword GUS_base]
  3961.   mov    al,01001011b
  3962.   out    dx,al
  3963.   mov    edx,[dword gus_irqdmacontrol]
  3964.   mov    al,[byte @@irq_control]
  3965.   out    dx,al
  3966.   mov    edx,[dword gus_voice]
  3967.   xor    al,al
  3968.   out    dx,al
  3969.   mov    edx,[dword GUS_base]
  3970.   mov    al,0001001b
  3971.   out    dx,al
  3972.   mov    edx,[dword gus_voice]
  3973.   xor    al,al
  3974.   out    dx,al
  3975.   in     al,0A1h
  3976.   mov    ah,al
  3977.   in     al,21h
  3978.   mov    cl,[byte init_settings.IRQ_no]
  3979.   cmp    cl,2
  3980.   jne    @@j3
  3981.   mov    cl,9
  3982. @@j3:
  3983.   mov    ebx,1
  3984.   shl    ebx,cl
  3985.   not    ebx
  3986.   and    eax,ebx
  3987.   mov    cl,[byte init_settings.IRQ_no2]
  3988.   cmp    cl,2
  3989.   jne    @@j4
  3990.   mov    cl,9
  3991. @@j4:
  3992.   mov    ebx,1
  3993.   shl    ebx,cl
  3994.   not    ebx
  3995.   and    eax,ebx
  3996.   out    021h,al
  3997.   mov    al,ah
  3998.   out    0A1h,al
  3999. ;part II
  4000.   mov    edx,[dword gus_command]
  4001.   mov    al,04Ch
  4002.   out    dx,al
  4003.   add    edx,2
  4004.   mov    al,00000000b
  4005.   out    dx,al
  4006.   mov    ecx,10
  4007. @@J56:
  4008.   call   gus_delay
  4009.   loop   @@J56
  4010.   mov    edx,[dword gus_command]
  4011.   mov    al,04Ch
  4012.   out    dx,al
  4013.   add    edx,2
  4014.   mov    al,00000001b
  4015.   out    dx,al
  4016.   mov    ecx,10
  4017. @@J57:
  4018.   call   gus_delay
  4019.   loop   @@J57
  4020.   mov    edx,[dword gus_midictrl]
  4021.   mov    al,00000011b
  4022.   out    dx,al
  4023.   mov    ecx,10
  4024. @@J58:
  4025.   call   gus_delay
  4026.   loop   @@J58
  4027.   xor    al,al
  4028.   out    dx,al
  4029.   mov    edx,[dword gus_command]
  4030.   mov    al,041h
  4031.   out    dx,al
  4032.   add    edx,2
  4033.   xor    al,al
  4034.   out    dx,al
  4035.   mov    edx,[dword gus_command]
  4036.   mov    al,045h
  4037.   out    dx,al
  4038.   add    edx,2
  4039.   xor    al,al
  4040.   out    dx,al
  4041.   mov    edx,[dword gus_command]
  4042.   mov    al,049h
  4043.   out    dx,al
  4044.   add    edx,2
  4045.   xor    al,al
  4046.   out    dx,al
  4047.   mov    edx,[dword gus_command]
  4048.   mov    al,049h
  4049.   out    dx,al
  4050.   add    edx,2
  4051.   xor    al,al
  4052.   out    dx,al
  4053.   mov    edx,[dword gus_command]
  4054.   mov    al,0eh
  4055.   out    dx,al
  4056.   add    edx,2
  4057.   mov    al,13 or 0C0h
  4058.   out    dx,al
  4059.   mov    edx,[dword gus_GF1_status]
  4060.   in     al,dx
  4061.   mov    edx,[dword gus_command]
  4062.   mov    al,041h
  4063.   out    dx,al
  4064.   add    edx,2
  4065.   in     al,dx
  4066.   mov    edx,[dword gus_command]
  4067.   mov    al,049h
  4068.   out    dx,al
  4069.   add    edx,2
  4070.   in     al,dx
  4071. @@ClrFIFO:
  4072.   mov    edx,[dword gus_command]
  4073.   mov    al,08fh
  4074.   out    dx,al
  4075.   add    edx,2
  4076.   in     al,dx
  4077.   and    al,11000000b
  4078.   cmp    al,11000000b
  4079.   jne    @@ClrFIFO
  4080.   xor    bl,bl
  4081. @@stop_loop:
  4082.   mov    edx,[dword GUS_voice]
  4083.   mov    al,bl
  4084.   out    dx,al
  4085.   mov    edx,[dword gus_command]
  4086.   xor    al,al
  4087.   out    dx,al
  4088.   add    edx,2
  4089.   xor    al,al
  4090.   out    dx,al
  4091.   mov    edx,[dword gus_command]
  4092.   xor    al,al
  4093.   out    dx,al
  4094.   add    edx,2
  4095.   mov    al,10b
  4096.   out    dx,al
  4097.   mov    edx,[dword gus_command]
  4098.   mov    al,0dh
  4099.   out    dx,al
  4100.   add    edx,2
  4101.   mov    al,10b
  4102.   out    dx,al
  4103.   mov    edx,[dword gus_command]
  4104.   mov    al,09h
  4105.   out    dx,al
  4106.   inc    edx
  4107.   movzx  eax,[byte gus_volume_table]
  4108.   shl    eax,8
  4109.   out    dx,ax
  4110.   call   gus_delay
  4111.   inc    bl
  4112.   cmp    bl,14
  4113.   jb     @@stop_loop
  4114.   mov    edx,[dword gus_GF1_status]
  4115.   in     al,dx
  4116.   mov    edx,[dword gus_command]
  4117.   mov    al,041h
  4118.   out    dx,al
  4119.   add    edx,2
  4120.   in     al,dx
  4121.   mov    edx,[dword gus_command]
  4122.   mov    al,049h
  4123.   out    dx,al
  4124.   add    edx,2
  4125.   in     al,dx
  4126. @@Clr2FIFO:
  4127.   mov    edx,[dword gus_command]
  4128.   mov    al,08fh
  4129.   out    dx,al
  4130.   add    edx,2
  4131.   in     al,dx
  4132.   and    al,11000000b
  4133.   cmp    al,11000000b
  4134.   jne    @@Clr2FIFO
  4135.   mov    edx,[dword gus_command]
  4136.   mov    al,0eh
  4137.   out    dx,al
  4138.   add    edx,2
  4139.   mov    al,13 or 0C0h
  4140.   out    dx,al
  4141.   mov    edx,[dword gus_command]
  4142.   mov    al,04ch
  4143.   out    dx,al
  4144.   add    edx,2
  4145.   mov    al,00000111b
  4146.   out    dx,al
  4147.   sti
  4148. @@invalid_setting:
  4149.   ret
  4150. @@dma_control:
  4151.   db ?
  4152. @@irq_control:
  4153.   db ?
  4154. @@gf1:
  4155.   db ?
  4156. @@midi:
  4157.   db ?
  4158. endp
  4159.  
  4160. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4161. ;                                                                          ;
  4162. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4163. proc GUS_reset
  4164. ;added code
  4165.   mov    edx,[dword gus_base]
  4166.   mov    al,0bh
  4167.   out    dx,al
  4168. ;added code
  4169.   mov    ebx,[dword gus_Command]
  4170.   mov    ecx,[dword gus_DataHi]
  4171.   mov    edx,ebx
  4172.   mov    al,4Ch
  4173.   out    dx,al
  4174.   mov    edx,ecx
  4175.   xor    al,al
  4176.   out    dx,al
  4177.   call   gus_delay
  4178.   call   gus_delay
  4179.   mov    edx,ebx
  4180.   mov    al,4Ch
  4181.   out    dx,al
  4182.   mov    edx,ecx
  4183.   mov    al,1
  4184.   out    dx,al
  4185.   call   gus_delay
  4186.   call   gus_delay
  4187.   mov    edx,ebx
  4188.   mov    al,41h
  4189.   out    dx,al
  4190.   mov    edx,ecx
  4191.   xor    al,al
  4192.   out    dx,al
  4193.   mov    edx,ebx
  4194.   mov    al,45h
  4195.   out    dx,al
  4196.   mov    edx,ecx
  4197.   xor    al,al
  4198.   out    dx,al
  4199.   mov    edx,ebx
  4200.   mov    al,49h
  4201.   out    dx,al
  4202.   mov    edx,ecx
  4203.   xor    al,al
  4204.   out    dx,al
  4205.   mov    edx,ebx
  4206.   mov    al,0Eh
  4207.   out    dx,al
  4208.   add    edx,2
  4209.   mov    al,13
  4210.   or     al,0Ch
  4211.   out    dx,al
  4212.   mov    edx,[dword gus_Status]
  4213.   in     al,dx
  4214.   mov    edx,ebx
  4215.   mov    al,41h
  4216.   out    dx,al
  4217.   mov    edx,ecx
  4218.   in     al,dx
  4219.   mov    edx,ebx
  4220.   mov    al,49h
  4221.   out    dx,al
  4222.   mov    edx,ecx
  4223.   in     al,dx
  4224.   mov    edx,ebx
  4225.   mov    al,8Fh
  4226.   out    dx,al
  4227.   mov    edx,ecx
  4228.   in     al,dx
  4229.   push   ebx ecx
  4230.   xor    ecx,ecx
  4231.   mov    bl,0
  4232. @@VoiceClearLoop:
  4233.   mov    edx,[dword gus_Voice]
  4234.   mov    al,cl
  4235.   out    dx,al
  4236.   inc    edx
  4237.   xor    al,al
  4238.   out    dx,al
  4239.   add    edx,2
  4240.   mov    al,3
  4241.   out    dx,al
  4242.   sub    edx,2
  4243.   mov    al,0Dh
  4244.   out    dx,al
  4245.   add    edx,2
  4246.   mov    al,3
  4247.   out    dx,al
  4248.   sub    edx,2
  4249.   mov    al,0ch
  4250.   out    dx,al
  4251.   add    edx,2
  4252.   mov    al,bl
  4253.   out    dx,al
  4254.   sub    edx,2
  4255.   mov    al,09h
  4256.   out    dx,al
  4257.   inc    edx
  4258.   movzx  eax,[byte gus_volume_table]
  4259.   shl    eax,8
  4260.   out    dx,ax
  4261.   xor    bl,0ffh
  4262.   inc    ecx
  4263.   cmp    ecx,13
  4264.   jnz    @@VoiceClearLoop
  4265.   pop    ecx ebx
  4266.   mov    edx,ebx
  4267.   mov    al,41h
  4268.   out    dx,al
  4269.   mov    edx,ecx
  4270.   in     al,dx
  4271.   mov    edx,ebx
  4272.   mov    al,49h
  4273.   out    dx,al
  4274.   mov    edx,ecx
  4275.   in     al,dx
  4276.   mov    edx,ebx
  4277.   mov    al,8Fh
  4278.   out    dx,al
  4279.   mov    edx,ecx
  4280.   in     al,dx
  4281.   mov    edx,ebx
  4282.   mov    al,4Ch
  4283.   out    dx,al
  4284.   mov    edx,ecx
  4285.   mov    al,7
  4286.   out    dx,al
  4287. ;added code
  4288.   mov    edx,ebx
  4289.   mov    al,4Ch
  4290.   out    dx,al
  4291.   mov    edx,ecx
  4292.   mov    al,7
  4293.   out    dx,al
  4294. ;;;;
  4295.   mov    edx,[dword gus_base]                             ;set irq
  4296.   mov    al,4bh
  4297.   out    dx,al
  4298.   movzx  eax,[byte init_settings.IRQ_no]
  4299.   mov    al,[byte eax+GUS_irq_table]
  4300.   push   eax
  4301.   MOV    edx,[dword gus_irqdmacontrol]
  4302.   OUT    dx,AL
  4303. ;;;;
  4304.   mov    edx,[dword gus_base]                             ;set dma
  4305.   mov    al,0bh
  4306.   out    dx,al
  4307.   movzx  eax,[byte init_settings.DMA_no]
  4308.   mov    al,[byte eax+GUS_dma_table]
  4309.   MOV    edx,[dword gus_irqdmacontrol]
  4310.   OUT    dx,AL
  4311. ;;;;
  4312.   mov    edx,[dword gus_base]                             ;set irq
  4313.   mov    al,4bh
  4314.   out    dx,al
  4315.   MOV    edx,[dword gus_irqdmacontrol]
  4316.   pop    eax
  4317.   OUT    dx,AL
  4318. ;;;;
  4319.   mov    edx,[dword gus_base]
  4320.   mov    al,0bh
  4321.   out    dx,al
  4322.   mov    edx,ebx
  4323.   mov    al,41h
  4324.   out    dx,al
  4325.   mov    edx,ecx
  4326.   xor    al,al
  4327.   out    dx,al
  4328.   mov    edx,ebx
  4329.   mov    al,45h
  4330.   out    dx,al
  4331.   mov    edx,ecx
  4332.   xor    al,al
  4333.   out    dx,al
  4334.   mov    edx,ebx
  4335.   mov    al,49h
  4336.   out    dx,al
  4337.   mov    edx,ecx
  4338.   xor    al,al
  4339.   out    dx,al
  4340.   MOV    AL,80h
  4341.   MOV    edx,[dword gus_timerdata]
  4342.   OUT    dx,AL
  4343.   xor    al,al
  4344.   MOV    edx,[dword gus_timerdata]
  4345.   OUT    dx,AL
  4346.   mov    edx,[dword gus_base]
  4347.   mov    al,0bh
  4348.   out    dx,al
  4349. ;added code
  4350.   ret
  4351. endp
  4352.  
  4353. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4354. ;                                                                          ;
  4355. ; GUS Interrupt ready                                                      ;
  4356. ;                                                                          ;
  4357. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4358. proc GUS_intready
  4359.   cli
  4360.   xor    cl,cl
  4361.   xor    bl,bl
  4362. @@resetb:
  4363.   mov    edx,[dword gus_Voice]
  4364.   mov    al,cl
  4365.   out    dx,al
  4366.   mov    edx,[dword gus_command]
  4367.   mov    al,0ch
  4368.   out    dx,al
  4369.   add    edx,2
  4370.   mov    al,bl
  4371.   out    dx,al
  4372.   xor    bl,0ffh
  4373.   inc    cl
  4374.   cmp    cl,13
  4375.   jnz    @@resetb
  4376.  
  4377.   mov    edx,[dword gus_command]
  4378.   mov    al,45h
  4379.   out    dx,al
  4380.   mov    al,2bh
  4381.   and    al,0f7h
  4382.   mov    edx,[dword gus_datahi]
  4383.   out    dx,al
  4384.   xor    al,al
  4385.   out    021h,al
  4386.   xor    al,al
  4387.   out    0a1h,al
  4388.   mov    al,20h
  4389.   out    020h,al
  4390.   mov    al,20h
  4391.   out    0a0h,al
  4392.   mov    al,47h
  4393.   mov    edx,[dword gus_command]
  4394.   out    dx,al
  4395.   mov    al,193 ;<<-speed
  4396.   add    edx,2
  4397.   out    dx,al
  4398.   sub    edx,2
  4399.   mov    al,45h
  4400.   out    dx,al
  4401.   add    edx,2
  4402.   mov    al,8
  4403.   out    dx,al
  4404.   mov    edx,[dword gus_timercontrol]
  4405.   mov    al,4
  4406.   out    dx,al
  4407.   mov    edx,[dword gus_timerdata]
  4408.   mov    al,2
  4409.   out    dx,al
  4410.   mov    al,8
  4411.   mov    edx,[dword gus_base]
  4412.   out    dx,al
  4413.   sti
  4414.   ret
  4415. endp
  4416.  
  4417. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4418. ;                                                                          ;
  4419. ; GUS Save INT timer registers                                             ;
  4420. ;                                                                          ;
  4421. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4422. proc GUS_init
  4423.   mov    bl,[byte init_settings.IRQ_no]
  4424.   call   getirqvector
  4425.   mov    [dword DAC_old_irq_ofs],edx
  4426.   mov    [word DAC_old_irq_sel],cx
  4427.  
  4428.   mov    bl,[byte init_settings.IRQ_no]
  4429.   lea    edx,[GUS_mixxer]
  4430.   mov    ecx,cs
  4431.   call   setirqvector
  4432.   call   GUS_total_reset
  4433.   call   GUS_reset
  4434.   call   GUS_intready
  4435.   ret
  4436. endp
  4437.  
  4438. proc GUS_deinit
  4439.   call   GUS_reset
  4440.   mov    bl,[byte init_settings.IRQ_no]
  4441.   mov    edx,[dword DAC_old_irq_ofs]
  4442.   mov    cx,[word DAC_old_irq_sel]
  4443.   call   setirqvector
  4444.   ret
  4445. endp
  4446.  
  4447. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4448. ;   esi     trans mem                                                      ;
  4449. ;   edi     gus mem locatin                                                ;
  4450. ;   ecx     bytes to trans                                                 ;
  4451. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4452. proc gus_upload
  4453.   cli
  4454.   mov    edx,[dword gus_Command]
  4455. @@MainLoop:
  4456.   mov    edx,[dword gus_Command]
  4457.   mov    al,44h
  4458.   out    dx,al
  4459.   add    edx,2
  4460.   mov    eax,edi
  4461.   shr    eax,16
  4462.   out    dx,al
  4463.   mov    edx,[dword gus_Command]
  4464.   mov    al,43h
  4465.   out    dx,al
  4466.   inc    edx
  4467.   mov    eax,edi
  4468.   out    dx,ax
  4469.   mov    edx,[dword gus_dram]
  4470.   outsb
  4471.   inc    edi
  4472.   dec    ecx
  4473.   jnz    @@MainLoop
  4474.   sti
  4475.   ret
  4476. endp
  4477.  
  4478. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4479. ;   edi     trans mem                                                      ;
  4480. ;   esi     gus mem locatin                                                ;
  4481. ;   ecx     bytes to trans                                                 ;
  4482. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4483. proc gus_dnload
  4484.   cli
  4485.   mov    edx,[dword gus_Command]
  4486. @@MainLoop:
  4487.   mov    edx,[dword gus_Command]
  4488.   mov    al,44h
  4489.   out    dx,al
  4490.   add    edx,2
  4491.   mov    eax,esi
  4492.   shr    eax,16
  4493.   out    dx,al
  4494.   mov    edx,[dword gus_Command]
  4495.   mov    al,43h
  4496.   out    dx,al
  4497.   inc    edx
  4498.   mov    eax,esi
  4499.   out    dx,ax
  4500.   mov    edx,[dword gus_dram]
  4501.   insb
  4502.   inc    esi
  4503.   dec    ecx
  4504.   jnz    @@MainLoop
  4505.   sti
  4506.   ret
  4507. endp
  4508.  
  4509. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4510. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4511. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4512. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4513. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4514. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4515. ;                                                                          ;
  4516. ; PAS DEPENDANT CODE                                                       ;
  4517. ;                                                                          ;
  4518. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4519. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4520. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4521. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4522. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4523. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4524.  
  4525. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4526. ;                                                                          ;
  4527. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4528. proc PAS16_virtualmixxer
  4529.   cld
  4530.   push   ds es
  4531.   pushad
  4532.   mov    ax,DGROUP
  4533.   mov    ds,ax
  4534.   mov    es,ax
  4535. @@ISR_l:
  4536.   mov    edx,INTRCTLRST                                 ;clear the interrupt
  4537.   xor    edx,[_MVTranslateCode]                         ;xlate the board address
  4538.   in     al,dx
  4539.   test   al,bISsampbuff+bISsamprate                     ;our interrupt?
  4540.   jz     @@exit_int
  4541.   out    dx,al                                          ;yes, flush it...
  4542.   mov    esi,[dword DAC_mix_buffer]
  4543.   mov    edx,[dword DAC_mix_buffer_right]
  4544.   mov    edi,[dword DAC_mix_buffer2]
  4545.   add    edi,[DAC_double_buf1]
  4546.   mov    eax,[DAC_double_buf1]
  4547.   xchg   eax,[DAC_double_buf2]
  4548.   mov    [DAC_double_buf1],eax
  4549.   mov    ecx,[dword DAC_mix_buffer_size]
  4550.   xor    ebx,ebx
  4551. @@trans16:
  4552.   mov    eax,[edx+ebx]
  4553.   shl    eax,16
  4554.   mov    ax,[word esi+ebx]
  4555.   mov    [edi+ebx*2],eax
  4556.   add    ebx,2
  4557.   dec    ecx
  4558.   jnz    @@trans16
  4559.   call   funk_tracker
  4560.   mov    ecx,[dword DAC_mix_buffer_size]
  4561.   shr    ecx,1
  4562.   mov    edi,[dword DAC_mix_buffer]
  4563.   xor    eax,eax
  4564.   rep    stosd
  4565.   mov    ecx,[dword DAC_mix_buffer_size]
  4566.   shr    ecx,1
  4567.   mov    edi,[dword DAC_mix_buffer_right]
  4568.   rep    stosd
  4569.   lea    ebx,[funk_chan1]
  4570.   mov    edi,[dword DAC_mix_buffer]
  4571.   call   DAC_channel_mixxer
  4572.   lea    ebx,[funk_chan2]
  4573.   mov    edi,[dword DAC_mix_buffer_right]
  4574.   call   DAC_channel_mixxer
  4575.   lea    ebx,[funk_chan3]
  4576.   mov    edi,[dword DAC_mix_buffer]
  4577.   call   DAC_channel_mixxer
  4578.   lea    ebx,[funk_chan4]
  4579.   mov    edi,[dword DAC_mix_buffer_right]
  4580.   call   DAC_channel_mixxer
  4581.   lea    ebx,[funk_chan5]
  4582.   mov    edi,[dword DAC_mix_buffer]
  4583.   call   DAC_channel_mixxer
  4584.   lea    ebx,[funk_chan6]
  4585.   mov    edi,[dword DAC_mix_buffer_right]
  4586.   call   DAC_channel_mixxer
  4587.   lea    ebx,[funk_chan7]
  4588.   mov    edi,[dword DAC_mix_buffer]
  4589.   call   DAC_channel_mixxer
  4590.   lea    ebx,[funk_chan8]
  4591.   mov    edi,[dword DAC_mix_buffer_right]
  4592.   call   DAC_channel_mixxer
  4593.   jmp    @@ISR_l
  4594. @@exit_int:
  4595.   mov    al,20h                                         ;clear the interrupt
  4596.   cmp    [init_settings.IRQ_no],8                       ;2nd IRQ controller?
  4597.   jb     @@F1
  4598.   out    0A0h,al
  4599. @@F1:
  4600.   out    020h,al
  4601.   popad
  4602.   pop    es ds
  4603.   iretd
  4604. endp
  4605.  
  4606. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4607. ;                                                                         ;
  4608. ; Pro Audio routines for FunkTracker                                      ;
  4609. ;                                                                         ;
  4610. ; Routines from Media Vision SDK, Inc.                                    ;
  4611. ; Copyright (c) 1991,1992. All Rights Res.                                ;
  4612. ;                                                                         ;
  4613. ; Converted to P-mode by Jason Nunn                                       ;
  4614. ;                                                                         ;
  4615. ; This INIT code that talks to MVSOUND.SYS isn't supposed to run in P-mode;
  4616. ; So, problems _may_ occur. I'll replace it when i get time.              ;
  4617. ;                                                                         ;
  4618. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4619.  
  4620. ; Hardware associated with the PAS1/PAS2/CDPC
  4621. DEFAULT_BASE          = 00388h  ;default base I/O address
  4622. ALT_BASE_1            = 00384h  ;first alternate address
  4623. ALT_BASE_2            = 0038Ch  ;second alternate address
  4624. ALT_BASE_3            = 00288h  ;third alternate address
  4625. USE_ACTIVE_ADDR       = 00000h  ;uses what is currently active
  4626. AUDIOFILT             = 00B8Ah  ;Audio Filter Control Register
  4627. INTRCTLRST            = 00B89h  ;Interrupt Control Status Register
  4628. INTRCTLR              = 00B8Bh  ;Interrupt Control Register write
  4629. CROSSCHANNEL          = 00F8Ah  ;Cross Channel Register
  4630. SAMPLERATE            = 01388h  ;(t0) Sample Rate Timer Register
  4631. SAMPLECNT             = 01389h  ;(t1) Sample Count Register
  4632. TMRCTLR               = 0138Bh  ;Local Timer Control Register
  4633. ; Factory Default Settings
  4634. DEFAULTDMA            = 1       ;DMA channel 1
  4635. DEFAULTIRQ            = 7       ;IRQ channel 7
  4636. DEFAULTINT            = 65h     ;Interrupt # for software interface
  4637. ; mixer select
  4638. OUTPUTMIXER           = 00h     ;output mixer H/W select
  4639. INPUTMIXER            = 40h     ;input mixer select
  4640. DEFMIXER              = -1      ;use last mixer selected
  4641. MIXERMAX              = 1fh     ;maximum mixer setting
  4642. MVVOLUMEMAX           = 3fh     ;MVA508 maximum mixer setting
  4643. NSVOLUMEMAX           = 28h     ;National maximum mixer setting
  4644. EQUALIZERMAX          = 0ch     ;maximum equalizer setting
  4645. EQUALIZERMID          = 06h     ;maximum mid setting
  4646. ; Filter register bits
  4647. fFIdatabits           = 00011111B ;filter select and decode field bits
  4648. fFImutebits           = 00100000B ;filter mute field bits
  4649. fFIpcmbits            = 11000000B ;filter sample rate field bits
  4650. bFImute               = 00100000B ;filter mute bit
  4651. bFIsrate              = 01000000B ;filter sample rate timer mask
  4652. bFIsbuff              = 10000000B ;filter sample buffer counter mask
  4653. FILTERMAX             = 6         ;six possible settings
  4654. ; Cross Channel Bit definitions
  4655. fCCcrossbits          = 00001111B ;; cross channel bit field
  4656. fCCpcmbits            = 11110000B ;; pcm/dma control bit field
  4657. bCCr2r                = 00000001B ;; CROSSCHANNEL Right to Right
  4658. bCCl2r                = 00000010B ;; CROSSCHANNEL Left  to Right
  4659. bCCr2l                = 00000100B ;; CROSSCHANNEL Right to Right
  4660. bCCl2l                = 00001000B ;; CROSSCHANNEL Left  to Left
  4661. bCCdac                = 00010000B ;; DAC/ADC Control
  4662. bCCmono               = 00100000B ;; PCM Monaural Enable
  4663. bCCenapcm             = 01000000B ;; Enable PCM state machine
  4664. bCCdrq                = 10000000B ;; Enable DRQ bit
  4665. ; Interrupt Control Register Bits
  4666. fICintmaskbits        = 00011111B ;; interrupt mask field bits
  4667. fICrevbits            = 11100000B ;; revision mask field bits
  4668. bICsamprate           = 00000100B ;; Sample Rate timer interrupt enable
  4669. bICsampbuff           = 00001000B ;; Sample buffer timer interrupt enable
  4670. fICrevshr             = 5         ;; rotate rev bits to lsb
  4671.  
  4672.  
  4673. ;Interrupt Status Register Bits
  4674.  
  4675. fISints               = 1fh ; Interrupt bit field
  4676. bISleftfm             = 01h ; Left FM interrupt active
  4677. bISritfm              = 02h ; Right FM interrupt active
  4678. bISsamprate           = 04h ; Sample Rate timer interrupt active
  4679. bISsampbuff           = 08h ; Sample buffer timer interrupt active
  4680. bISmidi               = 10h ; MIDI interrupt active
  4681. bISPCMlr              = 20h ; PCM left/right active
  4682. bISActive             = 40h ; Hardware is active (not in reset)
  4683. bISClip               =    80h ; Sample Clipping has occured
  4684.  
  4685. MASTERCHIPR           = 0ff88h  ;; Master Chip Rev      (r)
  4686. ENHANCEDSCSI          = 07f89h  ;; Enhanced SCSI detect port
  4687. SYSCONFIG2            = 08389h  ;; System Config 2      (r/w)
  4688. COMPATREGE            = 0f788h  ;; Compatible Rgister Enable (r/w)
  4689. MASTERMODRD           = 0ff8bh  ;; Master Mode Read      (r)
  4690. SLAVEMODRD            = 0ef8bh  ;; Slave Mode Read      (r)
  4691. ; Sys Config 2
  4692. bSC216bit             = 00000100b ;; 16 bit audio
  4693. bSC212bit             = 00001000b ;; 12 bit interleaving (d2 must be set too)
  4694. ; I/O Config 3
  4695. bIC3pcmint            = 00001111b       ;; pcm IRQ channel select
  4696. bIC3cdint             = 11110000b ;; cd  IRQ channel select
  4697. ; Compatibility Register
  4698. cpMPUEmulation        = 00000001b ;; MPU emuation is on bit
  4699. ; Slave Mode Read
  4700. bSMRDdrvtyp           = 00000011b       ;; drive interface type
  4701. bSMRDfmtyp            = 00000100b ;; FM chip type
  4702. bSMRDdactyp           = 00001000b ;; 16 bit dac (1) or 8 bit dac (0)
  4703. ; Master Mode Read
  4704. bMMRDatps2            = 00000001b       ;; AT(1) or PS2(0) bus
  4705. bMMRDmsmd             = 00000100b ;; master/slave mode
  4706. ; Interrupt Controller #1 Port Addresses and Interrupt Masks
  4707. IRQ1MASKREG           = 021h  ;; 8259 mask register
  4708. INT7MSK               = 10000000B ;; interrupt 7 mask
  4709. ; Interrupt Controller #2 Port Addresses and Interrupt Masks
  4710. IRQ2MASKREG           = 0A1h  ;; 8259 mask register
  4711. ;; dma controller #1 port addresses
  4712. DMAC0ADDR             = 000h  ;; DMA channel 0 Base & Current Address
  4713. DMAC0COUNT            = 001h  ;; DMA channel 0 Base & Current Count
  4714. DMAC1ADDR             = 002h  ;; DMA channel 1 Base & Current Address
  4715. DMAC1COUNT            = 003h  ;; DMA channel 1 Base & Current Count
  4716. DMAC2ADDR             = 004h  ;; DMA channel 2 Base & Current Address
  4717. DMAC2COUNT            = 005h  ;; DMA channel 2 Base & Current Count
  4718. DMAC3ADDR             = 006h  ;; DMA channel 3 Base & Current Address
  4719. DMAC3COUNT            = 007h  ;; DMA channel 3 Base & Current Count
  4720. DMA2C4ADDR            = 0C0h  ;; DMA channel 4 Base & Current Address
  4721. DMA2C4COUNT           = 0C2h  ;; DMA channel 4 Base & Current Count
  4722. DMA2C5ADDR            = 0C4h  ;; DMA channel 5 Base & Current Address
  4723. DMA2C5COUNT           = 0C6h  ;; DMA channel 5 Base & Current Count
  4724. DMA2C6ADDR            = 0C8h  ;; DMA channel 6 Base & Current Address
  4725. DMA2C6COUNT           = 0CAh  ;; DMA channel 6 Base & Current Count
  4726. DMA2C7ADDR            = 0CCh  ;; DMA channel 7 Base & Current Address
  4727. DMA2C7COUNT           = 0CEh  ;; DMA channel 7 Base & Current Count
  4728. DMARDSTAT             = 008h  ;; DMA read status
  4729. DMAWRCNTRL            = 008h  ;; DMA write command register
  4730. DMAWREQ               = 009h  ;; DMA write request register
  4731. DMAWRSMR              = 00Ah  ;; DMA write single mask register
  4732. DMAWRMODE             = 00Bh  ;; DMA write mode register
  4733. DMACLEAR              = 00Ch  ;; DMA clear low/high flip-flop
  4734. DMARDTEMP             = 00Dh  ;; DMA read temp register
  4735. DMAWRCLR              = 00Dh  ;; DMA write master clear
  4736. DMACLRMSK             = 00Eh  ;; DMA clear mask register
  4737. DMAWRALL              = 00Fh  ;; DMA write all mask register bits
  4738. DMA2RDSTAT            = 0D0h  ;; DMA read status
  4739. DMA2WRCNTRL           = 0D0h  ;; DMA write command register
  4740. DMA2WREQ              = 0D2h  ;; DMA write r=est register
  4741. DMA2WRSMR             = 0D4h  ;; DMA write single mask register
  4742. DMA2WRMODE            = 0D6h  ;; DMA write mode register
  4743. DMA2CLEAR             = 0D8h  ;; DMA clear low/high flip-flop
  4744. DMA2RDTEMP            = 0DAh  ;; DMA read temp register
  4745. DMA2WRCLR             = 0DAh  ;; DMA write master clear
  4746. DMA2CLRMSK            = 0DCh  ;; DMA clear mask register
  4747. DMA2WRALL             = 0DEh  ;; DMA write all mask register bits
  4748. CH0PAGEREG            = 087h  ;; Channel 0 Page Register
  4749. CH1PAGEREG            = 083h  ;; Channel 1 Page Register
  4750. CH2PAGEREG            = 081h  ;; Channel 2 Page Register
  4751. CH3PAGEREG            = 082h  ;; Channel 3 Page Register
  4752. CH5PAGEREG            = 08Bh  ;; Channel 5 Page Register
  4753. CH6PAGEREG            = 089h  ;; Channel 6 Page Register
  4754. CH7PAGEREG            = 08Ah  ;; Channel 7 Page Register
  4755.  
  4756. struc MVState
  4757.   _sysspkrtmr         db 0 ;    42 System Speaker Timer Address
  4758.   _systmrctlr         db 0 ;    43 System Timer Control
  4759.   _sysspkrreg         db 0 ;    61 System Speaker Register
  4760.   _joystick           db 0 ;   201 Joystick Register
  4761.   _lfmaddr            db 0 ;   388 Left  FM Synth Address
  4762.   _lfmdata            db 0 ;   389 Left  FM Synth Data
  4763.   _rfmaddr            db 0 ;   38A Right FM Synth Address
  4764.   _rfmdata            db 0 ;   38B Right FM Synth Data
  4765.   _dfmaddr            db 0 ;   788 Dual  FM Synthesizer Address Register
  4766.   _dfmdata            db 0 ;   789 Dual  FM Synthesizer Data Register
  4767.                       db 0 ; reserved for future use
  4768.   _paudiomixr         db 0 ;   78B Paralllel Audio Mixer Control
  4769.   _audiomixr          db 0 ;   B88 Audio Mixer Control
  4770.   _intrctlrst         db 0 ;   B89 Interrupt Status
  4771.   _audiofilt          db 0 ;   B8A Audio Filter Control
  4772.   _intrctlr           db 0 ;   B8B Interrupt Control
  4773.   _pcmdata            db 0 ;   F88 PCM Data I/O Register
  4774.   _RESRVD2            db 0 ; reserved
  4775.   _crosschannel       db 0 ;   F8A Cross Channel
  4776.   _RESRVD3            db 0 ; reserved
  4777.   _samplerate         dw 0 ;  1388 Sample Rate Timer
  4778.   _samplecnt          dw 0 ;  1389 Sample Count Register
  4779.   _spkrtmr            dw 0 ;  138A Shadow Speaker Timer Count
  4780.   _tmrctlr            db 0 ;  138B Shadow Speaker Timer Control
  4781.   _mdirqvect          db 0 ;  1788 MIDI IRQ Vector Register
  4782.   _mdsysctlr          db 0 ;  1789 MIDI System Control Register
  4783.   _mdsysstat          db 0 ;  178A MIDI IRQ Status Register
  4784.   _mdirqclr           db 0 ;  178B MIDI IRQ Clear Register
  4785.   _mdgroup1           db 0 ;  1B88 MIDI Group #1 Register
  4786.   _mdgroup2           db 0 ;  1B89 MIDI Group #2 Register
  4787.   _mdgroup3           db 0 ;  1B8A MIDI Group #3 Register
  4788.   _mdgroup4           db 0 ;  1B8B MIDI Group #4 Register
  4789. ends
  4790.  
  4791. bMVA508               = 0000000000000001b ; MVA508(1) or National(0)
  4792. bMVPS2                = 0000000000000010b ; PS2 bus stuff
  4793. bMVSLAVE              = 0000000000000100b ; CDPC Slave device is present
  4794. bMVSCSI               = 0000000000001000b ; SCSI interface
  4795. bMVENHSCSI            = 0000000000010000b ; Enhanced SCSI interface
  4796. bMVSONY               = 0000000000100000b ; Sony 535 interface
  4797. bMVDAC16              = 0000000001000000b ; 16 bit DAC
  4798. bMVSBEMUL             = 0000000010000000b ; SB h/w emulation
  4799. bMVMPUEMUL            = 0000000100000000b ; MPU h/w emulation
  4800. bMVOPL3               = 0000001000000000b ; OPL3(1) or 3812(0)
  4801. bMV101                = 0000010000000000b ; MV101 ASIC
  4802. bMV101_REV            = 0111100000000000b ; MV101 Revision
  4803. bMV101_MORE           = 1000000000000000b ; more bits in BX
  4804. ;; Define the ASIC versions
  4805. ASIC_VERSION_B        = 0000000000000010b ; revision B
  4806. ASIC_VERSION_C        = 0000000000000011b ; revision C
  4807. ASIC_VERSION_D        = 0000000000000100b ; revision D
  4808. ASIC_VERSION_E        = 0000000000000101b ; revision E
  4809. ASIC_VERSION_F        = 0000000000000110b ; revision F
  4810. ;; First Pro Audio Spectrum feature list
  4811. PRODUCT_PROAUDIO      = bMVSCSI
  4812. ;; Pro Audio Plus feature list
  4813. PRODUCT_PROPLUS       = bMV101+bMVSCSI+bMVENHSCSI+bMVSBEMUL+bMVOPL3
  4814. ;; Pro Audio Spectrum 16 feature list
  4815. PRODUCT_PRO16         = bMV101+bMVA508+bMVSCSI+bMVENHSCSI+bMVSBEMUL+bMVDAC16+bMVOPL3
  4816. ;; CDPC feature list
  4817. PRODUCT_CDPC          = bMV101+bMVSLAVE+bMVSONY+bMVSBEMUL+bMVDAC16+bMVOPL3
  4818. ;; Set each one to zero - to be init later if selected
  4819. PROAS100              = 0
  4820. PROAS200              = 0
  4821. PROAS300              = 0
  4822. CDPC                  = 0
  4823. PRODUCTDEFINED        = 0                 ; to be set if a product is selected
  4824. _MVTranslateCode      dd 0                ; I/O base xor default_base
  4825. _MVHWVersionBits      dw -1               ; holds the product feature bits
  4826. VERSION_PAS           = 0                 ; Pro Audio Spectrum
  4827. VERSION_PASPLUS       = 1                 ; Pro Audio Plus card
  4828. VERSION_PAS16         = 2                 ; Pro Audio 16 card
  4829. VERSION_CDPC          = 3                 ; CDPC card & unit
  4830. ; The following equates build up a mask of bits that we do wish to keep
  4831. ; when comparing feature bits. The zero bits can be ignored, whereas, the
  4832. ; the 1 bits must match.
  4833. PASdocare = bMVA508 OR bMVDAC16 OR bMVOPL3 OR bMV101
  4834. PASPLUSdocare = bMVA508 OR bMVDAC16 OR bMVOPL3 OR bMV101
  4835. PAS16docare = bMVA508 OR bMVDAC16 OR bMVOPL3 OR bMV101
  4836. CDPCdocare = bMVA508 OR bMVDAC16 OR bMVOPL3 OR bMV101
  4837. label MVProductIDTable
  4838.   dw PRODUCT_PROAUDIO and PASdocare
  4839.   dw PRODUCT_PROPLUS  and PASPLUSdocare
  4840.   dw PRODUCT_PRO16  and PAS16docare
  4841.   dw PRODUCT_CDPC  and CDPCdocare
  4842.   dw -1
  4843. label MVDoCareBits
  4844.   dw PASdocare
  4845.   dw PASPLUSdocare
  4846.   dw PAS16docare
  4847.   dw CDPCdocare
  4848.   dw -1
  4849.  
  4850. struc dmaaddr
  4851.   _dmach              db ? ; DMA channel selected
  4852.   _dmardstat          db ? ; DMA read status
  4853.   _dmawrcntrl         db ? ; DMA write command register
  4854.   _dmawreq            db ? ; DMA write request register
  4855.   _dmawrsmr           db ? ; DMA write single mask register
  4856.   _dmawrmode          db ? ; DMA write mode register
  4857.   _dmaclear           db ? ; DMA clear low/high flip-flop
  4858.   _dmardtemp          db ? ; DMA read temp register
  4859.   _dmawrclr           db ? ; DMA write master clear
  4860.   _dmaclrmsk          db ? ; DMA clear mask register
  4861.   _dmawrall           db ? ; DMA write all mask register bits
  4862. ends
  4863.  
  4864. MVOurDMAPageReg       dw CH1PAGEREG  ; default to DMA channel 1 page reg
  4865. MVOurDMAddress        dw DMAC1ADDR   ; default to DMA channel 1 address reg
  4866. label DMA1AddrTable
  4867.   db DEFAULTDMA ; DMA channel selected
  4868.   db DMARDSTAT  ; DMA read status
  4869.   db DMAWRCNTRL ; DMA write command register
  4870.   db DMAWREQ    ; DMA write request register
  4871.   db DMAWRSMR   ; DMA write single mask register
  4872.   db DMAWRMODE  ; DMA write mode register
  4873.   db DMACLEAR   ; DMA clear low/high flip-flop
  4874.   db DMARDTEMP  ; DMA read temp register
  4875.   db DMAWRCLR   ; DMA write master clear
  4876.   db DMACLRMSK  ; DMA clear mask register
  4877.   db DMAWRALL   ; DMA write all mask register bits
  4878. ; table of address pointers to the various DMA 2 addresses
  4879. label DMA2AddrTable
  4880.   db DEFAULTDMA ; DMA channel selected
  4881.   db DMA2RDSTAT ; DMA read status
  4882.   db DMA2WRCNTRL; DMA write command register
  4883.   db DMA2WREQ   ; DMA write request register
  4884.   db DMA2WRSMR  ; DMA write single mask register
  4885.   db DMA2WRMODE ; DMA write mode register
  4886.   db DMA2CLEAR  ; DMA clear low/high flip-flop
  4887.   db DMA2RDTEMP ; DMA read temp register
  4888.   db DMA2WRCLR  ; DMA write master clear
  4889.   db DMA2CLRMSK ; DMA clear mask register
  4890.   db DMA2WRALL  ; DMA write all mask register bits
  4891. PCM_DMAPointer        dd offset DMA1AddrTable           ;default to channel 1 table
  4892. MVTheIRQMask          db INT7MSK                        ;8259 interrupt mask
  4893. MVSampleSize          db 2                              ;sample size: 0=8,1=12,2=16
  4894. mvhwShadowPointer     dd 0                              ;points to the start of the data table
  4895. MVHardwareShadowTable MVState <>
  4896. MVTypeOfSetup         db 0                              ;polled/dma interrupt masks & stuff..
  4897. mvStatusWord          dw 0                              ;Holds current status:
  4898.                                                         ; 0 = inactive, available
  4899.                                                         ; 1 = currently playing
  4900.                                                         ; 2 = currently recording
  4901. DMAMASK               = bICsampbuff                     ;dma mask
  4902. POLLEDMASK            = bICsamprate+bICsampbuff         ;polled mask
  4903.  
  4904. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4905. ;                                                                         ;
  4906. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4907. proc PCM_pause
  4908.   jmp    @@j
  4909. @@j:
  4910.   ret
  4911. endp
  4912.  
  4913. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4914. ;                                                                         ;
  4915. ; Given a specific I/O address, this routine will see if the              ;
  4916. ; hardware exists at this address.                                        ;
  4917. ;                                                                         ;
  4918. ; Entry Conditions:                                                       ;
  4919. ;     DI holds the I/O address to test                                    ;
  4920. ;     BX:CX = bMVSCSI                                                     ;
  4921. ;                                                                         ;
  4922. ; Exit Conditions:                                                        ;
  4923. ;     BX:CX = the bit fields that identify the board                      ;
  4924. ;                                                                         ;
  4925. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4926. proc SearchHWVersion
  4927. ; calculate the translation code
  4928.   xor    edi,DEFAULT_BASE
  4929.   mov    eax,0BC00H                                      ;make sure MVSOUND.SYS is loaded
  4930.   mov    ebx,'??'                                        ;this is our way of knowing if the
  4931.   xor    ecx,ecx                                        ;hardware is actually present.
  4932.   xor    edx,edx
  4933.   int    2fh                                            ;get the ID pattern
  4934.   xor    bx,cx                                          ;build the result
  4935.   xor    bx,dx
  4936.   cmp    bx,'MV'                                        ;if not here, exit...
  4937.   jnz    @@sehw_bad
  4938. ; get the MVSOUND.SYS specified DMA and IRQ channel
  4939.   mov    eax,0bc04h                                     ;get the DMA and IRQ numbers
  4940.   int    2fh
  4941.   mov    [init_settings.DMA_no],bl                             ;save the correct DMA & IRQ
  4942.   mov    [init_settings.IRQ_no],cl
  4943. ; grab the version # in the interrupt mask. The top few bits hold the version #
  4944.   mov    edx,INTRCTLR                                    ;board ID is in MSB 3 bits
  4945.   xor    edx,edi
  4946.   in     al,dx
  4947.   cmp    al,-1                                          ;bus float meaning not present?
  4948.   je     @@sehw_bad                                     ;yes, there is no card here
  4949.   mov    ah,al
  4950.   xor    al,fICrevbits
  4951.   out    dx,al
  4952.   call   PCM_pause
  4953.   call   PCM_pause
  4954.   in     al,dx
  4955.   cmp    al,ah
  4956.   xchg   al,ah
  4957.   out    dx,al
  4958.   jnz    @@sehw_bad                                     ;we have a bogus board
  4959.   and    ax,fICrevbits                                  ;isolate the ID bits & clear AH
  4960.   mov    cl,fICrevshr                                   ;shift the bits into a meaningful
  4961.   shr    al,cl                                          ;position (least signficant bits)
  4962.   movzx  esi,ax                                         ;save the version #
  4963. ; We do have hardware! Load the product bit definitions
  4964.   sub    ebx,ebx
  4965.   mov    ecx,bMVSCSI                                    ;setup bx:cx for the original PAS
  4966.   or     al,al                                          ;is this the first version of h/w?
  4967.   jz     @@sehw_done                                    ;yes, simple exit will do.
  4968. ; Checks the installed hardware for all the feature bits.                 ;
  4969. ; All second generation Pro Audio cards use the MV101 and have SB emulation.
  4970.   or     ecx,bMVSBEMUL+bMV101                            ;force SB emulation
  4971. ; determine if the enhanced SCSI interface is present
  4972.   mov    edx,ENHANCEDSCSI                                ;test for SCSI mod (U48)
  4973.   xor    edx,edi                                          ;modify via the translate code
  4974.   out    dx,al                                          ;strobe
  4975.   call   PCM_pause                                      ;I/O bus delay
  4976.   in     al,dx                                          ;get the bit
  4977.   and    al,1                                           ; bit0==1 means old SCSI PAL
  4978.   cmp    al,1                                           ;reverse sense
  4979.   sbb    eax,eax                                         ;ax = ffff if enhanced SCSI
  4980.   and    eax,bMVENHSCSI
  4981.   or     ecx,eax
  4982. ; determine AT/PS2, CDPC slave mode
  4983.   mov    edx,MASTERMODRD
  4984.   xor    edx,edi
  4985.   in     al,dx
  4986.   test   al,bMMRDatps2                                  ;AT(1) or PS2(0)
  4987.   jnz    @@F1
  4988.   or     ecx,bMVPS2
  4989. @@F1:
  4990.   test   al,bMMRDmsmd                                   ;Master(0) or Slave(1)
  4991.   jz     @@F2
  4992.   or     ecx,bMVSLAVE
  4993. @@f2:
  4994.   push   ecx
  4995.   mov    edx,MASTERCHIPR
  4996.   xor    edx,edi
  4997.   in     al,dx
  4998.   and    ax,000Fh
  4999.   mov    cl,11
  5000.   shl    eax,cl
  5001.   pop    ecx
  5002.   or     ecx,eax
  5003. ; determine the CDROM drive type, FM chip, 8/16 bit DAC, and mixer
  5004.   mov    edx,SLAVEMODRD
  5005.   xor    edx,edi
  5006.   in     al,dx
  5007.   test   al,bSMRDdactyp                                 ;16 bit DAC?
  5008.   jz     @@F3                                           ;no, its an 8 bit DAC
  5009.   or     ecx,bMVDAC16                                    ;its a 16 bit DAC
  5010. @@f3:
  5011.   test   al,bSMRDfmtyp                                  ;OPL3 chip?
  5012.   jz     @@F4                                           ;no, so it's the PAS16 card
  5013.   or     ecx,bMVOPL3                                     ;is an OPL3
  5014. @@f4:
  5015.   mov    edx,ecx                                          ;inference check for new mixer
  5016.   and    edx,bMVSLAVE+bMVDAC16                           ;Slave & 16 bit dac is the CDPC
  5017.   cmp    edx,bMVDAC16                                    ;16 bit DAC on master?
  5018.   jnz    @@F5                                           ;no, it's the CDPC with Nation mixer
  5019.   or     ecx,bMVA508
  5020. @@f5:
  5021.   and    al,bSMRDdrvtyp                                 ;isolate the CDROM drive type
  5022.   cmp    al,2                                           ;Sony 535 interface?
  5023.   jnz    @@F6                                           ;no, continue on...
  5024.   and    ecx,NOT (bMVSCSI+bMVENHSCSI)                    ;yes, flush the SCSI bits
  5025.   or     ecx,bMVSONY                                     ;set the 535 bit
  5026. @@f6:
  5027. ; determine if MPU-401 emulation is active
  5028.   mov    edx,COMPATREGE                                  ;compatibility register
  5029.   xor    edx,edi
  5030.   in     al,dx
  5031.   test   al,cpMPUEmulation
  5032.   jz     @@sehw_done
  5033.   or     ecx,bMVMPUEMUL
  5034. @@sehw_done:
  5035. ; loop on a table search to find identify the board
  5036.   push   ebx
  5037.   mov    ebx,-2
  5038. @@sehw_05:
  5039.   add    ebx,2
  5040.   cmp    [word ebx+MVProductIDTable],-1
  5041.   jz     @@sehw_bad_hw                                  ;yes, we can't identify this board
  5042.   mov    edx,ecx
  5043.   and    dx,[word ebx+MVDoCareBits]
  5044.   cmp    dx,[word ebx+MVProductIDTable]
  5045.   jnz    @@sehw_05
  5046.   mov    edx,ebx
  5047.   shr    edx,1
  5048.   pop    ebx
  5049.   movzx  edi,di
  5050.   mov    [dword _MVTranslateCode],edi
  5051.   mov    eax,esi
  5052.   sub    ah,ah                                          ;for our purposes, we will return SCSI
  5053.   xchg   ah,al                                          ;into ah
  5054.   clc                                                   ;The board was identified !.
  5055.   mov    [_mvHWVersionBits],cx
  5056.   jmp    @@sehw_exit
  5057. @@sehw_bad_hw:
  5058.   pop    ebx
  5059.   stc
  5060.   jmp    @@sehw_exit
  5061. @@sehw_bad:
  5062.   stc
  5063. @@sehw_exit:
  5064.   ret
  5065. endp
  5066.  
  5067. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5068. ;                                                                         ;
  5069. ; Detects and identifies the installed Pro AudioSuctrum.                  ;
  5070. ;                                                                         ;
  5071. ; Entry Conditions:                                                       ;
  5072. ;     edi = word address containing the base address.                     ;
  5073. ;                                                                         ;
  5074. ; Exit Conditions:                                                        ;
  5075. ;     Carry is set on error                                               ;
  5076. ;                                                                         ;
  5077. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5078. proc mvGetHWVersion
  5079.   lea    eax,[DACi_freq_convert]
  5080.   mov    [dword CARD_freq_convert],eax
  5081.   lea    eax,[DACi_volume_convert]
  5082.   mov    [dword CARD_volume_convert],eax
  5083.  
  5084.   or     edi,edi
  5085.   jnz    @@mvgehw_05
  5086.   mov    edi,DEFAULT_BASE
  5087.   call   SearchHWVersion
  5088.   jnc    @@mvgehw_exit
  5089.   mov    edi,ALT_BASE_1
  5090.   call   SearchHWVersion
  5091.   jnc    @@mvgehw_exit
  5092.   mov    edi,ALT_BASE_2
  5093.   call SearchHWVersion
  5094.   jnc @@mvgehw_exit
  5095.   mov    edi,ALT_BASE_3
  5096. @@mvgehw_05:
  5097.   call   SearchHWVersion
  5098. @@mvgehw_exit:
  5099.   ret
  5100. endp
  5101.  
  5102. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5103. ;                                                                         ;
  5104. ; Initializes the state table pointer.                                    ;
  5105. ;                                                                         ;
  5106. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5107. proc MVInitStatePtr
  5108. ; setup a pointer to our local hardware state table
  5109.   lea    ebx,[MVHardwareShadowTable]
  5110.   mov    [dword mvhwShadowPointer],ebx
  5111.   mov    [ebx+MVState._audiomixr],31h                   ;lowest filter setting
  5112.   mov    [ebx+MVState._crosschannel],09h                ;cross channel l-2-l, r-2-r
  5113. ; find the int 2F interface and if found, use it's state table pointer
  5114.   mov    ax,0BC00h                                      ;MVSOUND.SYS ID check
  5115.   mov    bx,'??'
  5116.   sub    cx,cx
  5117.   sub    dx,dx
  5118.   int    2fh
  5119.   xor    bx,cx
  5120.   xor    bx,dx
  5121.   cmp    bx,'MV'
  5122.   jnz    @@imvsp_done                                   ;no, exit home
  5123.   mov    ax,0BC02H                                      ;get the pointer
  5124.   int    2fh
  5125.   cmp    ax,'MV'
  5126.   jnz    @@imvsp_done
  5127.   movzx  edx,dx
  5128.   movzx  ebx,bx
  5129.   shl    edx,4
  5130.   add    edx,ebx
  5131.   push   edx
  5132.   mov    ax,0EE02h
  5133.   int    31h            ; returns EBX with program base linear address
  5134.   pop    edx
  5135.   sub    edx,ebx
  5136.   mov    [dword mvhwShadowPointer],edx
  5137. @@imvsp_done:
  5138.   ret
  5139. endp
  5140.  
  5141. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5142. ;                                                                         ;
  5143. ; Turn off the PCM timers, interrupts, and state machine.                 ;
  5144. ;                                                                         ;
  5145. ; Entry Conditions:                                                       ;
  5146. ;                                                                         ;
  5147. ; Exit  Conditions:                                                       ;
  5148. ;                                                                         ;
  5149. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5150. proc StopPCM
  5151.   push   edi
  5152.   mov    edi,[mvhwShadowPointer]
  5153. ; clear the audio filter sample bits
  5154.   mov    edx,AUDIOFILT
  5155.   xor    edx,[_MVTranslateCode]
  5156.   cli
  5157.   mov    al,[edi+MVState._audiofilt]                  ;get the state
  5158.   and    al,not (bFIsrate+bFIsbuff)                     ;flush the sample timer bits
  5159.   mov    [edi+MVState._audiofilt],al                  ;save the new state
  5160.   out    dx,al
  5161. ; clear the PCM enable bit
  5162.   mov    al,[edi+MVState._crosschannel]               ;get the current cross channel
  5163.   and    al,not bCCenapcm                               ;clear the PCM enable bit
  5164.   or     al,bCCdac
  5165.   mov    edx,CROSSCHANNEL
  5166.   xor    edx,[_MVTranslateCode]
  5167.   out    dx,al                                          ; end to the hardware
  5168.   mov    [edi+MVState._crosschannel],al
  5169. ; disable the 16 bit stuff
  5170.   test   [_MVHWVersionBits],bMV101                      ;101 chip?
  5171.   jz     @@stpc02                                       ;no, don't touch this...
  5172.   mov    edx,SYSCONFIG2
  5173.   xor    edx,[_MVTranslateCode]
  5174.   in     al,dx
  5175.   and    al,not bSC216bit+bSC212bit                     ;flush the 16 bit stuff
  5176.   out    dx,al
  5177. @@stpc02:
  5178. ; clear the appropriate Interrupt Control Register bit
  5179.   mov    ah,[MVTypeOfSetup]
  5180.   and    ah,bICsamprate+bICsampbuff
  5181.   not    ah
  5182.   mov    edx,INTRCTLR
  5183.   xor    edx,[_MVTranslateCode]
  5184.   in     al,dx
  5185.   and    al,ah                                          ;kill sample timer interrupts
  5186.   out    dx,al
  5187.   mov    [edi+MVState._intrctlr],al
  5188. ; clear the system interrupt mask only if no other ints are used
  5189.   test   al,fICintmaskbits XOR (bICsamprate+bICsampbuff)
  5190.   jnz    @@stpc10
  5191. ; select the correct IRQ controller, then mask it...
  5192.   cmp    [init_settings.IRQ_no],2                              ;Chained IRQ channel?
  5193.   jz     @@stpc10                                       ;yes, leave it open...
  5194.   mov    dx,IRQ1MASKREG
  5195.   cmp    [init_settings.IRQ_no],8                              ;2nd IRQ controller?
  5196.   jl     @@stpc05
  5197.   mov    dl,IRQ2MASKREG
  5198. @@stpc05:
  5199.   in     al,dx
  5200.   or     al,[MVTheIRQMask]
  5201.   out    dx,al
  5202.   sti
  5203. @@stpc10:
  5204.   push   edi
  5205.   cmp    [mvStatusWord],0                               ;is there any activity?
  5206.   jz     @@kidm_none
  5207.   mov    edi,[PCM_DMAPointer]                                ;get the DMA pointer
  5208.   sub    dx,dx                                          ;clear out the high byte
  5209. ; mask out the DMA to stop it
  5210.   cli
  5211.   mov    al,[edi+dmaaddr._dmach]                         ;get the adjusted dma channel #
  5212.   or     al,0100b                                       ;disable the DMA
  5213.   mov    dl,[edi+dmaaddr._dmawrsmr]
  5214.   out    dx,al
  5215. ; remove control on the DRQ line
  5216.   mov    edi,[mvhwShadowPointer]
  5217.   mov    al,[edi+mvstate._crosschannel]               ;get the state
  5218.   mov    edx,CROSSCHANNEL
  5219.   xor    edx,[_MVTranslateCode]                          ;xlate the board address
  5220.   and    al,not bCCdrq                                  ;clear the DRQ bit
  5221.   out    dx,al
  5222.   mov    [edi+mvstate._crosschannel],al               ;and save the new state
  5223.   sti
  5224. @@kidm_none:
  5225.   pop    edi
  5226.   mov    [mvStatusWord],0
  5227.   pop    edi
  5228.   ret
  5229. endp
  5230.  
  5231. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5232. ;                                                                         ;
  5233. ; Initializes the PCM code                                                ;
  5234. ;                                                                         ;
  5235. ; Entry Conditions:                                                       ;
  5236. ;     None                                                                ;
  5237. ;                                                                         ;
  5238. ; Exit Conditions:                                                        ;
  5239. ;     AX =  Version of this Code                                          ;
  5240. ;                                                                         ;
  5241. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5242. proc InitPCM
  5243.   mov    [MVTypeOfSetup],POLLEDMASK                     ;flushes both interrupts
  5244.                                                         ;for upcoming calls
  5245.   movsx  eax,[byte init_settings.DMA_no]                  ;initialize the DMA now...
  5246.   and    eax,0111b
  5247.   mov    ebx,eax
  5248.   shl    ebx,1
  5249.   jnz    @@seldma_02
  5250.   push   sp
  5251.   pop    cx
  5252.   cmp    cx,sp
  5253.   jnz    @@seldma_bad
  5254. @@seldma_02:
  5255.   mov    dx,[word ebx+@@dmatable]
  5256.   or     dx,dx
  5257.   jz     @@seldma_bad
  5258.   mov    [init_settings.DMA_no],al
  5259.   mov    [byte MVOurDMAPageReg],dh
  5260.   mov    [byte MVOurDMAddress],dl
  5261.   lea    ebx,[DMA1AddrTable]
  5262.   cmp    al,4
  5263.   jl     @@seldma_05
  5264.   lea    ebx,[DMA2AddrTable]
  5265.   sub    al,4
  5266. @@seldma_05:
  5267.   mov    [ebx+dmaaddr._dmach],al
  5268.   mov    [dword PCM_DMAPointer],ebx
  5269.   sub    ax,ax
  5270. @@seldma_bad:
  5271.   mov    eax,[dword DAC_old_irq_ofs]
  5272.   or     eax,eax
  5273.   jz     @@F1
  5274.   mov    bl,[init_settings.IRQ_no]
  5275.   mov    edx,[dword DAC_old_irq_ofs]
  5276.   mov    cx,[word DAC_old_irq_sel]
  5277.   call   setirqvector
  5278.   mov    [dword DAC_old_irq_ofs],0
  5279.   mov    [word DAC_old_irq_sel],0
  5280. @@F1:
  5281.  
  5282.   sub    ax,ax
  5283.   movsx  ecx,[init_settings.IRQ_no]            ;initialize the IRQ now...                                 ;get the irq # (2-7,10-12,14-15)
  5284.   and    cl,0fh                                ;save only the valid bits
  5285.   mov    bx,01
  5286.   shl    bx,cl
  5287.   and    bx,1001110010111100b
  5288.   jz     @@seirqbad
  5289.   mov    [init_settings.IRQ_no],cl
  5290.   cmp    cl,8                                  ;2nd interrupt controller?
  5291.   jb     @@F3                                  ;no, skip
  5292.   xchg   bh,bl
  5293. @@f3:
  5294.   mov    [mvTheIRQMask],bl
  5295.  
  5296.   mov    eax,[DAC_old_irq_ofs]
  5297.   or     eax,eax
  5298.   jnz    @@F2
  5299.  
  5300.   mov    bl,[init_settings.IRQ_no]
  5301.   call   getirqvector
  5302.   mov    [dword DAC_old_irq_ofs],edx
  5303.   mov    [word DAC_old_irq_sel],cx
  5304. @@F2:
  5305.   mov    ax,1
  5306. @@seirqbad:
  5307.   dec    ax
  5308.   call   StopPCM                                        ;kill the Audio Spectrum board
  5309.   mov    edx,INTRCTLRST                                  ;flush any pending PCM irq
  5310.   xor    edx,[_MVTranslateCode]                          ;xlate the board address
  5311.   out    dx,al
  5312.   ret
  5313. label @@dmatable
  5314.   dw     (CH0PAGEREG SHL 8) + DMAC0ADDR
  5315.   dw     (CH1PAGEREG SHL 8) + DMAC1ADDR
  5316.   dw     (CH2PAGEREG SHL 8) + DMAC2ADDR
  5317.   dw     (CH3PAGEREG SHL 8) + DMAC3ADDR
  5318.   dw     0
  5319.   dw     (CH5PAGEREG SHL 8) + DMA2C5ADDR
  5320.   dw     (CH6PAGEREG SHL 8) + DMA2C6ADDR
  5321.   dw     (CH7PAGEREG SHL 8) + DMA2C7ADDR
  5322. endp
  5323.  
  5324. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5325. ;
  5326. ; LoadDMA  -- Load the DMA controller to read/write data to the MV board
  5327. ;
  5328. ; Entry Conditions:
  5329. ;
  5330. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5331. proc LoadDMA
  5332.   mov    edi,[mvhwShadowPointer]
  5333.   mov    esi,[PCM_DMAPointer]                            ;point to the DMA controller table
  5334.   sub    dx,dx                                          ;clear out the high byte
  5335. ; kill the dma until all programming is done
  5336.   mov    al,[esi+dmaaddr._dmach]                         ;get the adjusted dma channel #
  5337.   or     al,0100b                                       ;causes all DMA to be suspended
  5338.   mov    dl,[esi+dmaaddr._dmawrsmr]
  5339.   out    dx,al
  5340. ; program the mode
  5341.   mov    al,01011000b                   ;01011000b       ;get the app's desired mode
  5342.   or     al,[esi+dmaaddr._dmach]                         ;merge the adjusted dma channel #
  5343.   mov    dl,[esi+dmaaddr._dmawrmode]
  5344.   out    dx,al
  5345. ; adjust the address for a 16 bit channel
  5346.  
  5347.   mov    eax,[dword DAC_PHYSICAL_PAGE]
  5348.   push   eax
  5349.   shr    eax,16
  5350. ; setup the page register
  5351.   mov    dx,[MVOurDMAPageReg]
  5352.   out    dx,al
  5353.   mov    bl,al
  5354. ; reset the flip-flop, then output the address, then count
  5355.   mov    dl,[esi+dmaaddr._dmaclear]                      ;dh is still clear...
  5356.   out    dx,al                                          ;flush...
  5357.   pop    eax
  5358.   cmp    esi,offset DMA1AddrTable                        ;1st DMA controller?
  5359.   jz     @@F1                                           ;yes, continue on...
  5360.   shr    bl,1                                           ;no, divide the buffer in half
  5361.   rcr    ax,1                                           ;by shifting 17 bits
  5362. @@F1:
  5363.   mov    dx,[MVOurDMAddress]
  5364.   out    dx,al
  5365.   call   PCM_pause
  5366.   xchg   ah,al
  5367.   out    dx,al
  5368.   mov    eax,[DMA_Length] ;<------>
  5369.   lea    eax,[eax*2]
  5370.   cmp    esi,offset DMA1AddrTable                        ;is this the 2nd dma controller?
  5371.   jz     @@lodma03                                      ;no, use the full length
  5372.   shr    ax,1
  5373.   inc    dx                                             ;move to next port address
  5374. @@lodma03:
  5375.   dec    ax
  5376.   inc    dx                                             ;move to next port address
  5377.   out    dx,al
  5378.   call   PCM_pause
  5379.   xchg   ah,al
  5380.   out    dx,al
  5381. ; before we enable the DMA, let's make sure the DRQ is controlled, not floating
  5382.   mov    al,[edi+mvstate._crosschannel]               ;get the state
  5383.   mov    edx,CROSSCHANNEL
  5384.   xor    edx,[_MVTranslateCode]
  5385.   or     al,bCCdrq                                      ;set the DRQ bit to control it
  5386.   out    dx,al
  5387.   mov    [edi+mvstate._crosschannel],al               ;and save the new state
  5388. ; re-enable the dma now that all programming is done
  5389.   mov    al,[esi+dmaaddr._dmach]                         ;get the adjusted dma channel #
  5390.   sub    dx,dx
  5391.   mov    dl,[esi+dmaaddr._dmawrsmr]
  5392.   out    dx,al                                          ;& let'er loose (not moving though...)
  5393. ; all done, return home...
  5394.   ret
  5395. endp
  5396.  
  5397. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5398. ;
  5399. ; SetupPCMDMAIO  --  Setup to output to the DAC
  5400. ;
  5401. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5402. proc SetupPCMDMAIO
  5403.   push   edi
  5404.   mov    edi,[mvhwShadowPointer]
  5405. ; setup the sample rate timer
  5406.  
  5407.   mov    al,00110110b                                   ;36h Timer 0 & square wave
  5408.   mov    edx,TMRCTLR
  5409.   xor    edx,[_MVTranslateCode]
  5410.   pushf
  5411.   cli
  5412.   out    dx,al                                          ;setup the mode, etc
  5413.   mov    [edi+mvstate._tmrctlr],al
  5414.   mov    ax,[edi+mvstate._samplerate]                 ;pre-calculated & saved in prior code
  5415.   mov    edx,SAMPLERATE
  5416.   xor    edx,[_MVTranslateCode]
  5417.   out    dx,al                                          ;output the timer value
  5418.   call   PCM_pause
  5419.   xchg   ah,al
  5420.   out    dx,al
  5421.   popf
  5422.  
  5423. ; Setup the Sample Buffer Counter Timer (T1 & rate generator)
  5424.   mov    eax,[dword DMA_Length]                         ;get the count
  5425.   add    eax,1                                          ;make it 1 based (1 - 64k)
  5426.   mov    bl,[init_settings.DMA_no]                      ;is this a 16 bit channel?
  5427.   mov    bh,[MVSampleSize]                              ;CX = sample size, channel
  5428.   sub    cx,cx                                          ;ch = multiplier, cl=divider
  5429.   cmp    bx,0003h                                       ;8 bits on 8 bit channel?
  5430.   jbe    @@mdF1                                         ;yes, continue on...
  5431.   inc    cx                                             ;divide by 2
  5432.   cmp    bx,0007h                                       ;8 bits on 16 bit channel?
  5433.   jbe    @@mdF1                                         ;yes, continue on...
  5434.   xchg   ch,cl                                          ;multiply by 2
  5435.   cmp    bx,0203h                                       ;16 bits on 8 bit channel?
  5436.   jbe    @@mdF1                                         ;yes, continue on...
  5437.   sub    cx,cx                                          ;no multiply or divide
  5438. @@mdF1:
  5439.   dec    ax ;<------>
  5440.   shr    ax,cl                                          ;if 8 on 16 divide by 2
  5441.   xchg   ch,cl
  5442.   shl    ax,cl                                          ;if 16 on 8 multiply by 2
  5443.   sub    cx,cx                                          ;The buffer size is # of bytes, so
  5444.   neg    bh                                             ;we must convert it to the data size
  5445.   adc    cx,cx
  5446.   shr    ax,cl
  5447.  
  5448.   push   edi
  5449.   mov    edi,[mvhwShadowPointer]
  5450.   push   edx eax
  5451.   mov    al,01110100b                                   ;74h Timer 1 & rate generator
  5452.   mov    edx,TMRCTLR
  5453.   xor    edx,[_MVTranslateCode]
  5454.   cli
  5455.   out    dx,al
  5456.   mov    [edi+mvstate._tmrctlr],al                    ;local timer control register
  5457.   pop    eax
  5458.   mov    edx,SAMPLECNT
  5459.   xor    edx,[_MVTranslateCode]
  5460.   mov    [edi+mvstate._samplecnt],ax
  5461.   out    dx,al
  5462.   call   PCM_pause
  5463.   xchg   ah,al
  5464.   out    dx,al
  5465.   sti
  5466.   xchg   ah,al
  5467.   pop    edx edi
  5468.  
  5469. ; Setup the system interrupt mask (IRQ mask)
  5470.   mov    dx,IRQ1MASKREG
  5471.   cmp    [init_settings.IRQ_no],8                       ;2nd IRQ controller?
  5472.   jl     @@irqcF2
  5473.   mov    dl,IRQ2MASKREG
  5474. @@irqcF2:
  5475.   in     al,dx                                          ;get the mask
  5476.   mov    ah,[mvTheIRQMask]
  5477.   not    ah
  5478.   and    al,ah                                          ;unmask the correct IRQ
  5479.   out    dx,al                                          ;then let the system know
  5480. ; Setup the Interrupt Control Register
  5481.  
  5482.   mov    edx,INTRCTLRST                                  ;flush any pending interrupts
  5483.   xor    edx,[_MVTranslateCode]                          ;xlate the board address
  5484.   out    dx,al                                          ;of the PCM circuitry
  5485.   mov    edx,INTRCTLR
  5486.   xor    edx,[_MVTranslateCode]                          ;xlate the board address
  5487.   in     al,dx                                          ;get the real mask
  5488.   or     al,bICsampbuff                                 ;interrupt on sample buffer count
  5489.   out    dx,al                                          ;send it..
  5490.   mov    [edi+mvstate._intrctlr],al                   ;save it..
  5491. ; enable the 12/16 bit stuff
  5492.   test   [_MVHWVersionBits],bMV101                      ;101 chip?
  5493.   jz     @@sdhpas1_05                                       ;no, don't touch this...
  5494.   mov    cx,((NOT(bSC216bit+bSC212bit)) shl 8) + bSC216bit+bSC212bit
  5495.   cmp    [mvSampleSize],1                               ;12 bit?
  5496.   jz     @@F3scsi
  5497.   mov    cx,((NOT(bSC216bit+bSC212bit)) shl 8) + bSC216bit
  5498.   cmp    [mvSampleSize],2                               ;16 bit?
  5499.   jz     @@F3scsi
  5500.   mov    cx,((NOT(bSC216bit+bSC212bit)) shl 8) + 0
  5501. @@f3scsi:
  5502.   mov    edx,SYSCONFIG2
  5503.   xor    edx,[_MVTranslateCode]                          ;xlate the board address
  5504.   in     al,dx
  5505.   and    al,ch                                          ;clear the bits
  5506.   or     al,cl                                          ;set the appropriate bits
  5507.   out    dx,al
  5508. @@sdhpas1_05:
  5509. ; setup the direction, stereo/mono and DMA enable bits
  5510.   mov    al,bCCmono                                     ;get the stereo/mono mask bit
  5511.   and    al,0                                           ;al = bCCmono if in mono mode
  5512.   or     al,bCCdac                                      ;bit d6 of interrupt control register
  5513.   or     al,bCCenapcm
  5514.   mov    edx,CROSSCHANNEL
  5515.   xor    edx,[_MVTranslateCode]                          ;xlate the board address
  5516.   mov    ah,0fh + bCCdrq                                ;get a mask to load non PCM bits
  5517.   and    ah,[edi+mvstate._crosschannel]               ;grab all but PCM/DRQ/MONO/DIRECTION
  5518.   or     al,ah                                          ;merge the two states
  5519.   xor    al,bCCenapcm                                   ;disable the PCM bit
  5520.   out    dx,al                                          ;send to the hardware
  5521.   xor    al,bCCenapcm                                   ;enable the PCM bit
  5522.   out    dx,al                                          ;send to the hardware
  5523.   mov    [edi+mvstate._crosschannel],al               ; and save the new state
  5524. ; Setup the audio filter sample bits
  5525.   mov    al,[edi+mvstate._audiofilt]
  5526.   or     al,bFIsrate+bFIsbuff                           ;enable the sample count/buff counters
  5527.   mov    edx,AUDIOFILT
  5528.   xor    edx,[_MVTranslateCode]                         ;xlate the board address
  5529.   out    dx,al
  5530.   mov    [edi+mvstate._audiofilt],al
  5531.   sti                                                   ; fly baby fly !
  5532.   pop    edi
  5533.   ret
  5534. endp
  5535.  
  5536. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5537. ;                                                                         ;
  5538. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5539. label PAS16_sample_settings tDAC_ssetings
  5540.   tDAC_ssetings <11025,00222,0444,22050>
  5541.   tDAC_ssetings <16538,00332,0664,33075>
  5542.   tDAC_ssetings <22050,00442,0884,44100>
  5543.   tDAC_ssetings <33075,00662,1324,66150>
  5544.   tDAC_ssetings <44100,00882,1764,88200>
  5545.  
  5546. proc StartPlaying
  5547.   mov    [MVTypeOfSetup],DMAMASK
  5548.   mov    [byte DAC_shift_value],6
  5549.   movzx  eax,[byte init_settings.DAC_Samplerate]
  5550.   mov    ecx,size tDAC_ssetings
  5551.   mul    ecx
  5552.   mov    ebx,[dword eax+PAS16_sample_settings.DAC_sr]
  5553.   mov    [dword DAC_sampling_rate],ebx
  5554.   mov    ebx,[dword eax+PAS16_sample_settings.DAC_mix_buffer_size]
  5555.   mov    [dword DAC_mix_buffer_size],ebx
  5556.   lea    ebx,[ebx*4]
  5557.   mov    [DAC_double_buf2],ebx
  5558.   push   eax
  5559.   mov    bl,[init_settings.IRQ_no]
  5560.   lea    edx,[PAS16_virtualmixxer]
  5561.   mov    cx,cs
  5562.   call   setirqvector
  5563.   pop    eax
  5564.   mov    [byte MVSampleSize],2
  5565.   mov    ebx,[dword eax+PAS16_sample_settings.DMA_length]
  5566.   lea    ebx,[ebx*2]
  5567.   mov    [dword DMA_length],ebx
  5568.   mov    eax,[dword eax+PAS16_sample_settings.DMA_real_sr]
  5569.   mov    edi,[mvhwShadowPointer]
  5570.   mov    ecx,eax
  5571.   mov    eax,1193180
  5572.   xor    edx,edx
  5573.   div    ecx
  5574.   mov    [edi+MVState._samplerate],ax
  5575. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  5576. ; Program the DMA, then our board circuitry to start the interrupts
  5577.   call   LoadDMA                                        ;setup the DMA controller
  5578.   call   SetupPCMDMAIO                                  ;Setup the MV Hardware
  5579.   mov    [mvStatusWord],1                               ;set the global status word
  5580.   ret
  5581. endp
  5582.  
  5583. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5584. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5585. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5586. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5587. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5588. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5589. ;                                                                          ;
  5590. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5591. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5592. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5593. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5594. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5595. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5596.  
  5597. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5598. ;                                                                          ;
  5599. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5600. proc find_pats_seqs
  5601.   mov    [byte funk_info.no_of_sequences],0
  5602.   mov    edi,[funk_hr_ptr]                          ; find no of patterns
  5603.   xor    al,al
  5604.   mov    ecx,256
  5605. @@find_patseq:
  5606.   cmp    [byte edi+tfunk_hr.order_list],0FFh
  5607.   je     @@end_patseq
  5608.   inc    [byte funk_info.no_of_sequences]
  5609.   cmp    [byte edi+tfunk_hr.order_list],al
  5610.   jbe    @@test_next
  5611.   mov    al,[byte edi+tfunk_hr.order_list]
  5612. @@test_next:
  5613.   inc    edi
  5614.   dec    ecx
  5615.   jnz    @@find_patseq
  5616. @@end_patseq:
  5617.   dec    [byte funk_info.no_of_sequences]
  5618.   inc    al
  5619.   mov    [byte funk_info.no_of_patterns],al
  5620.   ret
  5621. endp
  5622.  
  5623. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5624. ;                                                                          ;
  5625. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5626. proc resync_sample_ptrs
  5627.   mov    al,[byte init_settings.card_type]
  5628.   cmp    al,SB_CARD
  5629.   je     @@DAC_CARD
  5630.   cmp    al,SBPRO_CARD
  5631.   je     @@DAC_CARD
  5632.   cmp    al,GUS_VARB_CARD
  5633.   je     @@DSP_CARD
  5634.   cmp    al,SB15EM_CARD
  5635.   je     @@DAC_CARD
  5636.   cmp    al,SB16_CARD
  5637.   je     @@DAC_CARD
  5638.   cmp    al,GUS_FIXB_CARD
  5639.   je     @@DSP_CARD
  5640.   cmp    al,PAS16_CARD
  5641.   je     @@DAC_CARD
  5642.   ret
  5643. @@DAC_CARD:
  5644.   mov    eax,[dword funk_sd_ptr]
  5645.   mov    [dword funk_info.sample_ptrs],eax
  5646.   jmp    @@calc
  5647. @@DSP_CARD:
  5648.   mov    [dword funk_info.sample_ptrs],32
  5649. @@calc:
  5650.   mov    ebx,[funk_hr_ptr]
  5651.   add    ebx,offset (tfunk_hr).funk_sb
  5652.   xor    edi,edi
  5653.   mov    cl,63
  5654. @@sync_sp:
  5655.   mov    eax,[dword ebx+tfunk_sb.length]
  5656.   add    eax,[dword edi+funk_info.sample_ptrs]
  5657.   add    ebx,size tfunk_sb
  5658.   add    edi,4
  5659.   mov    [dword edi+funk_info.sample_ptrs],eax
  5660.   dec    cl
  5661.   jnz    @@sync_sp
  5662.   mov    eax,[dword ebx+tfunk_sb.length]
  5663.   add    eax,[dword edi+funk_info.sample_ptrs]
  5664.   mov    [dword funk_info.sample_block_size],eax
  5665.   ret
  5666. endp
  5667.  
  5668. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5669. ;                                                                          ;
  5670. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5671. proc upload_exteral_data
  5672.   cmp    [byte init_settings.card_type],GUS_VARB_CARD
  5673.   je     @@GUS_mem_move
  5674.   cmp    [byte init_settings.card_type],GUS_FIXB_CARD
  5675.   je     @@GUS_mem_move
  5676.   ret
  5677. @@GUS_mem_move:
  5678.   call   GUS_reset
  5679.   mov    esi,[dword funk_sd_ptr]
  5680.   mov    edi,[dword funk_info.sample_ptrs]
  5681.   mov    ecx,[dword funk_info.sample_block_size]
  5682.   sub    ecx,[dword funk_info.sample_ptrs]
  5683.   call   GUS_upload
  5684.   call   GUS_reset
  5685.   call   GUS_intready
  5686.   ret
  5687. endp
  5688.  
  5689. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5690. ;                                                                          ;
  5691. ; eax = header buffer ptr                                                  ;
  5692. ; ebx = sample buffer ptr                                                  ;
  5693. ;                                                                          ;
  5694. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5695. proc init_for_play
  5696.   mov    [byte funk_info.trek_status],PLAY
  5697.   mov    [byte funk_info.sequence_ofs_old],0ffh
  5698.   mov    [byte funk_info.pattern_ofs2_old],0ffh
  5699.   mov    [byte funk_info.sequence_ofs],0
  5700.   mov    [byte funk_info.pattern_ofs],0
  5701.   mov    [byte funk_info.tempo],04h
  5702.   mov    [byte funk_info.tempo_count],0
  5703.   mov    [byte funk_info.master_volume],0fh
  5704.   call   find_pats_seqs
  5705.   lea    edi,[funk_chan1]
  5706.   mov    cl,8
  5707. @@clear_funk_chan:
  5708. ;─control system─────────────────
  5709.   mov    [byte edi+tfunk_chan.command],0fh
  5710.   mov    [byte edi+tfunk_chan.com_val],0
  5711.   mov    [byte edi+tfunk_chan.comspd_count],0
  5712.   mov    [byte edi+tfunk_chan.sample],3fh
  5713.   mov    [dword edi+tfunk_chan.start],0ffffffffh
  5714.   mov    [dword edi+tfunk_chan.length],100000h
  5715.   mov    [byte edi+tfunk_chan.funkctrl],0
  5716.   mov    [byte edi+tfunk_chan.port_type],0
  5717.   mov    [byte edi+tfunk_chan.sample_ofs_parm],08h
  5718.   mov    [byte edi+tfunk_chan.vib_waveform],0
  5719.   mov    [byte edi+tfunk_chan.vol_vib_waveform],0
  5720.   mov    [byte edi+tfunk_chan.balance],80h
  5721.   mov    [byte edi+tfunk_chan.retrig_limit],4
  5722.   mov    [byte edi+tfunk_chan.arp_speed],3
  5723. ;─note system────────────────────
  5724.   mov    [byte edi+tfunk_chan.note_command],0fh
  5725.   mov    [byte edi+tfunk_chan.note_com_val],0
  5726.   mov    [byte edi+tfunk_chan.note_comspd_count],0
  5727.   mov    [byte edi+tfunk_chan.note],03fh
  5728.   mov    [word edi+tfunk_chan.ifreq],0
  5729.   mov    [word edi+tfunk_chan.ifreq_vibrato],0
  5730.   mov    [word edi+tfunk_chan.ifreq_portdest],0
  5731.   mov    [dword edi+tfunk_chan.rfreq],0
  5732.   mov    [dword edi+tfunk_chan.rfreq_adjust],0
  5733.   mov    [dword edi+tfunk_chan.rfreq_portdest],0
  5734.   mov    [byte edi+tfunk_chan.vib_ptr],0
  5735.   mov    [byte edi+tfunk_chan.note_beat_count],0
  5736. ;─volume system──────────────────
  5737.   mov    [byte edi+tfunk_chan.volume_command],0fh
  5738.   mov    [byte edi+tfunk_chan.volume_com_val],0
  5739.   mov    [byte edi+tfunk_chan.volume_comspd_count],0
  5740.   mov    [byte edi+tfunk_chan.volume],0
  5741.   mov    [byte edi+tfunk_chan.volume_vibrato],0
  5742.   mov    [byte edi+tfunk_chan.volume_portdest],0
  5743.   mov    [byte edi+tfunk_chan.rvolume],0
  5744.   mov    [byte edi+tfunk_chan.vol_vib_ptr],0
  5745.   mov    [byte edi+tfunk_chan.volume_beat_count],0
  5746.  
  5747.   mov    [dword edi+tfunk_chan.CARD_sample_ptr],0
  5748.   mov    [dword edi+tfunk_chan.CARD_freq],0
  5749.   mov    [dword edi+tfunk_chan.CARD_freq_attract],0
  5750.   mov    [dword edi+tfunk_chan.CARD_volume],0
  5751.   add    edi,size tfunk_chan
  5752.   dec    cl
  5753.   jnz    @@clear_funk_chan
  5754.   call   resync_sample_ptrs
  5755.   mov    [byte funk_info.trek_status],STOP
  5756.   ret
  5757. endp
  5758.  
  5759. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5760. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5761. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5762. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5763. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5764. ;                                                                          ;
  5765. ; AUTODETECT CODE                                                          ;
  5766. ;                                                                          ;
  5767. ; process:                                                                 ;
  5768. ;                                                                          ;
  5769. ; a) it does PORT detection tests for the following cards (in order):      ;
  5770. ;      - PAS16                                                             ;
  5771. ;      - GUS CARD                                                          ;
  5772. ;      - Creative Labs cards                                               ;
  5773. ;                                                                          ;
  5774. ;    if a particular card is found, then the routines then determine IRQ,  ;
  5775. ;    and DMA settings of the card.                                         ;
  5776. ;                                                                          ;
  5777. ; PAS16: it first tests for a driver called "MVSOUND.SYS", which always    ;
  5778. ; resides with any PAS card. If it can't find the driver, then it          ;
  5779. ; assumes that the card isn't there. All information is obtained through   ;
  5780. ; this driver.                                                             ;
  5781. ; To my knowledge, most software will not work without this driver.        ;
  5782. ;                                                                          ;
  5783. ; GUS: AS far as i know, the ULTRASND= environment setting has been set    ;
  5784. ; for every single GUS card ever installed. It is assumed that every       ;
  5785. ; computer that has a GUS card will have ULTRASND= env. setting as well.   ;
  5786. ; DMA and IRQ information is extracted from this env setting. If it can't  ;
  5787. ; find it, then the detection routine will fail.                           ;
  5788. ;                                                                          ;
  5789. ; CT: After is has done a PORT test, it then determines the DSP version    ;
  5790. ; of the card. This will determine if it's a SB, SBPRO, SB16 etc. Once     ;
  5791. ; this is determined, it will go about searching for IRQ and DMA in the    ;
  5792. ; following way:                                                           ;
  5793. ;                                                                          ;
  5794. ; SB1.SB20,SBPRO,SBPRO2: The BLASTER= env. setting is searched for         ;
  5795. ; IRQ and DMA settings. If it can't find this enc setting, then the        ;
  5796. ; detection routine will fail.                                             ;
  5797. ;                                                                          ;
  5798. ; SB16 and AWE32: Because these cards have software configurable IRQ and   ;
  5799. ; DMA settings, the port status registers are read to determine these      ;
  5800. ; settings. The routines will also detect the POST address of the          ;
  5801. ; MPU-401 hardware.                                                        ;
  5802. ;                                                                          ;
  5803. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5804. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5805. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5806. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5807. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5808. ad_line1               db 13,10,13,10,"Detecting card: $"
  5809. ad_line2               db "Couldn't find IRQ?"
  5810. ad_enter               db 13,10,"$"
  5811. ad_line3               db "Couldn't find DMA?",13,10,"$"
  5812. ad_line4               db "Found IRQ: $"
  5813. ad_line5               db "Found DMA: $"
  5814. ad_line6               db "MPU-401 port found at: $"
  5815. ad_line7               db "300h",13,10,"$"
  5816. ad_line8               db "Searching BLASTER environment...",13,10,"$"
  5817. ad_line9               db "Corrupted environment settings...can't find settings.",13,10,"$"
  5818. ad_line10              db "Found MIDI IRQ: $"
  5819.  
  5820. str_card0              db "Creative Labs compatable card detected at port: 2"
  5821. str_card0_dig          db "10h",13,10,"$"
  5822. str_card1              db "SoundBlaster 1.X$"
  5823. str_card2              db "SoundBlaster 2.0$"
  5824. str_card3              db "SoundBlaster PRO$"
  5825. str_card4              db "SoundBlaster 16$"
  5826. str_card5              db "Gravis Ultrasnd card detected at port: 2"
  5827. str_card5_dig          db "10h",13,10,"$"
  5828. str_card19             db "not"
  5829. str_card20             db " detected.",13,10,"$"
  5830.  
  5831. str_sel1               db "Multipal cards detected. Please select one of the following.",13,10,13,10,"$"
  5832.  
  5833. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5834. ;                                                                          ;
  5835. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5836. ; eax= number
  5837. proc print_dec
  5838.   mov    esi,4*2
  5839.   mov    ecx,eax
  5840. @@dec83:
  5841.   mov    eax,ecx
  5842.   xor    edx,edx
  5843.   div    [dword esi+@@Dec_divider]
  5844.   mov    ecx,edx
  5845.   add    al,'0'
  5846.  
  5847.   mov    ah,0EH
  5848.   mov    bl,7
  5849.   int    10H
  5850.  
  5851.   sub    esi,4
  5852.   jge    @@dec83
  5853.   ret
  5854. @@dec_divider:
  5855.   dd 1,10
  5856. endp
  5857.  
  5858. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5859. ;                                                                          ;
  5860. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5861. proc display_irq_dma
  5862.   mov    edx,offset ad_line4
  5863.   mov    ah,9
  5864.   int    21h
  5865.   movzx  eax,[byte init_settings.IRQ_no]
  5866.   call   print_dec
  5867.   mov    edx,offset ad_enter
  5868.   mov    ah,9
  5869.   int    21h
  5870.   mov    edx,offset ad_line5
  5871.   mov    ah,9
  5872.   int    21h
  5873.   movzx  eax,[byte init_settings.DMA_no]
  5874.   call   print_dec
  5875.   mov    edx,offset ad_enter
  5876.   mov    ah,9
  5877.   int    21h
  5878.   ret
  5879. endp
  5880.  
  5881. proc CT_environment
  5882.   mov    edx,offset ad_line8
  5883.   mov    ah,9
  5884.   int    21h
  5885.   push   es
  5886.   mov    ax,0EE02h              ; get DOS32 address info
  5887.   int    31h                    ; returns Environment address in EDI
  5888.   mov    ecx,10000h
  5889. @@SrchEnvrLoop:
  5890.   lea    esi,[@@blaster_string]
  5891.   mov    ecx,8
  5892.   repe   cmpsb
  5893.   jne    @@No_SBstring
  5894.   dec    edi
  5895.   mov    ebx,edi
  5896.   xor    ecx,ecx
  5897. @@s_irq:
  5898.   cmp    [byte ebx],"I"
  5899.   je     @@s_irq_exit
  5900.   inc    ebx
  5901.   dec    cx
  5902.   jnz    @@s_irq
  5903.   jmp    @@No_BLASTER
  5904. @@s_irq_exit:
  5905.   mov    al,[byte ebx+1]
  5906.   sub    al,"0"
  5907.   jnz    @@set_irq
  5908.   mov    al,10
  5909.   xor    ecx,ecx
  5910. @@set_irq:
  5911.   mov    [byte init_settings.IRQ_no],al
  5912.   mov    ebx,edi
  5913.   dec    cx
  5914. @@s_dma:
  5915.   cmp    [byte ebx],"D"
  5916.   je     @@s_dma_exit
  5917.   inc    ebx
  5918.   dec    cx
  5919.   jnz    @@s_dma
  5920. @@s_dma_exit:
  5921.   mov    al,[byte ebx+1]
  5922.   sub    al,"0"
  5923.   mov    [byte init_settings.DMA_no],al
  5924.   call   display_irq_dma
  5925.   pop    es
  5926.   ret
  5927. @@No_SBstring:
  5928.   xor    al,al
  5929.   mov    ecx,400h
  5930.   repne  scasb
  5931.   and    ecx,ecx
  5932.   jz     @@No_BLASTER
  5933.   cmp    [byte es:edi],0
  5934.   jnz    @@SrchEnvrLoop
  5935. @@No_BLASTER:
  5936.   mov    edx,offset ad_line9
  5937.   mov    ah,9
  5938.   int    21h
  5939.   pop    es
  5940.   mov    [byte init_settings.card_type],0ffh
  5941.   ret
  5942. @@blaster_string:
  5943.   db     "BLASTER="
  5944. endp
  5945.  
  5946. proc CT_detect
  5947.   mov    [dword init_settings.PORT_no],210h
  5948.   call   SB_detect_port
  5949.   jnc    @@detected
  5950.   mov    [dword init_settings.PORT_no],220h
  5951.   call   SB_detect_port
  5952.   jnc    @@detected
  5953.   mov    [dword init_settings.PORT_no],230h
  5954.   call   SB_detect_port
  5955.   jnc    @@detected
  5956.   mov    [dword init_settings.PORT_no],240h
  5957.   call   SB_detect_port
  5958.   jnc    @@detected
  5959.   mov    [dword init_settings.PORT_no],250h
  5960.   call   SB_detect_port
  5961.   jnc    @@detected
  5962.   mov    [dword init_settings.PORT_no],260h
  5963.   call   SB_detect_port
  5964.   jnc    @@detected
  5965.   mov    [dword init_settings.PORT_no],280h
  5966.   call   SB_detect_port
  5967.   jnc    @@detected
  5968.   stc
  5969.   ret
  5970. @@detected:
  5971.   mov    eax,[dword init_settings.PORT_no]
  5972.   sub    eax,210h
  5973.   shr    eax,4
  5974.   add    [byte str_card0_dig],al
  5975.   mov    edx,offset str_card0
  5976.   mov    ah,9
  5977.   int    21h
  5978.   mov    al,0e1h
  5979.   call   SB_write_dac
  5980.   call   SB_read_dac
  5981.   mov    ah,al
  5982.   call   SB_read_dac
  5983.   cmp    ah,1
  5984.   je     @@sb15
  5985.   cmp    ah,2
  5986.   je     @@sb20
  5987.   cmp    ah,3
  5988.   je     @@sbpro
  5989.   cmp    ah,4
  5990.   jae    @@sb16
  5991.   ret
  5992. @@sb15:
  5993. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5994.   mov    [byte init_settings.card_type],SB15EM_CARD
  5995.   mov    edx,offset str_card1
  5996.   mov    ah,9
  5997.   int    21h
  5998.   mov    edx,offset str_card20
  5999.   mov    ah,9
  6000.   int    21h
  6001.   call   CT_environment
  6002.   jmp    @@done
  6003.   ret
  6004. @@sb20:
  6005. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6006.   cmp    al,0
  6007.   ja     @@sb202
  6008.   ret
  6009. @@sb202:
  6010.   mov    [byte init_settings.card_type],SB_CARD
  6011.   mov    edx,offset str_card2
  6012.   mov    ah,9
  6013.   int    21h
  6014.   mov    edx,offset str_card20
  6015.   mov    ah,9
  6016.   int    21h
  6017.   call   CT_environment
  6018.   jmp    @@done
  6019.   ret
  6020. @@sbpro:
  6021. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6022.   mov    [byte init_settings.card_type],SBPRO_CARD
  6023.   mov    edx,offset str_card3
  6024.   mov    ah,9
  6025.   int    21h
  6026.   mov    edx,offset str_card20
  6027.   mov    ah,9
  6028.   int    21h
  6029.   call   CT_environment
  6030.   jmp    @@done
  6031.   ret
  6032. @@sb16:
  6033. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6034.   mov    [byte init_settings.card_type],SB16_CARD
  6035.   mov    edx,offset str_card4
  6036.   mov    ah,9
  6037.   int    21h
  6038.   mov    edx,offset str_card20
  6039.   mov    ah,9
  6040.   int    21h
  6041.  
  6042.   mov    al,80h                                     ; get IRQ
  6043.   call   SB_read_mixer
  6044.   test   al,1
  6045.   jne    @@sb16_irq2
  6046.   test   al,2
  6047.   jne    @@sb16_irq5
  6048.   test   al,4
  6049.   jne    @@sb16_irq7
  6050.   test   al,8
  6051.   jne    @@sb16_irq10
  6052.   mov    [byte init_settings.card_type],0ffh
  6053.   mov    edx,offset ad_line2
  6054.   mov    ah,9
  6055.   int    21h
  6056.   jmp    @@done
  6057. @@sb16_irq2:
  6058.   mov    [byte init_settings.IRQ_no],2
  6059.   jmp    @@sb16_get_dma
  6060. @@sb16_irq5:
  6061.   mov    [byte init_settings.IRQ_no],5
  6062.   jmp    @@sb16_get_dma
  6063. @@sb16_irq7:
  6064.   mov    [byte init_settings.IRQ_no],7
  6065.   jmp    @@sb16_get_dma
  6066. @@sb16_irq10:
  6067.   mov    [byte init_settings.IRQ_no],10
  6068. @@sb16_get_dma:
  6069.   mov    al,81h                                     ; get DMA
  6070.   call   SB_read_mixer
  6071.   test   al,32
  6072.   jne    @@sb16_dma5
  6073.   test   al,64
  6074.   jne    @@sb16_dma6
  6075.   test   al,128
  6076.   jne    @@sb16_dma7
  6077.   mov    [byte init_settings.card_type],0ffh
  6078.   mov    edx,offset ad_line3
  6079.   mov    ah,9
  6080.   int    21h
  6081.   jmp    @@done
  6082. @@sb16_dma5:
  6083.   mov    [byte init_settings.DMA_no],5
  6084.   jmp    @@display_sb16
  6085. @@sb16_dma6:
  6086.   mov    [byte init_settings.DMA_no],6
  6087.   jmp    @@display_sb16
  6088. @@sb16_dma7:
  6089.   mov    [byte init_settings.DMA_no],7
  6090. @@display_sb16:
  6091.   call   display_irq_dma
  6092.   mov    edx,offset ad_line6
  6093.   mov    ah,9
  6094.   int    21h
  6095.   mov    [MPU_addr],300h
  6096.   call   MPU401_Reset
  6097.   or     al,al
  6098.   jz     @@mpu_found
  6099.   mov    [MPU_addr],330h
  6100.   call   MPU401_Reset
  6101.   or     al,al
  6102.   jnz    @@mpu_notfound
  6103. @@mpu_found:
  6104.   mov    eax,[MPU_addr]
  6105.   sub    eax,300h
  6106.   shr    eax,4
  6107.   add    [byte ad_line7+1],al
  6108.   mov    edx,offset ad_line7
  6109.   mov    ah,9
  6110.   int    21h
  6111.   jmp    @@done
  6112. @@mpu_notfound:
  6113.   mov    edx,offset str_card19
  6114.   mov    ah,9
  6115.   int    21h
  6116. @@done:
  6117.   ret
  6118. endp
  6119. endp
  6120.  
  6121. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6122. ;                                                                          ;
  6123. ; cy = not detected                                                        ;
  6124. ; cn = detected                                                            ;
  6125. ;                                                                          ;
  6126. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6127. proc GUS_environment
  6128.   push   es
  6129.   mov    ax,0EE02h              ; get DOS32 address info
  6130.   int    31h                    ; returns Environment address in EDI
  6131.   cld
  6132.   mov    ecx,10000h
  6133. @@SrchEnvrLoop:
  6134.   lea    esi,[@@ultrasnd_string]
  6135.   mov    ecx,9
  6136.   repe   cmpsb
  6137.   jne    @@No_GUSstring
  6138.   mov    [byte init_settings.card_type],GUS_FIXB_CARD
  6139.   mov    ebx,[es:edi]                                  ;OK, Found the string 'ULTRASND='
  6140.   mov    eax,ebx                                       ;check for the valid paramters
  6141.   and    ebx,0ffff00ffh
  6142.   cmp    ebx,02C300032h                                ;'2x0,'
  6143.   jne    @@No_ULTRASND
  6144.   shr    eax,8
  6145.   call   @@get_digit                                   ;eeax = char digit in al
  6146.   mov    edx,eax                                       ;load port address
  6147.   shl    edx,4
  6148.   add    edx,200h
  6149.   sub    al,1h                                         ;port must be between  210h .. 260h
  6150.   cmp    al,5h
  6151.   ja     @@No_ULTRASND
  6152.   mov    [dword init_settings.PORT_no],edx
  6153.   add    edi,4
  6154.   xor    ecx,ecx
  6155.   movzx  eax,[byte es:edi]
  6156.   call   @@get_digit
  6157.   cmp    [byte eax+GUS_dma_table],0
  6158.   je     @@No_ULTRASND
  6159.   mov    [byte init_settings.DMA_no],al                ;get playback DMA
  6160.   inc    edi
  6161.   cmp    [byte es:edi],','
  6162.   jne    @@No_ULTRASND
  6163.   inc    edi
  6164.   movzx  eax,[byte es:edi]
  6165.   call   @@get_digit
  6166.   cmp    [byte eax+GUS_dma_table],0
  6167.   je     @@No_ULTRASND
  6168.   mov    [byte init_settings.DMA_no2],al                ;DMA record channel
  6169.   inc    edi
  6170.   cmp    [byte es:edi],','
  6171.   jne    @@No_ULTRASND
  6172.   xor    ebx,ebx
  6173.   inc    edi
  6174.   cmp    [byte es:edi],'1'
  6175.   jne    @@J61
  6176.   mov    bl,10
  6177.   inc    edi
  6178. @@J61:
  6179.   mov    eax,[es:edi]
  6180.   call   @@get_digit
  6181.   add    al,bl
  6182.   cmp    al,15
  6183.   ja     @@No_ULTRASND
  6184.   cmp    [byte eax+GUS_irq_table],0
  6185.   je     @@No_ULTRASND
  6186.   mov    BL,AL
  6187.   mov    [byte init_settings.IRQ_no],al
  6188.   inc    edi
  6189.   cmp    [byte es:edi],','
  6190.   jne    @@No_ULTRASND
  6191.   inc    edi
  6192.   cmp    [byte es:edi],'1'
  6193.   jne    @@J62
  6194.   mov    BH,10
  6195.   inc    edi
  6196. @@J62:
  6197.   mov    al,[es:edi]
  6198.   call   @@get_digit
  6199.   add    al,bh
  6200.   cmp    al,15
  6201.   ja     @@No_ULTRASND
  6202.   cmp    [byte eax+GUS_irq_table],0
  6203.   je     @@No_ULTRASND
  6204.   mov    [byte init_settings.IRQ_no2],al              ;MIDI irq number
  6205.   inc    edi
  6206.   cmp    [byte es:edi],','
  6207.   je     @@got_it
  6208.   cmp    [byte es:edi],' '
  6209.   je     @@got_it
  6210.   cmp    [byte es:edi],0
  6211.   jne    @@No_ULTRASND
  6212. @@got_it:
  6213.   pop    es
  6214.  
  6215.   mov    edx,offset ad_line4
  6216.   mov    ah,9
  6217.   int    21h
  6218.   movzx  eax,[byte init_settings.IRQ_no]
  6219.   call   print_dec
  6220.   mov    edx,offset ad_enter
  6221.   mov    ah,9
  6222.   int    21h
  6223.  
  6224.  
  6225.   mov    edx,offset ad_line10
  6226.   mov    ah,9
  6227.   int    21h
  6228.   movzx  eax,[byte init_settings.IRQ_no2]
  6229.   call   print_dec
  6230.   mov    edx,offset ad_enter
  6231.   mov    ah,9
  6232.   int    21h
  6233.   ret
  6234. @@No_GUSstring:
  6235.   mov    al,0                                          ; scan environment for next ZERO
  6236.   mov    ecx,400h
  6237.   repne  scasb
  6238.   or     ecx,ecx
  6239.   jz     @@No_ULTRASND
  6240.   cmp    [byte es:edi],0                               ; if double zeros then finished
  6241.   jnz    @@SrchEnvrLoop
  6242. @@No_ULTRASND:
  6243.   pop    es
  6244.   mov    edx,offset ad_line9
  6245.   mov    ah,9
  6246.   int    21h
  6247.   mov    [byte init_settings.card_type],0ffh
  6248.   ret
  6249. @@get_digit:
  6250.   sub    al,'0'
  6251.   jc @@No_digi
  6252.   cmp    al,9
  6253.   ja @@No_digi
  6254.   movzx  eax,al
  6255.   ret    0
  6256. @@No_digi:
  6257.   add    esp,4                                         ; ignore pushed EIP
  6258.   stc
  6259.   pop    es
  6260.   ret
  6261. @@ULTRASND_string:
  6262.   db     'ULTRASND='
  6263. endp
  6264.  
  6265. proc GUS_detect
  6266.   mov    [dword init_settings.PORT_no],210h
  6267.   call   GUS_detect_port
  6268.   jnc    @@detected
  6269.   mov    [dword init_settings.PORT_no],220h
  6270.   call   GUS_detect_port
  6271.   jnc    @@detected
  6272.   mov    [dword init_settings.PORT_no],230h
  6273.   call   GUS_detect_port
  6274.   jnc    @@detected
  6275.   mov    [dword init_settings.PORT_no],240h
  6276.   call   GUS_detect_port
  6277.   jnc    @@detected
  6278.   mov    [dword init_settings.PORT_no],250h
  6279.   call   GUS_detect_port
  6280.   jnc    @@detected
  6281.   mov    [dword init_settings.PORT_no],260h
  6282.   call   GUS_detect_port
  6283.   jnc    @@detected
  6284.   ret
  6285. proc GUS_detect_port
  6286.   mov    [dword gus_base],0
  6287.   mov    [dword gus_status],6
  6288.   mov    [dword gus_timercontrol],8
  6289.   mov    [dword gus_timerdata],9
  6290.   mov    [dword gus_irqdmacontrol],0bh
  6291.   mov    [dword gus_midictrl],100h
  6292.   mov    [dword gus_mididata],101h
  6293.   mov    [dword gus_voice],102h
  6294.   mov    [dword gus_command],103h
  6295.   mov    [dword gus_datalo],104h
  6296.   mov    [dword gus_datahi],105h
  6297.   mov    [dword gus_GF1_status],106h
  6298.   mov    [dword gus_dram],107h
  6299.   mov    eax,[dword init_settings.PORT_no]
  6300.   add    [dword gus_base],eax
  6301.   add    [dword gus_Status],eax
  6302.   add    [dword gus_timercontrol],eax
  6303.   add    [dword gus_timerdata],eax
  6304.   add    [dword gus_irqdmacontrol],eax
  6305.   add    [dword gus_midictrl],eax
  6306.   add    [dword gus_mididata],eax
  6307.   add    [dword gus_voice],eax
  6308.   add    [dword gus_Command],eax
  6309.   add    [dword gus_DataLo],eax
  6310.   add    [dword gus_DataHi],eax
  6311.   add    [dword gus_GF1_status],eax
  6312.   add    [dword gus_dram],eax
  6313.   lea    eax,[GUSi_freq_convert]
  6314.   mov    [dword CARD_freq_convert],eax
  6315.   lea    eax,[GUSi_volume_convert]
  6316.   mov    [dword CARD_volume_convert],eax
  6317.   mov    edx,[dword gus_command]
  6318.   mov    al,4Ch
  6319.   out    dx,al
  6320.   add    edx,2
  6321.   xor    al,al
  6322.   out    dx,al
  6323.   call   gus_Delay
  6324.   call   gus_Delay
  6325.   mov    edx,[dword gus_command]
  6326.   mov    al,4Ch
  6327.   out    dx,al
  6328.   add    edx,2
  6329.   mov    al,1
  6330.   out    dx,al
  6331.   mov    al,0AAh
  6332.   xor    edi,edi
  6333.   call   gus_mem_out
  6334.   mov    edi,100h
  6335.   mov    al,55h
  6336.   call   gus_mem_out
  6337.   xor    esi,esi
  6338.   call   gus_mem_in
  6339.   push   eax
  6340.   mov    edx,[dword gus_command]
  6341.   mov    al,4Ch
  6342.   out    dx,al
  6343.   add    edx,2
  6344.   mov    al,1
  6345.   out    dx,al
  6346.   pop    eax
  6347.   cmp    al,0AAh
  6348.   jnz    @@Nope
  6349.   clc
  6350.   ret
  6351. @@Nope:
  6352.   stc
  6353.   ret
  6354. endp
  6355. @@detected:
  6356.   mov    eax,[dword init_settings.PORT_no]
  6357.   sub    eax,210h
  6358.   shr    eax,4
  6359.   add    [byte str_card5_dig],al
  6360.   mov    edx,offset str_card5
  6361.   mov    ah,9
  6362.   int    21h
  6363.   call   GUS_environment
  6364.   cmp    [byte init_settings.card_type],0ffh
  6365.   je     @@ignore
  6366.   call   GUS_find_mem
  6367. @@ignore:
  6368.   ret
  6369. endp
  6370.  
  6371. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6372. ;                                                                          ;
  6373. ; cy = not detected                                                        ;
  6374. ; cn = detected                                                            ;
  6375. ;                                                                          ;
  6376. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6377. proc PAS_detect
  6378.   xor    edi,edi
  6379.   call   mvGetHWVersion
  6380.   jnc    @@detected
  6381.   mov    [byte init_settings.card_type],0ffh
  6382.   ret
  6383. @@detected:
  6384.   mov    [byte init_settings.card_type],PAS16_CARD
  6385.   call   MVInitStatePtr
  6386.   ret
  6387. endp
  6388.  
  6389. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6390. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6391. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6392. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6393. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6394. ;                                                                         ;
  6395. ; Interface routines                                                      ;
  6396. ;                                                                         ;
  6397. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6398. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6399. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6400. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6401. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6402.  
  6403. ;bl = card override: 0=PAS,1=GUS,2=CT card
  6404. proc FNK_autodetect
  6405.   cmp    bl,1
  6406.   je     @@gus_d
  6407.   cmp    bl,2
  6408.   je     @@ct_d
  6409.  
  6410.   call   PAS_detect
  6411.   cmp    [byte init_settings.card_type],0ffh
  6412.   jne    @@card_detected
  6413. @@gus_d:
  6414.   call   GUS_detect
  6415.   cmp    [byte init_settings.card_type],0ffh
  6416.   jne    @@card_detected
  6417. @@ct_d:
  6418.   call   CT_detect
  6419.   cmp    [byte init_settings.card_type],0ffh
  6420.   jne    @@card_detected
  6421.   cmp    [byte init_settings.card_type],0ffh
  6422.   stc
  6423.   ret
  6424. @@card_detected:
  6425.   clc
  6426.   ret
  6427. endp
  6428.  
  6429. ;eax = DMA buffer ptr
  6430. proc FNK_card_init
  6431.   add    [dword DAC_mix_buffer],eax
  6432.   add    [dword DAC_mix_buffer_right],eax
  6433.   add    [dword DAC_mix_buffer2],eax
  6434.   push   eax
  6435.   mov    ax,0EE02h
  6436.   int    31h
  6437.   neg    ebx
  6438.   pop    eax
  6439.   sub    eax,ebx
  6440.   add    [dword DAC_PHYSICAL_PAGE],eax
  6441.   mov    edi,[dword DAC_mix_buffer]                    ; clear buffers
  6442.   mov    ecx,1000h/2
  6443.   mov    eax,8000h
  6444.   rep    stosw
  6445.   mov    edi,[dword DAC_mix_buffer_right]              ; clear buffers
  6446.   mov    ecx,1000h/2
  6447.   mov    eax,8000h
  6448.   rep    stosw
  6449.   mov    ecx,2000h
  6450.   mov    edi,[dword DAC_mix_buffer2]
  6451.   mov    al,80h
  6452.   rep    stosb
  6453.   cmp    [byte init_settings.card_type],SB_CARD
  6454.   je     @@sb08
  6455.   cmp    [byte init_settings.card_type],SBPRO_CARD
  6456.   je     @@sb08
  6457.   cmp    [byte init_settings.card_type],GUS_VARB_CARD
  6458.   je     @@gus
  6459.   cmp    [byte init_settings.card_type],SB15EM_CARD
  6460.   je     @@sb08
  6461.   cmp    [byte init_settings.card_type],SB16_CARD
  6462.   je     @@sb16
  6463.   cmp    [byte init_settings.card_type],GUS_FIXB_CARD
  6464.   je     @@gus
  6465.   cmp    [byte init_settings.card_type],PAS16_CARD
  6466.   je     @@pas_family
  6467.   ret
  6468. @@sb08:
  6469.   call   SB08_init
  6470.   jc     @@sb08_e
  6471.   call   SB08_deinit
  6472.   call   SB08_init
  6473. @@sb08_e:
  6474.   ret
  6475. @@sb16:
  6476.   mov    ecx,2000h/2
  6477.   mov    edi,[dword DAC_mix_buffer2]
  6478.   xor    eax,eax
  6479.   rep    stosw
  6480.   call   SB16_init
  6481.   ret
  6482. @@gus:
  6483.   call   GUS_init
  6484.   ret
  6485. @@pas_family:
  6486.   mov    ecx,2000h/2
  6487.   mov    edi,[dword DAC_mix_buffer2]
  6488.   xor    eax,eax
  6489.   rep    stosw
  6490.   call   InitPCM
  6491.   call   StartPlaying
  6492.   ret
  6493. endp
  6494.  
  6495. proc FNK_card_deinit
  6496.   cmp    [byte init_settings.card_type],SB_CARD
  6497.   je     @@sb08
  6498.   cmp    [byte init_settings.card_type],SBPRO_CARD
  6499.   je     @@sb08
  6500.   cmp    [byte init_settings.card_type],GUS_VARB_CARD
  6501.   je     @@gus
  6502.   cmp    [byte init_settings.card_type],SB15EM_CARD
  6503.   je     @@sb08
  6504.   cmp    [byte init_settings.card_type],SB16_CARD
  6505.   je     @@sb16
  6506.   cmp    [byte init_settings.card_type],GUS_FIXB_CARD
  6507.   je     @@gus
  6508.   cmp    [byte init_settings.card_type],PAS16_CARD
  6509.   je     @@pas_family
  6510.   ret
  6511. @@sb08:
  6512.   call   SB08_deinit
  6513.   ret
  6514. @@sb16:
  6515.   call   SB16_deinit
  6516.   ret
  6517. @@gus:
  6518.   call   GUS_deinit
  6519.   ret
  6520. @@pas_family:
  6521.   call   StopPCM
  6522.   ret
  6523. endp
  6524.  
  6525. ;eax = funksong pointer
  6526. proc FNK_setup_player
  6527.   mov    [funk_hr_ptr],eax
  6528.   call   find_pats_seqs
  6529.   movzx  ecx,[byte funk_info.no_of_patterns]
  6530.   mov    eax,600h
  6531.   mul    ecx
  6532.   mov    ebx,size tfunk_hr
  6533.   add    ebx,eax
  6534.   mov    eax,[funk_hr_ptr]
  6535.   add    ebx,eax
  6536.   mov    [funk_sd_ptr],ebx
  6537.   call   init_for_play
  6538.   call   upload_exteral_data
  6539.   ret
  6540. endp
  6541.  
  6542. proc FNK_PLAY
  6543.   mov    [byte funk_info.trek_status],PLAY
  6544.   ret
  6545. endp
  6546.  
  6547. proc FNK_STOP
  6548.   mov    [byte funk_info.trek_status],STOP
  6549.   ret
  6550. endp
  6551.  
  6552. proc FNK_teststatus
  6553.   cmp    [byte funk_info.trek_status],PLAY
  6554.   ret
  6555. endp
  6556.  
  6557. ;al = master volume (0-f)
  6558. proc FNK_set_mvolume
  6559.   mov    [byte funk_info.master_volume],al
  6560.   ret
  6561. endp
  6562.  
  6563. ;returns al = master volume (0-f)
  6564. proc FNK_get_mvolume
  6565.   mov    al,[byte funk_info.master_volume]
  6566.   ret
  6567. endp
  6568.