Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 377 → Rev 378

/kernel/trunk/debug-fdo.inc
File deleted
/kernel/trunk/boot/bootcode.inc
59,18 → 59,18
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:
/kernel/trunk/const.inc
231,15 → 231,18
 
;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
 
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
246,15 → 249,14
 
 
 
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
 
PAGES_USED equ 4
;PAGES_USED equ 4
 
PG_UNMAP equ 0x000
PG_MAP equ 0x001
/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
 
/kernel/trunk/core/fpu.inc
36,41 → 36,95
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
endp
.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
 
align 4
e7: ;#NM exception handler
/kernel/trunk/core/memory.inc
106,7 → 106,7
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
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
 
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
mov [0x2f0000+0x901c],byte 2
ret
@@:
call map_LFB
ret
endp
 
align 4
proc map_LFB
locals
pg_count dd ?
endl
 
mov edx, LFB_BASE
mov esi, [LFBAddress]
mov edi, [LFBSize]
mov esi, [LFBAddress]
mov dword [exp_lfb+4], esi
 
shr edi, 12
408,13 → 403,12
 
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
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
 
@@:
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
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
 
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
@@:
cmp eax, 17
ja @f
stdcall srv_handlerEx, ebx
call srv_handlerEx ;ebx
mov [esp+36], eax
ret
@@:
/kernel/trunk/core/taskman.inc
386,25 → 386,19
 
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
mov eax, [dir_addr]
or eax, PG_SW
stosd ; [(page_tabs shr 20)]= eax
 
mov ecx, 0x800/4
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
 
mov eax, [dir_addr]
call set_cr3
 
mov edx, [app_tabs]
555,8 → 549,8
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
/kernel/trunk/drivers/ati2d.asm
65,9 → 65,9
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
232,7 → 232,7
mov eax, [edi+input]
call video_free
.fail:
xor eax, eax
or eax, -1
ret
endp
 
981,7 → 981,7
dd (R9800XT shl 16)+VID_ATI
dd 0 ;terminator
 
version dd 0x00030003
version dd 0x00040004
 
sz_ati_srv db 'HWCURSOR',0
 
/kernel/trunk/drivers/codec.inc
67,7 → 67,7
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,27 → 98,30
 
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
125,16 → 128,10
 
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
 
/kernel/trunk/drivers/infinity.asm
26,26 → 26,28
 
DEBUG equ 1
 
EVENT_NOTIFY equ 0x00000200
 
OS_BASE equ 0
new_app_base equ 0x60400000
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
 
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
104,6 → 106,8
mov [mix_4_core], mmx128_mix_4
end if
 
if 0
 
if ~(FORCE_MMX or FORCE_MMX_128) ;autodetect
mov eax, 1
cpuid
120,7 → 124,10
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
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
mov ebx, [edi+input]
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 ebx, [edi+input]
stdcall play_buffer, [ebx]
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
stdcall SetBufferVol,[ebx],[ebx+4],[ebx+8]
ret
@@:
cmp eax, SND_GETVOLUME
jne @F
 
mov eax, [edi+input]
mov eax, [eax]
call DestroyBuffer ;eax
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
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 ?
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
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
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 eax, eax
ret
endp
xor edx, edx
mov ebx, MANUAL_DESTROY
call CreateEvent
 
if 0
align 4
pid_to_slot:
mov ebx, [str]
mov [ebx+STREAM.notify_event], eax
mov [ebx+STREAM.notify_id], edx
 
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
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
 
.pid_found:
shr ecx,5
mov eax,ecx
pop ecx
pop ebx
.fail:
xor ebx, ebx
or eax, -1
ret
endp
 
end if
 
;param
; eax= buffer handle
 
374,15 → 523,11
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,115 → 535,120
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
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
 
; for static buffers only
; use waveout for streams
 
align 4
proc stop_buffer stdcall, str:dword
proc set_buffer stdcall, str:dword,src:dword,offs:dword,size:dword
 
mov edi, [str]
mov edx, [str]
test [edx+STREAM.format], PCM_OUT
jnz .fail
 
cmp [edi+STREAM.magic], 'WAVE'
jne .fail
mov esi, [src]
mov edi, [offs]
add edi, [edx+STREAM.in_base]
add edi, 128
 
cmp [edi+STREAM.size], STREAM_SIZE
jne .fail
cmp edi, [edx+STREAM.in_top]
jae .fail
 
mov [edi+STREAM.flags], SND_STOP
 
; stdcall [ServiceHandler], [hSound], dword DEV_STOP, 0
 
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
inc eax
ret
.fail:
xor eax, eax
or eax, -1
ret
endp
 
; for stream buffers only
 
align 4
proc set_buffer stdcall, str:dword,src:dword,offs:dword,size:dword
proc wave_out stdcall, str:dword,src:dword,size:dword
locals
state_saved dd ?
fpu_state rb 528
endl
 
mov edx, [str]
test edx, edx
jz .fail
mov eax, [edx+STREAM.format]
test eax, PCM_STATIC+PCM_RING
jnz .fail
 
cmp [edx+STREAM.magic], 'WAVE'
jne .fail
cmp ax, PCM_ALL
je .fail
 
cmp [edx+STREAM.size], STREAM_SIZE
jne .fail
 
mov esi,[src]
test esi, esi
jz .fail
506,44 → 656,429
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
 
mov [src], esi
cmp edi, [edx+STREAM.in_top]
jb @F
sub edi, [edx+STREAM.in_size]
@@:
add edi, 0x1000
mov ecx, [size]
test ecx, ecx
jz .done
cmp ecx, 0x8000
ja .fail
mov [edx+STREAM.in_wp], edi
 
shr ecx, 2
rep movsd
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
.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:
 
xor edx, edx
562,8 → 1097,6
 
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
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
 
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
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
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
/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,48 → 51,54
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)
;}
PCM_2_8_8 equ 35
PCM_1_8_8 equ 36
 
;virtual at 0
; SND_DEV SND_DEV
;end virtual
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
 
;SND_DEV_SIZE equ 80
 
 
struc STREAM
{
.magic dd ? ;'WAVE'
94,32 → 114,35
.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 ?
.resample dd ?
.l_vol dd ?
.r_vol dd ?
.l_amp dw ?
.r_amp dw ?
.pan dd ?
 
.base dd ?
.limit dd ?
.seg_0 dd ?
.lim_0 dd ?
.seg_1 dd ?
.lim_1 dd ?
.curr_seg dd ?
.in_base dd ?
.in_size dd ?
.in_wp dd ?
.in_rp dd ?
.in_count dd ?
.in_free dd ?
.in_top dd ?
 
.buff_size dd ?
.notify_off1 dd ?
.notify_off2 dd ?
; .notify_task dd ?
.resample dd ?
.notify_event dd ?
.notify_id dd ?
}
 
STREAM_SIZE equ 31*4
STREAM_SIZE equ 34*4
FD_OFFSET equ 24
 
virtual at 0
/kernel/trunk/drivers/mixer.asm
13,96 → 13,67
; 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 .clear
 
cmp [play_count], 0
je .exit
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
call update_stream
.mix:
lea eax, [mix_list]
call do_mix_list
test eax, eax
je .done
 
dec ecx
jnz .l1
; cmp eax, 1
; je .copy
 
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
lea ebx, [mix_list]
stdcall mix_all, [output], ebx, eax
@@:
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
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
ret
endp
 
120,157 → 91,252
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
 
test eax, eax
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]
jnz .l1
ret
endp
 
align 4
proc refill stdcall, str:dword
locals
r_size rd 1
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 [ev_code], 0xFF000001
mov [ev_offs], ecx
mov eax, [ebx+STREAM.pid]
mov eax, [ebx+STREAM.in_count]
test eax, eax
jz .done
 
lea edx, [ev_code]
push ebx
stdcall SendEvent, eax, edx
pop ebx
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], 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, [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
 
.done:
mov eax, [ebx+STREAM.notify_event]
test eax, eax
jnz .l_end
jz .exit
 
not eax
mov [ebx+STREAM.pid], eax ;-1
.l_end:
inc [stream_index]
dec [play_count]
jnz .l1
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 stdcall, str:dword
proc refill_ring stdcall, str:dword
locals
ev_code dd ? ;EVENT
ev_offs dd ?
rd 4
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 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],[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, [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
 
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
 
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
cmp eax, [ebx+STREAM.notify_off2]
je @f
call RaiseEvent ;eax, ebx, ecx, edx
.exit:
ret
endp
 
mov ecx,0x8000
cmp eax, [ebx+STREAM.notify_off1]
je @f
ret
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
@@:
mov [ev_code], 0xFF000001
mov [ev_offs], ecx
mov eax, [ebx+STREAM.pid]
movq [edi], mm0
add edi, 8
dec ebx
jnz .mix
 
lea edx, [ev_code]
push ebx
stdcall SendEvent, eax, edx
pop ebx
test eax, eax
jnz @F
not eax
mov [ebx+STREAM.pid], eax ;-1
@@:
ret
endp
 
289,7 → 355,7
sub edx, 32*2
mov eax, 16
 
align 16
align 4
.l1:
mov ecx, eax
mov esi, eax
342,7 → 408,7
 
mov esi, 16
 
align 16
align 4
.l1:
mov ecx, esi
mov eax, esi
413,7 → 479,7
mov eax, 16
emms
 
align 16
align 4
.l1:
mov ecx, eax
mov esi, eax
466,7 → 532,7
movq mm7,[mm80]
movq mm6,[mm_mask]
 
align 16
align 4
.l1:
mov ecx, eax
mov esi, eax
840,6 → 906,8
and eax, eax
jz .err
 
mov [output], eax
 
mov edi, eax
mov eax, [str0]
mov ebx, [str1]
939,4 → 1007,100
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
 
/kernel/trunk/drivers/sis.asm
244,8 → 244,8
EVENT_NOTIFY equ 0x00000200
 
OS_BASE equ 0; 0x80400000
new_app_base equ 0x60400000; 0x01000000
PROC_BASE equ OS_BASE+0x0080000
new_app_base equ 0x80000000
 
public START
public service_proc
361,16 → 361,15
@@:
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
ret
@@:
.fail:
xor eax, eax
or eax, -1
ret
endp
 
401,7 → 400,7
; 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
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
 
.skip:
mov edx, PCM_OUT_CR_REG
mov ax, 0x1D
mov ax, 0x11
call [ctrl.ctrl_write8]
ret
endp
455,6 → 454,7
mov edi, eax
mov ecx, 0x10000/4
xor eax, eax
cld
rep stosd
 
mov eax, [ctrl.buffer]
1132,7 → 1132,7
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
/kernel/trunk/drivers/sound.asm
271,8 → 271,8
EVENT_NOTIFY equ 0x00000200
 
OS_BASE equ 0;
new_app_base equ 0x60400000
PROC_BASE equ OS_BASE+0x0080000
new_app_base equ 0x80000000
 
public START
public service_proc
405,27 → 405,26
@@:
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
 
1004,8 → 1003,7
endp
 
align 4
proc play
 
play:
mov eax, 16
mov [ctrl.lvi_reg], eax
mov edx, PCM_OUT_LVI_REG
1014,11 → 1012,11
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
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
1353,7 → 1351,7
 
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
/kernel/trunk/fdo.inc
0,0 → 1,422
;
; Formatted Debug Output (FDO)
; Copyright (c) 2005-2006, mike.dld
; Created: 2005-01-29, Changed: 2006-11-10
;
; For questions and bug reports, mail to mike.dld@gmail.com
;
; Available format specifiers are: %s, %d, %u, %x (with partial width support)
;
 
; to be defined:
; __DEBUG__ equ 1
; __DEBUG_LEVEL__ equ 5
 
macro debug_func name {
if used name
name@of@func equ name
}
 
macro debug_beginf {
align 4
name@of@func:
}
 
debug_endf fix end if
 
macro DEBUGS _sign,[_str] {
common
local tp
tp equ 0
match _arg:_num,_str \{
DEBUGS_N _sign,_num,_arg
tp equ 1
\}
match =0 _arg,tp _str \{
DEBUGS_N _sign,,_arg
\}
}
 
macro DEBUGS_N _sign,_num,[_str] {
common
pushf
pushad
local ..str,..label,is_str
is_str = 0
forward
if _str eqtype ''
is_str = 1
end if
common
if is_str = 1
jmp ..label
..str db _str,0
..label:
add esp,4*8+4
mov edx,..str
sub esp,4*8+4
else
mov edx,_str
end if
if ~_num eq
if _num eqtype eax
if _num in <eax,ebx,ecx,edx,edi,ebp,esp>
mov esi,_num
else if ~_num eq esi
movzx esi,_num
end if
else if _num eqtype 0
mov esi,_num
else
local tp
tp equ 0
match [_arg],_num \{
mov esi,dword[_arg]
tp equ 1
\}
match =0 =dword[_arg],tp _num \{
mov esi,dword[_arg]
tp equ 1
\}
match =0 =word[_arg],tp _num \{
movzx esi,word[_arg]
tp equ 1
\}
match =0 =byte[_arg],tp _num \{
movzx esi,byte[_arg]
tp equ 1
\}
match =0,tp \{
'Error: specified string width is incorrect'
\}
end if
else
mov esi,0x7FFFFFFF
end if
call fdo_debug_outstr
popad
popf
}
 
macro DEBUGD _sign,_dec {
local tp
tp equ 0
match _arg:_num,_dec \{
DEBUGD_N _sign,_num,_arg
tp equ 1
\}
match =0 _arg,tp _dec \{
DEBUGD_N _sign,,_arg
\}
}
 
macro DEBUGD_N _sign,_num,_dec {
pushf
pushad
if (~_num eq)
if (_dec eqtype eax | _dec eqtype 0)
'Error: precision allowed only for in-memory variables'
end if
if (~_num in <1,2,4>)
if _sign
'Error: 1, 2 and 4 are only allowed for precision in %d'
else
'Error: 1, 2 and 4 are only allowed for precision in %u'
end if
end if
end if
if _dec eqtype eax
if _dec in <ebx,ecx,edx,esi,edi,ebp,esp>
mov eax,_dec
else if ~_dec eq eax
if _sign = 1
movsx eax,_dec
else
movzx eax,_dec
end if
end if
else if _dec eqtype 0
mov eax,_dec
else
add esp,4*8+4
if _num eq
mov eax,dword _dec
else if _num = 1
if _sign = 1
movsx eax,byte _dec
else
movzx eax,byte _dec
end if
else if _num = 2
if _sign = 1
movsx eax,word _dec
else
movzx eax,word _dec
end if
else
mov eax,dword _dec
end if
sub esp,4*8+4
end if
mov cl,_sign
call fdo_debug_outdec
popad
popf
}
 
macro DEBUGH _sign,_hex {
local tp
tp equ 0
match _arg:_num,_hex \{
DEBUGH_N _sign,_num,_arg
tp equ 1
\}
match =0 _arg,tp _hex \{
DEBUGH_N _sign,,_arg
\}
}
 
macro DEBUGH_N _sign,_num,_hex {
pushf
pushad
if (~_num eq) & (~_num in <1,2,3,4,5,6,7,8>)
'Error: 1..8 are only allowed for precision in %x'
end if
if _hex eqtype eax
if _hex in <eax,ebx,ecx,edx,esi,edi,ebp,esp>
if ~_hex eq eax
mov eax,_hex
end if
else if _hex in <ax,bx,cx,dx,si,di,bp,sp>
if ~_hex eq ax
movzx eax,_hex
end if
shl eax,16
if (_num eq)
mov edx,4
end if
else if _hex in <al,ah,bl,bh,cl,ch,dl,dh>
if ~_hex eq al
movzx eax,_hex
end if
shl eax,24
if (_num eq)
mov edx,2
end if
end if
else if _hex eqtype 0
mov eax,_hex
else
add esp,4*8+4
mov eax,dword _hex
sub esp,4*8+4
end if
if ~_num eq
mov edx,_num
else
if ~_hex eqtype eax
mov edx,8
end if
end if
call fdo_debug_outhex
popad
popf
}
 
;-----------------------------------------------------------------------------
 
debug_func fdo_debug_outchar
debug_beginf
pushad
movzx ebx,al
mov eax,1
call sys_msg_board
popad
ret
debug_endf
 
debug_func fdo_debug_outstr
debug_beginf
mov eax,1
.l1: dec esi
js .l2
movzx ebx,byte[edx]
or bl,bl
jz .l2
call sys_msg_board
inc edx
jmp .l1
.l2: ret
debug_endf
 
debug_func fdo_debug_outdec
debug_beginf
or cl,cl
jz @f
or eax,eax
jns @f
neg eax
push eax
mov al,'-'
call fdo_debug_outchar
pop eax
@@: push 10
pop ecx
push -'0'
.l1: xor edx,edx
div ecx
push edx
test eax,eax
jnz .l1
.l2: pop eax
add al,'0'
jz .l3
call fdo_debug_outchar
jmp .l2
.l3: ret
debug_endf
 
debug_func fdo_debug_outhex
__fdo_hexdigits db '0123456789ABCDEF'
debug_beginf
mov cl,dl
neg cl
add cl,8
shl cl,2
rol eax,cl
.l1: rol eax,4
push eax
and eax,0x0000000F
mov al,[__fdo_hexdigits+eax]
call fdo_debug_outchar
pop eax
dec edx
jnz .l1
ret
debug_endf
 
;-----------------------------------------------------------------------------
 
macro DEBUGF _level,_format,[_arg] {
common
if __DEBUG__ = 1 & _level >= __DEBUG_LEVEL__
local ..f1,f2,a1,a2,c1,c2,c3,..lbl
_debug_str_ equ __debug_str_ # a1
a1 = 0
c2 = 0
c3 = 0
f2 = 0
repeat ..lbl-..f1
virtual at 0
db _format,0,0
load c1 word from %-1
end virtual
if c1 = '%s'
virtual at 0
db _format,0,0
store word 0 at %-1
load c1 from f2-c2
end virtual
if c1 <> 0
DEBUGS 0,_debug_str_+f2-c2
end if
c2 = c2 + 1
f2 = %+1
DEBUGF_HELPER S,a1,0,_arg
else if c1 = '%x'
virtual at 0
db _format,0,0
store word 0 at %-1
load c1 from f2-c2
end virtual
if c1 <> 0
DEBUGS 0,_debug_str_+f2-c2
end if
c2 = c2 + 1
f2 = %+1
DEBUGF_HELPER H,a1,0,_arg
else if c1 = '%d' | c1 = '%u'
local c4
if c1 = '%d'
c4 = 1
else
c4 = 0
end if
virtual at 0
db _format,0,0
store word 0 at %-1
load c1 from f2-c2
end virtual
if c1 <> 0
DEBUGS 0,_debug_str_+f2-c2
end if
c2 = c2 + 1
f2 = %+1
DEBUGF_HELPER D,a1,c4,_arg
else if c1 = '\n'
c3 = c3 + 1
end if
end repeat
virtual at 0
db _format,0,0
load c1 from f2-c2
end virtual
if (c1<>0)&(f2<>..lbl-..f1-1)
DEBUGS 0,_debug_str_+f2-c2
end if
virtual at 0
..f1 db _format,0
..lbl:
__debug_strings equ __debug_strings,_debug_str_,<_format>,..lbl-..f1-1-c2-c3
end virtual
end if
}
 
macro __include_debug_strings dummy,[_id,_fmt,_len] {
common
local c1,a1,a2
forward
if defined _len & ~_len eq
_id:
a1 = 0
a2 = 0
repeat _len
virtual at 0
db _fmt,0,0
load c1 word from %+a2-1
end virtual
if (c1='%s')|(c1='%x')|(c1='%d')|(c1='%u')
db 0
a2 = a2 + 1
else if (c1='\n')
dw $0A0D
a1 = a1 + 1
a2 = a2 + 1
else
db c1 and 0x0FF
end if
end repeat
db 0
end if
}
 
macro DEBUGF_HELPER _letter,_num,_sign,[_arg] {
common
local num
num = 0
forward
if num = _num
DEBUG#_letter _sign,_arg
end if
num = num+1
common
_num = _num+1
}
 
macro include_debug_strings {
if __DEBUG__ = 1
match dbg_str,__debug_strings \{
__include_debug_strings dbg_str
\}
end if
}
/kernel/trunk/kernel.asm
169,7 → 169,7
 
__DEBUG__ fix 1
__DEBUG_LEVEL__ fix 1
include 'debug-fdo.inc'
include 'fdo.inc'
 
iglobal
boot_memdetect db 'Determining amount of memory',0
414,8 → 414,11
.noSYSCALL:
; -----------------------------------------
 
 
 
; MEMORY MODEL
call mem_test
call init_mtrr
call init_mem
call init_page_map
 
430,8 → 433,8
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
align 4
paleholder:
ret
 
; --------------- APM ---------------------
apm_entry dp 0
apm_vf dd 0
/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