diff --git a/src/opcodes/flowcontrol.asm b/src/opcodes/flowcontrol.asm index d0ec213..79e1252 100644 --- a/src/opcodes/flowcontrol.asm +++ b/src/opcodes/flowcontrol.asm @@ -21,28 +21,28 @@ SECT_TEXT(suopadvn) %ifdef INCLUDE_POLYPHONY EXPORT MANGLE_FUNC(su_op_advance,0) ; Stack: addr voice wrkptr valptr comptr - mov WRK, [_SP+PTRSIZE*2] ; WRK = wrkptr + mov WRK, [_SP+su_stack.wrk] ; WRK = wrkptr add WRK, su_voice.size ; move to next voice - mov [_SP+PTRSIZE*2], WRK ; update stack - mov ecx, [_SP+PTRSIZE] ; ecx = voice + mov [_SP+su_stack.wrk], WRK ; update stack + mov ecx, [_SP+su_stack.voiceno] ; ecx = voice apply bt dword,su_polyphony_bitmask,{,ecx} ; if voice bit of su_polyphonism not set jnc su_op_advance_next_instrument ; goto next_instrument - mov VAL, PTRWORD [_SP+PTRSIZE*3] ; rollback to where we were earlier - mov COM, PTRWORD [_SP+PTRSIZE*4] + mov VAL, PTRWORD [_SP+su_stack.val] ; rollback to where we were earlier + mov COM, PTRWORD [_SP+su_stack.com] jmp short su_op_advance_finish su_op_advance_next_instrument: - mov PTRWORD [_SP+PTRSIZE*3], VAL ; save current VAL as a checkpoint - mov PTRWORD [_SP+PTRSIZE*4], COM ; save current COM as a checkpoint + 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+PTRSIZE] + inc PTRWORD [_SP+su_stack.voiceno] ret %else EXPORT MANGLE_FUNC(su_op_advance,0) ; Stack: addr voice wrkptr valptr comptr - mov WRK, PTRWORD [_SP+PTRSIZE*2] ; WRK = wrkptr + mov WRK, PTRWORD [_SP+su_stack.wrk] ; WRK = wrkptr add WRK, su_voice.size ; move to next voice - mov PTRWORD [_SP+PTRSIZE*2], WRK ; update stack - inc PTRWORD [_SP+PTRSIZE] ; voice++ + mov PTRWORD [_SP+su_stack.wrk], WRK ; update stack + inc PTRWORD [_SP+su_stack.voiceno] ; voice++ ret %endif @@ -65,7 +65,7 @@ EXPORT MANGLE_FUNC(su_op_speed,0) fist dword [_SP] ; Main stack: k=int(t+2^p-1) fisub dword [_SP] ; t+2^p-1-k, the remainder pop _AX - add dword [_SP+6*PTRSIZE], eax ; add the whole ticks to song tick count, [esp+24] is the current tick in the row + add dword [_SP+su_stack.curtick], eax ; add the whole ticks to song tick count, [esp+24] is the current tick in the row fstp dword [WRK+su_speed_wrk.remainder] ; save the remainder for future ret diff --git a/src/sointu.asm b/src/sointu.asm index 3e23bfd..c56fa13 100644 --- a/src/sointu.asm +++ b/src/sointu.asm @@ -93,6 +93,16 @@ %endmacro %endif +struc su_stack ; the structure of stack _as the units see it_ + .retaddr RESPTR 1 + .voiceno RESPTR 1 + .wrk RESPTR 1 + .val RESPTR 1 + .com RESPTR 1 + .retaddrvm RESPTR 1 + .curtick RESPTR 1 +endstruc + ;=============================================================================== ; Uninitialized data: The one and only synth object ;=============================================================================== @@ -174,13 +184,13 @@ su_run_vm_loop: ; loop until all voices done apply {mov al,byte},su_opcode_numparams,_AX,{} push _AX call su_transform_values - mov _CX, PTRWORD [_SP+2*PTRSIZE] + mov _CX, PTRWORD [_SP+su_stack.wrk] pop _AX shr eax,1 apply call,su_synth_commands,_AX*PTRSIZE,{} ; call the function corresponding to the instruction - cmp dword [_SP],MAX_VOICES ; if (voice < MAX_VOICES) + cmp dword [_SP+su_stack.voiceno-PTRSIZE],MAX_VOICES ; if (voice < MAX_VOICES) jl su_run_vm_loop ; goto vm_loop - add _SP, 4*PTRSIZE ; Stack cleared + add _SP, su_stack.retaddrvm-PTRSIZE ; Stack cleared ret ;-------------------------------------------------------------------------------