psg tweaks

This commit is contained in:
Irmen de Jong 2022-07-02 20:07:05 +02:00
parent f8658f6afa
commit 7a3745f642
3 changed files with 73 additions and 22 deletions

View File

@ -53,10 +53,10 @@ psg {
}
sub silent() {
for cx16.r9L in 0 to 15 {
volume(cx16.r9L, 0)
envelope_volumes[cx16.r9L] = 0
envelope_states[cx16.r9L] = 1
for cx16.r15L in 0 to 15 {
volume(cx16.r15L, 0)
envelope_volumes[cx16.r15L] = 0
envelope_states[cx16.r15L] = 255
}
}
@ -71,25 +71,28 @@ psg {
cx16.r14H = cx16.VERA_ADDR_H
for cx16.r15L in 0 to 15 {
if envelope_states[cx16.r15L] {
; release
cx16.r0 = envelope_volumes[cx16.r15L] - envelope_releases[cx16.r15L]
if msb(cx16.r0) & %11000000 {
cx16.r0 = 0
envelope_releases[cx16.r15L] = 0
when envelope_states[cx16.r15L] {
0 -> {
; attack
cx16.r0 = envelope_volumes[cx16.r15L] + envelope_attacks[cx16.r15L]
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_volumes[cx16.r15L] = cx16.r0
volume(cx16.r15L, msb(cx16.r0))
}
envelope_volumes[cx16.r15L] = cx16.r0
volume(cx16.r15L, msb(cx16.r0))
} else {
; attack
cx16.r0 = envelope_volumes[cx16.r15L] + envelope_attacks[cx16.r15L]
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
1 -> {
; release
cx16.r0 = envelope_volumes[cx16.r15L] - envelope_releases[cx16.r15L]
if msb(cx16.r0) & %11000000 {
cx16.r0 = 0
envelope_releases[cx16.r15L] = 0
}
envelope_volumes[cx16.r15L] = cx16.r0
volume(cx16.r15L, msb(cx16.r0))
}
envelope_volumes[cx16.r15L] = cx16.r0
volume(cx16.r15L, msb(cx16.r0))
}
}
cx16.VERA_CTRL = cx16.r13L

View File

@ -4,6 +4,7 @@ TODO
For next release
^^^^^^^^^^^^^^^^
- optimize msb(cx16.r0) -> cx16.r0H, lsb(cx16.r0) -> cx16.r0L
- if passing a subroutine or label name as an uword argument, without &, add the addressof automatically
- convert the sounds in cx16 tehtriz to use the psg module instead
- notify petaxian that it could use the psg module too?

View File

@ -4,12 +4,59 @@
main {
sub start() {
sub explosion() {
; this subroutine is not used but it is an example of how to make a sound effect using the psg library!
psg.silent()
cx16.set_irq(&psg.envelopes_irq, true)
psg.voice(0, psg.LEFT, 0, psg.NOISE, 0)
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)
sys.wait(100)
psg.silent()
cx16.restore_irq()
}
sub sweeping() {
; this subroutine is not used but it is an example of how to make a sound effect using the psg library!
psg.silent()
psg.voice(0, psg.LEFT, 63, psg.PULSE, 0)
psg.voice(1, psg.LEFT, 63, psg.PULSE, 1)
psg.voice(2, psg.RIGHT, 63, psg.PULSE, 2)
psg.voice(3, psg.RIGHT, 63, psg.PULSE, 3)
psg.freq(0, 160)
psg.freq(1, 161)
psg.freq(2, 162)
psg.freq(3, 163)
repeat {
ubyte pw
for pw in 0 to 63 {
psg.pulse_width(0, pw)
psg.pulse_width(1, pw)
psg.pulse_width(2, pw)
psg.pulse_width(3, pw)
sys.wait(2)
}
for pw in 62 downto 1 {
psg.pulse_width(0, pw)
psg.pulse_width(1, pw)
psg.pulse_width(2, pw)
psg.pulse_width(3, pw)
sys.wait(2)
}
}
psg.silent()
}
sub start() {
txt.print("will play the music from boulderdash,\nmade in 1984 by peter liepa.\npress enter to start: ")
void c64.CHRIN()
txt.clear_screen()
psg.silent()
psg.voice(0, psg.LEFT, 63, psg.TRIANGLE, 0)
psg.voice(1, psg.RIGHT, 63, psg.TRIANGLE, 0)
cx16.set_irq(&psg.envelopes_irq, false)