From 73c568fb03fc2e9880c29236f8c06958430e9156 Mon Sep 17 00:00:00 2001 From: "Sergey Semyonov (Serge)" Date: Tue, 27 Feb 2007 11:47:52 +0000 Subject: [PATCH] 1)new memory layout 2)Infinity 1.0 git-svn-id: svn://kolibrios.org@378 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/trunk/boot/bootcode.inc | 14 +- kernel/trunk/const.inc | 34 +- kernel/trunk/core/dll.inc | 4 +- kernel/trunk/core/fpu.inc | 92 +- kernel/trunk/core/memory.inc | 71 +- kernel/trunk/core/taskman.inc | 22 +- kernel/trunk/drivers/ati2d.asm | 14 +- kernel/trunk/drivers/codec.inc | 45 +- kernel/trunk/drivers/infinity.asm | 1152 +++++++++++++++++------ kernel/trunk/drivers/main.inc | 129 +-- kernel/trunk/drivers/mixer.asm | 512 ++++++---- kernel/trunk/drivers/sis.asm | 90 +- kernel/trunk/drivers/sound.asm | 120 ++- kernel/trunk/{debug-fdo.inc => fdo.inc} | 0 kernel/trunk/kernel.asm | 68 +- kernel/trunk/memmap.inc | 10 +- 16 files changed, 1581 insertions(+), 796 deletions(-) rename kernel/trunk/{debug-fdo.inc => fdo.inc} (100%) diff --git a/kernel/trunk/boot/bootcode.inc b/kernel/trunk/boot/bootcode.inc index 693859166a..b03949eb11 100644 --- a/kernel/trunk/boot/bootcode.inc +++ b/kernel/trunk/boot/bootcode.inc @@ -59,19 +59,19 @@ os_data_l: db 0x00 app_code_l: - dw 0xFFFF;((0x80000000-std_application_base_address) shr 12) and 0xffff + dw 0xFFFF dw 0 - db 0x40 + db 0 db cpl3 - dw G32+D32+0x6000+0x7; + dw G32+D32+0x8000+0x7; app_data_l: - dw 0xFFFF;(0x80000000-std_application_base_address) shr 12 and 0xffff + dw 0xFFFF dw 0 - db 0x40 + db 0 db drw3 - dw G32+D32+0x6000+0x7; - + dw G32+D32+0x8000+0x7; + ; --------------- APM --------------------- apm_code_32: dw 0x0f ; limit 64kb diff --git a/kernel/trunk/const.inc b/kernel/trunk/const.inc index 7af311ce2b..d026589141 100644 --- a/kernel/trunk/const.inc +++ b/kernel/trunk/const.inc @@ -85,7 +85,7 @@ CAPS_CMP_LEG equ 72 ; CAPS_SVM equ 73 ;secure virual machine CAPS_ALTMOVCR8 equ 74 ; -; CPU MSR names +; CPU MSR names MSR_SYSENTER_CS equ 0x174 MSR_SYSENTER_ESP equ 0x175 MSR_SYSENTER_EIP equ 0x176 @@ -231,30 +231,32 @@ resendQ equ OS_BASE+0x0770000 ;skin_data equ OS_BASE+0x0778000 + tss_data equ 0x780000 draw_data equ 0x988000 HEAP_BASE equ 0x98B000 -page_tabs equ 0x60000000 -master_tab equ 0x60180000 -current_pgdir equ 0x60180000 +LFB_BASE equ 0x7DC00000 -sys_pgdir equ OS_BASE+0x00050000 -sys_master_tab equ OS_BASE+0x00051000 -sys_pgmap equ OS_BASE+0x00052000 +page_tabs equ 0x7FC00000 +master_tab equ 0x7FDFF000 +app_page_tabs equ 0x7FE00000 + +sys_pgdir equ OS_BASE+0x00050000 +sys_master_tab equ OS_BASE+0x00051000 +sys_pgmap equ OS_BASE+0x00052000 -new_app_base equ 0x60400000 +new_app_base equ 0x80000000 twdw equ (CURRENT_TASK-window_data) std_application_base_address equ new_app_base +RING0_STACK_SIZE equ 0x2000 - 512 ;512 байт для контекста FPU -RING0_STACK_SIZE equ 0x2000 - 512 ;512 байт для контекста FPU - -PAGES_USED equ 4 +;PAGES_USED equ 4 PG_UNMAP equ 0x000 PG_MAP equ 0x001 @@ -445,11 +447,11 @@ struc PG_DATA } ;struc LIB -;{ .lib_name rb 16 -; .lib_base dd ? -; .lib_start dd ? -; .export dd ? -; .import dd ? +;{ .lib_name rb 16 +; .lib_base dd ? +; .lib_start dd ? +; .export dd ? +; .import dd ? ;} struc SRV diff --git a/kernel/trunk/core/dll.inc b/kernel/trunk/core/dll.inc index 7b375e65bd..3e50131d42 100644 --- a/kernel/trunk/core/dll.inc +++ b/kernel/trunk/core/dll.inc @@ -1,8 +1,8 @@ DRV_ENTRY equ 1 DRV_EXIT equ -1 -DRV_COMPAT equ 3 ;minimal required drivers version -DRV_CURRENT equ 3 ;current drivers model version +DRV_COMPAT equ 4 ;minimal required drivers version +DRV_CURRENT equ 4 ;current drivers model version DRV_VERSION equ (DRV_COMPAT shl 16) or DRV_CURRENT diff --git a/kernel/trunk/core/fpu.inc b/kernel/trunk/core/fpu.inc index c7748eeb86..932409f401 100644 --- a/kernel/trunk/core/fpu.inc +++ b/kernel/trunk/core/fpu.inc @@ -36,41 +36,95 @@ init_fpu: fnsave [fpu_data] ret +; param +; eax= 512 bytes memory area + align 4 -proc fpu_save +fpu_save: + push ecx + push esi + push edi + + pushfd + cli + clts - mov ebx, [fpu_owner] - shl ebx, 8 - mov eax, [ebx+PROC_BASE+0x10] - mov ebx, [CURRENT_TASK] - mov [fpu_owner], ebx + mov edi, eax + + mov ecx, [fpu_owner] + mov eax, [CURRENT_TASK] + cmp ecx, eax + jne .save +.copy: + shl eax, 8 + mov esi, [eax+PROC_BASE+APPDATA.fpu_state] + mov ecx, 512/4 + cld + rep movsd + fninit + + popfd + pop edi + pop esi + pop ecx + ret +.save: + mov [fpu_owner], eax + + shl ecx, 8 + mov ecx, [ecx+PROC_BASE+APPDATA.fpu_state] bt [cpu_caps], CAPS_SSE jnc .no_SSE - fxsave [eax] - fninit ;re-init fpu - ret + fxsave [ecx] + jmp .copy .no_SSE: - fnsave [eax] - ret -endp + fnsave [ecx] + jmp .copy align 4 -proc fpu_restore - mov ebx, [CURRENT_TASK] - shl ebx, 8 - mov eax, [ebx+PROC_BASE+0x10] +fpu_restore: + push ecx + push esi + + mov esi, eax + + pushfd + cli + + mov ecx, [fpu_owner] + mov eax, [CURRENT_TASK] + cmp ecx, eax + jne .copy + + clts + bt [cpu_caps], CAPS_SSE jnc .no_SSE - fxrstor [eax] + fxrstor [esi] + popfd + pop esi + pop ecx ret .no_SSE: fnclex ;fix possible problems - frstor [eax] + frstor [esi] + popfd + pop esi + pop ecx + ret +.copy: + shl eax, 8 + mov edi, [eax+PROC_BASE+APPDATA.fpu_state] + mov ecx, 512/4 + cld + rep movsd + popfd + pop esi + pop ecx ret -endp align 4 e7: ;#NM exception handler diff --git a/kernel/trunk/core/memory.inc b/kernel/trunk/core/memory.inc index bc70e47320..5103553b1e 100644 --- a/kernel/trunk/core/memory.inc +++ b/kernel/trunk/core/memory.inc @@ -106,7 +106,7 @@ proc init_mem dec ecx jnz .map_kernel_tabs - mov dword [sys_pgdir+0x600], sys_pgdir+PG_SW + mov dword [sys_pgdir+(page_tabs shr 20)], sys_pgdir+PG_SW ret endp @@ -365,7 +365,7 @@ proc map_page_table stdcall, lin_addr:dword, phis_addr:dword mov eax, [phis_addr] and eax, not 0xFFF or eax, PG_UW ;+PG_NOCACHE - mov dword [current_pgdir+ebx*4], eax + mov dword [master_tab+ebx*4], eax mov eax, [lin_addr] shr eax, 10 add eax, page_tabs @@ -376,6 +376,10 @@ endp align 4 proc init_LFB + locals + pg_count dd ? + endl + cmp dword [LFBAddress], -1 jne @f mov [0x2f0000+0x901c],byte 2 @@ -388,18 +392,9 @@ proc init_LFB mov [0x2f0000+0x901c],byte 2 ret @@: - call map_LFB - ret -endp - -align 4 -proc map_LFB - locals - pg_count dd ? - endl - - mov edi, [LFBSize] + mov edx, LFB_BASE mov esi, [LFBAddress] + mov edi, [LFBSize] mov dword [exp_lfb+4], esi shr edi, 12 @@ -408,13 +403,12 @@ proc map_LFB bt [cpu_caps], CAPS_PSE jnc .map_page_tables - mov ebx, esi or esi, PG_LARGE+PG_UW - shr ebx, 20 - mov ecx, ebx + shr edx, 20 + mov ecx, edx @@: - mov [sys_pgdir+ebx], esi - add ebx, 4 + mov [sys_pgdir+edx], esi + add edx, 4 add esi, 0x00400000 dec edi jnz @B @@ -423,6 +417,7 @@ proc map_LFB jnc @F or dword [sys_pgdir+ecx], PG_GLOBAL @@: + mov dword [LFBAddress], LFB_BASE mov eax, cr3 ;flush TLB mov cr3, eax ret @@ -431,31 +426,19 @@ proc map_LFB @@: call alloc_page - stdcall map_page_table, esi, eax + stdcall map_page_table, edx, eax add esi, 0x00400000 dec edi jnz @B mov eax, [LFBAddress] - mov esi, eax - shr esi, 10 - add esi, page_tabs + mov edi, page_tabs + (LFB_BASE shr 10) or eax, PG_UW mov ecx, [pg_count] - shr ecx, 2 -.map: - mov [esi], eax - add eax, 0x1000 - mov [esi+4], eax - add eax, 0x1000 - mov [esi+8], eax - add eax, 0x1000 - mov [esi+12], eax - add eax, 0x1000 - add esi, 16 - sub ecx, 1 - jnz .map + cld + rep stosd + mov dword [LFBAddress], LFB_BASE mov eax, cr3 ;flush TLB mov cr3, eax @@ -488,10 +471,10 @@ proc new_mem_resize stdcall, new_size:dword shr edi, 12 shr esi, 12 @@: - mov eax, [page_tabs+0x00181000+edi*4] + mov eax, [app_page_tabs+edi*4] test eax, 1 jz .next - mov dword [page_tabs+0x00181000+edi*4], 2 + mov dword [app_page_tabs+edi*4], 2 mov ebx, edi shl ebx, 12 invlpg [ebx+std_application_base_address] @@ -636,18 +619,18 @@ proc page_fault_handler mov ebx, [ebp-4] - cmp ebx, 0xe0000000 - jae .lfb_addr - - cmp ebx, 0x60400000 + cmp ebx, 0x80000000 jae .user_space - cmp ebx, master_tab+0x1000 + cmp ebx, app_page_tabs jae .alloc - cmp ebx, 0x60000000 + cmp ebx, page_tabs jae .tab_space + cmp ebx, 0x7DC00000 + jae .lfb_addr + jmp .kernel_space .user_space: @@ -1075,7 +1058,7 @@ new_services: @@: cmp eax, 17 ja @f - stdcall srv_handlerEx, ebx + call srv_handlerEx ;ebx mov [esp+36], eax ret @@: diff --git a/kernel/trunk/core/taskman.inc b/kernel/trunk/core/taskman.inc index 07f9939d31..0ec3abb722 100644 --- a/kernel/trunk/core/taskman.inc +++ b/kernel/trunk/core/taskman.inc @@ -386,23 +386,17 @@ proc create_app_space stdcall, app_size:dword,img_base:dword,img_size:dword mov esi, sys_pgdir mov edi, [tmp_task_pdir] - mov ecx, 384 + mov ecx, (page_tabs shr 20)/4 cld rep movsd - mov ecx, 384 - xor eax, eax - cld - rep stosd - - mov ecx, 256 - mov esi, sys_pgdir+0xc00 - rep movsd - mov eax, [dir_addr] or eax, PG_SW - mov ebx, [tmp_task_pdir] - mov [ebx+0x600], eax + stosd ; [(page_tabs shr 20)]= eax + + mov ecx, 0x800/4 + xor eax, eax + rep stosd mov eax, [dir_addr] call set_cr3 @@ -555,8 +549,8 @@ proc destroy_app_space stdcall, pg_dir:dword and eax, not 0xFFF stdcall map_page,[tmp_task_pdir],eax,dword PG_SW mov esi, [tmp_task_pdir] - add esi, 0x604 - mov edi, 383 + add esi, 0x800 + mov edi, 0x800/4 .destroy: mov eax, [esi] test eax, 1 diff --git a/kernel/trunk/drivers/ati2d.asm b/kernel/trunk/drivers/ati2d.asm index 2b9a25266b..479e741de8 100644 --- a/kernel/trunk/drivers/ati2d.asm +++ b/kernel/trunk/drivers/ati2d.asm @@ -65,9 +65,9 @@ R9800 equ 0x4E49 ;R350 R9800P equ 0x4E48 ;R350 R9800XT equ 0x4E4A ;R360 -OS_BASE equ 0; 0x80400000 -new_app_base equ 0x60400000; 0x01000000 -PROC_BASE equ OS_BASE+0x0080000 +OS_BASE equ 0 +new_app_base equ 0x80000000 +PROC_BASE equ 0x0080000 PG_SW equ 0x003 PG_NOCACHE equ 0x018 @@ -85,8 +85,8 @@ virtual at 0 IOCTL IOCTL end virtual -;MMIO equ 0F9000000h -RD_RB3D_CNTL equ 1c3ch +;MMIO equ 0F9000000h +RD_RB3D_CNTL equ 1c3ch RD_MEM_CNTL equ 0140h RD_CRTC_GEN_CNTL equ 0050h @@ -232,7 +232,7 @@ proc service_proc stdcall, ioctl:dword mov eax, [edi+input] call video_free .fail: - xor eax, eax + or eax, -1 ret endp @@ -981,7 +981,7 @@ devices dd (R8500 shl 16)+VID_ATI dd (R9800XT shl 16)+VID_ATI dd 0 ;terminator -version dd 0x00030003 +version dd 0x00040004 sz_ati_srv db 'HWCURSOR',0 diff --git a/kernel/trunk/drivers/codec.inc b/kernel/trunk/drivers/codec.inc index ae222dca5e..f17cd8e1f7 100644 --- a/kernel/trunk/drivers/codec.inc +++ b/kernel/trunk/drivers/codec.inc @@ -67,7 +67,7 @@ proc setup_codec xor eax, eax stdcall codec_write, dword CODEC_AUX_VOL - mov eax, 0x1010 + mov eax, 0x0B0B stdcall codec_write, dword CODEC_MASTER_VOL_REG mov ax, 0x08 @@ -98,43 +98,40 @@ proc setup_codec xor eax, eax ; exit with error ret - endp + +; param +; eax= volume -10000 - 0 for both channels + align 4 -proc set_master_vol stdcall, vol:dword - - mov ebx, 63 - mov ecx, 20644 - mov eax, [vol] - cmp eax, 90 - jna @f - mov eax, 90 +set_master_vol: + cmp eax, 0 + jl @F + xor eax, eax + jmp .set @@: - mul ecx - shr eax, 15 - sub ebx, eax - mov ah, bl - mov al, bl + cmp eax, -9450 + jg .set + mov eax, -9450 ;clamp into 6 bits +.set: + cdq + mov ebx, -150 + idiv ebx + mov ah, al stdcall codec_write, dword CODEC_MASTER_VOL_REG + xor eax, eax ret -endp align 4 proc get_master_vol stdcall, pvol:dword stdcall codec_read, dword CODEC_MASTER_VOL_REG and eax, 0x3F - mov ebx, 63 - mov ecx, 20644 - - xchg eax, ebx - sub eax, ebx - shl eax, 15 - xor edx, edx - div ecx + imul eax, -150 mov ebx, [pvol] mov [ebx], eax + xor eax, eax ret endp diff --git a/kernel/trunk/drivers/infinity.asm b/kernel/trunk/drivers/infinity.asm index 3c0521c757..e34122c699 100644 --- a/kernel/trunk/drivers/infinity.asm +++ b/kernel/trunk/drivers/infinity.asm @@ -19,44 +19,46 @@ include 'proc32.inc' include 'main.inc' include 'imports.inc' -FORCE_MMX equ 0 ;set to 1 to force use mmx or -FORCE_MMX_128 equ 0 ;integer sse2 extensions +FORCE_MMX equ 0 ;set to 1 to force use mmx or +FORCE_MMX_128 equ 0 ;integer sse2 extensions ;and reduce driver size -;USE_SSE equ 0 +;USE_SSE equ 0 -DEBUG equ 1 +DEBUG equ 1 -EVENT_NOTIFY equ 0x00000200 -OS_BASE equ 0 -new_app_base equ 0x60400000 -PROC_BASE equ OS_BASE+0x0080000 - -CAPS_SSE2 equ 26 -PG_SW equ 0x003 +OS_BASE equ 0 +new_app_base equ 0x80000000 +PROC_BASE equ OS_BASE+0x0080000 +CAPS_SSE2 equ 26 +PG_SW equ 0x003 public START public service_proc public version -SND_CREATE_BUFF equ 2 -SND_PLAY equ 3 -SND_STOP equ 4 -SND_SETBUFF equ 5 -SND_DESTROY_BUFF equ 6 +RT_INP_EMPTY equ 0xFF000001 +RT_OUT_EMPTY equ 0xFF000002 +RT_INP_FULL equ 0xFF000003 +RT_OUT_FULL equ 0xFF000004 -DEV_PLAY equ 1 -DEV_STOP equ 2 -DEV_CALLBACK equ 3 +EVENT_WATCHED equ 0x10000000 +EVENT_SIGNALED equ 0x20000000 +MANUAL_RESET equ 0x40000000 +MANUAL_DESTROY equ 0x80000000 + +DEV_PLAY equ 1 +DEV_STOP equ 2 +DEV_CALLBACK equ 3 struc IOCTL -{ .handle dd ? - .io_code dd ? - .input dd ? - .inp_size dd ? - .output dd ? - .out_size dd ? +{ .handle dd ? + .io_code dd ? + .input dd ? + .inp_size dd ? + .output dd ? + .out_size dd ? } virtual at 0 @@ -104,6 +106,8 @@ if FORCE_MMX_128 mov [mix_4_core], mmx128_mix_4 end if +if 0 + if ~(FORCE_MMX or FORCE_MMX_128) ;autodetect mov eax, 1 cpuid @@ -119,8 +123,11 @@ if ~(FORCE_MMX or FORCE_MMX_128) ;autodetect mov [mix_3_core], mmx128_mix_3 mov [mix_4_core], mmx128_mix_4 @@: +end if + end if stdcall set_handler, [hSound], new_mix + mov [eng_state], SND_STOP stdcall RegService, szInfinity, service_proc ret .fail: @@ -154,50 +161,144 @@ proc service_proc stdcall, ioctl:dword mov edi, [ioctl] mov eax, [edi+io_code] + cmp eax, SRV_GETVERSION + jne @F + mov eax, [edi+output] + mov eax, [eax] + mov [eax+new_app_base], dword SOUND_VERSION + xor eax, eax + ret +@@: cmp eax, SND_CREATE_BUFF jne @F mov ebx, [edi+input] - stdcall CreateBuffer,[ebx] + push edi + stdcall CreateBuffer,[ebx],[ebx+4] + pop edi + mov ecx, [edi+output] + mov ecx, [ecx] + mov [ecx+new_app_base], ebx ret @@: - cmp eax, SND_PLAY - jne @F - mov ebx, [edi+input] - stdcall play_buffer, [ebx] + mov edx, [ebx] + + cmp [edx+STREAM.magic], 'WAVE' + jne .fail + + cmp [edx+STREAM.size], STREAM_SIZE + jne .fail + + cmp eax, SND_DESTROY_BUFF + jne @F + mov eax, edx + call DestroyBuffer ;edx= stream ret @@: - cmp eax, SND_STOP + cmp eax, SND_SETFORMAT + jne @F + stdcall SetFormat,[ebx],[ebx+4] + ret +@@: + cmp eax, SND_GETFORMAT jne @F -; if DEBUG -; mov esi, msgStop -; call [SysMsgBoardStr] -; end if - - mov ebx, [edi+input] - stdcall stop_buffer, [ebx] + movzx eax, word [edx+STREAM.format] + mov ecx, [edi+output] + mov ecx, [ecx] + mov [ecx+new_app_base], eax + xor eax, eax + ret +@@: + cmp eax, SND_RESET + jne @F + stdcall ResetBuffer,[ebx],[ebx+4] + ret +@@: + cmp eax, SND_SETPOS + jne @F + stdcall SetBufferPos,[ebx],[ebx+4] + ret +@@: + cmp eax, SND_GETPOS + jne @F + push edi + stdcall GetBufferPos, [ebx] + pop edi + mov ecx, [edi+output] + mov ecx, [ecx] + mov [ecx+new_app_base], ebx ret @@: cmp eax, SND_SETBUFF jne @F - - mov ebx, [edi+input] mov eax, [ebx+4] add eax, new_app_base stdcall set_buffer, [ebx],eax,[ebx+8],[ebx+12] ret @@: - cmp eax, SND_DESTROY_BUFF + cmp eax, SND_SETVOLUME jne @F - - mov eax, [edi+input] - mov eax, [eax] - call DestroyBuffer ;eax + stdcall SetBufferVol,[ebx],[ebx+4],[ebx+8] ret @@: + cmp eax, SND_GETVOLUME + jne @F + + mov eax, [edi+output] + mov ecx, [eax] + mov eax, [eax+4] + add ecx, new_app_base + add eax, new_app_base + stdcall GetBufferVol,[ebx],ecx,eax + ret +@@: + cmp eax, SND_SETPAN + jne @F + stdcall SetBufferPan,[ebx],[ebx+4] + ret +@@: + cmp eax, SND_GETPAN + jne @F + mov eax, [edx+STREAM.pan] + mov ebx, [edi+output] + mov ebx, [ebx] + mov [ebx+new_app_base], eax xor eax, eax ret +@@: + cmp eax, SND_OUT + jne @F + + mov eax, [ebx+4] + add eax, new_app_base + stdcall wave_out, [ebx],eax,[ebx+8] + ret +@@: + cmp eax, SND_PLAY + jne @F + + stdcall play_buffer, [ebx],[ebx+4] + ret +@@: + cmp eax, SND_STOP + jne @F + + stdcall stop_buffer, [ebx] + ret +@@: + cmp eax, SND_GETBUFFSIZE + jne @F + mov eax, [edx+STREAM.in_size] + mov ecx, [edi+output] + mov ecx, [ecx] + mov [ecx+new_app_base], eax + xor eax, eax + ret +@@: +.fail: + or eax, -1 + ret endp restore handle @@ -210,12 +311,35 @@ restore out_size TASK_COUNT equ 0x0003004 CURRENT_TASK equ 0x0003000 + align 4 -proc CreateBuffer stdcall, format:dword +proc CreateBuffer stdcall, format:dword, size:dword locals - str dd ? + str dd ? + ring_size dd ? + ring_pages dd ? endl + mov eax, [format] + cmp ax, PCM_1_8_8 + ja .fail + + test eax, PCM_OUT + jnz .test_out + test eax, PCM_RING + jnz .test_ring +;staic + test eax, PCM_OUT+PCM_RING + jnz .fail + jmp .test_ok +.test_out: + test eax, PCM_RING+PCM_STATIC + jnz .fail + jmp .test_ok +.test_ring: + test eax, PCM_OUT+PCM_STATIC + jnz .fail +.test_ok: mov ebx, [CURRENT_TASK] ;hack: direct accsess shl ebx, 5 ;to kernel data mov ebx, [0x3000+ebx+4] @@ -226,52 +350,116 @@ proc CreateBuffer stdcall, format:dword jz .fail mov [str], eax - mov [eax+STREAM.magic], 'WAVE' - mov [eax+STREAM.destroy], DestroyBuffer.destroy - mov [eax+STREAM.size], STREAM_SIZE + mov ebx, [format] + mov [eax+STREAM.format], ebx - pushf - cli - mov ebx, str.fd-FD_OFFSET - mov edx, [ebx+STREAM.str_fd] - mov [eax+STREAM.str_fd], edx - mov [eax+STREAM.str_bk], ebx - mov [ebx+STREAM.str_fd], eax - mov [edx+STREAM.str_bk], eax - popf + xor ecx, ecx + movzx ebx, bx + cmp ebx, 19 + jb @f + mov ecx, 0x80808080 +@@: + mov [eax+STREAM.r_silence], ecx - stdcall KernelAlloc, dword 72*1024 + shl ebx, 2 + lea ebx, [ebx+ebx*2] ;ebx*=12 + + mov ecx, [resampler_params+ebx] + mov edx, [resampler_params+ebx+4] + mov esi, [resampler_params+ebx+8] + + mov [eax+STREAM.r_size],ecx + mov [eax+STREAM.r_dt], edx + mov [eax+STREAM.resample], esi + xor ecx, ecx + mov [eax+STREAM.l_vol], ecx + mov [eax+STREAM.r_vol], ecx + mov dword [eax+STREAM.l_amp], 0x7FFF7FFF + mov [eax+STREAM.pan], ecx + + test [format], PCM_STATIC + jnz .static + +; ring and waveout + + mov eax, 0x10000 + test [format], PCM_RING + jz .waveout + + mov eax, [eax+STREAM.r_size] + add eax, 4095 + and eax, -4096 + add eax, eax +.waveout: + mov [ring_size], eax + mov ebx, eax + shr ebx, 12 + mov [ring_pages], ebx + + add eax, eax ;double ring size + stdcall AllocKernelSpace, eax mov edi, [str] - mov [edi+STREAM.base], eax - add eax, 0x1000 - mov [edi+STREAM.seg_0], eax - mov [edi+STREAM.curr_seg], eax - mov [edi+STREAM.notify_off1], eax - add eax, 0x8000 - mov [edi+STREAM.lim_0], eax - add eax, 0x1000 - mov [edi+STREAM.seg_1], eax - mov [edi+STREAM.notify_off2], eax - add eax, 0x8000 - mov [edi+STREAM.limit], eax - mov [edi+STREAM.lim_1], eax + mov ecx, [ring_size] + mov [edi+STREAM.in_base], eax + mov [edi+STREAM.in_size], ecx + add eax, 128 + sub ecx, 128 + mov [edi+STREAM.in_wp], eax + mov [edi+STREAM.in_rp], eax + mov [edi+STREAM.in_count], 0 -; create ring buffer + mov [edi+STREAM.in_free], ecx + add eax, ecx + mov [edi+STREAM.in_top], eax + mov ebx, [ring_pages] + stdcall AllocPages, ebx + mov edi, [str] + mov ebx, [edi+STREAM.in_base] + mov ecx, [ring_pages] + or eax, PG_SW + push eax + push ebx + call CommitPages ;eax, ebx, ecx + mov ecx, [ring_pages] + pop ebx + pop eax + add ebx, [ring_size] + call CommitPages ;double mapped + + jmp .out_buff +.static: + mov ecx, [size] + add ecx, 128 ;resampler required + mov [eax+STREAM.in_size], ecx + stdcall KernelAlloc, ecx + + mov edi, [str] + mov [edi+STREAM.in_base], eax + add eax, 128 + mov [edi+STREAM.in_wp], eax + mov [edi+STREAM.in_rp], eax + mov ebx, [size] + mov [edi+STREAM.in_count], ebx + mov [edi+STREAM.in_free], ebx + add eax, ebx + mov [edi+STREAM.in_top], eax + +.out_buff: stdcall AllocKernelSpace, dword 128*1024 mov edi, [str] - mov [edi+STREAM.work_buff], eax - mov [edi+STREAM.work_read], eax - mov [edi+STREAM.work_write], eax - mov [edi+STREAM.work_count], 0 + mov [edi+STREAM.out_base], eax + mov [edi+STREAM.out_wp], eax + mov [edi+STREAM.out_rp], eax + mov [edi+STREAM.out_count], 0 add eax, 64*1024 - mov [edi+STREAM.work_top], eax + mov [edi+STREAM.out_top], eax stdcall AllocPages, dword 64/4 mov edi, [str] - mov ebx, [edi+STREAM.work_buff] + mov ebx, [edi+STREAM.out_base] mov ecx, 16 or eax, PG_SW push eax @@ -284,89 +472,50 @@ proc CreateBuffer stdcall, format:dword call CommitPages ;double mapped mov edi, [str] - mov eax, [format] - mov [edi+STREAM.format], eax - mov [edi+STREAM.flags], SND_STOP - - xor ebx, ebx - cmp eax, 19 - jb @f - mov ebx, 0x80808080 -@@: - mov [edi+STREAM.r_silence], ebx - - shl eax, 4 - mov ebx, [resampler_params+eax] - mov ecx, [resampler_params+eax+4] - mov edx, [resampler_params+eax+8] - - mov [edi+STREAM.r_size],ebx - mov [edi+STREAM.r_end], ecx - mov [edi+STREAM.r_dt], edx - - mov ebx, [resampler_params+eax+12] - mov [edi+STREAM.resample], ebx - - mov edx, [edi+STREAM.base] - lea eax, [edx+0x9000] - call GetPgAddr ;eax - call FreePage ;eax - - mov eax, edx - lea ebx, [edx+0x9000] - call GetPgAddr ;eax - stdcall MapPage, ebx, eax, dword 3 - - mov edi, [edi+STREAM.base] - mov ecx, (72*1024)/4 + mov ecx, [edi+STREAM.in_top] + mov edi, [edi+STREAM.in_base] + sub ecx, edi xor eax, eax + shr ecx, 2 cld rep stosd mov edi, [str] - mov edi, [edi+STREAM.work_buff] + mov edi, [edi+STREAM.out_base] mov ecx, (64*1024)/4 rep stosd - mov eax, [str] - ret -.fail: + xor edx, edx + mov ebx, MANUAL_DESTROY + call CreateEvent + + mov ebx, [str] + mov [ebx+STREAM.notify_event], eax + mov [ebx+STREAM.notify_id], edx + + mov [ebx+STREAM.magic], 'WAVE' + mov [ebx+STREAM.destroy], DestroyBuffer.destroy + mov [ebx+STREAM.size], STREAM_SIZE + mov [ebx+STREAM.flags], SND_STOP + + pushf + cli + mov eax, str.fd-FD_OFFSET + mov edx, [eax+STREAM.str_fd] + mov [ebx+STREAM.str_fd], edx + mov [ebx+STREAM.str_bk], eax + mov [eax+STREAM.str_fd], ebx + mov [edx+STREAM.str_bk], ebx + popf + xor eax, eax ret +.fail: + xor ebx, ebx + or eax, -1 + ret endp -if 0 -align 4 -pid_to_slot: - - push ebx - push ecx - mov ebx,[TASK_COUNT] - shl ebx,5 - mov ecx,2*32 -.loop: - cmp byte [CURRENT_TASK+ecx+0xa],9 - jz .endloop ;skip empty slots - cmp [CURRENT_TASK+ecx+0x4],eax ;check PID - jz .pid_found -.endloop: - add ecx,32 - cmp ecx,ebx - jle .loop - pop ecx - pop ebx - xor eax,eax - ret - -.pid_found: - shr ecx,5 - mov eax,ecx - pop ecx - pop ebx - ret - -end if - ;param ; eax= buffer handle @@ -374,15 +523,11 @@ align 4 DestroyBuffer: .handle equ esp ;local - cmp [eax+STREAM.magic], 'WAVE' - jne .fail - - cmp [eax+STREAM.size], STREAM_SIZE - jne .fail + mov [eax+STREAM.flags], SND_STOP .destroy: push eax - pushf + pushfd cli mov ebx, [eax+STREAM.str_fd] mov ecx, [eax+STREAM.str_bk] @@ -390,114 +535,119 @@ DestroyBuffer: mov [ecx+STREAM.str_fd], ebx popf - stdcall KernelFree, [eax+STREAM.base] + stdcall KernelFree, [eax+STREAM.in_base] mov eax, [.handle] - stdcall KernelFree, [eax+STREAM.work_buff] + stdcall KernelFree, [eax+STREAM.out_base] pop eax ;restore stack - call DestroyObject ;eax -.fail: + call DestroyObject ;eax= stream + xor eax, eax ret +.fail: + or eax, -1 + ret +restore .handle align 4 -proc play_buffer stdcall, str:dword +proc SetFormat stdcall, str:dword, format:dword - mov ebx, [str] - cmp [ebx+STREAM.magic], 'WAVE' - jne .fail + cmp word [format], PCM_1_8_8 + ja .fail - cmp [ebx+STREAM.size], STREAM_SIZE - jne .fail + mov edx, [str] + mov [edx+STREAM.flags], SND_STOP - mov edi,[ebx+STREAM.work_buff] - mov [ebx+STREAM.work_read], edi - mov [ebx+STREAM.work_write], edi - mov [ebx+STREAM.work_count], 0 + test [edx+STREAM.format], PCM_RING + jnz .fail - mov edx, [ebx+STREAM.base] - add edx, 0x1000 - mov [ebx+STREAM.seg_0], edx - mov [ebx+STREAM.curr_seg], edx - add edx, 0x8000 - mov [ebx+STREAM.lim_0], edx - add edx, 0x1000 - mov [ebx+STREAM.seg_1], edx - add edx, 0x8000 - mov [ebx+STREAM.lim_1], edx +; mov eax,[edx+STREAM.out_base] +; mov [edx+STREAM.out_wp], eax +; mov [edx+STREAM.out_rp], eax +; mov [edx+STREAM.out_count], 0 - mov edx, [ebx+STREAM.seg_0] - mov ecx, -128 - mov eax, [ebx+STREAM.r_silence] + movzx eax, word [format] + mov word [edx+STREAM.format], ax + + xor ebx, ebx + cmp eax, 19 + jb @f + mov ebx, 0x80808080 @@: - mov [edx+ecx], eax - add ecx, 4 - jnz @B + mov [edx+STREAM.r_silence], ebx - stdcall [ebx+STREAM.resample], edi, edx,\ - [ebx+STREAM.r_dt],[ebx+STREAM.r_size],[ebx+STREAM.r_end] + shl eax, 2 + lea eax, [eax+eax*2] ;eax*=12 - mov ebx, [str] + mov edi, [resampler_params+eax] + mov ecx, [resampler_params+eax+4] + mov ebx, [resampler_params+eax+8] - add [ebx+STREAM.work_count], eax - add [ebx+STREAM.work_write], eax + mov [edx+STREAM.r_size],edi + mov [edx+STREAM.r_dt], ecx + mov [edx+STREAM.resample], ebx - mov edx, [ebx+STREAM.r_size] - add [ebx+STREAM.curr_seg], edx - - mov [ebx+STREAM.flags], SND_PLAY - - mov eax, [ebx+STREAM.r_silence] - mov edi, [ebx+STREAM.work_write] - mov ecx, [ebx+STREAM.work_top] - sub ecx, edi - shr ecx, 2 + mov edi, [edx+STREAM.in_base] + mov ecx, 128/4 + mov eax, [edx+STREAM.r_silence] cld rep stosd - - stdcall dev_play, [hSound] xor eax, eax - inc eax ret .fail: - xor eax, eax + or eax, -1 ret endp -align 4 -proc stop_buffer stdcall, str:dword - - mov edi, [str] - - cmp [edi+STREAM.magic], 'WAVE' - jne .fail - - cmp [edi+STREAM.size], STREAM_SIZE - jne .fail - - mov [edi+STREAM.flags], SND_STOP - -; stdcall [ServiceHandler], [hSound], dword DEV_STOP, 0 - - xor eax, eax - inc eax - ret -.fail: - xor eax, eax - ret -endp +; for static buffers only +; use waveout for streams align 4 proc set_buffer stdcall, str:dword,src:dword,offs:dword,size:dword mov edx, [str] - test edx, edx - jz .fail + test [edx+STREAM.format], PCM_OUT + jnz .fail - cmp [edx+STREAM.magic], 'WAVE' - jne .fail + mov esi, [src] + mov edi, [offs] + add edi, [edx+STREAM.in_base] + add edi, 128 - cmp [edx+STREAM.size], STREAM_SIZE - jne .fail + cmp edi, [edx+STREAM.in_top] + jae .fail + + mov ecx, [size] + lea ebx, [ecx+edi] + sub ebx, [edx+STREAM.in_top] + jb @F + sub ecx, ebx +@@: + shr ecx, 2 + cld + rep movsd + xor eax,eax + ret +.fail: + or eax, -1 + ret +endp + +; for stream buffers only + +align 4 +proc wave_out stdcall, str:dword,src:dword,size:dword + locals + state_saved dd ? + fpu_state rb 528 + endl + + mov edx, [str] + mov eax, [edx+STREAM.format] + test eax, PCM_STATIC+PCM_RING + jnz .fail + + cmp ax, PCM_ALL + je .fail mov esi,[src] test esi, esi @@ -506,43 +656,428 @@ proc set_buffer stdcall, str:dword,src:dword,offs:dword,size:dword cmp esi, new_app_base jb .fail - mov edi, [offs] - mov ecx, 0x8000 + mov [state_saved], 0 - sub ecx, edi - jbe .seg_1 +.main_loop: + mov edx, [str] + mov ebx, [size] + test ebx, ebx + jz .done + + cmp [edx+STREAM.flags], SND_STOP + jne .fill + + mov edi, [edx+STREAM.in_base] + mov ecx, 128/4 + mov eax, [edx+STREAM.r_silence] + cld + rep stosd + + mov ecx, [edx+STREAM.in_size] + sub ecx, 128 + mov [edx+STREAM.in_wp], edi + mov [edx+STREAM.in_rp], edi + mov [edx+STREAM.in_count], 0 + mov [edx+STREAM.in_free], ecx + + mov eax,[edx+STREAM.out_base] + mov [edx+STREAM.out_wp], eax + mov [edx+STREAM.out_rp], eax + mov [edx+STREAM.out_count], 0 +.fill: + mov ecx, [edx+STREAM.in_free] + test ecx, ecx + jz .wait + + cmp ecx, ebx + jbe @F + + mov ecx, ebx +@@: sub [size], ecx - jb .fail + add [edx+STREAM.in_count], ecx + sub [edx+STREAM.in_free], ecx - add edi, [edx+STREAM.base] - add edi, 0x1000 shr ecx, 2 + mov edi, [edx+STREAM.in_wp] + mov esi, [src] cld rep movsd - jmp @F -.seg_1: - add edi, [edx+STREAM.base] - add edi, 0x1000 -@@: - add edi, 0x1000 - mov ecx, [size] - test ecx, ecx - jz .done - cmp ecx, 0x8000 - ja .fail - shr ecx, 2 - rep movsd + mov [src], esi + cmp edi, [edx+STREAM.in_top] + jb @F + sub edi, [edx+STREAM.in_size] +@@: + mov [edx+STREAM.in_wp], edi + + cmp [edx+STREAM.out_count], 32768 + jae .skip + + cmp [state_saved], 0 + jne @F + lea eax, [fpu_state+15] + and eax, -16 + call FpuSave + mov [state_saved], 1 +@@: + stdcall refill, edx +.skip: + mov ebx, [str] + mov [ebx+STREAM.flags], SND_PLAY + cmp [eng_state], SND_PLAY + je .main_loop + + stdcall dev_play, [hSound] + mov [eng_state], SND_PLAY + jmp .main_loop +.wait: + mov edx, [str] + mov eax, [edx+STREAM.notify_event] + mov ebx, [edx+STREAM.notify_id] + call WaitEvent ;eax ebx + jmp .main_loop .done: + cmp [state_saved], 1 + jne @F + + lea eax, [fpu_state+15] + and eax, -16 + call FpuRestore +@@: + xor eax, eax + ret +.fail: + or eax, -1 + ret +endp + +; both static and stream +; reset all but not clear buffers + + +; flags reserved +; RESET_INPUT equ 1 ;reserved reset and clear input buffer +; RESET_OUTPUT equ 2 ;reserved reset and clear output buffer +; RESET_ALL equ 3 + + +align 4 +proc ResetBuffer stdcall, str:dword, flags:dword + + mov edx, [str] + mov [edx+STREAM.flags], SND_STOP + + mov edi, [edx+STREAM.in_base] + mov ecx, 128/4 + mov eax, [edx+STREAM.r_silence] + cld + rep stosd + + mov [edx+STREAM.in_wp], edi + mov [edx+STREAM.in_rp], edi + + mov [edx+STREAM.in_count], 0 + mov eax, [edx+STREAM.in_size] + sub eax, 128 + mov [edx+STREAM.in_free], eax + + xor eax, eax + mov ebx,[edx+STREAM.out_base] + mov [edx+STREAM.out_wp], ebx + mov [edx+STREAM.out_rp], ebx + mov [edx+STREAM.out_count], eax + ret +.fail: + or eax, -1 + ret +endp + +; for static buffers only + +align 4 +proc SetBufferPos stdcall, str:dword, pos:dword + + mov edx, [str] + test [edx+STREAM.format], PCM_OUT+PCM_RING + jnz .fail + + mov [edx+STREAM.flags], SND_STOP + + mov eax, [pos] + add eax, [edx+STREAM.in_base] + mov ebx, [edx+STREAM.in_top] + add eax, 128 + + cmp eax, ebx + jae .fail + + mov [edx+STREAM.in_rp], eax + sub ebx, eax + mov [edx+STREAM.in_count], ebx + xor eax, eax + ret +.fail: + or eax, -1 + ret +endp + +align 4 +proc GetBufferPos stdcall, str:dword + + mov edx, [str] + test [edx+STREAM.format], PCM_OUT+PCM_RING + jnz .fail + + mov ebx, [edx+STREAM.in_rp] + xor eax, eax + ret +.fail: + xor ebx,ebx + or eax, -1 + ret +endp + +; both + +align 4 +proc SetBufferVol stdcall, str:dword,l_vol:dword,r_vol:dword + + mov edx, [str] + stdcall set_vol_param,[l_vol],[r_vol],[edx+STREAM.pan] + ret +endp + +proc set_vol_param stdcall, l_vol:dword,r_vol:dword,pan:dword + locals + _600 dd ? + _32767 dd ? + state rb 108 + endl + + mov [_600], 0x44160000 ;600.0 + mov [_32767], 32767 + + lea ebx, [state] + fnsave [ebx] + + movq mm0, qword [l_vol] + pminsw mm0, qword [vol_max] + pmaxsw mm0, qword [vol_min] + movq qword [l_vol], mm0 + movq qword [edx+STREAM.l_vol], mm0 + + movd mm1,[pan] + pminsw mm1, qword [pan_max] + pmaxsw mm1, qword [vol_min] + movd [edx+STREAM.pan], mm1 + + cmp word [edx+STREAM.pan], 0 + jl @F + + psubsw mm0,mm1 + pminsw mm0, qword [vol_max] + pmaxsw mm0, qword [vol_min] + movd [l_vol],mm0 + jmp .calc_amp +@@: + punpckhdq mm0,mm0 + paddsw mm0,mm1 + pminsw mm0, qword [vol_max] + pmaxsw mm0, qword [vol_min] + movd [r_vol], mm0 +.calc_amp: + emms + fild word [l_vol] + + call .calc + + fistp word [edx+STREAM.l_amp] + fstp st0 + + fild word [r_vol] + + call .calc + + fistp word [edx+STREAM.r_amp] + fstp st0 + + fnclex + lea ebx, [state] + frstor [ebx] + xor eax, eax inc eax ret -.fail: +.calc: + fdiv dword [_600] + fld st0 + frndint + fxch st1 + fsub st, st1 + f2xm1 + fld1 + faddp st1, st0 + fscale + fimul dword [_32767] + ret 0 +endp + +align 4 +proc GetBufferVol stdcall, str:dword,p_lvol:dword,p_rvol:dword + + mov edx, [str] + mov eax, [p_lvol] + movsx ecx, word [edx+STREAM.l_vol] + mov [eax], ecx + + mov eax, [p_rvol] + movsx ecx, word [edx+STREAM.r_vol] + mov [eax], ecx xor eax, eax ret endp +align 4 +proc SetBufferPan stdcall, str:dword,pan:dword + + mov edx, [str] + stdcall set_vol_param,[edx+STREAM.l_vol],\ + [edx+STREAM.r_vol],[pan] + ret +endp + +; for static and ring buffers only + +align 4 +proc play_buffer stdcall, str:dword, flags:dword + locals + fpu_state rb 528 + endl + + mov ebx, [str] + mov eax, [ebx+STREAM.format] + test eax, PCM_OUT + jnz .fail + + cmp ax, PCM_ALL + je .fail + + mov [ebx+STREAM.flags], SND_PLAY + cmp [eng_state], SND_PLAY + je .done + + stdcall dev_play, [hSound] + mov [eng_state], SND_PLAY +.done: + test [flags], PLAY_SYNC + jz @F + + mov edx, [str] +.wait: + mov eax, [edx+STREAM.notify_event] + mov ebx, [edx+STREAM.notify_id] + call WaitEvent ;eax ebx + + mov edx, [str] + cmp [edx+STREAM.flags], SND_STOP + jne .wait +@@: + xor eax, eax + ret +.fail: + or eax, -1 + ret +endp + +; for static buffers only + +align 4 +proc stop_buffer stdcall, str:dword + + mov edx, [str] + test [edx+STREAM.format], PCM_STATIC+PCM_RING + jz .fail + + mov [edx+STREAM.flags], SND_STOP + +; stdcall [ServiceHandler], [hSound], dword DEV_STOP, 0 + + mov eax, [edx+STREAM.notify_event] + mov ebx, [edx+STREAM.notify_id] + call ClearEvent ;eax ebx + + xor eax, eax + ret +.fail: + or eax, -1 + ret +endp + +; parm +; eax= mix_list + +align 4 +do_mix_list: + + xor edx, edx + mov esi, str.fd-FD_OFFSET + mov ebx, [esi+STREAM.str_fd] +@@: + cmp ebx, esi + je .done + + cmp [ebx+STREAM.magic], 'WAVE' + jne .next + + cmp [ebx+STREAM.size], STREAM_SIZE + jne .next + + cmp [ebx+STREAM.flags], SND_PLAY; + jne .next + + mov ecx, [ebx+STREAM.out_count] + test ecx, ecx + jnz .l1 + + test [ebx+STREAM.format], PCM_RING + jnz .next + mov [ebx+STREAM.flags], SND_STOP + jmp .next +.l1: + cmp ecx, 512 + jae .add_buff + + mov edi, [ebx+STREAM.out_rp] + add edi, ecx + sub ecx, 512 + neg ecx + push eax + xor eax, eax + cld + rep stosb + pop eax + + mov [ebx+STREAM.out_count], 512 + +.add_buff: + mov ecx, [ebx+STREAM.out_rp] + mov [eax],ecx + mov edi, dword [ebx+STREAM.l_amp] + mov [eax+4], edi + add [ebx+STREAM.out_rp], 512 + sub [ebx+STREAM.out_count], 512 + + add eax, 8 + inc edx +.next: + mov ebx, [ebx+STREAM.str_fd] + jmp @B +.done: + mov eax, edx + ret + align 4 prepare_playlist: @@ -562,8 +1097,6 @@ prepare_playlist: cmp [edi+STREAM.flags], SND_PLAY; jne .next - cmp [edi+STREAM.work_count], 16384 - jb .next mov [play_list+edx], edi inc [play_count] @@ -629,6 +1162,26 @@ proc dev_play stdcall, hsrv:dword ret endp +if 0 +align 4 +dword2str: + mov esi, hex_buff + mov ecx, -8 +@@: + rol eax, 4 + mov ebx, eax + and ebx, 0x0F + mov bl, [ebx+hexletters] + mov [8+esi+ecx], bl + inc ecx + jnz @B + ret + +hexletters db '0123456789ABCDEF' +hex_buff db 8 dup(0),13,10,0 + +end if + include 'mixer.asm' include 'mix_mmx.inc' include 'mix_sse2.inc' @@ -639,68 +1192,72 @@ include 'mix_sse2.inc' align 16 resampler_params: - ;r_size r_end r_dt resampler_func - dd 0,0,0,0 ; 0 PCM_ALL - dd 16384, 0, 0, copy_stream ; 1 PCM_2_16_48 - dd 16384, 0, 0, m16_stereo ; 2 PCM_1_16_48 + ;r_size r_dt resampler_func + dd 0,0,0 ; 0 PCM_ALL + dd 16384, 0, copy_stream ; 1 PCM_2_16_48 + dd 16384, 0, m16_stereo ; 2 PCM_1_16_48 - dd 16384, 0x08000000, 30109, resample_2 ; 3 PCM_2_16_44 - dd 8192, 0x08000000, 30109, resample_1 ; 4 PCM_1_16_44 + dd 16384, 30109, resample_2 ; 3 PCM_2_16_44 + dd 8192, 30109, resample_1 ; 4 PCM_1_16_44 - dd 16384, 0x08000000, 21846, resample_2 ; 5 PCM_2_16_32 - dd 8192, 0x08000000, 21846, resample_1 ; 6 PCM_1_16_32 + dd 16384, 21846, resample_2 ; 5 PCM_2_16_32 + dd 8192, 21846, resample_1 ; 6 PCM_1_16_32 - dd 16384, 0x08000000, 16384, resample_2 ; 7 PCM_2_16_24 - dd 8192, 0x08000000, 16384, resample_1 ; 8 PCM_1_16_24 + dd 16384, 16384, resample_2 ; 7 PCM_2_16_24 + dd 8192, 16384, resample_1 ; 8 PCM_1_16_24 - dd 8192, 0x04000000, 15052, resample_2 ; 9 PCM_2_16_22 - dd 4096, 0x04000000, 15052, resample_1 ;10 PCM_1_16_22 + dd 8192, 15052, resample_2 ; 9 PCM_2_16_22 + dd 4096, 15052, resample_1 ;10 PCM_1_16_22 - dd 8192, 0x04000000, 10923, resample_2 ;11 PCM_2_16_16 - dd 4096, 0x04000000, 10923, resample_1 ;12 PCM_1_16_16 + dd 8192, 10923, resample_2 ;11 PCM_2_16_16 + dd 4096, 10923, resample_1 ;12 PCM_1_16_16 - dd 8192, 0x04000000, 8192, resample_2 ;13 PCM_2_16_12 - dd 4096, 0x04000000, 8192, resample_1 ;14 PCM_1_16_12 + dd 8192, 8192, resample_2 ;13 PCM_2_16_12 + dd 4096, 8192, resample_1 ;14 PCM_1_16_12 - dd 4096, 0x02000000, 7527, resample_2 ;15 PCM_2_16_11 - dd 2048, 0x02000000, 7527, resample_1 ;16 PCM_1_16_11 + dd 4096, 7527, resample_2 ;15 PCM_2_16_11 + dd 2048, 7527, resample_1 ;16 PCM_1_16_11 - dd 4096, 0x02000000, 5462, resample_2 ;17 PCM_2_16_8 - dd 2048, 0x02000000, 5462, resample_1 ;18 PCM_1_16_8 + dd 4096, 5462, resample_2 ;17 PCM_2_16_8 + dd 2048, 5462, resample_1 ;18 PCM_1_16_8 - dd 16384, 0, 0, s8_stereo ;19 PCM_2_8_48 - dd 8192, 0, 0, m8_stereo ;20 PCM_1_8_48 + dd 16384, 0, s8_stereo ;19 PCM_2_8_48 + dd 8192, 0, m8_stereo ;20 PCM_1_8_48 - dd 8192, 0x08000000, 30109, resample_28 ;21 PCM_2_8_44 - dd 4096, 0x08000000, 30109, resample_18 ;22 PCM_1_8_44 + dd 8192, 30109, resample_28 ;21 PCM_2_8_44 + dd 4096, 30109, resample_18 ;22 PCM_1_8_44 - dd 8192, 0x08000000, 21846, resample_28 ;23 PCM_2_8_32 - dd 4096, 0x08000000, 21846, resample_18 ;24 PCM_1_8_32 + dd 8192, 21846, resample_28 ;23 PCM_2_8_32 + dd 4096, 21846, resample_18 ;24 PCM_1_8_32 - dd 8192, 0x08000000, 16384, resample_28 ;25 PCM_2_8_24 - dd 4096, 0x08000000, 16384, resample_18 ;26 PCM_1_8_24 + dd 8192, 16384, resample_28 ;25 PCM_2_8_24 + dd 4096, 16384, resample_18 ;26 PCM_1_8_24 - dd 4096, 0x04000000, 15052, resample_28 ;27 PCM_2_8_22 - dd 2048, 0x04000000, 15052, resample_18 ;28 PCM_1_8_22 + dd 4096, 15052, resample_28 ;27 PCM_2_8_22 + dd 2048, 15052, resample_18 ;28 PCM_1_8_22 - dd 4096, 0x04000000, 10923, resample_28 ;29 PCM_2_8_16 - dd 2048, 0x04000000, 10923, resample_18 ;30 PCM_1_8_16 + dd 4096, 10923, resample_28 ;29 PCM_2_8_16 + dd 2048, 10923, resample_18 ;30 PCM_1_8_16 - dd 4096, 0x04000000, 8192, resample_28 ;31 PCM_2_8_12 - dd 2048, 0x04000000, 8192, resample_18 ;32 PCM_1_8_12 + dd 4096, 8192, resample_28 ;31 PCM_2_8_12 + dd 2048, 8192, resample_18 ;32 PCM_1_8_12 - dd 2048, 0x02000000, 7527, resample_28 ;33 PCM_2_8_11 - dd 1024, 0x02000000, 7527, resample_18 ;34 PCM_1_8_11 + dd 2048, 7527, resample_28 ;33 PCM_2_8_11 + dd 1024, 7527, resample_18 ;34 PCM_1_8_11 - dd 2048, 0x02000000, 5462, resample_28 ;35 PCM_2_8_8 - dd 1024, 0x02000000, 5462, resample_18 ;36 PCM_1_8_8 + dd 2048, 5462, resample_28 ;35 PCM_2_8_8 + dd 1024, 5462, resample_18 ;36 PCM_1_8_8 m7 dw 0x8000,0x8000,0x8000,0x8000 mm80 dq 0x8080808080808080 mm_mask dq 0xFF00FF00FF00FF00 +vol_max dd 0x00000000,0x00000000 +vol_min dd 0x0000D8F0,0x0000D8F0 +pan_max dd 0x00002710,0x00002710 + ;stream_map dd 0xFFFF ; 16 -version dd 0x00030003 +version dd (4 shl 16) or (SOUND_VERSION and 0xFFFF) szInfinity db 'INFINITY',0 szSound db 'SOUND',0 @@ -712,6 +1269,8 @@ msgStop db 'Stop',13,10,0 msgUser db 'User callback',13,10,0 msgMem db 'Not enough memory',13,10,0 msgDestroy db 'Destroy sound buffer', 13,10,0 +msgWaveout db 'Play waveout', 13,10,0 +msgSetVolume db 'Set volume',13,10,0 end if section '.data' data readable writable align 16 @@ -720,6 +1279,7 @@ play_list rd 16 mix_input rd 16 play_count rd 1 hSound rd 1 +eng_state rd 1 mix_buff rd 1 mix_buff_map rd 1 str.fd rd 1 diff --git a/kernel/trunk/drivers/main.inc b/kernel/trunk/drivers/main.inc index 9a52b23d2b..c0f9a4c9cd 100644 --- a/kernel/trunk/drivers/main.inc +++ b/kernel/trunk/drivers/main.inc @@ -1,6 +1,6 @@ ; -; This file is part of the Infinity sound AC97 driver. -; (C) copyright Serge 2006 +; This file is part of the Infinity sound driver. +; (C) copyright Serge 2006-2007 ; email: infinity_sound@mail.ru ; ; This program is free software; you can redistribute it and/or modify @@ -13,6 +13,20 @@ ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. + +SOUND_VERSION equ 0x01000100 + +PLAY_SYNC equ 0x80000000 + + +PCM_ALL equ 0 + +PCM_OUT equ 0x08000000 +PCM_RING equ 0x10000000 +PCM_STATIC equ 0x20000000 +PCM_FLOAT equ 0x40000000 ;reserved +PCM_FILTER equ 0x80000000 ;reserved + PCM_2_16_48 equ 1 PCM_1_16_48 equ 2 @@ -37,47 +51,53 @@ PCM_1_16_12 equ 14 PCM_2_16_11 equ 15 PCM_1_16_11 equ 16 -PCM_2_8_48 equ 17 -PCM_1_8_48 equ 18 +PCM_2_16_8 equ 17 +PCM_1_16_8 equ 18 -PCM_2_8_44 equ 19 -PCM_1_8_44 equ 20 +PCM_2_8_48 equ 19 +PCM_1_8_48 equ 20 -PCM_2_8_32 equ 21 -PCM_1_8_32 equ 22 +PCM_2_8_44 equ 21 +PCM_1_8_44 equ 22 -PCM_2_8_24 equ 23 -PCM_1_8_24 equ 24 +PCM_2_8_32 equ 23 +PCM_1_8_32 equ 24 -PCM_2_8_22 equ 25 -PCM_1_8_22 equ 26 +PCM_2_8_24 equ 25 +PCM_1_8_24 equ 26 -PCM_2_8_16 equ 27 -PCM_1_8_16 equ 28 +PCM_2_8_22 equ 27 +PCM_1_8_22 equ 28 -PCM_2_8_12 equ 29 -PCM_1_8_12 equ 30 +PCM_2_8_16 equ 29 +PCM_1_8_16 equ 30 -PCM_2_8_11 equ 31 -PCM_1_8_11 equ 32 +PCM_2_8_12 equ 31 +PCM_1_8_12 equ 32 -SND_PLAY equ 1 -SND_STOP equ 2 +PCM_2_8_11 equ 33 +PCM_1_8_11 equ 34 -; struc SND_DEV -;{ .magic dd 0 -; .size dd 0 -; .count dd 0 -; dd 0 -; .snd_buff dd 16 dup (0) -;} - -;virtual at 0 -; SND_DEV SND_DEV -;end virtual - -;SND_DEV_SIZE equ 80 +PCM_2_8_8 equ 35 +PCM_1_8_8 equ 36 +SRV_GETVERSION equ 0 +SND_CREATE_BUFF equ 1 +SND_DESTROY_BUFF equ 2 +SND_SETFORMAT equ 3 +SND_GETFORMAT equ 4 +SND_RESET equ 5 +SND_SETPOS equ 6 +SND_GETPOS equ 7 +SND_SETBUFF equ 8 +SND_OUT equ 9 +SND_PLAY equ 10 +SND_STOP equ 11 +SND_SETVOLUME equ 12 +SND_GETVOLUME equ 13 +SND_SETPAN equ 14 +SND_GETPAN equ 15 +SND_GETBUFFSIZE equ 16 struc STREAM { @@ -94,32 +114,35 @@ struc STREAM .format dd ? .flags dd ? - .work_buff dd ? - .work_read dd ? - .work_write dd ? - .work_count dd ? - .work_top dd ? + .out_base dd ? + .out_wp dd ? + .out_rp dd ? + .out_count dd ? + .out_top dd ? + .r_size dd ? - .r_end dd ? .r_dt dd ? .r_silence dd ? - - .base dd ? - .limit dd ? - .seg_0 dd ? - .lim_0 dd ? - .seg_1 dd ? - .lim_1 dd ? - .curr_seg dd ? - - .buff_size dd ? - .notify_off1 dd ? - .notify_off2 dd ? -; .notify_task dd ? .resample dd ? + .l_vol dd ? + .r_vol dd ? + .l_amp dw ? + .r_amp dw ? + .pan dd ? + + .in_base dd ? + .in_size dd ? + .in_wp dd ? + .in_rp dd ? + .in_count dd ? + .in_free dd ? + .in_top dd ? + + .notify_event dd ? + .notify_id dd ? } -STREAM_SIZE equ 31*4 +STREAM_SIZE equ 34*4 FD_OFFSET equ 24 virtual at 0 diff --git a/kernel/trunk/drivers/mixer.asm b/kernel/trunk/drivers/mixer.asm index 95003e3bed..2dbdecad64 100644 --- a/kernel/trunk/drivers/mixer.asm +++ b/kernel/trunk/drivers/mixer.asm @@ -13,93 +13,64 @@ ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. + +align 4 + +mix_list rq 32 + align 4 proc new_mix stdcall, output:dword locals - mixCounter dd ? - mixIndex dd ? - streamIndex dd ? - inputCount dd ? - main_count dd ? - blockCount dd ? - mix_out dd ? + main_count rd 1 + fpu_state rb 528 ;512+16 endl + mov [main_count], 32 call prepare_playlist - cmp [play_count], 0 - je .exit + je .clear + + lea eax, [fpu_state+16] + and eax, -16 ;must be 16b aligned call FpuSave - mov [main_count], 32; -.l00: - mov [mix_buff_map], 0x0000FFFF; - xor eax, eax - mov [mixCounter], eax - mov [mixIndex],eax - mov [streamIndex], eax; - mov ebx, [play_count] - mov [inputCount], ebx -.l0: - mov ecx, 4 -.l1: - mov ebx, [streamIndex] - mov esi, [play_list+ebx*4] - mov eax, [esi+STREAM.work_read] - add [esi+STREAM.work_read], 512 - - mov ebx, [mixIndex] - mov [mix_input+ebx*4], eax - inc [mixCounter] - inc [mixIndex] - inc [streamIndex] - dec [inputCount] - jz .m2 - - dec ecx - jnz .l1 - - cmp [mixCounter], 4 - jnz .m2 - - stdcall mix_4_1, [mix_input],[mix_input+4],[mix_input+8],[mix_input+12] - sub [mixIndex],4 - mov ebx, [mixIndex] - mov [mix_input+ebx*4], eax - inc [mixIndex] - mov [mixCounter], 0 - - cmp [inputCount], 0 - jnz .l0 -.m2: - cmp [mixIndex], 1 - jne @f - stdcall copy_mem, [output], [mix_input] - jmp .m3 -@@: - cmp [mixIndex], 2 - jne @f - stdcall mix_2_1, [output], [mix_input], [mix_input+4] - jmp .m3 -@@: - cmp [mixIndex], 3 - jne @f - stdcall mix_3_1, [output],[mix_input],[mix_input+4],[mix_input+8] - jmp .m3 -@@: - stdcall final_mix, [output],[mix_input],[mix_input+4],[mix_input+8], [mix_input+12] -.m3: - add [output],512 - - dec [main_count] - jnz .l00 call update_stream - emms +.mix: + lea eax, [mix_list] + call do_mix_list + test eax, eax + je .done + + ; cmp eax, 1 + ; je .copy + + lea ebx, [mix_list] + stdcall mix_all, [output], ebx, eax +@@: + add [output], 512 + dec [main_count] + jnz .mix +.exit: + lea eax, [fpu_state+16] + and eax, -16 call FpuRestore ret -.exit: +.copy: + lea eax, [mix_list] + stdcall copy_mem, [output], [eax] + jmp @B +.done: + mov ecx, [main_count] + shl ecx, 7 ;ecx*= 512/4 + mov edi, [output] - mov ecx, 0x1000 + xor eax, eax + cld + rep stosd + jmp .exit +.clear: + mov edi, [output] + mov ecx, 4096 xor eax, eax cld rep stosd @@ -120,81 +91,62 @@ proc update_stream mov edx, [stream_index] mov esi, [play_list+edx*4] - mov eax, [esi+STREAM.work_read] - cmp eax, [esi+STREAM.work_top] + mov eax, [esi+STREAM.out_rp] + cmp eax, [esi+STREAM.out_top] jb @f sub eax, 64*1024 @@: - mov [esi+STREAM.work_read], eax + mov [esi+STREAM.out_rp], eax - cmp [esi+STREAM.format], PCM_2_16_48 + cmp word [esi+STREAM.format], PCM_2_16_48 je .copy - sub [esi+STREAM.work_count], 16384 + cmp [esi+STREAM.out_count], 16384 + ja .skip - cmp [esi+STREAM.work_count], 32768 - ja @f + test [esi+STREAM.format], PCM_RING + jnz .ring stdcall refill, esi -@@: +.skip: inc [stream_index] dec [play_count] jnz .l1 ret + +.ring: + stdcall refill_ring, esi + jmp .skip .copy: mov ebx, esi - mov edi, [ebx+STREAM.work_write] - cmp edi, [ebx+STREAM.work_top] + mov edi, [ebx+STREAM.out_wp] + cmp edi, [ebx+STREAM.out_top] jb @f sub edi, 64*1024 - mov [ebx+STREAM.work_write], edi + mov [ebx+STREAM.out_wp], edi @@: - mov esi, [ebx+STREAM.curr_seg] + mov esi, [ebx+STREAM.in_rp] mov ecx, 16384/4 cld rep movsd - mov [ebx+STREAM.work_write], edi + mov [ebx+STREAM.out_wp], edi - cmp esi, [ebx+STREAM.lim_0] + cmp esi, [ebx+STREAM.in_top] jb @f - mov esi, [ebx+STREAM.seg_0] - mov eax, [ebx+STREAM.lim_0] - xchg esi, [ebx+STREAM.seg_1] - xchg eax, [ebx+STREAM.lim_1] - mov [ebx+STREAM.seg_0], esi - mov [ebx+STREAM.lim_0], eax + sub esi, 0x10000 @@: - mov [ebx+STREAM.curr_seg], esi + mov [ebx+STREAM.in_rp], esi - xor ecx, ecx - cmp esi, [ebx+STREAM.notify_off2] - je @f - - mov ecx,0x8000 - cmp esi, [ebx+STREAM.notify_off1] - je @f - - inc [stream_index] - dec [play_count] - jnz .l1 - ret -@@: - mov [ev_code], 0xFF000001 - mov [ev_offs], ecx - mov eax, [ebx+STREAM.pid] - - lea edx, [ev_code] - push ebx - stdcall SendEvent, eax, edx - pop ebx test eax, eax - jnz .l_end - - not eax - mov [ebx+STREAM.pid], eax ;-1 + jz .l_end + mov eax, [ebx+STREAM.notify_event] + mov ebx, [ebx+STREAM.notify_id] + mov ecx, EVENT_WATCHED + xor edx, edx + call RaiseEvent ;eax, ebx, ecx, edx .l_end: inc [stream_index] dec [play_count] @@ -205,72 +157,186 @@ endp align 4 proc refill stdcall, str:dword locals - ev_code dd ? ;EVENT - ev_offs dd ? - rd 4 + r_size rd 1 + event rd 6 endl mov ebx, [str] - mov edi, [ebx+STREAM.work_write] - cmp edi, [ebx+STREAM.work_top] + mov edi, [ebx+STREAM.out_wp] + cmp edi, [ebx+STREAM.out_top] jb @F - sub edi, 64*1024 - mov [ebx+STREAM.work_write], edi + sub edi, 0x10000 + mov [ebx+STREAM.out_wp], edi @@: - mov esi, [ebx+STREAM.curr_seg] - mov edi, [ebx+STREAM.work_write] + mov eax, [ebx+STREAM.in_count] + test eax, eax + jz .done + + mov ecx, [ebx+STREAM.r_size] + cmp eax, ecx + jle @F + + mov eax, ecx +@@: + mov ecx, eax + cmp word [ebx+STREAM.format], PCM_1_16_8 + ja @F + + shr eax, 1 ;two channles +@@: + test [ebx+STREAM.format], 1 ;even formats mono + jz @F + + shr eax, 1 ;eax= samples +@@: + shl eax, 15 ;eax*=32768 =r_end + + mov [r_size], ecx + + mov esi, [ebx+STREAM.in_rp] + mov edi, [ebx+STREAM.out_wp] stdcall [ebx+STREAM.resample], edi, esi, \ - [ebx+STREAM.r_dt],[ebx+STREAM.r_size],[ebx+STREAM.r_end] + [ebx+STREAM.r_dt], ecx, eax mov ebx, [str] - add [ebx+STREAM.work_count], eax; - add [ebx+STREAM.work_write], eax; + add [ebx+STREAM.out_count], eax; + add [ebx+STREAM.out_wp], eax; - mov eax, [ebx+STREAM.curr_seg] - add eax, [ebx+STREAM.r_size] - cmp eax, [ebx+STREAM.lim_0] + mov eax, [ebx+STREAM.in_rp] + mov ecx, [r_size] + add eax, ecx + add [ebx+STREAM.in_free], ecx + sub [ebx+STREAM.in_count], ecx + + cmp eax, [ebx+STREAM.in_top] jb @f - mov esi, [ebx+STREAM.seg_0] - lea edi, [esi-128] - add esi, 0x7F80 - mov ecx, 128/4 - cld - rep movsd - - mov eax, [ebx+STREAM.seg_0] - mov ecx, [ebx+STREAM.lim_0] - xchg eax, [ebx+STREAM.seg_1] - xchg ecx, [ebx+STREAM.lim_1] - mov [ebx+STREAM.seg_0], eax - mov [ebx+STREAM.lim_0], ecx + sub eax, [ebx+STREAM.in_size] @@: - mov [ebx+STREAM.curr_seg], eax + mov [ebx+STREAM.in_rp], eax - xor ecx, ecx - cmp eax, [ebx+STREAM.notify_off2] - je @f - - mov ecx,0x8000 - cmp eax, [ebx+STREAM.notify_off1] - je @f - ret -@@: - mov [ev_code], 0xFF000001 - mov [ev_offs], ecx - mov eax, [ebx+STREAM.pid] - - lea edx, [ev_code] - push ebx - stdcall SendEvent, eax, edx - pop ebx +.done: + mov eax, [ebx+STREAM.notify_event] test eax, eax - jnz @F - not eax - mov [ebx+STREAM.pid], eax ;-1 + jz .exit + + mov ebx, [ebx+STREAM.notify_id] + mov ecx, EVENT_WATCHED + xor edx, edx + call RaiseEvent ;eax, ebx, ecx, edx +.exit: + ret +endp + +align 4 +proc refill_ring stdcall, str:dword + locals + event rd 6 + endl + + mov ebx, [str] + mov edi, [ebx+STREAM.out_wp] + cmp edi, [ebx+STREAM.out_top] + jb @F + sub edi, 0x10000 + mov [ebx+STREAM.out_wp], edi @@: + mov ecx, [ebx+STREAM.r_size] + mov eax, ecx + cmp word [ebx+STREAM.format], PCM_1_16_8 + ja @F + + shr eax, 1 ;two channles +@@: + test [ebx+STREAM.format], 1 ;even formats mono + jz @F + + shr eax, 1 ;eax= samples +@@: + shl eax, 15 ;eax*=32768 =r_end + + mov esi, [ebx+STREAM.in_rp] + mov edi, [ebx+STREAM.out_wp] + + stdcall [ebx+STREAM.resample], edi, esi, \ + [ebx+STREAM.r_dt], ecx, eax + + mov ebx, [str] + + add [ebx+STREAM.out_count], eax; + add [ebx+STREAM.out_wp], eax; + + mov eax, [ebx+STREAM.in_rp] + mov ecx, [ebx+STREAM.r_size] + add eax, ecx + add [ebx+STREAM.in_free], ecx + sub [ebx+STREAM.in_count], ecx + + cmp eax, [ebx+STREAM.in_top] + jb @f + + sub eax, [ebx+STREAM.in_size] +@@: + mov [ebx+STREAM.in_rp], eax + + sub eax, [ebx+STREAM.in_base] + sub eax, 128 + lea edx, [event] + + mov dword [edx], RT_INP_EMPTY + mov dword [edx+4], 0 + mov dword [edx+8], ebx + mov dword [edx+12], eax + + mov eax, [ebx+STREAM.notify_event] + test eax, eax + jz .exit + + mov ebx, [ebx+STREAM.notify_id] + xor ecx, ecx + call RaiseEvent ;eax, ebx, ecx, edx +.exit: + ret +endp + +align 4 +proc mix_all stdcall, dest:dword, list:dword, count:dword + + mov edi, [dest] + mov ebx, 64 +.mix: + mov edx, [list] + mov ecx, [count] + + mov eax, [edx] + movq mm0, [eax] + movd mm1, [edx+4] + punpckldq mm1,mm1 + pmulhw mm0, mm1 + psllw mm0, 1 + +.mix_loop: + add dword [edx], 8 + add edx, 8 + dec ecx + jz @F + + mov eax, [edx] + movq mm1, [eax] + movd mm2, [edx+4] + punpckldq mm2,mm2 + pmulhw mm1, mm2 + psllw mm1, 1 + paddsw mm0, mm1 + jmp .mix_loop +@@: + movq [edi], mm0 + add edi, 8 + dec ebx + jnz .mix + ret endp @@ -282,14 +348,14 @@ proc resample_1 stdcall, dest:dword,src:dword,\ ; src equ esp+12 ; r_dt equ esp+16 ; r_size equ esp+20 -;r_end equ esp+24 +; r_end equ esp+24 mov edi, [dest] mov edx, [src] sub edx, 32*2 mov eax, 16 -align 16 +align 4 .l1: mov ecx, eax mov esi, eax @@ -342,7 +408,7 @@ proc resample_18 stdcall, dest:dword,src:dword,\ mov esi, 16 -align 16 +align 4 .l1: mov ecx, esi mov eax, esi @@ -413,7 +479,7 @@ proc resample_2 stdcall, dest:dword,src:dword,\ mov eax, 16 emms -align 16 +align 4 .l1: mov ecx, eax mov esi, eax @@ -466,7 +532,7 @@ proc resample_28 stdcall, dest:dword,src:dword,\ movq mm7,[mm80] movq mm6,[mm_mask] -align 16 +align 4 .l1: mov ecx, eax mov esi, eax @@ -840,6 +906,8 @@ proc mix_4_1 stdcall, str0:dword, str1:dword,\ and eax, eax jz .err + mov [output], eax + mov edi, eax mov eax, [str0] mov ebx, [str1] @@ -939,4 +1007,100 @@ proc memcpy ret endp +if 0 + +align 4 +proc new_mix stdcall, output:dword + locals + mixCounter dd ? + mixIndex dd ? + streamIndex dd ? + inputCount dd ? + main_count dd ? + blockCount dd ? + mix_out dd ? + endl + + call prepare_playlist + + cmp [play_count], 0 + je .exit + call FpuSave + mov [main_count], 32; +.l00: + mov [mix_buff_map], 0x0000FFFF; + xor eax, eax + mov [mixCounter], eax + mov [mixIndex],eax + mov [streamIndex], eax; + mov ebx, [play_count] + mov [inputCount], ebx +.l0: + mov ecx, 4 +.l1: + mov ebx, [streamIndex] + mov esi, [play_list+ebx*4] + mov eax, [esi+STREAM.work_read] + add [esi+STREAM.work_read], 512 + + mov ebx, [mixIndex] + mov [mix_input+ebx*4], eax + inc [mixCounter] + inc [mixIndex] + inc [streamIndex] + dec [inputCount] + jz .m2 + + dec ecx + jnz .l1 + + cmp [mixCounter], 4 + jnz .m2 + + stdcall mix_4_1, [mix_input],[mix_input+4],[mix_input+8],[mix_input+12] + sub [mixIndex],4 + mov ebx, [mixIndex] + mov [mix_input+ebx*4], eax + inc [mixIndex] + mov [mixCounter], 0 + + cmp [inputCount], 0 + jnz .l0 +.m2: + cmp [mixIndex], 1 + jne @f + stdcall copy_mem, [output], [mix_input] + jmp .m3 +@@: + cmp [mixIndex], 2 + jne @f + stdcall mix_2_1, [output], [mix_input], [mix_input+4] + jmp .m3 +@@: + cmp [mixIndex], 3 + jne @f + stdcall mix_3_1, [output],[mix_input],[mix_input+4],[mix_input+8] + jmp .m3 +@@: + stdcall final_mix, [output],[mix_input],[mix_input+4],[mix_input+8], [mix_input+12] +.m3: + add [output],512 + + dec [main_count] + jnz .l00 + + call update_stream + emms + call FpuRestore + ret +.exit: + mov edi, [output] + mov ecx, 0x1000 + xor eax, eax + cld + rep stosd + ret +endp + +end if diff --git a/kernel/trunk/drivers/sis.asm b/kernel/trunk/drivers/sis.asm index af485987d1..c47243c8fe 100644 --- a/kernel/trunk/drivers/sis.asm +++ b/kernel/trunk/drivers/sis.asm @@ -44,15 +44,15 @@ BIT31 EQU 0x80000000 VID_SIS equ 0x1039 CTRL_SIS equ 0x7012 -PCM_OUT_BDL equ 0x10 ; PCM out buffer descriptors list -PCM_OUT_CR_REG equ 0x1b ; PCM out Control Register +PCM_OUT_BDL equ 0x10 ; PCM out buffer descriptors list +PCM_OUT_CR_REG equ 0x1b ; PCM out Control Register PCM_OUT_LVI_REG equ 0x15 ; PCM last valid index -PCM_OUT_SR_REG equ 0x18 ; PCM out Status register +PCM_OUT_SR_REG equ 0x18 ; PCM out Status register PCM_OUT_PIV_REG equ 0x1a ; PCM out prefetched index PCM_OUT_CIV_REG equ 0x14 ; PCM out current index PCM_IN_CR_REG equ 0x0b ; PCM in Control Register -MC_IN_CR_REG equ 0x2b ; MIC in Control Register +MC_IN_CR_REG equ 0x2b ; MIC in Control Register RR equ BIT1 ; reset registers. Nukes all regs CODEC_MASTER_VOL_REG equ 0x02 @@ -65,24 +65,24 @@ CODEC_PCM_SURND_DACRATE_REG equ 2eh ; surround sound sample rate CODEC_PCM_LFE_DACRATE_REG equ 30h ; LFE sample rate -GLOB_CTRL equ 0x2C ; Global Control -CTRL_STAT equ 0x30 ; Global Status -CTRL_CAS equ 0x34 ; Codec Access Semiphore +GLOB_CTRL equ 0x2C ; Global Control +CTRL_STAT equ 0x30 ; Global Status +CTRL_CAS equ 0x34 ; Codec Access Semiphore -CAS_FLAG equ 0x01 ; Codec Access Semiphore Bit +CAS_FLAG equ 0x01 ; Codec Access Semiphore Bit -CTRL_ST_CREADY equ BIT8+BIT9+BIT28 ; Primary Codec Ready +CTRL_ST_CREADY equ BIT8+BIT9+BIT28 ; Primary Codec Ready -CTRL_ST_RCS equ 0x00008000 ; Read Completion Status +CTRL_ST_RCS equ 0x00008000 ; Read Completion Status -CTRL_CNT_CRIE equ BIT4+BIT5+BIT6 ; Codecs Resume Interrupt Enable -CTRL_CNT_AC_OFF equ 0x00000008 ; ACLINK Off -CTRL_CNT_WARM equ 0x00000004 ; AC97 Warm Reset -CTRL_CNT_COLD equ 0x00000002 ; AC97 Cold Reset -CTRL_CNT_GIE equ 0x00000001 ; GPI Interrupt Enable +CTRL_CNT_CRIE equ BIT4+BIT5+BIT6 ; Codecs Resume Interrupt Enable +CTRL_CNT_AC_OFF equ 0x00000008 ; ACLINK Off +CTRL_CNT_WARM equ 0x00000004 ; AC97 Warm Reset +CTRL_CNT_COLD equ 0x00000002 ; AC97 Cold Reset +CTRL_CNT_GIE equ 0x00000001 ; GPI Interrupt Enable CODEC_REG_POWERDOWN equ 0x26 -CODEC_REG_ST equ 0x26 +CODEC_REG_ST equ 0x26 DEV_PLAY equ 1 @@ -217,24 +217,24 @@ struc CODEC ;Audio Chip base class } struc CTRL_INFO -{ .pci_cmd dd ? - .irq dd ? - .glob_cntrl dd ? - .glob_sta dd ? - .codec_io_base dd ? - .ctrl_io_base dd ? - .codec_mem_base dd ? - .ctrl_mem_base dd ? - .codec_id dd ? +{ .pci_cmd dd ? + .irq dd ? + .glob_cntrl dd ? + .glob_sta dd ? + .codec_io_base dd ? + .ctrl_io_base dd ? + .codec_mem_base dd ? + .ctrl_mem_base dd ? + .codec_id dd ? } struc IOCTL -{ .handle dd ? - .io_code dd ? - .input dd ? - .inp_size dd ? - .output dd ? - .out_size dd ? +{ .handle dd ? + .io_code dd ? + .input dd ? + .inp_size dd ? + .output dd ? + .out_size dd ? } virtual at 0 @@ -243,9 +243,9 @@ end virtual EVENT_NOTIFY equ 0x00000200 -OS_BASE equ 0; 0x80400000 -new_app_base equ 0x60400000; 0x01000000 -PROC_BASE equ OS_BASE+0x0080000 +OS_BASE equ 0; 0x80400000 +PROC_BASE equ OS_BASE+0x0080000 +new_app_base equ 0x80000000 public START public service_proc @@ -361,16 +361,15 @@ proc service_proc stdcall, ioctl:dword @@: cmp eax, DEV_SET_MASTERVOL jne @F - mov ebx, [edi+input] - stdcall set_master_vol, [ebx] + mov eax, [edi+input] + mov eax, [eax] + call set_master_vol ;eax= vol ret @@: cmp eax, DEV_GET_MASTERVOL jne @F mov ebx, [edi+output] - test ebx, ebx - jz .fail - + add ebx, new_app_base stdcall get_master_vol, ebx ret @@: @@ -381,7 +380,7 @@ proc service_proc stdcall, ioctl:dword ret @@: .fail: - xor eax, eax + or eax, -1 ret endp @@ -401,7 +400,7 @@ proc ac97_irq ; end if mov edx, PCM_OUT_CR_REG - mov al, 0x14 + mov al, 0x10 call [ctrl.ctrl_write8] mov ax, 0x1c @@ -424,11 +423,11 @@ proc ac97_irq call [ctrl.ctrl_write8] mov edx, PCM_OUT_CR_REG - mov ax, 0x1D + mov ax, 0x11 call [ctrl.ctrl_write8] mov eax, [civ_val] - add eax, 2 + add eax, 1 and eax, 31 mov ebx, dword [buff_list+eax*4] @@ -441,7 +440,7 @@ proc ac97_irq .skip: mov edx, PCM_OUT_CR_REG - mov ax, 0x1D + mov ax, 0x11 call [ctrl.ctrl_write8] ret endp @@ -455,6 +454,7 @@ proc create_primary_buff mov edi, eax mov ecx, 0x10000/4 xor eax, eax + cld rep stosd mov eax, [ctrl.buffer] @@ -1132,7 +1132,7 @@ align 4 devices dd (CTRL_SIS shl 16)+VID_SIS,msg_AC, set_SIS dd 0 -version dd 0x00030003 +version dd 0x00040004 msg_AC db '7012 AC97 controller',13,10, 0 msg_SIS db 'Silicon Integrated Systems',13,10, 0 diff --git a/kernel/trunk/drivers/sound.asm b/kernel/trunk/drivers/sound.asm index 7966f955bd..7ed4a6c7a8 100644 --- a/kernel/trunk/drivers/sound.asm +++ b/kernel/trunk/drivers/sound.asm @@ -51,38 +51,38 @@ BIT29 EQU 0x20000000 BIT30 EQU 0x40000000 BIT31 EQU 0x80000000 -VID_INTEL equ 0x8086 -VID_NVIDIA equ 0x10DE +VID_INTEL equ 0x8086 +VID_NVIDIA equ 0x10DE -CTRL_ICH equ 0x2415 -CTRL_ICH0 equ 0x2425 -CTRL_ICH2 equ 0x2435 -CTRL_ICH3 equ 0x2445 -CTRL_ICH4 equ 0x24C5 -CTRL_ICH5 equ 0x24D5 -CTRL_ICH6 equ 0x266E -CTRL_ICH7 equ 0x27DE +CTRL_ICH equ 0x2415 +CTRL_ICH0 equ 0x2425 +CTRL_ICH2 equ 0x2435 +CTRL_ICH3 equ 0x2445 +CTRL_ICH4 equ 0x24C5 +CTRL_ICH5 equ 0x24D5 +CTRL_ICH6 equ 0x266E +CTRL_ICH7 equ 0x27DE -CTRL_NFORCE equ 0x01B1 -CTRL_NFORCE2 equ 0x006A -CTRL_NFORCE3 equ 0x00DA -CTRL_MCP04 equ 0x003A -CTRL_CK804 equ 0x0059 -CTRL_CK8 equ 0x008A -CTRL_CK8S equ 0x00EA -CTRL_MCP51 equ 0x026B +CTRL_NFORCE equ 0x01B1 +CTRL_NFORCE2 equ 0x006A +CTRL_NFORCE3 equ 0x00DA +CTRL_MCP04 equ 0x003A +CTRL_CK804 equ 0x0059 +CTRL_CK8 equ 0x008A +CTRL_CK8S equ 0x00EA +CTRL_MCP51 equ 0x026B -PCM_OUT_BDL equ 0x10 ; PCM out buffer descriptors list +PCM_OUT_BDL equ 0x10 ; PCM out buffer descriptors list PCM_OUT_CR_REG equ 0x1b ; PCM out Control Register -PCM_OUT_LVI_REG equ 0x15 ; PCM last valid index +PCM_OUT_LVI_REG equ 0x15 ; PCM last valid index PCM_OUT_SR_REG equ 0x16 ; PCM out Status register -PCM_OUT_PIV_REG equ 0x1a -PCM_OUT_CIV_REG equ 0x14 ; PCM out current index +PCM_OUT_PIV_REG equ 0x1a +PCM_OUT_CIV_REG equ 0x14 ; PCM out current index -PCM_IN_CR_REG equ 0x0b ; PCM in Control Register -MC_IN_CR_REG equ 0x2b ; MIC in Control Register -RR equ BIT1 ; reset registers. Nukes all regs +PCM_IN_CR_REG equ 0x0b ; PCM in Control Register +MC_IN_CR_REG equ 0x2b ; MIC in Control Register +RR equ BIT1 ; reset registers. Nukes all regs CODEC_MASTER_VOL_REG equ 0x02 CODEC_AUX_VOL equ 0x04 ; @@ -93,21 +93,21 @@ CODEC_PCM_FRONT_DACRATE_REG equ 2ch ; PCM out sample rate CODEC_PCM_SURND_DACRATE_REG equ 2eh ; surround sound sample rate CODEC_PCM_LFE_DACRATE_REG equ 30h ; LFE sample rate -GLOB_CTRL equ 0x2C ; Global Control -CTRL_STAT equ 0x30 ; Global Status -CTRL_CAS equ 0x34 ; Codec Access Semiphore +GLOB_CTRL equ 0x2C ; Global Control +CTRL_STAT equ 0x30 ; Global Status +CTRL_CAS equ 0x34 ; Codec Access Semiphore -CAS_FLAG equ 0x01 ; Codec Access Semiphore Bit +CAS_FLAG equ 0x01 ; Codec Access Semiphore Bit -CTRL_ST_CREADY equ BIT8+BIT9+BIT28 ; Primary Codec Ready +CTRL_ST_CREADY equ BIT8+BIT9+BIT28 ; Primary Codec Ready -CTRL_ST_RCS equ 0x00008000 ; Read Completion Status +CTRL_ST_RCS equ 0x00008000 ; Read Completion Status -CTRL_CNT_CRIE equ BIT4+BIT5+BIT6 ; Codecs Resume Interrupt Enable -CTRL_CNT_AC_OFF equ 0x00000008 ; ACLINK Off -CTRL_CNT_WARM equ 0x00000004 ; AC97 Warm Reset -CTRL_CNT_COLD equ 0x00000002 ; AC97 Cold Reset -CTRL_CNT_GIE equ 0x00000001 ; GPI Interrupt Enable +CTRL_CNT_CRIE equ BIT4+BIT5+BIT6 ; Codecs Resume Interrupt Enable +CTRL_CNT_AC_OFF equ 0x00000008 ; ACLINK Off +CTRL_CNT_WARM equ 0x00000004 ; AC97 Warm Reset +CTRL_CNT_COLD equ 0x00000002 ; AC97 Cold Reset +CTRL_CNT_GIE equ 0x00000001 ; GPI Interrupt Enable CODEC_REG_POWERDOWN equ 0x26 CODEC_REG_ST equ 0x26 @@ -271,8 +271,8 @@ end virtual EVENT_NOTIFY equ 0x00000200 OS_BASE equ 0; -new_app_base equ 0x60400000 -PROC_BASE equ OS_BASE+0x0080000 +PROC_BASE equ OS_BASE+0x0080000 +new_app_base equ 0x80000000 public START public service_proc @@ -405,27 +405,26 @@ proc service_proc stdcall, ioctl:dword @@: cmp eax, DEV_SET_MASTERVOL jne @F - mov ebx, [edi+input] - stdcall set_master_vol, [ebx] + mov eax, [edi+input] + mov eax, [eax] + call set_master_vol ;eax= vol ret @@: cmp eax, DEV_GET_MASTERVOL jne @F mov ebx, [edi+output] - test ebx, ebx - jz .fail - + add ebx, new_app_base stdcall get_master_vol, ebx ret -@@: - cmp eax, DEV_GET_INFO - jne @F - mov ebx, [edi+output] - stdcall get_dev_info, ebx - ret +;@@: +; cmp eax, DEV_GET_INFO +; jne @F +; mov ebx, [edi+output] +; stdcall get_dev_info, ebx +; ret @@: .fail: - xor eax, eax + or eax, -1 ret endp @@ -763,8 +762,8 @@ proc set_ICH ret endp -PG_SW equ 0x003 -PG_NOCACHE equ 0x018 +PG_SW equ 0x003 +PG_NOCACHE equ 0x018 align 4 proc set_ICH4 @@ -1004,8 +1003,7 @@ proc cold_reset endp align 4 -proc play - +play: mov eax, 16 mov [ctrl.lvi_reg], eax mov edx, PCM_OUT_LVI_REG @@ -1014,11 +1012,11 @@ proc play mov edx, PCM_OUT_CR_REG mov ax, 0x1D call [ctrl.ctrl_write8] + xor eax, eax ret -endp align 4 -proc stop +stop: mov edx, PCM_OUT_CR_REG mov ax, 0x0 call [ctrl.ctrl_write8] @@ -1026,8 +1024,8 @@ proc stop mov ax, 0x1c mov edx, PCM_OUT_SR_REG call [ctrl.ctrl_write16] + xor eax, eax ret -endp align 4 proc get_dev_info stdcall, p_info:dword @@ -1334,9 +1332,9 @@ include "codec.inc" 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 - dd (CTRL_ICH3 shl 16)+VID_INTEL,msg_ICH3,set_ICH + dd (CTRL_ICH0 shl 16)+VID_INTEL,msg_ICH0,set_ICH + dd (CTRL_ICH2 shl 16)+VID_INTEL,msg_ICH2,set_ICH + dd (CTRL_ICH3 shl 16)+VID_INTEL,msg_ICH3,set_ICH dd (CTRL_ICH4 shl 16)+VID_INTEL,msg_ICH4,set_ICH4 dd (CTRL_ICH5 shl 16)+VID_INTEL,msg_ICH5,set_ICH4 dd (CTRL_ICH6 shl 16)+VID_INTEL,msg_ICH6,set_ICH4 @@ -1353,7 +1351,7 @@ devices dd (CTRL_ICH shl 16)+VID_INTEL,msg_ICH, set_ICH dd 0 ;terminator -version dd 0x00030003 +version dd 0x00040004 msg_ICH db 'Intel ICH', 13,10, 0 msg_ICH0 db 'Intel ICH0', 13,10, 0 diff --git a/kernel/trunk/debug-fdo.inc b/kernel/trunk/fdo.inc similarity index 100% rename from kernel/trunk/debug-fdo.inc rename to kernel/trunk/fdo.inc diff --git a/kernel/trunk/kernel.asm b/kernel/trunk/kernel.asm index e6bf0383b2..9c02ea6e4a 100644 --- a/kernel/trunk/kernel.asm +++ b/kernel/trunk/kernel.asm @@ -169,7 +169,7 @@ include 'unpacker.inc' __DEBUG__ fix 1 __DEBUG_LEVEL__ fix 1 -include 'debug-fdo.inc' +include 'fdo.inc' iglobal boot_memdetect db 'Determining amount of memory',0 @@ -370,33 +370,33 @@ B32: ; btr [cpu_caps], CAPS_PGE ;test: don't use global pages ; btr [cpu_caps], CAPS_MTRR ;test: don't use MTRR bts [cpu_caps], CAPS_TSC ;force use rdtsc - + ; -------- Fast System Call init ---------- - ; Intel SYSENTER/SYSEXIT (AMD CPU support it too) - bt [cpu_caps], CAPS_SEP - jnc .SEnP ; SysEnter not Present - xor edx, edx - mov ecx, MSR_SYSENTER_CS - mov eax, os_code - wrmsr - mov ecx, MSR_SYSENTER_ESP - mov eax, sysenter_stack ; Check it - wrmsr - mov ecx, MSR_SYSENTER_EIP - mov eax, sysenter_entry - wrmsr +; Intel SYSENTER/SYSEXIT (AMD CPU support it too) + bt [cpu_caps], CAPS_SEP + jnc .SEnP ; SysEnter not Present + xor edx, edx + mov ecx, MSR_SYSENTER_CS + mov eax, os_code + wrmsr + mov ecx, MSR_SYSENTER_ESP + mov eax, sysenter_stack ; Check it + wrmsr + mov ecx, MSR_SYSENTER_EIP + mov eax, sysenter_entry + wrmsr .SEnP: - ; AMD SYSCALL/SYSRET - cmp byte[cpu_vendor], 'A' - jne .noSYSCALL - mov eax, 0x80000001 - cpuid - test edx, 0x800 ; bit_11 - SYSCALL/SYSRET support - jz .noSYSCALL - mov ecx, MSR_AMD_EFER - rdmsr - or eax, 1 ; bit_0 - System Call Extension (SCE) - wrmsr +; AMD SYSCALL/SYSRET + cmp byte[cpu_vendor], 'A' + jne .noSYSCALL + mov eax, 0x80000001 + cpuid + test edx, 0x800 ; bit_11 - SYSCALL/SYSRET support + jz .noSYSCALL + mov ecx, MSR_AMD_EFER + rdmsr + or eax, 1 ; bit_0 - System Call Extension (SCE) + wrmsr ; !!!! It`s dirty hack, fix it !!! ; Bits of EDX : @@ -406,16 +406,19 @@ B32: ; and the contents of this field, plus 8, are copied into the SS register. ; mov edx, (os_code + 16) * 65536 + os_code - mov edx, 0x1B0013 + mov edx, 0x1B0013 - mov eax, syscall_entry - mov ecx, MSR_AMD_STAR - wrmsr + mov eax, syscall_entry + mov ecx, MSR_AMD_STAR + wrmsr .noSYSCALL: ; ----------------------------------------- + + ; MEMORY MODEL call mem_test + call init_mtrr call init_mem call init_page_map @@ -430,8 +433,8 @@ B32: call init_kernel_heap stdcall kernel_alloc, 0x2000 mov [os_stack], eax + call init_LFB - call init_mtrr call init_fpu call init_malloc @@ -4872,6 +4875,7 @@ read_from_hd: ; Read from hd - fn not in use align 4 paleholder: ret + ; --------------- APM --------------------- apm_entry dp 0 apm_vf dd 0 @@ -5066,7 +5070,7 @@ endg if __DEBUG__ eq 1 include_debug_strings -end if +end if IncludeIGlobals endofcode: diff --git a/kernel/trunk/memmap.inc b/kernel/trunk/memmap.inc index b983ac898f..082102fad7 100644 --- a/kernel/trunk/memmap.inc +++ b/kernel/trunk/memmap.inc @@ -211,8 +211,14 @@ ; ; ; 0x0098B000 -> kernel heap - - +; +; 0x01FFFFFF heam min limit +; 0x7DBFFFFF heap max limit +; 0x7DC00000 -> 0x7FBFFFFF LFB 32Mb +; 0x7DC00000 -> 0x7E3FFFFF application available LFB 8Mb +; 0x7E400000 -> 0x7FBFFFFF kernel LFB part 24 Mb +; 0x7FC00000 -> 0x7FFFFFFF page tables 4Mb +; 0x80000000 -> 0xFFFFFFFF application 2Gb