4 ms·
Yes, I bet you’re misremembering something — no released NES has a “hardware timer”, in any revision. The earliest revisions of the NES CPU do remnants of a bu
by NobodyNada 3y ago
Yes, I bet you’re misremembering something — no released NES has a “hardware timer”, in any revision.
The earliest revisions of the NES CPU do remnants of a buggy and disabled programmable interval timer on the die: https://www.nesdev.org/wiki/RP2A03_Programmable_Interval_Timer https://www.nesdev.org/wiki/RP2A03_Programmable_Interval_Tim.... This was fully removed in later revisions. Perhaps this was enabled on a dev kit or something — relying on functionality that never worked on consumer units certainly would have led to Nintendo rejecting it during testing.
But even if released consoles had a PIT, it would only be very useful for sub-frame measurements for e.g. timing precise raster effects. Counting NMIs would be by far the most sensible way to measure real time. The NMI fires at the start of each video frame, which is extremely consistent at 60.0988 Hz, and not affected by in-game processing (i.e. game engine may run at a slower/variable framerate if it can’t keep up, but nothing that happens CPU-side can affect the timing of the video signal in any way; the rendering process runs off a fixed timer in hardware).
(FWIW, the audio hardware also has the ability to generate timer interrupts, and many expansion chips have scanline counters that can generate timer interrupts if you need fine-grained synchronization to the rendering process. There’s no shortage of ways to measure time on the NES if you need it).
- layer8 3y ago> The NMI fires at the start of each video frame, which is extremely consistent at 60.0988 Hz Wouldn’t that be different on a PAL NES? The parent mentioned that they wanted "to keep track of real time [...] regardless of the frame rate, which varied".
- MarkMoxon 3y agoIt is indeed different on PAL vs NTSC. The code relies on the NMI being called at 50Hz - as a result a number of timings are wrong on the NTSC version, so the music is too fast, the combat demo auto-play doesn't work properly, the time reported for completing the combat demo is wrong, and so on. The NTSC version is unfinished, and this is just one area where it shows.
- MarkMoxon 3y agoYes, no hardware timers are used in NES Elite, as there aren't any. Instead there's an NMI counter (nmiTimer) that counts every VBlank and wraps around every 50 ticks, so it's effectively a seconds counter on the 50Hz PAL version. And in the NMI handler, they keep a running total of cycles spent so they know when VBlank has finished and can stop sending data to the PPU, picking up where they left off in the next VBlank (see the NMI routine in bank 7). They also use sprite 0 collision detection to flag when the screen redraw has reached the icon bar, so it can force the PPU to nametable and pattern table 0 (as the icon bar's tiles are only in table 0, with table 1 being used for the vector graphics). This is not unlike the original BBC Micro version's split-screen mode, just without any hardware timers (instead, the whole source is littered with macros that check the collision flag - not very elegant, but it works). Having hardware timers would have made things a lot easier!
- abainbridge 3y agoInteresting stuff. I'm going on a 20 year old memory of a conversation I probably didn't understand at the time, so I'm very fuzzy on the details.
- ndiddy 3y agoI believe what Braben was referring to is the IRQ the APU sends when it's done playing an audio sample. This can be used as a hardware timer by playing a silent sample (all zeroes) and varying the sample length and pitch to adjust the amount of time before the IRQ happens. There's a Twitter thread (https://togetter.com/li/753345 https://togetter.com/li/753345) from the programmer of Guardian Legend (a game that uses the APU IRQ for measuring when to switch from displaying the main gameplay to displaying the HUD) that mentions something similar to Braben's story. After the game came out, he started getting reports that it wasn't working correctly on a small number of consoles. It turned out out that Guardian Legend was the first game to use the APU IRQ and Nintendo had never tested that feature at manufacture. After this, Nintendo started instructing developers to not use the APU IRQ.
- joneholland 3y agoI randomly used that game as a test rom when I wrote my nes emulator and was pulling my hair out in why the HUD wasn’t rendering until I realized I needed to implement the APU as well. What a fun era of development.