1) comment, comment, comment ...
Code: Select all
dutyModification
ld a, (ix + DUTY)
ld c, (ix + DUTYDELTA)
add a, c ;add duty change to duty
bit 7, c ;is delta negative ?
jr nz, negDutyDelta
ld b, (ix + DUTYMAX) ;compare with max duty
cp b
jr c, noDutyChange ;will not change duty delta sign
dutyChange
ld a, c ;negate duty delta
neg
ld c, a
ld a, b ;and set min/max limit as duty
ld (ix + DUTYDELTA), c ;store new delta
noDutyChange
ld (ix + DUTY), a ;store new duty
ret
negDutyDelta
ld b, (ix + DUTYMIN) ;compare with min duty
cp b
jr nc, noDutyChange ;will not change duty delta sign
jr dutyChange
noteModification
ld a, (ix + NOTELEN) ;decrease note length
dec a
ld (ix + NOTELEN), a
noteNoLastTick
ld a, (ix + ARPFLAG) ;is appergio enabled ?
or a
jr z, noteNoArp ;no
ld a, (tickCounter) ;if appergio enabled
and 1 ;every second tick play tone one octave higher
jr z, noteNoArp
ld a, 12 ;octave plus
noteNoArp
add a, (ix + BASENOTE) ;add nothing or octave to base note
call getNoteFreq ;get note frequency
ld a, (ix + VIBRATOFLAG)
or a
jr z, noteNoVibrato ;no vibrato
ld de, 47 ;1 + 11*2 = 23
add hl, de ;move note
ld a, (hl)
inc hl
ld h, (hl) ;get frequency for note+1
ld l, a
or a
sbc hl, bc ;difference between notes to HL
ld a, (ix + VIBRATODEPTH)
vibratoDepth
srl h
rr l
dec a
jr nz, vibratoDepth ; delta of frequency / ( 2^vibratoDepth)
ld a, (vibratoCounter) ; now multiply vibrato depth by vibracounter
or a
jr z, noteNoVibrato ;level 0
ld d, h
ld e, l
bit 1, a
jr nc, vibratoBit1
add hl, hl
vibratoBit1
rra
jr c, vibratoBit0
add hl, de
vibratoBit0
add hl, bc ; add vibrato to base note frequence
ld c, l
ld b, h
noteNoVibrato
ld a, (ix + PORTAMENTOFLAG)
or a
jr z, noteNoPortamento ;no portamento
ld e, (ix + PORTAMENTOLO)
ld d, (ix + PORTAMENTOHI)
ld l, e
ld h, d
add hl, bc ;add portamento to frequency
ld c, l ;store final frequency
ld b, h
ld l, (ix + PORTAMENTODELTALO)
ld h, (ix + PORTAMENTODELTAHI)
add hl, de ;update portamento
bit 7, (ix + PORTAMENTODELTAHI) ;is delta negative ?
jr z, notePortamentoChange
ccf
notePortamentoChange
jr nc, notePortamentoContinue
xor a ;switch portamento off
ld (ix + PORTAMENTOFLAG), a
notePortamentoContinue
ld (ix + PORTAMENTODELTALO), l ;store portamento delta
ld (ix + PORTAMENTODELTAHI), h
noteNoPortamento
;BC is final frequency
ld a, (ix + RELEASEFLAG)
or a
ret z ;if not release then exit
ld a, (ix + NOTELEN)
or a
ret nz ;is last tick ?
ld bc, 0 ;erase frequency for the very last tick
ret