From c51c1da618f1e7e0fa1a1d818637b97ce27f394a Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 3 Jul 2022 11:55:13 +0200 Subject: [PATCH] psg micro optimizations --- compiler/res/prog8lib/cx16/psg.p8 | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/compiler/res/prog8lib/cx16/psg.p8 b/compiler/res/prog8lib/cx16/psg.p8 index 4d1afad05..8af0e598f 100644 --- a/compiler/res/prog8lib/cx16/psg.p8 +++ b/compiler/res/prog8lib/cx16/psg.p8 @@ -16,8 +16,14 @@ psg { sub voice(ubyte voice_num, ubyte channel, ubyte volume, ubyte waveform, ubyte pulsewidth) { envelope_states[voice_num] = 255 - cx16.vpoke(1, $f9c2 + voice_num * 4, channel | volume) - cx16.vpoke(1, $f9c3 + voice_num * 4, waveform | pulsewidth) + cx16.r0 = $f9c2 + voice_num * 4 + cx16.VERA_CTRL = 0 + cx16.VERA_ADDR_L = lsb(cx16.r0) + cx16.VERA_ADDR_M = msb(cx16.r0) + cx16.VERA_ADDR_H = 1 + cx16.VERA_DATA0 = channel | volume + cx16.VERA_ADDR_L++ + cx16.VERA_DATA0 = waveform | pulsewidth envelope_volumes[voice_num] = mkword(volume, 0) envelope_maxvolumes[voice_num] = volume } @@ -30,20 +36,26 @@ psg { ; } sub freq(ubyte voice_num, uword vera_freq) { - cx16.vpoke(1, $f9c1 + voice_num*4, msb(vera_freq)) - cx16.vpoke(1, $f9c0 + voice_num*4, lsb(vera_freq)) + cx16.r0 = $f9c0 + voice_num * 4 + cx16.VERA_CTRL = 0 + cx16.VERA_ADDR_L = lsb(cx16.r0) + cx16.VERA_ADDR_M = msb(cx16.r0) + cx16.VERA_ADDR_H = 1 + cx16.VERA_DATA0 = lsb(vera_freq) + cx16.VERA_ADDR_L++ + cx16.VERA_DATA0 = msb(vera_freq) } sub volume(ubyte voice_num, ubyte vol) { - uword reg = $f9c2 + voice_num * 4 - cx16.vpoke(1, reg, cx16.vpeek(1, reg) & %11000000 | vol) + cx16.r0 = $f9c2 + voice_num * 4 + cx16.vpoke(1, cx16.r0, cx16.vpeek(1, cx16.r0) & %11000000 | vol) envelope_volumes[voice_num] = mkword(vol, 0) envelope_maxvolumes[voice_num] = vol } sub pulse_width(ubyte voice_num, ubyte pw) { - uword reg = $f9c3 + voice_num * 4 - cx16.vpoke(1, reg, cx16.vpeek(1, reg) & %11000000 | pw) + cx16.r0 = $f9c3 + voice_num * 4 + cx16.vpoke(1, cx16.r0, cx16.vpeek(1, cx16.r0) & %11000000 | pw) } sub envelope(ubyte voice_num, ubyte maxvolume, ubyte attack, ubyte sustain, ubyte release) {