I'm cleaning up a project I started late last year to play 'DIGIs' (digital samples) on the C64 SID. After figuring out how to process the sample is Audacity for good results: 8-bit samples at 8khz. I then reduce the samples to 4-bit, doing some rounding up, and pack two per byte.
I also tried to do a simple Run Length Encoding, which reduced the sample file size by about 25%. And while I can decode it easy enough on the C64 it takes far too long to do to process in an 8khz interrupt loop. It would work at 4khz I suspect though.
Anyhow, I was optimizing my simple, non-RLE, interrupt routine this morning and was unhappy with how long it took to toggle a bit in zero page that I'm using as a flag to know which nibble should be played next.
Originally I was doing this to check, and then toggle the bit at the end. The #- indicates clock cycles with (#) as the total for that block. So originally it took 14 clock cycles ignoring the single-cycle difference in BNE if branch take or not.
Code: Select all
;every other NMI do *1 or *2
LDA flag ; 3- if flag==0 we just played upper nibble
BNE lower ; 2- (5) so skip ahead to load new byte
...other code
LDA flag ; 3- toggle hi/low nibble flag and exit NMI
EOR #$1 ; 3-
STA flag ; 3- (9)
Code: Select all
LDA #$01 ; 2-
AND flag ; 3-
BNE lower ; 2- (7)
INC flag ; 5 (5)
It got me wondering what clever ways had been devised to handle a simple task like this over the years? I did a search on the forum but the terms 'bit toggle' brings up many, many threads of course.