Rusty Earth - support of PCM_RING sound

git-svn-id: svn://kolibrios.org@5274 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Marat Zakiyanov (Mario79) 2014-12-28 18:22:18 +00:00
parent 3c66f47b1e
commit aec9ac073f
12 changed files with 441 additions and 162 deletions

View File

@ -15,4 +15,5 @@ if not exist bin mkdir rstearth_eng_bin
@copy resources\barret_8bpp.png rstearth_eng_bin\barret_8bpp.png
@copy resources\walking_with_poseidon.wav rstearth_eng_bin\walking_with_poseidon.wav
@copy resources\flaunch.wav rstearth_eng_bin\flaunch.wav
@copy resources\misc_menu.wav rstearth_eng_bin\misc_menu.wav
@pause

View File

@ -15,4 +15,5 @@ if not exist bin mkdir rstearth_rus_bin
@copy resources\barret_8bpp.png rstearth_rus_bin\barret_8bpp.png
@copy resources\walking_with_poseidon.wav rstearth_rus_bin\walking_with_poseidon.wav
@copy resources\flaunch.wav rstearth_rus_bin\flaunch.wav
@copy resources\misc_menu.wav rstearth_rus_bin\misc_menu.wav
@pause

View File

@ -254,6 +254,7 @@ npc_ifrit_icons_file_name db 'ifrit_8bpp.png',0
npc_barret_icons_file_name db 'barret_8bpp.png',0
background_music_file_name db 'walking_with_poseidon.wav',0
stone_kick_sound_file_name db 'flaunch.wav',0
menu_sound_file_name db 'misc_menu.wav',0
;---------------------------------------------------------------------
protagonist_route dd 2
protagonist_position:

View File

@ -154,6 +154,11 @@ load_all_sound_files:
mov ebx,stone_kick_sound_file_name
call load_sound
mov [stone_kick_sound],eax
; load menu sound
mov ebx,menu_sound_file_name
call load_sound
mov [menu_sound],eax
ret
;---------------------------------------------------------------------

View File

@ -1,6 +1,6 @@
;---------------------------------------------------------------------
title:
db 'Rusty Earth (Prototype 1.7) 26.12.2014',0
db 'Rusty Earth (Prototype 1.8) 28.12.2014',0
;---------------------------------------------------------------------
menu_game_label:
db 'GAME',0

View File

@ -2,7 +2,7 @@
; Code page - Cyrillic OEM866
;---------------------------------------------------------------------
title:
db '<27>¦ Ά ο ‡¥¬«ο (<28>ΰ®β®β¨― 1.7) 26.12.2014',0
db '<27>¦ Ά ο ‡¥¬«ο (<28>ΰ®β®β¨― 1.8) 28.12.2014',0
;---------------------------------------------------------------------
menu_game_label:
db 'ˆƒ<CB86>€',0

View File

@ -1,6 +1,8 @@
;---------------------------------------------------------------------
main_menu_start:
mov [main_menu_pointer],0
mov eax,[menu_sound]
mov [sounds_sample],eax
;--------------------------------------
.red:
mov [menu_text_pointers],main_menu_text_pointers

Binary file not shown.

View File

@ -100,16 +100,20 @@ load_libraries l_libs_start,end_l_libs
mov ebx,eax
add ebx,1024
mov [wav_for_test_end],ebx
call initialize_sound_system
call test_wav_file
mov [sounds_flag],1
mov [music_flag],1
mcall 51,1,snd_background_music_thread_start,snd_background_music_thread_stack
mov [sounds_flag],1
mcall 51,1,snd_kick_action_thread_start,snd_kick_action_thread_stack
;---------------------------------------------------------------------
menu_still:
jmp main_menu_start
;---------------------------------------------------------------------
start_level_0:
mov eax,[stone_kick_sound]
mov [sounds_sample],eax
mov [death_of_protagonist],0
mov [protagonist_route],2
mov [protagonist_position.x],4
@ -170,6 +174,8 @@ button:
mcall 51,1,thread_start,thread_stack
;--------------------------------------
@@:
mov [music_flag],2
mov [sounds_flag],2
mcall -1
;---------------------------------------------------------------------
draw_window:

View File

@ -148,8 +148,125 @@ _CreateBuffer@12: ;format:dword,size:dword,p_str:dword
pop ecx ebx
ret 12
;------------------------------------------------------------------------------
;align 4
;_DestroyBuffer@4: ;str:dword
; push ebx ecx
; xor eax,eax
; lea ebx,[esp+12] ;[stream]
;
; push eax ;.out_size
; push eax ;.output
; push 4 ;.inp_size
; push ebx ;.input
; push SND_DESTROY_BUFF;.code
; push [hSound] ;.handle
;
; mov ecx, esp ;[handle]
; mcall 68,17
; add esp,24
; pop ecx ebx
; ret 4
;------------------------------------------------------------------------------
;align 4
;_WaveOut@12: ;str:dword, src:dword, size:dword
; push ebx ecx
; xor eax,eax
; lea ebx,[esp+12] ;[stream]
;
; push eax ;.out_size
; push eax ;.output
; push 12 ;.inp_size
; push ebx ;.input
; push SND_OUT ;.code
; push dword [hSound] ;.handle
;
; mov ecx,esp
; mcall 68,17
; add esp,24
; pop ecx ebx
; ret 12
;------------------------------------------------------------------------------
align 4
_DestroyBuffer@4: ;str:dword
_GetBufferSize@8: ;str:dword, p_size:dword
push ebx ecx
lea eax,[esp+16]
lea ebx,[esp+12] ;[stream]
push 4 ;.out_size
push eax ;.output
push 4 ;.inp_size
push ebx ;.input
push SND_GETBUFFSIZE;.code
push dword [hSound] ;.handle
mov ecx,esp
mcall 68,17
add esp,24
pop ecx ebx
ret 8
;------------------------------------------------------------------------------
;align 4
;_GetBufferFree@8: ;str:dword, p_free:dword
; push ebx ecx
; lea ebx,[esp+12] ;[stream]
; push 0 ;storage for free_space
; mov eax,esp
;
; push 4 ;.out_size
; push eax ;.output
; push 4 ;.inp_size
; push ebx ;.input
; push SND_GETFREESPACE ;.code
; push dword [hSound] ;.handle
;
; mov ecx,esp
; mcall 68,17
; add esp, 24
; mov ecx,[esp+20] ; p_free
; pop dword [ecx]
; pop ecx ebx
; ret 8
;------------------------------------------------------------------------------
align 4
_SetBuffer@16: ;str:dword, src:dword, offs:dword, size:dword
push ebx ecx
xor eax,eax
lea ebx,[esp+12] ;[stream]
push eax ;.out_size
push eax ;.output
push 16 ;.inp_size
push ebx ;.input
push SND_SETBUFF ;.code
push dword [hSound] ;.handle
mov ecx,esp
mcall 68,17
add esp,24
pop ecx ebx
ret 16
;------------------------------------------------------------------------------
align 4
_PlayBuffer@8: ;str:dword,flags:dword
push ebx ecx
xor eax,eax
lea ebx,[esp+12] ;[stream]
push eax ;.out_size
push eax ;.output
push 8 ;.inp_size
push ebx ;.input
push SND_PLAY ;.code
push dword [hSound] ;.handle
mov ecx, esp
mcall 68,17
add esp, 24
pop ecx ebx
ret 8
;------------------------------------------------------------------------------
align 4
_StopBuffer@4: ;str:dword
push ebx ecx
xor eax,eax
lea ebx,[esp+12] ;[stream]
@ -158,33 +275,52 @@ _DestroyBuffer@4: ;str:dword
push eax ;.output
push 4 ;.inp_size
push ebx ;.input
push SND_DESTROY_BUFF;.code
push [hSound] ;.handle
mov ecx, esp ;[handle]
mcall 68,17
add esp,24
pop ecx ebx
ret 4
;------------------------------------------------------------------------------
align 4
_WaveOut@12: ;str:dword, src:dword, size:dword
push ebx ecx
xor eax,eax
lea ebx,[esp+12] ;[stream]
push eax ;.out_size
push eax ;.output
push 12 ;.inp_size
push ebx ;.input
push SND_OUT ;.code
push SND_STOP ;.code
push dword [hSound] ;.handle
mov ecx,esp
mcall 68,17
add esp,24
pop ecx ebx
ret 12
ret 4
;------------------------------------------------------------------------------
;align 4
;_GetBufferPos@8: ;str:dword, p_pos:dword
; push ebx ecx
; lea eax,[esp+16]
; lea ebx,[esp+12] ;[stream]
;
; push 4 ;.out_size
; push eax ;.output
; push 4 ;.inp_size
; push ebx ;.input
; push SND_GETPOS ;.code
; push dword [hSound] ;.handle
;
; mov ecx,esp
; mcall 68,17
; add esp,24
; pop ecx ebx
; ret 8
;------------------------------------------------------------------------------
;align 4
;_SetBufferPos@8: ;str:dword, offs:dword
; push ebx ecx
; xor eax,eax
; lea ebx,[esp+12] ;[stream]
;
; push eax ;.out_size
; push eax ;.output
; push 8 ;.inp_size
; push ebx ;.input
; push SND_SETPOS ;.code
; push dword [hSound] ;.handle
;
; mov ecx,esp
; mcall 68,17
; add esp,24
; pop ecx ebx
; ret 8
;------------------------------------------------------------------------------
align 4
proc _test_wav@4 stdcall, hdr:dword

View File

@ -1,40 +1,12 @@
;------------------------------------------------------------------------------
; init.obj
; _InitSound@4 Èíèò,
; _CreateBuffer@12 ñîçäàòü áóôåð,
; _DestroyBuffer@4 óäàëèòü áóôåð
;
; sndgetsize.obj
; _GetBufferSize@8 âçÿòü ðàçìåð áóôåðà,
; _GetBufferFree@8 WTF???
;
; setbuf.obj
; _SetBuffer@16 óñòàíîâèòü áóôåð,
; _PlayBuffer@8 èãðàòü áóôåð,
;
; stopbuf.obj
; _StopBuffer@4 îñòàíîâèòü áóôåð,
;------------------------------------------------------------------------------
initialize_sound_system:
test_wav_file:
mov [sound_flag],1
stdcall _InitSound@4,version
cmp eax,-1
je snd_init_fail
; DEBUGF 1, "Sound init successful %x\n",eax
mov eax,[version]
and eax,0xffff
cmp eax,SOUND_VERSION
jne snd_version_fail
; DEBUGF 1, "Sound version successful %x\n",eax
stdcall _test_wav@4,dword [wav_for_test] ;letter_1a
test eax,eax
jz snd_test_wav_fail
or eax,PCM_OUT
; or eax,PCM_OUT
or eax,PCM_RING
mov [snd_format],eax
; DEBUGF 1, "Test wav successful %x\n",eax
@ -43,32 +15,75 @@ initialize_sound_system:
mov al,[sound_flag]
test al,al
jz .exit
jnz .exit
stdcall _CreateBuffer@12,[snd_format],0,hBuff1
cmp eax,-1
je snd_create_buffer_fail
; DEBUGF 1, "Create Buffer 1 successful %x\n",eax
stdcall _CreateBuffer@12,[snd_format],0,hBuff2
cmp eax,-1
je snd_create_buffer_fail
; DEBUGF 1, "Create Buffer 1 successful %x\n",eax
;--------------------------------------
mov [sound_flag],2 ; close thread
;--------------------------------------
.exit:
ret
;------------------------------------------------------------------------------
check_init_sound_busy:
cmp [init_sound_busy_flag],1
jne @f
mcall 5,1
mcall 68,1
jmp check_init_sound_busy
;--------------------------------------
@@:
mov [init_sound_busy_flag],1
ret
;------------------------------------------------------------------------------
initialize_sound_system:
cmp [sound_flag],1
jne sound_exit
stdcall _InitSound@4,version
test eax,eax
jnz snd_init_fail
; DEBUGF 1, "Sound init successful %x\n",eax
mov eax,[version]
and eax,0xffff
cmp eax,SOUND_VERSION
jne snd_version_fail
; DEBUGF 1, "Sound version successful %x\n",eax
;--------------------------------------
stdcall _CreateBuffer@12,[snd_format],0,[hBuff_pointer]
test eax,eax
jnz snd_create_buffer_fail
; DEBUGF 1, "Create Buffer successful %x\n",eax
mov eax,[hBuff_pointer]
mov ebx,[hBuff_buffer_size_pointer]
stdcall _GetBufferSize@8,[eax],ebx ;hBuff1_buffer_size
test eax,eax
jnz snd_get_buffer_size_fail
mov ebx,[hBuff_buffer_size_pointer]
mov eax,[ebx]
; DEBUGF 1, "Get Buffer size successful size: %x\n",eax
shr eax,1
mov [ebx],eax
mov [init_sound_busy_flag],0
ret
;------------------------------------------------------------------------------
sound_exit:
mcall -1
;------------------------------------------------------------------------------
find_data_offset:
mov esi,[wav_for_test] ;letter_1a
mov esi,[wav_for_test]
;--------------------------------------
@@:
cmp [esi],dword 'data'
je @f
inc esi
cmp esi,[wav_for_test_end] ;letter_1a + letter_2b
cmp esi,[wav_for_test_end]
jne @b
; DEBUGF 1, "find data offset fail\n"
@ -76,89 +91,75 @@ find_data_offset:
ret
;--------------------------------------
@@:
sub esi,[wav_for_test] ;letter_1a
sub esi,[wav_for_test]
add esi,4
mov [data_offset],esi
ret
;------------------------------------------------------------------------------
wave_out:
; in:
; eax - adress of wav sample
; ebp - hBuff ; hardware buffer
pusha
; DEBUGF 1, "Wave out\n"
; check for correct data_offset
push eax
add eax,[data_offset]
sub eax,4
cmp [eax],dword 'data'
pop eax
je @f
mov [wav_for_test],eax
mov ebx,eax
add ebx,1024
mov [wav_for_test_end],ebx
call find_data_offset
cmp [sound_flag],0
jz .exit
;--------------------------------------
@@:
add eax,[data_offset]
mov ebx,[eax]
add eax,4
; DEBUGF 1, "src EAX: %x size EBX: %x\n",eax,ebx
; stdcall _WaveOut@12,[hBuff],eax,ebx
stdcall _WaveOut@12,ebp,eax,ebx
; DEBUGF 1, "return EAX: %x\n",eax
cmp eax,-1
popa
je snd_wave_out_fail
ret
;--------------------------------------
.exit:
popa
ret
;------------------------------------------------------------------------------
snd_init_fail:
; DEBUGF 1, "Sound init fail %x\n",eax
mov [sound_flag],0
ret
;------------------------------------------------------------------------------
snd_version_fail:
; DEBUGF 1, "Sound version fail %x\n",eax
mov [sound_flag],0
ret
;------------------------------------------------------------------------------
snd_test_wav_fail:
; DEBUGF 1, "Test wav fail %x\n",eax
mov [sound_flag],0
ret
;------------------------------------------------------------------------------
snd_init_fail:
; DEBUGF 1, "Sound init fail %x\n",eax
jmp disable_sound
;------------------------------------------------------------------------------
snd_version_fail:
; DEBUGF 1, "Sound version fail %x\n",eax
jmp disable_sound
;------------------------------------------------------------------------------
snd_create_buffer_fail:
; DEBUGF 1, "Create Buffer fail %x\n",eax
mov [sound_flag],0
ret
jmp disable_sound
;------------------------------------------------------------------------------
snd_wave_out_fail:
; DEBUGF 1, "Wave Out fail\n"
snd_get_buffer_size_fail:
; DEBUGF 1, "Get Buffer size fail %x\n",eax
jmp disable_sound
;------------------------------------------------------------------------------
snd_play_buffer_fail:
; DEBUGF 1, "Play Buffer fail\n"
jmp disable_sound
;------------------------------------------------------------------------------
snd_set_buffer_fail:
; DEBUGF 1, "Set Buffer fail\n"
jmp disable_sound
;------------------------------------------------------------------------------
disable_sound:
mov [sound_flag],0
ret
jmp sound_exit
;------------------------------------------------------------------------------
snd_background_music_thread_start:
call check_init_sound_busy
; DEBUGF 1, "snd_background_music_thread_start\n"
mov [hBuff_pointer], dword hBuff1
mov [hBuff_buffer_size_pointer], dword hBuff1_buffer_size
call initialize_sound_system
;--------------------------------------
.1:
cmp [music_flag],2
je sound_exit
cmp [music_flag],1
je .start
mcall 5,50
.2:
mcall 5,1
mcall 68,1
jmp snd_background_music_thread_start
jmp .1
;--------------------------------------
.start:
cmp [init_sound_busy_flag],1
je .2
; DEBUGF 1, "background_music Play Buffer start\n",eax
stdcall _PlayBuffer@8, [hBuff1], 0
test eax,eax
jnz snd_play_buffer_fail
; DEBUGF 1, "background_music Play Buffer successful EAX: %x\n",eax
;--------------------------------------
.start_1:
mov eax,[background_music]
; call wave_out
; pusha
; DEBUGF 1, "Wave out\n"
; check for correct data_offset
push eax
add eax,[data_offset]
@ -173,7 +174,7 @@ snd_background_music_thread_start:
mov [wav_for_test_end],ebx
call find_data_offset
cmp [sound_flag],0
jz snd_background_music_thread_start ;.exit
jz .1
;--------------------------------------
@@:
add eax,[data_offset]
@ -184,27 +185,45 @@ snd_background_music_thread_start:
; DEBUGF 1, "start EAX: %x\n",eax
;--------------------------------------
.loop:
cmp [music_flag],0
je snd_background_music_thread_start
; DEBUGF 1, "src EBP: %x size EBX: %x\n",ebp,ebx
; stdcall _WaveOut@12,[hBuff],eax,ebx
stdcall _WaveOut@12,[hBuff1],ebp,8192
; DEBUGF 1, "return EAX: %x\n",eax
cmp eax,-1
; popa
je snd_wave_out_fail
add ebp,8192*2
cmp ebx,ebp
jbe .start
sub ebp,8192
jmp .loop
cmp [music_flag],1
je @f
stdcall _StopBuffer@4, [hBuff1]
; DEBUGF 1, "Stop Buffer EAX: %x\n",eax
jmp .1
;--------------------------------------
;.exit:
; popa
; jmp snd_background_music_thread_start
; mcall -1
@@:
; get event data from the driver
; DEBUGF 1, "Get driver_notify_struct \n"
push ebx
mcall 68,14,hBuff1_driver_notify_struct
pop ebx
; DEBUGF 1, "Check to code \n"
; check to code
cmp [hBuff1_driver_notify_struct], dword 0xFF000001
jne @b
; DEBUGF 1, "Check to stream \n"
; check to stream
mov eax,[hBuff1_driver_notify_struct+8]
cmp eax,[hBuff1]
jne @b
; DEBUGF 1, "Get buffer_offset \n"
; get buffer_offset
mov eax,[hBuff1_driver_notify_struct+12]
mov [hBuff1_buffer_offset],eax
; DEBUGF 1, "src EBP: %x size EBX: %x\n",ebp,ebx
stdcall _SetBuffer@16, [hBuff1], ebp, [hBuff1_buffer_offset], [hBuff1_buffer_size]
test eax,eax
jnz snd_set_buffer_fail
; DEBUGF 1, "Set Buffer successful EAX: %x\n",eax
add ebp,[hBuff1_buffer_size]
add ebp,[hBuff1_buffer_size]
cmp ebx,ebp
jbe .start_1
sub ebp,[hBuff1_buffer_size]
jmp .loop
;------------------------------------------------------------------------------
snd_kick_action:
cmp [sounds_flag],1
@ -213,16 +232,109 @@ snd_kick_action:
cmp [snd_kick_flag],1
je @f
mcall 51,1,snd_kick_action_thread_start,snd_kick_action_thread_stack
mov [snd_kick_flag],1
;--------------------------------------
@@:
ret
;------------------------------------------------------------------------------
snd_kick_action_thread_start:
mov [snd_kick_flag],1
mov eax,[stone_kick_sound]
mov ebp,[hBuff2]
call wave_out
call check_init_sound_busy
; DEBUGF 1, "snd_kick_action_thread_start\n"
mov [hBuff_pointer], dword hBuff2
mov [hBuff_buffer_size_pointer], dword hBuff2_buffer_size
call initialize_sound_system
;--------------------------------------
.1:
cmp [sounds_flag],2
je sound_exit
cmp [sounds_flag],0
je @f
cmp [snd_kick_flag],1
je .start
;--------------------------------------
@@:
mcall 5,1
mcall 68,1
jmp .1
;--------------------------------------
.start:
; DEBUGF 1, "kick_action Play Buffer start\n"
stdcall _PlayBuffer@8, [hBuff2], 0
test eax,eax
jnz snd_play_buffer_fail
; DEBUGF 1, "kick_action Play Buffer successful EAX: %x\n",eax
mov eax,[sounds_sample] ;[stone_kick_sound]
; check for correct data_offset
push eax
add eax,[data_offset]
sub eax,4
cmp [eax],dword 'data'
pop eax
je @f
mov [wav_for_test],eax
mov ebx,eax
add ebx,1024
mov [wav_for_test_end],ebx
call find_data_offset
cmp [sound_flag],0
jz .1
;--------------------------------------
@@:
add eax,[data_offset]
mov ebx,[eax]
add eax,4
mov ebp,eax
add ebx,eax
; DEBUGF 1, "start EAX: %x\n",eax
;--------------------------------------
.loop:
cmp [sounds_flag],1
je @f
stdcall _StopBuffer@4, [hBuff2]
; DEBUGF 1, "Stop Buffer EAX: %x\n",eax
jmp .1
;--------------------------------------
@@:
; get event data from the driver
; DEBUGF 1, "Get driver_notify_struct \n"
push ebx
mcall 68,14,hBuff2_driver_notify_struct
pop ebx
; DEBUGF 1, "Check to code \n"
; check to code
cmp [hBuff2_driver_notify_struct], dword 0xFF000001
jne @b
; DEBUGF 1, "Check to stream \n"
; check to stream
mov eax,[hBuff2_driver_notify_struct+8]
cmp eax,[hBuff2]
jne @b
; DEBUGF 1, "Get buffer_offset \n"
; get buffer_offset
mov eax,[hBuff2_driver_notify_struct+12]
mov [hBuff2_buffer_offset],eax
; DEBUGF 1, "src EBP: %x size EBX: %x\n",ebp,ebx
stdcall _SetBuffer@16, [hBuff2], ebp, [hBuff2_buffer_offset], [hBuff2_buffer_size]
test eax,eax
jnz snd_set_buffer_fail
; DEBUGF 1, "Set Buffer successful EAX: %x\n",eax
add ebp,[hBuff2_buffer_size]
add ebp,[hBuff2_buffer_size]
cmp ebx,ebp
jbe .exit
sub ebp,[hBuff2_buffer_size]
jmp .loop
;--------------------------------------
.exit:
stdcall _StopBuffer@4, [hBuff2]
mov [snd_kick_flag],0
mcall -1
jmp .1
;------------------------------------------------------------------------------

View File

@ -13,6 +13,7 @@ snd_kick_flag rb 1
main_menu_pointer rb 1
settings_menu_pointer rb 1
use_separate_draw_text rb 1
init_sound_busy_flag rb 1
;---------------------------------------------------------------------
align 4
N_error rd 1
@ -30,7 +31,10 @@ npc_ifrit_icons rd 1
npc_barret_icons rd 1
;---------------------------------------------------------------------
background_music rd 1
sounds_sample rd 1
stone_kick_sound rd 1
menu_sound rd 1
;---------------------------------------------------------------------
show_tiles_iterations rd 1
characters_offset_x rd 1
@ -58,10 +62,21 @@ version rd 1 ; версия интерфейса, текущая 0x0101
; Окончательно формат устанавливается вызовом SetFormat.
snd_format rd 1 ; формат данных
; хэндл буфера
;hBuff rd 1
hBuff_pointer rd 1
hBuff_buffer_size_pointer rd 1
hBuff1 rd 1
hBuff2 rd 1
hBuff1_buffer_size rd 1
hBuff2_buffer_size rd 1
hBuff1_buffer_offset rd 1
hBuff2_buffer_offset rd 1
hBuff1_driver_notify_struct rd 6 ; структура события от драйвера
hBuff2_driver_notify_struct rd 6 ; структура события от драйвера
data_offset rd 1
;---------------------------------------------------------------------
voice_samples_start rd 1 ; start of *.SMP