From 2eb2bb82f99ac3c24f2387329971ba548cca3c36 Mon Sep 17 00:00:00 2001 From: Bobbi Webber-Manners Date: Tue, 18 Oct 2022 00:15:39 -0400 Subject: [PATCH] ADSR refactoring. --- applecorn.po | Bin 819200 -> 819200 bytes mainmem.audio.s | 29 ++++++++++++++++++----------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/applecorn.po b/applecorn.po index 7bc75f46c7f4d24d95f6da0c73a404e197d7aedb..284abffb4b581e711170e9e89252b9ba6f3322e5 100644 GIT binary patch delta 414 zcmZo@FluNp+K|p7@YIDNNSBX+q2V!u0*KLE&eC4a!U)7nK+FupAU-P)vjH(X5OV-A z=k{_IuG9&Pm$%=Y!sTMm=sI2L3RfJEYP`aAnCEDcL~UK%+`70G3X`V?T;&qYQcPID zzR|{G0ry6mDuro@8)Om|aDezcP(Dw>0?v&#D^@Z9B@_NN#U=C|P3parc!0q`_-& z;7|bb8x}DG`SY^kP6>QZ@VFHPw8LY?&Zo&BYxgGs)nov9Nh?+=KzLPAD;*##pji!Y z)&e-|094(tjD%ZJ$mUe(0=Y;A{Q}Cv%&Lk?kjOonv?_sNt<3?0-w7TH$F}de#%0L7 P><^1X+b6DNpSb$~{Y$Lf delta 399 zcmZo@FluNp+K|p7aLI)sP}h`^q2V!u0*KLE&eC4a!U)7nK+FupAU-P)vjH(X5OV-A z=k{_IuG9&P2e#jx!sTMmXf$2v3RfJEYP`aAm}gUxL~UK%+`70G3Juc(u5yWn%Oxye z-)Q5pfP14&mBNI?4PprkI6!ZcNOSsz>cY(F|sF+QZmpQg*8b)H5ou&(u$P|5MEW(N(TrFXjTK9 zwE)gK09E%ZBjHvQvN=_{KrWI&zku>Ev#O#JByu+;tx8~6YjeQhcY=q)=I!UNaTzjC T7GM%y_J>8H?Gx9sPuzU~ A1L,A1H LDA PITCHSECT,X ; See what section we are in @@ -551,7 +551,7 @@ UPDPITCH STX OSCNUM * Process amplitude envelope * On entry: X is audio channel # * X is preserved -ADSRENV LDA CHANENV,X ; Set envelope number +ADSRENV LDA CHANENV,X ; Get envelope number TAY JSR GETENVADDR ; Addr of envelope -> A1L,A1H LDA AMPSECT,X ; See what section we are in @@ -577,14 +577,14 @@ ADSRENV LDA CHANENV,X ; Set envelope number LDY #ENVALD ; Parm: level at end of delay LDA (A1L),Y ; Get value of parm PLY -* JSR ADSRPHASE ; Generic ADSR phase handler + JSR ADSRPHASE ; Generic ADSR phase handler BCS :NEXTSECT ; Phase done -> sustain RTS :SUSTAIN LDY #ENVAS ; Parm: delay change/step LDA (A1L),Y ; Get value of parm TAY LDA #$00 ; Target level zero -* JSR ADSRPHASE ; Generic ADSR phase handler + JSR ADSRPHASE ; Generic ADSR phase handler RTS :NEXTSECT INC AMPSECT,X ; Next section RTS @@ -593,21 +593,28 @@ ADSRENV LDA CHANENV,X ; Set envelope number * Handle any individual phase of the ADSR envelope. Called by ADSRENV. * On entry: A - level at end of phase, X - audio channel, Y - change/step * On return: CS if end of phase, CC otherwise. X preserved. -ADSRPHASE CMP CURRAMP,X ; Compare tgt with current level +ADSRPHASE STX OSCNUM + STA :TARGET ; Stash target level for later + CPY #$00 ; Check sign of change/step + BMI :DESCEND ; Descending amplitude +:ASCEND CMP CURRAMP,X ; Compare tgt with current level BNE :S1 ; Not equal to target, keep going SEC ; CS to indicate phase is done RTS -:S1 STA :TARGET ; Target level - TYA ; Change/step -> A +:S1 TYA ; Change/step -> A CLC ADC CURRAMP,X ; Add change to current amp - BCS :CLAMP ; If wrapped, clamp to target - CPY #$00 ; Check sign of change/step - BMI :DESCEND ; Descending amplitude CMP :TARGET ; Compare with target BCS :CLAMP ; If target < sum, clamp to target BRA :UPDATE -:DESCEND CMP :TARGET ; Compare with target +:DESCEND CMP CURRAMP,X ; Compare tgt with current level + BNE :S2 ; Not equal to target, keep going + SEC ; CS to indicate phase is done + RTS +:S2 TYA ; Change/step -> A + CLC + ADC CURRAMP,X ; Add change to current amp + CMP :TARGET ; Compare with target BCC :CLAMP ; If target >= sum, clamp to target BRA :UPDATE :CLAMP LDA :TARGET ; Recover target level