2010-10-01 13:21:55 +04:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2012-10-12 22:24:48 +04:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
|
2010-10-01 13:21:55 +04:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
format MS COFF
|
|
|
|
|
2011-07-22 22:08:47 +04:00
|
|
|
include 'CONFIG.INC'
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
;structs----------------------------------------------------------
|
|
|
|
struc IOCTL
|
2012-03-08 12:33:38 +04:00
|
|
|
{ .handle dd ?
|
|
|
|
.io_code dd ?
|
|
|
|
.input dd ?
|
|
|
|
.inp_size dd ?
|
|
|
|
.output dd ?
|
|
|
|
.out_size dd ?
|
2010-10-01 13:21:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual at 0
|
|
|
|
IOCTL IOCTL
|
|
|
|
end virtual
|
|
|
|
|
|
|
|
;something--------------------------------------------------------
|
|
|
|
public START
|
|
|
|
public service_proc
|
|
|
|
public version
|
|
|
|
|
|
|
|
include '..\proc32.inc'
|
|
|
|
include '..\imports.inc'
|
|
|
|
|
|
|
|
section '.flat' code readable align 16
|
|
|
|
|
2011-07-22 22:08:47 +04:00
|
|
|
include 'SB16.INC'
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
;-------------------------------------------------------------------------------
|
|
|
|
proc START stdcall, state:dword
|
2012-03-08 12:33:38 +04:00
|
|
|
cmp [state], 1
|
|
|
|
jne .stop
|
2010-10-01 13:21:55 +04:00
|
|
|
.entry:
|
|
|
|
|
|
|
|
if DEBUG
|
2012-03-08 12:33:38 +04:00
|
|
|
mov esi, msgInit
|
|
|
|
call SysMsgBoardStr
|
2010-10-01 13:21:55 +04:00
|
|
|
end if
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
call detect ;returns DSP version or zero if
|
|
|
|
test eax, eax ;SB card not found
|
|
|
|
jz .exit
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
if DEBUG
|
2012-03-08 12:33:38 +04:00
|
|
|
movzx eax, al ;major version
|
|
|
|
mov esi, sb_DSP_description
|
|
|
|
dec eax
|
|
|
|
jz .sb_say_about_found_dsp
|
|
|
|
mov dword[esi], '2.x '
|
|
|
|
dec eax
|
|
|
|
jz .sb_say_about_found_dsp
|
|
|
|
mov dword[esi], 'Pro '
|
|
|
|
dec eax
|
|
|
|
jz .sb_say_about_found_dsp
|
|
|
|
mov dword[esi], '16 '
|
2010-10-01 13:21:55 +04:00
|
|
|
.sb_say_about_found_dsp:
|
2012-03-08 12:33:38 +04:00
|
|
|
mov esi, msgDSPFound
|
|
|
|
call SysMsgBoardStr
|
2010-10-01 13:21:55 +04:00
|
|
|
end if
|
2012-03-08 12:33:38 +04:00
|
|
|
; xor eax,eax
|
|
|
|
; mov ebx,[sb_base_port]
|
|
|
|
; lea ecx,[ebx+0xF]
|
|
|
|
xor ebx, ebx
|
|
|
|
mov ecx, [sb_base_port]
|
|
|
|
lea edx, [ebx+0xF]
|
|
|
|
|
|
|
|
call ReservePortArea ;these ports must be my!
|
2010-10-01 13:21:55 +04:00
|
|
|
if DEBUG
|
2012-03-08 12:33:38 +04:00
|
|
|
dec eax
|
|
|
|
jnz @f
|
|
|
|
mov esi, msgErrRsrvPorts
|
|
|
|
call SysMsgBoardStr
|
2010-10-01 13:21:55 +04:00
|
|
|
@@:
|
|
|
|
end if
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
call sb_setup ;clock it, etc
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
stdcall AttachIntHandler, sb_irq_num, sb_irq, 0
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
if DEBUG
|
2012-03-08 12:33:38 +04:00
|
|
|
test eax, eax
|
|
|
|
jnz @f
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
mov esi, msgErrAtchIRQ
|
|
|
|
call SysMsgBoardStr
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-10-12 22:24:48 +04:00
|
|
|
; stdcall GetIntHandler, sb_irq_num
|
|
|
|
; call SysMsgBoardNum
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
jmp .stop
|
2010-10-01 13:21:55 +04:00
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
mov esi, msgSucAtchIRQ
|
|
|
|
call SysMsgBoardStr
|
2010-10-01 13:21:55 +04:00
|
|
|
end if
|
2012-03-08 12:33:38 +04:00
|
|
|
stdcall RegService, my_service, service_proc
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
.stop:
|
2012-03-08 12:33:38 +04:00
|
|
|
call sb_reset
|
2010-10-01 13:21:55 +04:00
|
|
|
.exit:
|
|
|
|
|
|
|
|
if DEBUG
|
2012-03-08 12:33:38 +04:00
|
|
|
mov esi, msgExit
|
|
|
|
call SysMsgBoardStr
|
2010-10-01 13:21:55 +04:00
|
|
|
end if
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
xor eax, eax
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
endp
|
|
|
|
;-------------------------------------------------------------------------------
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
handle equ IOCTL.handle
|
|
|
|
io_code equ IOCTL.io_code
|
|
|
|
input equ IOCTL.input
|
|
|
|
inp_size equ IOCTL.inp_size
|
|
|
|
output equ IOCTL.output
|
|
|
|
out_size equ IOCTL.out_size
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
align 4
|
|
|
|
proc service_proc stdcall, ioctl:dword
|
2012-03-08 12:33:38 +04:00
|
|
|
mov edi, [ioctl]
|
|
|
|
mov eax, [edi+io_code]
|
|
|
|
cmp eax, SRV_GETVERSION
|
|
|
|
jne @F
|
|
|
|
|
|
|
|
mov eax, [edi+output]
|
|
|
|
cmp [edi+out_size], 4
|
|
|
|
jne .fail
|
|
|
|
mov [eax], dword API_VERSION
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
cmp eax, DEV_PLAY
|
|
|
|
jne @f
|
2010-10-01 13:21:55 +04:00
|
|
|
if DEBUG
|
2012-03-08 12:33:38 +04:00
|
|
|
mov esi, msgPlay
|
|
|
|
call SysMsgBoardStr
|
2010-10-01 13:21:55 +04:00
|
|
|
end if
|
2012-03-08 12:33:38 +04:00
|
|
|
call sb_stop ;to play smth new we must stop smth old
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
call pre_fill_data ;fill first and second half of the buffer
|
|
|
|
call pre_fill_data ;
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
call sb_set_dma ;is it really needed here? Paranoia.
|
|
|
|
call sb_play
|
|
|
|
xor eax, eax ;set maximum volume
|
|
|
|
call sb_set_master_vol
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
;@@: ;all this commented stuff in service proc
|
|
|
|
; cmp eax,DEV_STOP ;is never used. Mixer do this virtually,
|
|
|
|
; jne @f ;e.g. instead of stopping driver it
|
|
|
|
;if DEBUG ;outputs silence
|
|
|
|
; mov esi,msgStop
|
|
|
|
; call SysMsgBoardStr
|
|
|
|
;end if
|
|
|
|
; call sb_stop
|
|
|
|
; xor eax,eax
|
|
|
|
; ret
|
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
cmp eax, DEV_CALLBACK
|
|
|
|
jne @f
|
2010-10-01 13:21:55 +04:00
|
|
|
if DEBUG
|
2012-03-08 12:33:38 +04:00
|
|
|
mov esi, msgCallback
|
|
|
|
call SysMsgBoardStr
|
2010-10-01 13:21:55 +04:00
|
|
|
end if
|
2012-03-08 12:33:38 +04:00
|
|
|
mov edi, [edi+input]
|
|
|
|
mov eax, [edi]
|
|
|
|
mov [callback], eax
|
2010-10-01 13:21:55 +04:00
|
|
|
if DEBUG
|
2012-03-08 12:33:38 +04:00
|
|
|
call SysMsgBoardNum
|
2010-10-01 13:21:55 +04:00
|
|
|
end if
|
2012-03-08 12:33:38 +04:00
|
|
|
xor eax, eax
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
cmp eax, DEV_SET_MASTERVOL;Serge asked me to unlock
|
|
|
|
jne @F ;DEV_SET(GET)_MASTERVOL, although mixer doesn't use it.
|
|
|
|
;It doesn't use it _in current version_ - but in the future...
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
if DEBUG
|
2012-03-08 12:33:38 +04:00
|
|
|
mov esi, msgSetVol
|
|
|
|
call SysMsgBoardStr
|
2010-10-01 13:21:55 +04:00
|
|
|
end if
|
2012-03-08 12:33:38 +04:00
|
|
|
mov eax, [edi+input]
|
|
|
|
mov eax, [eax]
|
|
|
|
call sb_set_master_vol
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
cmp eax, DEV_GET_MASTERVOL
|
|
|
|
jne @F
|
2010-10-01 13:21:55 +04:00
|
|
|
if DEBUG
|
2012-03-08 12:33:38 +04:00
|
|
|
mov esi, msgGetVol
|
|
|
|
call SysMsgBoardStr
|
2010-10-01 13:21:55 +04:00
|
|
|
end if
|
2012-03-08 12:33:38 +04:00
|
|
|
mov eax, [edi+output]
|
|
|
|
mov edx, [sb_master_vol]
|
|
|
|
mov [eax], edx
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
.fail:
|
2012-03-08 12:33:38 +04:00
|
|
|
or eax, -1
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
endp
|
|
|
|
|
|
|
|
restore handle
|
|
|
|
restore io_code
|
|
|
|
restore input
|
|
|
|
restore inp_size
|
|
|
|
restore output
|
|
|
|
restore out_size
|
|
|
|
|
|
|
|
;-------------------------------------------------------------------------------
|
|
|
|
align 4
|
|
|
|
proc sb_irq
|
2012-03-08 12:33:38 +04:00
|
|
|
mov edx, [sb_base_port];tell the DSP that we have processed IRQ
|
|
|
|
add dl, 0xF ;0xF for 16 bit sound, 0xE for 8 bit sound
|
|
|
|
in al, dx ;for non-stop sound
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
pre_fill_data:
|
2012-03-08 12:33:38 +04:00
|
|
|
mov eax, int_flip_flop
|
|
|
|
not dword[eax]
|
|
|
|
mov eax, [eax]
|
|
|
|
test eax, eax
|
|
|
|
jns .fill_second_half
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
if sb_buffer_size eq small_buffer
|
2012-03-08 12:33:38 +04:00
|
|
|
stdcall [callback], SB16Buffer0 ;for 32k buffer
|
2010-10-01 13:21:55 +04:00
|
|
|
else if sb_buffer_size eq full_buffer
|
2012-03-08 12:33:38 +04:00
|
|
|
stdcall [callback], SB16Buffer0 ;for 64k buffer
|
|
|
|
stdcall [callback], SB16Buffer1 ;for 64k buffer
|
2010-10-01 13:21:55 +04:00
|
|
|
end if
|
2012-03-08 12:33:38 +04:00
|
|
|
xor eax, eax
|
|
|
|
not eax
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
.fill_second_half:
|
|
|
|
if sb_buffer_size eq small_buffer
|
2012-03-08 12:33:38 +04:00
|
|
|
stdcall [callback], SB16Buffer1 ;for 32k buffer
|
2010-10-01 13:21:55 +04:00
|
|
|
else if sb_buffer_size eq full_buffer
|
2012-03-08 12:33:38 +04:00
|
|
|
stdcall [callback], SB16Buffer2 ;for 64k buffer
|
|
|
|
stdcall [callback], SB16Buffer3 ;for 64k buffer
|
2010-10-01 13:21:55 +04:00
|
|
|
end if
|
2012-03-08 12:33:38 +04:00
|
|
|
xor eax, eax
|
|
|
|
not eax
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
endp
|
|
|
|
;-------------------------------------------------------------------------------
|
|
|
|
align 4
|
|
|
|
proc detect
|
|
|
|
.sb_detect_next_port:
|
|
|
|
if DEBUG
|
2012-03-08 12:33:38 +04:00
|
|
|
inc dword[port_second_digit_num]
|
2010-10-01 13:21:55 +04:00
|
|
|
end if
|
2012-03-08 12:33:38 +04:00
|
|
|
mov edx, sb_base_port
|
|
|
|
add byte[edx], 10h
|
|
|
|
cmp byte[edx], 80h
|
|
|
|
jbe .sb_try_to_detect_at_specified_port
|
2010-10-01 13:21:55 +04:00
|
|
|
;error - no SB card detected
|
|
|
|
.sb_not_found_err:
|
2012-03-08 12:33:38 +04:00
|
|
|
xor eax, eax
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
.sb_try_to_detect_at_specified_port:
|
2012-03-08 12:33:38 +04:00
|
|
|
call sb_reset
|
|
|
|
add dl, 8
|
|
|
|
mov ecx, 100
|
2010-10-01 13:21:55 +04:00
|
|
|
.sb_check_port:
|
2012-03-08 12:33:38 +04:00
|
|
|
in al, dx
|
|
|
|
test al, al ;is DSP port ready to be read?
|
|
|
|
jns .sb_port_not_ready
|
|
|
|
|
|
|
|
sub dl, 4
|
|
|
|
in al, dx ;check for AAh response
|
|
|
|
add dl, 4
|
|
|
|
cmp al, 0xAA
|
|
|
|
jne .sb_port_not_ready
|
2010-10-01 13:21:55 +04:00
|
|
|
.sb_card_found:
|
2012-03-08 12:33:38 +04:00
|
|
|
and dl, 0xF0
|
|
|
|
add dl, 0xC
|
|
|
|
sb_out 0xE1 ;get DSP version
|
|
|
|
add dl, 2
|
2010-10-01 13:21:55 +04:00
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
in al, dx
|
|
|
|
test al, al ;is DSP port ready to be read?
|
|
|
|
jns @b
|
|
|
|
sub dl, 4
|
|
|
|
in al, dx ;get major version
|
|
|
|
ror eax, 16
|
|
|
|
add dl, 4
|
2010-10-01 13:21:55 +04:00
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
in al, dx
|
|
|
|
test al, al ;is DSP port ready to be read?
|
|
|
|
jns @b
|
|
|
|
sub dl, 4
|
|
|
|
in al, dx ;get minor version
|
|
|
|
xor edx, edx
|
|
|
|
mov dl, 10
|
|
|
|
div dl
|
|
|
|
ror eax, 16
|
|
|
|
xor ah, ah
|
|
|
|
mov [sb_DSP_version_int], eax;for internal usage
|
2010-10-01 13:21:55 +04:00
|
|
|
if DEBUG
|
2012-03-08 12:33:38 +04:00
|
|
|
add [sb_DSP_version], eax
|
2010-10-01 13:21:55 +04:00
|
|
|
end if
|
2012-03-08 12:33:38 +04:00
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
.sb_port_not_ready:
|
2012-03-08 12:33:38 +04:00
|
|
|
loop .sb_check_port ;100 retries (~100 microsec.)
|
|
|
|
jmp .sb_detect_next_port
|
2010-10-01 13:21:55 +04:00
|
|
|
endp
|
|
|
|
;-------------------------------------------------------------------------------
|
|
|
|
if DEBUG
|
|
|
|
proc SysMsgBoardNum ;warning: destroys eax,ebx,ecx,esi
|
2012-03-08 12:33:38 +04:00
|
|
|
mov ebx, eax
|
|
|
|
mov ecx, 8
|
|
|
|
mov esi, (number_to_out+1)
|
2010-10-01 13:21:55 +04:00
|
|
|
.1:
|
2012-03-08 12:33:38 +04:00
|
|
|
mov eax, ebx
|
|
|
|
and eax, 0xF
|
|
|
|
add al, '0'
|
|
|
|
cmp al, (10+'0')
|
|
|
|
jb @f
|
|
|
|
add al, ('A'-'0'-10)
|
2010-10-01 13:21:55 +04:00
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
mov [esi+ecx], al
|
|
|
|
shr ebx, 4
|
|
|
|
loop .1
|
|
|
|
dec esi
|
|
|
|
call SysMsgBoardStr
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
endp
|
|
|
|
end if
|
|
|
|
;all initialized data place here
|
|
|
|
align 4
|
|
|
|
version dd (5 shl 16) or (API_VERSION and 0xFFFF)
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
sb_base_port:
|
|
|
|
dd 200h ;don't ask me why - see the code&docs
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
sound_dma dd sb_dma_num
|
|
|
|
|
|
|
|
;note that 4th DMA channel doesn't exist, it is used for cascade
|
|
|
|
;plugging the first DMA controler to the second
|
|
|
|
dma_table db 0x87,0x83,0x81,0x82,0xFF,0x8B,0x89,0x8A
|
|
|
|
|
|
|
|
my_service db 'SOUND',0 ;max 16 chars include zero
|
|
|
|
|
|
|
|
if DEBUG
|
|
|
|
number_to_out db '0x00000000',13,10,0
|
|
|
|
|
|
|
|
msgInit db 'detecting hardware...',13,10,0
|
|
|
|
msgExit db 'exiting... May be some problems found?',13,10,0
|
|
|
|
msgPlay db 'start play',13,10,0
|
|
|
|
;msgStop db 'stop play',13,10,0
|
|
|
|
msgCallback db 'set_callback received from the mixer!',13,10
|
2012-03-08 12:33:38 +04:00
|
|
|
db 'callback handler is: ',0
|
2010-10-01 13:21:55 +04:00
|
|
|
msgErrAtchIRQ db 'failed to attach IRQ',(sb_irq_num+'0'),13,10
|
2012-03-08 12:33:38 +04:00
|
|
|
db 'owner',39,'s handler: ',0
|
2010-10-01 13:21:55 +04:00
|
|
|
msgSucAtchIRQ db 'succesfully attached IRQ',(sb_irq_num+'0')
|
2012-03-08 12:33:38 +04:00
|
|
|
db ' as hardcoded',13,10,0
|
2010-10-01 13:21:55 +04:00
|
|
|
msgErrRsrvPorts db 'failed to reserve needed ports.',13,10
|
2012-03-08 12:33:38 +04:00
|
|
|
db 'Driver may work unstable',13,10,0
|
2010-10-01 13:21:55 +04:00
|
|
|
msgSetVol db 'DEV_SET_MASTERVOL call came',13,10,0
|
|
|
|
msgGetVol db 'DEV_GET_MASTERVOL call came',13,10,0
|
|
|
|
msgErrDMAsetup db 'failed to setup DMA - bad channel',13,10,0
|
|
|
|
;-------------------------------------------------------------------------------
|
|
|
|
msgDSPFound db 'DSP found at port 2'
|
|
|
|
label port_second_digit_num dword at $
|
2012-03-08 12:33:38 +04:00
|
|
|
db '00h',13,10,'DSP version '
|
|
|
|
sb_DSP_version:
|
|
|
|
db '0.00 - SB'
|
|
|
|
sb_DSP_description:
|
|
|
|
db 32,32,32,32,13,10,0
|
2010-10-01 13:21:55 +04:00
|
|
|
;-------------------------------------------------------------------------------
|
|
|
|
end if
|
|
|
|
|
|
|
|
section '.data' data readable writable align 16
|
|
|
|
;all uninitialized data place here
|
|
|
|
|
|
|
|
;pTempBuf rd 1
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
callback rd 1
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
int_flip_flop rd 1
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
sb_master_vol rd 1
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
sb_DSP_version_int rd 1
|