home *** CD-ROM | disk | FTP | other *** search
/ Sound, Music & MIDI Collection 2 / SMMVOL2.bin / DOS / SS_PLAY / FUNK106.ZIP / FUNK_S.ZIP / FUNKLITE.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-05-16  |  201.2 KB  |  6,321 lines

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