|
| 1 | +;;; |
| 2 | +;;; nullsound - modular sound driver |
| 3 | +;;; Copyright (c) 2025 Damien Ciabrini |
| 4 | +;;; This file is part of ngdevkit |
| 5 | +;;; |
| 6 | +;;; ngdevkit is free software: you can redistribute it and/or modify |
| 7 | +;;; it under the terms of the GNU Lesser General Public License as |
| 8 | +;;; published by the Free Software Foundation, either version 3 of the |
| 9 | +;;; License, or (at your option) any later version. |
| 10 | +;;; |
| 11 | +;;; ngdevkit is distributed in the hope that it will be useful, |
| 12 | +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +;;; GNU Lesser General Public License for more details. |
| 15 | +;;; |
| 16 | +;;; You should have received a copy of the GNU Lesser General Public License |
| 17 | +;;; along with ngdevkit. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +;;; Trigger effect (delay, cut...), common functions for FM and SSG |
| 20 | +;;; |
| 21 | + |
| 22 | + .module nullsound |
| 23 | + |
| 24 | + .include "ym2610.inc" |
| 25 | + .include "struct-fx.inc" |
| 26 | + .include "pipeline.inc" |
| 27 | + |
| 28 | + |
| 29 | + .area CODE |
| 30 | + |
| 31 | + |
| 32 | +;;; ARPEGGIO |
| 33 | +;;; Enable arpeggio chord for note playback |
| 34 | +;;; ------ |
| 35 | +;;; ix : state for channel |
| 36 | +;;; [ hl ]: semitone:4 - semitone:4 |
| 37 | +;;; hl modified |
| 38 | +arpeggio:: |
| 39 | + ;; check whether this disables FX |
| 40 | + ld a, (hl) |
| 41 | + cp #0 |
| 42 | + jr nz, _arpeggio_init |
| 43 | + inc hl |
| 44 | + res BIT_FX_ARPEGGIO, FX(ix) |
| 45 | + ;; To fully clear the state after the FX is disabled, we must remember |
| 46 | + ;; to recompute the note and tune values without shift, so force it here |
| 47 | + ld ARPEGGIO_POS8(ix), a |
| 48 | + set BIT_LOAD_NOTE, PIPELINE(ix) |
| 49 | + ld a, #1 |
| 50 | + ret |
| 51 | +_arpeggio_init: |
| 52 | + ;; 2nd note in chord |
| 53 | + ld a, (hl) |
| 54 | + rra |
| 55 | + rra |
| 56 | + rra |
| 57 | + rra |
| 58 | + and #0xf |
| 59 | + ld ARPEGGIO_2ND(ix), a |
| 60 | + |
| 61 | + ;; 3rd note in chord |
| 62 | + ld a, (hl) |
| 63 | + and #0xf |
| 64 | + ld ARPEGGIO_3RD(ix), a |
| 65 | + |
| 66 | + inc hl |
| 67 | + |
| 68 | + ;; init arpeggio state if it is not running already |
| 69 | + bit BIT_FX_ARPEGGIO, FX(ix) |
| 70 | + jr nz, _arpeggio_end |
| 71 | + ld a, ARPEGGIO_SPEED(ix) |
| 72 | + ld ARPEGGIO_COUNT(ix), a |
| 73 | + xor a |
| 74 | + ld ARPEGGIO_POS(ix), a |
| 75 | + ld ARPEGGIO_POS8(ix), a |
| 76 | + |
| 77 | + set BIT_FX_ARPEGGIO, FX(ix) |
| 78 | + |
| 79 | +_arpeggio_end: |
| 80 | + ld a, #1 |
| 81 | + ret |
| 82 | + |
| 83 | + |
| 84 | +;;; ARPEGGIO_SPEED |
| 85 | +;;; configure the number of ticks between two notes of the chord |
| 86 | +;;; ------ |
| 87 | +;;; ix : state for channel |
| 88 | +;;; [ hl ]: speed |
| 89 | +;;; hl modified |
| 90 | +arpeggio_speed:: |
| 91 | + ld a, (hl) |
| 92 | + inc hl |
| 93 | + |
| 94 | + ld ARPEGGIO_SPEED(ix), a |
| 95 | + |
| 96 | + ld a, #1 |
| 97 | + |
| 98 | + ret |
| 99 | + |
| 100 | + |
| 101 | +;;; Update the arpeggio state for the current channel |
| 102 | +;;; ------ |
| 103 | +;;; ix: mirrored state of the current channel |
| 104 | +;;; [TODO modified] |
| 105 | +eval_arpeggio_step:: |
| 106 | + ;; assert: speed is always >=1, so count is never 0 here |
| 107 | + dec ARPEGGIO_COUNT(ix) |
| 108 | + ld a, ARPEGGIO_COUNT(ix) |
| 109 | + cp #0 |
| 110 | + jr z, _arpeggio_update_pos |
| 111 | + ret |
| 112 | +_arpeggio_update_pos: |
| 113 | + ;; rearm countdown |
| 114 | + ld a, ARPEGGIO_SPEED(ix) |
| 115 | + ld ARPEGGIO_COUNT(ix), a |
| 116 | + |
| 117 | + ;; update position in the arpeggio |
| 118 | + ld a, ARPEGGIO_POS(ix) |
| 119 | + dec a |
| 120 | + jp p, _arpeggio_post_pos |
| 121 | + add #3 |
| 122 | +_arpeggio_post_pos: |
| 123 | + ld ARPEGGIO_POS(ix), a |
| 124 | + |
| 125 | + ;; set semitone offset according to position |
| 126 | + cp #2 |
| 127 | + jr nz, _arpeggio_not2 |
| 128 | + ;; pos == 2: 2nd note in chord |
| 129 | + ld a, ARPEGGIO_2ND(ix) |
| 130 | + ld ARPEGGIO_POS8(ix), a |
| 131 | + jr _arpeggio_eval_end |
| 132 | +_arpeggio_not2: |
| 133 | + cp #1 |
| 134 | + jr nz, _arpeggio_not1 |
| 135 | + ;; pos == 2: 3rd note in chord |
| 136 | + ld a, ARPEGGIO_3RD(ix) |
| 137 | + ld ARPEGGIO_POS8(ix), a |
| 138 | + jr _arpeggio_eval_end |
| 139 | +_arpeggio_not1: |
| 140 | + ;; 1st note in chord (0 displacement) |
| 141 | + ld ARPEGGIO_POS8(ix), #0 |
| 142 | + |
| 143 | +_arpeggio_eval_end: |
| 144 | + ret |
0 commit comments