home *** CD-ROM | disk | FTP | other *** search
/ The Party 1994: Try This At Home / disk_image.bin / source / cbrosrc / gusplay.asm < prev    next >
Assembly Source File  |  1995-03-13  |  62KB  |  2,290 lines

  1. ;
  2. ; This is GUSPLAY by Robban/Cascada, two little modifications done
  3. ; by me... the interrupt rate and and a framecounter for syncing
  4. ; video to music... sorry about raping the replay, robban!
  5. ;
  6.         .386
  7.  
  8. player_intrate          equ 512                         ; Hz
  9. player_pit_divisor      equ (1193180/player_intrate)
  10.  
  11.         .286
  12.  
  13.         Jumps
  14.  
  15. _Code   Segment Para 'PlaySeg'
  16.  
  17.         assume  cs:_Code
  18.  
  19. ;       Publics
  20.  
  21. Public  MainVolume,PlayingPattern,RealPPattern,PatternRow,RealRow,OrderLen,ChanOn,NumChans,Time,SampChans,Bar,BasePort,ErrorCode,Syncro
  22. public  framespersec, framecounter, frames
  23. Public  LoadMod,ClearMem,StartPlaying,StopPlaying,Init,InitDevice
  24.  
  25. ;       Structures
  26.  
  27. ChanSize        Equ 52
  28.  
  29. ChanInfo        Struc
  30.  
  31. SampOff         dd 0
  32. FreqVal         dw 0
  33. Vol             dw 0
  34. OldVol          dw 0
  35. Fine            dw 0
  36. Repeat          dw 0
  37. RepLen          dw 0
  38. Len             dw 0
  39. Amiga           dw 0
  40. Effect          dw 0
  41. VibratoPek      dw 0
  42. OldVibrato      dw 0
  43. PortTo          dw 0
  44. OldPortTo       dw 0
  45. EffectTime      dw 0
  46. CurrSamp        dw 0
  47. OldSamp         dw 0
  48. Arp             dw 0,0,0
  49. ArpCounter      dw 0
  50. InstSet         dw 0
  51. LoopOnOff       dw 0
  52. OffsetAdd       dw 0
  53. Bar             dw 0
  54.  
  55. ChanInfo        EndS
  56.  
  57. ; Number of voices to use
  58.  
  59. NumVoices       Equ 14
  60.  
  61. ; UltraSound Ports
  62.  
  63. StatusPort      Equ 6h
  64. TimerCtrlPort   Equ 8h
  65. TimerDataPort   Equ 9h
  66. MidiCtrlPort    Equ 100h
  67. MidiDataPort    Equ 101h
  68. ActiveVoicePort Equ 102h
  69. CommandPort     Equ 103h
  70. DataLowPort     Equ 104h
  71. DataHighPort    Equ 105h
  72. DRAMIOPort      Equ 107h
  73.  
  74. ; UltraSound Commands
  75.  
  76. WriteVoiceMode  Equ 00h
  77. SetVoiceFreq    Equ 01h         ; Value=Freq/Divisor
  78. LoopStartLo     Equ 02h
  79. LoopStartHi     Equ 03h
  80. SampleEndLo     Equ 04h
  81. SampleEndHi     Equ 05h
  82. VolRampRate     Equ 06h
  83. VolRampStart    Equ 07h
  84. VolRampEnd      Equ 08h
  85. SetVolume       Equ 09h
  86. SampleStartLo   Equ 0Ah
  87. SampleStartHi   Equ 0Bh
  88. VoiceBalance    Equ 0Ch
  89. VolumeCtrl      Equ 0Dh
  90. VoicesActive    Equ 0Eh
  91. DMACtrl         Equ 41h
  92. DRAMAddrLo      Equ 43h
  93. DRAMAddrHi      Equ 44h
  94. Initialize      Equ 4Ch
  95. ReadVolume      Equ 89h
  96. VoicePosLo      Equ 8Ah
  97. VoicePosHi      Equ 8Bh
  98. ReadVolCtrl     Equ 8Dh
  99.  
  100. ; Divisors
  101.  
  102. Voices14        Equ 4410-1
  103. Voices15        Equ 4000
  104. Voices16        Equ 3700
  105. Voices17        Equ 3500
  106. Voices18        Equ 3300
  107. Voices19        Equ 3100
  108. Voices20        Equ 3030
  109. Voices21        Equ 2800
  110. Voices22        Equ 2700
  111. Voices23        Equ 2600
  112. Voices24        Equ 2500
  113. Voices25        Equ 2400
  114. Voices26        Equ 2300
  115. Voices27        Equ 2200
  116. Voices28        Equ 2100
  117. Voices29        Equ 2000
  118. Voices30        Equ 2000
  119. Voices31        Equ 1900
  120. Voices32        Equ 1800
  121.  
  122. ;       Variables
  123.  
  124. MKSign          db 'M.K.FLT46CHN8CHNOCTA'
  125. MKMod           db 0
  126. Info            db 1084 dup (0)
  127. OrderLen        db 0
  128. Restart         db 0
  129. PatternOrder    db 128 dup (0)
  130.  
  131. SinTab          db 0,25,50,74,98,120,142,162,180,197,212,225,236
  132.                 db 244,250,254,255,254,250,244,236,225,212,197,180
  133.                 db 162,142,120,98,74,50,25
  134.  
  135. ArpTable      db 70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70
  136.               db 70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,68,68,68,68,68,68,68,66,66,66,66,66,66,66,64,64,64,64,64,64,64,64,62,62,62,62,62,62,62,62,60,60,60,60,60,60,60,60,58,58,58,58,58,58
  137.               db 58,58,58,56,56,56,56,56,56,56,56,56,56,54,54,54,54,54,54,54,54,54,54,52,52,52,52,52,52,52,52,52,52,50,50,50,50,50,50,50,50,50,50,50,50,48,48,48,48,48,48,48,48,48,48,48,48,46,46,46,46,46,46,46,46,46,46,46,46,44,44,44,44,44,44,44,44,44,44
  138.               db 44,44,44,44,42,42,42,42,42,42,42,42,42,42,42,42,42,42,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,36,36,36,36,36,36,36,36,36,36,36,36,36,36,36,36,36,34,34,34,34,34,34,34,34,34,34,34,34,34
  139.               db 34,34,34,34,34,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,26,26,26,26,26,26,26,26,26,26,26,26,26
  140.               db 26,26,26,26,26,26,26,26,26,26,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20
  141.               db 20,20,20,20,20,20,20,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,14,14,14,14,14,14,14,14,14,14,14,14,14,14
  142.               db 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10
  143.               db 10,10,10,10,10,10,10,10,10,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4
  144.               db 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  145.  
  146. pl=4
  147. pr=11
  148. PanRegs         db pl,pr,pr,pl,0,0,0,0,0,0,0,0,0,0,0,0
  149.  
  150. EvenData
  151.  
  152. AmigaVals       dw 856,808,762,720,678,640,604,570,538,508,480,453 ;C-1 to B-1 Finetune +0.
  153.                 dw 428,404,381,360,339,320,302,285,269,254,240,226 ;C-2 to B-2 Finetune +0.
  154.                 dw 214,202,190,180,170,160,151,143,135,127,120,113 ;C-3 to B-3 Finetune +0.
  155.  
  156.                 dw 850,802,757,715,674,637,601,567,535,505,477,450 ;C-1 to B-1 Finetune +1.
  157.                 dw 425,401,379,357,337,318,300,284,268,253,239,225 ;C-2 to B-2 Finetune +1.
  158.                 dw 213,201,189,179,169,159,150,142,134,126,119,113 ;C-3 to B-3 Finetune +1.
  159.  
  160.                 dw 844,796,752,709,670,632,597,563,532,502,474,447 ;C-1 to B-1 Finetune +2.
  161.                 dw 422,398,376,355,335,316,298,282,266,251,237,224 ;C-2 to B-2 Finetune +2.
  162.                 dw 211,199,188,177,167,158,149,141,133,125,118,112 ;C-3 to B-3 Finetune +2.
  163.  
  164.                 dw 838,791,746,704,665,628,592,559,528,498,470,444 ;C-1 to B-1 Finetune +3.
  165.                 dw 419,395,373,352,332,314,296,280,264,249,235,222 ;C-2 to B-2 Finetune +3.
  166.                 dw 209,198,187,176,166,157,148,140,132,125,118,111 ;C-3 to B-3 Finetune +3.
  167.  
  168.                 dw 832,785,741,699,660,623,588,555,524,495,467,441 ;C-1 to B-1 Finetune +4.
  169.                 dw 416,392,370,350,330,312,294,278,262,247,233,220 ;C-2 to B-2 Finetune +4.
  170.                 dw 208,196,185,175,165,156,147,139,131,124,117,110 ;C-3 to B-3 Finetune +4.
  171.  
  172.                 dw 826,779,736,694,655,619,584,551,520,491,463,437 ;C-1 to B-1 Finetune +5.
  173.                 dw 413,390,368,347,328,309,292,276,260,245,232,219 ;C-2 to B-2 Finetune +5.
  174.                 dw 206,195,184,174,164,155,146,138,130,123,116,109 ;C-3 to B-3 Finetune +5.
  175.  
  176.                 dw 820,774,730,689,651,614,580,547,516,487,460,434 ;C-1 to B-1 Finetune +6.
  177.                 dw 410,387,365,345,325,307,290,274,258,244,230,217 ;C-2 to B-2 Finetune +6.
  178.                 dw 205,193,183,172,163,154,145,137,129,122,115,109 ;C-3 to B-3 Finetune +6.
  179.  
  180.                 dw 814,768,725,684,646,610,575,543,513,484,457,431 ;C-1 to B-1 Finetune +7.
  181.                 dw 407,384,363,342,323,305,288,272,256,242,228,216 ;C-2 to B-2 Finetune +7.
  182.                 dw 204,192,181,171,161,152,144,136,128,121,114,108 ;C-3 to B-3 Finetune +7.
  183.  
  184.                 dw 907,856,808,762,720,678,640,604,570,538,504,480 ;C-1 to B-1 Finetune -8.
  185.                 dw 453,428,404,381,360,339,320,302,285,269,254,240 ;C-2 to B-2 Finetune -8.
  186.                 dw 226,214,202,190,180,170,160,151,143,135,127,120 ;C-3 to B-3 Finetune -8.
  187.  
  188.                 dw 900,850,802,757,715,675,636,601,567,535,505,477 ;C-1 to B-1 Finetune -7.
  189.                 dw 450,425,401,379,357,337,318,300,284,268,253,238 ;C-2 to B-2 Finetune -7.
  190.                 dw 225,212,200,189,179,169,159,150,142,134,126,119 ;C-3 to B-3 Finetune -7.
  191.  
  192.                 dw 894,844,796,752,709,670,632,597,563,532,502,474 ;C-1 to B-1 Finetune -6.
  193.                 dw 447,422,398,376,355,335,316,298,282,266,251,237 ;C-2 to B-2 Finetune -6.
  194.                 dw 223,211,199,188,177,167,158,149,141,133,125,118 ;C-3 to B-3 Finetune -6.
  195.  
  196.                 dw 887,838,791,746,704,665,628,592,559,528,498,470 ;C-1 to B-1 Finetune -5.
  197.                 dw 444,419,395,373,352,332,314,296,280,264,249,235 ;C-2 to B-2 Finetune -5.
  198.                 dw 222,209,198,187,176,166,157,148,140,132,125,118 ;C-3 to B-3 Finetune -5.
  199.  
  200.                 dw 881,832,785,741,699,660,623,588,555,524,494,467 ;C-1 to B-1 Finetune -4.
  201.                 dw 441,416,392,370,350,330,312,294,278,262,247,233 ;C-2 to B-2 Finetune -4.
  202.                 dw 220,208,196,185,175,165,156,147,139,131,123,117 ;C-3 to B-3 Finetune -4.
  203.  
  204.                 dw 875,826,779,736,694,655,619,584,551,520,491,463 ;C-1 to B-1 Finetune -3.
  205.                 dw 437,413,390,368,347,338,309,292,276,260,245,232 ;C-2 to B-2 Finetune -3.
  206.                 dw 219,206,195,184,174,164,155,146,138,130,123,116 ;C-3 to B-3 Finetune -3.
  207.  
  208.                 dw 868,820,774,730,689,651,614,580,547,516,487,460 ;C-1 to B-1 Finetune -2.
  209.                 dw 434,410,387,365,345,325,307,290,274,258,244,230 ;C-2 to B-2 Finetune -2.
  210.                 dw 217,205,193,183,172,163,154,145,137,129,122,115 ;C-3 to B-3 Finetune -2.
  211.  
  212.                 dw 862,814,768,725,684,646,610,575,543,513,484,457 ;C-1 to B-1 Finetune -1.
  213.                 dw 431,407,384,363,342,323,305,288,272,256,242,228 ;C-2 to B-2 Finetune -1.
  214.                 dw 216,203,192,181,171,161,152,144,136,128,121,114 ;C-3 to B-3 Finetune -1.
  215.  
  216. GusVol          dw 20000,39120,41376,42656,43936,45072,45696,46240,46848,47408
  217.                 dw 47952,48528,49072,49360,49632,49920,50160,50432,50704,50928
  218.                 dw 51168,51424,51680,51952,52160,52448,52672,52912,53152,53312
  219.                 dw 53440,53584,53664,53808,53952,54048,54144,54288,54400,54496
  220.                 dw 54608,54720,54832,54944,55072,55184,55312,55440,55552,55696
  221.                 dw 55760,55888,56016,56096,56240,56304,56448,56528,56672,56752
  222.                 dw 56896,56976,57136,57216
  223.  
  224. SampOffset      dd 31 dup (0)
  225. SampLen         dw 31 dup (0)
  226. SampVol         dw 31 dup (0)
  227. SampFine        dw 31 dup (0)
  228. SampRep         dw 31 dup (0)
  229. SampRepLen      dw 31 dup (0)
  230.  
  231. BasePort        dw 220h
  232. FileHandle      dw 0
  233. NumChans        dw 4                    ; 4,6 or 8 (Defualt = 4)
  234. ChanOn          dw 0FFh
  235. ChanOnCount     dw 0
  236. PatternSpeed    dw 0
  237. PatternCount    dw 0
  238. PatternRow      dw 0
  239. RealRow         dw 0
  240. PlayingPattern  dw 0
  241. RealPPattern    dw 0
  242.  
  243. framespersec    dw 70
  244. framecounter    dw player_intrate/70
  245. frametimer      dw 1
  246. frames          dw 0
  247.  
  248. Syncro          dw 0
  249.  
  250. MainVolume      dw 0
  251. TempVol         dw 0
  252. ErrorCode       dw 0
  253.  
  254. FreqTable       dw 908 dup (0)
  255.  
  256. PatternPek      equ this DWord
  257. BytePattern     dw 0
  258. SegPattern      dw 0
  259.  
  260. SampMem         dw 0
  261. PatternMem      dw 0
  262. BreakData       dw 0
  263. OldTimer        dd 0
  264. GUSMem          dd 0
  265. Speed           dd 0
  266. SpeedAdd        dd 0
  267. Counter         dw 0
  268. Time            dd 0
  269. JumpOldTimer    dw 0
  270.  
  271. SampChans       ChanInfo 8 dup (<>)
  272.  
  273. ;       Macros
  274.  
  275. ;       The Code
  276.  
  277. Even
  278.  
  279.  
  280.  
  281.         assume  ds:_Code
  282.  
  283. waitgus:
  284.         rept 7
  285.         in      al, dx
  286.         endm
  287.         ret
  288.  
  289. Pattern         Proc    Near
  290.  
  291.         pusha
  292.         push    ds
  293.         push    es
  294.  
  295.         mov     ax,_Code
  296.         mov     ds,ax
  297.  
  298.         mov     al,20h
  299.         out     20h,al
  300.         sti
  301.  
  302.         add     Word Ptr [Time],1
  303.         adc     Word Ptr [Time+2],0
  304.  
  305.         inc     [Counter]
  306.         mov     ax,Word Ptr [Speed+2]
  307.         add     Word Ptr [SpeedAdd+2],ax
  308.         mov     ax,Word Ptr [Speed]
  309.         adc     Word Ptr [SpeedAdd],ax
  310.         jc      JumpPattern
  311.         mov     ax, [counter]
  312.         cmp     ax,4
  313.         je      ClearNotes
  314.         cmp     ax,5
  315.         je      SetNotes
  316.         jmp     EndPattern
  317.  
  318. ClearNotes:
  319.         mov     di,offset [SampChans]
  320.         mov     cx,[NumChans]
  321.         mov     dx,[BasePort]
  322.         add     dx,CommandPort
  323.  
  324. StopVoices:
  325.         dec     dx
  326.         mov     al,Byte Ptr [NumChans]
  327.         sub     al,cl
  328.         out     dx,al
  329.         inc     dx
  330.  
  331.         cmp     [di.InstSet],2
  332.         je      VoiceOff1
  333.         cmp     [di.InstSet],1
  334.         je      VoiceOff2
  335.         cmp     [di.OffsetAdd],0
  336.         jne     VoiceOff1
  337.         jmp     NoVoiceOff
  338.  
  339. VoiceOff2:
  340.         mov     ax,[di.CurrSamp]
  341.         cmp     ax,[di.OldSamp]
  342.         jne     VoiceOff1
  343.         jmp     NoVoiceOff
  344.  
  345. VoiceOff1:
  346.         mov     ax,[di.OldVol]
  347.         mov     [di.OldVol],0
  348.         mul     word [MainVolume]
  349.         shr     ax,6
  350.         adc     ax,0
  351.         mov     bx,ax
  352.         shl     bx,1
  353.         mov     bx,[GusVol+bx]
  354.  
  355.         mov     dx,[BasePort]
  356.         add     dx,CommandPort
  357.  
  358.         mov     al,VolumeCtrl
  359.         out     dx,al
  360.         add     dx,2
  361.         mov     al,3
  362.         out     dx,al
  363.         sub     dx,2
  364.  
  365.         mov     bp,[GusVol]
  366.         mov     ah,0
  367.         cmp     bx,bp
  368.         jb      NoFixVolDir1
  369.         mov     ah,01000000b
  370.         xchg    bx,bp
  371. NoFixVolDir1:
  372.  
  373.         mov     al,VolRampStart
  374.         out     dx,al
  375.         xchg    ax,bx
  376.         inc     dx
  377.         out     dx,ax
  378.         dec     dx
  379.  
  380.         mov     al,VolRampEnd
  381.         out     dx,al
  382.         mov     ax,bp
  383.         inc     dx
  384.         out     dx,ax
  385.         dec     dx
  386.  
  387.         mov     al,VolumeCtrl
  388.         out     dx,al
  389.         mov     al,bh
  390.         add     dx,2
  391.         out     dx,al
  392.         sub     dx,2
  393. NoVoiceOff:
  394.  
  395.         add     di,ChanSize
  396.         dec     cx
  397.         jnz     StopVoices
  398.         jmp     EndPattern
  399.  
  400. SetNotes:
  401.         mov     [Counter],1
  402.         mov     di,offset [SampChans]
  403.         mov     cx,[NumChans]
  404.         mov     dx,[BasePort]
  405.         add     dx,CommandPort
  406.  
  407. ChangeSamps:
  408.         dec     dx
  409.         mov     al,Byte Ptr [NumChans]
  410.         sub     al,cl
  411.         out     dx,al
  412.         inc     dx
  413.  
  414.         cmp     [di.InstSet],2
  415.         je      SampChange1
  416.         cmp     [di.InstSet],1
  417.         je      SampChange2
  418.         cmp     [di.OffsetAdd],0
  419.         jne     ChangeOffset
  420.         jmp     NoChangeSamp
  421.  
  422. ChangeOffset:
  423.         mov     al,SampleStartLo
  424.         out     dx,al
  425.         inc     dx
  426.         mov     ax,Word Ptr [di.SampOff]
  427.         mov     bp,Word Ptr [di.SampOff+2]
  428.         add     ax,[di.OffsetAdd]
  429.         adc     bp,0
  430.         shr     ax,7
  431.         shl     bp,9
  432.         or      ax,bp
  433.         out     dx,ax
  434.         dec     dx
  435.         mov     al,SampleStartHi
  436.         out     dx,al
  437.         inc     dx
  438.         mov     ax,Word Ptr [di.SampOff]
  439.         add     ax,[di.OffsetAdd]
  440.         shl     ax,9
  441.         out     dx,ax
  442.         dec     dx
  443.         sub     dx,CommandPort
  444.         call    waitgus
  445.         add     dx,CommandPort
  446.         jmp     NoChangeSamp
  447.  
  448. SampChange1:
  449.         mov     al,WriteVoiceMode
  450.         out     dx,al
  451.         add     dx,2
  452.         mov     al,3
  453.         out     dx,al
  454.         sub     dx,DataHighPort
  455.         call    waitgus
  456.         add     dx,CommandPort
  457.  
  458.         mov     al,SampleStartLo
  459.         out     dx,al
  460.         inc     dx
  461.         mov     ax,Word Ptr [di.SampOff]
  462.         mov     bp,Word Ptr [di.SampOff+2]
  463.         add     ax,[di.OffsetAdd]
  464.         adc     bp,0
  465.         shr     ax,7
  466.         shl     bp,9
  467.         or      ax,bp
  468.         out     dx,ax
  469.         dec     dx
  470.         mov     al,SampleStartHi
  471.         out     dx,al
  472.         inc     dx
  473.         mov     ax,Word Ptr [di.SampOff]
  474.         add     ax,[di.OffsetAdd]
  475.         shl     ax,9
  476.         out     dx,ax
  477.         sub     dx,DataLowPort
  478.         call    waitgus
  479.         add     dx,CommandPort
  480.  
  481.         mov     ax,[di.OldSamp]
  482.         cmp     ax,[di.CurrSamp]
  483.         je      NoChangeSamp
  484.  
  485.         mov     al,SampleEndLo
  486.         out     dx,al
  487.         inc     dx
  488.         mov     ax,Word Ptr [di.SampOff]
  489.         mov     bp,Word Ptr [di.SampOff+2]
  490.         add     ax,[di.Len]
  491.         adc     bp,0
  492.         shr     ax,7
  493.         shl     bp,9
  494.         or      ax,bp
  495.         out     dx,ax
  496.         dec     dx
  497.         mov     al,SampleEndHi
  498.         out     dx,al
  499.         inc     dx
  500.         mov     ax,Word Ptr [di.SampOff]
  501.         add     ax,[di.Len]
  502.         shl     ax,9
  503.         out     dx,ax
  504.         dec     dx
  505.  
  506.         mov     al,LoopStartLo
  507.         out     dx,al
  508.         inc     dx
  509.         mov     ax,Word Ptr [di.SampOff]
  510.         mov     bp,Word Ptr [di.SampOff+2]
  511.         add     ax,[di.Repeat]
  512.         adc     bp,0
  513.         shr     ax,7
  514.         shl     bp,9
  515.         or      ax,bp
  516.         out     dx,ax
  517.         dec     dx
  518.         mov     al,LoopStartHi
  519.         out     dx,al
  520.         inc     dx
  521.         mov     ax,Word Ptr [di.SampOff]
  522.         add     ax,[di.Repeat]
  523.         shl     ax,9
  524.         out     dx,ax
  525.         dec     dx
  526.  
  527.         mov     al,WriteVoiceMode
  528.         out     dx,al
  529.         add     dx,2
  530.         mov     al,3
  531.         out     dx,al
  532.         sub     dx,2
  533.         jmp     NoChangeSamp
  534.  
  535. SampChange2:
  536.         mov     ax,[di.OldSamp]
  537.         cmp     ax,[di.CurrSamp]
  538.         je      NoChangeSamp
  539.  
  540.         mov     al,VoicePosLo
  541.         out     dx,al
  542.         inc     dx
  543.         in      ax,dx
  544.         mov     bx,ax
  545.         dec     dx
  546.         mov     al,VoicePosHi
  547.         out     dx,al
  548.         inc     dx
  549.         in      ax,dx
  550.         dec     dx
  551.         xchg    ax,bx
  552.         shl     ax,7
  553.         shr     bx,9
  554.         and     bx,7Fh
  555.         or      ax,bx
  556.         mov     bx,[di.OldSamp]
  557.         dec     bx
  558.         shl     bx,2
  559.         sub     ax,Word Ptr [SampOffset+bx]
  560.         mov     bx,ax
  561.         cmp     bx,[di.Len]
  562.         jb      NoFixStart
  563.         mov     bx,[di.Len]
  564.         dec     bx
  565. NoFixStart:
  566.  
  567.         cmp     [di.OffsetAdd],0
  568.         jne     NoOffsetEff
  569.         mov     [di.OffsetAdd],bx
  570. NoOffsetEff:
  571.  
  572.         mov     al,SampleStartLo
  573.         out     dx,al
  574.         inc     dx
  575.         mov     ax,Word Ptr [di.SampOff]
  576.         mov     bp,Word Ptr [di.SampOff+2]
  577.         add     ax,[di.OffsetAdd]
  578.         adc     bp,0
  579.         shr     ax,7
  580.         shl     bp,9
  581.         or      ax,bp
  582.         out     dx,ax
  583.         dec     dx
  584.         mov     al,SampleStartHi
  585.         out     dx,al
  586.         inc     dx
  587.         mov     ax,Word Ptr [di.SampOff]
  588.         add     ax,[di.OffsetAdd]
  589.         shl     ax,9
  590.         out     dx,ax
  591.         sub     dx,DataLowPort
  592.         call    waitgus
  593.         add     dx,CommandPort
  594.  
  595.         mov     al,SampleEndLo
  596.         out     dx,al
  597.         inc     dx
  598.         mov     ax,Word Ptr [di.SampOff]
  599.         mov     bp,Word Ptr [di.SampOff+2]
  600.         add     ax,[di.Len]
  601.         adc     bp,0
  602.         shr     ax,7
  603.         shl     bp,9
  604.         or      ax,bp
  605.         out     dx,ax
  606.         dec     dx
  607.         mov     al,SampleEndHi
  608.         out     dx,al
  609.         inc     dx
  610.         mov     ax,Word Ptr [di.SampOff]
  611.         add     ax,[di.Len]
  612.         shl     ax,9
  613.         out     dx,ax
  614.         dec     dx
  615.  
  616.         mov     al,LoopStartLo
  617.         out     dx,al
  618.         inc     dx
  619.         mov     ax,Word Ptr [di.SampOff]
  620.         mov     bp,Word Ptr [di.SampOff+2]
  621.         add     ax,[di.Repeat]
  622.         adc     bp,0
  623.         shr     ax,7
  624.         shl     bp,9
  625.         or      ax,bp
  626.         out     dx,ax
  627.         dec     dx
  628.         mov     al,LoopStartHi
  629.         out     dx,al
  630.         inc     dx
  631.         mov     ax,Word Ptr [di.SampOff]
  632.         add     ax,[di.Repeat]
  633.         shl     ax,9
  634.         out     dx,ax
  635.         dec     dx
  636.  
  637.         mov     al,WriteVoiceMode
  638.         out     dx,al
  639.         add     dx,2
  640.         mov     al,Byte Ptr [di.LoopOnOff]
  641.         out     dx,al
  642.         sub     dx,DataHighPort
  643.         call    waitgus
  644.         add     dx,CommandPort
  645. NoChangeSamp:
  646.  
  647.         mov     ax,[di.Vol]
  648.         cmp     ax,[di.OldVol]
  649.         je      NoSetBar
  650.         mov     [di.Bar],ax
  651. NoSetBar:
  652.  
  653.         mov     [TempVol],ax
  654.         mov     ax,[Counter]
  655.         test    [ChanOn],ax
  656.         jnz     NoChanOff
  657.         mov     [TempVol],0
  658.         mov     [di.Bar],0
  659. NoChanOff:
  660.  
  661.         mov     ax,[di.OldVol]
  662.         mul     word [MainVolume]
  663.         shr     ax,6
  664.         adc     ax,0
  665.         mov     bx,ax
  666.         shl     bx,1
  667.         mov     bx,[GusVol+bx]
  668.         mov     ax,[TempVol]
  669.         mul     word [MainVolume]
  670.         shr     ax,6
  671.         adc     ax,0
  672.         mov     bp,ax
  673.         shl     bp,1
  674.         mov     bp,[GusVol+bp]
  675.  
  676.         mov     dx,bp
  677.         mov     dl,bh
  678.         cmp     dl,dh
  679.         jne     SetVol
  680.  
  681.         mov     dx,[BasePort]
  682.         add     dx,CommandPort
  683.  
  684.         mov     al,VolumeCtrl
  685.         out     dx,al
  686.         add     dx,2
  687.         mov     al,3
  688.         out     dx,al
  689.         sub     dx,2
  690.  
  691.         mov     al,SetVolume
  692.         out     dx,al
  693.         mov     ax,bp
  694.         inc     dx
  695.         out     dx,ax
  696.         dec     dx
  697.         jmp     NoSetVol
  698.  
  699. SetVol:
  700.         mov     dx,[BasePort]
  701.         add     dx,CommandPort
  702.  
  703.         mov     al,VolumeCtrl
  704.         out     dx,al
  705.         add     dx,2
  706.         mov     al,3
  707.         out     dx,al
  708.         sub     dx,2
  709.  
  710.         mov     ah,0
  711.         cmp     bx,bp
  712.         jb      NoFixVolDir
  713.         mov     ah,01000000b
  714.         xchg    bx,bp
  715. NoFixVolDir:
  716.  
  717.         mov     dx,[BasePort]
  718.         add     dx,CommandPort
  719.         mov     al,VolRampStart
  720.         out     dx,al
  721.         xchg    ax,bx
  722.         inc     dx
  723.         out     dx,ax
  724.         dec     dx
  725.  
  726.         mov     al,VolRampEnd
  727.         out     dx,al
  728.         mov     ax,bp
  729.         inc     dx
  730.         out     dx,ax
  731.         dec     dx
  732.  
  733.         mov     al,VolumeCtrl
  734.         out     dx,al
  735.         mov     al,bh
  736.         add     dx,2
  737.         out     dx,al
  738.         sub     dx,2
  739. NoSetVol:
  740.  
  741.         mov     al,SetVoiceFreq
  742.         out     dx,al
  743.         inc     dx
  744.         mov     ax,[di.FreqVal]
  745.         out     dx,ax
  746.         dec     dx
  747.  
  748.         shl     [Counter],1
  749.         add     di,ChanSize
  750.         dec     cx
  751.         jnz     ChangeSamps
  752.  
  753.         mov     di,offset [SampChans]
  754.         mov     cx,[NumChans]
  755.  
  756. StartVoices:
  757.         dec     dx
  758.         mov     al,Byte Ptr [NumChans]
  759.         sub     al,cl
  760.         out     dx,al
  761.         inc     dx
  762.  
  763.         cmp     [di.InstSet],2
  764.         jne     NoVoiceStart
  765.  
  766.         mov     al,WriteVoiceMode
  767.         out     dx,al
  768.         add     dx,2
  769.         mov     al,Byte Ptr [di.LoopOnOff]
  770.         out     dx,al
  771.         sub     dx,DataHighPort
  772.         call    waitgus
  773.         add     dx,CommandPort
  774. NoVoiceStart:
  775.  
  776.         mov     [di.InstSet],0
  777.         mov     [di.OffsetAdd],0
  778.  
  779.         add     di,ChanSize
  780.         dec     cx
  781.         jnz     StartVoices
  782.         jmp     EndPattern
  783.  
  784. JumpPattern:
  785.  
  786.         mov     [Counter],0
  787.  
  788.         dec     Word Ptr [PatternCount]
  789.         jnz     DoEffects
  790.         jmp     DoPattern
  791. DoEffects:
  792.  
  793.         mov     di,offset [SampChans]
  794.         mov     cx,[NumChans]
  795.  
  796. EffectLoop:
  797.  
  798.         mov     ax,[di.Vol]
  799.         mov     [di.OldVol],ax
  800.  
  801.         inc     [di.EffectTime]
  802.         add     [di.ArpCounter],2
  803.         cmp     [di.ArpCounter],6
  804.         jb      NoWrapArp
  805.         mov     [di.ArpCounter],0
  806. NoWrapArp:
  807.         mov     ax,[di.Effect]
  808.         cmp     ax,0
  809.         jne     DoEffect
  810.         jmp     NoEffect
  811. DoEffect:
  812.         mov     bl,al
  813.         mov     bh,0
  814.         cmp     bl,0Eh
  815.         je      DoEEffects
  816.         shl     bx,1
  817.         jmp     [EffectJumps+bx]
  818. DoEEffects:
  819.         mov     bl,ah
  820.         and     ah,0Fh
  821.         shr     bl,4
  822.         shl     bx,1
  823.         jmp     [EEffectJumps+bx]
  824. Arpeggio:
  825.         mov     bx,[di.ArpCounter]
  826.         mov     bx,[di.Arp+bx]
  827.         shl     bx,1
  828.         mov     ax,Word Ptr [FreqTable+bx]
  829.         mov     [di.FreqVal],ax
  830.         jmp     NoEffect
  831. PortUp:
  832.         xchg    ah,al
  833.         mov     ah,0
  834.         mov     bp,[di.Fine]
  835.         mov     bp,[AmigaVals+35*2+bp]
  836.         mov     bx,[di.Amiga]
  837.         sub     bx,ax
  838.         jnc     NoFix1
  839.         mov     bx,bp
  840. NoFix1:
  841.         cmp     bx,bp
  842.         jae     NotSmall1
  843.         mov     bx,bp
  844. NotSmall1:
  845.         mov     [di.Amiga],bx
  846.         shl     bx,1
  847.         mov     ax,[FreqTable+bx]
  848.         mov     [di.FreqVal],ax
  849.         jmp     NoEffect
  850. PortDown:
  851.         xchg    ah,al
  852.         mov     ah,0
  853.         mov     bp,[di.Fine]
  854.         mov     bp,[AmigaVals+bp]
  855.         mov     bx,[di.Amiga]
  856.         add     bx,ax
  857.         cmp     bx,bp
  858.         jbe     NotBig1
  859.         mov     bx,bp
  860. NotBig1:
  861.         mov     [di.Amiga],bx
  862.         shl     bx,1
  863.         mov     ax,[FreqTable+bx]
  864.         mov     [di.FreqVal],ax
  865.         jmp     NoEffect
  866. PortToTone:
  867.         xchg    ah,al
  868.         xor     ah,ah
  869.         mov     dx,[di.PortTo]
  870.         mov     bx,[di.Amiga]
  871.         cmp     bx,dx
  872.         jae     NoPortToUp
  873.         add     bx,ax
  874.         cmp     bx,dx
  875.         jna     NoPortToUp
  876.         mov     [di.Amiga],dx
  877. NoPortToUp:
  878.         cmp     bx,dx
  879.         jbe     NoPortToDown
  880.         sub     bx,ax
  881.         jnc     NoPortToError
  882.         mov     bx,dx
  883. NoPortToError:
  884.         cmp     bx,dx
  885.         jnb     NoPortToDown
  886.         mov     bx,dx
  887. NoPortToDown:
  888.         mov     [di.Amiga],bx
  889.         shl     bx,1
  890.         mov     ax,[FreqTable+bx]
  891.         mov     [di.FreqVal],ax
  892.         jmp     NoEffect
  893. Vibrato:
  894.         mov     bp,[di.Fine]
  895.         mov     si,[AmigaVals+bp]
  896.         mov     bp,[AmigaVals+35*2+bp]
  897.         mov     dl,ah
  898.         and     ah,0F0h
  899.         shr     ah,2
  900.         and     dl,0Fh
  901.         mov     bl,Byte Ptr [di.VibratoPek]
  902.         add     bl,ah
  903.         mov     Byte Ptr [di.VibratoPek],bl
  904.         shr     bl,2
  905.         and     bx,1Fh
  906.         mov     al,[SinTab+bx]
  907.         mul     dl
  908.         rol     ax,1
  909.         xchg    ah,al
  910.         and     ah,1
  911.         test    Byte Ptr [di.VibratoPek],128
  912.         jne     VibUp1
  913.         neg     ax
  914. VibUp1:
  915.         add     ax,[di.Amiga]
  916.         cmp     ax,bp
  917.         jae     NoHighVibrato1
  918.         mov     ax,bp
  919. NoHighVibrato1:
  920.         cmp     ax,si
  921.         jbe     NoLowVibrato1
  922.         mov     ax,si
  923. NoLowVibrato1:
  924.         shl     ax,1
  925.         mov     bx,ax
  926.         mov     ax,[FreqTable+bx]
  927.         mov     [di.FreqVal],ax
  928.         jmp     NoEffect
  929. PortToVSlide:
  930.         mov     al,ah
  931.         and     ah,0Fh
  932.         shr     al,4
  933.         sub     ah,al
  934.         mov     al,Byte Ptr [di.Vol]
  935.         sub     al,ah
  936.         jns     NoSlideLow2
  937.         mov     al,0
  938. NoSlideLow2:
  939.         cmp     al,40h
  940.         jb      NoSlideHigh2
  941.         mov     al,3Fh
  942. NoSlideHigh2:
  943.         mov     Byte Ptr [di.Vol],al
  944.         mov     ax,[di.OldPortTo]
  945.         mov     dx,[di.PortTo]
  946.         mov     bx,[di.Amiga]
  947.         cmp     bx,dx
  948.         jae     NoPortToUp2
  949.         add     bx,ax
  950.         cmp     bx,dx
  951.         jna     NoPortToUp2
  952.         mov     [di.Amiga],dx
  953. NoPortToUp2:
  954.         cmp     bx,dx
  955.         jbe     NoPortToDown2
  956.         sub     bx,ax
  957.         jnc     NoPortToError2
  958.         mov     bx,0
  959. NoPortToError2:
  960.         cmp     bx,dx
  961.         jnb     NoPortToDown2
  962.         mov     bx,dx
  963. NoPortToDown2:
  964.         mov     [di.Amiga],bx
  965.         shl     bx,1
  966.         mov     ax,Word Ptr [FreqTable+bx]
  967.         mov     [di.FreqVal],ax
  968.         jmp     NoEffect
  969. VibratoVSlide:
  970.         mov     al,ah
  971.         and     ah,0Fh
  972.         shr     al,4
  973.         sub     ah,al
  974.         mov     al,Byte Ptr [di.Vol]
  975.         sub     al,ah
  976.         jns     NoSlideLow3
  977.         mov     al,0
  978. NoSlideLow3:
  979.         cmp     al,40h
  980.         jb      NoSlideHigh3
  981.         mov     al,3Fh
  982. NoSlideHigh3:
  983.         mov     Byte Ptr [di.Vol],al
  984.         mov     bp,[di.Fine]
  985.         mov     si,[AmigaVals+bp]
  986.         mov     bp,[AmigaVals+35*2+bp]
  987.         mov     ah,Byte Ptr [di.OldVibrato]
  988.         or      ah,Byte Ptr [di.OldVibrato+1]
  989.         mov     dl,ah
  990.         and     ah,0F0h
  991.         shr     ah,2
  992.         and     dl,0Fh
  993.         mov     bl,Byte Ptr [di.VibratoPek]
  994.         add     bl,ah
  995.         mov     Byte Ptr [di.VibratoPek],bl
  996.         shr     bl,2
  997.         and     bx,1Fh
  998.         mov     al,[SinTab+bx]
  999.         mul     dl
  1000.         rol     ax,1
  1001.         xchg    ah,al
  1002.         and     ah,1
  1003.         test    Byte Ptr [di.VibratoPek],128
  1004.         jne     VibUp2
  1005.         neg     ax
  1006. VibUp2:
  1007.         add     ax,[di.Amiga]
  1008.         cmp     ax,bp
  1009.         jae     NoHighVibrato2
  1010.         mov     ax,bp
  1011. NoHighVibrato2:
  1012.         cmp     ax,si
  1013.         jbe     NoLowVibrato2
  1014.         mov     ax,si
  1015. NoLowVibrato2:
  1016.         shl     ax,1
  1017.         mov     bx,ax
  1018.         mov     ax,[FreqTable+bx]
  1019.         mov     [di.FreqVal],ax
  1020.         jmp     NoEffect
  1021. VolSlide:
  1022.         mov     al,ah
  1023.         and     ah,0Fh
  1024.         shr     al,4
  1025.         cmp     al,0
  1026.         je      NoVolSlideUp
  1027.         neg     al
  1028.         mov     ah,al
  1029. NoVolSlideUp:
  1030.         mov     al,Byte Ptr [di.Vol]
  1031.         sub     al,ah
  1032.         jns     NoSlideLow1
  1033.         mov     al,0
  1034. NoSlideLow1:
  1035.         cmp     al,40h
  1036.         jb      NoSlideHigh1
  1037.         mov     al,3Fh
  1038. NoSlideHigh1:
  1039.         mov     Byte Ptr [di.Vol],al
  1040.         jmp     NoEffect
  1041. RetrigNote:
  1042.         cmp     ah,Byte Ptr [di.EffectTime]
  1043.         jne     NoRetrig
  1044.         mov     [di.EffectTime],0
  1045.         mov     [di.InstSet],2
  1046. NoRetrig:
  1047.         jmp     NoEffect
  1048. CutNote:
  1049.         cmp     ah,Byte Ptr [di.EffectTime]
  1050.         jne     NoCutNote
  1051.         mov     [di.Amiga],0
  1052.         mov     [di.FreqVal],0
  1053. NoCutNote:
  1054.         jmp     NoEffect
  1055. DelayNote:
  1056.         cmp     ah,Byte Ptr [di.EffectTime]
  1057.         jne     NoDelayNote
  1058.         mov     [di.InstSet],2
  1059.         mov     [di.VibratoPek],0
  1060.         mov     bx,[di.PortTo]
  1061.         mov     [di.Amiga],bx
  1062.         shl     bx,1
  1063.         mov     bx,[FreqTable+bx]
  1064.         mov     [di.FreqVal],bx
  1065. NoDelayNote:
  1066.         jmp     NoEffect
  1067. NoEffect:
  1068.  
  1069.         add     di,ChanSize
  1070.         dec     cx
  1071.         jz      EndEffects
  1072.         jmp     EffectLoop
  1073. EndEffects:
  1074.         jmp     EndPattern
  1075.  
  1076. DoPattern:
  1077.         mov     ax,[PatternSpeed]
  1078.         mov     [PatternCount],ax
  1079.         cmp     [PatternRow],64
  1080.         jb      NoPatternWrap
  1081.         mov     ax,[PlayingPattern]
  1082.         cmp     al,[OrderLen]
  1083.         jb      NoTrackWrap
  1084.         mov     ax,0
  1085.         cmp     [Restart],78h
  1086.         jae     NoRestart
  1087.         mov     al,[Restart]
  1088. NoRestart:
  1089.         mov     [PlayingPattern],ax
  1090. NoTrackWrap:
  1091.         mov     bx,[PlayingPattern]
  1092.         mov     [RealPPattern],bx
  1093.         inc     [RealPPattern]
  1094.         mov     ah,0
  1095.         mov     al,[PatternOrder+bx]
  1096.         mov     dx,[NumChans]
  1097.         shl     dx,8
  1098.         mul     dx
  1099.         shl     dx,12
  1100.         add     dx,[PatternMem]
  1101.         mov     [SegPattern],dx
  1102.         mov     [BytePattern],ax
  1103.         mov     ax,[BreakData]
  1104.         mov     [PatternRow],ax
  1105.         shl     ax,4
  1106.         add     [BytePattern],ax
  1107.         mov     [BreakData],0
  1108.         inc     [PlayingPattern]
  1109. NoPatternWrap:
  1110.  
  1111.         les     si,[PatternPek]
  1112.         mov     di,offset [SampChans]
  1113.         mov     cx,[NumChans]
  1114.         mov     ax,[PatternRow]
  1115.         mov     [RealRow],ax
  1116.  
  1117. PattLoop:
  1118.  
  1119.         mov     ax,[di.Vol]
  1120.         mov     [di.OldVol],ax
  1121.  
  1122.         mov     bh,es:[si]              ; New Sample
  1123.         mov     bl,es:[si+2]
  1124.         and     bh,0F0h
  1125.         shr     bl,4
  1126.         add     bl,bh
  1127.         je      NoNewSample
  1128.         mov     bh,Byte Ptr [di.CurrSamp]
  1129.         mov     Byte Ptr [di.OldSamp],bh
  1130.         mov     Byte Ptr [di.CurrSamp],bl
  1131.         mov     bh,0
  1132.         dec     bx
  1133.         shl     bx,1
  1134.         mov     ax,[SampVol+bx]
  1135.         cmp     ax,40h
  1136.         jb      NoHighVol
  1137.         mov     ax,3Fh
  1138. NoHighVol:
  1139.         mov     [di.Vol],ax
  1140.         mov     [di.InstSet],1
  1141.         shl     bx,1
  1142.         mov     ax,Word Ptr [SampOffset+bx]
  1143.         mov     Word Ptr [di.SampOff],ax
  1144.         mov     ax,Word Ptr [SampOffset+bx+2]
  1145.         mov     Word Ptr [di.SampOff+2],ax
  1146.         shr     bx,1
  1147.         mov     ax,[SampFine+bx]
  1148.         shl     ax,3
  1149.         mov     [di.Fine],ax
  1150.         shl     ax,3
  1151.         add     [di.Fine],ax
  1152.         mov     [di.LoopOnOff],0
  1153.         mov     ax,[SampLen+bx]
  1154.         mov     [di.Len],ax
  1155.         mov     ax,[SampRep+bx]
  1156.         mov     [di.Repeat],ax
  1157.         mov     ax,[SampRepLen+bx]
  1158.         mov     [di.RepLen],ax
  1159.         cmp     ax,2
  1160.         jbe     NoNewSample
  1161.         mov     [di.LoopOnOff],8
  1162.         mov     ax,[di.Repeat]
  1163.         add     ax,[di.RepLen]
  1164.         cmp     ax,[di.Len]
  1165.         ja      NoNewSample
  1166.         mov     [di.Len],ax
  1167. NoNewSample:
  1168.  
  1169.         mov     bx,es:[si]
  1170.         xchg    bh,bl
  1171.         and     bx,0FFFh
  1172.         je      NoNewNote
  1173.  
  1174.         mov     bl,[ArpTable+bx]
  1175.         mov     bh,0
  1176.         add     bx,[di.Fine]
  1177.         mov     bx,[AmigaVals+bx]
  1178.         mov     [di.PortTo],bx
  1179.         mov     ax,es:[si+2]
  1180.         and     al,0Fh
  1181.         and     ah,0F0h
  1182.         cmp     al,03h
  1183.         je      PortToP
  1184.         cmp     al,05h
  1185.         je      PortToP
  1186.         jmp     NoPortToP
  1187. PortToP:
  1188.         push    cx
  1189.         neg     cx
  1190.         add     cx,[NumChans]
  1191.         mov     ax,1
  1192.         shl     ax,cl
  1193.         test    ax,[ChanOn]
  1194.         je      NoSetPortBar
  1195.         mov     ax,[di.Vol]
  1196.         mov     [di.Bar],ax
  1197. NoSetPortBar:
  1198.         pop     cx
  1199.         jmp     NoNewNote
  1200. NoPortToP:
  1201.         cmp     ax,0D00Eh
  1202.         jne     NewNote
  1203.         mov     al,es:[si+2]
  1204.         cmp     al,0
  1205.         je      NewNote
  1206.         mov     [di.InstSet],0
  1207.         jmp     NoNewNote
  1208. NewNote:
  1209.         mov     [di.InstSet],2
  1210.         mov     [di.VibratoPek],0
  1211.         mov     [di.Amiga],bx
  1212.         shl     bx,1
  1213.         mov     bx,[FreqTable+bx]
  1214.         mov     [di.FreqVal],bx
  1215. NoNewNote:
  1216.  
  1217.         mov     [di.ArpCounter],0
  1218.         mov     ax,es:[si+2]
  1219.         and     al,0Fh
  1220.         mov     [di.Effect],ax
  1221.         cmp     al,7
  1222.         jb      NoSetOldFreq
  1223.         mov     bx,ax
  1224.         and     bh,0F0h
  1225.         cmp     bx,0C00Eh
  1226.         je      NoSetOldFreq
  1227.         cmp     bx,0D00Eh
  1228.         je      NoSetOldFreq
  1229.         mov     bx,[di.Amiga]
  1230.         shl     bx,1
  1231.         mov     bx,[FreqTable+bx]
  1232.         mov     [di.FreqVal],bx
  1233. NoSetOldFreq:
  1234.         mov     bh,0
  1235.         mov     bl,al
  1236.         cmp     bl,0Eh
  1237.         je      DoEPattEffects
  1238.         shl     bx,1
  1239.         jmp     [PattJumps+bx]
  1240. DoEPattEffects:
  1241.         mov     bl,ah
  1242.         and     ah,0Fh
  1243.         shr     bl,4
  1244.         shl     bx,1
  1245.         jmp     [EPattJumps+bx]
  1246. ArpeggioFix:
  1247.         mov     bx,[di.Amiga]
  1248.         mov     bl,[ArpTable+bx]
  1249.         mov     bh,0
  1250.         mov     bp,bx
  1251.         add     bx,[di.Fine]
  1252.         mov     dx,[AmigaVals+bx]
  1253.         mov     [di.Arp],dx
  1254.         xchg    ah,al
  1255.         mov     ah,0
  1256.         mov     dx,ax
  1257.         shr     dx,4
  1258.         and     ax,0Fh
  1259.         shl     dx,1
  1260.         shl     ax,1
  1261.         mov     bx,bp
  1262.         add     bx,dx
  1263.         cmp     bx,70
  1264.         jbe     NoWrapArp1
  1265.         mov     bx,70
  1266. NoWrapArp1:
  1267.         add     bx,[di.Fine]
  1268.         mov     dx,[AmigaVals+bx]
  1269.         mov     [di.Arp+2],dx
  1270.         mov     bx,bp
  1271.         add     bx,ax
  1272.         cmp     bx,70
  1273.         jbe     NoWrapArp2
  1274.         mov     bx,70
  1275. NoWrapArp2:
  1276.         add     bx,[di.Fine]
  1277.         mov     dx,[AmigaVals+bx]
  1278.         mov     [di.Arp+4],dx
  1279.         jmp     NoPattEffect
  1280. PortToFix:
  1281.         cmp     ah,0
  1282.         jne     NoPortPekFix
  1283.         mov     ah,Byte Ptr [di.OldPortTo]
  1284. NoPortPekFix:
  1285.         mov     Byte Ptr [di.OldPortTo],ah
  1286.         mov     Byte Ptr [di.Effect+1],ah
  1287.         jmp     NoPattEffect
  1288. VibratoFix:
  1289.         mov     al,ah
  1290.         and     al,0Fh
  1291.         and     ah,0F0h
  1292.         cmp     al,0
  1293.         jne     NoVibratoFix1
  1294.         mov     al,Byte Ptr [di.OldVibrato]
  1295. NoVibratoFix1:
  1296.         cmp     ah,0
  1297.         jne     NoVibratoFix2
  1298.         mov     ah,Byte Ptr [di.OldVibrato+1]
  1299. NoVibratoFix2:
  1300.         mov     Byte Ptr [di.OldVibrato],al
  1301.         mov     Byte Ptr [di.OldVibrato+1],ah
  1302.         or      al,ah
  1303.         mov     Byte Ptr [di.Effect+1],al
  1304.         jmp     NoPattEffect
  1305. SampleOff:
  1306.         mov     al,0
  1307.         cmp     ax,[di.Len]
  1308.         jb      NoFixOffset
  1309.         mov     ax,[di.Len]
  1310.         dec     ax
  1311. NoFixOffset:
  1312.         mov     [di.OffsetAdd],ax
  1313.         jmp     NoPattEffect
  1314. PosJump:
  1315.         mov     [PatternRow],63
  1316.         mov     Byte Ptr [PlayingPattern],ah
  1317.         jmp     NoPattEffect
  1318. Volume:
  1319.         cmp     ah,40h
  1320.         jb      NoFixVol1
  1321.         mov     ah,3Fh
  1322. NoFixVol1:
  1323.         mov     Byte Ptr [di.Vol],ah
  1324.         jmp     NoPattEffect
  1325. BreakPatt:
  1326.         mov     [PatternRow],63
  1327.         cmp     ah,64h
  1328.         jb      NoFixBreak
  1329.         mov     ah,63h
  1330. NoFixBreak:
  1331.         mov     al,ah
  1332.         and     al,0Fh
  1333.         shr     ah,4
  1334.         shl     ah,1
  1335.         mov     Byte Ptr [BreakData],al
  1336.         add     Byte Ptr [BreakData],ah
  1337.         shl     ah,2
  1338.         add     Byte Ptr [BreakData],ah
  1339.         jmp     NoPattEffect
  1340. SpeedSet:
  1341.         cmp     ah,0
  1342.         je      NoPattEffect
  1343.         cmp     ah,1Fh
  1344.         jbe     UsualSpeed
  1345.  
  1346.         xchg    ah,al
  1347.         mov     ah,0
  1348.         shl     ax,1                    ;
  1349.         mov     bl,5                    ; Denna bit är för att ställa
  1350.         div     bl                      ; Effects till annat än 50Hz
  1351.         mov     dl,al                   ; Detta ger automatiskt en annan
  1352.         mov     dh,0                    ; patternspeed.; Hz=2*BPM/5
  1353.         mov     ax,0
  1354.         mov     bx, player_intrate
  1355.         div     bx
  1356.         mov     Word Ptr cs:[Speed],ax
  1357.         mov     ax,0
  1358.         div     bx
  1359.         mov     Word Ptr cs:[Speed+2],ax
  1360.         jmp     NoPattEffect
  1361. UsualSpeed:
  1362.         mov     Byte Ptr [PatternSpeed],ah
  1363.         mov     Byte Ptr [PatternCount],ah
  1364.         jmp     NoPattEffect
  1365. FinePortUp:
  1366.         xchg    ah,al
  1367.         mov     ah,0
  1368.         sub     [di.Amiga],ax
  1369.         mov     bx,[di.Fine]
  1370.         mov     bx,[AmigaVals+35*2+bx]
  1371.         cmp     [di.Amiga],bx
  1372.         jae     NoFixFineUp
  1373.         mov     [di.Amiga],bx
  1374. NoFixFineUp:
  1375.         jmp     NoPattEffect
  1376. FinePortDown:
  1377.         xchg    ah,al
  1378.         mov     ah,0
  1379.         add     [di.Amiga],ax
  1380.         mov     bx,[di.Fine]
  1381.         mov     bx,[AmigaVals+bx]
  1382.         cmp     [di.Amiga],bx
  1383.         jbe     NoFixFineDown
  1384.         mov     [di.Amiga],bx
  1385. NoFixFineDown:
  1386.         jmp     NoPattEffect
  1387. FineVolUp:
  1388.         add     Byte Ptr [di.Vol],ah
  1389.         cmp     Byte Ptr [di.Vol],3Fh
  1390.         jbe     NoFixFineVolUp
  1391.         mov     Byte Ptr [di.Vol],3Fh
  1392. NoFixFineVolUp:
  1393.         jmp     NoPattEffect
  1394. FineVolDown:
  1395.         sub     Byte Ptr [di.Vol],ah
  1396.         jnc     NoFixFineVolDown
  1397.         mov     Byte Ptr [di.Vol],0
  1398. NoFixFineVolDown:
  1399.         jmp     NoPattEffect
  1400. NoPattEffect:
  1401.  
  1402.         add     si,4
  1403.         jnc     NoChangeSeg1
  1404.         mov     dx,es
  1405.         add     dx,1000h
  1406.         mov     es,dx
  1407. NoChangeSeg1:
  1408.         mov     [di.EffectTime],0
  1409.         add     di,ChanSize
  1410.         dec     cx
  1411.         jz      EndChannels
  1412.         jmp     PattLoop
  1413. EndChannels:
  1414.         inc     [PatternRow]
  1415.         mov     ax,[NumChans]
  1416.         shl     ax,2
  1417.         add     [BytePattern],ax
  1418.         jnc     EndPattern
  1419.         add     [SegPattern],1000h
  1420. EndPattern:
  1421.  
  1422.         mov     ax, [Syncro]
  1423.         cmp     ax, 0ffffh
  1424.         jz      @@forced
  1425.         mov     al, [byte ptr RealRow]
  1426.         mov     ah, [byte ptr RealPPattern]
  1427.         mov     [Syncro], ax
  1428. @@forced:
  1429.  
  1430.         dec     [framecounter]
  1431.         jnz     notyet
  1432.         inc     [frames]
  1433.         xor     dx, dx
  1434.         mov     ax, player_intrate
  1435.         div     [framespersec]
  1436.         mov     [framecounter], ax
  1437. notyet:
  1438.  
  1439.         dec     [JumpOldTimer]
  1440.         jnz     NoJumpOld
  1441.         mov     [JumpOldTimer],55
  1442.  
  1443.  
  1444.         pop     es
  1445.         pop     ds
  1446.         popa
  1447.         jmp     DWord Ptr cs:[OldTimer]
  1448. NoJumpOld:
  1449.         pop     es
  1450.         pop     ds
  1451.         popa
  1452.         iret
  1453.  
  1454. Pattern         EndP
  1455.  
  1456. PattJumps       dw offset cs:[ArpeggioFix]      ; 0
  1457.                 dw offset cs:[NoPattEffect]     ; 1
  1458.                 dw offset cs:[NoPattEffect]     ; 2
  1459.                 dw offset cs:[PortToFix]        ; 3
  1460.                 dw offset cs:[VibratoFix]       ; 4
  1461.                 dw offset cs:[NoPattEffect]     ; 5
  1462.                 dw offset cs:[NoPattEffect]     ; 6
  1463.                 dw offset cs:[NoPattEffect]     ; 7
  1464.                 dw offset cs:[NoPattEffect]     ; 8
  1465.                 dw offset cs:[SampleOff]        ; 9
  1466.                 dw offset cs:[NoPattEffect]     ; A
  1467.                 dw offset cs:[PosJump]          ; B
  1468.                 dw offset cs:[Volume]           ; C
  1469.                 dw offset cs:[BreakPatt]        ; D
  1470.                 dw offset cs:[NoPattEffect]     ; E
  1471.                 dw offset cs:[SpeedSet]         ; F
  1472.  
  1473. EPattJumps      dw offset cs:[NoPattEffect]     ; 0
  1474.                 dw offset cs:[FinePortUp]       ; 1
  1475.                 dw offset cs:[FinePortDown]     ; 2
  1476.                 dw offset cs:[NoPattEffect]     ; 3
  1477.                 dw offset cs:[NoPattEffect]     ; 4
  1478.                 dw offset cs:[NoPattEffect]     ; 5
  1479.                 dw offset cs:[NoPattEffect]     ; 6
  1480.                 dw offset cs:[NoPattEffect]     ; 7
  1481.                 dw offset cs:[NoPattEffect]     ; 8
  1482.                 dw offset cs:[NoPattEffect]     ; 9
  1483.                 dw offset cs:[FineVolUp]        ; A
  1484.                 dw offset cs:[FineVolDown]      ; B
  1485.                 dw offset cs:[NoPattEffect]     ; C
  1486.                 dw offset cs:[NoPattEffect]     ; D
  1487.                 dw offset cs:[NoPattEffect]     ; E
  1488.                 dw offset cs:[NoPattEffect]     ; F
  1489.  
  1490. EffectJumps     dw offset cs:[Arpeggio]         ; 0
  1491.                 dw offset cs:[PortUp]           ; 1
  1492.                 dw offset cs:[PortDown]         ; 2
  1493.                 dw offset cs:[PortToTone]       ; 3
  1494.                 dw offset cs:[Vibrato]          ; 4
  1495.                 dw offset cs:[PortToVSlide]     ; 5
  1496.                 dw offset cs:[VibratoVSlide]    ; 6
  1497.                 dw offset cs:[NoEffect]         ; 7
  1498.                 dw offset cs:[NoEffect]         ; 8
  1499.                 dw offset cs:[NoEffect]         ; 9
  1500.                 dw offset cs:[VolSlide]         ; A
  1501.                 dw offset cs:[NoEffect]         ; B
  1502.                 dw offset cs:[NoEffect]         ; C
  1503.                 dw offset cs:[NoEffect]         ; D
  1504.                 dw offset cs:[NoEffect]         ; E
  1505.                 dw offset cs:[NoEffect]         ; F
  1506.  
  1507. EEffectJumps    dw offset cs:[NoEffect]         ; 0
  1508.                 dw offset cs:[NoEffect]         ; 1
  1509.                 dw offset cs:[NoEffect]         ; 2
  1510.                 dw offset cs:[NoEffect]         ; 3
  1511.                 dw offset cs:[NoEffect]         ; 4
  1512.                 dw offset cs:[NoEffect]         ; 5
  1513.                 dw offset cs:[NoEffect]         ; 6
  1514.                 dw offset cs:[NoEffect]         ; 7
  1515.                 dw offset cs:[NoEffect]         ; 8
  1516.                 dw offset cs:[RetrigNote]       ; 9
  1517.                 dw offset cs:[NoEffect]         ; A
  1518.                 dw offset cs:[NoEffect]         ; B
  1519.                 dw offset cs:[CutNote]          ; C
  1520.                 dw offset cs:[DelayNote]        ; D
  1521.                 dw offset cs:[NoEffect]         ; E
  1522.                 dw offset cs:[NoEffect]         ; F
  1523.  
  1524.         assume  ds:nothing
  1525.  
  1526. StartPlaying    Proc    Far
  1527.  
  1528.         pusha
  1529.         push    ds
  1530.         push    es
  1531.  
  1532.         cli
  1533.         mov     cs:[JumpOldTimer],55
  1534.         mov     di,offset cs:[SampChans]
  1535.         mov     cx,cs:[NumChans]
  1536. ClearVarLoop:
  1537.         mov     cs:[di.FreqVal],0
  1538.         mov     cs:[di.Vol],0
  1539.         add     di,ChanSize
  1540.         loop    ClearVarLoop
  1541.  
  1542.         mov     ax,0
  1543.         mov     es,ax
  1544.  
  1545.         mov     bx,es:[8*4]
  1546.         mov     ax,es:[8*4+2]
  1547.         mov     Word Ptr cs:[OldTimer],bx
  1548.         mov     Word Ptr cs:[OldTimer+2],ax
  1549.  
  1550.         push    cs
  1551.         pop     ds
  1552.         mov     dx,offset cs:[Pattern]
  1553.  
  1554.         mov     es:[8*4],dx
  1555.         mov     es:[8*4+2],ds
  1556.  
  1557.         mov     al, 36h
  1558.         out     43h,al
  1559. ;        mov     al, 169
  1560. ;        out     40h,al
  1561. ;        mov     al,4
  1562. ;        out     40h,al
  1563.         mov     al, player_pit_divisor and 255  ; 169
  1564.         out     40h,al
  1565.         mov     al, (player_pit_divisor/256) mod 255  ; 4
  1566.         out     40h,al
  1567.  
  1568.         mov     ax, 0
  1569.         mov     dx, 50
  1570.         mov     bx, player_intrate
  1571.         div     bx
  1572.         mov     Word Ptr cs:[Speed],ax
  1573.         mov     ax,0
  1574.         div     bx
  1575.         mov     Word Ptr cs:[Speed+2],ax
  1576.         mov     Word Ptr cs:[SpeedAdd],0
  1577.         mov     Word Ptr cs:[SpeedAdd+2],0
  1578.         mov     [Counter],20
  1579.         mov     Word Ptr [Time],0
  1580.         mov     Word Ptr [Time+2],0
  1581.  
  1582.         mov     dx,cs:[BasePort]        ; Speaker On!!!
  1583.         mov     al,00000001b
  1584.         out     dx,al
  1585.         sti
  1586.  
  1587.         pop     es
  1588.         pop     ds
  1589.         popa
  1590.         ret
  1591.  
  1592. StartPlaying    EndP
  1593.  
  1594. StopPlaying     Proc    Far
  1595.  
  1596.         pusha
  1597.         push    ds
  1598.         push    es
  1599.  
  1600.         cli
  1601.  
  1602.         mov     dx,cs:[BasePort]        ; Speaker Off!!!
  1603.         mov     al,00000011b
  1604.         out     dx,al
  1605.  
  1606.         mov     ax,0
  1607.         mov     es,ax
  1608.  
  1609.         mov     al,36h
  1610.         out     43h,al
  1611.         mov     al,0
  1612.         out     40h,al
  1613.         out     40h,al
  1614.  
  1615.         mov     dx,Word Ptr cs:[OldTimer]
  1616.         mov     ds,Word Ptr cs:[OldTimer+2]
  1617.         mov     es:[8*4],dx
  1618.         mov     es:[8*4+2],ds
  1619.         sti
  1620.  
  1621.         mov     dx,cs:[BasePort]
  1622.         add     dx,ActiveVoicePort
  1623.         mov     cx,NumVoices
  1624. VoiceClearL:
  1625.         mov     al,cl
  1626.         dec     al
  1627.         out     dx,al
  1628.         inc     dx
  1629.         mov     al,0
  1630.         out     dx,al
  1631.         add     dx,2
  1632.         mov     al,3    ; Voice Off
  1633.         out     dx,al
  1634.         sub     dx,2
  1635.         mov     al,0Dh
  1636.         out     dx,al
  1637.         add     dx,2
  1638.         mov     al,3    ; Ramp Off
  1639.         out     dx,al
  1640.         sub     dx,3
  1641.         loop    VoiceClearL
  1642.  
  1643.         pop     es
  1644.         pop     ds
  1645.         popa
  1646.         ret
  1647.  
  1648. StopPlaying     EndP
  1649.  
  1650. Init            Proc    Far
  1651.         mov     cs:[PatternRow],64
  1652.         mov     cs:[PlayingPattern],0
  1653.         mov     cs:[PatternSpeed],6
  1654.         mov     cs:[PatternCount],1
  1655.         ret
  1656. Init            EndP
  1657.  
  1658. InitDevice      Proc    Far
  1659.         pusha
  1660.         push    es
  1661.         push    ds
  1662.  
  1663.         mov     dx, cs:[BasePort]        ; Speaker On!!!
  1664.         mov     al, 0
  1665.         out     dx, al
  1666.  
  1667.         mov     cs:[PatternRow],64
  1668.         mov     cs:[PlayingPattern],0
  1669.         mov     cs:[PatternSpeed],6
  1670.         mov     cs:[PatternCount],1
  1671.  
  1672.         mov     si,108*2
  1673.         mov     bp,108
  1674.         mov     cx,908-108+1
  1675. CountLoop:
  1676.         mov     dx,36h
  1677.         mov     ax,9DE4h
  1678.         div     bp
  1679.         mov     dx,100
  1680.         mul     dx
  1681.         mov     bx,Voices14   ; Voices20
  1682.         div     bx
  1683.         shr     bx,1
  1684.         adc     bx,0
  1685.         cmp     dx,bx
  1686.         jb      NoHigherFreq
  1687.         inc     ax
  1688. NoHigherFreq:
  1689.         mov     Word Ptr cs:[FreqTable+si],ax
  1690.         inc     bp
  1691.         inc     si
  1692.         inc     si
  1693.         loop    CountLoop
  1694.  
  1695. ;       Init the UltraSound
  1696.  
  1697.         mov     bx,cs:[BasePort]
  1698.         mov     cx,bx
  1699.         add     bx,CommandPort
  1700.         add     cx,DataHighPort
  1701.         mov     dx,bx
  1702.         mov     al,Initialize
  1703.         out     dx,al
  1704.         mov     dx,cx
  1705.         mov     al,0
  1706.         out     dx,al
  1707.         mov     dx,cs:[BasePort]
  1708.         call    waitgus
  1709.         mov     dx,bx
  1710.         mov     al,Initialize
  1711.         out     dx,al
  1712.         mov     dx,cx
  1713.         mov     al, 1
  1714.         out     dx,al
  1715.         mov     dx,cs:[BasePort]
  1716.         call    waitgus
  1717.  
  1718.         mov     dx,bx
  1719.         mov     al,DMACtrl
  1720.         out     dx,al
  1721.         mov     dx,cx
  1722.         mov     al,0
  1723.         out     dx,al
  1724.         mov     dx,bx
  1725.         mov     al,45h
  1726.         out     dx,al
  1727.         mov     dx,cx
  1728.         mov     al,0
  1729.         out     dx,al
  1730.         mov     dx,bx
  1731.         mov     al,49h
  1732.         out     dx,al
  1733.         mov     dx,cx
  1734.         mov     al,0
  1735.         out     dx,al
  1736.  
  1737.         mov     dx,bx
  1738.         mov     al,VoicesActive
  1739.         out     dx,al
  1740.         mov     dx,cx
  1741.         mov     al,NumVoices
  1742.         dec     al
  1743.         or      al,0C0h
  1744.         out     dx,al
  1745.  
  1746.         mov     dx,cs:[BasePort]
  1747.         add     dx,StatusPort
  1748.         in      al,dx
  1749.         mov     dx,bx
  1750.         mov     al,DMACtrl
  1751.         out     dx,al
  1752.         mov     dx,cx
  1753.         in      al,dx
  1754.         mov     dx,bx
  1755.         mov     al,49h
  1756.         out     dx,al
  1757.         mov     dx,cx
  1758.         in      al,dx
  1759.         mov     dx,bx
  1760.         mov     al,8Fh
  1761.         out     dx,al
  1762.         mov     dx,cx
  1763.         in      al,dx
  1764.  
  1765.         push    cx
  1766.         mov     cx,32
  1767. VoiceClearLoop:
  1768.         mov     dx,cs:[BasePort]
  1769.         add     dx,ActiveVoicePort
  1770.         mov     al,cl
  1771.         dec     al
  1772.         out     dx,al
  1773.         inc     dx
  1774.         mov     al,0
  1775.         out     dx,al
  1776.         add     dx,2
  1777.         mov     al,3    ; Voice Off
  1778.         out     dx,al
  1779.         sub     dx,2
  1780.         mov     al,0Dh
  1781.         out     dx,al
  1782.         add     dx,2
  1783.         mov     al,3    ; Ramp Off
  1784.         out     dx,al
  1785.         loop    VoiceClearLoop
  1786.         pop     cx
  1787.  
  1788.         mov     dx,bx
  1789.         mov     al,DMACtrl
  1790.         out     dx,al
  1791.         mov     dx,cx
  1792.         in      al,dx
  1793.         mov     dx,bx
  1794.         mov     al,49h
  1795.         out     dx,al
  1796.         mov     dx,cx
  1797.         in      al,dx
  1798.         mov     dx,bx
  1799.         mov     al,8Fh
  1800.         out     dx,al
  1801.         mov     dx,cx
  1802.         in      al,dx
  1803.  
  1804.         mov     dx,bx
  1805.         mov     al,Initialize
  1806.         out     dx,al
  1807.         mov     dx,cx
  1808.         mov     al,7
  1809.         out     dx,al
  1810.  
  1811.         mov     cx,NumVoices
  1812. SetRampRateLoop:
  1813.         mov     dx,cs:[BasePort]
  1814.         add     dx,ActiveVoicePort
  1815.         mov     al,NumVoices
  1816.         sub     al,cl
  1817.         out     dx,al
  1818.  
  1819.         mov     dx,cs:[BasePort]
  1820.         add     dx,CommandPort
  1821.         mov     al,VolRampRate
  1822.         out     dx,al
  1823.         mov     al,00111111b
  1824.         mov     dx,cs:[BasePort]
  1825.         add     dx,DataHighPort
  1826.         out     dx,al
  1827.  
  1828.         mov     dx,cs:[BasePort]
  1829.         add     dx,CommandPort
  1830.         mov     al,SetVolume
  1831.         out     dx,al
  1832.         mov     ax,cs:[GusVol]
  1833.         mov     dx,cs:[BasePort]
  1834.         add     dx,DataLowPort
  1835.         out     dx,ax
  1836.         loop    SetRampRateLoop
  1837.  
  1838. ;       Finished Initialize (Pheewww!!!!!!!!!!!!!)
  1839.  
  1840.         pop     es
  1841.         pop     ds
  1842.         popa
  1843.         ret
  1844.  
  1845. InitDevice      EndP
  1846.  
  1847. ClearMem        Proc    Far
  1848.  
  1849.         pusha
  1850.         push    es
  1851.         mov     es,cs:[PatternMem]
  1852.         call    DeAlloc
  1853.         pop     es
  1854.         popa
  1855.         ret
  1856.  
  1857. ClearMem        EndP
  1858.  
  1859. LoadMod         Proc    Far
  1860. ; Error if CF set! ax=errorcode.
  1861. ; ax=1, File or path not found.
  1862. ; ax=2, Error loading file.
  1863. ; ax=3, Out of memory.
  1864.  
  1865.         call    FileOpen
  1866.         jnc     NoOpenError
  1867.         mov     ax,[ErrorCode]
  1868.         jmp     NoMod
  1869. NoOpenError:
  1870.         call    ModLoad
  1871.         jnc     NoLoadError
  1872.         mov     ax,[ErrorCode]
  1873.         jmp     NoMod
  1874. NoLoadError:
  1875.         call    FileClose
  1876. NoMod:
  1877.         ret
  1878.  
  1879. LoadMod         EndP
  1880.  
  1881. ModLoad         Proc    Near
  1882.  
  1883.         pusha
  1884.         push    ds
  1885.         push    es
  1886.  
  1887.         mov     cs:[MainVolume], 64
  1888.         mov     cx,1084
  1889.         mov     dx,offset cs:[Info]
  1890.         push    cs
  1891.         pop     ds
  1892.         call    FileRead
  1893.         mov     cs:[NumChans],4
  1894.         mov     bp,offset cs:[Info+1080]
  1895.         mov     bx,0
  1896.         mov     cx,4
  1897. TestInst1:
  1898.         mov     al,cs:[bp]
  1899.         cmp     al,cs:[MKSign+bx]
  1900.         jne     NoMK1
  1901.         inc     bp
  1902.         inc     bx
  1903.         loop    TestInst1
  1904.         mov     si,offset cs:[Info+952]
  1905.         mov     cs:[MKMod],1
  1906.         jmp     Load
  1907. NoMK1:
  1908.         mov     bp,offset cs:[Info+1080]
  1909.         mov     bx,4
  1910.         mov     cx,4
  1911. TestInst2:
  1912.         mov     al,cs:[bp]
  1913.         cmp     al,cs:[MKSign+bx]
  1914.         jne     NoMK2
  1915.         inc     bp
  1916.         inc     bx
  1917.         loop    TestInst2
  1918.         mov     si,offset cs:[Info+952]
  1919.         mov     cs:[MKMod],1
  1920.         jmp     Load
  1921. NoMK2:
  1922.         mov     bp,offset cs:[Info+1080]
  1923.         mov     bx,8
  1924.         mov     cx,4
  1925. TestInst3:
  1926.         mov     al,cs:[bp]
  1927.         cmp     al,cs:[MKSign+bx]
  1928.         jne     No6CHN2
  1929.         inc     bp
  1930.         inc     bx
  1931.         loop    TestInst3
  1932.         mov     cs:[MainVolume],48
  1933.         mov     cs:[NumChans],6
  1934.         mov     si,offset cs:[Info+952]
  1935.         mov     cs:[MKMod],1
  1936.         jmp     Load
  1937. No6CHN2:
  1938.         mov     bp,offset cs:[Info+1080]
  1939.         mov     bx,12
  1940.         mov     cx,4
  1941. TestInst4:
  1942.         mov     al,cs:[bp]
  1943.         cmp     al,cs:[MKSign+bx]
  1944.         jne     No8CHN3
  1945.         inc     bp
  1946.         inc     bx
  1947.         loop    TestInst4
  1948.  
  1949.         mov     cs:[MainVolume],32
  1950.         mov     cs:[NumChans],8
  1951.         mov     si,offset cs:[Info+952]
  1952.         mov     cs:[MKMod],1
  1953.         jmp     Load
  1954. No8CHN3:
  1955.         mov     bp,offset cs:[Info+1080]
  1956.         mov     bx,16
  1957.         mov     cx,4
  1958. TestInst5:
  1959.         mov     al,cs:[bp]
  1960.         cmp     al,cs:[MKSign+bx]
  1961.         jne     STMod
  1962.         inc     bp
  1963.         inc     bx
  1964.         loop    TestInst5
  1965.         mov     cs:[MainVolume],32
  1966.         mov     cs:[NumChans],8
  1967.         mov     si,offset cs:[Info+952]
  1968.         mov     cs:[MKMod],1
  1969.         jmp     Load
  1970. STMod:
  1971.         call    MovePoint
  1972.         mov     dx,offset cs:[Info]
  1973.         mov     cx,600
  1974.         call    FileRead
  1975.         mov     si,offset cs:[Info+472]
  1976.         mov     cs:[MKMod],0
  1977.  
  1978. Load:
  1979.         mov     ax,cs:[si-2]
  1980.         mov     Word Ptr cs:[OrderLen],ax
  1981.         mov     di,offset cs:[PatternOrder]
  1982.         mov     cx,128
  1983. CopyOrder:
  1984.         mov     al,cs:[si]
  1985.         mov     cs:[di],al
  1986.         inc     si
  1987.         inc     di
  1988.         loop    CopyOrder
  1989.         mov     si,offset cs:[PatternOrder]
  1990.         mov     cx,128
  1991.         mov     ax,0
  1992. CheckPatt:
  1993.         mov     al,cs:[si]
  1994.         cmp     al,ah
  1995.         jb      NoHigh
  1996.         xchg    ah,al
  1997. NoHigh:
  1998.         inc     si
  1999.         loop    CheckPatt
  2000.         inc     ah
  2001.         xor     al,al
  2002.         mov     bx,cs:[NumChans]
  2003.         mul     bx
  2004.         mov     si,dx
  2005.         mov     di,ax
  2006.         mov     bx,16
  2007.         div     bx
  2008.         mov     bx,ax
  2009.         call    Alloc
  2010.         jnc     NoOutHunk
  2011.         stc
  2012.         mov     cs:[ErrorCode],3
  2013.         jmp     ErrorLoad               ; Fixa nån slags error-flagga.
  2014. NoOutHunk:
  2015.         mov     cs:[PatternMem],ax
  2016.         mov     ds,ax
  2017.  
  2018. LoadLoop:
  2019.         dec     si
  2020.         js      EndBigLoad
  2021.         mov     dx,0
  2022.         mov     cx,65535
  2023.         call    FileRead
  2024.         mov     dx,65535
  2025.         mov     cx,1
  2026.         call    FileRead
  2027.         mov     dx,ds
  2028.         add     dx,1000h
  2029.         mov     ds,dx
  2030.         jmp     Short LoadLoop
  2031. EndBigLoad:
  2032.         mov     cx,di
  2033.         mov     dx,0
  2034.         call    FileRead
  2035.  
  2036.         mov     cx,15
  2037.         cmp     cs:[MKMod],1
  2038.         jne     NoMK
  2039.         mov     cx,31
  2040. NoMK:
  2041.         mov     bx,4096
  2042.         call    Alloc
  2043.         mov     cs:[SampMem],ax
  2044.         mov     Word Ptr cs:[GUSMem],0
  2045.         mov     Word Ptr cs:[GUSMem+2],0
  2046.         mov     si,offset cs:[Info+42]
  2047.         mov     bp,0
  2048. LoadIns:
  2049.         push    cx
  2050.         mov     Word Ptr cs:[SampLen+bp],0
  2051.         mov     cx,cs:[si]
  2052.         add     si,2
  2053.         xchg    ch,cl
  2054.         cmp     cx,2
  2055.         jbe     NoIns
  2056.         shl     cx,1
  2057.         mov     cs:[SampLen+bp],cx
  2058.         mov     ds,cs:[SampMem]
  2059.         mov     dx,0
  2060.         call    FileRead
  2061.  
  2062. ;       Lets move the sample to the UltaraSound!
  2063.  
  2064.         push    bp
  2065.         mov     cx,cs:[SampLen+bp]
  2066.         shl     bp,1
  2067.         mov     di,Word Ptr cs:[GUSMem]
  2068.         mov     bl,Byte Ptr cs:[GUSMem+2]
  2069.         mov     Word Ptr [SampOffset+bp],di
  2070.         mov     Byte Ptr [SampOffset+bp+2],bl
  2071.         mov     bp,di
  2072.         mov     di,0
  2073.         mov     dx,cs:[BasePort]
  2074.         add     dx,CommandPort
  2075.  
  2076. MSamp2GUS:
  2077.         mov     al,DRAMAddrLo
  2078.         out     dx,al
  2079.         inc     dx
  2080.         mov     ax,bp
  2081.         out     dx,ax
  2082.         dec     dx
  2083.         mov     al,DRAMAddrHi
  2084.         out     dx,al
  2085.         inc     dx
  2086.         inc     dx
  2087.         mov     al,bl
  2088.         out     dx,al
  2089.         inc     dx
  2090.         inc     dx
  2091.         mov     al,[di]
  2092.         out     dx,al
  2093.         sub     dx,4
  2094.         inc     di
  2095.         add     bp,1
  2096.         adc     bl,0
  2097.         dec     cx
  2098.         jnz     MSamp2GUS
  2099.  
  2100.         dec     di
  2101.         mov     al,DRAMAddrLo
  2102.         out     dx,al
  2103.         inc     dx
  2104.         mov     ax,bp
  2105.         out     dx,ax
  2106.         dec     dx
  2107.         mov     al,DRAMAddrHi
  2108.         out     dx,al
  2109.         add     dx,2
  2110.         mov     al,bl
  2111.         out     dx,al
  2112.         add     dx,2
  2113.         mov     al,[di]
  2114.         out     dx,al
  2115.         sub     dx,4
  2116.         add     bp,1
  2117.         adc     bl,0
  2118.         mov     Word Ptr cs:[GUSMem],bp
  2119.         mov     Byte Ptr cs:[GUSMem+2],bl
  2120.         pop     bp
  2121.  
  2122. NoIns:
  2123.         mov     ah,0
  2124.         mov     al,cs:[si]
  2125.         inc     si
  2126.         mov     cs:[SampFine+bp],ax
  2127.         mov     al,cs:[si]
  2128.         inc     si
  2129.         mov     Byte Ptr cs:[SampVol+bp],al
  2130.  
  2131.         mov     dx,cs:[SampLen+bp]
  2132.         mov     ax,cs:[si]
  2133.         add     si,2
  2134.         xchg    ah,al
  2135.         mov     cx,cs:[si]
  2136.         add     si,2
  2137.         xchg    ch,cl
  2138.         cmp     cs:[MKMod],1
  2139.         jne     STMod1
  2140.         shl     ax,1
  2141.         shl     cx,1
  2142. STMod1:
  2143.         mov     cs:[SampRepLen+bp],cx
  2144.         add     cx,ax
  2145.         cmp     cx,dx
  2146.         jbe     NoRepFix
  2147.         mov     cx,dx
  2148.         sub     cx,ax
  2149.         mov     cs:[SampRepLen+bp],cx
  2150. NoRepFix:
  2151.         mov     cs:[SampRep+bp],ax
  2152.  
  2153.         add     si,22
  2154.         add     bp,2
  2155.         pop     cx
  2156.         dec     cx
  2157.         jz      Loaded
  2158.         jmp     LoadIns
  2159. Loaded:
  2160.         mov     es,cs:[SampMem]
  2161.         call    DeAlloc
  2162.         mov     cs:[ErrorCode],0
  2163.         clc
  2164.  
  2165. ;       Set Pan Regs!!
  2166.  
  2167. ErrorLoad:
  2168.         mov     cx,cs:[NumChans]
  2169.         mov     bx,cx
  2170.         shr     bx,1
  2171.         sub     bx,2
  2172.         shl     bx,4
  2173. SetPanLoop:
  2174.         mov     dx,cs:[BasePort]
  2175.         add     dx,ActiveVoicePort
  2176.         mov     al,Byte Ptr cs:[NumChans]
  2177.         sub     al,cl
  2178.         out     dx,al
  2179.  
  2180.         mov     dx,cs:[BasePort]
  2181.         add     dx,CommandPort
  2182.         mov     al,VoiceBalance
  2183.         out     dx,al
  2184.         mov     dx,cs:[BasePort]
  2185.         add     dx,DataHighPort
  2186.         mov     al,cs:[PanRegs+bx]
  2187.         out     dx,al
  2188.         inc     bx
  2189.         loop    SetPanLoop
  2190.  
  2191.         pop     es
  2192.         pop     ds
  2193.         popa
  2194.         ret
  2195.  
  2196. ModLoad         EndP
  2197.  
  2198. Alloc           Proc    Near
  2199.  
  2200.         push    bx
  2201.         mov     ax,4800h
  2202.         int     21h
  2203.         pop     bx
  2204.         ret
  2205.  
  2206. Alloc           EndP
  2207.  
  2208. DeAlloc         Proc    Near
  2209.  
  2210.         push    ax
  2211.         push    es
  2212.         mov     ax,4900h
  2213.         int     21h
  2214.         pop     es
  2215.         pop     ax
  2216.         ret
  2217.  
  2218. DeAlloc         EndP
  2219.  
  2220. FileRead        Proc    Near
  2221.  
  2222.         push    ax
  2223.         push    bx
  2224.         push    cx
  2225.         push    dx
  2226.         push    ds
  2227.         mov     ax,3F00h
  2228.         mov     bx,cs:[FileHandle]
  2229.         int     21h
  2230.         pop     ds
  2231.         pop     dx
  2232.         pop     cx
  2233.         pop     bx
  2234.         pop     ax
  2235.         ret
  2236.  
  2237. FileRead        EndP
  2238.  
  2239. FileOpen        Proc    Near
  2240.  
  2241.         push    dx
  2242.         push    ds
  2243.         mov     ax,3D00h
  2244.         int     21h
  2245.         mov     cs:[FileHandle],ax
  2246.         jnc     NoErrorOpen
  2247.         mov     cs:[ErrorCode],1
  2248. NoErrorOpen:
  2249.         pop     ds
  2250.         pop     dx
  2251.         ret
  2252.  
  2253. FileOpen        EndP
  2254.  
  2255. FileClose       Proc    Near
  2256.  
  2257.         push    ax
  2258.         push    bx
  2259.         mov     ax,3E00h
  2260.         mov     bx,cs:[FileHandle]
  2261.         int     21h
  2262.         pop     bx
  2263.         pop     ax
  2264.         ret
  2265.  
  2266. FileClose       EndP
  2267.  
  2268. MovePoint       Proc    Near
  2269.  
  2270.         push    ax
  2271.         push    bx
  2272.         push    cx
  2273.         push    dx
  2274.         mov     ax,4200h
  2275.         mov     bx,cs:[FileHandle]
  2276.         mov     cx,0
  2277.         mov     dx,0
  2278.         int     21h
  2279.         pop     dx
  2280.         pop     cx
  2281.         pop     bx
  2282.         pop     ax
  2283.         ret
  2284.  
  2285. MovePoint       EndP
  2286.  
  2287. _Code   EndS
  2288.  
  2289.         End
  2290.