From 55d9ca0ffc3d8df750b28024fd110138637dcad4 Mon Sep 17 00:00:00 2001 From: Veikko Sariola Date: Mon, 25 May 2020 17:23:54 +0300 Subject: [PATCH] Reverse the voiceno counter: now it starts from MAX_VOICES and decrements until 0. This way, the VM needs not know anything about MAX_VOICES. --- src/opcodes/flowcontrol.asm | 5 +++-- src/player.asm | 5 +++-- src/sointu.asm | 15 +++++++++------ src/sointu.inc | 5 +++-- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/opcodes/flowcontrol.asm b/src/opcodes/flowcontrol.asm index 84a51c7..227b414 100644 --- a/src/opcodes/flowcontrol.asm +++ b/src/opcodes/flowcontrol.asm @@ -17,6 +17,7 @@ EXPORT MANGLE_FUNC(su_op_advance,0) ; Stack: addr voice wrkptr valptr comptr add WRK, su_voice.size ; move to next voice mov [_SP+su_stack.wrk], WRK ; update stack mov ecx, [_SP+su_stack.voiceno] ; ecx = voice + dec ecx ; decrement number of voices to process bt dword [_SP+su_stack.polyphony], ecx ; if voice bit of su_polyphonism not set jnc su_op_advance_next_instrument ; goto next_instrument mov VAL, PTRWORD [_SP+su_stack.val] ; rollback to where we were earlier @@ -26,7 +27,7 @@ su_op_advance_next_instrument: mov PTRWORD [_SP+su_stack.val], VAL ; save current VAL as a checkpoint mov PTRWORD [_SP+su_stack.com], COM ; save current COM as a checkpoint su_op_advance_finish: - inc PTRWORD [_SP+su_stack.voiceno] + mov [_SP+su_stack.voiceno], ecx ret %else @@ -34,7 +35,7 @@ su_op_advance_finish: mov WRK, PTRWORD [_SP+su_stack.wrk] ; WRK = wrkptr add WRK, su_voice.size ; move to next voice mov PTRWORD [_SP+su_stack.wrk], WRK ; update stack - inc PTRWORD [_SP+su_stack.voiceno] ; voice++ + dec PTRWORD [_SP+su_stack.voiceno] ; voices-- ret %endif diff --git a/src/player.asm b/src/player.asm index 83ae363..48c837b 100644 --- a/src/player.asm +++ b/src/player.asm @@ -123,6 +123,7 @@ su_render_sampleloop: ; loop through every sample in the row %ifdef INCLUDE_POLYPHONY push POLYPHONY_BITMASK ; does the next voice reuse the current opcodes? %endif + push MAX_VOICES mov _DX, PTRWORD su_synth_obj ; _DX points to the synth object mov COM, PTRWORD MANGLE_DATA(su_commands) ; COM points to vm code mov VAL, PTRWORD MANGLE_DATA(su_params) ; VAL points to unit params @@ -130,13 +131,13 @@ su_render_sampleloop: ; loop through every sample in the row lea _CX, [_DX + su_synth.size - su_delayline_wrk.filtstate] %endif lea WRK, [_DX + su_synth.voices] ; WRK points to the first voice - xor edi, edi ; voice = 0 call MANGLE_FUNC(su_run_vm,0) ; run through the VM code + pop _AX %ifdef INCLUDE_POLYPHONY pop _AX %endif output_sound ; *ptr++ = left, *ptr++ = right - pop _AX ; Stack: row pushad ptr + pop _AX inc dword [_SP + PTRSIZE] ; increment global time, used by delays inc eax cmp eax, SAMPLES_PER_ROW diff --git a/src/sointu.asm b/src/sointu.asm index dd33aef..cf72767 100644 --- a/src/sointu.asm +++ b/src/sointu.asm @@ -99,7 +99,9 @@ struc su_stack ; the structure of stack _as the units see it_ .retaddr RESPTR 1 - .voiceno RESPTR 1 +%if BITS == 32 ; we dump everything with pushad, so this is unused in 32-bit + RESPTR 1 +%endif .val RESPTR 1 .wrk RESPTR 1 %if BITS == 32 ; we dump everything with pushad, so this is unused in 32-bit @@ -112,6 +114,7 @@ struc su_stack ; the structure of stack _as the units see it_ RESPTR 1 %endif .retaddrvm RESPTR 1 + .voiceno RESPTR 1 %ifdef INCLUDE_POLYPHONY .polyphony RESPTR 1 %endif @@ -175,7 +178,7 @@ EXPORT MANGLE_DATA(LFO_NORMALIZE) ; COM : Pointer to command stream ; VAL : Pointer to value stream ; WRK : Pointer to the last workspace processed -; _DI : Voice number (0 = starting from first voice) +; _DI : Number of voices to process ; Output: su_synth_obj.left : left sample ; su_synth_obj.right : right sample ; Dirty: everything @@ -183,7 +186,7 @@ EXPORT MANGLE_DATA(LFO_NORMALIZE) SECT_TEXT(surunvm) EXPORT MANGLE_FUNC(su_run_vm,0) - push_registers _CX, _DX, COM, WRK, VAL, _DI ; save everything to stack + push_registers _CX, _DX, COM, WRK, VAL ; save everything to stack su_run_vm_loop: ; loop until all voices done movzx edi, byte [COM] ; edi = command byte inc COM ; move to next instruction @@ -210,9 +213,9 @@ su_transform_values_loop: su_transform_values_out: bt dword [COM-1],0 ; LSB of COM = stereo bit => carry do call [,su_synth_commands,_DI*PTRSIZE,] ; call the function corresponding to the instruction - cmp dword [_SP+su_stack.voiceno-PTRSIZE],MAX_VOICES ; if (voice < MAX_VOICES) - jl su_run_vm_loop ; goto vm_loop - pop_registers _CX, _DX, COM, WRK, VAL, _DI ; pop everything from stack + cmp dword [_SP+su_stack.voiceno-PTRSIZE],0 ; do we have more voices to process? + jne su_run_vm_loop ; if there's more voices to process, goto vm_loop + pop_registers _CX, _DX, COM, WRK, VAL ; pop everything from stack ret ;------------------------------------------------------------------------------- diff --git a/src/sointu.inc b/src/sointu.inc index 318d4aa..9c11409 100644 --- a/src/sointu.inc +++ b/src/sointu.inc @@ -128,10 +128,11 @@ ; increment MAX_VOICES equal to %1 and construct the POLYPHONY_BITMASK so that ; for every except the last, the bit is on %rep %1-1 - %assign POLYPHONY_BITMASK POLYPHONY_BITMASK + (1 << MAX_VOICES) + %assign POLYPHONY_BITMASK (POLYPHONY_BITMASK << 1) + 1 %assign MAX_VOICES MAX_VOICES + 1 %endrep - %assign MAX_VOICES MAX_VOICES + 1 ; the last voice increment, without adding bit mask + %assign POLYPHONY_BITMASK (POLYPHONY_BITMASK << 1) + %assign MAX_VOICES MAX_VOICES + 1 ; the last voice increment, without adding one bit to the mask %if MAX_VOICES > 32 %error Error: cannot have more than 32 voices! %endif