Implement IN, OUTAUX and AUX opcodes, to conveniently input from or output to global ports.

This commit is contained in:
Veikko Sariola
2020-05-25 23:14:02 +03:00
parent 17c6afceb4
commit dac5afea60
18 changed files with 350 additions and 3 deletions

View File

@ -1,8 +1,8 @@
;-------------------------------------------------------------------------------
; OUT opcode: outputs and pops the signal
;-------------------------------------------------------------------------------
; Mono: add ST0 to global left port
; Stereo: also add ST1 to global right port
; Mono: add ST0 to main left port
; Stereo: also add ST1 to main right port
;-------------------------------------------------------------------------------
%if OUT_ID > -1
@ -23,6 +23,61 @@ EXPORT MANGLE_FUNC(su_op_out,0) ; l r
%endif ; SU_OUT_ID > -1
;-------------------------------------------------------------------------------
; OUTAUX opcode: outputs to main and aux1 outputs and pops the signal
;-------------------------------------------------------------------------------
; Mono: add outgain*ST0 to main left port and auxgain*ST0 to aux1 left
; Stereo: also add outgain*ST1 to main right port and auxgain*ST1 to aux1 right
;-------------------------------------------------------------------------------
%if OUTAUX_ID > -1
SECT_TEXT(suoutaux)
EXPORT MANGLE_FUNC(su_op_outaux,0) ; l r
mov _AX, [_SP + su_stack.synth]
%ifdef INCLUDE_STEREO_OUTAUX
jnc su_op_outaux_mono
call su_op_outaux_mono
add _AX, 4
su_op_outaux_mono:
%endif
fld st0 ; l l
fmul dword [INP + su_outaux_ports.outgain] ; g*l
fadd dword [_AX + su_synth.left] ; g*l+o
fstp dword [_AX + su_synth.left] ; o'=g*l+o
fmul dword [INP + su_outaux_ports.auxgain] ; h*l
fadd dword [_AX + su_synth.aux] ; h*l+a
fstp dword [_AX + su_synth.aux] ; a'=h*l+a
ret
%endif ; SU_OUTAUX_ID > -1
;-------------------------------------------------------------------------------
; AUX opcode: outputs the signal to aux (or main) port and pops the signal
;-------------------------------------------------------------------------------
; Mono: add gain*ST0 to left port
; Stereo: also add gain*ST1 to right port
;-------------------------------------------------------------------------------
%if AUX_ID > -1
SECT_TEXT(suopaux)
EXPORT MANGLE_FUNC(su_op_aux,0) ; l r
lodsb
mov _DI, [_SP + su_stack.synth]
%ifdef INCLUDE_STEREO_AUX
jnc su_op_aux_mono
call su_op_aux_mono
add _DI, 4
su_op_aux_mono:
%endif
fmul dword [INP + su_aux_ports.gain] ; g*l
fadd dword [_DI + su_synth.left + _AX*4] ; g*l+o
fstp dword [_DI + su_synth.left + _AX*4] ; o'=g*l+o
ret
%endif ; SU_AUX_ID > -1
;-------------------------------------------------------------------------------
; SEND opcode: adds the signal to a port
;-------------------------------------------------------------------------------

View File

@ -27,6 +27,66 @@ struc su_out_ports
.params
endstruc
;-------------------------------------------------------------------------------
; OUTAUX structs
;-------------------------------------------------------------------------------
%assign OUTAUX_ID -1
%macro USE_OUTAUX 0
%if OUTAUX_ID == -1
%assign OUTAUX_ID CUR_ID
%assign CUR_ID CUR_ID + 2
%xdefine OPCODES OPCODES MANGLE_FUNC(su_op_outaux,0),
%xdefine NUMPARAMS NUMPARAMS 2,
%endif
%endmacro
%macro SU_OUTAUX 3
db %2
db %3
USE_OUTAUX
%xdefine CMDS CMDS OUTAUX_ID+%1,
%if %1 == STEREO
%define INCLUDE_STEREO_OUTAUX
%endif
%endmacro
%define OUTGAIN(val) val
%define AUXGAIN(val) val
struc su_outaux_ports
.outgain resd 1
.auxgain resd 1
endstruc
;-------------------------------------------------------------------------------
; AUX defines
;-------------------------------------------------------------------------------
%assign AUX_ID -1
%macro USE_AUX 0
%if AUX_ID == -1
%assign AUX_ID CUR_ID
%assign CUR_ID CUR_ID + 2
%xdefine OPCODES OPCODES MANGLE_FUNC(su_op_aux,0),
%xdefine NUMPARAMS NUMPARAMS 1,
%endif
%endmacro
%macro SU_AUX 3
db %2
db %3
USE_AUX
%xdefine CMDS CMDS AUX_ID+%1,
%if %1 == STEREO
%define INCLUDE_STEREO_AUX
%endif
%endmacro
%define CHANNEL(val) val
struc su_aux_ports
.gain resd 1
endstruc
;-------------------------------------------------------------------------------
; SEND structs
;-------------------------------------------------------------------------------

View File

@ -406,3 +406,35 @@ su_op_receive_mono:
ret
%endif ; RECEIVE_ID > -1
;-------------------------------------------------------------------------------
; IN opcode: inputs and clears a global port
;-------------------------------------------------------------------------------
; Mono: push the left channel of a global port (out or aux)
; Stereo: also push the right channel (stack in l r order)
;-------------------------------------------------------------------------------
%if IN_ID > -1
SECT_TEXT(suopin)
EXPORT MANGLE_FUNC(su_op_in,0)
lodsb
%ifdef INCLUDE_STEREO_IN
mov _DI, [_SP + su_stack.synth]
jnc su_op_in_mono
call su_op_in_right
su_op_in_mono:
sub _DI, 4
su_op_in_right:
xor ecx, ecx
fld dword [_DI + su_synth.right + _AX*4]
mov dword [_DI + su_synth.right + _AX*4], ecx
%else
xor ecx, ecx
mov _DI, [_SP + su_stack.synth]
fld dword [_DI + su_synth.left + _AX*4]
mov dword [_DI + su_synth.left + _AX*4], ecx
%endif
ret
%endif ; SU_IN_ID > -1

View File

@ -250,3 +250,25 @@ struc su_receive_ports
.left resd 1
.right resd 1
endstruc
;-------------------------------------------------------------------------------
; IN defines
;-------------------------------------------------------------------------------
%assign IN_ID -1
%macro USE_IN 0
%if IN_ID == -1
%assign IN_ID CUR_ID
%assign CUR_ID CUR_ID + 2
%xdefine OPCODES OPCODES MANGLE_FUNC(su_op_in,0),
%xdefine NUMPARAMS NUMPARAMS 0,
%endif
%endmacro
%macro SU_IN 2
db %2
USE_IN
%xdefine CMDS CMDS IN_ID+%1,
%if %1 == STEREO
%define INCLUDE_STEREO_IN
%endif
%endmacro