.386
.MODEL TPascal
  b equ byte ptr
  w equ word ptr
  d equ dword ptr


.DATA

extrn current_voice : word;
extrn calc_size     : word;
extrn mixed_data    : dword;
extrn mixed_posi    : word;
extrn mixed_data_st : dword;

extrn mixingprocs : dword;
extrn emptyvoice  : dword;

extrn length_voice      : dword
extrn position_voice    : dword
extrn loop_length_voice : dword
extrn loop_start_voice  : dword
extrn segment_voice     : dword
extrn notvol_voice      : dword
extrn incval_voice      : dword


.CODE


public voice_normal
voice_normal proc pascal ;current_voice : word;
 pusha
 mov si,current_voice
 dec si
 shl si,2                    ; for dword accessw

 mov cx,calc_size

@load_loop:

;{ Is voice at the end ? }
  mov bx,w length_voice[si]
  sub bx,20
  cmp bx,word ptr position_voice[si+2]
  ja  @voice_not_at_end

;{ Voice at end, is it looped ? }
  cmp loop_length_voice[si],10
  jae @voice_is_looped

;{Voice is at the end and not looped => out}
  mov eax,emptyvoice
  mov mixingprocs[si],eax
  mov notvol_voice[si],0
  jmp @end_voice_normal

; {Parameter for voice1 at start of loop }
@voice_is_looped:
  mov bx,w loop_start_voice[si]
  mov word ptr position_voice[si + 2],bx

; {Load byte from sample of voice1 }
@voice_not_at_end:
  mov bx,w segment_voice[si]
  mov es,bx
  mov bx,word ptr position_voice[si + 2]
  mov al,es:[bx]
  sub al,128
  mul b notvol_voice[si]
  shr ax,6

@voice_output:
  les di,mixed_data
  add di,mixed_posi
  add es:[di],ax
  add mixed_posi,2

; {Increment pointer}
  mov ebx,Incval_voice[si]
  add dword ptr position_voice[si],ebx

  loop @load_loop

@end_voice_normal:
  popa
  ret
voice_normal endp



public voice_normal_st
voice_normal_st proc pascal ;current_voice : word;
 pusha
 mov si,current_voice
 dec si
 shl si,2                    ; for dword-accessw

 mov cx,calc_size

@load_loop_st:

;{ Is voice at the end ? }
  mov bx,w length_voice[si]
  sub bx,20
  cmp bx,word ptr position_voice[si+2]
  ja  @voice_not_at_end_st

;{ Voice at end, is it looped ? }
  cmp loop_length_voice[si],10
  jae @voice_is_looped_st

;{Voice is at the end and not looped => out}
  mov eax,emptyvoice
  mov mixingprocs[si],eax
  mov ax,127
  mov notvol_voice[si],0
  jmp @end_voice_normal_st

; {Parameter for voice1 at start of loop }
@voice_is_looped_st:
  mov bx,w loop_start_voice[si]
  mov word ptr position_voice[si + 2],bx

; {Load byte from sample of voice1 }
@voice_not_at_end_st:
  mov bx,w segment_voice[si]
  mov es,bx
  mov bx,word ptr position_voice[si + 2]
  mov al,es:[bx]
  sub al,128
  mul b notvol_voice[si]
  shr ax,6

@voice_output_st:
  les di,mixed_data_st
  add di,mixed_posi
  add es:[di],ax
  add mixed_posi,2

; {Increment pointer}
  mov ebx,incval_voice[si]
  add dword ptr position_voice[si],ebx

  loop @load_loop_st

@end_voice_normal_st:
  popa
  ret
voice_normal_st endp






public empty_voice
empty_voice proc pascal
  ret
empty_voice endp

END
