--- np2/win9x/x86/opngeng.x86 2003/10/25 09:08:24 1.4 +++ np2/win9x/x86/opngeng.x86 2003/11/28 08:01:33 1.6 @@ -1,4 +1,33 @@ +FMDIV_BITS equ 8 +FMDIV_ENT equ (1 << FMDIV_BITS) +FMVOL_SFTBIT equ 4 + +SIN_BITS equ 11 +EVC_BITS equ 10 +ENV_BITS equ 16 +KF_BITS equ 6 +FREQ_BITS equ 20 +ENVTBL_BIT equ 14 +SINTBL_BIT equ 14 + +TL_BITS equ (FREQ_BITS+2) +OPM_OUTSB equ (TL_BITS + 2 - 16) + +SIN_ENT equ (1 << SIN_BITS) +EVC_ENT equ (1 << EVC_BITS) + +EC_ATTACK equ 0 +EC_DECAY equ (EVC_ENT << ENV_BITS) +EC_OFF equ ((2 * EVC_ENT) << ENV_BITS) + +EM_ATTACK equ 4 +EM_DECAY1 equ 3 +EM_DECAY2 equ 2 +EM_RELEASE equ 1 +EM_OFF equ 0 + + struc slot_t .detune1 resd 1 ; 00 .totallevel resd 1 ; 04 @@ -29,7 +58,7 @@ .algorithm resb 1 .feedback resb 1 .playing resb 1 - resb 1 +.outslot resb 1 .op1fb resd 1 .connect1 resd 1 .connect3 resd 1 @@ -66,36 +95,11 @@ .vr_en resd 1 .vr_l resd 1 .vr_r resd 1 - endstruc - - -FMDIV_BITS equ 8 -FMDIV_ENT equ (1 << FMDIV_BITS) -FMVOL_SFTBIT equ 4 -SIN_BITS equ 11 -EVC_BITS equ 10 -ENV_BITS equ 16 -KF_BITS equ 6 -FREQ_BITS equ 20 -ENVTBL_BIT equ 14 -SINTBL_BIT equ 14 - -TL_BITS equ (FREQ_BITS+2) -OPM_OUTSB equ (TL_BITS + 2 - 16) - -SIN_ENT equ (1 << SIN_BITS) -EVC_ENT equ (1 << EVC_BITS) - -EC_ATTACK equ 0 -EC_DECAY equ (EVC_ENT << ENV_BITS) -EC_OFF equ ((2 * EVC_ENT) << ENV_BITS) - -EM_ATTACK equ 4 -EM_DECAY1 equ 3 -EM_DECAY2 equ 2 -EM_RELEASE equ 1 -EM_OFF equ 0 +.sintable resd SIN_ENT +.envtable resd EVC_ENT +.envcurve resd (EVC_ENT*2 + 1) + endstruc section .text @@ -105,10 +109,11 @@ section .text extern _opncfg extern _sinshift - extern _sintable extern _envshift - extern _envtable - extern _env_curve + +ENVCURVE equ (_opncfg + opncfg_t.envcurve) +SINTABLE equ (_opncfg + opncfg_t.sintable) +ENVTABLE equ (_opncfg + opncfg_t.envtable) global @opngen_getpcm@12 @@ -119,9 +124,9 @@ section .text shr eax, (FREQ_BITS - SIN_BITS) and eax, (SIN_ENT - 1) mov cl, [_sinshift + eax] - mov eax, [_sintable + eax*4] + mov eax, [SINTABLE + eax*4] add cl, [_envshift + edx] - imul eax, [_envtable + edx*4] + imul eax, [ENVTABLE + edx*4] sar eax, cl %endmacro @@ -135,10 +140,10 @@ section .text %2: mov [edi + slot_t.env_cnt], eax shr eax, ENV_BITS mov edx, [edi + slot_t.totallevel] - sub edx, [_env_curve + eax*4] + sub edx, [ENVCURVE + eax*4] %endmacro -%macro setenv 2 +%macro setenv 3 %1: mov dl, [edi + slot_t.env_mode] dec dl je short %%setrr @@ -164,6 +169,7 @@ section .text %%setrr: mov byte [edi + slot_t.env_mode], EM_OFF %%setd2: mov dword [edi + slot_t.env_end], EC_OFF + 1 and dword [edi + slot_t.env_inc], byte 0 + and byte [esi + ch_t.playing], ~(%3) mov eax, EC_OFF jmp near %2 %endmacro @@ -173,6 +179,8 @@ section .text @opngen_getpcm@12: cmp dword [esp+4], byte 0 je near og_noupdate + cmp dword [_opngen + opngen_t.playing], byte 0 + je near og_noupdate push ebx push esi @@ -193,18 +201,20 @@ og_fmout_st: mov eax, ebx sub ebx, eax imul eax, [_opngen + opngen_t.outdr] mov [esp + OPN_SAMPR], eax -og_fmout_lp: xor eax, eax - mov [_opngen + opngen_t.calcremain], ebx - mov [_opngen + opngen_t.outdl], eax - mov [_opngen + opngen_t.outdc], eax - mov [_opngen + opngen_t.outdr], eax +og_fmout_lp: mov [_opngen + opngen_t.calcremain], ebx + and dword [_opngen + opngen_t.playing], byte 0 + and dword [_opngen + opngen_t.outdl], byte 0 + and dword [_opngen + opngen_t.outdc], byte 0 + and dword [_opngen + opngen_t.outdr], byte 0 mov ch, [_opngen + opngen_t.playchannels] - mov edi, _opnch -og_calcch_lp: xor eax, eax - mov [_opngen + opngen_t.feedback2], eax - mov [_opngen + opngen_t.feedback3], eax - mov [_opngen + opngen_t.feedback4], eax - mov esi, edi + mov esi, _opnch +og_calcch_lp: mov cl, [esi + ch_t.outslot] + test cl, [esi + ch_t.playing] + je near og_calcch_nt + and dword [_opngen + opngen_t.feedback2], byte 0 + and dword [_opngen + opngen_t.feedback3], byte 0 + and dword [_opngen + opngen_t.feedback4], byte 0 + mov edi, esi calcenv envcalc1, envret1 ; slot1 calculate jl near og_calcslot3 mov cl, [esi + ch_t.feedback] @@ -249,7 +259,8 @@ og_calcslot4: add edi, byte slot_t.size op_out mov ebx, [esi + ch_t.connect4] add [ebx], eax -og_calcsloted: add edi, byte (ch_t.size - (slot_t.size * 3)) +og_calcsloted: inc dword [_opngen + opngen_t.playing] +og_calcch_nt: add esi, ch_t.size dec ch jne near og_calcch_lp mov eax, [_opngen + opngen_t.outdc] @@ -291,10 +302,10 @@ og_nextsamp: neg ebx pop ebx og_noupdate: ret 4 - setenv envcalc1, envret1 - setenv envcalc2, envret2 - setenv envcalc3, envret3 - setenv envcalc4, envret4 + setenv envcalc1, envret1, 1 + setenv envcalc2, envret2, 2 + setenv envcalc3, envret3, 4 + setenv envcalc4, envret4, 8 align 16 @@ -435,10 +446,10 @@ ogv_nextsamp: neg ebx pop ebx ogv_noupdate: ret 4 - setenv vrenvcalc1, vrenvret1 - setenv vrenvcalc2, vrenvret2 - setenv vrenvcalc3, vrenvret3 - setenv vrenvcalc4, vrenvret4 + setenv vrenvcalc1, vrenvret1, 1 + setenv vrenvcalc2, vrenvret2, 2 + setenv vrenvcalc3, vrenvret3, 4 + setenv vrenvcalc4, vrenvret4, 8 ends