added sustain to psg envelope

This commit is contained in:
Irmen de Jong 2022-07-03 00:55:25 +02:00
parent cc41218d37
commit 4bdac7404a
2 changed files with 16 additions and 6 deletions

View File

@ -41,9 +41,10 @@ psg {
cx16.vpoke(1, reg, cx16.vpeek(1, reg) & %11000000 | pw)
}
sub envelope(ubyte voice_num, ubyte attack, ubyte release) {
sub envelope(ubyte voice_num, ubyte attack, ubyte sustain, ubyte release) {
envelope_states[voice_num] = 255
envelope_attacks[voice_num] = attack * $0040
envelope_sustains[voice_num] = sustain
envelope_releases[voice_num] = release * $0040
if attack
attack = 0
@ -75,11 +76,19 @@ psg {
if msb(cx16.r0) & %11000000 or envelope_attacks[cx16.r15L]==0 {
cx16.r0 = mkword(63, 0)
envelope_attacks[cx16.r15L] = 0
envelope_states[cx16.r15L] = 1 ; start release
envelope_states[cx16.r15L] = 1 ; start sustain
}
envelope_volumes[cx16.r15L] = cx16.r0
}
1 -> {
; sustain
if envelope_sustains[cx16.r15L] {
envelope_sustains[cx16.r15L]--
} else {
envelope_states[cx16.r15L] = 2 ; start release
}
}
2 -> {
; release
cx16.r0 = envelope_volumes[cx16.r15L] - envelope_releases[cx16.r15L]
if msb(cx16.r0) & %11000000 {
@ -110,5 +119,6 @@ psg {
ubyte[16] envelope_states
uword[16] envelope_volumes
uword[16] envelope_attacks
ubyte[16] envelope_sustains
uword[16] envelope_releases
}

View File

@ -12,8 +12,8 @@ main {
psg.voice(1, psg.RIGHT, 0, psg.NOISE, 0)
psg.freq(0, 1000)
psg.freq(1, 2000)
psg.envelope(0, 50, 5)
psg.envelope(1, 80, 6)
psg.envelope(0, 50, 0, 5)
psg.envelope(1, 80, 0, 6)
sys.wait(100)
psg.silent()
cx16.restore_irq()
@ -68,8 +68,8 @@ main {
ubyte note1 = msb(note)
psg.freq(0, vera_freqs[note0])
psg.freq(1, vera_freqs[note1])
psg.envelope(0, 255, 6)
psg.envelope(1, 255, 6)
psg.envelope(0, 255, 0, 6)
psg.envelope(1, 255, 0, 6)
print_notes(note0, note1)
sys.wait(10)
}