Here's an idea that may or may not be useful, but I thought it would be worth sharing here. So the frame counter allows for clocking the length counters at a ~96Hz rate with the 5-step mode selected, and writing to $4017 clocks all the hardware timer units. By writing $18 to $400F and then $C0 to $4017 at the end of VBlank, you could set up another (albeit fixed timer) flag ($4015 noise bit) to poll for a raster effect that would be reliably lowered after 14 914 CPU cycles, since the $4017 write immediately decrements the 2-clock length counter table entry you have selected in $400F. Once the flag is lowered, an immediate write to $400F with say $08 would ensure that then oise channel would immediately start playing again, without causing any audible artifacts in the sound.
Could this be useful for a two-player split-screen game for example? (Provided that the first half of the frame can be filled with fixed-time or mostly fixed-time processes)
Noise length counter polling
Moderator: Moderators
Re: Noise length counter polling
14 914 APU cycles.14 914 CPU cycles
To quote the wiki...
If set-up at the top of the frame, the IRQ wouldn't fire until past the bottom of the screen. I think, what you were proposing were useful, someone would have used it.In this mode, the interrupt flag is set every 29830 CPU cycles, which is slightly slower than the 29780.5 CPU cycles per NTSC PPU frame.
But, feel free to do some tests on hardware, and test it out. Prove me wrong.
nesdoug.com -- blog/tutorial on programming for the NES
- rainwarrior
- Posts: 8732
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: Noise length counter polling
This isn't an IRQ, this is polling $4015 for when the noise shuts off. The "length counter" is ticked 2 times per frame, and can be synchronized with $4017 writes.dougeff wrote:IRQ
I'm not exactly sure why noise specifically is being suggested here. Wouldn't this work with any channel? The triangle's "linear counter" has a 4x per frame resolution instead, which might be more useful. I guess probably the brief interruption of noise would be the least noticeable of the 4 channels...? I think on any channel that's not silent you will get a 60hz buzz from the regular interruption, but it might be acceptably quiet.
The big drawback here is just not being able to time it very conveniently. You can't easily move it around like sprite 0. Seems like even DPCM would usually be a better option with its IRQ.
You could even position $4017's IRQ directly by writing it mid-screen. (Though it might start to gradually slip vs. NMI? I don't think it has the exact same timing as the NMI, but I haven't tested it.)
Re: Noise length counter polling
Yeah, unfortunately the frame IRQ is slightly longer than the NMI period (as you can see in the quote in dougeff's post). It would be wayyy more useful if it was slightly shorter than NMI instead. :/rainwarrior wrote:You could even position $4017's IRQ directly by writing it mid-screen. (Though it might start to gradually slip vs. NMI? I don't think it has the exact same timing as the NMI, but I haven't tested it.)
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
Re: Noise length counter polling
I did mean CPU cycles. Since the write immediately decrements the length counter of the channel in question, only 2 frame counter steps out of the 5 have to occur before the length counter gets clocked again, which amounts to 7456.5 APU cycles.dougeff wrote:14 914 APU cycles.14 914 CPU cycles
That's the basic idea, I thought it would be a lot less apparent with the noise, especially when it's playing at lower pitches, since the buzz (if any) would be buried in mix anyway, and whenever the time period of the channel stopping and you rewriting $400F again would line up with a 0 output bit from the LFSR, there really shouldn't be any artifacts present. Also, the linear counter stopping the channel is not reflected in the state of the triangle flag at $4015, all of those bits care about the corresponding length counters only.rainwarrior wrote:I'm not exactly sure why noise specifically is being suggested here. Wouldn't this work with any channel? The triangle's "linear counter" has a 4x per frame resolution instead, which might be more useful. I guess probably the brief interruption of noise would be the least noticeable of the 4 channels...? I think on any channel that's not silent you will get a 60hz buzz from the regular interruption, but it might be acceptably quiet.
Re: Noise length counter polling
Speaking of silly stupid ideas, you could also start with a sprite 0 hit, then set an APU frame IRQ to go off one frame and ~200 dots later. The Frame IRQ could interrupt code that runs long and prevents the sprite 0 polling loop from getting reached in time.
APU frame IRQ has the advantage of not interfering with anything else sound-wise, except for the sweep trick to set high bits of square channels. Nobody should be using the length counters and envelopes anyway.
APU frame IRQ has the advantage of not interfering with anything else sound-wise, except for the sweep trick to set high bits of square channels. Nobody should be using the length counters and envelopes anyway.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!