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

  1. ;=1.08a=;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;                                                                          ;
  3. ; FunkTracker - By Super Real Darwin!                                      ;
  4. ;               Designed & Coded By Jason Nunn (JsNO)                      ;
  5. ;                                                                          ;
  6. ; Thanks go to Tom Verbeure/Synergy as he composed a faster frequency      ;
  7. ; transformer, making my DAC routines alot tighter. On ya mate :).         ;
  8. ; ...and Adam's little fix ups etc.                                        ;
  9. ;                                                                          ;
  10. ; Snail: 32 Rothdale Road, Moil, Darwin, NT, 0810, Australia               ;
  11. ; Email: jsno@amigar.apana.org.au                                          ;
  12. ; BBS  : ■ Amiga Retreat BBS                                               ;
  13. ;          (089)451516  (3:850/105)                                        ;
  14. ;                                                                          ;
  15. ; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;
  16. ; RUNNING IN PROTECTED MODE USING DOS32 By Adam Seychell                   ;
  17. ; Snail: 16 Avion Place, Westmeadows, VIC, 3049, AUSTRALIA                 ;
  18. ; Email: s921880@minyos.xx.rmit.edu.au                                     ;
  19. ; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;
  20. ;                                                                          ;
  21. ; This code is a byproduct of our productions, and have given it to the    ;
  22. ; public domain condition free. Please fill free to use it in your         ;
  23. ; productions.                                                             ;
  24. ;                                                                          ;
  25. ;=====================================================================     ;
  26. ; EDITOR CODE                                                              ;
  27. ;                                                                          ;
  28. ; At the application level, this is the editor of funktracker. It does     ;
  29. ; everything accept (physically) play the music :).                        ;
  30. ;                                                                          ;
  31. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  32. ideal
  33. p386
  34. model flat
  35. stack 2048
  36. codeseg
  37.  
  38. extrn debug            : near
  39. Zero_Addr              dd ?
  40. Environment_Address    dd ?
  41. PSP_Address            dd ?
  42. _0B8000h               dd ?
  43.  
  44. include "funklite.asm"
  45.  
  46. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  47. ;                                                                          ;
  48. ; editor data                                                              ;
  49. ;                                                                          ;
  50. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  51.  
  52. kb_up                 = 4800h  ;just keyboards equates.
  53. kb_down               = 5000h
  54. kb_left               = 4B00h
  55. kb_right              = 4D00h
  56. kb_home               = 4700h
  57. kb_end                = 4F00h
  58. kb_f1                 = 3B00h
  59. kb_f2                 = 3C00h
  60. kb_f3                 = 3D00h
  61. kb_f4                 = 3E00h
  62. kb_f5                 = 3F00h
  63. kb_altf5              = 6c00h
  64. kb_f6                 = 4000h
  65. kb_altf6              = 6d00h
  66. kb_f7                 = 4100h
  67. kb_f8                 = 4200h
  68. kb_f9                 = 4300h
  69. kb_f10                = 4400h
  70. kb_pageup             = 4900h
  71. kb_pagedn             = 5100h
  72. kb_insert             = 5200h
  73. kb_delete             = 5300h
  74. kb_altc               = 2e00h
  75. kb_altv               = 2f00h
  76. kb_altb               = 3000h
  77. kb_alte               = 1200h
  78. kb_altx               = 2d00h
  79. kb_altn               = 3100h
  80. kb_altm               = 3200h
  81. kb_alto               = 1800h
  82. kb_altz               = 2c00h
  83. kb_alts               = 1f00h
  84. kb_altd               = 2000h
  85. kb_altk               = 2500h
  86. kb_altq               = 1000h
  87. kb_alth               = 2300h
  88. kb_altt               = 1400h
  89.  
  90. nibble_display        db "0123456789ABCDEF"
  91. note_display          db "C-1C#1D-1D#1E-1F-1F#1G-1G#1A-1A#1B-1"
  92.                       db "C-2C#2D-2D#2E-2F-2F#2G-2G#2A-2A#2B-2"
  93.                       db "C-3C#3D-3D#3E-3F-3F#3G-3G#3A-3A#3B-3"
  94.                       db "C-4C#4D-4D#4E-4F-4F#4G-4G#4A-4A#4B-4"
  95.                       db "C-5C#5D-5D#5E-5F-5F#5G-5G#5A-5A#5B-5"
  96.                       db "???RLO■■■   "
  97. file_search_all       db "*.*",0
  98. file_search_funk      db "*.FNK",0
  99. file_search_wav       db "*.WAV",0
  100. file_search_snd       db "*.SND",0
  101. file_temp             db "\{funky}.tmp"
  102. numread               dd ?
  103. file_handle_funk      dd ?
  104. file_handle_funk2     dd ?
  105.  
  106. edit_mode             db 0
  107. pat_number            db 0
  108. pat_real              db 0
  109. pat_hl                db 0
  110. pat_chan              db 0
  111. pat_old_hl            db 0
  112. pat_old_chan          db 0
  113. ;;;;;;
  114. sel_flag              db 0
  115. sel_area_pattern      dw 0
  116. sel_area_chan1        db 0
  117. sel_area_chan2        db 0
  118. sel_area_trek1        db 0
  119. sel_area_trek2        db 0
  120. temp_pattern          db 600h dup(?)
  121. copied_flag           db 0
  122. copied_area_chan1     db 0
  123. copied_area_chan2     db 0
  124. copied_area_trek1     db 0
  125. copied_area_trek2     db 0
  126. ;;;;;;
  127. sam_real              db 0
  128. sam_hl                db 0
  129. sam_col               db 0
  130. note                  db 0
  131. octave                db 0
  132. MIDI_quantise         db 0
  133. seq_real              db 0
  134. seq_hl                db 0
  135. fdir_real             dw 0
  136. fdir_hl               db 0
  137. fdir_length           dw 0
  138. song_name             db "NEW_SONG.FNK",0
  139. initial_dir           db 80 dup(0)
  140. song_dir              db 80 dup(0)
  141. sample_dir            db 80 dup(0)
  142. trakplay_type         db ?
  143.  
  144. key1_map              db 0,160,160,160,160,160,255
  145. key2_map              db 2,160,160,160,255
  146. key3_map              db 4,160,160,160,158,2,158,2,255
  147. key4_map              db 6,160,160,160,255
  148. key5_map              db 8,160,160,160,158,2,158,2,255
  149. key6_map              db 10,160,160,160,160,160,255
  150. key7_map              db 12,160,160,160,255
  151. key8_map              db 14,160,160,160,158,2,158,2,255
  152. key9_map              db 16,160,160,160,255
  153. keya_map              db 18,160,160,160,158,2,158,2,255
  154. keyb_map              db 20,160,160,160,255
  155. keyc_map              db 22,160,160,160,158,2,158,2,255
  156.  
  157. dis_keyboard_map:     dd  key1_map, key2_map, key3_map, key4_map, key5_map
  158.                       dd  key6_map, key7_map, key8_map, key9_map, keya_map
  159.                       dd  keyb_map, keyc_map
  160.  
  161. main_screen:
  162. include "main_sc.asm"
  163. main_screen_size      = $-main_screen
  164.  
  165. pe_screen:
  166. include "mode_pe.asm"
  167. pe_screen_size        = $-pe_screen
  168.  
  169. se_screen:
  170. include "mode_se.asm"
  171. se_screen_size        = $-se_screen
  172.  
  173. trakd_screen:
  174. include "mode_d.asm"
  175. trakd_screen_size     = $-trakd_screen
  176.  
  177. trakp_screen:
  178. include "mode_ply.asm"
  179. trakp_screen_size     = $-trakp_screen
  180.  
  181. modefile_screen:
  182. include "modefile.asm"
  183. modefile_screen_size  = $-modefile_screen
  184.  
  185. comms_screen:
  186. include "comms.asm"
  187. comms_screen_size     = $-comms_screen
  188.  
  189. help_screen:
  190. include "help.asm"
  191. help_screen_size      = $-help_screen
  192.  
  193. end_screen:
  194. include "end.asm"
  195. end_screen_size       = $-end_screen
  196.  
  197. splash_screen:
  198. include "splash.asm"
  199.  
  200. resample_window:
  201. include "resample.asm"
  202.  
  203. font_data:
  204. include "funkfont.asm"
  205.  
  206. struc tdta
  207.   reserved            db 21 dup(?)
  208.   attr                db ?
  209.   time                dw ?
  210.   date                dw ?
  211.   filesize            dd ?
  212.   fname               db 13 dup(?)
  213. ends
  214.  
  215. struc tfdirectory
  216.   attr                db ?
  217.   fname               db 13 dup(?)
  218. ends
  219. fdir_max_length       = 3000
  220. fdirectory_buffer     dd ?
  221. funk_dma_buffer_addr  dd ?
  222. fade_palette_buf      db 64*3 dup(?)
  223.  
  224. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  225. ;                                                                         ;
  226. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  227. proc key_pressed2
  228.   push   esi
  229.   mov    esi,[Zero_Addr]
  230.   add    esi,41ah
  231.   mov    ax,[esi]
  232.   cmp    ax,[word esi+2]
  233.   jne    @@l
  234.   pop    esi
  235.   clc
  236.   ret
  237. @@l:
  238.   movzx  eax,ax
  239.   add    eax,400h
  240.   add    eax,[Zero_Addr]
  241.   mov    ax,[word eax]
  242.   pop    esi
  243.   stc
  244.   ret
  245. endp
  246.  
  247. proc get_key
  248. @@l:
  249.   call   key_pressed2
  250.   jnc    @@l
  251.   mov    eax,0
  252.   int    16h
  253.   ret
  254. endp
  255.  
  256. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  257. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  258. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  259. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  260. ;                                                                          ;
  261. ;                                                                          ;
  262. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  263. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  264. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  265. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  266. MACRO @WaitVert
  267. LOCAL    @@VR
  268.   mov    edx,3dah
  269. @@VR:
  270.   in     al,dx
  271.   test   al,8
  272.   jz     @@VR
  273. ENDM
  274.  
  275. MACRO @WaitVertEnd
  276. LOCAL    @@NVR
  277.   mov    edx,3dah
  278. @@NVR:
  279.   in     al,dx
  280.   test   al,8
  281.   jnz    @@NVR
  282. ENDM
  283.  
  284. ;esi = offset to palette
  285. ;ecx = number of color values to write
  286. ;al  = starting palette register
  287. proc WritePalette
  288.   cli
  289.   mov    edx,03c8h
  290.   out    dx,al
  291.   inc    dx
  292.   cld
  293.   rep    outsb
  294.   sti
  295.   ret
  296. endp
  297.  
  298. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  299. ;                                                                         ;
  300. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  301. ; cx = scroll factor
  302. proc scroll_sc
  303.   cli
  304.   mov    eax,ecx
  305.   mov    bl,80
  306.   mul    bl
  307.   mov    ebx,eax
  308.   mov    edx,3d4h
  309.   mov    al,0ch
  310.   mov    ah,bh      ;write the HIGH byte
  311.   out    dx,ax
  312.   mov    edx,3d4h
  313.   mov    al,0dh
  314.   mov    ah,bl      ;write the LOW byte
  315.   out    dx,ax
  316.   sti
  317.   ret
  318. endp
  319.  
  320. proc help_sc1
  321.   mov    edi,[_0b8000h]
  322.   add    edi,(50*160)
  323.   push   edi ecx
  324.   mov    ecx,(160*50)/4
  325.   xor    eax,eax
  326.   rep    stosd
  327.   pop    ecx edi
  328.   call   uncrush_text
  329.   xor    ecx,ecx
  330. @@sd:
  331.   @WaitVertEnd
  332.   call   scroll_sc
  333.   @WaitVert
  334.   inc    ecx
  335.   cmp    ecx,50
  336.   jbe    @@sd
  337.   ret
  338. endp
  339.  
  340. proc help_sc2
  341.   mov    ecx,50
  342. @@sd2:
  343.   @WaitVertEnd
  344.   call   scroll_sc
  345.   @WaitVert
  346.   dec    ecx
  347.   jnz    @@sd2
  348.   call   scroll_sc
  349.   ret
  350. endp
  351.  
  352. proc help_scroll
  353.   call   help_sc1
  354.   call   get_key
  355.   call   help_sc2
  356.   ret
  357. endp
  358.  
  359. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  360. ;                                                                         ;
  361. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  362. proc text_ded_pfout
  363.   XOR    AL,AL                                          ;fade screen
  364.   MOV    ecx,(64*3)
  365.   lea    edi,[fade_palette_buf]
  366.   cli
  367.   MOV    eDX,3c7h
  368.   OUT    DX,AL
  369.   ADD    eDX,2
  370.   rep    insb
  371.   sti
  372.   mov    ecx,64
  373. @@fade_out_loop:
  374.   push   ecx
  375.   lea    edi,[fade_palette_buf]
  376.   mov    ecx,(64*3)
  377. @@fade_loop:
  378.   mov    al,[byte edi]
  379.   or     al,al
  380.   jz     @@dont_dec
  381.   dec    [byte edi]
  382. @@dont_dec:
  383.   inc    edi
  384.   dec    ecx
  385.   jnz    @@fade_loop
  386.   xor    al,al
  387.   mov    ecx,64*3
  388.   lea    esi,[fade_palette_buf]
  389.   call   WritePalette
  390.   @WaitVertEnd
  391.   @WaitVert
  392.   pop    ecx
  393.   dec    ecx
  394.   jnz    @@fade_out_loop
  395.   ret
  396. endp
  397.  
  398. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  399. ;                                                                          ;
  400. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  401. proc dis_sbar
  402.   xor    al,al
  403. @@write_entry:
  404.   push   edi ecx eax
  405.   cmp    al,dl
  406.   je     @@hle
  407.   jmp    @@hlne
  408. @@hle:
  409.   mov    al,bh
  410.   jmp    @@write_lin
  411. @@hlne:
  412.   mov    al,bl
  413. @@write_lin:
  414.   stosb
  415.   inc    edi
  416.   dec    ecx
  417.   jnz    @@write_lin
  418.   pop    eax ecx edi
  419.   add    edi,160
  420.   inc    al
  421.   cmp    al,dh
  422.   jb     @@write_entry
  423.   ret
  424. endp
  425.  
  426. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  427. ;                                                                          ;
  428. ; SETUP_SCREEN PROC: Modified By Adam Seychell 14/03/94  in V1.02          ;
  429. ;                                                                          ;
  430. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  431. proc setup_screen
  432.   mov    eax,3
  433.   int    10h
  434.  
  435.         mov     bl,00h                 ;  goto Text Mode 80x50
  436.         mov     ah,11h
  437.         mov     al,12h
  438.         int     10h
  439.  
  440.  
  441.     ; set up registers to accsess one Bit plane  only
  442.     ; set for sequentual memory addressing
  443.         mov dx,3C4h             ; sequencer reg group
  444.         mov al,4
  445.         mov ah,0111b
  446.         out dx,ax
  447.  
  448.         mov dx,3CEh             ; The Graphics Controller reg group
  449.         mov al,5                ; Mode Register
  450.         mov ah,00000000b
  451.         out dx,ax
  452.  
  453.         mov dx,3ceh             ; The Graphics Controller reg group
  454.         mov al,6                ; Misellaneous Register
  455.         mov ah,1100b
  456.         out dx,ax
  457.  
  458.       ; set Map Mask Register
  459.         mov dx,3c4h             ; sequencer reg group
  460.         mov al,2
  461.         mov ah,0100b            ; to write to bit plane 2 ( font memory )
  462.         out dx,ax
  463.  
  464.      ; can now fill up the video font memory
  465.  
  466.         mov     edi,[_0b8000h]
  467.         xor     edx,edx
  468. @@fill_font:
  469.         mov     eax,[Dword PTR font_data+EDX]
  470.         mov     [edi],eax
  471.         mov     eax,[Dword PTR font_data+EDX+4]
  472.         mov     [edi+4],eax
  473.         add     edi,32
  474.         add     edx,8
  475.         cmp     edx,255*8
  476.         jb      @@fill_font
  477.  
  478.  
  479.  
  480.   ;      set up registers to accsess one Bit plane 0 and 1 chained together
  481.   ; i.e return to it's normal write mode.
  482.   ;
  483.         mov dx,3C4h             ; sequencer reg group
  484.         mov al,4
  485.         mov ah,00011b           ; Chain four enabled
  486.         out dx,ax
  487.  
  488.         mov dx,3CEh             ; The Graphics Controller reg group
  489.         mov al,5                ; Mode Register
  490.         mov ah,00010000b
  491.         out dx,ax
  492.  
  493.         mov al,6                ; Miscellaneous Register
  494.         mov ah,1110b
  495.         out dx,ax
  496.  
  497.      ; set Map Mask Register
  498.         mov dx,3c4h             ; sequencer reg group
  499.         mov al,2
  500.         mov ah,0011b            ; to write to bit plane 0 and 1
  501.         out dx,ax
  502.  
  503.     ;------- end of font filling code --------------------
  504.  
  505.   mov    ah,02h
  506.   xor    bh,bh
  507.   mov    edx,6400h
  508.   int    10h
  509.   mov    al,1
  510.   mov    ecx,3
  511.   lea    esi,[@@colour]
  512.   call   WritePalette
  513.   mov    al,5
  514.   mov    ecx,3
  515.   lea    esi,[@@colour+3]
  516.   call   WritePalette
  517.   mov    al,3ah
  518.   mov    ecx,3
  519.   lea    esi,[@@colour+6]
  520.   call   WritePalette
  521.   mov    al,3bh
  522.   mov    ecx,3
  523.   lea    esi,[@@colour+9]
  524.   call   WritePalette
  525.   mov    al,3dh
  526.   mov    ecx,3
  527.   lea    esi,[@@colour+12]
  528.   call   WritePalette
  529.   mov    al,3eh
  530.   mov    ecx,3
  531.   lea    esi,[@@colour+15]
  532.   call   WritePalette
  533.   ret
  534. @@colour:
  535.   db     12h,13h,1bh   ;01
  536.   db     0ch,12h,29h   ;05
  537.   db     1ch,38h,26h   ;3a
  538.   db     08h,3fh,38h   ;3b
  539.   db     00h,20h,2fh   ;3d
  540.   db     31h,31h,00h   ;3e
  541. endp
  542.  
  543.  
  544. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  545. ;                                                                          ;
  546. ; ch = size of edit                                                        ;
  547. ; dl = x, dh = y                                                           ;
  548. ;                                                                          ;
  549. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  550. proc get_input
  551.   movzx  edi,dh
  552.   mov    eax,edi
  553.   shl    edi,7
  554.   shl    eax,5
  555.   add    edi,eax
  556.   movzx  eax,dl
  557.   shl    eax,1
  558.   add    edi,eax
  559.   add    edi,[_0b8000h]
  560.   push   edi
  561.   push   edi
  562.   mov    cl,ch
  563.   mov    eax,6f20h
  564. @@set_bound:
  565.   stosw
  566.   dec    cl
  567.   jnz    @@set_bound
  568.   pop    edi
  569. @@get_input:
  570.   cmp    cl,ch
  571.   ja     @@exit
  572.   jae    @@ign
  573.   mov    ah,02h
  574.   xor    bh,bh
  575.   int    10h
  576. @@ign:
  577.   call   get_key
  578.   cmp    al,27
  579.   je     @@abort
  580.   cmp    al,13
  581.   je     @@exit
  582.   cmp    al,8
  583.   je     @@back_space
  584.   cmp    al,31
  585.   jbe    @@get_input
  586.   cmp    cl,ch
  587.   jae    @@ignore_write
  588.   mov    ah,6fh
  589.   stosw
  590. @@ignore_write:
  591.   inc    cl
  592.   inc    dl
  593.   jmp    @@get_input
  594. @@back_space:
  595.   or     cl,cl
  596.   jz     @@get_input
  597.   dec    cl
  598.   dec    dl
  599.   sub    edi,2
  600.   mov    [word edi],6f20h
  601.   jmp    @@get_input
  602. @@exit:
  603.   mov    ah,02h
  604.   xor    bh,bh
  605.   mov    edx,1900h
  606.   int    10h
  607.   pop    edi
  608.   clc
  609.   ret
  610. @@abort:
  611.   mov    ah,02h
  612.   xor    bh,bh
  613.   mov    edx,6400h
  614.   int    10h
  615.   pop    edi
  616.   stc
  617.   ret
  618. endp
  619.  
  620. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  621. ;                                                                          ;
  622. ; edi = screen pos, returns al                                             ;
  623. ;                                                                          ;
  624. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  625.  
  626. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  627. proc get_vnib
  628.   xor    ebx,ebx
  629. @@find_com_loop:
  630.   mov    al,[byte ebx+nibble_display]
  631.   cmp    al,[byte edi]
  632.   je     @@num_found
  633.   mov    al,[byte ebx+@@nibble_display2]
  634.   cmp    al,[byte edi]
  635.   je     @@num_found
  636.   inc    ebx
  637.   cmp    ebx,16
  638.   jb     @@find_com_loop
  639.   xor    bl,bl
  640. @@num_found:
  641.   add    edi,1
  642.   ret
  643. @@nibble_display2:
  644.   db     "0123456789abcdef"
  645. endp
  646.  
  647. proc get_vbyte
  648.   call   get_vnib
  649.   push   ebx
  650.   call   get_vnib
  651.   pop    eax
  652.   shl    al,4
  653.   and    bl,1111b
  654.   or     al,bl
  655.   ret
  656. endp
  657.  
  658. proc get_vdword
  659.   call   get_vbyte
  660.   shl    eax,24
  661.   mov    ebx,eax
  662.   push   ebx
  663.   call   get_vbyte
  664.   pop    ebx
  665.   shl    eax,16
  666.   and    eax,00FF0000h
  667.   or     ebx,eax
  668.   push   ebx
  669.   call   get_vbyte
  670.   pop    ebx
  671.   shl    eax,8
  672.   and    eax,0000FF00h
  673.   or     ebx,eax
  674.   push   ebx
  675.   call   get_vbyte
  676.   pop    ebx
  677.   and    eax,000000FFh
  678.   or     ebx,eax
  679.   ret
  680. endp
  681. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  682. proc get_inib
  683.   xor    ebx,ebx
  684. @@find_com_loop:
  685.   mov    al,[byte ebx+nibble_display]
  686.   cmp    al,[byte edi]
  687.   je     @@num_found
  688.   mov    al,[byte ebx+@@nibble_display2]
  689.   cmp    al,[byte edi]
  690.   je     @@num_found
  691.   inc    ebx
  692.   cmp    ebx,16
  693.   jb     @@find_com_loop
  694.   xor    bl,bl
  695. @@num_found:
  696.   add    edi,2
  697.   ret
  698. @@nibble_display2:
  699.   db     "0123456789abcdef"
  700. endp
  701.  
  702. proc get_ibyte
  703.   call   get_inib
  704.   push   ebx
  705.   call   get_inib
  706.   pop    eax
  707.   shl    al,4
  708.   and    bl,1111b
  709.   or     al,bl
  710.   ret
  711. endp
  712.  
  713. proc get_idword
  714.   call   get_ibyte
  715.   shl    eax,24
  716.   mov    ebx,eax
  717.   push   ebx
  718.   call   get_ibyte
  719.   pop    ebx
  720.   shl    eax,16
  721.   and    eax,00FF0000h
  722.   or     ebx,eax
  723.   push   ebx
  724.   call   get_ibyte
  725.   pop    ebx
  726.   shl    eax,8
  727.   and    eax,0000FF00h
  728.   or     ebx,eax
  729.   push   ebx
  730.   call   get_ibyte
  731.   pop    ebx
  732.   and    eax,000000FFh
  733.   or     ebx,eax
  734.   ret
  735. endp
  736. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  737.  
  738. ; cl = size of string; returns esi of string data
  739. proc get_string
  740. @@sg_loop:
  741.   mov    al,[byte edi]
  742.   mov    [byte esi],al
  743.   inc    esi
  744.   add    edi,2
  745.   dec    cl
  746.   jnz    @@sg_loop
  747.   ret
  748. endp
  749.  
  750. ;esi  Crunched image source pointer.
  751. ;edi  screen
  752. ;ecx  Length of crunched image source data.
  753. proc uncrush_text
  754.   MOV    edx,edi
  755.   XOR    EAX,EAX
  756. @@LOOPA:
  757.   LODSB
  758.   CMP    AL,32
  759.   JC     @@ForeGround
  760.   STOSW
  761. @@Next:
  762.   dec    ecx
  763.   jnz    @@LOOPA
  764.   JMP    @@Done
  765. @@ForeGround:
  766.   CMP    AL,16
  767.   JNC    @@BackGround
  768.   AND    AH,0F0H
  769.   OR     AH,AL
  770.   JMP    @@Next
  771. @@BackGround:
  772.   CMP    AL,24
  773.   JZ     @@NextLine
  774.   JNC    @@FlashBitToggle
  775.   SUB    AL,16
  776.   ADD    AL,AL
  777.   ADD    AL,AL
  778.   ADD    AL,AL
  779.   ADD    AL,AL
  780.   AND    AH,8FH
  781.   OR     AH,AL
  782.   JMP    @@Next
  783. @@NextLine:
  784.   ADD    edx,160
  785.   MOV    edi,edx
  786.   JMP    @@Next
  787. @@FlashBitToggle:
  788.   CMP    AL,27
  789.   JC     @@MultiOutput
  790.   JNZ    @@Next
  791.   XOR    AH,128
  792.   JMP    @@Next
  793. @@MultiOutput:
  794.   CMP    AL,25
  795.   MOV    ebx,ecx
  796.   LODSB
  797.   MOV    CL,AL
  798.   MOV    AL,32
  799.   JZ     @@StartOutput
  800.   LODSB
  801.   DEC    ebx
  802. @@StartOutput:
  803.   XOR    CH,CH
  804.   inc    ecx
  805.   REP STOSW
  806.   MOV    ecx,ebx
  807.   dec    ecx
  808.   LOOPNZ @@LOOPA
  809. @@Done:
  810.   ret
  811. endp
  812.  
  813. proc DecSizeSet
  814.   mov    ecx,eax
  815. @@dec83:
  816.   mov    eax,ecx
  817.   xor    edx,edx
  818.   div    [dword esi+@@Dec_divider]
  819.   mov    ecx,edx
  820.   add    al,'0'
  821.   mov    [edi],al
  822.   add    edi,2
  823.   sub    esi,4
  824.   jge    @@dec83
  825.   ret
  826. @@dec_divider:
  827.   dd 1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000
  828. endp
  829.  
  830. proc print_decn1
  831.   add    edi,[_0b8000h]
  832.   and    eax,0ffh
  833.   mov    esi,4*1
  834.   call   DecSizeSet
  835.   ret
  836. endp
  837.  
  838. proc print_decn3
  839.   add    edi,[_0b8000h]
  840.   and    eax,03fffh
  841.   mov    esi,4*3
  842.   call   DecSizeSet
  843.   ret
  844. endp
  845.  
  846. proc print_decn5
  847.   add    edi,[_0b8000h]
  848.   mov    esi,4*4
  849.   call     DecSizeSet
  850.   ret
  851. endp
  852.  
  853. proc print_decn9
  854.   add    edi,[_0b8000h]
  855.   mov    esi,4*9
  856.   call     DecSizeSet
  857.   ret
  858. endp
  859.  
  860. ; edi = position (x * (y*160))
  861. ; bl  = number
  862. ; ah  = colour
  863. proc display_nibble
  864.   add    edi,[_0b8000h]
  865.   and    ebx,1111b
  866.   mov    al,[byte ebx+nibble_display]
  867.   mov    [edi],ax
  868.   add    edi,2
  869.   ret
  870. endp
  871.  
  872. ; edi = position (x * (y*160))
  873. ; bl  = number
  874. ; ah  = colour
  875. proc display_byte
  876.   add    edi,[_0b8000h]
  877. proc display_byte_f
  878.   push   ebx
  879.   and    ebx,11110000b
  880.   shr    bl,4
  881.   mov    al,[byte ebx+nibble_display]
  882.   mov    [edi],ax
  883.   add    edi,2
  884.   pop    ebx
  885.   and    ebx,00001111b
  886.   mov    al,[byte ebx+nibble_display]
  887.   mov    [edi],ax
  888.   add    edi,2
  889.   ret
  890. endp
  891. endp
  892.  
  893. ; edi = position (x * (y*160))
  894. ; ecx = number
  895. ; ah  = colour
  896. proc display_word
  897.   and    ecx,0ffffh
  898.   add    edi,[_0b8000h]
  899.   mov    ebx,ecx
  900.   shr    ebx,12
  901.   mov    al,[byte ebx+nibble_display]
  902.   mov    [edi],ax
  903.   add    edi,2
  904.   mov    ebx,ecx
  905.   shr    ebx,8
  906.   and    ebx,1111b
  907.   mov    al,[byte ebx+nibble_display]
  908.   mov    [edi],ax
  909.   add    edi,2
  910.   mov    ebx,ecx
  911.   shr    ebx,4
  912.   and    ebx,1111b
  913.   mov    al,[byte ebx+nibble_display]
  914.   mov    [edi],ax
  915.   add    edi,2
  916.   mov    ebx,ecx
  917.   and    ebx,1111b
  918.   mov    al,[byte ebx+nibble_display]
  919.   mov    [edi],ax
  920.   add    edi,2
  921.   ret
  922. endp
  923.  
  924. ; edi = position (x * (y*160))
  925. ; ecx = number
  926. ; ah  = colour
  927. proc display_dword
  928.   add    edi,[_0b8000h]
  929.   mov    ebx,ecx
  930.   shr    ebx,28
  931.   mov    al,[byte ebx+nibble_display]
  932.   mov    [edi],ax
  933.   add    edi,2
  934.   mov    ebx,ecx
  935.   shr    ebx,24
  936.   and    ebx,1111b
  937.   mov    al,[byte ebx+nibble_display]
  938.   mov    [edi],ax
  939.   add    edi,2
  940.   mov    ebx,ecx
  941.   shr    ebx,20
  942.   and    ebx,1111b
  943.   mov    al,[byte ebx+nibble_display]
  944.   mov    [edi],ax
  945.   add    edi,2
  946.   mov    ebx,ecx
  947.   shr    ebx,16
  948.   and    ebx,1111b
  949.   mov    al,[byte ebx+nibble_display]
  950.   mov    [edi],ax
  951.   add    edi,2
  952.   mov    ebx,ecx
  953.   shr    ebx,12
  954.   and    ebx,1111b
  955.   mov    al,[byte ebx+nibble_display]
  956.   mov    [edi],ax
  957.   add    edi,2
  958.   mov    ebx,ecx
  959.   shr    ebx,8
  960.   and    ebx,1111b
  961.   mov    al,[byte ebx+nibble_display]
  962.   mov    [edi],ax
  963.   add    edi,2
  964.   mov    ebx,ecx
  965.   shr    ebx,4
  966.   and    ebx,1111b
  967.   mov    al,[byte ebx+nibble_display]
  968.   mov    [edi],ax
  969.   add    edi,2
  970.   mov    ebx,ecx
  971.   and    ebx,1111b
  972.   mov    al,[byte ebx+nibble_display]
  973.   mov    [edi],ax
  974.   add    edi,2
  975.   ret
  976. endp
  977.  
  978. ; edi = position (x * (y*160))
  979. ; bx  = number    value(hi):command(lo)
  980. ; ah  = colour
  981. proc display_command
  982.   add    edi,[_0b8000h]
  983. proc display_command_f
  984.   cmp    bl,0fh
  985.   je     @@blank
  986.   mov    al,"a"
  987.   add    al,bl
  988.   mov    [edi],ax
  989.   add    edi,2
  990.   push   ebx
  991.   and    ebx,1111000000000000b
  992.   shr    ebx,12
  993.   mov    al,[byte ebx+nibble_display]
  994.   mov    [edi],ax
  995.   add    edi,2
  996.   pop    ebx
  997.   and    ebx,0000111100000000b
  998.   shr    ebx,8
  999.   mov    al,[byte ebx+nibble_display]
  1000.   mov    [edi],ax
  1001.   add    edi,2
  1002.   ret
  1003. @@blank:
  1004.   mov    al,"-"
  1005.   mov    [edi],ax
  1006.   add    edi,2
  1007.   mov    [edi],ax
  1008.   add    edi,2
  1009.   mov    [edi],ax
  1010.   add    edi,2
  1011.   ret
  1012. endp
  1013. endp
  1014.  
  1015. ; edi = position (x * (y*160))
  1016. ; ah  = colour
  1017. proc display_note
  1018.   add    edi,[_0b8000h]
  1019. proc display_note_f
  1020.   lea    ebx,[ebx*2+ebx]
  1021.   mov    al,[byte ebx+note_display]
  1022.   mov    [edi],ax
  1023.   add    edi,2
  1024.   mov    al,[byte ebx+note_display+1]
  1025.   mov    [edi],ax
  1026.   add    edi,2
  1027.   mov    al,[byte ebx+note_display+2]
  1028.   mov    [edi],ax
  1029.   add    edi,2
  1030.   ret
  1031. endp
  1032. endp
  1033.  
  1034. ; byte_write1: esi = string addr  null terminated
  1035. ;              edi = position
  1036. ;              cl = len
  1037. ;              ah  = colour
  1038. proc byte_write1
  1039.   add    edi,[_0b8000h]
  1040. @@str_copy_loop:
  1041.   mov    al,[esi]
  1042.   inc    esi
  1043.   or     al,al
  1044.   jz     @@paint_nulls
  1045.   cmp    al,"."
  1046.   je     @@paint_nulls
  1047.   stosw
  1048.   dec    cl
  1049.   jnz    @@str_copy_loop
  1050. @@paint_nulls:
  1051.   xor    al,al
  1052. @@paint_nl:
  1053.   or     cl,cl
  1054.   jz     @@exit
  1055.   mov    [edi],ax
  1056.   add    edi,2
  1057.   dec    cl
  1058.   jmp    @@paint_nl
  1059. @@exit:
  1060.   ret
  1061. endp
  1062.  
  1063. ; byte_write2: esi = string addr  null terminated
  1064. ;              edi = position
  1065. ;              cl = len
  1066. ;              ah  = colour
  1067. proc byte_write2
  1068.   add    edi,[_0b8000h]
  1069. @@str_copy_loop:
  1070.   mov    al,[esi]
  1071.   inc    esi
  1072.   mov    [edi],ax
  1073.   add    edi,2
  1074.   dec    cl
  1075.   jnz    @@str_copy_loop
  1076.   ret
  1077. endp
  1078.  
  1079. ; esi = ANSIIZ
  1080. proc display_bm
  1081.   mov    edi,(49*160)
  1082.   mov    cl,80
  1083.   mov    ah,8eh
  1084.   call   byte_write1
  1085.   ret
  1086. endp
  1087.  
  1088. proc clear_bm
  1089.   mov    edi,[_0b8000h]
  1090.   add    edi,(49*160)
  1091.   xor    eax,eax
  1092.   mov    ecx,160/4
  1093.   rep    stosd
  1094.   ret
  1095. endp
  1096.  
  1097. macro @error_mess string
  1098. local @@tttext, @@skip
  1099.   jmp    @@skip
  1100.   ifb    <string>
  1101. @@tttext:
  1102.   db     " - Hit any key",0
  1103.   else
  1104. @@tttext:
  1105.   db     string, " - Hit any key",0
  1106.   endif
  1107. @@skip:
  1108.   push   edi esi ecx
  1109.   lea    esi,[@@tttext]
  1110.   call   display_bm
  1111.   call   get_key
  1112.   call   clear_bm
  1113.   pop    ecx esi edi
  1114. endm
  1115.  
  1116. macro @splash_on_sm string
  1117. local @@tttext, @@skip
  1118.   jmp    @@skip
  1119.   ifb    <string>
  1120. @@tttext:
  1121.   db     0
  1122.   else
  1123. @@tttext:
  1124.   db     string, 0
  1125.   endif
  1126. @@skip:
  1127.   push   edi esi ecx
  1128.   lea    esi,[@@tttext]
  1129.   call   display_bm
  1130.   pop    ecx esi edi
  1131. endm
  1132.  
  1133. macro @splash_off_sm string
  1134. local @@tttext, @@skip
  1135.   push   edi esi ecx
  1136.   call   clear_bm
  1137.   pop    ecx esi edi
  1138. endm
  1139.  
  1140. ;esi = source buffer
  1141. ;edi = video buffer
  1142. ;dl = height
  1143. ;ebx = width
  1144. proc paint_window
  1145. @@splash_loop:
  1146.   mov    ecx,ebx
  1147.   rep    movsw
  1148.   mov    eax,80
  1149.   sub    eax,ebx
  1150.   lea    eax,[eax*2]
  1151.   add    edi,eax
  1152.   dec    dl
  1153.   jnz    @@splash_loop
  1154.   ret
  1155. endp
  1156.  
  1157. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1158. ;                                                                          ;
  1159. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1160. proc scroll_display32
  1161.   mov    edi,[_0b8000h]
  1162.   add    edi,(78*2)+(2*160)
  1163.   xor    cl,cl
  1164. @@clear_scroll:
  1165.   mov    al,"▒"
  1166.   cmp    cl,dl
  1167.   jne    @@cont2
  1168.   mov    al,17
  1169. @@cont2:
  1170.   stosb
  1171.   add    edi,159
  1172.   inc    cl
  1173.   cmp    cl,32
  1174.   jb     @@clear_scroll
  1175.   ret
  1176. endp
  1177.  
  1178. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1179. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1180. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1181. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1182. ;                                                                          ;
  1183. ;display keyboard                                                          ;
  1184. ;                                                                          ;
  1185. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1186. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1187. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1188. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1189.  
  1190. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1191. ;                                                                          ;
  1192. ; cl = channel to play                                                     ;
  1193. ;                                                                          ;
  1194. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1195. proc play_keynote
  1196.   cli
  1197.   mov    al,size tfunk_chan
  1198.   mul    cl                                         ;[byte pat_chan]
  1199.   movzx  edi,ax
  1200.   add    edi,offset funk_chan1
  1201.   mov    al,[byte sam_hl]
  1202.   add    al,[byte sam_real]
  1203.   mov    [byte edi+tfunk_chan.sample],al
  1204.   movzx  eax,al
  1205.   shl    eax,5
  1206.   add    eax,[funk_hr_ptr]
  1207.   add    eax,offset (tfunk_hr).funk_sb
  1208.   cmp    [dword eax+tfunk_sb.length],0
  1209.   je     @@endendend
  1210.   mov    [byte edi+tfunk_chan.funkctrl],10b       ; set funkctrl
  1211.   mov    ebx,[dword eax+tfunk_sb.start]
  1212.   cmp    ebx,0ffffffffh
  1213.   je     @@dont_loop
  1214.   mov    [byte edi+tfunk_chan.funkctrl],11b       ; set funkctrl
  1215. @@dont_loop:
  1216.   mov    [dword edi+tfunk_chan.start],ebx
  1217.   mov    ebx,[dword eax+tfunk_sb.length]
  1218.   mov    [dword edi+tfunk_chan.length],ebx
  1219.   mov    bl,[byte eax+tfunk_sb.balance]
  1220.   mov    [byte edi+tfunk_chan.balance],bl
  1221.   mov    bl,[byte eax+tfunk_sb.pt_and_sop]        ; get both port type and sample ofs parm
  1222.   mov    dl,bl
  1223.   shr    bl,4
  1224.   and    dl,1111b
  1225.   mov    [byte edi+tfunk_chan.port_type],bl
  1226.   mov    [byte edi+tfunk_chan.sample_ofs_parm],dl
  1227.   mov    bl,[byte eax+tfunk_sb.vv_waveform]       ; get both vibrato wf & tremola wf
  1228.   mov    dl,bl
  1229.   shr    bl,4
  1230.   and    dl,1111b
  1231.   mov    [byte edi+tfunk_chan.vib_waveform],bl
  1232.   mov    [byte edi+tfunk_chan.vol_vib_waveform],dl
  1233.   mov    bl,[byte eax+tfunk_sb.rl_and_as]         ; get both retrig speed & arp speed
  1234.   mov    dl,bl
  1235.   shr    bl,4
  1236.   and    dl,1111b
  1237.   mov    [byte edi+tfunk_chan.retrig_limit],bl
  1238.   mov    [byte edi+tfunk_chan.arp_speed],dl
  1239.   mov    bl,[byte eax+tfunk_sb.volume]
  1240.   mov    [byte edi+tfunk_chan.volume],bl
  1241.   call   vol_to_realvol
  1242.   call   [dword CARD_volume_convert]
  1243.   mov    al,[byte octave]
  1244.   mov    bl,al
  1245.   shl    al,3
  1246.   shl    bl,2
  1247.   add    bl,al
  1248.   add    bl,[byte note]
  1249.   mov    [byte edi+tfunk_chan.note],bl
  1250.   @note_2_ifreq
  1251.   mov    [word edi+tfunk_chan.ifreq],bx
  1252.   call   ifreq_to_rfreq
  1253.   mov    [dword edi+tfunk_chan.rfreq],eax
  1254.   call   [dword CARD_freq_convert]
  1255.   movzx  esi,[byte edi+tfunk_chan.sample]
  1256.   lea    esi,[esi*4]
  1257.   mov    eax,[dword esi+funk_info.sample_ptrs]
  1258.   add    [dword edi+tfunk_chan.start],eax
  1259.   add    [dword edi+tfunk_chan.length],eax
  1260.   mov    [dword edi+tfunk_chan.CARD_sample_ptr],eax
  1261. @@endendend:
  1262.   sti
  1263.   ret
  1264. endp
  1265.  
  1266. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1267. ;                                                                          ;
  1268. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1269. proc clr_keyboard
  1270.   mov    edi,[_0b8000h]
  1271.   add    edi,((1*2)+(42*160))+1
  1272.   mov    ch,6
  1273. @@clr_row:
  1274.   mov    cl,(12)*5
  1275. @@clr_line:
  1276.   mov    [byte edi],07h
  1277.   add    edi,2
  1278.   dec    cl
  1279.   jnz    @@clr_line
  1280.   add    edi,160-((12*2)*5)
  1281.   dec    ch
  1282.   jnz    @@clr_row
  1283.   ret
  1284. endp
  1285.  
  1286. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1287. ;                                                                          ;
  1288. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1289. proc dis_keyboard
  1290.   call   clr_keyboard
  1291. proc dis_keyboard2
  1292.   movzx  ebx,[byte note]
  1293.   lea    ebx,[ebx*4]
  1294.   mov    esi,[dword ebx+dis_keyboard_map]
  1295.  
  1296.   mov    edi,[_0b8000h]
  1297.   add    edi,((1*2)+(42*160))+1
  1298.   movzx  eax,[byte octave]
  1299.   mov    ebx,eax
  1300.   shl    eax,4
  1301.   shl    ebx,3
  1302.   add    edi,eax
  1303.   add    edi,ebx
  1304. @@map_key:
  1305.   lodsb
  1306.   cmp    al,255
  1307.   je     @@done
  1308.   movzx  eax,al
  1309.   add    edi,eax
  1310.   mov    [byte edi],22h
  1311.   jmp    @@map_key
  1312. @@done:
  1313.   ret
  1314. endp
  1315. endp
  1316.  
  1317. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1318. ;                                                                          ;
  1319. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1320. proc mus_kb_input
  1321.   cmp    al,"z"
  1322.   je     @@key1
  1323.   cmp    al,"Z"
  1324.   je     @@key1
  1325.   cmp    al,"s"
  1326.   je     @@key2
  1327.   cmp    al,"S"
  1328.   je     @@key2
  1329.   cmp    al,"x"
  1330.   je     @@key3
  1331.   cmp    al,"X"
  1332.   je     @@key3
  1333.   cmp    al,"d"
  1334.   je     @@key4
  1335.   cmp    al,"D"
  1336.   je     @@key4
  1337.   cmp    al,"c"
  1338.   je     @@key5
  1339.   cmp    al,"C"
  1340.   je     @@key5
  1341.   cmp    al,"v"
  1342.   je     @@key6
  1343.   cmp    al,"V"
  1344.   je     @@key6
  1345.   cmp    al,"g"
  1346.   je     @@key7
  1347.   cmp    al,"G"
  1348.   je     @@key7
  1349.   cmp    al,"b"
  1350.   je     @@key8
  1351.   cmp    al,"B"
  1352.   je     @@key8
  1353.   cmp    al,"h"
  1354.   je     @@key9
  1355.   cmp    al,"H"
  1356.   je     @@key9
  1357.   cmp    al,"n"
  1358.   je     @@key10
  1359.   cmp    al,"N"
  1360.   je     @@key10
  1361.   cmp    al,"j"
  1362.   je     @@key11
  1363.   cmp    al,"J"
  1364.   je     @@key11
  1365.   cmp    al,"m"
  1366.   je     @@key12
  1367.   cmp    al,"M"
  1368.   je     @@key12
  1369.   ret
  1370. @@key1:
  1371.   mov    [byte note],0
  1372.   call   enter_slot
  1373.   call   dis_keyboard
  1374.   mov    cl,[byte pat_chan]
  1375.   call   play_keynote
  1376.   jmp    @@cont
  1377. @@key2:
  1378.   mov    [byte note],1
  1379.   call   enter_slot
  1380.   call   dis_keyboard
  1381.   mov    cl,[byte pat_chan]
  1382.   call   play_keynote
  1383.   jmp    @@cont
  1384. @@key3:
  1385.   mov    [byte note],2
  1386.   call   enter_slot
  1387.   call   dis_keyboard
  1388.   mov    cl,[byte pat_chan]
  1389.   call   play_keynote
  1390.   jmp    @@cont
  1391. @@key4:
  1392.   mov    [byte note],3
  1393.   call   enter_slot
  1394.   call   dis_keyboard
  1395.   mov    cl,[byte pat_chan]
  1396.   call   play_keynote
  1397.   jmp    @@cont
  1398. @@key5:
  1399.   mov    [byte note],4
  1400.   call   enter_slot
  1401.   call   dis_keyboard
  1402.   mov    cl,[byte pat_chan]
  1403.   call   play_keynote
  1404.   jmp    @@cont
  1405. @@key6:
  1406.   mov    [byte note],5
  1407.   call   enter_slot
  1408.   call   dis_keyboard
  1409.   mov    cl,[byte pat_chan]
  1410.   call   play_keynote
  1411.   jmp    @@cont
  1412. @@key7:
  1413.   mov    [byte note],6
  1414.   call   enter_slot
  1415.   call   dis_keyboard
  1416.   mov    cl,[byte pat_chan]
  1417.   call   play_keynote
  1418.   jmp    @@cont
  1419. @@key8:
  1420.   mov    [byte note],7
  1421.   call   enter_slot
  1422.   call   dis_keyboard
  1423.   mov    cl,[byte pat_chan]
  1424.   call   play_keynote
  1425.   jmp    @@cont
  1426. @@key9:
  1427.   mov    [byte note],8
  1428.   call   enter_slot
  1429.   call   dis_keyboard
  1430.   mov    cl,[byte pat_chan]
  1431.   call   play_keynote
  1432.   jmp    @@cont
  1433. @@key10:
  1434.   mov    [byte note],9
  1435.   call   enter_slot
  1436.   call   dis_keyboard
  1437.   mov    cl,[byte pat_chan]
  1438.   call   play_keynote
  1439.   jmp    @@cont
  1440. @@key11:
  1441.   mov    [byte note],10
  1442.   call   enter_slot
  1443.   call   dis_keyboard
  1444.   mov    cl,[byte pat_chan]
  1445.   call   play_keynote
  1446.   jmp    @@cont
  1447. @@key12:
  1448.   mov    [byte note],11
  1449.   call   enter_slot
  1450.   call   dis_keyboard
  1451.   mov    cl,[byte pat_chan]
  1452.   call   play_keynote
  1453. @@cont:
  1454.   ret
  1455. endp
  1456.  
  1457. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1458. ;                                                                          ;
  1459. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1460. proc update_octave
  1461.   mov    edi,[_0b8000h]
  1462.   mov    [byte edi+((06*2)+(41*160))+1],1eh
  1463.   mov    [byte edi+((06*2)+(41*160))+3],1eh
  1464.   mov    [byte edi+((18*2)+(41*160))+1],1eh
  1465.   mov    [byte edi+((18*2)+(41*160))+3],1eh
  1466.   mov    [byte edi+((30*2)+(41*160))+1],1eh
  1467.   mov    [byte edi+((30*2)+(41*160))+3],1eh
  1468.   mov    [byte edi+((42*2)+(41*160))+1],1eh
  1469.   mov    [byte edi+((42*2)+(41*160))+3],1eh
  1470.   mov    [byte edi+((54*2)+(41*160))+1],1eh
  1471.   mov    [byte edi+((54*2)+(41*160))+3],1eh
  1472.   cmp    [byte octave],0
  1473.   je     @@oct1
  1474.   cmp    [byte octave],1
  1475.   je     @@oct2
  1476.   cmp    [byte octave],2
  1477.   je     @@oct3
  1478.   cmp    [byte octave],3
  1479.   je     @@oct4
  1480.   cmp    [byte octave],4
  1481.   je     @@oct5
  1482.   ret
  1483. @@oct1:
  1484.   mov    [byte edi+((06*2)+(41*160))+1],1fh
  1485.   mov    [byte edi+((06*2)+(41*160))+3],1fh
  1486.   ret
  1487. @@oct2:
  1488.   mov    [byte edi+((18*2)+(41*160))+1],1fh
  1489.   mov    [byte edi+((18*2)+(41*160))+3],1fh
  1490.   ret
  1491. @@oct3:
  1492.   mov    [byte edi+((30*2)+(41*160))+1],1fh
  1493.   mov    [byte edi+((30*2)+(41*160))+3],1fh
  1494.   ret
  1495. @@oct4:
  1496.   mov    [byte edi+((42*2)+(41*160))+1],1fh
  1497.   mov    [byte edi+((42*2)+(41*160))+3],1fh
  1498.   ret
  1499. @@oct5:
  1500.   mov    [byte edi+((54*2)+(41*160))+1],1fh
  1501.   mov    [byte edi+((54*2)+(41*160))+3],1fh
  1502.   ret
  1503. endp
  1504.  
  1505. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1506. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1507. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1508. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1509. ;                                                                          ;
  1510. ; file operations                                                          ;
  1511. ;                                                                          ;
  1512. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1513. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1514. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1515. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1516. proc get_directory
  1517.   mov    [byte esi],"a"
  1518.   mov    [byte esi+1],":"
  1519.   mov    [byte esi+2],"\"
  1520.   mov    [byte esi+3],0
  1521.   mov    ah,19h
  1522.   int    21h
  1523.   add    [byte esi],al
  1524.   add    esi,3
  1525.   mov    ah,47h
  1526.   xor    dl,dl
  1527.   int    21h
  1528.   ret
  1529. endp
  1530.  
  1531. ; edx = pointer to buffer
  1532. proc set_directory
  1533.   mov    ah,3bh
  1534.   push   ds
  1535.   pop    es
  1536.   int    21h
  1537.   ret
  1538. endp
  1539.  
  1540. ; ecx <- eax
  1541. proc intel_2_motorola
  1542.   mov    cl,al
  1543.   shl    ecx,8
  1544.   shr    eax,8
  1545.  
  1546.   mov    cl,al
  1547.   shl    ecx,8
  1548.   shr    eax,8
  1549.  
  1550.   mov    cl,al
  1551.   shl    ecx,8
  1552.   shr    eax,8
  1553.  
  1554.   mov    cl,al
  1555.   ret
  1556. endp
  1557.  
  1558. ; bl = 1 - get directory
  1559. proc load_fset
  1560.   xor    ebp,ebp
  1561.   mov    edi,[fdirectory_buffer]
  1562. @@l:
  1563.   cmp    [byte edi+tfdirectory.attr],0ffh
  1564.   je     @@end
  1565.   add    edi,size tfdirectory
  1566.   inc    ebp
  1567. @@end:
  1568.   mov    [@@base_entry],ebp
  1569.  
  1570.   mov    ah,4eh
  1571.   mov    ecx,10h
  1572.   int    21h
  1573.   jnc    @@load_next
  1574.   ret
  1575. @@load_next:
  1576.   mov    esi,[dword PSP_address]
  1577.   add    esi,80h
  1578.   or     bl,bl
  1579.   jz     @@aas
  1580.   cmp    [byte esi+tdta.attr],10h
  1581.   je     @@readln
  1582.   jmp    @@next_DTA
  1583. @@aas:
  1584.   cmp    [byte esi+tdta.attr],10h
  1585.   je     @@next_DTA
  1586. @@readln:
  1587.   mov    eax,ebp
  1588.   mov    ecx,size tfdirectory
  1589.   mul    ecx
  1590.   mov    edi,[fdirectory_buffer]
  1591.   add    edi,eax
  1592.  
  1593.   mov    eax,[dword esi+tdta.fname]
  1594.   call   intel_2_motorola
  1595.   mov    edx,ecx
  1596.   mov    eax,[dword edi+tfdirectory.fname]
  1597.   call   intel_2_motorola
  1598.   cmp    edx,ecx
  1599.   ja     @@next_line
  1600. ;;;INSERT SPACE and add;;;;;;;;;;;
  1601.   mov    ecx,fdir_max_length-1
  1602.   sub    ecx,ebp
  1603.   js     @@dont_shift
  1604.   jz     @@dont_shift
  1605.  
  1606.   push   esi edi
  1607.   mov    edi,[fdirectory_buffer]
  1608.   add    edi,(size tfdirectory)*fdir_max_length
  1609.   mov    esi,edi
  1610.   sub    esi,(size tfdirectory)
  1611.   mov    eax,(size tfdirectory)
  1612.   mul    ecx
  1613.   mov    ecx,eax
  1614.   inc    ecx
  1615.   std
  1616.   rep    movsb
  1617.   cld
  1618.   pop    edi esi
  1619.  
  1620. @@dont_shift:
  1621.   mov    al,[byte esi+tdta.attr]
  1622.   mov    [byte edi+tfdirectory.attr],al
  1623.   lea    esi,[esi+tdta.fname]
  1624.   lea    edi,[edi+tfdirectory.fname]
  1625.   mov    ecx,13
  1626.   rep    movsb
  1627.   mov    ebp,[@@base_entry]
  1628.   inc    [word fdir_length]
  1629.   cmp    [word fdir_length],fdir_max_length
  1630.   jbe    @@next_DTA
  1631.   ret
  1632. ;;;NEXT LINE;;;;;;;;;;;;;;;;;;;;;;
  1633. @@next_line:
  1634.   inc    ebp
  1635.   jmp    @@load_next
  1636. @@next_DTA:
  1637.   mov    ah,4fh
  1638.   int    21h
  1639.   jnc    @@load_next
  1640.   ret
  1641. @@base_entry          dd ?
  1642. endp
  1643.  
  1644. proc load_fdirectory
  1645.   push   edx
  1646.   mov    edi,[fdirectory_buffer]
  1647.   mov    ecx,(size tfdirectory)*(fdir_max_length)
  1648.   mov    al,0ffh
  1649.   rep    stosb
  1650.   mov    [word fdir_real],0
  1651.   mov    [byte fdir_hl],0
  1652.   mov    [word fdir_length],0
  1653.   mov    bl,1
  1654.   lea    edx,[file_search_all]
  1655.   call   load_fset
  1656.   xor    bl,bl
  1657.   pop    edx
  1658.   call   load_fset
  1659.   ret
  1660. endp
  1661.  
  1662. proc display_fdir
  1663.   cmp    [word fdir_length],0
  1664.   jne    @@cont
  1665.   ret
  1666. @@cont:
  1667.   mov    dl,[byte fdir_hl]
  1668.   call   scroll_display32
  1669.   mov    eax,size tfdirectory
  1670.   mul    [word fdir_real]
  1671.   movzx  esi,ax
  1672.   add    esi,[dword fdirectory_buffer]
  1673.   mov    edi,[_0b8000h]
  1674.   add    edi,(3*2)+(2*160)
  1675.   movzx  edx,[word fdir_real]
  1676.   xor    bl,bl
  1677. @@display_loop:
  1678.   push   esi edi
  1679.   mov    ecx,19
  1680.   mov    ah,0fh
  1681.   cmp    dx,[word fdir_length]
  1682.   jae    @@paint_blank
  1683.   cmp    [byte esi+tfdirectory.attr],10h
  1684.   jne    @@dont_dd
  1685.   mov    ah,0eh
  1686. @@dont_dd:
  1687.   cmp    bl,[byte fdir_hl]
  1688.   jne    @@dont_dd2
  1689.   add    ah,70h
  1690. @@dont_dd2:
  1691.   lea    esi,[esi+tfdirectory.fname]
  1692. @@dis_name:
  1693.   lodsb
  1694.   or     al,al
  1695.   jz     @@exit_fn
  1696.   stosw
  1697.   dec    cl
  1698.   jnz    @@dis_name
  1699.   jmp    @@exit_fn
  1700. @@paint_blank:
  1701.   xor    al,al
  1702. @@exit_fn:
  1703.   rep    stosw
  1704.   pop    edi esi
  1705.   add    esi,size tfdirectory
  1706.   add    edi,160
  1707.   inc    edx
  1708.   inc    bl
  1709.   cmp    bl,32
  1710.   jb     @@display_loop
  1711.   ret
  1712. endp
  1713.  
  1714. proc goto_end_str
  1715.   xor    ebx,ebx
  1716. @@get_str_len:
  1717.   cmp    [byte edi+ebx],0
  1718.   je     @@e_get_str_len
  1719.   inc    ebx
  1720.   jmp    @@get_str_len
  1721. @@e_get_str_len:
  1722.   ret
  1723. endp
  1724.  
  1725. proc mini_trans_str
  1726. @@copy_str:
  1727.   mov    al,[byte esi]
  1728.   mov    [byte edi+ebx],al
  1729.   or     al,al
  1730.   je     @@e_copy_str
  1731.   inc    ebx
  1732.   inc    esi
  1733.   jmp    @@copy_str
  1734. @@e_copy_str:
  1735.   ret
  1736. endp
  1737.  
  1738. proc fdir_scroll_up
  1739.   cmp    [byte fdir_hl],0
  1740.   je     @@adj_real_bk
  1741.   dec    [byte fdir_hl]
  1742.   ret
  1743. @@adj_real_bk:
  1744.   cmp    [word fdir_real],0
  1745.   je     @@end
  1746.   dec    [word fdir_real]
  1747. @@end:
  1748.   ret
  1749. endp
  1750.  
  1751. proc fdir_scroll_dn
  1752.   movzx  ax,[byte fdir_hl]
  1753.   inc    ax
  1754.   cmp    [byte fdir_hl],31
  1755.   je     @@adj_real_fd
  1756.   cmp    ax,[word fdir_length]
  1757.   je     @@end
  1758.   inc    [byte fdir_hl]
  1759.   ret
  1760. @@adj_real_fd:
  1761.   add    ax,[word fdir_real]
  1762.   cmp    ax,[word fdir_length]
  1763.   je     @@end
  1764.   inc    [word fdir_real]
  1765. @@end:
  1766.   ret
  1767. endp
  1768.  
  1769. proc fdir_scroll_pageup
  1770.   mov    cl,16
  1771. @@sl:
  1772.   call   fdir_scroll_up
  1773.   dec    cl
  1774.   jnz    @@sl
  1775.   ret
  1776. endp
  1777.  
  1778. proc fdir_scroll_pagedn
  1779.   mov    cl,16
  1780. @@sl:
  1781.   call   fdir_scroll_dn
  1782.   dec    cl
  1783.   jnz    @@sl
  1784.   ret
  1785. endp
  1786.  
  1787. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1788. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1789. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1790. ;                                                                          ;
  1791. ; pattern editor                                                           ;
  1792. ;                                                                          ;
  1793. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1794. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1795. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1796.  
  1797. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1798. ;                                                                          ;
  1799. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1800. macro @mini_clear_slot
  1801.   mov    [byte esi],0fch
  1802.   mov    [byte esi+1],0fh
  1803.   mov    [byte esi+2],0
  1804. endm
  1805.  
  1806. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1807. ;                                                                          ;
  1808. ; esi = pattern number, dl = chan, dh = real + hl                          ;
  1809. ;                                                                          ;
  1810. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1811. proc calc_data
  1812.   mov    eax,esi                                  ; bx * 600h
  1813.   shl    eax,10
  1814.   shl    esi,9
  1815.   add    esi,eax
  1816.   movzx  eax,dh
  1817.   mov    ebx,eax
  1818.   shl    eax,4
  1819.   shl    ebx,3
  1820.   add    esi,eax
  1821.   add    esi,ebx
  1822.   movzx  eax,dl                                   ; [byte pe.chan]
  1823.   lea    eax,[eax*2+eax]
  1824.   add    esi,eax
  1825.   add    esi,[dword funk_hr_ptr]
  1826.   add    esi,size tfunk_hr
  1827.   ret
  1828. endp
  1829.  
  1830. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1831. ;                                                                          ;
  1832. ; esi = pattern numebr, dl = chan, dh = real + hl, ch = hl                 ;
  1833. ; cl  = colour ofs                                                         ;
  1834. ;                                                                          ;
  1835. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1836. proc display_slot_f
  1837.   cmp    [byte sel_flag],0
  1838.   je     @@paint_slot
  1839.   cmp    dl,[sel_area_chan1]
  1840.   jae    @@pass1
  1841.   jmp    @@paint_slot
  1842. @@pass1:
  1843.   cmp    dl,[sel_area_chan2]
  1844.   jbe    @@pass2
  1845.   jmp    @@paint_slot
  1846. @@pass2:
  1847.   cmp    dh,[sel_area_trek1]
  1848.   jae    @@pass3
  1849.   jmp    @@paint_slot
  1850. @@pass3:
  1851.   cmp    dh,[sel_area_trek2]
  1852.   jbe    @@pass4
  1853.   jmp    @@paint_slot
  1854. @@pass4:
  1855.   cmp    si,[word sel_area_pattern]
  1856.   je     @@pass5
  1857.   jmp    @@paint_slot
  1858. @@pass5:
  1859.   add    cl,50h
  1860. @@paint_slot:
  1861.   call   calc_data
  1862.   mov    edi,[_0b8000h]                           ; calc ofs
  1863.   add    edi,(4*2)+(2*160)
  1864.   xor    eax,eax
  1865.   mov    eax,160
  1866.   mul    ch
  1867.   add    edi,eax
  1868.   mov    eax,18
  1869.   mul    dl
  1870.   add    edi,eax
  1871.   mov    al,[byte esi]
  1872.   shr    al,2
  1873.   push   eax
  1874.   cmp    al,3Fh                                   ;IF FULL SLOT or SAMPLE
  1875.   je     @@display_nullslot
  1876.   mov    bx,[word esi]                            ; display sample no
  1877.   xchg   bl,bh
  1878.   shr    bx,4
  1879.   and    bl,03fh
  1880.   mov    ah,10
  1881.   add    ah,cl
  1882.   call   display_byte_f
  1883.   jmp    @@cont
  1884. @@display_nullslot:
  1885.   mov    ah,cl
  1886.   mov    al," "
  1887.   stosw
  1888.   stosw
  1889. @@cont:
  1890.   pop    ebx
  1891.   and    ebx,03fh                                 ; display note
  1892.   mov    ah,11
  1893.   add    ah,cl
  1894.   call   display_note_f
  1895.   mov    bx,[word esi+1]
  1896.   and    bl,1111b
  1897.   mov    ah,12
  1898.   add    ah,cl
  1899.   call   display_command_f
  1900.   ret
  1901. endp
  1902.  
  1903. ; cl = colour offset
  1904. proc display_slot
  1905.   push   ecx
  1906.   movzx  esi,[byte pat_number]
  1907.   mov    dl,[byte pat_old_chan]
  1908.   mov    dh,[byte pat_real]
  1909.   mov    ch,[byte pat_old_hl]
  1910.   add    dh,ch
  1911.   xor    cl,cl
  1912.   call   display_slot_f
  1913.   pop    ecx
  1914.   movzx  esi,[byte pat_number]
  1915.   mov    dl,[byte pat_chan]
  1916.   mov    dh,[byte pat_real]
  1917.   mov    ch,[byte pat_hl]
  1918.   add    dh,ch
  1919.   call   display_slot_f
  1920.   mov    ax,[word pat_hl]
  1921.   mov    [word pat_old_hl],ax
  1922.   ret
  1923. endp
  1924.  
  1925. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1926. ;                                                                          ;
  1927. ; esi = pattern number, dh = pattern real position                         ;
  1928. ;                                                                          ;
  1929. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1930. proc display_pattern
  1931.   mov    edi,[_0b8000h]
  1932.   add    edi,(1*2)+(2*160)
  1933.   xor    ch,ch
  1934. @@paint_treks:
  1935.   push   edi
  1936.   mov    ah,7
  1937.   mov    ebx,[funk_hr_ptr]
  1938.   mov    al,[byte esi+ebx+tfunk_hr.break_list]
  1939.   mov    bl,dh
  1940.   cmp    al,bl
  1941.   jne    @@pbbb
  1942.   mov    ah,14
  1943. @@pbbb:
  1944.   call   display_byte_f
  1945.   xor    dl,dl
  1946. @@paint_slots:
  1947.   push   esi
  1948.   xor    cl,cl
  1949.   call   display_slot_f
  1950.   pop    esi
  1951.   inc    dl
  1952.   cmp    dl,8
  1953.   jb     @@paint_slots
  1954.   pop    edi
  1955.   add    edi,160
  1956.   inc    dh
  1957.   inc    ch
  1958.   cmp    ch,32
  1959.   jb     @@paint_treks
  1960.   ret
  1961. endp
  1962.  
  1963. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1964. ;                                                                          ;
  1965. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1966. proc pat_scroll_up
  1967.   cmp    [byte pat_hl],0
  1968.   je     @@adj_real_bk
  1969.   dec    [byte pat_hl]
  1970.   jmp    @@end
  1971. @@adj_real_bk:
  1972.   cmp    [byte pat_real],0
  1973.   je     @@end
  1974.   dec    [byte pat_real]
  1975.   movzx  esi,[byte pat_number]
  1976.   mov    dh,[byte pat_real]
  1977.   call   display_pattern
  1978. @@end:
  1979.   mov    cl,20h
  1980.   call   display_slot
  1981.   ret
  1982. endp
  1983.  
  1984. proc pat_scroll_dn
  1985.   cmp    [byte pat_hl],31
  1986.   je     @@adj_real_fd
  1987.   inc    [byte pat_hl]
  1988.   jmp    @@end
  1989. @@adj_real_fd:
  1990.   cmp    [byte pat_real],(64-32)                  ; 32
  1991.   je     @@end
  1992.   inc    [byte pat_real]
  1993.   movzx  esi,[byte pat_number]
  1994.   mov    dh,[byte pat_real]
  1995.   call   display_pattern
  1996. @@end:
  1997.   mov    cl,20h
  1998.   call   display_slot
  1999.   ret
  2000. endp
  2001.  
  2002. proc pat_pageup
  2003.   mov    cl,16
  2004. @@scl:
  2005.   cmp    [byte pat_hl],0
  2006.   je     @@adj_real_bk
  2007.   dec    [byte pat_hl]
  2008.   jmp    @@end
  2009. @@adj_real_bk:
  2010.   cmp    [byte pat_real],0
  2011.   je     @@end
  2012.   dec    [byte pat_real]
  2013. @@end:
  2014.   dec    cl
  2015.   jnz    @@scl
  2016.   movzx  esi,[byte pat_number]
  2017.   mov    dh,[byte byte pat_real]
  2018.   call   display_pattern
  2019.   mov    cl,20h
  2020.   call   display_slot
  2021.   ret
  2022. endp
  2023.  
  2024. proc pat_pagedn
  2025.   mov    cl,16
  2026. @@scl:
  2027.   cmp    [byte pat_hl],31
  2028.   je     @@adj_real_fd
  2029.   inc    [byte pat_hl]
  2030.   jmp    @@end
  2031. @@adj_real_fd:
  2032.   cmp    [byte pat_real],(64-32)                  ; 32
  2033.   je     @@end
  2034.   inc    [byte pat_real]
  2035. @@end:
  2036.   dec    cl
  2037.   jnz    @@scl
  2038.   movzx  esi,[byte pat_number]
  2039.   mov    dh,[byte pat_real]
  2040.   call   display_pattern
  2041.   mov    cl,20h
  2042.   call   display_slot
  2043.   ret
  2044. endp
  2045.  
  2046. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2047. ;                                                                          ;
  2048. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2049. proc set_select_start
  2050.   mov    [byte sel_flag],1
  2051.   mov    al,[byte pat_number]
  2052.   mov    [byte sel_area_pattern],al
  2053.   mov    al,[byte pat_chan]
  2054.   mov    [byte sel_area_chan1],al
  2055.   mov    [byte sel_area_chan2],al
  2056.   mov    al,[byte pat_real]
  2057.   add    al,[byte pat_hl]
  2058.   mov    [byte sel_area_trek1],al
  2059.   mov    [byte sel_area_trek2],al
  2060.   movzx  esi,[byte pat_number]
  2061.   mov    dh,[byte pat_real]
  2062.   call   display_pattern
  2063.   mov    cl,20h
  2064.   call   display_slot
  2065.   ret
  2066. endp
  2067.  
  2068. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2069. ;                                                                          ;
  2070. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2071. proc set_select_end
  2072.   cmp    [byte sel_flag],0
  2073.   je     @@end
  2074.   mov    al,[byte pat_number]
  2075.   mov    [byte sel_area_pattern],al
  2076.   mov    al,[byte pat_chan]
  2077.   mov    [byte sel_area_chan2],al
  2078.   mov    al,[byte pat_real]
  2079.   add    al,[byte pat_hl]
  2080.   mov    [byte sel_area_trek2],al
  2081.   mov    al,[byte sel_area_chan1]
  2082.   cmp    al,[byte sel_area_chan2]
  2083.   jbe    @@test1
  2084.   xchg   al,[byte sel_area_chan2]
  2085.   mov    [byte sel_area_chan1],al
  2086. @@test1:
  2087.   mov    al,[byte sel_area_trek1]
  2088.   cmp    al,[byte sel_area_trek2]
  2089.   jbe    @@test2
  2090.   xchg   al,[byte sel_area_trek2]
  2091.   mov    [byte sel_area_trek1],al
  2092. @@test2:
  2093.   movzx  esi,[byte pat_number]
  2094.   mov    dh,[byte pat_real]
  2095.   call   display_pattern
  2096.   mov    cl,20h
  2097.   call   display_slot
  2098. @@end:
  2099.   ret
  2100. endp
  2101.  
  2102. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2103. ;                                                                          ;
  2104. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2105. proc copy_select
  2106.   cmp    [byte sel_flag],0
  2107.   je     @@end
  2108.   mov    [byte sel_flag],0
  2109.   mov    [byte copied_flag],1
  2110.   mov    eax,[dword sel_area_chan1]
  2111.   mov    [dword copied_area_chan1],eax
  2112.   movzx  esi,[byte pat_number]
  2113.   mov    eax,esi                                  ; bx * 600h
  2114.   shl    eax,10
  2115.   shl    esi,9
  2116.   add    esi,eax
  2117.   add    esi,[dword funk_hr_ptr]
  2118.   add    esi,size tfunk_hr
  2119.   lea    edi,[temp_pattern]
  2120.   mov    ecx,600h
  2121.   rep    movsb
  2122.   movzx  esi,[byte pat_number]
  2123.   mov    dh,[byte pat_real]
  2124.   call   display_pattern
  2125.   mov    cl,20h
  2126.   call   display_slot
  2127. @@end:
  2128.   ret
  2129. endp
  2130.  
  2131. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2132. ;                                                                          ;
  2133. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2134. proc paste_select
  2135.   cmp    [byte copied_flag],0
  2136.   je     @@end
  2137.   mov    dh,[byte copied_area_trek1]
  2138. @@copy_trek:
  2139.   mov    dl,[byte copied_area_chan1]
  2140. @@copy_slot:
  2141.   push   edx
  2142.   lea    edi,[temp_pattern]
  2143.   movzx  eax,dh
  2144.   mov    ebx,eax
  2145.   shl    eax,4
  2146.   shl    ebx,3
  2147.   add    edi,eax
  2148.   add    edi,ebx
  2149.   movzx  eax,dl
  2150.   lea    eax,[eax*2+eax]
  2151.   add    edi,eax
  2152.   sub    dh,[byte copied_area_trek1]
  2153.   sub    dl,[byte copied_area_chan1]
  2154.   add    dh,[byte pat_real]
  2155.   add    dh,[byte pat_hl]
  2156.   add    dl,[byte pat_chan]
  2157.   cmp    dl,7
  2158.   ja     @@ignore_paste
  2159.   cmp    dh,03fh
  2160.   ja     @@ignore_paste
  2161.   movzx  esi,[byte pat_number]
  2162.   call   calc_data
  2163.   mov    ax,[word edi]
  2164.   mov    bl,[byte edi+2]
  2165.   mov    [word esi],ax
  2166.   mov    [byte esi+2],bl
  2167. @@ignore_paste:
  2168.   pop    edx
  2169.   inc    dl
  2170.   cmp    dl,[copied_area_chan2]
  2171.   jbe    @@copy_slot
  2172.   inc    dh
  2173.   cmp    dh,[byte copied_area_trek2]
  2174.   jbe    @@copy_trek
  2175.   movzx  esi,[byte pat_number]
  2176.   mov    dh,[byte pat_real]
  2177.   call   display_pattern
  2178.   mov    cl,20h
  2179.   call   display_slot
  2180. @@end:
  2181.   ret
  2182. endp
  2183.  
  2184. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2185. ;                                                                          ;
  2186. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2187. proc clear_select
  2188.   cmp    [byte sel_flag],0
  2189.   je     @@end
  2190.   mov    [byte sel_flag],0
  2191.   mov    dh,[byte sel_area_trek1]
  2192. @@copy_trek:
  2193.   mov    dl,[byte sel_area_chan1]
  2194. @@copy_slot:
  2195.   push   edx
  2196.   movzx  esi,[byte pat_number]
  2197.   call   calc_data
  2198.   @mini_clear_slot
  2199. @@ignore_paste:
  2200.   pop    edx
  2201.   inc    dl
  2202.   cmp    dl,[sel_area_chan2]
  2203.   jbe    @@copy_slot
  2204.   inc    dh
  2205.   cmp    dh,[byte sel_area_trek2]
  2206.   jbe    @@copy_trek
  2207.   movzx  esi,[byte pat_number]
  2208.   mov    dh,[byte pat_real]
  2209.   call   display_pattern
  2210.   mov    cl,20h
  2211.   call   display_slot
  2212. @@end:
  2213.   ret
  2214. endp
  2215.  
  2216. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2217. ;                                                                          ;
  2218. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2219. ; dl = [byte pat_chan]
  2220. proc enter_slot_data
  2221.   movzx  esi,[byte pat_number]
  2222.   mov    dh,[byte pat_real]
  2223.   add    dh,[byte pat_hl]
  2224.   call   calc_data
  2225.   mov    al,[byte octave]
  2226.   mov    bl,al
  2227.   shl    al,3
  2228.   shl    bl,2
  2229.   add    al,bl
  2230.   add    al,[byte note]
  2231.   mov    [byte esi],al
  2232.   shl    [byte esi],2
  2233.   mov    al,[byte sam_real]
  2234.   add    al,[byte sam_hl]
  2235.   push   eax
  2236.   shr    al,4
  2237.   or     [byte esi],al
  2238.   pop    eax
  2239.   shl    al,4
  2240.   or     al,0fh
  2241.   mov    [byte esi+1],al
  2242.   mov    [byte esi+2],0
  2243.   ret
  2244. endp
  2245.  
  2246. proc quat_slot
  2247.   cmp    [MIDI.midi_status],PLAY
  2248.   je     @@end
  2249.   cmp    [byte MIDI_quantise],0
  2250.   je     @@end
  2251.   mov    al,8
  2252. @@nl:
  2253.   push   eax
  2254.   inc    [byte pat_chan]
  2255.   and    [byte pat_chan],7
  2256.   xor    ecx,ecx
  2257.   mov    cl,[byte pat_chan]
  2258.   mov    eax,size tfunk_chan
  2259.   mul    ecx
  2260.   mov    ecx,eax
  2261.   add    ecx,offset funk_chan1
  2262.  
  2263.   pop    eax
  2264.   cmp    [byte ecx+tfunk_chan.channel_kill],PLAY
  2265.   je     @@end
  2266.   dec    al
  2267.   jnz    @@nl
  2268. @@end:
  2269.   ret
  2270. endp
  2271.  
  2272. proc enter_slot
  2273.   cmp    [byte edit_mode],1
  2274.   je     @@pe
  2275.   call   quat_slot
  2276.   ret
  2277. @@pe:
  2278.   mov    dl,[byte pat_chan]
  2279.   call   enter_slot_data
  2280.   call   quat_slot
  2281.   call   pat_scroll_dn
  2282.   ret
  2283. endp
  2284.  
  2285. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2286. ;                                                                          ;
  2287. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2288. proc erase_slot
  2289.   movzx  esi,[byte pat_number]
  2290.   mov    dl,[byte pat_chan]
  2291.   mov    dh,[byte pat_real]
  2292.   add    dh,[byte pat_hl]
  2293.   call   calc_data
  2294.   @mini_clear_slot
  2295.   call   pat_scroll_dn
  2296.   ret
  2297. endp
  2298.  
  2299. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2300. ;                                                                          ;
  2301. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2302. proc insert_slot
  2303.   mov    dh,[byte pat_real]
  2304.   add    dh,[byte pat_hl]
  2305.   cmp    dh,03fh
  2306.   je     @@dont_ad
  2307.   movzx  esi,[byte pat_number]
  2308.   mov    dl,[byte pat_chan]
  2309.   mov    ch,dh
  2310.   mov    dh,03fh
  2311.   call   calc_data
  2312. @@add_loop:
  2313.   mov    ax,[word esi-24]
  2314.   mov    [word esi],ax
  2315.   mov    al,[byte esi-22]
  2316.   mov    [byte esi+2],al
  2317.   dec    dh
  2318.   sub    esi,24
  2319.   cmp    dh,ch
  2320.   ja     @@add_loop
  2321. @@dont_ad:
  2322.   movzx  esi,[byte pat_number]
  2323.   mov    dl,[byte pat_chan]
  2324.   mov    dh,[byte pat_real]
  2325.   add    dh,[byte pat_hl]
  2326.   call   calc_data
  2327.   @mini_clear_slot
  2328.   movzx  esi,[byte pat_number]
  2329.   mov    dh,[byte pat_real]
  2330.   call   display_pattern
  2331.   mov    cl,20h
  2332.   call   display_slot
  2333.   ret
  2334. endp
  2335.  
  2336. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2337. ;                                                                          ;
  2338. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2339. proc delete_slot
  2340.   movzx  esi,[byte pat_number]
  2341.   mov    dl,[byte pat_chan]
  2342.   mov    dh,[byte pat_real]
  2343.   add    dh,[byte pat_hl]
  2344.   call   calc_data
  2345.   cmp    dh,03fh
  2346.   je     @@dont_ad
  2347. @@del_loop:
  2348.   mov    ax,[word esi+24]
  2349.   mov    [word esi],ax
  2350.   mov    al,[byte esi+26]
  2351.   mov    [byte esi+2],al
  2352.   inc    dh
  2353.   add    esi,24
  2354.   cmp    dh,3fh
  2355.   jb     @@del_loop
  2356. @@dont_ad:
  2357.   @mini_clear_slot
  2358.   movzx  esi,[byte pat_number]
  2359.   mov    dh,[byte pat_real]
  2360.   call   display_pattern
  2361.   mov    cl,20h
  2362.   call   display_slot
  2363.   ret
  2364. endp
  2365.  
  2366. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2367. ;                                                                          ;
  2368. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2369. proc setto_ReLOad_slot
  2370.   movzx  esi,[byte pat_number]
  2371.   mov    dl,[byte pat_chan]
  2372.   mov    dh,[byte pat_real]
  2373.   add    dh,[byte pat_hl]
  2374.   call   calc_data
  2375.   @mini_clear_slot
  2376.   mov    [byte esi],0f4h
  2377.   call   pat_scroll_dn
  2378.   ret
  2379. endp
  2380.  
  2381. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2382. ;                                                                          ;
  2383. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2384. proc enter_sample
  2385.   mov    ch,2
  2386.   mov    dh,[byte pat_hl]
  2387.   add    dh,2
  2388.   mov    dl,[byte pat_chan]
  2389.   shl    dl,3
  2390.   add    dl,[byte pat_chan]
  2391.   add    dl,4
  2392.   call   get_input
  2393.   jc     @@abort
  2394.   movzx  esi,[byte pat_number]
  2395.   mov    dl,[byte pat_chan]
  2396.   mov    dh,[byte pat_real]
  2397.   add    dh,[byte pat_hl]
  2398.   call   calc_data
  2399.   call   get_ibyte
  2400.   cmp    al,40h
  2401.   jb     @@ovs
  2402.   xor    al,al
  2403. @@ovs:
  2404.   mov    bl,[byte esi]
  2405.   shr    bl,2
  2406.   cmp    bl,3fh
  2407.   je     @@con_sample_only
  2408.   and    [byte esi],11111100b
  2409.   jmp    @@set_sample
  2410. @@con_sample_only:
  2411.   mov    [byte esi],0f8h
  2412. @@set_sample:
  2413.   mov    bl,al
  2414.   shr    bl,4
  2415.   shl    al,4
  2416.   or     [byte esi],bl
  2417.   and    [byte esi+1],1111b
  2418.   or     [byte esi+1],al
  2419. @@abort:
  2420.   mov    cl,20h
  2421.   call   display_slot
  2422.   ret
  2423. endp
  2424.  
  2425. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2426. ;                                                                          ;
  2427. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2428. proc enter_command
  2429. @@repeat:
  2430.   mov    ch,3
  2431.   mov    dh,[byte pat_hl]
  2432.   add    dh,2
  2433.   mov    dl,[byte pat_chan]
  2434.   shl    dl,3
  2435.   add    dl,[byte pat_chan]
  2436.   add    dl,9
  2437.   call   get_input
  2438.   jc     @@abort
  2439.   movzx  esi,[byte pat_number]
  2440.   mov    dl,[byte pat_chan]
  2441.   mov    dh,[byte pat_real]
  2442.   add    dh,[byte pat_hl]
  2443.   call   calc_data
  2444.   cmp    [byte edi],"?"                                ; help function
  2445.   je     @@help
  2446.   jmp    @@cont
  2447. @@help:
  2448.   mov    ecx,comms_screen_size
  2449.   lea    esi,[comms_screen]
  2450.   call   help_scroll
  2451.   jmp    @@repeat
  2452. @@cont:
  2453.   xor    ebx,ebx
  2454. @@find_com_loop:
  2455.   mov    al,[byte ebx+@@coms_test1]
  2456.   cmp    al,[byte edi]
  2457.   je     @@com_found
  2458.   add    al,("a"-"A")
  2459.   cmp    al,[byte edi]
  2460.   je     @@com_found
  2461.   inc    ebx
  2462.   cmp    ebx,15
  2463.   jb     @@find_com_loop
  2464.   and    [byte esi+1],11110000b
  2465.   or     [byte esi+1],00001111b
  2466.   mov    [byte esi+2],0
  2467.   jmp    @@abort
  2468. @@com_found:
  2469.   and    [byte esi+1],11110000b
  2470.   or     [byte esi+1],bl
  2471.   add    edi,2
  2472.   call   get_ibyte
  2473.   mov    [byte esi+2],al
  2474. @@abort:
  2475.   mov    cl,20h
  2476.   call   display_slot
  2477.   ret
  2478. @@coms_test1:
  2479.   db     "ABCDEFGHIJKLMNO"
  2480. endp
  2481.  
  2482. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2483. ;                                                                          ;
  2484. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2485. proc display_seqlist
  2486.   mov    dl,[byte seq_real]
  2487.   add    dl,[byte seq_hl]
  2488.   shr    dl,3
  2489.   call   scroll_display32
  2490.   mov    edi,[_0b8000h]
  2491.   add    edi,(76*2)+(2*160)
  2492.   mov    esi,[funk_hr_ptr]
  2493.   xor    cl,cl
  2494. @@display_seq:
  2495.   push   edi
  2496.   mov    ah,7
  2497.   cmp    cl,[byte seq_hl]
  2498.   jne    @@pbbb
  2499.   mov    ah,14
  2500. @@pbbb:
  2501.   mov    bl,cl
  2502.   add    bl,[byte seq_real]
  2503.   cmp    bl,[byte esi+tfunk_hr.loop_order]
  2504.   jne    @@pbbb2
  2505.   dec    ah
  2506. @@pbbb2:
  2507.   xor    ebx,ebx
  2508.   mov    bl,[byte seq_real]
  2509.   add    bl,cl
  2510.   mov    bl,[byte ebx+esi+tfunk_hr.order_list]
  2511.   cmp    bl,0ffh
  2512.   je     @@display_null
  2513.   call   display_byte_f
  2514.   jmp    @@cont
  2515. @@display_null:
  2516.   mov    al,"-"
  2517.   stosw
  2518.   stosw
  2519. @@cont:
  2520.   pop    edi
  2521.   add    edi,160
  2522.   inc    cl
  2523.   cmp    cl,32
  2524.   jb     @@display_seq
  2525.   ret
  2526. endp
  2527.  
  2528. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2529. ;                                                                          ;
  2530. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2531. proc seq_scroll_up
  2532.   cmp    [byte seq_hl],0
  2533.   je     @@adj_real_bk
  2534.   dec    [byte seq_hl]
  2535.   jmp    @@end
  2536. @@adj_real_bk:
  2537.   cmp    [byte seq_real],0
  2538.   je     @@end
  2539.   dec    [byte seq_real]
  2540. @@end:
  2541.   call   display_seqlist
  2542.   ret
  2543. endp
  2544.  
  2545. proc seq_scroll_dn
  2546.   cmp    [byte seq_hl],31
  2547.   je     @@adj_real_fd
  2548.   inc    [byte seq_hl]
  2549.   jmp    @@end
  2550. @@adj_real_fd:
  2551.   cmp    [byte seq_real],(256-32)
  2552.   je     @@end
  2553.   inc    [byte seq_real]
  2554. @@end:
  2555.   call   display_seqlist
  2556.   ret
  2557. endp
  2558.  
  2559. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2560. ;                                                                          ;
  2561. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2562. proc seq_add
  2563.   mov    esi,[funk_hr_ptr]
  2564.   xor    edx,edx
  2565.   mov    dl,[byte seq_real]
  2566.   add    dl,[byte seq_hl]
  2567.   cmp    dl,0ffh
  2568.   je     @@dont_ad
  2569.   mov    ebx,0ffh
  2570. @@add_loop:
  2571.   mov    al,[byte esi+ebx+(offset(tfunk_hr).order_list-1)]
  2572.   mov    [byte esi+ebx+tfunk_hr.order_list],al
  2573.   dec    ebx
  2574.   cmp    ebx,edx
  2575.   ja     @@add_loop
  2576. @@dont_ad:
  2577.   mov    al,[byte pat_number]
  2578.   mov    [byte esi+edx+tfunk_hr.order_list],al
  2579.   call   seq_scroll_dn
  2580.   ret
  2581. endp
  2582.  
  2583. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2584. ;                                                                          ;
  2585. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2586. proc seq_del
  2587.   call   seq_scroll_up
  2588.   mov    esi,[funk_hr_ptr]
  2589.   xor    ebx,ebx
  2590.   mov    bl,[byte seq_real]
  2591.   add    bl,[byte seq_hl]
  2592.   cmp    bl,0ffh
  2593.   je     @@dont_ad
  2594. @@del_loop:
  2595.   mov    al,[byte esi+ebx+(offset (tfunk_hr).order_list+1)]
  2596.   mov    [byte esi+ebx+tfunk_hr.order_list],al
  2597.   inc    ebx
  2598.   cmp    ebx,0ffh
  2599.   jb     @@del_loop
  2600. @@dont_ad:
  2601.   mov    [byte esi+ebx+tfunk_hr.order_list],0ffh
  2602.   call   display_seqlist
  2603.   ret
  2604. endp
  2605.  
  2606. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2607. ;                                                                          ;
  2608. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2609. proc dis_sample_name
  2610.   mov    edi,(17*2)+(36*160)
  2611.   mov    bl,[byte sam_hl]
  2612.   add    bl,[byte sam_real]
  2613.   mov    ah,13h
  2614.   call   display_byte
  2615.   mov    al,[byte sam_hl]
  2616.   add    al,[byte sam_real]
  2617.   movzx  esi,al
  2618.   shl    esi,5
  2619.   add    esi,[funk_hr_ptr]
  2620.   add    esi,offset (tfunk_hr).funk_sb
  2621.   mov    edi,(20*2)+(36*160)
  2622.   mov    cl,19
  2623.   mov    ah,13h
  2624.   call   byte_write2
  2625. endp
  2626.  
  2627. proc dis_pattern_no
  2628.   mov    edi,(55*2)+(36*160)
  2629.   mov    bl,[byte pat_number]
  2630.   mov    ah,13h
  2631.   call   display_byte
  2632.   mov    edi,(1*2)+(1*160)
  2633.   mov    bl,[byte pat_number]
  2634.   mov    ah,0fh
  2635.   call   display_byte
  2636.   ret
  2637. endp
  2638.  
  2639. proc dis_order_loop
  2640.   mov    edi,(17*2)+(37*160)
  2641.   mov    eax,[funk_hr_ptr]
  2642.   mov    bl,[byte eax+tfunk_hr.loop_order]
  2643.   mov    ah,13h
  2644.   call   display_byte
  2645.   ret
  2646. endp
  2647.  
  2648. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2649. ;                                                                          ;
  2650. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2651. proc edit_order_loop
  2652.   mov    al,[byte seq_real]
  2653.   add    al,[byte seq_hl]
  2654.   mov    ebx,[funk_hr_ptr]
  2655.   mov    [byte ebx+tfunk_hr.loop_order],al
  2656.   call   display_seqlist
  2657.   call   dis_order_loop
  2658.   ret
  2659. endp
  2660.  
  2661. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2662. ;                                                                          ;
  2663. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2664. proc dis_chan_status
  2665.   mov    edi,[_0b8000h]
  2666.   add    edi,(7*2)+(1*160)+1
  2667.  
  2668.   lea    esi,[funk_chan1]
  2669.   mov    cl,8
  2670. @@discs:
  2671.   mov    al,07h
  2672.   cmp    [byte esi+tfunk_chan.channel_kill],PLAY
  2673.   jne    @@dont_ad
  2674.   mov    al,0ch
  2675. @@dont_ad:
  2676.   mov    [byte edi],al
  2677.   mov    [byte edi+2],al
  2678.   add    esi,size tfunk_chan
  2679.   add    edi,9*2
  2680.   dec    cl
  2681.   jnz    @@discs
  2682.   ret
  2683. endp
  2684.  
  2685. proc channel_toggle
  2686.   cmp    al,"1"
  2687.   je     @@toggle1
  2688.   cmp    al,"2"
  2689.   je     @@toggle2
  2690.   cmp    al,"3"
  2691.   je     @@toggle3
  2692.   cmp    al,"4"
  2693.   je     @@toggle4
  2694.   cmp    al,"5"
  2695.   je     @@toggle5
  2696.   cmp    al,"6"
  2697.   je     @@toggle6
  2698.   cmp    al,"7"
  2699.   je     @@toggle7
  2700.   cmp    al,"8"
  2701.   je     @@toggle8
  2702.   ret
  2703. @@toggle1:
  2704.   xor    [byte funk_chan1.channel_kill],PLAY
  2705.   mov    edi,offset funk_chan1
  2706.   call   [dword CARD_volume_convert]
  2707.   call   dis_chan_status
  2708.   ret
  2709. @@toggle2:
  2710.   xor    [byte funk_chan2.channel_kill],PLAY
  2711.   mov    edi,offset funk_chan2
  2712.   call   [dword CARD_volume_convert]
  2713.   call   dis_chan_status
  2714.   ret
  2715. @@toggle3:
  2716.   xor    [byte funk_chan3.channel_kill],PLAY
  2717.   mov    edi,offset funk_chan3
  2718.   call   [dword CARD_volume_convert]
  2719.   call   dis_chan_status
  2720.   ret
  2721. @@toggle4:
  2722.   xor    [byte funk_chan4.channel_kill],PLAY
  2723.   mov    edi,offset funk_chan4
  2724.   call   [dword CARD_volume_convert]
  2725.   call   dis_chan_status
  2726.   ret
  2727. @@toggle5:
  2728.   xor    [byte funk_chan5.channel_kill],PLAY
  2729.   mov    edi,offset funk_chan5
  2730.   call   [dword CARD_volume_convert]
  2731.   call   dis_chan_status
  2732.   ret
  2733. @@toggle6:
  2734.   xor    [byte funk_chan6.channel_kill],PLAY
  2735.   mov    edi,offset funk_chan6
  2736.   call   [dword CARD_volume_convert]
  2737.   call   dis_chan_status
  2738.   ret
  2739. @@toggle7:
  2740.   xor    [byte funk_chan7.channel_kill],PLAY
  2741.   mov    edi,offset funk_chan7
  2742.   call   [dword CARD_volume_convert]
  2743.   call   dis_chan_status
  2744.   ret
  2745. @@toggle8:
  2746.   xor    [byte funk_chan8.channel_kill],PLAY
  2747.   mov    edi,offset funk_chan8
  2748.   call   [dword CARD_volume_convert]
  2749.   call   dis_chan_status
  2750.   ret
  2751. endp
  2752.  
  2753. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2754. ;                                                                          ;
  2755. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2756. proc pe_handle
  2757.   cmp    ax,kb_up
  2758.   je     @@hkb_up
  2759.   cmp    ax,kb_down
  2760.   je     @@hkb_down
  2761.   cmp    ax,kb_left
  2762.   je     @@hkb_left
  2763.   cmp    ax,kb_right
  2764.   je     @@hkb_right
  2765.   push   eax
  2766.   call   mus_kb_input
  2767.   pop    eax
  2768.   cmp    ax,kb_altb
  2769.   je     @@select_start
  2770.   cmp    ax,kb_alte
  2771.   je     @@select_end
  2772.   cmp    ax,kb_altc
  2773.   je     @@copy_sel
  2774.   cmp    ax,kb_alto
  2775.   je     @@paste_sel
  2776.   cmp    ax,kb_altz
  2777.   je     @@clear_sel
  2778.   cmp    al," "
  2779.   je     @@erase_slot
  2780.   cmp    al,"/"
  2781.   je     @@dec_oct
  2782.   cmp    al,"*"
  2783.   je     @@inc_oct
  2784.   cmp    al,"-"
  2785.   je     @@dec_pat
  2786.   cmp    al,"+"
  2787.   je     @@inc_pat
  2788.   cmp    al,13
  2789.   je     @@set_bp
  2790.   cmp    al,"'"
  2791.   je     @@set_RLO
  2792.   cmp    al,"["
  2793.   je     @@edits
  2794.   cmp    al,"]"
  2795.   je     @@editc
  2796.   cmp    ax,kb_home
  2797.   je     @@hkb_home
  2798.   cmp    ax,kb_end
  2799.   je     @@hkb_end
  2800.   cmp    al,"9"
  2801.   je     @@seqadd
  2802.   cmp    al,"0"
  2803.   je     @@seqdel
  2804.   cmp    ax,kb_pageup
  2805.   je     @@hkb_pageup
  2806.   cmp    ax,kb_pagedn
  2807.   je     @@hkb_pagedn
  2808.   cmp    ax,kb_insert
  2809.   je     @@insert_slot
  2810.   cmp    ax,kb_delete
  2811.   je     @@delete_slot
  2812.   cmp    al,'p'
  2813.   je     @@inc_sam
  2814.   cmp    al,'o'
  2815.   je     @@dec_sam
  2816.   cmp    ax,kb_alts
  2817.   je     @@edit_ol
  2818.   call   channel_toggle
  2819.   jmp    @@input_loop
  2820. @@hkb_up:
  2821.   call   pat_scroll_up
  2822.   jmp    @@input_loop
  2823. @@hkb_down:
  2824.   call   pat_scroll_dn
  2825.   jmp    @@input_loop
  2826. @@hkb_left:
  2827.   cmp    [byte pat_chan],0
  2828.   je     @@input_loop
  2829.   dec    [byte pat_chan]
  2830.   mov    cl,20h
  2831.   call   display_slot
  2832.   jmp    @@input_loop
  2833. @@hkb_right:
  2834.   cmp    [byte pat_chan],7
  2835.   je     @@input_loop
  2836.   inc    [byte pat_chan]
  2837.   mov    cl,20h
  2838.   call   display_slot
  2839.   jmp    @@input_loop
  2840. @@select_start:
  2841.   call   set_select_start
  2842.   jmp    @@input_loop
  2843. @@select_end:
  2844.   call   set_select_end
  2845.   jmp    @@input_loop
  2846. @@copy_sel:
  2847.   call   copy_select
  2848.   jmp    @@input_loop
  2849. @@paste_sel:
  2850.   call   paste_select
  2851.   jmp    @@input_loop
  2852. @@clear_sel:
  2853.   call   clear_select
  2854.   jmp    @@input_loop
  2855. @@erase_slot:
  2856.   call   erase_slot
  2857.   jmp    @@input_loop
  2858. @@dec_oct:
  2859.   cmp    [byte octave],0
  2860.   je     @@input_loop
  2861.   dec    [byte octave]
  2862.   call   update_octave
  2863.   jmp    @@input_loop
  2864. @@inc_oct:
  2865.   cmp    [byte octave],4
  2866.   je     @@input_loop
  2867.   inc    [byte octave]
  2868.   call   update_octave
  2869.   jmp    @@input_loop
  2870. @@dec_pat:
  2871.   cmp    [byte pat_number],0
  2872.   je     @@input_loop
  2873.   dec    [byte pat_number]
  2874.   call   dis_pattern_no
  2875.   movzx  esi,[byte pat_number]
  2876.   mov    dh,[byte pat_real]
  2877.   call   display_pattern
  2878.   mov    cl,20h
  2879.   call   display_slot
  2880.   jmp    @@input_loop
  2881. @@inc_pat:
  2882.   mov    al,[funk_info.funk_pd_size]
  2883.   dec    al
  2884.   cmp    [byte pat_number],al
  2885.   je     @@input_loop
  2886.   inc    [byte pat_number]
  2887.   call   dis_pattern_no
  2888.   movzx  esi,[byte pat_number]
  2889.   mov    dh,[byte pat_real]
  2890.   call   display_pattern
  2891.   mov    cl,20h
  2892.   call   display_slot
  2893.   jmp    @@input_loop
  2894. @@set_bp:
  2895.   mov    al,[byte pat_real]
  2896.   add    al,[byte pat_hl]
  2897.   xor    ebx,ebx
  2898.   mov    bl,[byte pat_number]
  2899.   add    ebx,[funk_hr_ptr]
  2900.   mov    [byte ebx+tfunk_hr.break_list],al
  2901.   movzx  esi,[byte pat_number]
  2902.   mov    dh,[byte pat_real]
  2903.   call   display_pattern
  2904.   mov    cl,20h
  2905.   call   display_slot
  2906.   jmp    @@input_loop
  2907. @@set_RLO:
  2908.   call   setto_ReLOad_slot
  2909.   jmp    @@input_loop
  2910. @@edits:
  2911.   call   enter_sample
  2912.   jmp    @@input_loop
  2913. @@editc:
  2914.   call   enter_command
  2915.   jmp    @@input_loop
  2916. @@hkb_home:
  2917.   call   seq_scroll_up
  2918.   jmp    @@input_loop
  2919. @@hkb_end:
  2920.   call   seq_scroll_dn
  2921.   jmp    @@input_loop
  2922. @@seqadd:
  2923.   call   seq_add
  2924.   jmp    @@input_loop
  2925. @@seqdel:
  2926.   call   seq_del
  2927.   jmp    @@input_loop
  2928. @@hkb_pageup:
  2929.   call   pat_pageup
  2930.   jmp    @@input_loop
  2931. @@hkb_pagedn:
  2932.   call   pat_pagedn
  2933.   jmp    @@input_loop
  2934. @@insert_slot:
  2935.   call   insert_slot
  2936.   jmp    @@input_loop
  2937. @@delete_slot:
  2938.   call   delete_slot
  2939.   jmp    @@input_loop
  2940. @@inc_sam:
  2941.   call   sam_scroll_dn
  2942.   call   dis_sample_name
  2943.   jmp    @@input_loop
  2944. @@dec_sam:
  2945.   call   sam_scroll_up
  2946.   call   dis_sample_name
  2947.   jmp    @@input_loop
  2948. @@edit_ol:
  2949.   call   edit_order_loop
  2950. @@input_loop:
  2951.   ret
  2952. endp
  2953.  
  2954. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2955. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2956. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2957. ;                                                                          ;
  2958. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2959. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2960. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2961.  
  2962. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2963. ;                                                                          ;
  2964. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2965. macro @hl_field n
  2966. local @@dont_hl
  2967.   mov    ah,03h
  2968.   mov    cl,[byte @@line]
  2969.   cmp    cl,[byte sam_hl]
  2970.   jne    @@dont_hl
  2971.   mov    ah,03bh
  2972.   cmp    [byte sam_col],n
  2973.   jne    @@dont_hl
  2974.   add    ah,11h
  2975. @@dont_hl:
  2976. endm
  2977.  
  2978. proc display_samples
  2979.   mov    dl,[byte sam_real]
  2980.   add    dl,[byte sam_hl]
  2981.   shr    dl,1
  2982.   call   scroll_display32
  2983.   mov    [byte @@line],0
  2984.   xor    edx,edx
  2985.   movzx  esi,[byte sam_real]
  2986.   shl    esi,5
  2987.   add    esi,[funk_hr_ptr]
  2988.   add    esi,offset (tfunk_hr).funk_sb
  2989. @@display_treks:
  2990.   mov    ah,03h
  2991.   mov    cl,[byte @@line]
  2992.   cmp    cl,[byte sam_hl]
  2993.   jne    @@dont_hl
  2994.   mov    ah,03bh
  2995. @@dont_hl:
  2996.   mov    edi,(3*2)+(2*160)
  2997.   add    edi,edx
  2998.   mov    bl,[byte @@line]
  2999.   add    bl,[byte sam_real]
  3000.   call   display_byte
  3001.   @hl_field 0
  3002.   push   esi
  3003.   mov    edi,(8*2)+(2*160)
  3004.   add    edi,edx
  3005.   add    edi,[_0b8000h]
  3006.   mov    ch,19
  3007.   lea    esi,[esi+tfunk_sb.sname]
  3008. @@dis_sname:
  3009.   lodsb
  3010.   stosw
  3011.   dec    ch
  3012.   jnz    @@dis_sname
  3013.   pop    esi
  3014.   @hl_field 1
  3015.   mov    edi,(29*2)+(2*160)
  3016.   add    edi,edx
  3017.   mov    ecx,[dword esi+tfunk_sb.start]
  3018.   call   display_dword
  3019.   mov    edi,(39*2)+(2*160)
  3020.   add    edi,edx
  3021.   mov    ecx,[dword esi+tfunk_sb.length]
  3022.   call   display_dword
  3023.   @hl_field 2
  3024.   mov    edi,(49*2)+(2*160)
  3025.   add    edi,edx
  3026.   mov    bl,[byte esi+tfunk_sb.volume]
  3027.   call   display_byte
  3028.   @hl_field 3
  3029.   mov    edi,(53*2)+(2*160)
  3030.   add    edi,edx
  3031.   mov    bl,[byte esi+tfunk_sb.balance]
  3032.   call   display_byte
  3033.   @hl_field 4
  3034.   mov    edi,(57*2)+(2*160)
  3035.   add    edi,edx
  3036.   mov    bl,[byte esi+tfunk_sb.pt_and_sop]
  3037.   shr    bl,4
  3038.   call   display_nibble
  3039.   @hl_field 5
  3040.   mov    edi,(60*2)+(2*160)
  3041.   add    edi,edx
  3042.   mov    bl,[byte esi+tfunk_sb.pt_and_sop]
  3043.   call   display_nibble
  3044.   @hl_field 6
  3045.   mov    edi,(63*2)+(2*160)
  3046.   add    edi,edx
  3047.   mov    bl,[byte esi+tfunk_sb.vv_waveform]
  3048.   shr    bl,4
  3049.   call   display_nibble
  3050.   @hl_field 7
  3051.   mov    edi,(66*2)+(2*160)
  3052.   add    edi,edx
  3053.   mov    bl,[byte esi+tfunk_sb.vv_waveform]
  3054.   call   display_nibble
  3055.   @hl_field 8
  3056.   mov    edi,(69*2)+(2*160)
  3057.   add    edi,edx
  3058.   mov    bl,[byte esi+tfunk_sb.rl_and_as]
  3059.   shr    bl,4
  3060.   call   display_nibble
  3061.   @hl_field 9
  3062.   mov    edi,(72*2)+(2*160)
  3063.   add    edi,edx
  3064.   mov    bl,[byte esi+tfunk_sb.rl_and_as]
  3065.   call   display_nibble
  3066.   add    esi,size tfunk_sb
  3067.   add    edx,160
  3068.   inc    [byte @@line]
  3069.   cmp    [byte @@line],32
  3070.   jb     @@display_treks
  3071.   ret
  3072. @@line:
  3073.   db     ?
  3074. endp
  3075.  
  3076. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3077. ;                                                                          ;
  3078. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3079. proc sam_scroll_up
  3080.   cmp    [byte sam_hl],0
  3081.   je     @@adj_real_bk
  3082.   dec    [byte sam_hl]
  3083.   jmp    @@end
  3084. @@adj_real_bk:
  3085.   cmp    [byte sam_real],0
  3086.   je     @@end
  3087.   dec    [byte sam_real]
  3088. @@end:
  3089.   ret
  3090. endp
  3091.  
  3092. proc sam_scroll_dn
  3093.   cmp    [byte sam_hl],31
  3094.   je     @@adj_real_fd
  3095.   inc    [byte sam_hl]
  3096.   jmp    @@end
  3097. @@adj_real_fd:
  3098.   cmp    [byte sam_real],(64-32)
  3099.   je     @@end
  3100.   inc    [byte sam_real]
  3101. @@end:
  3102.   ret
  3103. endp
  3104.  
  3105. proc sam_pageup
  3106.   mov    cl,16
  3107. @@sp:
  3108.   call   sam_scroll_up
  3109.   dec    cl
  3110.   jnz    @@sp
  3111.   ret
  3112. endp
  3113.  
  3114. proc sam_pagedn
  3115.   mov    cl,16
  3116. @@sp:
  3117.   call   sam_scroll_dn
  3118.   dec    cl
  3119.   jnz    @@sp
  3120.   ret
  3121. endp
  3122.  
  3123. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3124. ;                                                                          ;
  3125. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3126. proc sam_ins_nd
  3127.   mov    dl,[byte sam_real]
  3128.   add    dl,[byte sam_hl]
  3129.   movzx  edx,dl
  3130.   cmp    edx,3fh
  3131.   je     @@dont_ad
  3132.   mov    edi,03fh
  3133. @@add_loop:
  3134.   push   edi
  3135.   shl    edi,5
  3136.   add    edi,[funk_hr_ptr]
  3137.   add    edi,offset (tfunk_hr).funk_sb
  3138.   mov    esi,edi
  3139.   sub    esi,size tfunk_sb
  3140.   mov    ecx,size tfunk_sb
  3141.   rep    movsb
  3142.   pop    edi
  3143.   dec    edi
  3144.   cmp    edi,edx
  3145.   ja     @@add_loop
  3146. @@dont_ad:
  3147.   mov    edi,edx
  3148.   shl    edi,5
  3149.   add    edi,[funk_hr_ptr]
  3150.   add    edi,offset (tfunk_hr).funk_sb
  3151.   mov    al,20h
  3152.   mov    ecx,19
  3153.   rep    stosb
  3154.   sub    edi,19
  3155.   mov    [dword edi+tfunk_sb.start],0ffffffffh
  3156.   mov    [dword edi+tfunk_sb.length],0
  3157.   mov    [byte edi+tfunk_sb.balance],80h
  3158.   mov    [byte edi+tfunk_sb.volume],0ffh
  3159.   mov    [byte edi+tfunk_sb.pt_and_sop],08h
  3160.   mov    [byte edi+tfunk_sb.vv_waveform],0
  3161.   mov    [byte edi+tfunk_sb.rl_and_as],43h
  3162.   mov    bl,[byte sam_real]
  3163.   add    bl,[byte sam_hl]
  3164.   movzx  ebx,dl
  3165.   lea    ebx,[ebx*2]
  3166.   mov    [dword ebx+funk_info.sample_ptrs],0
  3167.   call   resync_sample_ptrs
  3168.   ret
  3169. endp
  3170.  
  3171. proc sam_ins
  3172.   call   stop_all_voices
  3173.   @splash_on_sm  "Rearranging memory, please wait"
  3174.   call   sam_ins_nd
  3175.   call   display_samples
  3176.   call   display_s_info
  3177.   @splash_off_sm
  3178.   ret
  3179. endp
  3180.  
  3181. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3182. ;                                                                          ;
  3183. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3184. proc del_sample
  3185.   mov    dl,[byte sam_real]
  3186.   add    dl,[byte sam_hl]
  3187.   movzx  edx,dl
  3188.   mov    ebx,edx
  3189.   lea    ebx,[ebx*4]
  3190.   shl    edx,5
  3191.   add    edx,[funk_hr_ptr]
  3192.   add    edx,offset (tfunk_hr).funk_sb
  3193.   mov    ecx,[dword funk_info.sample_block_size]
  3194.   sub    ecx,[dword edx+tfunk_sb.length]
  3195.   sub    ecx,[dword ebx+funk_info.sample_ptrs]
  3196.   inc    ecx
  3197.   mov    edi,[dword ebx+funk_info.sample_ptrs]
  3198.   mov    esi,edi
  3199.   add    esi,[dword edx+tfunk_sb.length]
  3200.   mov    al,[byte init_settings.card_type]
  3201.   cmp    al,SB_CARD
  3202.   je     @@DAC_CARD
  3203.   cmp    al,SBPRO_CARD
  3204.   je     @@DAC_CARD
  3205.   cmp    al,GUS_VARB_CARD
  3206.   je     @@GUS_CARD
  3207.   cmp    al,SB15EM_CARD
  3208.   je     @@DAC_CARD
  3209.   cmp    al,SB16_CARD
  3210.   je     @@DAC_CARD
  3211.   cmp    al,GUS_FIXB_CARD
  3212.   je     @@GUS_CARD
  3213.   cmp    al,PAS16_CARD
  3214.   je     @@DAC_CARD
  3215.   ret
  3216. @@DAC_CARD:
  3217.   rep    movsb
  3218.   ret
  3219. @@GUS_CARD:
  3220.   push   esi edi ecx
  3221.   call   GUS_reset
  3222.   pop    ecx edi esi
  3223. @@GUS_loop:
  3224.   call   GUS_mem_in
  3225.   call   GUS_mem_out
  3226.   inc    esi
  3227.   inc    edi
  3228.   dec    ecx
  3229.   jnz    @@GUS_loop
  3230.   call   GUS_reset
  3231.   call   GUS_intready
  3232.   ret
  3233. endp
  3234.  
  3235. proc sam_del_nd
  3236.   call   del_sample
  3237.   mov    dl,[byte sam_real]
  3238.   add    dl,[byte sam_hl]
  3239.   movzx  edi,dl
  3240.   cmp    edi,3fh
  3241.   je     @@dont_ad
  3242. @@del_loop:
  3243.   push   edi
  3244.   shl    edi,5
  3245.   add    edi,[funk_hr_ptr]
  3246.   add    edi,offset (tfunk_hr).funk_sb
  3247.   mov    esi,edi
  3248.   add    esi,size tfunk_sb
  3249.   mov    ecx,size tfunk_sb
  3250.   rep    movsb
  3251.   pop    edi
  3252.   inc    edi
  3253.   cmp    edi,3fh
  3254.   jb     @@del_loop
  3255. @@dont_ad:
  3256.   shl    edi,5
  3257.   add    edi,[funk_hr_ptr]
  3258.   add    edi,offset (tfunk_hr).funk_sb
  3259.   mov    al,20h
  3260.   mov    ecx,19
  3261.   rep    stosb
  3262.   sub    edi,19
  3263.   mov    [dword edi+tfunk_sb.start],0ffffffffh
  3264.   mov    [dword edi+tfunk_sb.length],0
  3265.   mov    [byte edi+tfunk_sb.balance],80h
  3266.   mov    [byte edi+tfunk_sb.volume],0ffh
  3267.   mov    [byte edi+tfunk_sb.pt_and_sop],08h
  3268.   mov    [byte edi+tfunk_sb.vv_waveform],0
  3269.   mov    [byte edi+tfunk_sb.rl_and_as],43h
  3270.   call   resync_sample_ptrs
  3271.   ret
  3272. endp
  3273.  
  3274. proc sam_del
  3275.   call   stop_all_voices
  3276.   @splash_on_sm  "Rearranging memory, please wait"
  3277.   call   sam_del_nd
  3278.   call   display_samples
  3279.   call   display_s_info
  3280.   @splash_off_sm
  3281.   ret
  3282. endp
  3283.  
  3284. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3285. ;                                                                          ;
  3286. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3287. proc edit_sname
  3288.   mov    ch,19
  3289.   mov    dh,[byte sam_hl]
  3290.   add    dh,2
  3291.   mov    dl,8
  3292.   call   get_input
  3293.   jc     @@abort
  3294.   mov    al,[byte sam_real]
  3295.   add    al,[byte sam_hl]
  3296.   movzx  esi,al
  3297.   shl    esi,5
  3298.   add    esi,[funk_hr_ptr]
  3299.   add    esi,offset (tfunk_hr).funk_sb
  3300.   mov    cl,19
  3301.   call   get_string
  3302. @@abort:
  3303.   call   display_samples
  3304.   ret
  3305. endp
  3306.  
  3307. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3308. ;                                                                          ;
  3309. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3310. proc edit_sstart
  3311.   mov    ch,8
  3312.   mov    dh,[byte sam_hl]
  3313.   add    dh,2
  3314.   mov    dl,29
  3315.   call   get_input
  3316.   jc     @@abort
  3317.   call   get_idword
  3318.   mov    al,[byte sam_real]
  3319.   add    al,[byte sam_hl]
  3320.   movzx  esi,al
  3321.   shl    esi,5
  3322.   add    esi,[funk_hr_ptr]
  3323.   add    esi,offset (tfunk_hr).funk_sb
  3324.   mov    [dword esi+tfunk_sb.start],ebx
  3325. @@abort:
  3326.   call   display_samples
  3327.   ret
  3328. endp
  3329.  
  3330. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3331. ;                                                                          ;
  3332. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3333. proc edit_svolume
  3334.   mov    ch,2
  3335.   mov    dh,[byte sam_hl]
  3336.   add    dh,2
  3337.   mov    dl,49
  3338.   call   get_input
  3339.   jc     @@abort
  3340.   call   get_ibyte
  3341.   mov    bl,[byte sam_real]
  3342.   add    bl,[byte sam_hl]
  3343.   movzx  esi,bl
  3344.   shl    esi,5
  3345.   add    esi,[funk_hr_ptr]
  3346.   add    esi,offset (tfunk_hr).funk_sb
  3347.   mov    [byte esi+tfunk_sb.volume],al
  3348. @@abort:
  3349.   call   display_samples
  3350.   ret
  3351. endp
  3352.  
  3353. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3354. ;                                                                          ;
  3355. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3356. proc edit_sbalance
  3357.   mov    ch,2
  3358.   mov    dh,[byte sam_hl]
  3359.   add    dh,2
  3360.   mov    dl,53
  3361.   call   get_input
  3362.   jc     @@abort
  3363.   call   get_ibyte
  3364.   mov    bl,[byte sam_real]
  3365.   add    bl,[byte sam_hl]
  3366.   movzx  esi,bl
  3367.   shl    esi,5
  3368.   add    esi,[funk_hr_ptr]
  3369.   add    esi,offset (tfunk_hr).funk_sb
  3370.   mov    [byte esi+tfunk_sb.balance],al
  3371. @@abort:
  3372.   call   display_samples
  3373.   ret
  3374. endp
  3375.  
  3376. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3377. ;                                                                          ;
  3378. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3379. proc edit_port_type
  3380.   mov    ch,1
  3381.   mov    dh,[byte sam_hl]
  3382.   add    dh,2
  3383.   mov    dl,57
  3384.   call   get_input
  3385.   jc     @@abort
  3386.   call   get_inib
  3387.   cmp    bl,1
  3388.   jbe    @@dont_adjust
  3389.   mov    bl,1
  3390. @@dont_adjust:
  3391.   mov    al,[byte sam_real]
  3392.   add    al,[byte sam_hl]
  3393.   movzx  esi,al
  3394.   shl    esi,5
  3395.   add    esi,[funk_hr_ptr]
  3396.   add    esi,offset (tfunk_hr).funk_sb
  3397.   shl    bl,4
  3398.   and    [byte esi+tfunk_sb.pt_and_sop],1111b
  3399.   or     [byte esi+tfunk_sb.pt_and_sop],bl
  3400. @@abort:
  3401.   call   display_samples
  3402.   ret
  3403. endp
  3404.  
  3405. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3406. ;                                                                          ;
  3407. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3408. proc edit_ssample_op
  3409.   mov    ch,1
  3410.   mov    dh,[byte sam_hl]
  3411.   add    dh,2
  3412.   mov    dl,60
  3413.   call   get_input
  3414.   jc     @@abort
  3415.   call   get_inib
  3416.   mov    al,[byte sam_real]
  3417.   add    al,[byte sam_hl]
  3418.   movzx  esi,al
  3419.   shl    esi,5
  3420.   add    esi,[funk_hr_ptr]
  3421.   add    esi,offset (tfunk_hr).funk_sb
  3422.   and    [byte esi+tfunk_sb.pt_and_sop],11110000b
  3423.   or     [byte esi+tfunk_sb.pt_and_sop],bl
  3424. @@abort:
  3425.   call   display_samples
  3426.   ret
  3427. endp
  3428.  
  3429. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3430. ;                                                                          ;
  3431. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3432. proc edit_svwt
  3433.   mov    ch,1
  3434.   mov    dh,[byte sam_hl]
  3435.   add    dh,2
  3436.   mov    dl,63
  3437.   call   get_input
  3438.   jc     @@abort
  3439.   call   get_inib
  3440.   cmp    bl,4
  3441.   jbe    @@dont_adjust
  3442.   mov    bl,4
  3443. @@dont_adjust:
  3444.   mov    al,[byte sam_real]
  3445.   add    al,[byte sam_hl]
  3446.   movzx  esi,al
  3447.   shl    esi,5
  3448.   add    esi,[funk_hr_ptr]
  3449.   add    esi,offset (tfunk_hr).funk_sb
  3450.   shl    bl,4
  3451.   and    [byte esi+tfunk_sb.vv_waveform],1111b
  3452.   or     [byte esi+tfunk_sb.vv_waveform],bl
  3453. @@abort:
  3454.   call   display_samples
  3455.   ret
  3456. endp
  3457.  
  3458. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3459. ;                                                                          ;
  3460. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3461. proc edit_svvwt
  3462.   mov    ch,1
  3463.   mov    dh,[byte sam_hl]
  3464.   add    dh,2
  3465.   mov    dl,66
  3466.   call   get_input
  3467.   jc     @@abort
  3468.   call   get_inib
  3469.   cmp    bl,4
  3470.   jbe    @@dont_adjust
  3471.   mov    bl,4
  3472. @@dont_adjust:
  3473.   mov    al,[byte sam_real]
  3474.   add    al,[byte sam_hl]
  3475.   movzx  esi,al
  3476.   shl    esi,5
  3477.   add    esi,[funk_hr_ptr]
  3478.   add    esi,offset (tfunk_hr).funk_sb
  3479.   and    [byte esi+tfunk_sb.vv_waveform],11110000b
  3480.   or     [byte esi+tfunk_sb.vv_waveform],bl
  3481. @@abort:
  3482.   call   display_samples
  3483.   ret
  3484. endp
  3485.  
  3486. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3487. ;                                                                          ;
  3488. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3489. proc edit_retriglim
  3490.   mov    ch,1
  3491.   mov    dh,[byte sam_hl]
  3492.   add    dh,2
  3493.   mov    dl,69
  3494.   call   get_input
  3495.   jc     @@abort
  3496.   call   get_inib
  3497.   mov    al,[byte sam_real]
  3498.   add    al,[byte sam_hl]
  3499.   movzx  esi,al
  3500.   shl    esi,5
  3501.   add    esi,[funk_hr_ptr]
  3502.   add    esi,offset (tfunk_hr).funk_sb
  3503.   shl    bl,4
  3504.   and    [byte esi+tfunk_sb.rl_and_as],1111b
  3505.   or     [byte esi+tfunk_sb.rl_and_as],bl
  3506. @@abort:
  3507.   call   display_samples
  3508.   ret
  3509. endp
  3510.  
  3511. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3512. ;                                                                          ;
  3513. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3514. proc edit_arpspeed
  3515.   mov    ch,1
  3516.   mov    dh,[byte sam_hl]
  3517.   add    dh,2
  3518.   mov    dl,72
  3519.   call   get_input
  3520.   jc     @@abort
  3521.   call   get_inib
  3522.   mov    al,[byte sam_real]
  3523.   add    al,[byte sam_hl]
  3524.   movzx  esi,al
  3525.   shl    esi,5
  3526.   add    esi,[funk_hr_ptr]
  3527.   add    esi,offset (tfunk_hr).funk_sb
  3528.   and    [byte esi+tfunk_sb.rl_and_as],11110000b
  3529.   or     [byte esi+tfunk_sb.rl_and_as],bl
  3530. @@abort:
  3531.   call   display_samples
  3532.   ret
  3533. endp
  3534.  
  3535. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3536. ;                                                                          ;
  3537. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3538. proc insert_space
  3539.   mov    dl,[byte sam_real]
  3540.   add    dl,[byte sam_hl]
  3541.   movzx  edx,dl
  3542.   mov    ebx,edx
  3543.   shl    edx,5
  3544.   lea    ebx,[ebx*4]
  3545.   add    edx,[funk_hr_ptr]
  3546.   add    edx,offset (tfunk_hr).funk_sb
  3547.   mov    ecx,[dword funk_info.sample_block_size]
  3548.   sub    ecx,[dword edx+tfunk_sb.length]
  3549.   sub    ecx,[dword ebx+funk_info.sample_ptrs]
  3550.   inc    ecx
  3551.   mov    edi,[dword funk_info.sample_block_size]
  3552.   mov    esi,edi
  3553.   sub    esi,[dword edx+tfunk_sb.length]
  3554.   mov    al,[byte init_settings.card_type]
  3555.   cmp    al,SB_CARD
  3556.   je     @@DAC_CARD
  3557.   cmp    al,SBPRO_CARD
  3558.   je     @@DAC_CARD
  3559.   cmp    al,GUS_VARB_CARD
  3560.   je     @@GUS_CARD
  3561.   cmp    al,SB15EM_CARD
  3562.   je     @@DAC_CARD
  3563.   cmp    al,SB16_CARD
  3564.   je     @@DAC_CARD
  3565.   cmp    al,GUS_FIXB_CARD
  3566.   je     @@GUS_CARD
  3567.   cmp    al,PAS16_CARD
  3568.   je     @@DAC_CARD
  3569.   ret
  3570. @@DAC_CARD:
  3571.   std
  3572.   rep    movsb
  3573.   cld
  3574.   ret
  3575. @@GUS_CARD:
  3576.   push   esi edi ecx
  3577.   call   GUS_reset
  3578.   pop    ecx edi esi
  3579. @@gus_loop:
  3580.   call   GUS_mem_in
  3581.   call   GUS_mem_out
  3582.   dec    esi
  3583.   dec    edi
  3584.   dec    ecx
  3585.   jnz    @@gus_loop
  3586.   call   GUS_reset
  3587.   call   GUS_intready
  3588.   ret
  3589. endp
  3590.  
  3591. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3592. ;                                                                          ;
  3593. ; edx = ptr to sample block info                                           ;
  3594. ; ebx = ptr to sample ptrs                                                 ;
  3595. ;                                                                          ;
  3596. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3597. ;eax = length
  3598. proc convert_sine
  3599.   push   edx eax
  3600. @@cs:
  3601.   xor    [byte edx],80h
  3602.   inc    edx
  3603.   dec    eax
  3604.   jnz    @@cs
  3605.   pop    eax edx
  3606.   ret
  3607. endp
  3608.  
  3609. proc load_sample
  3610.   mov    al,[byte init_settings.card_type]
  3611.   cmp    al,SB_CARD
  3612.   je     @@DAC_CARD
  3613.   cmp    al,SBPRO_CARD
  3614.   je     @@DAC_CARD
  3615.   cmp    al,GUS_VARB_CARD
  3616.   je     @@GUS_CARD
  3617.   cmp    al,SB15EM_CARD
  3618.   je     @@DAC_CARD
  3619.   cmp    al,SB16_CARD
  3620.   je     @@DAC_CARD
  3621.   cmp    al,GUS_FIXB_CARD
  3622.   je     @@GUS_CARD
  3623.   cmp    al,PAS16_CARD
  3624.   je     @@DAC_CARD
  3625.   ret
  3626. @@DAC_CARD:
  3627.   mov    esi,[dword edx+tfunk_sb.length]
  3628.   mov    edx,[dword ebx+funk_info.sample_ptrs]
  3629.   mov    ebx,[dword file_handle_funk]
  3630. @@SB_load_sample_loop:
  3631.   mov    ah,3fh
  3632.   mov    ecx,40000
  3633.   cmp    ecx,esi
  3634.   jbe    @@SB_dont_adjust
  3635.   mov    ecx,esi
  3636. @@SB_dont_adjust:
  3637.   int    21h
  3638.   call   convert_sine
  3639.   add    edx,eax
  3640.   sub    esi,eax
  3641.   jnz    @@SB_load_sample_loop
  3642.   ret
  3643. @@GUS_CARD:
  3644.   push   edx ebx
  3645.   call   GUS_reset
  3646.   pop    ebx edx
  3647.   mov    ebp,[dword edx+tfunk_sb.length]
  3648.   mov    edi,[dword ebx+funk_info.sample_ptrs]
  3649.   mov    ebx,[dword file_handle_funk]
  3650. @@GUS_load_sample_loop:
  3651.   mov    ah,3fh
  3652.   mov    edx,[dword fdirectory_buffer]
  3653.   mov    ecx,40000
  3654.   cmp    ecx,ebp
  3655.   jbe    @@GUS_dont_adjust
  3656.   mov    ecx,ebp
  3657. @@GUS_dont_adjust:
  3658.   int    21h
  3659.   call   convert_sine
  3660.   mov    esi,[dword fdirectory_buffer]
  3661.   push   eax
  3662.   call   gus_upload
  3663.   pop    eax
  3664.   sub    ebp,eax
  3665.   jnz    @@GUS_load_sample_loop
  3666.   call   GUS_reset
  3667.   call   GUS_intready
  3668.   ret
  3669. endp
  3670.  
  3671. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3672. ;                                                                          ;
  3673. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3674. proc dis_resamwin
  3675.   lea    esi,[resample_window]
  3676.   mov    edi,[_0b8000h]
  3677.   add    edi,(((78-25)/2)*2)+(((40-12)/2)*160)
  3678.   mov    ebx,25
  3679.   mov    dl,12
  3680.   call   paint_window
  3681.  
  3682.   xor    ecx,ecx
  3683.   xor    edx,edx
  3684. @@select_src:
  3685.   push   ecx edx
  3686.   mov    dh,04h                          ; no of entries
  3687.   mov    ebx,2f07h                       ; colour of hl
  3688.   mov    edi,[_0b8000h]
  3689.   add    edi,((((78-25)/2)+1)*2)+((((40-12)/2)+5)*160)+1
  3690.   mov    ecx,9                           ; length
  3691.   call   dis_sbar
  3692.   pop    edx ecx
  3693. @@again:
  3694.   call   get_key
  3695.   cmp    al,27
  3696.   je     @@finish
  3697.   cmp    al,13
  3698.   je     @@select_tar
  3699.   cmp    ax,kb_up
  3700.   je     @@up
  3701.   cmp    ax,kb_down
  3702.   je     @@dn
  3703.   jmp    @@again
  3704. @@up:
  3705.   cmp    dl,0
  3706.   je     @@again
  3707.   dec    dl
  3708.   jmp    @@select_src
  3709. @@dn:
  3710.   cmp    dl,3
  3711.   je     @@again
  3712.   inc    dl
  3713.   jmp    @@select_src
  3714. @@select_tar:
  3715.   cmp    dl,0
  3716.   je     @@sr_8000
  3717.   cmp    dl,1
  3718.   je     @@sr_11025
  3719.   cmp    dl,2
  3720.   je     @@sr_22050
  3721.   cmp    dl,3
  3722.   je     @@sr_44100
  3723. @@sr_8000:
  3724.   mov    ecx,8000
  3725.   jmp    @@sr_cont
  3726. @@sr_11025:
  3727.   mov    ecx,11025
  3728.   jmp    @@sr_cont
  3729. @@sr_22050:
  3730.   mov    ecx,22050
  3731.   jmp    @@sr_cont
  3732. @@sr_44100:
  3733.   mov    ecx,44100
  3734. @@sr_cont:
  3735.   mov    edx,ecx
  3736. @@tar_l:
  3737.   push   ecx edx
  3738.   mov    eax,edx
  3739.   mov    edi,((((78-25)/2)+13)*2)+((((40-12)/2)+6)*160)
  3740.   call   print_decn5
  3741.   pop    edx ecx
  3742. @@tar_again:
  3743.   call   get_key
  3744.   cmp    al,27
  3745.   je     @@finish
  3746.   cmp    al,13
  3747.   je     @@finish
  3748.   cmp    ax,kb_up
  3749.   je     @@tar_up
  3750.   cmp    ax,kb_down
  3751.   je     @@tar_dn
  3752.   cmp    ax,kb_pageup
  3753.   je     @@tar_pdup
  3754.   cmp    ax,kb_pagedn
  3755.   je     @@tar_pddn
  3756.   jmp    @@tar_again
  3757. @@tar_up:
  3758.   cmp    edx,0
  3759.   je     @@tar_again
  3760.   dec    edx
  3761.   jmp    @@tar_l
  3762. @@tar_dn:
  3763.   cmp    edx,88200
  3764.   je     @@tar_again
  3765.   inc    edx
  3766.   jmp    @@tar_l
  3767. @@tar_pdup:
  3768.   sub    edx,100
  3769.   cmp    edx,0
  3770.   jge    @@tar_l
  3771.   mov    edx,0
  3772.   jmp    @@tar_l
  3773. @@tar_pddn:
  3774.   add    edx,100
  3775.   cmp    edx,88200
  3776.   jle    @@tar_l
  3777.   mov    edx,88200
  3778.   jmp    @@tar_l
  3779. @@finish:
  3780.   ret
  3781. endp
  3782.  
  3783. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3784. ;                                                                          ;
  3785. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3786. FTRANS_INB_SIZE       = 2048
  3787. FTRANS_OUTB_SIZE      = 2048
  3788. ftrans_scr_len        dd ?
  3789. LS_src_freq           dd ?
  3790. LS_dst_freq           dd ?
  3791. LS_length             dd ?
  3792.  
  3793. proc ftrans_read
  3794.   push   edx
  3795.   mov    ecx,FTRANS_INB_SIZE
  3796.   cmp    ecx,[ftrans_scr_len]
  3797.   jbe    @@cont
  3798.   mov    ecx,[ftrans_scr_len]
  3799. @@cont:
  3800.   mov    ebx,[dword file_handle_funk]
  3801.   mov    edx,[fdirectory_buffer]
  3802.   mov    ah,3fh
  3803.   int    21h
  3804.   mov    [numread],eax
  3805.   sub    [ftrans_scr_len],eax
  3806.   pop    edx
  3807.   xor    esi,esi
  3808.   ret
  3809. endp
  3810.  
  3811. proc ftrans_write
  3812.   push   edx
  3813.   mov    ecx,edi
  3814.   mov    ebx,[dword file_handle_funk2]
  3815.   mov    edx,[fdirectory_buffer]
  3816.   add    edx,FTRANS_INB_SIZE
  3817.   mov    ah,40h
  3818.   int    21h
  3819.   pop    edx
  3820.   xor    edi,edi
  3821.   ret
  3822. endp
  3823.  
  3824. ;eax = target freq
  3825. ;ebx = source freq
  3826. ;ecx = scr len
  3827. proc ftrans_buffer
  3828.   mov    [@@target_freq],eax
  3829.   mov    [@@source_freq],ebx
  3830.   mov    [ftrans_scr_len],ecx
  3831.   mov    eax,[@@target_freq]
  3832.   mov    edx,eax
  3833.   shl    eax,16
  3834.   shr    edx,16
  3835.   div    [dword @@source_freq]
  3836.   mov    edx,eax
  3837.   mov    ebp,edx
  3838.   shl    edx,16
  3839.   shr    ebp,16
  3840.   xor    esi,esi
  3841.   xor    edi,edi
  3842.   call   ftrans_read
  3843.   jc     @@error_trans
  3844.   cmp    [dword numread],0
  3845.   je     @@done
  3846. @@mix_loop:
  3847.   mov    ebx,[fdirectory_buffer]
  3848.   mov    al,[esi+ebx]
  3849.   mov    ebx,[fdirectory_buffer]
  3850.   mov    [edi+ebx+FTRANS_INB_SIZE],al
  3851.   inc    edi
  3852.   add    [dword @@freq_attract],edx
  3853.   adc    esi,ebp
  3854.   cmp    esi,[numread]
  3855.   jb     @@cont
  3856.   call   ftrans_read
  3857.   jc     @@error_trans
  3858.   cmp    [dword numread],0
  3859.   je     @@done
  3860. @@cont:
  3861.   cmp    edi,FTRANS_OUTB_SIZE
  3862.   jb     @@mix_loop
  3863.   call   ftrans_write
  3864.   jc     @@error_trans
  3865.   jmp    @@mix_loop
  3866. @@error_trans:
  3867.   @error_mess "Error: Can not transform sample"
  3868.   stc
  3869.   ret
  3870. @@done:
  3871.   cmp    edi,0
  3872.   je     @@cont2
  3873.   call   ftrans_write
  3874. @@cont2:
  3875.   clc
  3876.   ret
  3877. @@freq_attract        dd 0
  3878. @@target_freq         dd ?
  3879. @@source_freq         dd ?
  3880. endp
  3881.  
  3882. macro @LS_CONFREQ
  3883.   mov    edx,offset file_temp
  3884.   mov    eax,3c00h
  3885.   xor    ecx,ecx
  3886.   int    21h
  3887.   jc     @@mess2
  3888.   mov    [dword file_handle_funk2],eax
  3889.  
  3890.   mov    eax,[LS_src_freq]
  3891.   mov    ebx,[LS_dst_freq]
  3892.   mov    ecx,[LS_length]
  3893.   call   ftrans_buffer
  3894.   jnc    @@no_ftrans_error
  3895.   mov    ebx,[dword file_handle_funk2]
  3896.   mov    ah,3eh
  3897.   int    21h
  3898.   jmp    @@closef
  3899. @@no_ftrans_error:
  3900.   mov    ebx,[dword file_handle_funk]
  3901.   mov    ah,3eh
  3902.   int    21h
  3903.   mov    eax,[dword file_handle_funk2]
  3904.   mov    [dword file_handle_funk],eax
  3905.  
  3906.   mov    ebx,[dword file_handle_funk]
  3907.   mov    eax,4202h
  3908.   xor    edx,edx
  3909.   int    21h
  3910.   push   eax
  3911.   mov    ebx,[dword file_handle_funk]
  3912.   mov    eax,4200h
  3913.   xor    edx,edx
  3914.   int    21h
  3915.   pop    eax
  3916. endm
  3917.  
  3918. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3919. ;                                                                          ;
  3920. ; WAV loader                                                               ;
  3921. ;                                                                          ;
  3922. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3923. struc triff_hr
  3924.   rID                 dd ?      ; Contains the characters "RIFF"
  3925.   rLen                dd ?      ; The length of the data in the next chunk
  3926. ends
  3927.  
  3928. struc twaveformat
  3929.   wID                 dd ?      ; Contains the characters "WAVE"
  3930.   fId                 dd ?      ; Contains the characters "fmt"
  3931.   fLen                dd ?      ; Length of data in the format chunk
  3932.   wFormatTag          dw ?      ; *
  3933.   nChannels           dw ?      ; Number of channels, 1=mono, 2=stereo
  3934.   nSamplesPerSec      dw ?      ; Playback frequency
  3935.   nAvgBytesPerSec     dw ?      ; **
  3936.   nBlockAlign         dw ?      ; ***
  3937.   FormatSpecific      dw ?      ; Format specific data area
  3938.   blank               dd ?
  3939. ends
  3940.  
  3941. struc twavedata
  3942.   dId                 dd ?      ; Contains the characters "data"
  3943.   dLen                dd ?      ; Length of data in the dData field
  3944. ends
  3945.  
  3946. riff_hr               triff_hr <>
  3947. waveformat            twaveformat <>
  3948. wavedata              twavedata <>
  3949.  
  3950. proc load_single_WAV
  3951.   call   dis_resamwin
  3952.   mov    [LS_src_freq],ecx
  3953.   mov    [LS_dst_freq],edx
  3954.   @splash_on_sm  "Loading WAV, please wait"
  3955.   mov    dl,[byte sam_real]
  3956.   add    dl,[byte sam_hl]
  3957.   movzx  edx,dl
  3958.   shl    edx,5
  3959.   add    edx,[funk_hr_ptr]
  3960.   add    edx,offset (tfunk_hr).funk_sb
  3961.   mov    eax,3d00h
  3962.   int    21h
  3963.   jc     @@mess1
  3964.   mov    [dword file_handle_funk],eax
  3965.   mov    ebx,eax
  3966.   mov    ah,3fh                                         ; load riff header
  3967.   lea    edx,[riff_hr]
  3968.   mov    ecx,size triff_hr
  3969.   int    21h
  3970.   cmp    [dword riff_hr.rID],"FFIR"
  3971.   jne    @@not_wave_mess
  3972.   mov    ah,3fh                                         ; load wave header
  3973.   lea    edx,[waveformat]
  3974.   mov    ecx,size twaveformat
  3975.   int    21h
  3976.   cmp    [dword waveformat.wID],"EVAW"
  3977.   jne    @@not_wave_mess
  3978.   cmp    [dword waveformat.fId]," tmf"
  3979.   jne    @@not_wave_mess
  3980.   mov    ah,3fh                                         ; load data header
  3981.   lea    edx,[wavedata]
  3982.   mov    ecx,size twavedata
  3983.   int    21h
  3984.   cmp    [dword wavedata.dId],"atad"
  3985.   jne    @@not_wave_mess
  3986.   cmp    [dword wavedata.dLen],0
  3987.   je     @@closef
  3988.   mov    eax,[LS_src_freq]
  3989.   cmp    eax,[LS_dst_freq]
  3990.   je     @@load_normal
  3991. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3992.   mov    eax,[dword wavedata.dLen]
  3993.   mov    [LS_length],eax
  3994.   @LS_CONFREQ
  3995.   jmp    @@load_data
  3996. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3997. @@load_normal:
  3998.   mov    eax,[dword wavedata.dLen]
  3999. @@load_data:
  4000.   xor    edx,edx
  4001.   mov    dl,[byte sam_real]
  4002.   add    dl,[byte sam_hl]
  4003.   shl    edx,5
  4004.   add    edx,[funk_hr_ptr]
  4005.   add    edx,offset (tfunk_hr).funk_sb
  4006.   mov    ebx,[dword funk_info.sample_memory_lim]
  4007.   mov    ecx,[dword funk_info.sample_block_size]
  4008.   sub    ecx,[dword funk_info.sample_ptrs]
  4009.   sub    ebx,ecx
  4010.   cmp    eax,ebx
  4011.   ja     @@out_of_mem
  4012.   mov    [dword edx+tfunk_sb.length],eax
  4013.   call   resync_sample_ptrs
  4014.   call   insert_space
  4015.   mov    dl,[byte sam_real]
  4016.   add    dl,[byte sam_hl]
  4017.   movzx  edx,dl
  4018.   mov    ebx,edx
  4019.   shl    edx,5
  4020.   lea    ebx,[ebx*4]
  4021.   add    edx,[funk_hr_ptr]
  4022.   add    edx,offset (tfunk_hr).funk_sb
  4023.   call   load_sample
  4024.   mov    ebx,[dword file_handle_funk]
  4025.   mov    ah,3eh                                         ; close
  4026.   int    21h
  4027.   @splash_off_sm
  4028.   ret
  4029. @@mess1:
  4030.   @error_mess "Error: Can not load WAV"
  4031.   ret
  4032. @@mess2:
  4033.   @error_mess "Error: Can not load WAV"
  4034.   jmp    @@closef
  4035. @@out_of_mem:
  4036.   @error_mess "Error: Out of sample memory; Can not load WAV"
  4037.   jmp    @@closef
  4038. @@not_wave_mess:
  4039.   @error_mess "Error: Not a recognised Windows WAV"
  4040.   jmp    @@closef
  4041. @@closef:
  4042.   mov    ebx,[dword file_handle_funk]
  4043.   mov    ah,3eh                                   ; close
  4044.   int    21h
  4045.   ret
  4046. endp
  4047.  
  4048. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4049. ;                                                                          ;
  4050. ; SND loader                                                               ;
  4051. ;                                                                          ;
  4052. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4053. proc load_single_SMP
  4054.   call   dis_resamwin
  4055.   mov    [LS_src_freq],ecx
  4056.   mov    [LS_dst_freq],edx
  4057.   @splash_on_sm  "Loading SMP, please wait"
  4058.   xor    edx,edx
  4059.   mov    dl,[byte sam_real]
  4060.   add    dl,[byte sam_hl]
  4061.   shl    edx,5
  4062.   add    edx,[funk_hr_ptr]
  4063.   add    edx,offset (tfunk_hr).funk_sb
  4064.   mov    eax,3d00h
  4065.   int    21h
  4066.   jc     @@mess1
  4067.   mov    [dword file_handle_funk],eax
  4068.   mov    ebx,eax
  4069.  
  4070.   mov    eax,4202h
  4071.   xor    edx,edx
  4072.   int    21h
  4073.   push   eax
  4074.   mov    eax,4200h
  4075.   xor    edx,edx
  4076.   int    21h
  4077.   pop    [dword LS_length]
  4078.   mov    eax,[LS_src_freq]
  4079.   cmp    eax,[LS_dst_freq]
  4080.   je     @@load_normal
  4081. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4082.   @LS_CONFREQ
  4083.   jmp    @@load_data
  4084. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4085. @@load_normal:
  4086.   mov    eax,[dword LS_length]
  4087. @@load_data:
  4088.   xor    edx,edx
  4089.   mov    dl,[byte sam_real]
  4090.   add    dl,[byte sam_hl]
  4091.   shl    edx,5
  4092.   add    edx,[funk_hr_ptr]
  4093.   add    edx,offset (tfunk_hr).funk_sb
  4094.   mov    ebx,[dword funk_info.sample_memory_lim]
  4095.   mov    ecx,[dword funk_info.sample_block_size]
  4096.   sub    ecx,[dword funk_info.sample_ptrs]
  4097.   sub    ebx,ecx
  4098.   cmp    eax,ebx
  4099.   ja     @@out_of_mem
  4100.   mov    [dword edx+tfunk_sb.length],eax
  4101.   call   resync_sample_ptrs
  4102.   call   insert_space
  4103.   xor    edx,edx
  4104.   mov    dl,[byte sam_real]
  4105.   add    dl,[byte sam_hl]
  4106.   mov    ebx,edx
  4107.   shl    edx,5
  4108.   lea    ebx,[ebx*4]
  4109.   add    edx,[funk_hr_ptr]
  4110.   add    edx,offset (tfunk_hr).funk_sb
  4111.   call   load_sample
  4112.   mov    ebx,[dword file_handle_funk]
  4113.   mov    ah,3eh                                         ; close
  4114.   int    21h
  4115.   @splash_off_sm
  4116.   ret
  4117. @@mess1:
  4118.   @error_mess "Error: Can not load SND"
  4119.   ret
  4120. @@mess2:
  4121.   @error_mess "Error: Can not load SND"
  4122.   jmp    @@closef
  4123. @@out_of_mem:
  4124.   @error_mess "Error: Out of sample memory; Can not load SND"
  4125.   jmp    @@closef
  4126. @@closef:
  4127.   mov    ebx,[dword file_handle_funk]
  4128.   mov    ah,3eh                                   ; close
  4129.   int    21h
  4130.   ret
  4131. endp
  4132.  
  4133. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4134. ;                                                                          ;
  4135. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4136. proc select_sample_file
  4137.   call   stop_all_voices
  4138.   lea    edx,[sample_dir]
  4139.   call   set_directory
  4140.   mov    ecx,modefile_screen_size
  4141.   lea    esi,[modefile_screen]
  4142.   mov    edi,[_0b8000h]
  4143.   call   uncrush_text
  4144.   lea    edx,[file_search_wav]
  4145.   call   load_fdirectory
  4146.   xor    bl,bl
  4147.   lea    edx,[file_search_snd]
  4148.   call   load_fset
  4149.   call   display_fdir
  4150. @@input_loop:
  4151.   call   get_key
  4152.   cmp    al,27
  4153.   je     @@exit
  4154.   cmp    ax,kb_up
  4155.   je     @@hkb_up
  4156.   cmp    ax,kb_down
  4157.   je     @@hkb_down
  4158.   cmp    ax,kb_pageup
  4159.   je     @@hkb_pageup
  4160.   cmp    ax,kb_pagedn
  4161.   je     @@hkb_pagedn
  4162.   cmp    al,13
  4163.   je     @@enter_key
  4164.   jmp    @@input_loop
  4165. @@scroll_fdir_up:
  4166.   call   display_fdir
  4167.   jmp    @@input_loop
  4168. @@scroll_fdir_dw:
  4169.   call   display_fdir
  4170.   jmp    @@input_loop
  4171. @@hkb_up:
  4172.   call   fdir_scroll_up
  4173.   call   display_fdir
  4174.   jmp    @@input_loop
  4175. @@hkb_down:
  4176.   call   fdir_scroll_dn
  4177.   call   display_fdir
  4178.   jmp    @@input_loop
  4179. @@hkb_pageup:
  4180.   call   fdir_scroll_pageup
  4181.   call   display_fdir
  4182.   jmp    @@input_loop
  4183. @@hkb_pagedn:
  4184.   call   fdir_scroll_pagedn
  4185.   call   display_fdir
  4186.   jmp    @@input_loop
  4187. @@enter_key:
  4188.   mov    cl,size tfdirectory
  4189.   mov    ax,[word fdir_real]
  4190.   add    al,[byte fdir_hl]
  4191.   adc    ah,0
  4192.   mul    cl
  4193.   movzx  esi,ax
  4194.   add    esi,[dword fdirectory_buffer]
  4195.   cmp    [byte esi+tfdirectory.attr],10h
  4196.   jne    @@load_file
  4197.   push   esi
  4198.   lea    esi,[sample_dir]
  4199.   mov    edi,esi
  4200.   call   get_directory
  4201.   pop    esi
  4202.   lea    esi,[esi+tfdirectory.fname]
  4203.   call   goto_end_str
  4204.   cmp    ebx,3
  4205.   jne    @@form_path2
  4206.   call   mini_trans_str
  4207.   jmp    @@change_dir
  4208. @@form_path2:
  4209.   mov    [byte edi+ebx],'\'
  4210.   inc    ebx
  4211.   call   mini_trans_str
  4212. @@change_dir:
  4213.   lea    edx,[sample_dir]
  4214.   call   set_directory
  4215.   lea    esi,[sample_dir]
  4216.   call   get_directory
  4217.   lea    edx,[file_search_wav]
  4218.   call   load_fdirectory
  4219.   xor    bl,bl
  4220.   lea    edx,[file_search_snd]
  4221.   call   load_fset
  4222.   call   display_fdir
  4223.   jmp    @@input_loop
  4224. @@load_file:
  4225.   push   esi
  4226.   mov    al,[byte sam_real]
  4227.   add    al,[byte sam_hl]
  4228.   movzx  esi,al
  4229.   shl    esi,5
  4230.   add    esi,[funk_hr_ptr]
  4231.   add    esi,offset (tfunk_hr).funk_sb
  4232.   cmp    [dword esi+tfunk_sb.length],0
  4233.   je     @@dont_del
  4234.   @splash_on_sm  "Deleting old sample ready for replacement, please wait"
  4235.   call   sam_del_nd
  4236.   call   sam_ins_nd
  4237.   @splash_off_sm
  4238. @@dont_del:
  4239.   pop    esi
  4240.   mov    al,[byte sam_real]
  4241.   add    al,[byte sam_hl]
  4242.   movzx  edi,al
  4243.   shl    edi,5
  4244.   add    edi,[funk_hr_ptr]
  4245.   add    edi,offset (tfunk_hr).funk_sb
  4246.   push   edi
  4247.   mov    ecx,19
  4248.   mov    al," "
  4249. @@clr_sname:
  4250.   stosb
  4251.   dec    ecx
  4252.   jnz    @@clr_sname
  4253.   pop    edi
  4254.   lea    esi,[esi+tfdirectory.fname]
  4255.   push   esi
  4256.   xor    ebx,ebx
  4257.   call   mini_trans_str
  4258.   pop    esi
  4259. @@search_type:
  4260.   cmp    [byte esi],"."
  4261.   je     @@done_st
  4262.   inc    esi
  4263.   jmp    @@search_type
  4264. @@done_st:
  4265.   cmp    [dword esi],"DNS."
  4266.   je     @@do_SMP
  4267.   call   load_single_WAV
  4268.   jmp    @@load_done
  4269. @@do_SMP:
  4270.   call   load_single_SMP
  4271. @@load_done:
  4272. ;;;;;;;;;;;;
  4273.   mov    edx,offset file_temp
  4274.   mov    ah,41h
  4275.   int    21h
  4276. ;;;;;;;;;;;
  4277. @@exit:
  4278.   call   display_mode
  4279.   ret
  4280. endp
  4281.  
  4282. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4283. ;                                                                          ;
  4284. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4285. proc se_handle
  4286.   cmp    ax,kb_up
  4287.   je     @@hkb_up
  4288.   cmp    ax,kb_down
  4289.   je     @@hkb_down
  4290.   cmp    ax,kb_pageup
  4291.   je     @@hkb_pageup
  4292.   cmp    ax,kb_pagedn
  4293.   je     @@hkb_pagedn
  4294.   cmp    ax,kb_left
  4295.   je     @@hkb_left
  4296.   cmp    ax,kb_right
  4297.   je     @@hkb_right
  4298.   cmp    al,"/"
  4299.   je     @@dec_oct
  4300.   cmp    al,"*"
  4301.   je     @@inc_oct
  4302.   push   eax
  4303.   call   mus_kb_input
  4304.   pop    eax
  4305.   cmp    al,"["
  4306.   je     @@edit_field
  4307.   cmp    ax,kb_insert
  4308.   je     @@insert_sb
  4309.   cmp    ax,kb_delete
  4310.   je     @@delete_sb
  4311.   cmp    al," "
  4312.   je     @@load_sample
  4313.   jmp    @@input_loop
  4314. @@hkb_up:
  4315.   call   sam_scroll_up
  4316.   call   display_samples
  4317.   jmp    @@input_loop
  4318. @@hkb_down:
  4319.   call   sam_scroll_dn
  4320.   call   display_samples
  4321.   jmp    @@input_loop
  4322. @@hkb_pageup:
  4323.   call   sam_pageup
  4324.   call   display_samples
  4325.   jmp    @@input_loop
  4326. @@hkb_pagedn:
  4327.   call   sam_pagedn
  4328.   call   display_samples
  4329.   jmp    @@input_loop
  4330. @@hkb_left:
  4331.   cmp    [byte sam_col],0
  4332.   je     @@input_loop
  4333.   dec    [byte sam_col]
  4334.   call   display_samples
  4335.   jmp    @@input_loop
  4336. @@hkb_right:
  4337.   cmp    [byte sam_col],9
  4338.   je     @@input_loop
  4339.   inc    [byte sam_col]
  4340.   call   display_samples
  4341.   jmp    @@input_loop
  4342. @@dec_oct:
  4343.   cmp    [byte octave],0
  4344.   je     @@input_loop
  4345.   dec    [byte octave]
  4346.   call   update_octave
  4347.   jmp    @@input_loop
  4348. @@inc_oct:
  4349.   cmp    [byte octave],4
  4350.   je     @@input_loop
  4351.   inc    [byte octave]
  4352.   call   update_octave
  4353.   jmp    @@input_loop
  4354. @@edit_field:
  4355.   cmp    [byte sam_col],1
  4356.   je     @@edit_f2
  4357.   cmp    [byte sam_col],2
  4358.   je     @@edit_f3
  4359.   cmp    [byte sam_col],3
  4360.   je     @@edit_f4
  4361.   cmp    [byte sam_col],4
  4362.   je     @@edit_f5
  4363.   cmp    [byte sam_col],5
  4364.   je     @@edit_f6
  4365.   cmp    [byte sam_col],6
  4366.   je     @@edit_f7
  4367.   cmp    [byte sam_col],7
  4368.   je     @@edit_f8
  4369.   cmp    [byte sam_col],8
  4370.   je     @@edit_f9
  4371.   cmp    [byte sam_col],9
  4372.   je     @@edit_f10
  4373. @@edit_f1:
  4374.   call   edit_sname
  4375.   jmp    @@input_loop
  4376. @@edit_f2:
  4377.   call   edit_sstart
  4378.   jmp    @@input_loop
  4379. @@edit_f3:
  4380.   call   edit_svolume
  4381.   jmp    @@input_loop
  4382. @@edit_f4:
  4383.   call   edit_sbalance
  4384.   jmp    @@input_loop
  4385. @@edit_f5:
  4386.   call   edit_port_type
  4387.   jmp    @@input_loop
  4388. @@edit_f6:
  4389.   call   edit_ssample_op
  4390.   jmp    @@input_loop
  4391. @@edit_f7:
  4392.   call   edit_svwt
  4393.   jmp    @@input_loop
  4394. @@edit_f8:
  4395.   call   edit_svvwt
  4396.   jmp    @@input_loop
  4397. @@edit_f9:
  4398.   call   edit_retriglim
  4399.   jmp    @@input_loop
  4400. @@edit_f10:
  4401.   call   edit_arpspeed
  4402.   jmp    @@input_loop
  4403. @@insert_sb:
  4404.   call   sam_ins
  4405.   jmp    @@input_loop
  4406. @@delete_sb:
  4407.   call   sam_del
  4408.   jmp    @@input_loop
  4409. @@load_sample:
  4410.   call   select_sample_file
  4411.   jmp    @@input_loop
  4412. @@input_loop:
  4413.   ret
  4414. endp
  4415.  
  4416. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4417. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4418. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4419. ;                                                                          ;
  4420. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4421. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4422. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4423.  
  4424. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4425. ;                                                                          ;
  4426. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4427. proc trak_seq_info
  4428.   mov    esi,[funk_hr_ptr]
  4429.  
  4430.   mov    ah,13h
  4431.   mov    edi,(12*2)+(46*160)
  4432.   mov    bl,[byte funk_info.sequence_ofs]
  4433.   call   display_byte
  4434.  
  4435.   mov    edi,(28*2)+(46*160)
  4436.   xor    ebx,ebx
  4437.   mov    bl,[byte funk_info.sequence_ofs]
  4438.   mov    bl,[byte esi+ebx+tfunk_hr.order_list]
  4439.   call   display_byte
  4440.  
  4441.   mov    edi,(28*2)+(47*160)
  4442.   mov    bl,[byte funk_info.pattern_ofs]
  4443.   call   display_byte
  4444.  
  4445.   mov    edi,(39*2)+(46*160)
  4446.   mov    bl,[byte funk_info.tempo]
  4447.   call   display_nibble
  4448.  
  4449.   mov    edi,(39*2)+(47*160)
  4450.   mov    bl,[byte funk_info.master_volume]
  4451.   call   display_nibble
  4452.   ret
  4453. endp
  4454.  
  4455. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4456. ;                                                                          ;
  4457. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4458. proc track_screen_debug
  4459.   call   trak_seq_info
  4460.   mov    ah,03h
  4461.   lea    esi,[funk_chan1]
  4462.   mov    cl,8
  4463.   xor    edx,edx
  4464. @@display_chan_dump:
  4465.   push   ecx edx
  4466. ;;;
  4467.   mov    edi,(1*2)+(37*160)
  4468.   add    edi,edx
  4469.   movzx  ebx,[word esi+tfunk_chan.command]
  4470.   call   display_command
  4471. ;;
  4472.   mov    edi,(5*2)+(37*160)
  4473.   add    edi,edx
  4474.   mov    bl,[byte esi+tfunk_chan.sample]
  4475.   call   display_byte
  4476. ;;;
  4477.   mov    edi,(8*2)+(37*160)
  4478.   add    edi,edx
  4479.   mov    bl,[byte esi+tfunk_chan.balance]
  4480.   call   display_byte
  4481. ;;;
  4482.   mov    edi,(10*2)+(37*160)
  4483.   add    edi,edx
  4484.   mov    bl,[byte esi+tfunk_chan.port_type]
  4485.   call   display_nibble
  4486. ;;;
  4487.   mov    edi,(11*2)+(37*160)
  4488.   add    edi,edx
  4489.   mov    bl,[byte esi+tfunk_chan.sample_ofs_parm]
  4490.   call   display_nibble
  4491. ;;;
  4492.   mov    edi,(12*2)+(37*160)
  4493.   add    edi,edx
  4494.   mov    bl,[byte esi+tfunk_chan.vib_waveform]
  4495.   call   display_nibble
  4496. ;;;
  4497.   mov    edi,(13*2)+(37*160)
  4498.   add    edi,edx
  4499.   mov    bl,[byte esi+tfunk_chan.vol_vib_waveform]
  4500.   call   display_nibble
  4501. ;;;
  4502.   mov    edi,(14*2)+(37*160)
  4503.   add    edi,edx
  4504.   mov    bl,[byte esi+tfunk_chan.retrig_limit]
  4505.   call   display_nibble
  4506. ;;;
  4507.   mov    edi,(15*2)+(37*160)
  4508.   add    edi,edx
  4509.   mov    bl,[byte esi+tfunk_chan.arp_speed]
  4510.   call   display_nibble
  4511. ;;;
  4512.   mov    edi,(16*2)+(37*160)
  4513.   add    edi,edx
  4514.   mov    bl,[byte esi+tfunk_chan.funkctrl]
  4515.   call   display_nibble
  4516. ;;;
  4517.   mov    edi,(18*2)+(37*160)
  4518.   add    edi,edx
  4519.   movzx  ebx,[word esi+tfunk_chan.note_command]
  4520.   call   display_command
  4521. ;;
  4522.   mov    edi,(22*2)+(37*160)
  4523.   add    edi,edx
  4524.   movzx  ebx,[byte esi+tfunk_chan.note]
  4525.   call   display_note
  4526. ;;;
  4527.   mov    edi,(26*2)+(37*160)
  4528.   add    edi,edx
  4529.   mov    ecx,[dword esi+tfunk_chan.ifreq]
  4530.   call   display_word
  4531. ;;;
  4532.   mov    edi,(31*2)+(37*160)
  4533.   add    edi,edx
  4534.   mov    ecx,[dword esi+tfunk_chan.ifreq_vibrato]
  4535.   call   display_word
  4536. ;;;
  4537.   mov    edi,(36*2)+(37*160)
  4538.   add    edi,edx
  4539.   mov    ecx,[dword esi+tfunk_chan.ifreq_portdest]
  4540.   call   display_word
  4541. ;;;
  4542.   mov    edi,(41*2)+(37*160)
  4543.   add    edi,edx
  4544.   mov    ecx,[dword esi+tfunk_chan.rfreq]
  4545.   call   display_dword
  4546. ;;;
  4547.   mov    edi,(50*2)+(37*160)
  4548.   add    edi,edx
  4549.   mov    ecx,[dword esi+tfunk_chan.rfreq_adjust]
  4550.   call   display_word
  4551. ;;;
  4552.   mov    edi,(55*2)+(37*160)
  4553.   add    edi,edx
  4554.   mov    ecx,[dword esi+tfunk_chan.rfreq_portdest]
  4555.   call   display_dword
  4556. ;;;
  4557.   mov    edi,(64*2)+(37*160)
  4558.   add    edi,edx
  4559.   movzx  ebx,[word esi+tfunk_chan.volume_command]
  4560.   call   display_command
  4561. ;;
  4562.   mov    edi,(68*2)+(37*160)
  4563.   add    edi,edx
  4564.   mov    bl,[byte esi+tfunk_chan.volume]
  4565.   call   display_byte
  4566. ;;;
  4567.   mov    edi,(71*2)+(37*160)
  4568.   add    edi,edx
  4569.   mov    bl,[byte esi+tfunk_chan.volume_vibrato]
  4570.   call   display_byte
  4571. ;;;
  4572.   mov    edi,(74*2)+(37*160)
  4573.   add    edi,edx
  4574.   mov    bl,[byte esi+tfunk_chan.volume_portdest]
  4575.   call   display_byte
  4576. ;;;
  4577.   mov    edi,(77*2)+(37*160)
  4578.   add    edi,edx
  4579.   mov    bl,[byte esi+tfunk_chan.rvolume]
  4580.   call   display_byte
  4581. ;;;
  4582.   pop    edx ecx
  4583.   add    esi,size tfunk_chan
  4584.   add    dx,160
  4585.   dec    cl
  4586.   jnz    @@display_chan_dump
  4587.   ret
  4588. endp
  4589.  
  4590. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4591. ;                                                                          ;
  4592. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4593. proc track_screen_play
  4594.   call   trak_seq_info
  4595.   lea    esi,[funk_chan1]
  4596.   mov    cl,8
  4597.   xor    edx,edx
  4598. @@display_chan_dump:
  4599.   push   ecx edx
  4600. ;;;
  4601.   mov    ah,0fh
  4602.   push   esi
  4603.   mov    al,[byte esi+tfunk_chan.sample]
  4604.   movzx  esi,al
  4605.   shl    esi,5
  4606.   add    esi,[funk_hr_ptr]
  4607.   add    esi,offset (tfunk_hr).funk_sb
  4608.   mov    edi,(1*2)+(36*160)
  4609.   add    edi,edx
  4610.   mov    cl,19
  4611.   call   byte_write2
  4612.   pop    esi
  4613. ;;;
  4614.   mov    ah,03h
  4615.   mov    edi,(56*2)+(36*160)
  4616.   add    edi,edx
  4617.   movzx  ebx,[word esi+tfunk_chan.command]
  4618.   call   display_command
  4619. ;;
  4620.   mov    edi,(61*2)+(36*160)
  4621.   add    edi,edx
  4622.   movzx  ebx,[word esi+tfunk_chan.note_command]
  4623.   call   display_command
  4624. ;;
  4625.   mov    edi,(66*2)+(36*160)
  4626.   add    edi,edx
  4627.   movzx  ebx,[word esi+tfunk_chan.volume_command]
  4628.   call   display_command
  4629. ;;
  4630.   mov    edi,(22*2)+(36*160)
  4631.   add    edi,[_0b8000h]
  4632.   add    edi,edx
  4633.   mov    bl,[byte esi+tfunk_chan.rvolume]
  4634.   shr    bl,3
  4635.   xor    cl,cl
  4636. @@p_trek_bar:
  4637.   cmp    cl,bl
  4638.   je     @@paint_end
  4639.   mov    al," "
  4640.   ja     @@asd
  4641.   mov    al,205
  4642.   jmp    @@asd
  4643. @@paint_end:
  4644.   mov    al,[byte esi+tfunk_chan.rvolume]
  4645.   and    al,111b
  4646.   add    al,198
  4647. @@asd:
  4648.   stosb
  4649.   inc    edi
  4650.   inc    cl
  4651.   cmp    cl,32
  4652.   jnz    @@p_trek_bar
  4653. ;;
  4654.   pop    edx ecx
  4655.   add    esi,size tfunk_chan
  4656.   add    edx,160
  4657.   dec    cl
  4658.   jnz    @@display_chan_dump
  4659.  
  4660.   ret
  4661. endp
  4662.  
  4663. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4664. ;                                                                          ;
  4665. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4666. ; dl = colour adjust ; eax = pattern ofs
  4667. proc display_trak
  4668.   and    al,11111b
  4669.   mov    edi,[_0b8000h]
  4670.   add    edi,((4*2)+(2*160))+1
  4671.   mov    ebx,eax
  4672.   shl    eax,7
  4673.   shl    ebx,5
  4674.   add    edi,eax
  4675.   add    edi,ebx
  4676.   mov    cl,9*8
  4677. @@hl_trek:
  4678.   and    [byte edi],1111b
  4679.   or     [byte edi],dl
  4680.   add    edi,2
  4681.   dec    cl
  4682.   jnz    @@hl_trek
  4683.   ret
  4684. endp
  4685.  
  4686. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4687. ;                                                                          ;
  4688. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4689. proc trak_pattern
  4690.   movzx  ebx,[byte funk_info.sequence_ofs]
  4691.   cmp    bl,80h
  4692.   jae    @@end
  4693.   cmp    bl,[byte funk_info.sequence_ofs_old]
  4694.   jne    @@draw_pat
  4695.   mov    al,[byte funk_info.pattern_ofs2_old]
  4696.   mov    ah,[byte funk_info.pattern_ofs]
  4697.   shr    al,5
  4698.   shr    ah,5
  4699.   cmp    al,ah
  4700.   je     @@clear_bar
  4701. @@draw_pat:
  4702.   mov    [byte funk_info.sequence_ofs_old],bl
  4703.   mov    esi,[funk_hr_ptr]
  4704.   movzx  ebx,[byte esi+ebx+tfunk_hr.order_list]
  4705.   movzx  esi,bl
  4706.   mov    dh,[byte funk_info.pattern_ofs]
  4707.   and    dh,100000b
  4708.   call   display_pattern
  4709.   jmp    @@set_bar
  4710. @@clear_bar:
  4711.   xor    dl,dl
  4712.   movzx  eax,[byte funk_info.pattern_ofs2_old]
  4713.   call   display_trak
  4714. @@set_bar:
  4715.   mov    dl,70h
  4716.   movzx  eax,[byte funk_info.pattern_ofs]
  4717.   mov    [byte funk_info.pattern_ofs2_old],al
  4718.   call   display_trak
  4719. @@end:
  4720.   ret
  4721. endp
  4722.  
  4723. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4724. ;                                                                          ;
  4725. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4726. proc trak_paint_screen
  4727.   mov    ecx,main_screen_size
  4728.   lea    esi,[main_screen]
  4729.   mov    edi,[_0b8000h]
  4730.   call   uncrush_text
  4731.   lea    esi,[song_name]
  4732.   mov    edi,(72*2)
  4733.   mov    cl,8
  4734.   mov    ah,0dh
  4735.   call   byte_write1
  4736.   cmp    [byte trakplay_type],1                        ; 1 = ply
  4737.   je     @@dis_ply
  4738.   mov    ecx,trakd_screen_size
  4739.   lea    esi,[trakd_screen]
  4740.   mov    edi,[_0b8000h]
  4741.   add    edi,5600
  4742.   call   uncrush_text
  4743.   jmp    @@dis_done
  4744. @@dis_ply:
  4745.   mov    ecx,trakp_screen_size
  4746.   lea    esi,[trakp_screen]
  4747.   mov    edi,[_0b8000h]
  4748.   add    edi,5600
  4749.   call   uncrush_text
  4750. @@dis_done:
  4751.   ret
  4752. endp
  4753.  
  4754. proc trak_play
  4755.   call   init_for_play
  4756.   cmp    [byte trakplay_type],2                        ; 1 = ply
  4757.   jb     @@dont_pay_from_mod
  4758.   xor    eax,eax
  4759.   mov    al,[byte seq_real]
  4760.   add    al,[byte seq_hl]
  4761.   add    eax,[funk_hr_ptr]
  4762.   cmp    [byte eax+tfunk_hr.order_list],080h
  4763.   jae    @@mess2
  4764.   @splash_on_sm "Backtracking, please wait"
  4765.   mov    al,[byte seq_real]
  4766.   add    al,[byte seq_hl]
  4767. @@back_trak:
  4768.   cli
  4769.   push   eax
  4770.   mov    [byte funk_info.trek_status],PLAY
  4771.   call   funk_tracker
  4772.   mov    [byte funk_info.trek_status],STOP
  4773.   call   stop_all_voices
  4774.   pop    eax
  4775.   sti
  4776.   cmp    [byte funk_info.sequence_ofs],al
  4777.   jne    @@back_trak
  4778.   sub    [byte trakplay_type],2
  4779.   @splash_off_sm
  4780. @@dont_pay_from_mod:
  4781.   call   trak_paint_screen
  4782.   call   dis_chan_status
  4783.   call   display_seqlist
  4784.   cmp    [byte funk_info.no_of_sequences],0ffh
  4785.   je     @@mess1
  4786.   mov    [byte funk_info.trek_status],PLAY
  4787. @@input_loop:
  4788.   @WaitVertEnd
  4789.   @WaitVert
  4790.   call   trak_pattern
  4791.   cmp    [byte trakplay_type],1                        ; 1 = ply
  4792.   je     @@trak_ply
  4793.   call   track_screen_debug
  4794.   jmp    @@trak_done
  4795. @@trak_ply:
  4796.   call   track_screen_play
  4797. @@trak_done:
  4798.   cmp    [byte funk_info.trek_status],STOP
  4799.   je     @@exit
  4800.   call   key_pressed2
  4801.   jnc    @@input_loop
  4802.   call   get_key
  4803.   cmp    al,27
  4804.   je     @@exit
  4805.   cmp    ax,kb_altd
  4806.   je     @@dosshell
  4807.   call   channel_toggle
  4808.   jmp    @@input_loop
  4809. @@dosshell:
  4810.   call   dos_shell
  4811.   mov    [byte funk_info.sequence_ofs_old],0ffh
  4812.   mov    [byte funk_info.pattern_ofs2_old],0ffh
  4813.   call   trak_paint_screen
  4814.   call   display_seqlist
  4815.   jmp    @@input_loop
  4816. @@exit:
  4817.   mov    [byte funk_info.trek_status],STOP
  4818.   call   stop_all_voices
  4819.   ret
  4820. @@mess1:
  4821.   @error_mess "You can not play a song with an empty order list"
  4822.   ret
  4823. @@mess2:
  4824.   @error_mess "backtrack order out of range, try another sequence"
  4825.   ret
  4826. endp
  4827.  
  4828. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4829. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4830. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4831. ;                                                                          ;
  4832. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4833. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4834. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4835.  
  4836. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4837. ;                                                                          ;
  4838. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4839. proc init_vars
  4840.   mov    [byte edit_mode],0
  4841.   mov    [byte pat_number],0
  4842.   mov    [byte pat_real],0
  4843.   mov    [byte pat_hl],0
  4844.   mov    [byte pat_chan],0
  4845.   mov    [byte pat_old_hl],0
  4846.   mov    [byte pat_old_chan],0
  4847.   mov    [byte sam_real],0
  4848.   mov    [byte sam_hl],0
  4849.   mov    [byte sam_col],0
  4850.   mov    [byte note],0
  4851.   mov    [byte octave],2
  4852.   mov    [byte seq_real],0
  4853.   mov    [byte seq_hl],0
  4854.   mov    [word fdir_real],0
  4855.   mov    [byte fdir_hl],0
  4856.   ret
  4857. endp
  4858.  
  4859. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4860. ;                                                                         ;
  4861. ; Routine from Intel Corp                                                 ;
  4862. ;                                                                         ;
  4863. ; 0=????                                                                  ;
  4864. ; 1=????                                                                  ;
  4865. ; 2=????                                                                  ;
  4866. ; 3=Intel386(TM) processor                                                ;
  4867. ; 4=Intel486(TM) processor                                                ;
  4868. ; 5=Pentium(TM) processor                                                 ;
  4869. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4870. cpu_vendor_id         db 12 dup (?)
  4871. cpu_cpu_type          db ?
  4872. cpu_c_model           db ?
  4873. cpu_stepping          db ?
  4874. cpu_id_flag           db 0
  4875. cpu_intel_proc        db 0
  4876. cpu_feature_flags     dw 2 dup (0)
  4877.  
  4878. macro @CPUID
  4879.   db     0fh
  4880.   db     0a2h
  4881. endm
  4882.  
  4883. proc get_cpuid
  4884.   mov    [byte cpu_cpu_type],0
  4885.   mov    [byte cpu_id_flag],0
  4886.   mov    [byte cpu_intel_proc],0
  4887.   pushad
  4888.   mov    ebx,esp
  4889.   and    esp,not 3
  4890.   pushf
  4891.   pop    eax
  4892.   mov    ecx,eax
  4893.   xor    eax,40000h
  4894.   push   eax
  4895.   popf
  4896.   pushf
  4897.   pop    eax
  4898.   xor    eax,ecx
  4899.   mov    [byte cpu_cpu_type],3
  4900.   mov    esp,ebx
  4901.   jz     @@end_get_cpuid
  4902.   and    esp,not 3
  4903.   push   ecx
  4904.   popf
  4905.   mov    esp,ebx
  4906. @@check_80486:
  4907.   mov    [byte cpu_cpu_type],4
  4908.   mov    eax,ecx
  4909.   xor    eax,200000h
  4910.   push   eax
  4911.   popf
  4912.   pushf
  4913.   pop    eax
  4914.   xor    eax,ecx
  4915.   je     @@end_get_cpuid
  4916. @@check_vendor:
  4917.   mov    [byte cpu_id_flag],1
  4918.   xor    eax,eax
  4919.   @CPUID
  4920.   mov    [word cpu_vendor_id],bx
  4921.   mov    [word 4+cpu_vendor_id],dx
  4922.   mov    [word 8+cpu_vendor_id],cx
  4923.   lea    esi,[cpu_vendor_id]
  4924.   lea    edi,[@@intel_id]
  4925.   mov    ecx,length @@intel_id
  4926. @@compare:
  4927.   repe   cmpsb
  4928.   or     ecx,ecx
  4929.   jnz    @@end_get_cpuid
  4930. @@intel_processor:
  4931.   mov    [byte cpu_intel_proc],1
  4932. @@cpuid_data:
  4933.   cmp    eax,1
  4934.   jl     @@end_get_cpuid
  4935.   xor    eax,eax
  4936.   inc    eax
  4937.   @CPUID
  4938.   mov    [byte cpu_stepping],al
  4939.   and    [byte cpu_stepping],0fh
  4940.   and    al,0f0h
  4941.   shr    al,4
  4942.   mov    [byte cpu_c_model],al
  4943.   and    ax,0f00h
  4944.   shr    ax,8
  4945.   mov    [byte cpu_cpu_type],al
  4946.   mov    [word cpu_feature_flags],dx
  4947. @@end_get_cpuid:
  4948.   popad
  4949.   ret
  4950. @@intel_id:
  4951.   db      "GenuineIntel"
  4952. endp
  4953.  
  4954. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4955. ;                                                                          ;
  4956. ; 'info' code:                                                             ;
  4957. ;                                                                          ;
  4958. ;  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   ;
  4959. ;  \-day---/ \month--/ \----year---/   \-card/ \-CPU-/   | 0 0 0 0 0 0 0   ;
  4960. ;                                                        | \memory reqi/   ;
  4961. ;                                                        |                 ;
  4962. ;                                         16 bit = 1 ----|                 ;
  4963. ;                                                                          ;
  4964. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4965. proc clear_all_funk
  4966. ;CLEAR HEADER
  4967.   mov    esi,[funk_hr_ptr]
  4968.   mov    [dword esi+tfunk_hr.sig],"knuF"
  4969.   mov    [dword esi+tfunk_hr.LZH_check_sum],"80kF"
  4970.   mov    ah,2ah
  4971.   int    21h
  4972.   movzx  eax,dl
  4973.   movzx  edx,dh
  4974.   shl    edx,5
  4975.   or     eax,edx
  4976.   sub    ecx,1980
  4977.   shl    ecx,9
  4978.   or     eax,ecx
  4979.   mov    edi,[funk_hr_ptr]
  4980.   mov    [word edi+tfunk_hr.info],ax
  4981.   movzx  ax,[byte init_settings.card_type]
  4982.   mov    bl,[byte cpu_cpu_type]
  4983.   shl    bl,4
  4984.   or     al,bl
  4985.   mov    [word edi+2+tfunk_hr.info],ax
  4986.   mov    [byte edi+tfunk_hr.loop_order],0ffh
  4987.   add    edi,offset (tfunk_hr).order_list
  4988.   mov    al,0ffh
  4989.   mov    ecx,256
  4990.   rep    stosb
  4991.   mov    al,03fh
  4992.   mov    ecx,128
  4993.   rep    stosb
  4994. ;CLEAR SAMPLE BLOCK
  4995.   mov    dl,64
  4996.   mov    edi,[funk_hr_ptr]
  4997.   add    edi,offset (tfunk_hr).funk_sb
  4998. @@clear_sb:
  4999.   xor    al,al
  5000.   mov    ecx,19
  5001.   rep    stosb
  5002.   sub    edi,19
  5003.   mov    [dword edi+tfunk_sb.start],0ffffffffh
  5004.   mov    [dword edi+tfunk_sb.length],0
  5005.   mov    [byte edi+tfunk_sb.volume],0ffh
  5006.   mov    [byte edi+tfunk_sb.balance],80h
  5007.   mov    [byte edi+tfunk_sb.pt_and_sop],08h
  5008.   mov    [byte edi+tfunk_sb.vv_waveform],0
  5009.   mov    [byte edi+tfunk_sb.rl_and_as],43h
  5010.   add    edi,size tfunk_sb
  5011.   dec    dl
  5012.   jnz    @@clear_sb
  5013. ;CLEAR PATTERNS
  5014.   mov    esi,[funk_hr_ptr]
  5015.   add    esi,size tfunk_hr
  5016.   movzx  eax,[byte funk_info.funk_pd_size]
  5017.   mov    ecx,8*64
  5018.   mul    ecx
  5019.   mov    ecx,eax
  5020. @@clear_patterns:
  5021.   @mini_clear_slot
  5022.   add    esi,3
  5023.   dec    ecx
  5024.   jnz    @@clear_patterns
  5025.   call   resync_sample_ptrs
  5026.   ret
  5027. endp
  5028.  
  5029. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5030. ;                                                                          ;
  5031. ; returns eax           MODIFIED: Adam 10/5/95 V1.06                       ;
  5032. ;                                                                          ;
  5033. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5034. proc find_funk_size_parity
  5035.   mov    ebx,[dword file_handle_funk]
  5036.   mov    eax,4202h
  5037.   xor    edx,edx
  5038.   int    21h
  5039.   push   eax
  5040.   mov    ebx,[dword file_handle_funk]
  5041.   mov    eax,4200h
  5042.   xor    edx,edx
  5043.   int    21h
  5044.   pop    eax
  5045.   ret
  5046. endp
  5047.  
  5048. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5049. ;                                                                          ;
  5050. ; edx = points to the filename ANSIIZ                                      ;
  5051. ;                                                                          ;
  5052. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5053. proc load_funk_module
  5054.   push   edx
  5055.   call   clear_all_funk
  5056.   mov    eax,3d00h
  5057.   pop    edx
  5058.   int    21h
  5059.   jc     @@mess1
  5060.   mov    [dword file_handle_funk],eax
  5061.   call   find_funk_size_parity                    ; find parity and size
  5062.   mov    [dword @@temp_size],eax
  5063.   mov    ebx,[dword file_handle_funk]
  5064.   mov    edx,[funk_hr_ptr]
  5065.   mov    ecx,size tfunk_hr
  5066.   mov    ah,3fh                                   ; read header+sample block
  5067.   int    21h
  5068.   cmp    [dword edx+tfunk_hr.sig],"knuF"
  5069.   jne    @@mess2
  5070.   movzx  eax,[byte edx+3+tfunk_hr.info]           ; find memory requirement
  5071.   and    al,11111110b
  5072.   add    al,2
  5073.   shl    eax,18
  5074.   cmp    eax,[dword funk_info.sample_memory_lim]
  5075.   ja     @@mess3
  5076.   call   find_pats_seqs
  5077.   mov    al,[byte funk_info.no_of_patterns]
  5078.   cmp    al,[funk_info.funk_pd_size]
  5079.   ja     @@mess3
  5080.   call   resync_sample_ptrs
  5081.   mov    eax,[dword @@temp_size]                  ; check size and parity
  5082.   mov    edx,[funk_hr_ptr]
  5083.   cmp    [dword edx+tfunk_hr.LZH_check_size],eax
  5084.   jne    @@mess2
  5085.   push   edx
  5086.   mov    eax,600h                                 ; save patterns
  5087.   movzx  ecx,[byte funk_info.no_of_patterns]
  5088.   mul    ecx
  5089.   mov    ebx,[dword file_handle_funk]
  5090.   pop    edx
  5091.   add    edx,size tfunk_hr
  5092.   mov    ecx,eax
  5093.   mov    ah,3fh
  5094.   int    21h
  5095.   mov    eax,[dword funk_info.sample_block_size]
  5096.   sub    eax,[dword funk_info.sample_ptrs]
  5097.   mov    ebx,[dword file_handle_funk]
  5098.   mov    edx,[dword funk_sd_ptr]
  5099.   mov    ecx,eax
  5100.   mov    ah,3fh
  5101.   int    21h
  5102.   mov    ebx,[dword file_handle_funk]
  5103.   mov    ah,3eh                                   ; close
  5104.   int    21h
  5105.   call   upload_exteral_data
  5106.   mov    al,0
  5107.   ret
  5108. @@mess1:
  5109.   mov    al,1                                     ;can't load song
  5110.   ret
  5111. @@mess2:
  5112.   call   clear_all_funk                           ;invalid song
  5113.   mov    al,2
  5114. @@mess3:
  5115.   call   clear_all_funk                           ;not enough sample mem
  5116.   mov    al,3
  5117.   ret
  5118. @@temp_size:
  5119.   dd     ?
  5120. endp
  5121.  
  5122. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5123. ;                                                                          ;
  5124. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5125. proc dnload_exteral_data
  5126.   cmp    [byte init_settings.card_type],GUS_VARB_CARD
  5127.   je     @@GUS_mem_move
  5128.   cmp    [byte init_settings.card_type],GUS_FIXB_CARD
  5129.   je     @@GUS_mem_move
  5130.   ret
  5131. @@GUS_mem_move:
  5132.   call   GUS_reset
  5133.   mov    edi,[dword funk_sd_ptr]
  5134.   mov    esi,[dword funk_info.sample_ptrs]
  5135.   mov    ecx,[dword funk_info.sample_block_size]
  5136.   sub    ecx,[dword funk_info.sample_ptrs]
  5137.   call   GUS_dnload
  5138.   call   GUS_reset
  5139.   call   GUS_intready
  5140.   ret
  5141. endp
  5142.  
  5143. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5144. ;                                                                          ;
  5145. ; edx = points to the filename ANSIIZ                                      ;
  5146. ;                                                                          ;
  5147. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5148. proc save_funk_module
  5149.   mov    [dword @@fn],edx
  5150.   call   find_pats_seqs
  5151.   call   resync_sample_ptrs
  5152.   cmp    [byte funk_info.no_of_sequences],0ffh
  5153.   je     @@mess1
  5154.   mov    eax,[dword funk_info.sample_block_size]
  5155.   cmp    eax,[dword funk_info.sample_ptrs]
  5156.   je     @@mess2
  5157. ; disk space test
  5158.   mov    ah,36h
  5159.   xor    dl,dl
  5160.   int    21h
  5161.   mul    ecx
  5162.   mul    ebx
  5163.   or     edx,edx
  5164.   jnz    @@heaps_of_space
  5165.   push   eax
  5166.   mov    eax,600h
  5167.   movzx  ecx,[byte funk_info.no_of_sequences]
  5168.   inc    ecx
  5169.   mul    ecx
  5170.   mov    ecx,[dword funk_info.sample_block_size]
  5171.   sub    ecx,[dword funk_info.sample_ptrs]
  5172.   add    eax,ecx
  5173.   add    eax,size tfunk_hr
  5174.   pop    ecx
  5175.   cmp    eax,ecx
  5176.   jbe    @@heaps_of_space
  5177.   jmp    @@mess4
  5178. @@heaps_of_space:
  5179.   call   dnload_exteral_data
  5180.   mov    eax,3c00h
  5181.   mov    edx,[dword @@fn]
  5182.   xor    ecx,ecx
  5183.   int    21h
  5184.   jc     @@mess3
  5185.   mov    [dword file_handle_funk],eax
  5186.   mov    ebx,eax
  5187.   mov    edx,[funk_hr_ptr]
  5188.   mov    ecx,size tfunk_hr
  5189.   mov    ah,40h                                   ; save tables+sample block
  5190.   int    21h
  5191.   mov    eax,600h                                 ; save patterns
  5192.   movzx  ecx,[byte funk_info.no_of_patterns]
  5193.   mul    ecx
  5194.   mov    ebx,[dword file_handle_funk]
  5195.   mov    edx,[funk_hr_ptr]
  5196.   add    edx,size tfunk_hr
  5197.   mov    ecx,eax
  5198.   mov    ah,40h
  5199.   int    21h
  5200.   mov    eax,[dword funk_info.sample_block_size]
  5201.   sub    eax,[dword funk_info.sample_ptrs]
  5202.   mov    ebx,[dword file_handle_funk]
  5203.   mov    edx,[dword funk_sd_ptr]
  5204.   mov    ecx,eax
  5205.   mov    ah,40h
  5206.   int    21h
  5207. ; write memory requirement
  5208.   mov    eax,[dword funk_info.sample_block_size]
  5209.   sub    eax,[dword funk_info.sample_ptrs]
  5210.   and    al,11111110b
  5211.   shr    eax,18
  5212. ;; or     al,10000000b
  5213. ;; set bit 7 if a 16 bit sample
  5214.   mov    edx,[funk_hr_ptr]
  5215.   mov    [byte edx+3+tfunk_hr.info],al
  5216.   call   find_funk_size_parity
  5217.   mov    edx,[funk_hr_ptr]
  5218.   mov    [dword edx+tfunk_hr.LZH_check_size],eax
  5219.   mov    edx,[funk_hr_ptr]
  5220.   mov    ecx,offset (tfunk_hr).loop_order
  5221.   mov    ah,40h
  5222.   int    21h
  5223.   mov    ah,3eh                                   ;close
  5224.   int    21h
  5225.   mov    al,0
  5226.   ret
  5227. @@mess1:
  5228.   mov    al,0                                     ;can't save song with emptylist
  5229.   ret
  5230. @@mess2:
  5231.   mov    al,1                                     ;no samples
  5232.   ret
  5233. @@mess3:
  5234.   mov    al,2                                     ;can't save song
  5235.   ret
  5236. @@mess4:
  5237.   mov    al,3                                     ;not enough save on harddisk
  5238.   ret
  5239. @@fn     dd ?
  5240. endp
  5241.  
  5242. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5243. ;                                                                          ;
  5244. ; displays file direct                                                     ;
  5245. ;                                                                          ;
  5246. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5247. proc sload_funk
  5248.   call   stop_all_voices
  5249.   lea    edx,[song_dir]
  5250.   call   set_directory
  5251.   mov    ecx,modefile_screen_size
  5252.   lea    esi,[modefile_screen]
  5253.   mov    edi,[_0b8000h]
  5254.   call   uncrush_text
  5255.   lea    edx,[file_search_funk]
  5256.   call   load_fdirectory
  5257.   call   display_fdir
  5258. @@input_loop:
  5259.   call   get_key
  5260.   cmp    al,27
  5261.   je     @@exit
  5262.   cmp    ax,kb_up
  5263.   je     @@hkb_up
  5264.   cmp    ax,kb_down
  5265.   je     @@hkb_down
  5266.   cmp    ax,kb_pageup
  5267.   je     @@hkb_pageup
  5268.   cmp    ax,kb_pagedn
  5269.   je     @@hkb_pagedn
  5270.   cmp    al,13
  5271.   je     @@enter_key
  5272.   jmp    @@input_loop
  5273. @@scroll_fdir_up:
  5274.   call   display_fdir
  5275.   jmp    @@input_loop
  5276. @@scroll_fdir_dw:
  5277.   call   display_fdir
  5278.   jmp    @@input_loop
  5279. @@hkb_up:
  5280.   call   fdir_scroll_up
  5281.   call   display_fdir
  5282.   jmp    @@input_loop
  5283. @@hkb_down:
  5284.   call   fdir_scroll_dn
  5285.   call   display_fdir
  5286.   jmp    @@input_loop
  5287. @@hkb_pageup:
  5288.   call   fdir_scroll_pageup
  5289.   call   display_fdir
  5290.   jmp    @@input_loop
  5291. @@hkb_pagedn:
  5292.   call   fdir_scroll_pagedn
  5293.   call   display_fdir
  5294.   jmp    @@input_loop
  5295. @@enter_key:
  5296.   mov    cl,size tfdirectory
  5297.   mov    ax,[word fdir_real]
  5298.   add    al,[byte fdir_hl]
  5299.   adc    ah,0
  5300.   mul    cl
  5301.   movzx  esi,ax
  5302.   add    esi,[dword fdirectory_buffer]
  5303.   cmp    [byte esi+tfdirectory.attr],10h
  5304.   jne    @@load_file
  5305.   push   esi
  5306.   lea    esi,[song_dir]
  5307.   mov    edi,esi
  5308.   call   get_directory
  5309.   pop    esi
  5310.   lea    esi,[esi+tfdirectory.fname]
  5311.   call   goto_end_str
  5312.   cmp    ebx,3
  5313.   jne    @@form_path2
  5314.   call   mini_trans_str
  5315.   jmp    @@change_dir
  5316. @@form_path2:
  5317.   mov    [byte edi+ebx],'\'
  5318.   inc    ebx
  5319.   call   mini_trans_str
  5320. @@change_dir:
  5321.   lea    edx,[song_dir]
  5322.   call   set_directory
  5323.   lea    esi,[song_dir]
  5324.   call   get_directory
  5325.   lea    edx,[file_search_funk]
  5326.   call   load_fdirectory
  5327.   call   display_fdir
  5328.   jmp    @@input_loop
  5329. @@load_file:
  5330.   lea    edi,[song_name]
  5331.   lea    esi,[esi+tfdirectory.fname]
  5332.   xor    ebx,ebx
  5333.   call   mini_trans_str
  5334.   lea    esi,[song_name]
  5335.   mov    edi,(72*2)
  5336.   mov    cl,8
  5337.   mov    ah,0dh
  5338.   call   byte_write1
  5339.   lea    edx,[song_name]
  5340.   @splash_on_sm  "Loading music, please wait"
  5341.   call   load_funk_module
  5342.   cmp    al,1
  5343.   je     @@mess1
  5344.   cmp    al,2
  5345.   je     @@mess2
  5346.   cmp    al,3
  5347.   je     @@mess3
  5348.   @splash_off_sm
  5349.   jmp    @@end_mess
  5350. @@mess1:
  5351.   @error_mess "Error: Can not load song"
  5352.   jmp    @@end_mess
  5353. @@mess2:
  5354.   @error_mess "Error: A corrupted or invalid funk song!"
  5355.   jmp    @@end_mess
  5356. @@mess3:
  5357.   @error_mess "Abort: Not enough pattern/sample memory"
  5358. @@end_mess:
  5359.   call   init_vars
  5360. @@exit:
  5361.   call   display_mode
  5362.   ret
  5363. endp
  5364.  
  5365. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5366. ;                                                                          ;
  5367. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5368. proc isave_funk_module
  5369.   @splash_on_sm  "Saving your music, please wait"
  5370.   call   save_funk_module
  5371.   cmp    al,1
  5372.   je     @@mess1
  5373.   cmp    al,2
  5374.   je     @@mess2
  5375.   cmp    al,3
  5376.   je     @@mess3
  5377.   cmp    al,4
  5378.   je     @@mess4
  5379.   @splash_off_sm
  5380.   ret
  5381. @@mess1:
  5382.   @error_mess "Error: Can not save song with empty order list"
  5383.   ret
  5384. @@mess2:
  5385.   @error_mess "Error: Can not save song with no samples"
  5386.   ret
  5387. @@mess3:
  5388.   @error_mess "Error: Unable to save song"
  5389.   ret
  5390. @@mess4:
  5391.   @error_mess "Error: Not enough space on harddisk to save song"
  5392.   ret
  5393. endp
  5394.  
  5395. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5396. ;                                                                          ;
  5397. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5398. proc ssave_funk
  5399.   mov    ch,8
  5400.   mov    edx,0048h
  5401.   call   get_input
  5402.   jc     @@abort
  5403.   lea    esi,[song_name]
  5404.   mov    cl,8
  5405.   call   get_string
  5406.   mov    [byte esi],"."
  5407.   mov    [byte esi+1],"F"
  5408.   mov    [byte esi+2],"N"
  5409.   mov    [byte esi+3],"K"
  5410.   mov    [byte esi+4],0
  5411.   lea    edx,[song_dir]
  5412.   call   set_directory
  5413.   lea    edx,[song_name]
  5414.   call   isave_funk_module
  5415. @@abort:
  5416.   lea    esi,[song_name]
  5417.   mov    edi,(72*2)
  5418.   mov    cl,8
  5419.   mov    ah,0dh
  5420.   call   byte_write1
  5421.   ret
  5422. endp
  5423.  
  5424. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5425. ;                                                                          ;
  5426. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5427. proc dump_GUSmem
  5428.   mov    al,[byte init_settings.card_type]
  5429.   cmp    al,GUS_VARB_CARD
  5430.   je     @@GUS_mem_move
  5431.   cmp    al,GUS_FIXB_CARD
  5432.   je     @@GUS_mem_move
  5433.   ret
  5434. @@GUS_mem_move:
  5435. ; disk space test
  5436.   mov    ah,36h
  5437.   xor    dl,dl
  5438.   int    21h
  5439.   mul    ecx
  5440.   mul    ebx
  5441.   or     edx,edx
  5442.   jz     @@heaps_of_space
  5443.   cmp    eax,[dword funk_info.sample_memory_lim]
  5444.   jb     @@mess3
  5445. @@heaps_of_space:
  5446.   @splash_on_sm  "dumping GUSmem to '\GUS_DUMP·SND', please wait"
  5447.   mov    eax,3c00h
  5448.   lea    edx,[@@dump_name]                        ; create
  5449.   xor    ecx,ecx
  5450.   int    21h
  5451.   jc     @@mess3
  5452.   mov    [dword file_handle_funk],eax
  5453.   call   GUS_reset
  5454.   mov    eax,[dword funk_info.sample_memory_lim]
  5455.   or     eax,eax
  5456.   jz     @@end
  5457.   mov    ebx,4000h
  5458.   xor    edx,edx
  5459.   div    ebx
  5460.   mov    ecx,eax
  5461.   mov    esi,[dword funk_info.sample_ptrs]
  5462. @@dnlop:
  5463.   push   ecx
  5464.   mov    edi,[dword fdirectory_buffer]
  5465.   mov    ecx,4000h
  5466.   call   GUS_dnload
  5467.   mov    ebx,[dword file_handle_funk]
  5468.   mov    edx,[dword fdirectory_buffer]
  5469.   mov    ecx,4000h
  5470.   mov    ah,40h
  5471.   int    21h
  5472.   pop    ecx
  5473.   dec    ecx
  5474.   jnz    @@dnlop
  5475.   call   GUS_reset
  5476. @@end:
  5477.   mov    ebx,[dword file_handle_funk]
  5478.   mov    ah,3eh                                   ; close
  5479.   int    21h
  5480.   call   GUS_intready
  5481.   @splash_off_sm
  5482.   ret
  5483. @@dump_name:
  5484.   db     "\GUS_DUMP.SND",0
  5485. @@mess3:
  5486.   @error_mess "Error: Unable to save dump"
  5487.   ret
  5488. endp
  5489.  
  5490. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5491. ;                                                                          ;
  5492. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5493. proc display_s_info
  5494.   mov    edi,(16*2)+(37*160)
  5495.   mov    eax,[dword funk_info.sample_memory_lim]
  5496.   call   print_decn9
  5497.   mov    edi,(46*2)+(37*160)
  5498.   mov    eax,[dword funk_info.sample_block_size]
  5499.   sub    eax,[dword funk_info.sample_ptrs]
  5500.   call   print_decn9
  5501.   mov    edi,(46*2)+(38*160)
  5502.   mov    eax,[dword funk_info.sample_memory_lim]
  5503.   mov    ecx,[dword funk_info.sample_block_size]
  5504.   sub    ecx,[dword funk_info.sample_ptrs]
  5505.   sub    eax,ecx
  5506.   call   print_decn9
  5507.   ret
  5508. endp
  5509.  
  5510. proc display_midi
  5511.   mov    edi,[_0B8000h]
  5512.   cmp    [MIDI.midi_status],STOP
  5513.   je     @@ddm
  5514.   mov    [dword edi+(32*2)],0a490a4dh
  5515.   mov    [dword edi+(32*2)+4],0a490a44h
  5516.   mov    [dword edi+(32*2)+8],0a4f0a20h
  5517.   mov    [dword edi+(32*2)+12],0a200a4eh
  5518.   jmp    @@t_chord
  5519. @@ddm:
  5520.   mov    [dword edi+(32*2)],0
  5521.   mov    [dword edi+(32*2)+4],0
  5522.   mov    [dword edi+(32*2)+8],0
  5523.   mov    [dword edi+(32*2)+12],0
  5524. @@t_chord:
  5525.   cmp    [byte MIDI_quantise],1
  5526.   jne    @@no_chord
  5527.   mov    [dword edi+(32*2)+16],0a640a43h
  5528.   ret
  5529. @@no_chord:
  5530.   mov    [dword edi+(32*2)+16],0
  5531.   ret
  5532. endp
  5533.  
  5534. proc other_info
  5535.   mov    ebx,[funk_hr_ptr]
  5536. ;Display date
  5537.   mov    al,[byte ebx+tfunk_hr.info]
  5538.   and    al,11111b
  5539.   mov    edi,(68*2)+(40*160)
  5540.   call   print_decn1
  5541.   movzx  eax,[word ebx+tfunk_hr.info]
  5542.   shr    eax,5
  5543.   and    al,1111b
  5544.   mov    edi,(71*2)+(40*160)
  5545.   call   print_decn1
  5546.   movzx  eax,[word ebx+tfunk_hr.info]
  5547.   shr    eax,9
  5548.   and    eax,1111111b
  5549.   add    eax,1980
  5550.   mov    edi,(74*2)+(40*160)
  5551.   call   print_decn3
  5552. ;display cpu
  5553.   movzx  esi,[byte ebx+2+tfunk_hr.info]
  5554.   shr    esi,1
  5555.   and    esi,1111000b
  5556.   add    esi,offset @@cpu_display
  5557.   mov    edi,(68*2)+(41*160)
  5558.   mov    ah,1dh
  5559.   mov    cl,8
  5560.   call   byte_write2
  5561. ;display card
  5562.   mov    ebx,[funk_hr_ptr]
  5563.   movzx  esi,[byte ebx+2+tfunk_hr.info]
  5564.   and    esi,1111b
  5565.   lea    esi,[esi*8]
  5566.   add    esi,offset @@card_display
  5567.   mov    edi,(68*2)+(42*160)
  5568.   mov    ah,1dh
  5569.   mov    cl,8
  5570.   call   byte_write2
  5571. ; display memory
  5572.   mov    ebx,[funk_hr_ptr]
  5573.   movzx  eax,[byte ebx+3+tfunk_hr.info]
  5574.   and    al,11111110b
  5575.   add    al,2
  5576.   shl    eax,18
  5577.   mov    edi,(68*2)+(43*160)
  5578.   call   print_decn9
  5579. ;precision
  5580.   lea    esi,[@@precision1]
  5581.   test   [byte ebx+3+tfunk_hr.info],10000000b
  5582.   jz     @@8bit_module
  5583.   lea    esi,[@@precision2]
  5584. @@8bit_module:
  5585.   mov    edi,(68*2)+(44*160)
  5586.   mov    ah,1dh
  5587.   mov    cl,2
  5588.   call   byte_write2
  5589. ; LZH size
  5590.   mov    ebx,[funk_hr_ptr]
  5591.   mov    edi,(68*2)+(45*160)
  5592.   mov    eax,[dword ebx+tfunk_hr.LZH_check_size]
  5593.   call   print_decn9
  5594. ; LZH checksum
  5595.   mov    esi,offset (tfunk_hr).LZH_check_sum
  5596.   add    esi,ebx
  5597.   cmp    [byte esi],"F"
  5598.   jne    @@endchksum
  5599.   mov    edi,(68*2)+(46*160)
  5600.   mov    ah,1dh
  5601.   mov    cl,4
  5602.   call   byte_write2
  5603. @@endchksum:
  5604.   ret
  5605. @@cpu_display:
  5606.   db     "Unknown "     ;0
  5607.   db     "IBM ????"     ;1
  5608.   db     "IBM ????"     ;2
  5609.   db     "Intel386"     ;3
  5610.   db     "Intel486"     ;4
  5611.   db     "Pentium "     ;5
  5612.   db     ">Pentium"     ;6
  5613.   db     ">Pentium"     ;7
  5614.   db     ">Pentium"     ;8
  5615.   db     ">Pentium"     ;9
  5616.   db     ">Pentium"     ;a
  5617.   db     ">Pentium"     ;b
  5618.   db     ">Pentium"     ;c
  5619.   db     ">Pentium"     ;d
  5620.   db     ">Pentium"     ;e
  5621.   db     ">Pentium"     ;f
  5622. @@card_display:
  5623.   db     "SB 2.0  "     ;0
  5624.   db     "SB PRO  "     ;1
  5625.   db     "GUS v<> "     ;2
  5626.   db     "SB COMP "     ;3
  5627.   db     "SB 16   "     ;4
  5628.   db     "GUS f<> "     ;5
  5629.   db     "Ripped  "     ;6
  5630.   db     "PAS 16  "     ;7
  5631.   db     "????????"     ;8
  5632.   db     "????????"     ;9
  5633.   db     "????????"     ;a
  5634.   db     "????????"     ;b
  5635.   db     "????????"     ;c
  5636.   db     "????????"     ;d
  5637.   db     "????????"     ;e
  5638.   db     "????????"     ;f
  5639. @@precision1:
  5640.   db     "08"
  5641. @@precision2:
  5642.   db     "16"
  5643. endp
  5644.  
  5645. proc display_mode
  5646.   @WaitVertEnd
  5647.   cmp    [byte edit_mode],0
  5648.   je     @@se
  5649.   cmp    [byte edit_mode],1
  5650.   je     @@pe
  5651.   ret
  5652. @@se:
  5653.   mov    ecx,se_screen_size
  5654.   lea    esi,[se_screen]
  5655.   mov    edi,[_0b8000h]
  5656.   call   uncrush_text
  5657.   call   display_samples
  5658.   call   display_s_info
  5659.   call   update_octave
  5660.   call   other_info
  5661.   jmp    @@all
  5662. @@pe:
  5663.   mov    ecx,main_screen_size
  5664.   lea    esi,[main_screen]
  5665.   mov    edi,[_0b8000h]
  5666.   call   uncrush_text
  5667.   mov    ecx,pe_screen_size
  5668.   lea    esi,[pe_screen]
  5669.   mov    edi,[_0b8000h]
  5670.   add    edi,5600
  5671.   call   uncrush_text
  5672.   call   dis_sample_name
  5673.   call   dis_pattern_no
  5674.   call   dis_order_loop
  5675.   call   update_octave
  5676.   movzx  esi,[byte pat_number]
  5677.   mov    dh,[byte pat_real]
  5678.   call   display_pattern
  5679.   call   display_seqlist
  5680.   mov    cl,20h
  5681.   call   display_slot
  5682.   call   dis_chan_status
  5683. @@all:
  5684.   lea    esi,[song_name]
  5685.   mov    edi,(72*2)
  5686.   mov    cl,8
  5687.   mov    ah,0dh
  5688.   call   byte_write1
  5689.   call   display_midi
  5690.   ret
  5691. endp
  5692.  
  5693. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5694. ;                                                                          ;
  5695. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5696. proc set_colour
  5697.   @splash_on_sm  "What Colour do you wish to change?: "
  5698.   mov    ch,2
  5699.   mov    dh,49
  5700.   mov    dl,36
  5701.   call   get_input
  5702.   jc     @@abort
  5703.   call   get_ibyte
  5704.   mov    [byte @@colour],al
  5705.   lea    edi,[@@red_v]
  5706.   mov    ecx,3
  5707.   mov    edx,3c7h                                   ; read palette
  5708.   out    dx,al
  5709.   add    edx,2
  5710.   rep    insb
  5711. ; returns al
  5712. @@input_loop:
  5713.   call   get_key
  5714.   cmp    al,27
  5715.   je     @@abort
  5716.   cmp    al,"q"
  5717.   je     @@dec_r
  5718.   cmp    al,"a"
  5719.   je     @@inc_r
  5720.   cmp    al,"w"
  5721.   je     @@dec_g
  5722.   cmp    al,"s"
  5723.   je     @@inc_g
  5724.   cmp    al,"e"
  5725.   je     @@dec_b
  5726.   cmp    al,"d"
  5727.   je     @@inc_b
  5728.   jmp    @@input_loop
  5729. @@dec_r:
  5730.   cmp    [byte @@red_v],0
  5731.   je     @@input_loop
  5732.   dec    [byte @@red_v]
  5733.   jmp    @@set_pal
  5734. @@inc_r:
  5735.   cmp    [byte @@red_v],63
  5736.   je     @@input_loop
  5737.   inc    [byte @@red_v]
  5738.   jmp    @@set_pal
  5739. @@dec_g:
  5740.   cmp    [byte @@grn_v],0
  5741.   je     @@input_loop
  5742.   dec    [byte @@grn_v]
  5743.   jmp    @@set_pal
  5744. @@inc_g:
  5745.   cmp    [byte @@grn_v],63
  5746.   je     @@input_loop
  5747.   inc    [byte @@grn_v]
  5748.   jmp    @@set_pal
  5749. @@dec_b:
  5750.   cmp    [byte @@ble_v],0
  5751.   je     @@input_loop
  5752.   dec    [byte @@ble_v]
  5753.   jmp    @@set_pal
  5754. @@inc_b:
  5755.   cmp    [byte @@ble_v],63
  5756.   je     @@input_loop
  5757.   inc    [byte @@ble_v]
  5758. @@set_pal:
  5759.   lea    esi,[@@red_v]
  5760.   mov    ecx,3
  5761.   mov    edx,3c8h                                   ; read palette
  5762.   mov    al,[byte @@colour]
  5763.   out    dx,al
  5764.   inc    edx
  5765.   rep    outsb
  5766.   mov    ah,0fh
  5767.   mov    edi,(60*2)+(49*160)
  5768.   mov    bl,[byte @@red_v]
  5769.   call   display_byte
  5770.   mov    edi,(64*2)+(49*160)
  5771.   mov    bl,[byte @@grn_v]
  5772.   call   display_byte
  5773.   mov    edi,(68*2)+(49*160)
  5774.   mov    bl,[byte @@ble_v]
  5775.   call   display_byte
  5776.   jmp    @@input_loop
  5777. @@abort:
  5778.   @splash_off_sm
  5779.   ret
  5780. @@red_v:
  5781.   db     ?
  5782. @@grn_v:
  5783.   db     ?
  5784. @@ble_v:
  5785.   db     ?
  5786. @@colour:
  5787.   db     ?
  5788. endp
  5789.  
  5790. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5791. ;                                                                          ;
  5792. ; Shell to MessyDOS (from DOS32 libraries)                                 ;
  5793. ;                                                                          ;
  5794. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5795. proc dos_shell
  5796.   mov    eax,3h
  5797.   int    10h
  5798.   mov    edx,offset @@shell_mess
  5799.   mov    ah,9
  5800.   int    21h
  5801.   mov    ax,0EE02h
  5802.   int    31h
  5803. @@get_str_loop:
  5804.   cmp    [dword edi],'SMOC'
  5805.   jne    @@not_string
  5806.   cmp    [dword edi+4],'=CEP'
  5807.   je     @@got_string
  5808. @@not_string:
  5809.   mov    al,0
  5810.   mov    ecx,20000
  5811.   repne  scasb
  5812.   jmp    @@get_str_loop
  5813. @@got_string:
  5814.   add    edi,8
  5815.   mov    edx,edi
  5816.   mov    ah,4Bh
  5817.   mov    al,0
  5818.   mov    edi,00000
  5819.   mov    esi,Offset @@dummy_cmd_tail
  5820.   int    21h
  5821.   call   setup_screen
  5822.   ret
  5823. @@shell_mess:
  5824. db "┌────────────────────────────────────────┐",13,10
  5825. db "│ ■ In V86 mode,so please keep it clean. │",13,10
  5826. db "│ ■ Type 'EXIT' to return to FunkTracker │",13,10
  5827. db "└────────────────────────────────────────┘$"
  5828. @@dummy_cmd_tail      db 1,' '
  5829. endp
  5830.  
  5831. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5832. ;                                                                          ;
  5833. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5834. MIDI_test_mode        db ?
  5835. MIDI_chan             db ?
  5836.  
  5837. proc MIDI_off
  5838.   cmp    [MIDI.midi_status],STOP
  5839.   je     @@end
  5840.   cmp    [byte init_settings.card_type],SB16_CARD
  5841.   je     @@sb16_s
  5842.   ret
  5843. @@sb16_s:
  5844.   call   MPU401_Reset
  5845.   mov    [MIDI.midi_status],STOP
  5846. @@end:
  5847.   ret
  5848. endp
  5849.  
  5850. proc MIDI_toggle
  5851.   cmp    [MIDI.midi_status],PLAY
  5852.   je     @@stop_midi
  5853.   cmp    [byte init_settings.card_type],SB16_CARD
  5854.   je     @@sb16_p
  5855.   ret
  5856. @@sb16_p:
  5857.   mov    [MIDI_quantise],0
  5858.   call   MPU401_Reset
  5859.   or     al,al
  5860.   jnz    @@fail
  5861.   call   MPU401_EUARTM
  5862.   or     al,al
  5863.   jnz    @@fail2
  5864.   mov    [MIDI.midi_status],PLAY
  5865.   call   display_midi
  5866.  
  5867.   @splash_on_sm  "Please hit C#1 on your MIDI board...now"
  5868.   mov    [byte MIDI_test_mode],PLAY
  5869. @@l:
  5870.   call   MIDI_decode_single
  5871.   cmp    [byte MIDI_test_mode],PLAY
  5872.   je     @@l
  5873.   @splash_off_sm
  5874.   ret
  5875. @@stop_midi:
  5876.   call   MIDI_off
  5877.   call   display_midi
  5878.   ret
  5879. @@fail:
  5880.   @error_mess "Error: MIDI not detected"
  5881.   ret
  5882. @@fail2:
  5883.   call   MPU401_Reset
  5884.   @error_mess "Error: MIDI not responding"
  5885.   ret
  5886. endp
  5887.  
  5888. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5889. ;                                                ;
  5890. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5891. proc fire_note_chord
  5892.   mov    al,[MIDI.byte2]
  5893.   sub    al,[MIDI.base]
  5894.   cmp    al,59
  5895.   ja     @@done
  5896.   xor    ah,ah
  5897.   mov    cl,12
  5898.   div    cl
  5899.   mov    [byte octave],al
  5900.   mov    [byte note],ah
  5901.  
  5902.   cmp    [byte edit_mode],1
  5903.   jne    @@ignore
  5904. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5905.   mov    dl,[MIDI_chan]
  5906.   call   enter_slot_data         ;dl= [byte pat_chan]
  5907.  
  5908.   xor    cl,cl
  5909.   movzx  esi,[byte pat_number]
  5910.   mov    dl,[MIDI_chan]
  5911.   mov    dh,[byte pat_real]
  5912.   mov    ch,[byte pat_hl]
  5913.   add    dh,ch
  5914.   call   display_slot_f
  5915. @@ignore:
  5916. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5917.   mov    cl,[MIDI_chan]
  5918.   call   play_keynote
  5919.   call   dis_keyboard2
  5920.   cmp    [MIDI_chan],7
  5921.   je     @@done
  5922.   inc    [MIDI_chan]
  5923. @@done:
  5924.   ret
  5925. endp
  5926.  
  5927. proc MIDI_decode_chord
  5928.   cmp    [MIDI.midi_status],STOP
  5929.   je     @@exit
  5930.   call   MIDI_queue_out_sig
  5931.   jc     @@exit
  5932.   mov    ah,al
  5933.   shr    al,4
  5934.   cmp    al,1001b
  5935.   je     @@note_on
  5936.   ret
  5937. @@note_on:
  5938.   mov    [MIDI.byte1],ah
  5939.   mov    al,[pat_chan]
  5940.   mov    [MIDI_chan],al
  5941.   call   clr_keyboard
  5942. @@next_note:
  5943.   call   MIDI_queue_out_pol
  5944.   cmp    al,0feh
  5945.   je     @@done
  5946.   mov    [MIDI.byte2],al
  5947.   call   MIDI_queue_out_pol
  5948.   mov    [MIDI.byte3],al
  5949.   or     al,al
  5950.   jz     @@next_note
  5951.   call   fire_note_chord
  5952.   jmp    @@next_note
  5953. @@done:
  5954.   cmp    [byte edit_mode],1
  5955.   jne    @@exit
  5956.   call   pat_scroll_dn
  5957. @@exit:
  5958.   ret
  5959. endp
  5960.  
  5961. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5962. ;                                                ;
  5963. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5964. proc fire_note_single
  5965.   cmp    [byte MIDI_test_mode],PLAY
  5966.   je     @@test_mode
  5967. ;  mov    edi,(40*2)+(0*160)
  5968. ;  add    edi,[@@scroller2]
  5969. ;  mov    bl,[MIDI.byte2]
  5970. ;  mov    ah,[@@colour2]
  5971. ;  add    ah,8
  5972. ;  call   display_byte
  5973. ;  add    [@@scroller2],4
  5974. ;  and    [@@scroller2],31
  5975. ;  jz     @@c
  5976. ;  inc    [byte @@colour2]
  5977. ;  and    [byte @@colour2],7
  5978. ;@@c:
  5979.  
  5980.   mov    al,[MIDI.byte2]
  5981.   sub    al,[MIDI.base]
  5982.   cmp    al,59
  5983.   ja     @@done
  5984.   xor    ah,ah
  5985.   mov    cl,12
  5986.   div    cl
  5987.   mov    [byte octave],al
  5988.   mov    [byte note],ah
  5989.  
  5990.   cmp    [byte edit_mode],1
  5991.   jne    @@ignore
  5992. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5993.   mov    dl,[pat_chan]
  5994.   call   enter_slot_data         ;dl= [byte pat_chan]
  5995.  
  5996.   xor    cl,cl
  5997.   movzx  esi,[byte pat_number]
  5998.   mov    dl,[pat_chan]
  5999.   mov    dh,[byte pat_real]
  6000.   mov    ch,[byte pat_hl]
  6001.   add    dh,ch
  6002.   call   display_slot_f
  6003. @@ignore:
  6004. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6005.   mov    cl,[pat_chan]
  6006.   call   play_keynote
  6007.   call   dis_keyboard
  6008.   cmp    [byte edit_mode],1
  6009.   jne    @@done
  6010.   call   pat_scroll_dn
  6011. @@done:
  6012.   ret
  6013. ;@@scroller2           dd 0
  6014. ;@@colour2             db 0
  6015. @@test_mode:
  6016.   mov    al,[MIDI.byte2]
  6017.   mov    [MIDI.base],al
  6018.   mov    [byte MIDI_test_mode],STOP
  6019.   ret
  6020. endp
  6021.  
  6022. proc MIDI_decode_single
  6023.   cmp    [MIDI.midi_status],STOP
  6024.   je     @@exit
  6025.   call   MIDI_queue_out_sig
  6026.   jc     @@exit
  6027.   mov    ah,al
  6028.   shr    al,4
  6029.   cmp    al,1001b
  6030.   je     @@note_on
  6031.   ret
  6032. @@note_on:
  6033.   mov    [MIDI.byte1],ah
  6034. @@next_note:
  6035.   call   MIDI_queue_out_pol
  6036.   cmp    al,0feh
  6037.   je     @@exit
  6038.   mov    [MIDI.byte2],al
  6039.   call   MIDI_queue_out_pol
  6040.   mov    [MIDI.byte3],al
  6041.   or     al,al
  6042.   jz     @@next_note
  6043.   call   fire_note_single
  6044.   jmp    @@next_note
  6045. @@exit:
  6046.   ret
  6047. endp
  6048.  
  6049. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6050. ;                                                                          ;
  6051. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6052. proc display_about
  6053.   call   display_mode
  6054.   lea    esi,[splash_screen]
  6055.   mov    edi,[_0b8000h]
  6056.   add    edi,(19*2)+(14*160)
  6057.   mov    ebx,42
  6058.   mov    dl,12
  6059.   call   paint_window
  6060.  
  6061.   call   get_key
  6062.   call   display_mode
  6063.   ret
  6064. endp
  6065.  
  6066. proc main_handle
  6067.   call   display_about
  6068. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6069. @@input_loop:
  6070.   cmp    [byte MIDI_quantise],1
  6071.   je     @@get_chord
  6072.   call   MIDI_decode_single
  6073.   jmp    @@cont
  6074. @@get_chord:
  6075.   call   MIDI_decode_chord
  6076. @@cont:
  6077.   call   key_pressed2
  6078.   jnc    @@input_loop
  6079.   call   get_key
  6080. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6081.   cmp    ax,kb_altx
  6082.   je     @@exit
  6083.   cmp    ax,kb_f1
  6084.   je     @@set_to_se
  6085.   cmp    ax,kb_f2
  6086.   je     @@set_to_pe
  6087.   cmp    ax,kb_f3
  6088.   je     @@dis_help
  6089.   cmp    ax,kb_f5
  6090.   je     @@set_to_trakdbg
  6091.   cmp    ax,kb_altf5
  6092.   je     @@set_to_trakply
  6093.   cmp    ax,kb_f6
  6094.   je     @@set_to_trakfm_dbg
  6095.   cmp    ax,kb_altf6
  6096.   je     @@set_to_trakfm_ply
  6097.   cmp    ax,kb_f7
  6098.   je     @@stop_voices
  6099.   cmp    ax,kb_f8
  6100.   je     @@load
  6101.   cmp    ax,kb_f9
  6102.   je     @@saveas
  6103.   cmp    ax,kb_f10
  6104.   je     @@save
  6105.   cmp    ax,kb_altv
  6106.   je     @@dumptofile
  6107.   cmp    ax,kb_altn
  6108.   je     @@clear_module
  6109.   cmp    ax,kb_altm
  6110.   je     @@set_colour
  6111.   cmp    ax,kb_altd
  6112.   je     @@dosshell
  6113.   cmp    ax,kb_altk
  6114.   je     @@MIDI_toggle
  6115.   cmp    ax,kb_altq
  6116.   je     @@MIDI_quantise
  6117.   cmp    ax,kb_alth
  6118.   je     @@about
  6119.   cmp    ax,kb_altt
  6120.   je     @@toggle_chan
  6121.   cmp    [byte edit_mode],0
  6122.   je     @@se
  6123.   cmp    [byte edit_mode],1
  6124.   je     @@pe
  6125.   jmp    @@input_loop
  6126. @@dis_help:
  6127.   mov    ecx,help_screen_size
  6128.   lea    esi,[help_screen]
  6129.   call   help_scroll
  6130.   jmp    @@input_loop
  6131. @@set_to_se:
  6132.   mov    [byte edit_mode],0
  6133.   call   display_mode
  6134.   jmp    @@input_loop
  6135. @@set_to_pe:
  6136.   mov    [byte edit_mode],1
  6137.   call   display_mode
  6138.   jmp    @@input_loop
  6139. @@set_to_trakdbg:
  6140.   mov    [byte trakplay_type],0
  6141.   call   trak_play
  6142.   call   display_mode
  6143.   jmp    @@input_loop
  6144. @@set_to_trakply:
  6145.   mov    [byte trakplay_type],1
  6146.   call   trak_play
  6147.   call   display_mode
  6148.   jmp    @@input_loop
  6149. @@set_to_trakfm_dbg:
  6150.   mov    [byte trakplay_type],2
  6151.   call   trak_play
  6152.   call   display_mode
  6153.   jmp    @@input_loop
  6154. @@set_to_trakfm_ply:
  6155.   mov    [byte trakplay_type],3
  6156.   call   trak_play
  6157.   call   display_mode
  6158.   jmp    @@input_loop
  6159. @@se:
  6160.   call   se_handle
  6161.   jmp    @@input_loop
  6162. @@pe:
  6163.   call   pe_handle
  6164.   jmp    @@input_loop
  6165. @@stop_voices:
  6166.   call   stop_all_voices
  6167.   jmp    @@input_loop
  6168. @@load:
  6169.   call   sload_funk
  6170.   jmp    @@input_loop
  6171. @@saveas:
  6172.   call   ssave_funk
  6173.   jmp    @@input_loop
  6174. @@save:
  6175.   lea    edx,[song_dir]
  6176.   call   set_directory
  6177.   lea    edx,[song_name]
  6178.   call   isave_funk_module
  6179.   jmp    @@input_loop
  6180. @@clear_module:
  6181.   lea    esi,[@@file_name]
  6182.   lea    edi,[song_name]
  6183.   mov    ecx,13
  6184.   rep    movsb
  6185.   call   clear_all_funk
  6186.   call   display_mode
  6187.   jmp    @@input_loop
  6188. @@set_colour:
  6189.   call   set_colour
  6190.   jmp    @@input_loop
  6191. @@dumptofile:
  6192.   call   dump_GUSmem
  6193.   jmp    @@input_loop
  6194. @@dosshell:
  6195.   call   dos_shell
  6196.   call   display_mode
  6197.   jmp    @@input_loop
  6198. @@MIDI_toggle:
  6199.   call   MIDI_toggle
  6200.   jmp    @@input_loop
  6201. @@MIDI_quantise:
  6202.   xor    [byte MIDI_quantise],1
  6203.   call   display_midi
  6204.   jmp    @@input_loop
  6205. @@about:
  6206.   call   display_about
  6207.   jmp    @@input_loop
  6208. @@toggle_chan:
  6209.   mov    ebx,[funk_hr_ptr]
  6210.   cmp    [word ebx+tfunk_hr.LZH_check_sum],"kF"
  6211.   je     @@toggle_chan1
  6212.   cmp    [word ebx+tfunk_hr.LZH_check_sum],"vF"
  6213.   je     @@toggle_chan2
  6214.   jmp    @@input_loop
  6215. @@toggle_chan1:
  6216.   mov    ebx,[funk_hr_ptr]
  6217.   mov    [word ebx+tfunk_hr.LZH_check_sum],"vF"
  6218.   call   other_info
  6219.   jmp    @@input_loop
  6220. @@toggle_chan2:
  6221.   mov    [word ebx+tfunk_hr.LZH_check_sum],"kF"
  6222.   call   other_info
  6223.   jmp    @@input_loop
  6224. @@exit:
  6225.   @splash_on_sm  "Retreating?, Do you wish to save your music? (y/n)"
  6226.   call   get_key
  6227.   cmp    al,"y"
  6228.   je     @@save_song
  6229.   cmp    al,"Y"
  6230.   je     @@save_song
  6231.   ret
  6232. @@save_song:
  6233.   lea    edx,[song_dir]
  6234.   call   set_directory
  6235.   lea    edx,[song_name]
  6236.   call   isave_funk_module
  6237.   ret
  6238. @@file_name:
  6239.   db     "NEW_SONG.FNK",0
  6240. endp
  6241.  
  6242. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6243. ;                                                                         ;
  6244. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6245. help_mess             db 13,10,"COMMAND LINE: funk -h -cX -sX -pXX -bXXXXXXXX",13,10
  6246.                       db "       cX: Card type (0=PAS, 1=GUS, 2=CT card)",13,10
  6247.                       db "       sX: Sample rate (0=11025hz,1=16538hz,2=22050hz,3=33075hz,4=44100hz)",13,10
  6248.                       db "      pXX: Pattern allocation, hex number [default -p80]",13,10
  6249.                       db "bXXXXXXXX: Sample allocation, hex number [default: -b00100000]",13,10
  6250.                       db "$"
  6251. parm_card             db 0ffh
  6252.  
  6253. proc search_funkline
  6254.   mov    bx,"h-"
  6255.   call   @@get_parm
  6256.   jnc    @@help
  6257.   mov    bx,"c-"
  6258.   call   @@get_parm
  6259.   jnc    @@set_card
  6260. @@scb:
  6261.   mov    bx,"s-"
  6262.   call   @@get_parm
  6263.   jnc    @@set_sr
  6264. @@scp:
  6265.   mov    bx,"p-"
  6266.   call   @@get_parm
  6267.   jnc    @@set_pa
  6268. @@scbb:
  6269.   mov    bx,"b-"
  6270.   call   @@get_parm
  6271.   jnc    @@set_sa
  6272. @@end:
  6273.   ret
  6274. @@help:
  6275.   lea    edx,[help_mess]
  6276.   mov    ah,9
  6277.   int    21h
  6278.   mov    eax,4c00h
  6279.   int    21h
  6280. @@set_card:
  6281.   sub    al,"0"
  6282.   mov    [byte parm_card],al
  6283.   jmp    @@scb
  6284. @@set_sr:
  6285.   sub    al,"0"
  6286.   js     @@end
  6287.   cmp    al,4
  6288.   ja     @@scp
  6289.   mov    [byte init_settings.DAC_Samplerate],al
  6290.   jmp    @@scp
  6291. @@set_pa:
  6292.   add    edi,2
  6293.   call   get_vbyte
  6294.   mov    [funk_info.funk_pd_size],al
  6295.   jmp    @@scbb
  6296. @@set_sa:
  6297.   add    edi,2
  6298.   call   get_vdword
  6299.   mov    [funk_info.sample_memory_lim],ebx
  6300.   jmp    @@end
  6301. proc @@get_parm
  6302.   mov    edi,[PSP_Address]
  6303.   add    edi,81h
  6304.   mov    cl,128
  6305. @@l:
  6306.   cmp    bx,[word edi]
  6307.   je     @@found
  6308.   cmp    [byte edi],13
  6309.   je     @@eol
  6310.   inc    edi
  6311.   dec    cl
  6312.   jnz    @@l
  6313. @@eol:
  6314.   stc
  6315.   ret
  6316. @@found:
  6317.   mov    al,[byte edi+2]
  6318.   clc
  6319.   ret
  6320. endp
  6321. endp
  6322.  
  6323. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6324. ;                                                                         ;
  6325. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6326. proc alloc_funk_mem
  6327. ;alloc DMA
  6328.   mov    eax,0EE41h         ; allocate a 16Kb DMA buffer
  6329.   Int    31h                ;  rets EDX->near pointer EBX = phys address
  6330.   jc     @@memory_error
  6331.   mov    [funk_dma_buffer_addr],edx
  6332. ;alloc header
  6333.   cmp    [byte funk_info.funk_pd_size],2
  6334.   jb     @@illegal_mem
  6335.   cmp    [byte funk_info.funk_pd_size],80h
  6336.   ja     @@illegal_mem
  6337.   movzx  ecx,[byte funk_info.funk_pd_size]     ;(600h*128)
  6338.   mov    eax,600h
  6339.   mul    ecx
  6340.   mov    edx,eax
  6341.   add    edx,size tfunk_hr
  6342.   mov    AX,0EE42h          ; allocate a DOS32 memory block
  6343.   Int    31h                ;  expects EDX = size; ret EAX=size, EDX->pointer
  6344.   jc     @@memory_error
  6345.   mov    [funk_hr_ptr],edx
  6346. ;alloc sample block
  6347.   mov    edx,[dword funk_info.sample_memory_lim]
  6348.   cmp    edx,00001000h
  6349.   jb     @@illegal_mem
  6350.   mov    AX,0EE42h          ; allocate a DOS32 memory block
  6351.   int    31h                ;  expects EDX = size; ret EAX=size, EDX->pointer
  6352.   jc     @@memory_error
  6353.   mov    [funk_sd_ptr],edx
  6354. ;alloc directory buffer
  6355.   mov    eax,size tfdirectory
  6356.   mov    ecx,fdir_max_length
  6357.   mul    ecx
  6358.   add    eax,1000h
  6359.   mov    edx,eax
  6360.   mov    AX,0EE42h          ; allocate a DOS32 memory block
  6361.   Int    31h
  6362.   jc     @@memory_error
  6363.   mov    [dword fdirectory_buffer],edx
  6364.   cli
  6365.   ret
  6366. @@memory_error:
  6367.   mov    eax,3h
  6368.   int    10h
  6369.   lea    edx,[@@main_mess1]
  6370.   mov    ah,9
  6371.   int    21h
  6372.   sti
  6373.   ret
  6374. @@illegal_mem:
  6375.   mov    eax,3h
  6376.   int    10h
  6377.   lea    edx,[@@main_mess2]
  6378.   mov    ah,9
  6379.   int    21h
  6380.   sti
  6381.   ret
  6382. @@main_mess1:
  6383. db "Memory Error. FunkTracker unable to run.",13,10,"$"
  6384. @@main_mess2:
  6385. db "Invalid memory entry as parameter. FunkTracker unable to run.",13,10,"$"
  6386. endp
  6387.  
  6388. proc dealloc_funk_mem
  6389. ;dealloc directory buffer
  6390.   mov    eax,0EE40h
  6391.   int    31h
  6392. ;dealloc sam blok
  6393.   mov    eax,0EE40h
  6394.   int    31h
  6395. ;dealloc hdr blok
  6396.   mov    eax,0EE40h
  6397.   int    31h
  6398. ;delloc DMA
  6399.   mov    eax,0EE40h
  6400.   int    31h
  6401.   ret
  6402. endp
  6403.  
  6404. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6405. ;                                                                         ;
  6406. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6407.  
  6408. main_mess0:
  6409. db "Using DOS32 V"
  6410. ver_major:
  6411. db "0."
  6412. ver_minor:
  6413. db "00 by Adam Seychell",13,10,"$"
  6414. main_mess1:
  6415. db "FunkTracker/SuperReal                                       by Jason Nunn (JsNO)"
  6416. db "────────────────────────────────────────────────────────────────────────────────$"
  6417. main_mess3:
  6418. db "No legal sound card not detected.",13,10,"$"
  6419. main_mess4:
  6420. db "Soundcard initisation failed. FunkTracker unable to run.",13,10,"$"
  6421.  
  6422. Start_FunkTracker:
  6423. ;  call   debug
  6424.   cld
  6425.   mov    ax,0EE02h       ; get DOS32 address information
  6426.   int    31h
  6427.   neg    ebx
  6428.   mov    [Zero_Addr],ebx
  6429.   add    ebx,0b8000h
  6430.   mov    [_0B8000h],ebx
  6431.   mov    [Environment_Address],edi
  6432.   mov    [PSP_Address],esi
  6433.  
  6434.   lea    edx,[main_mess1]
  6435.   mov    ah,9
  6436.   int    21h
  6437.   call   get_cpuid
  6438.   mov    eax,0EE00h
  6439.   int    31h
  6440.   push   edx
  6441.   and    eax,0f0fh
  6442.   add    [byte ver_major],ah
  6443.   add    [byte ver_minor+1],al
  6444.   lea    edx,[main_mess0]
  6445.   mov    ah,9
  6446.   int    21h
  6447.   pop    edx
  6448.   call   search_funkline
  6449.   call   alloc_funk_mem
  6450.   jc     @@abort
  6451.   call   init_vars
  6452.   mov    bl,[parm_card]
  6453.   call   FNK_autodetect
  6454.   jc     @@card_not_found
  6455.   lea    esi,[initial_dir]
  6456.   call   get_directory
  6457.   lea    esi,[song_dir]
  6458.   call   get_directory
  6459.   lea    esi,[sample_dir]
  6460.   call   get_directory
  6461.   mov    eax,[funk_dma_buffer_addr]
  6462.   call   FNK_card_init
  6463.   jc     @@card_error
  6464.   call   init_for_play
  6465.   call   clear_all_funk
  6466.   call   setup_screen
  6467.   call   main_handle
  6468.   call   MIDI_off
  6469.   call   FNK_card_deinit
  6470.   call   text_ded_pfout
  6471.   lea    edx,[initial_dir]
  6472.   call   set_directory
  6473.   mov    eax,3h
  6474.   int    10h
  6475.   mov    ecx,end_screen_size
  6476.   lea    esi,[end_screen]
  6477.   mov    edi,[_0b8000h]
  6478.   call   uncrush_text
  6479.   mov    ah,02h
  6480.   xor    bh,bh
  6481.   mov    edx,0400h
  6482.   int    10h
  6483. @@abort:
  6484.   call   dealloc_funk_mem
  6485.   mov    eax,4c00h
  6486.   int    21h
  6487. @@card_not_found:
  6488.   mov    eax,3h
  6489.   int    10h
  6490.   lea    edx,[main_mess3]
  6491.   mov    ah,9
  6492.   int    21h
  6493.   jmp    @@abort
  6494. @@card_error:
  6495.   mov    eax,3h
  6496.   int    10h
  6497.   lea    edx,[main_mess4]
  6498.   mov    ah,9
  6499.   int    21h
  6500.   jmp    @@abort
  6501. ends
  6502.  
  6503. end Start_FunkTracker
  6504.