Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 5057 → Rev 4961

/kernel/trunk/drivers/sb16/sb16.asm
1,25 → 1,42
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
format PE DLL native 0.05
entry START
format MS COFF
 
include 'CONFIG.INC'
 
section '.flat' code readable writable executable
include '..\..\struct.inc'
include '..\..\macros.inc'
include '..\..\proc32.inc'
include '..\..\peimport.inc'
;structs----------------------------------------------------------
struc IOCTL
{ .handle dd ?
.io_code dd ?
.input dd ?
.inp_size dd ?
.output dd ?
.out_size dd ?
}
 
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
 
include 'SB16.INC'
 
;-------------------------------------------------------------------------------
proc START c uses ebx esi edi, state:dword, cmdline:dword
proc START stdcall, state:dword
cmp [state], 1
jne .stop
.entry:
26,7 → 43,7
 
if DEBUG
mov esi, msgInit
invoke SysMsgBoardStr
call SysMsgBoardStr
end if
 
call detect ;returns DSP version or zero if
47,13 → 64,13
mov dword[esi], '16 '
.sb_say_about_found_dsp:
mov esi, msgDSPFound
invoke SysMsgBoardStr
call SysMsgBoardStr
end if
 
xor ebx, ebx
mov ecx, [sb_base_port]
lea edx, [ecx+0xF]
invoke ReservePortArea ;these ports must be mine !
call ReservePortArea ;these ports must be mine !
 
dec eax
jnz @f
60,19 → 77,15
 
if DEBUG
mov esi, msgErrRsrvPorts
invoke SysMsgBoardStr
call SysMsgBoardStr
end if
jmp .exit
 
@@:
invoke AllocDMA24, sb_buffer_size
test eax, eax
jz .exit
mov [SB16Buffer], eax
 
call sb_setup ;clock it, etc
 
invoke AttachIntHandler, sb_irq_num, sb_irq, 0
stdcall AttachIntHandler, sb_irq_num, sb_irq, 0
 
if DEBUG
test eax, eax
79,7 → 92,7
jnz @f
 
mov esi, msgErrAtchIRQ
invoke SysMsgBoardStr
call SysMsgBoardStr
 
; stdcall GetIntHandler, sb_irq_num
; call SysMsgBoardNum
87,9 → 100,9
jmp .stop
@@:
mov esi, msgSucAtchIRQ
invoke SysMsgBoardStr
call SysMsgBoardStr
end if
invoke RegService, my_service, service_proc
stdcall RegService, my_service, service_proc
ret
.stop:
call sb_reset
97,7 → 110,7
 
if DEBUG
mov esi, msgExit
invoke SysMsgBoardStr
call SysMsgBoardStr
end if
 
xor eax, eax
105,14 → 118,22
endp
;-------------------------------------------------------------------------------
 
proc service_proc stdcall uses ebx esi edi, ioctl:dword
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
 
align 4
proc service_proc stdcall, ioctl:dword
mov edi, [ioctl]
mov eax, [edi+IOCTL.io_code]
mov eax, [edi+io_code]
cmp eax, SRV_GETVERSION
jne @F
 
mov eax, [edi+IOCTL.output]
cmp [edi+IOCTL.out_size], 4
mov eax, [edi+output]
cmp [edi+out_size], 4
jne .fail
mov [eax], dword API_VERSION
xor eax, eax
122,7 → 143,7
jne @f
if DEBUG
mov esi, msgPlay
invoke SysMsgBoardStr
call SysMsgBoardStr
end if
call sb_stop ;to play smth new we must stop smth old
 
150,9 → 171,9
jne @f
if DEBUG
mov esi, msgCallback
invoke SysMsgBoardStr
call SysMsgBoardStr
end if
mov edi, [edi+IOCTL.input]
mov edi, [edi+input]
mov eax, [edi]
mov [callback], eax
if DEBUG
167,9 → 188,9
 
if DEBUG
mov esi, msgSetVol
invoke SysMsgBoardStr
call SysMsgBoardStr
end if
mov eax, [edi+IOCTL.input]
mov eax, [edi+input]
mov eax, [eax]
call sb_set_master_vol
xor eax, eax
179,9 → 200,9
jne @F
if DEBUG
mov esi, msgGetVol
invoke SysMsgBoardStr
call SysMsgBoardStr
end if
mov eax, [edi+IOCTL.output]
mov eax, [edi+output]
mov edx, [sb_master_vol]
mov [eax], edx
xor eax, eax
192,7 → 213,15
ret
endp
 
restore handle
restore io_code
restore input
restore inp_size
restore output
restore out_size
 
;-------------------------------------------------------------------------------
align 4
proc sb_irq
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
206,15 → 235,10
jns .fill_second_half
 
if sb_buffer_size eq small_buffer
mov eax, [SB16Buffer]
stdcall [callback], eax ;for 32k buffer
stdcall [callback], SB16Buffer0 ;for 32k buffer
else if sb_buffer_size eq full_buffer
mov eax, [SB16Buffer]
push eax
stdcall [callback], eax ;for 64k buffer
pop eax
add eax, 16384
stdcall [callback], eax ;for 64k buffer
stdcall [callback], SB16Buffer0 ;for 64k buffer
stdcall [callback], SB16Buffer1 ;for 64k buffer
end if
xor eax, eax
not eax
222,17 → 246,10
 
.fill_second_half:
if sb_buffer_size eq small_buffer
mov eax, [SB16Buffer]
add eax, 16384
stdcall [callback], eax ;for 32k buffer
stdcall [callback], SB16Buffer1 ;for 32k buffer
else if sb_buffer_size eq full_buffer
mov eax, [SB16Buffer]
add eax, 32768
push eax
stdcall [callback], eax ;for 64k buffer
pop eax
add eax, 16384
stdcall [callback], eax ;for 64k buffer
stdcall [callback], SB16Buffer2 ;for 64k buffer
stdcall [callback], SB16Buffer3 ;for 64k buffer
end if
xor eax, eax
not eax
320,12 → 337,13
shr ebx, 4
loop .1
dec esi
invoke SysMsgBoardStr
call SysMsgBoardStr
ret
endp
end if
;all initialized data place here
align 4
version dd (5 shl 16) or (API_VERSION and 0xFFFF)
 
sb_base_port:
dd 200h ;don't ask me why - see the code&docs
366,12 → 384,10
;-------------------------------------------------------------------------------
end if
 
align 4
data fixups
end data
section '.data' data readable writable align 16
;all uninitialized data place here
 
align 4
SB16Buffer rd 1
;pTempBuf rd 1
 
callback rd 1
 
/kernel/trunk/drivers/sb16/CONFIG.INC
12,6 → 12,18
;constants--------------------------------------------------------
API_VERSION equ 0 ;debug
 
OS_BASE equ 0x80000000
new_app_base equ 0x0
PROC_BASE equ (OS_BASE+0x080000)
SB16Buffer equ (OS_BASE+0x2A0000)
SB16_Status equ (OS_BASE+0x2B0000)
DMAPage equ ((SB16Buffer-OS_BASE) shr 16)
 
SB16Buffer0 equ SB16Buffer
SB16Buffer1 equ (SB16Buffer+16384)
SB16Buffer2 equ (SB16Buffer+(2*16384))
SB16Buffer3 equ (SB16Buffer+(3*16384))
 
sb_irq_num equ 5 ;default values for SB16, may be overrided by autodetect
sb_dma_num equ 5 ;default values for SB16, may be overrided by autodetect
 
/kernel/trunk/drivers/sb16/SB16.INC
17,7 → 17,7
.dma_setup_error:
if DEBUG
mov esi, msgErrDMAsetup
invoke SysMsgBoardStr
call SysMsgBoardStr
end if
mov dword[esp], START.stop
ret
33,20 → 33,16
lea eax, [ebx+0x58];auto-init mode for channel (ebx)
out 0xB, al;DMA channel 0-3 mode register
 
mov eax, [SB16Buffer]
invoke GetPhysAddr
mov ecx, eax
shr eax, 16
 
movzx edx, byte[ebx+dma_table];page register
mov al, DMAPage
out dx, al
 
lea edx, [ebx*2];DMA channel 0-3 base address
 
mov al, cl;LSB
mov al, 0;LSB is 0
out dx, al
 
mov al, ch;MSB
; mov al,0 ;MSB is 0 too
out dx, al
 
inc edx ;DMA channel 0-3 byte count
82,21 → 78,16
lea eax, [ebx+0x58];auto-init mode for channel (ebx+4)
out 0xD6, al;DMA channel 4-7 mode register
 
mov eax, [SB16Buffer]
invoke GetPhysAddr
mov ecx, eax
shr eax, 16
shr ecx, 1 ; 16-bit DMA takes offset in words
 
movzx edx, byte[ebx+dma_table+4];page register
mov al, DMAPage
out dx, al
 
lea edx, [ebx*4+0xC0];DMA channel 4-7 base address
 
mov al, cl;LSB;for 16bit DMA this contains
mov al, 0;LSB is 0 ;for 16bit DMA this contains
out dx, al;A1-A8 lines of address bus, A0 is zero
 
mov al, ch;MSB;for 16bit DMA this contains
; mov al,0 ;MSB is 0 too ;for 16bit DMA this contains
out dx, al;A9-A16 lines of address bus
 
inc edx