Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 187 → Rev 188

/kernel/trunk/drivers/infinity.asm
26,10 → 26,28
new_app_base equ 0x60400000; 0x01000000
PROC_BASE equ OS_BASE+0x0080000
 
public START
public STOP
public service_proc
public START
public IMPORTS
 
extrn AttachIntHandler
extrn SysMsgBoardStr
extrn PciApi
extrn PciRead32
extrn PciRead8
extrn PciWrite8
extrn AllocKernelSpace
extrn MapPage
extrn RegService
extrn KernelAlloc
extrn KernelFree
extrn GetPgAddr
extrn GetCurrentTask
extrn GetService
extrn ServiceHandler
extrn FpuSave
extrn FpuRestore
 
SND_CREATE_BUFF equ 2
SND_PLAY equ 3
SND_STOP equ 4
53,15 → 71,15
IOCTL IOCTL
end virtual
 
section '.flat' align 16
section '.flat' code readable align 16
 
START:
stdcall [GetService], szSound
stdcall GetService, szSound
test eax, eax
jz .fail
mov [hSound], eax
 
stdcall [KernelAlloc], 16*512
stdcall KernelAlloc, 16*512
test eax, eax
jz .out_of_mem
mov [mix_buff], eax
75,17 → 93,15
mov edi, stream
mov ecx, 4*STREAM_SIZE
rep stosd
mov [stream_count],0
 
stdcall set_handler, [hSound], new_mix
 
stdcall [RegService], szInfinity, service_proc
mov [stream_count],0
 
stdcall RegService, szInfinity, service_proc
ret
.fail:
if DEBUG
mov esi, msgFail
call [SysMsgBoardStr]
call SysMsgBoardStr
end if
xor eax, eax
ret
93,9 → 109,10
.out_of_mem:
if DEBUG
mov esi, msgMem
call [SysMsgBoardStr]
call SysMsgBoardStr
end if
xor eax, eax
STOP:
ret
 
handle equ IOCTL.handle
166,7 → 183,6
TASK_COUNT equ 0x0003004
CURRENT_TASK equ 0x0003000
 
 
align 8
proc CreateBuffer stdcall, format:dword
locals
186,7 → 202,7
mov [edi+STREAM.magic], 'WAVE'
mov [edi+STREAM.size], STREAM_SIZE
 
stdcall [KernelAlloc], 180*1024
stdcall KernelAlloc, 180*1024
 
mov edi, [str]
mov [edi+STREAM.base], eax
279,8 → 295,6
pop ebx
ret
 
 
 
align 4
proc DestroyBuffer stdcall, str:dword
 
292,7 → 306,7
cmp [esi+STREAM.size], STREAM_SIZE
jne .fail
 
stdcall [KernelFree], [esi+STREAM.base]
stdcall KernelFree, [esi+STREAM.base]
 
mov eax, [str]
call free_stream
625,7 → 639,7
mov [out_size], 0
 
lea eax, [handler]
stdcall [ServiceHandler], eax
stdcall ServiceHandler, eax
ret
endp
 
652,7 → 666,7
mov [out_size], ebx
 
lea eax, [handle]
stdcall [ServiceHandler], eax
stdcall ServiceHandler, eax
ret
endp
 
659,10 → 673,6
include 'mixer.asm'
 
align 16
play_list dd 16 dup(0)
stream_list dd 17 dup(0)
 
align 16
resampler_params:
;r_size r_end r_dt resampler_func
dd 0,0,0,0 ; 0 PCM_ALL
720,69 → 730,12
dd 2048, 0x02000000, 5462, resample_28 ;35 PCM_2_8_8
dd 1024, 0x02000000, 5462, resample_18 ;36 PCM_1_8_8
 
 
play_count dd 0
 
stream_count dd 0
 
align 8
hSound dd 0
 
m7 dw 0x8000,0x8000,0x8000,0x8000
mm80 dq 0x8080808080808080
mm_mask dq 0xFF00FF00FF00FF00
 
mix_input dd 16 dup(0)
 
align 16
;fpu_state db 512 dup(0)
 
align 16
stream db STREAM_SIZE*16 dup(0)
stream_map dd 0xFFFF ; 16
mix_buff dd 0
mix_buff_map dd 0
 
align 16
IMPORTS:
 
AttachIntHandler dd szAttachIntHandler
SysMsgBoardStr dd szSysMsgBoardStr
PciApi dd szPciApi
PciRead32 dd szPciRead32
PciRead8 dd szPciRead8
AllocKernelSpace dd szAllocKernelSpace
MapPage dd szMapPage
KernelAlloc dd szKernelAlloc
KernelFree dd szKernelFree
GetPgAddr dd szGetPgAddr
RegService dd szRegService
GetCurrentTask dd szGetCurrentTask
GetService dd szGetService
ServiceHandler dd szServiceHandler
FpuSave dd szFpuSave
FpuRestore dd szFpuRestore
dd 0
 
szKernel db 'KERNEL', 0
szAttachIntHandler db 'AttachIntHandler',0
szSysMsgBoardStr db 'SysMsgBoardStr', 0
szPciApi db 'PciApi', 0
szPciRead32 db 'PciRead32', 0
szPciRead8 db 'PciRead8', 0
szAllocKernelSpace db 'AllocKernelSpace',0
szMapPage db 'MapPage',0
szRegService db 'RegService',0
szKernelAlloc db 'KernelAlloc',0
szGetPgAddr db 'GetPgAddr',0
szGetCurrentTask db 'GetCurrentTask ',0
szGetService db 'GetService',0
szServiceHandler db 'ServiceHandler',0
szKernelFree db 'KernelFree',0
szFpuSave db 'FpuSave',0
szFpuRestore db 'FpuRestore',0
 
 
szInfinity db 'INFINITY',0
szSound db 'SOUND',0
 
793,3 → 746,18
msgUser db 'User callback',13,10,0
msgMem db 'Not enough memory',13,10,0
end if
 
section '.data' data readable writable align 16
 
stream rb STREAM_SIZE*16
 
play_list rd 16
mix_input rd 16
 
stream_list rd 17
play_count rd 1
stream_count rd 1
hSound rd 1
mix_buff rd 1
mix_buff_map rd 1
 
/kernel/trunk/drivers/mixer.asm
31,7 → 31,7
je .exit
; mov eax, fpu_state
; fnsave [eax]
call [FpuSave]
call FpuSave
emms
mov [main_count], 32;
 
98,7 → 98,7
jnz .l00
 
call update_stream
call [FpuRestore]
call FpuRestore
ret
.exit:
mov edi, [output]
/kernel/trunk/drivers/sis.asm
95,125 → 95,125
DEV_GET_INFO equ 8
 
struc AC_CNTRL ;AC controller base class
{ .bus dd 0
.devfn dd 0
{ .bus dd ?
.devfn dd ?
 
.vendor dd 0
.dev_id dd 0
.pci_cmd dd 0
.pci_stat dd 0
.vendor dd ?
.dev_id dd ?
.pci_cmd dd ?
.pci_stat dd ?
 
.codec_io_base dd 0
.codec_mem_base dd 0
.codec_io_base dd ?
.codec_mem_base dd ?
 
.ctrl_io_base dd 0
.ctrl_mem_base dd 0
.cfg_reg dd 0
.int_line dd 0
.ctrl_io_base dd ?
.ctrl_mem_base dd ?
.cfg_reg dd ?
.int_line dd ?
 
.vendor_ids dd 0 ;vendor id string
.ctrl_ids dd 0 ;hub id string
.vendor_ids dd ? ;vendor id string
.ctrl_ids dd ? ;hub id string
 
.buffer dd 0
.buffer dd ?
 
.notify_pos dd 0
.notify_task dd 0
.notify_pos dd ?
.notify_task dd ?
 
.lvi_reg dd 0
.ctrl_setup dd 0
.user_callback dd 0
.codec_read16 dd 0
.codec_write16 dd 0
.lvi_reg dd ?
.ctrl_setup dd ?
.user_callback dd ?
.codec_read16 dd ?
.codec_write16 dd ?
 
.ctrl_read8 dd 0
.ctrl_read16 dd 0
.ctrl_read32 dd 0
.ctrl_read8 dd ?
.ctrl_read16 dd ?
.ctrl_read32 dd ?
 
.ctrl_write8 dd 0
.ctrl_write16 dd 0
.ctrl_write32 dd 0
.ctrl_write8 dd ?
.ctrl_write16 dd ?
.ctrl_write32 dd ?
}
 
struc CODEC ;Audio Chip base class
{
.chip_id dd 0
.flags dd 0
.status dd 0
.chip_id dd ?
.flags dd ?
.status dd ?
 
.ac_vendor_ids dd 0 ;ac vendor id string
.chip_ids dd 0 ;chip model string
.ac_vendor_ids dd ? ;ac vendor id string
.chip_ids dd ? ;chip model string
 
.shadow_flag dd 0
dd 0
.shadow_flag dd ?
dd ?
 
.regs dw 0 ; codec registers
.reg_master_vol dw 0 ;0x02
.reg_aux_out_vol dw 0 ;0x04
.reg_mone_vol dw 0 ;0x06
.reg_master_tone dw 0 ;0x08
.reg_beep_vol dw 0 ;0x0A
.reg_phone_vol dw 0 ;0x0C
.reg_mic_vol dw 0 ;0x0E
.reg_line_in_vol dw 0 ;0x10
.reg_cd_vol dw 0 ;0x12
.reg_video_vol dw 0 ;0x14
.reg_aux_in_vol dw 0 ;0x16
.reg_pcm_out_vol dw 0 ;0x18
.reg_rec_select dw 0 ;0x1A
.reg_rec_gain dw 0 ;0x1C
.reg_rec_gain_mic dw 0 ;0x1E
.reg_gen dw 0 ;0x20
.reg_3d_ctrl dw 0 ;0X22
.reg_page dw 0 ;0X24
.reg_powerdown dw 0 ;0x26
.reg_ext_audio dw 0 ;0x28
.reg_ext_st dw 0 ;0x2a
.reg_pcm_front_rate dw 0 ;0x2c
.reg_pcm_surr_rate dw 0 ;0x2e
.reg_lfe_rate dw 0 ;0x30
.reg_pcm_in_rate dw 0 ;0x32
dw 0 ;0x34
.reg_cent_lfe_vol dw 0 ;0x36
.reg_surr_vol dw 0 ;0x38
.reg_spdif_ctrl dw 0 ;0x3A
dw 0 ;0x3C
dw 0 ;0x3E
dw 0 ;0x40
dw 0 ;0x42
dw 0 ;0x44
dw 0 ;0x46
dw 0 ;0x48
dw 0 ;0x4A
dw 0 ;0x4C
dw 0 ;0x4E
dw 0 ;0x50
dw 0 ;0x52
dw 0 ;0x54
dw 0 ;0x56
dw 0 ;0x58
dw 0 ;0x5A
dw 0 ;0x5C
dw 0 ;0x5E
.reg_page_0 dw 0 ;0x60
.reg_page_1 dw 0 ;0x62
.reg_page_2 dw 0 ;0x64
.reg_page_3 dw 0 ;0x66
.reg_page_4 dw 0 ;0x68
.reg_page_5 dw 0 ;0x6A
.reg_page_6 dw 0 ;0x6C
.reg_page_7 dw 0 ;0x6E
dw 0 ;0x70
dw 0 ;0x72
dw 0 ;0x74
dw 0 ;0x76
dw 0 ;0x78
dw 0 ;0x7A
.reg_vendor_id_1 dw 0 ;0x7C
.reg_vendor_id_2 dw 0 ;0x7E
.regs dw ? ; codec registers
.reg_master_vol dw ? ;0x02
.reg_aux_out_vol dw ? ;0x04
.reg_mone_vol dw ? ;0x06
.reg_master_tone dw ? ;0x08
.reg_beep_vol dw ? ;0x0A
.reg_phone_vol dw ? ;0x0C
.reg_mic_vol dw ? ;0x0E
.reg_line_in_vol dw ? ;0x10
.reg_cd_vol dw ? ;0x12
.reg_video_vol dw ? ;0x14
.reg_aux_in_vol dw ? ;0x16
.reg_pcm_out_vol dw ? ;0x18
.reg_rec_select dw ? ;0x1A
.reg_rec_gain dw ? ;0x1C
.reg_rec_gain_mic dw ? ;0x1E
.reg_gen dw ? ;0x20
.reg_3d_ctrl dw ? ;0X22
.reg_page dw ? ;0X24
.reg_powerdown dw ? ;0x26
.reg_ext_audio dw ? ;0x28
.reg_ext_st dw ? ;0x2a
.reg_pcm_front_rate dw ? ;0x2c
.reg_pcm_surr_rate dw ? ;0x2e
.reg_lfe_rate dw ? ;0x30
.reg_pcm_in_rate dw ? ;0x32
dw ? ;0x34
.reg_cent_lfe_vol dw ? ;0x36
.reg_surr_vol dw ? ;0x38
.reg_spdif_ctrl dw ? ;0x3A
dw ? ;0x3C
dw ? ;0x3E
dw ? ;0x40
dw ? ;0x42
dw ? ;0x44
dw ? ;0x46
dw ? ;0x48
dw ? ;0x4A
dw ? ;0x4C
dw ? ;0x4E
dw ? ;0x50
dw ? ;0x52
dw ? ;0x54
dw ? ;0x56
dw ? ;0x58
dw ? ;0x5A
dw ? ;0x5C
dw ? ;0x5E
.reg_page_0 dw ? ;0x60
.reg_page_1 dw ? ;0x62
.reg_page_2 dw ? ;0x64
.reg_page_3 dw ? ;0x66
.reg_page_4 dw ? ;0x68
.reg_page_5 dw ? ;0x6A
.reg_page_6 dw ? ;0x6C
.reg_page_7 dw ? ;0x6E
dw ? ;0x70
dw ? ;0x72
dw ? ;0x74
dw ? ;0x76
dw ? ;0x78
dw ? ;0x7A
.reg_vendor_id_1 dw ? ;0x7C
.reg_vendor_id_2 dw ? ;0x7E
 
 
.reset dd 0 ;virual
.set_master_vol dd 0
.reset dd ? ;virual
.set_master_vol dd ?
}
 
struc CTRL_INFO
247,17 → 247,29
new_app_base equ 0x60400000; 0x01000000
PROC_BASE equ OS_BASE+0x0080000
 
 
public START
public STOP
public service_proc
public START
public IMPORTS
 
section '.flat' align 16
extrn AttachIntHandler
extrn SysMsgBoardStr
extrn PciApi
extrn PciRead32
extrn PciRead8
extrn PciWrite8
extrn AllocKernelSpace
extrn MapPage
extrn RegService
extrn KernelAlloc
extrn GetPgAddr
extrn GetCurrentTask
 
section '.flat' code readable align 16
 
START:
if DEBUG
mov esi, msgInit
call [SysMsgBoardStr]
call SysMsgBoardStr
end if
 
call detect_controller
266,9 → 278,9
 
if DEBUG
mov esi,[ctrl.vendor_ids]
call [SysMsgBoardStr]
call SysMsgBoardStr
mov esi, [ctrl.ctrl_ids]
call [SysMsgBoardStr]
call SysMsgBoardStr
end if
 
call init_controller
277,7 → 289,7
 
if DEBUG
mov esi, msgInitCodec
call [SysMsgBoardStr]
call SysMsgBoardStr
end if
 
call init_codec
286,10 → 298,10
 
if DEBUG
mov esi, [codec.ac_vendor_ids]
call [SysMsgBoardStr]
call SysMsgBoardStr
 
mov esi, [codec.chip_ids]
call [SysMsgBoardStr]
call SysMsgBoardStr
end if
 
call reset_controller
296,16 → 308,16
call setup_codec
 
mov esi, msgPrimBuff
call [SysMsgBoardStr]
call SysMsgBoardStr
 
call create_primary_buff
 
stdcall [AttachIntHandler], [ctrl.int_line], ac97_irq
stdcall AttachIntHandler, [ctrl.int_line], ac97_irq
 
stdcall [RegService], sz_sound_srv, service_proc
stdcall RegService, sz_sound_srv, service_proc
 
mov esi, msgOk
call [SysMsgBoardStr]
call SysMsgBoardStr
 
ret
 
312,9 → 324,9
.fail:
if DEBUG
mov esi, msgFail
call [SysMsgBoardStr]
call SysMsgBoardStr
end if
 
STOP:
xor eax, eax
ret
 
334,7 → 346,7
jne @F
if DEBUG
mov esi, msgPlay
call [SysMsgBoardStr]
call SysMsgBoardStr
end if
call play
ret
343,7 → 355,7
jne @F
if DEBUG
mov esi, msgStop
call [SysMsgBoardStr]
call SysMsgBoardStr
end if
call stop
ret
392,7 → 404,7
 
; if DEBUG
; mov esi, msgIRQ
; call [SysMsgBoardStr]
; call SysMsgBoardStr
; end if
 
mov edx, PCM_OUT_CR_REG
444,7 → 456,7
align 4
proc create_primary_buff
 
stdcall [KernelAlloc], 0x10000
stdcall KernelAlloc, 0x10000
mov [ctrl.buffer], eax
 
mov edi, eax
452,7 → 464,7
xor eax, eax
rep stosd
 
stdcall [GetPgAddr], [ctrl.buffer]
stdcall GetPgAddr, [ctrl.buffer]
 
mov ebx, 0xC0004000
mov ecx, 4
504,7 → 516,7
loop @B
 
mov ecx, pcmout_bdl
stdcall [GetPgAddr], ecx
stdcall GetPgAddr, ecx
and ecx, 0xFFF
add eax, ecx
 
537,7 → 549,7
xor eax, eax
mov [bus], eax
inc eax
call [PciApi]
call PciApi
cmp eax, -1
je .err
 
546,7 → 558,7
.next_bus:
and [devfn], 0
.next_dev:
stdcall [PciRead32], [bus], [devfn], dword 0
stdcall PciRead32, [bus], [devfn], dword 0
test eax, eax
jz .next
cmp eax, -1
602,7 → 614,7
align 4
proc init_controller
 
stdcall [PciRead32], [ctrl.bus], [ctrl.devfn], dword 4
stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 4
mov ebx, eax
and eax, 0xFFFF
mov [ctrl.pci_cmd], eax
609,25 → 621,25
shr ebx, 16
mov [ctrl.pci_stat], ebx
 
stdcall [PciRead32], [ctrl.bus], [ctrl.devfn], dword 0x10
stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x10
and eax,0xFFFE
mov [ctrl.codec_io_base], eax
 
stdcall [PciRead32], [ctrl.bus], [ctrl.devfn], dword 0x14
stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x14
and eax, 0xFFC0
mov [ctrl.ctrl_io_base], eax
 
stdcall [PciRead32], [ctrl.bus], [ctrl.devfn], dword 0x18
stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x18
mov [ctrl.codec_mem_base], eax
 
stdcall [PciRead32], [ctrl.bus], [ctrl.devfn], dword 0x1C
stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x1C
mov [ctrl.ctrl_mem_base], eax
 
stdcall [PciRead32], [ctrl.bus], [ctrl.devfn], dword 0x3C
stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x3C
and eax, 0xFF
mov [ctrl.int_line], eax
 
stdcall [PciRead8], [ctrl.bus], [ctrl.devfn], dword 0x41
stdcall PciRead8, [ctrl.bus], [ctrl.devfn], dword 0x41
and eax, 0xFF
mov [ctrl.cfg_reg], eax
 
735,7 → 747,7
 
if DEBUG
mov esi, msgCFail
call [SysMsgBoardStr]
call SysMsgBoardStr
end if
xor eax, eax ; timeout error
ret
757,7 → 769,7
 
if DEBUG
mov esi, msgWarm
call [SysMsgBoardStr]
call SysMsgBoardStr
end if
 
mov [counter], 10 ; total 10*100 ms = 1s
774,7 → 786,7
 
if DEBUG
mov esi, msgWRFail
call [SysMsgBoardStr]
call SysMsgBoardStr
end if
 
stc
803,7 → 815,7
 
if DEBUG
mov esi, msgCold
call [SysMsgBoardStr]
call SysMsgBoardStr
end if
 
mov eax, 1000000 ; wait 1 s
827,7 → 839,7
 
if DEBUG
mov esi, msgCRFail
call [SysMsgBoardStr]
call SysMsgBoardStr
end if
stc
ret
1105,58 → 1117,13
 
include "codec.inc"
 
 
align 16
pcmout_bdl dq 32 dup(0)
buff_list dd 32 dup(0)
 
align 16
ctrl AC_CNTRL
 
align 16
codec CODEC
 
civ_val dd 0
 
align 16
align 4
devices dd (CTRL_SIS shl 16)+VID_SIS,msg_AC, set_SIS
dd 0
 
align 16
imp_table:
IMPORTS:
 
AttachIntHandler dd szAttachIntHandler
SysMsgBoardStr dd szSysMsgBoardStr
PciApi dd szPciApi
PciRead32 dd szPciRead32
PciRead8 dd szPciRead8
PciWrite8 dd szPciWrite8
AllocKernelSpace dd szAllocKernelSpace
MapPage dd szMapPage
KernelAlloc dd szKernelAlloc
GetPgAddr dd szGetPgAddr
RegService dd szRegService
GetCurrentTask dd szGetCurrentTask
dd 0
 
msg_AC db '7012 AC97 controller',13,10, 0
msg_SIS db 'Silicon Integrated Systems',13,10, 0
 
szKernel db 'KERNEL', 0
szAttachIntHandler db 'AttachIntHandler',0
szSysMsgBoardStr db 'SysMsgBoardStr', 0
szPciApi db 'PciApi', 0
szPciRead32 db 'PciRead32', 0
szPciRead8 db 'PciRead8', 0
szPciWrite8 db 'PciWrite8',0
szAllocKernelSpace db 'AllocKernelSpace',0
szMapPage db 'MapPage',0
szRegService db 'RegService',0
szKernelAlloc db 'KernelAlloc',0
szGetPgAddr db 'GetPgAddr',0
szGetCurrentTask db 'GetCurrentTask ',0
 
sz_sound_srv db 'SOUND',0
 
msgInit db 'detect hardware...',13,10,0
1175,3 → 1142,14
msgWRFail db 'warm reset failed',13,10,0
msgCRFail db 'cold reset failed',13,10,0
msgCFail db 'codec not ready',13,10,0
 
section '.data' data readable writable align 16
 
pcmout_bdl rq 32
buff_list rd 32
 
codec CODEC
ctrl AC_CNTRL
 
lpc_bus rd 1
civ_val rd 1
/kernel/trunk/drivers/unisound.asm
116,125 → 116,125
DEV_GET_INFO equ 8
 
struc AC_CNTRL ;AC controller base class
{ .bus dd 0
.devfn dd 0
{ .bus dd ?
.devfn dd ?
 
.vendor dd 0
.dev_id dd 0
.pci_cmd dd 0
.pci_stat dd 0
.vendor dd ?
.dev_id dd ?
.pci_cmd dd ?
.pci_stat dd ?
 
.codec_io_base dd 0
.codec_mem_base dd 0
.codec_io_base dd ?
.codec_mem_base dd ?
 
.ctrl_io_base dd 0
.ctrl_mem_base dd 0
.cfg_reg dd 0
.int_line dd 0
.ctrl_io_base dd ?
.ctrl_mem_base dd ?
.cfg_reg dd ?
.int_line dd ?
 
.vendor_ids dd 0 ;vendor id string
.ctrl_ids dd 0 ;hub id string
.vendor_ids dd ? ;vendor id string
.ctrl_ids dd ? ;hub id string
 
.buffer dd 0
.buffer dd ?
 
.notify_pos dd 0
.notify_task dd 0
.notify_pos dd ?
.notify_task dd ?
 
.lvi_reg dd 0
.ctrl_setup dd 0
.user_callback dd 0
.codec_read16 dd 0
.codec_write16 dd 0
.lvi_reg dd ?
.ctrl_setup dd ?
.user_callback dd ?
.codec_read16 dd ?
.codec_write16 dd ?
 
.ctrl_read8 dd 0
.ctrl_read16 dd 0
.ctrl_read32 dd 0
.ctrl_read8 dd ?
.ctrl_read16 dd ?
.ctrl_read32 dd ?
 
.ctrl_write8 dd 0
.ctrl_write16 dd 0
.ctrl_write32 dd 0
.ctrl_write8 dd ?
.ctrl_write16 dd ?
.ctrl_write32 dd ?
}
 
struc CODEC ;Audio Chip base class
{
.chip_id dd 0
.flags dd 0
.status dd 0
.chip_id dd ?
.flags dd ?
.status dd ?
 
.ac_vendor_ids dd 0 ;ac vendor id string
.chip_ids dd 0 ;chip model string
.ac_vendor_ids dd ? ;ac vendor id string
.chip_ids dd ? ;chip model string
 
.shadow_flag dd 0
dd 0
.shadow_flag dd ?
dd ?
 
.regs dw 0 ; codec registers
.reg_master_vol dw 0 ;0x02
.reg_aux_out_vol dw 0 ;0x04
.reg_mone_vol dw 0 ;0x06
.reg_master_tone dw 0 ;0x08
.reg_beep_vol dw 0 ;0x0A
.reg_phone_vol dw 0 ;0x0C
.reg_mic_vol dw 0 ;0x0E
.reg_line_in_vol dw 0 ;0x10
.reg_cd_vol dw 0 ;0x12
.reg_video_vol dw 0 ;0x14
.reg_aux_in_vol dw 0 ;0x16
.reg_pcm_out_vol dw 0 ;0x18
.reg_rec_select dw 0 ;0x1A
.reg_rec_gain dw 0 ;0x1C
.reg_rec_gain_mic dw 0 ;0x1E
.reg_gen dw 0 ;0x20
.reg_3d_ctrl dw 0 ;0X22
.reg_page dw 0 ;0X24
.reg_powerdown dw 0 ;0x26
.reg_ext_audio dw 0 ;0x28
.reg_ext_st dw 0 ;0x2a
.reg_pcm_front_rate dw 0 ;0x2c
.reg_pcm_surr_rate dw 0 ;0x2e
.reg_lfe_rate dw 0 ;0x30
.reg_pcm_in_rate dw 0 ;0x32
dw 0 ;0x34
.reg_cent_lfe_vol dw 0 ;0x36
.reg_surr_vol dw 0 ;0x38
.reg_spdif_ctrl dw 0 ;0x3A
dw 0 ;0x3C
dw 0 ;0x3E
dw 0 ;0x40
dw 0 ;0x42
dw 0 ;0x44
dw 0 ;0x46
dw 0 ;0x48
dw 0 ;0x4A
dw 0 ;0x4C
dw 0 ;0x4E
dw 0 ;0x50
dw 0 ;0x52
dw 0 ;0x54
dw 0 ;0x56
dw 0 ;0x58
dw 0 ;0x5A
dw 0 ;0x5C
dw 0 ;0x5E
.reg_page_0 dw 0 ;0x60
.reg_page_1 dw 0 ;0x62
.reg_page_2 dw 0 ;0x64
.reg_page_3 dw 0 ;0x66
.reg_page_4 dw 0 ;0x68
.reg_page_5 dw 0 ;0x6A
.reg_page_6 dw 0 ;0x6C
.reg_page_7 dw 0 ;0x6E
dw 0 ;0x70
dw 0 ;0x72
dw 0 ;0x74
dw 0 ;0x76
dw 0 ;0x78
dw 0 ;0x7A
.reg_vendor_id_1 dw 0 ;0x7C
.reg_vendor_id_2 dw 0 ;0x7E
.regs dw ? ; codec registers
.reg_master_vol dw ? ;0x02
.reg_aux_out_vol dw ? ;0x04
.reg_mone_vol dw ? ;0x06
.reg_master_tone dw ? ;0x08
.reg_beep_vol dw ? ;0x0A
.reg_phone_vol dw ? ;0x0C
.reg_mic_vol dw ? ;0x0E
.reg_line_in_vol dw ? ;0x10
.reg_cd_vol dw ? ;0x12
.reg_video_vol dw ? ;0x14
.reg_aux_in_vol dw ? ;0x16
.reg_pcm_out_vol dw ? ;0x18
.reg_rec_select dw ? ;0x1A
.reg_rec_gain dw ? ;0x1C
.reg_rec_gain_mic dw ? ;0x1E
.reg_gen dw ? ;0x20
.reg_3d_ctrl dw ? ;0X22
.reg_page dw ? ;0X24
.reg_powerdown dw ? ;0x26
.reg_ext_audio dw ? ;0x28
.reg_ext_st dw ? ;0x2a
.reg_pcm_front_rate dw ? ;0x2c
.reg_pcm_surr_rate dw ? ;0x2e
.reg_lfe_rate dw ? ;0x30
.reg_pcm_in_rate dw ? ;0x32
dw ? ;0x34
.reg_cent_lfe_vol dw ? ;0x36
.reg_surr_vol dw ? ;0x38
.reg_spdif_ctrl dw ? ;0x3A
dw ? ;0x3C
dw ? ;0x3E
dw ? ;0x40
dw ? ;0x42
dw ? ;0x44
dw ? ;0x46
dw ? ;0x48
dw ? ;0x4A
dw ? ;0x4C
dw ? ;0x4E
dw ? ;0x50
dw ? ;0x52
dw ? ;0x54
dw ? ;0x56
dw ? ;0x58
dw ? ;0x5A
dw ? ;0x5C
dw ? ;0x5E
.reg_page_0 dw ? ;0x60
.reg_page_1 dw ? ;0x62
.reg_page_2 dw ? ;0x64
.reg_page_3 dw ? ;0x66
.reg_page_4 dw ? ;0x68
.reg_page_5 dw ? ;0x6A
.reg_page_6 dw ? ;0x6C
.reg_page_7 dw ? ;0x6E
dw ? ;0x70
dw ? ;0x72
dw ? ;0x74
dw ? ;0x76
dw ? ;0x78
dw ? ;0x7A
.reg_vendor_id_1 dw ? ;0x7C
.reg_vendor_id_2 dw ? ;0x7E
 
 
.reset dd 0 ;virual
.set_master_vol dd 0
.reset dd ? ;virual
.set_master_vol dd ?
}
 
struc CTRL_INFO
268,16 → 268,29
new_app_base equ 0x60400000; 0x01000000
PROC_BASE equ OS_BASE+0x0080000
 
public START
public STOP
public service_proc
public START
public IMPORTS
 
section '.flat' align 16
extrn AttachIntHandler
extrn SysMsgBoardStr
extrn PciApi
extrn PciRead32
extrn PciRead8
extrn PciWrite8
extrn AllocKernelSpace
extrn MapPage
extrn RegService
extrn KernelAlloc
extrn GetPgAddr
extrn GetCurrentTask
 
section '.flat' code readable align 16
 
START:
if DEBUG
mov esi, msgInit
call [SysMsgBoardStr]
call SysMsgBoardStr
end if
 
call detect_controller
286,9 → 299,9
 
if DEBUG
mov esi,[ctrl.vendor_ids]
call [SysMsgBoardStr]
call SysMsgBoardStr
mov esi, [ctrl.ctrl_ids]
call [SysMsgBoardStr]
call SysMsgBoardStr
 
end if
 
298,7 → 311,7
 
if DEBUG
mov esi, msgInitCodec
call [SysMsgBoardStr]
call SysMsgBoardStr
end if
 
call init_codec
307,10 → 320,10
 
if DEBUG
mov esi, [codec.ac_vendor_ids]
call [SysMsgBoardStr]
call SysMsgBoardStr
 
mov esi, [codec.chip_ids]
call [SysMsgBoardStr]
call SysMsgBoardStr
end if
 
call reset_controller
317,7 → 330,7
call setup_codec
 
mov esi, msgPrimBuff
call [SysMsgBoardStr]
call SysMsgBoardStr
 
call create_primary_buff
 
341,22 → 354,16
bt eax, ebx
jnc .fail
 
stdcall [AttachIntHandler], ebx, ac97_irq
 
stdcall [RegService], sz_sound_srv, service_proc
 
mov esi, msgOk
call [SysMsgBoardStr]
 
stdcall AttachIntHandler, ebx, ac97_irq
stdcall RegService, sz_sound_srv, service_proc
ret
 
.fail:
if DEBUG
mov esi, msgFail
call [SysMsgBoardStr]
call SysMsgBoardStr
end if
 
xor eax, eax
STOP:
ret
 
handle equ IOCTL.handle
375,7 → 382,7
jne @F
if DEBUG
mov esi, msgPlay
call [SysMsgBoardStr]
call SysMsgBoardStr
end if
call play
ret
384,7 → 391,7
jne @F
if DEBUG
mov esi, msgStop
call [SysMsgBoardStr]
call SysMsgBoardStr
end if
call stop
ret
440,7 → 447,7
bts ax, IRQ_LINE
out dx, aX
 
stdcall [PciWrite8], dword 0, dword 0xF8, dword 0x61, dword IRQ_LINE
stdcall PciWrite8, dword 0, dword 0xF8, dword 0x61, dword IRQ_LINE
mov [ctrl.int_line], IRQ_LINE
 
.exit:
452,7 → 459,7
 
; if DEBUG
; mov esi, msgIRQ
; call [SysMsgBoardStr]
; call SysMsgBoardStr
; end if
 
mov edx, PCM_OUT_CR_REG
504,7 → 511,7
align 4
proc create_primary_buff
 
stdcall [KernelAlloc], 0x10000
stdcall KernelAlloc, 0x10000
mov [ctrl.buffer], eax
 
mov edi, eax
513,7 → 520,7
cld
rep stosd
 
stdcall [GetPgAddr], [ctrl.buffer]
stdcall GetPgAddr, [ctrl.buffer]
 
mov ebx, 0xC0002000
mov ecx, 4
565,7 → 572,7
loop @B
 
mov ecx, pcmout_bdl
stdcall [GetPgAddr], ecx
stdcall GetPgAddr, ecx
and ecx, 0xFFF
add eax, ecx
 
591,7 → 598,7
xor eax, eax
mov [bus], eax
inc eax
call [PciApi]
call PciApi
cmp eax, -1
je .err
 
600,7 → 607,7
.next_bus:
and [devfn], 0
.next_dev:
stdcall [PciRead32], [bus], [devfn], dword 0
stdcall PciRead32, [bus], [devfn], dword 0
test eax, eax
jz .next
cmp eax, -1
677,7 → 684,7
 
mov [last_bus], eax
.next_bus:
stdcall [PciRead32], [bus], dword 0xF8, dword 0
stdcall PciRead32, [bus], dword 0xF8, dword 0
test eax, eax
jz .next
cmp eax, -1
703,7 → 710,7
align 4
proc init_controller
 
stdcall [PciRead32], [ctrl.bus], [ctrl.devfn], dword 4
stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 4
mov ebx, eax
and eax, 0xFFFF
mov [ctrl.pci_cmd], eax
710,25 → 717,25
shr ebx, 16
mov [ctrl.pci_stat], ebx
 
stdcall [PciRead32], [ctrl.bus], [ctrl.devfn], dword 0x10
stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x10
and eax,0xFFFE
mov [ctrl.codec_io_base], eax
 
stdcall [PciRead32], [ctrl.bus], [ctrl.devfn], dword 0x14
stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x14
and eax, 0xFFC0
mov [ctrl.ctrl_io_base], eax
 
stdcall [PciRead32], [ctrl.bus], [ctrl.devfn], dword 0x18
stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x18
mov [ctrl.codec_mem_base], eax
 
stdcall [PciRead32], [ctrl.bus], [ctrl.devfn], dword 0x1C
stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x1C
mov [ctrl.ctrl_mem_base], eax
 
stdcall [PciRead32], [ctrl.bus], [ctrl.devfn], dword 0x3C
stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x3C
and eax, 0xFF
mov [ctrl.int_line], eax
 
stdcall [PciRead8], [ctrl.bus], [ctrl.devfn], dword 0x41
stdcall PciRead8, [ctrl.bus], [ctrl.devfn], dword 0x41
and eax, 0xFF
mov [ctrl.cfg_reg], eax
 
758,12 → 765,12
 
align 4
proc set_ICH4
stdcall [AllocKernelSpace], dword 0x2000
stdcall AllocKernelSpace, dword 0x2000
mov edi, eax
stdcall [MapPage], edi,[ctrl.codec_mem_base],PG_SW+PG_NOCACHE
stdcall MapPage, edi,[ctrl.codec_mem_base],PG_SW+PG_NOCACHE
mov [ctrl.codec_mem_base], edi
add edi, 0x1000
stdcall [MapPage], edi, [ctrl.ctrl_mem_base],PG_SW+PG_NOCACHE
stdcall MapPage, edi, [ctrl.ctrl_mem_base],PG_SW+PG_NOCACHE
mov [ctrl.ctrl_mem_base], edi
 
mov [ctrl.codec_read16], codec_mem_r16 ;virtual
861,7 → 868,7
 
if DEBUG
mov esi, msgCFail
call [SysMsgBoardStr]
call SysMsgBoardStr
end if
xor eax, eax ; timeout error
ret
868,7 → 875,7
.ok:
if DEBUG
mov esi, msgResetOk
call [SysMsgBoardStr]
call SysMsgBoardStr
end if
 
xor eax, eax
888,7 → 895,7
 
if DEBUG
mov esi, msgWarm
call [SysMsgBoardStr]
call SysMsgBoardStr
end if
 
mov [counter], 10 ; total 10*100 ms = 1s
905,7 → 912,7
 
if DEBUG
mov esi, msgWRFail
call [SysMsgBoardStr]
call SysMsgBoardStr
end if
 
stc
934,7 → 941,7
 
if DEBUG
mov esi, msgCold
call [SysMsgBoardStr]
call SysMsgBoardStr
end if
 
mov eax, 1000000 ; wait 1 s
958,7 → 965,7
 
if DEBUG
mov esi, msgCRFail
call [SysMsgBoardStr]
call SysMsgBoardStr
end if
stc
ret
1292,21 → 1299,7
 
include "codec.inc"
 
 
align 16
pcmout_bdl dq 32 dup(0)
buff_list dd 32 dup(0)
 
align 16
ctrl AC_CNTRL
 
align 16
codec CODEC
 
lpc_bus dd 0
civ_val dd 0
 
align 16
align 4
devices dd (CTRL_ICH shl 16)+VID_INTEL,msg_ICH, set_ICH
dd (CTRL_ICH0 shl 16)+VID_INTEL,msg_ICH0,set_ICH
dd (CTRL_ICH2 shl 16)+VID_INTEL,msg_ICH2,set_ICH
1322,24 → 1315,6
 
dd 0 ;terminator
 
align 16
imp_table:
IMPORTS:
 
AttachIntHandler dd szAttachIntHandler
SysMsgBoardStr dd szSysMsgBoardStr
PciApi dd szPciApi
PciRead32 dd szPciRead32
PciRead8 dd szPciRead8
PciWrite8 dd szPciWrite8
AllocKernelSpace dd szAllocKernelSpace
MapPage dd szMapPage
KernelAlloc dd szKernelAlloc
GetPgAddr dd szGetPgAddr
RegService dd szRegService
GetCurrentTask dd szGetCurrentTask
dd 0
 
msg_ICH db 'Intel ICH', 13,10, 0
msg_ICH0 db 'Intel ICH0', 13,10, 0
msg_ICH2 db 'Intel ICH2', 13,10, 0
1355,21 → 1330,7
msg_NForce3 db 'NForce 3', 13,10, 0
msg_NVidia db 'NVidea', 0
 
 
szKernel db 'KERNEL', 0
szAttachIntHandler db 'AttachIntHandler',0
szSysMsgBoardStr db 'SysMsgBoardStr', 0
szPciApi db 'PciApi', 0
szPciRead32 db 'PciRead32', 0
szPciRead8 db 'PciRead8', 0
szPciWrite8 db 'PciWrite8',0
szAllocKernelSpace db 'AllocKernelSpace',0
szMapPage db 'MapPage',0
szRegService db 'RegService',0
szKernelAlloc db 'KernelAlloc',0
szGetPgAddr db 'GetPgAddr',0
szGetCurrentTask db 'GetCurrentTask ',0
 
sz_sound_srv db 'SOUND',0
 
msgInit db 'detect hardware...',13,10,0
1392,3 → 1353,15
msgCFail db 'codec not ready',13,10,0
msgResetOk db 'reset complete',13,10,0
 
section '.data' data readable writable align 16
 
pcmout_bdl rq 32
buff_list rd 32
 
codec CODEC
ctrl AC_CNTRL
 
lpc_bus rd 1
civ_val rd 1