Most people rejoice when they manage to bring old things back to life. The infinite desire to relive the experience of youth leads us in ways that we have long forgotten. And along the way, we sometimes encounter forgotten memories, evoking other forgotten memories, allowing us to relive happy moments that we have not thought about for years, or even decades. Someone back to high school, to the evening avtoprokulkami with the volume of the radio turned out to its fullest, returns the roar of the engine Ford Windsor . For those born in the 80s and 90s, such memories can trigger video games. Who can forget the first meeting with the Microsoft Office assistant clip, elegant music from Final Fantasy, or up-up-down-down-left-left-right-left-right-ba-select-start ?
Progress in processor technology has allowed us to re-spend time with our favorite games through emulators - programs that emulate the processors of old computers. Games are downloaded from ROM chips to files. These files can then be downloaded to the emulator, and play the game as if you were playing it on the original system. NES Zapper insides ')
Technology is a beautiful thing. It allows us to move forward and do today what was impossible yesterday. However, in some cases, this paradigm is incorrect. One of them is the NES game console, the Nintendo Entertainment System, and its gun controller, the Zapper. At the time, NES has become the most popular game console, and for good reason. Nintendo’s engineers, programmers, and audio experts have managed to generate some of the best video games ever created. Unfortunately, some of these games cannot be played on your favorite emulator on the Raspberry Pi, since the Zapper is incompatible with modern digital monitors. Hardly anyone can forget how fun it was to play Duck Hunt . This game was bundled with all NES systems, so we all played it. But the nostalgia connected with it is buried because of unresolved technological features.
I can tell you how a hacker hacker - this can no longer be tolerated. So first, we'll figure out how the Zapper works, and why it doesn't work with digital displays. And then we will think about how to fix it.
Problem
The Zapper gun is just a photocell with a switch. When the trigger (switch) is pressed, the NES performs certain screen manipulations in order to understand where the gun is going. Which ones - we will discuss later. But first we need to understand that they only work on analogue CRT TVs. If you connect your emulator to this TV, you will not have problems. The problem is that no one else has a CRT TV. All have digital flat-screen TVs and monitors. When connected to such a monitor, the game will not work. We need to understand why this is so.
Debunk Myths
Regarding where the NES knows where the Zapper is going, there is a lot of confusion, even among people with a little knowledge of electronics. Some of them believe, and continue to spread this myth, that the NES reads scan lines from a CRT. The CRT draws scan lines from top to bottom of the screen at regular intervals. By comparing the start time of drawing and the time when Zapper sees the line, NES can find out where Zapper is pointing. And since the modern monitor shows all the lines at the same time, it’s impossible to calculate exactly where the Zapper points. It is possible that some older photocell pistols worked this way, but the NES does not work that way. Totally.
How does NES Zapper work
The system is quite clever. When you pull the trigger, NES draws a solid black frame on the TV. NES draws 60 frames per second, so one frame is approximately 0.0166 on the screen, or 17 ms. In the next frame, a white rectangle appears in place of the duck, and the prefix interrogates the state of the photocell in the gun. The output of the photodiode is very different depending on whether it is directed to a black screen or a white rectangle. And all this happens during the demonstration of two frames, 34 ms. The man barely notices this. The next frame draws the playing field again and you are hit or missed. Brilliant!
“But wait, how does this system work when there are two goals on the screen?” Good question. NES engineers deal with this problem by simply repeating the whole process. The first frame will be black, followed by a frame with a white rectangle in place of a single target and a photocell survey. If there is another target on the screen, the third frame will be with a rectangle around the second target. All three frames are about half a second, so you will not be able to shoot two ducks at once. You can only shoot one, and this technique lets the NES know which one.
“If the NES simply polls the state of the photocell, can I just point the gun at a bright light and record my hit each time?” Another good question. NES engineers got rid of this deception by interrogating the photocell state while the first black frame appeared. If the photocell sees something that is different from the black screen, the prefix counts you a miss. There are rumors that in the very early versions of the game this error was not corrected, but so far no one has demonstrated such a bug.
Another look at the problem
Now, knowing how the Zapper works, we can move on to solving problems with a digital monitor. If the game just measures the difference between black and white, then the gun should work fine on digital monitors. But he obviously does not work. Some argue that the photocell is sensitive to infrared CRT, and the digital monitor does not emit infrared rays. But look at this video: Zapper works great!
[The video shows a modified Zapper / approx.transl.]
We know that the scan lines have nothing to do with it, and that the Zapper can distinguish the contrast between white and black on a digital screen. We can conclude that our problem is related to time. Apparently, a CRT can display an image much faster than a digital colleague. In NES, the need to check for a white rectangle after 16 ms is hardcoded. If your digital screen is not able to process the NES output with sufficient speed, then the console will search for a white rectangle while the game is still visible on the screen.
The output resolution of the NES is 256 x 240 pixels. The digital monitor needs to scale each frame to the working resolution. This process creates a delay that can go up to 70 ms, seriously exceeding our figure of 16 ms.
How to fix it
It will not be easy. If a digital monitor is inherently too slow, the only solution would be to slow down the NES.
Option 1: reduced clock frequency
We all heard about the overclocking of the processor through an increase in the clock frequency. What about braking? Can we slow down the time in the NES processor without speeding it up to a tangible fraction of the speed of light? At the same time, it is necessary that the game was played at a normal speed, but when the trigger was pressed, it switched to slow motion and, in fact, increased the delay time. Remember that NES displays a black screen for 16 ms, and then draws a white rectangle. By slowing down the processor, we can increase this delay and give the digital monitor time to react.
Option 2: ROM editing
ROM can be edited only in a hexadecimal editor. What if we studied the emulator and found where the delay value is set after pressing the trigger? We could just make it bigger, and hope that nothing broke.
Option 3: your option
Now that you know how the NES Zapper works, and why it doesn’t work with modern digital monitors, you are already halfway to solving this problem and freeing nostalgia that our cruel technological fate has deprived us of. What would you do to make Zapper work with a digital monitor and become a hero of the Internet?
The scheme of work is not so difficult - for sure we can all together figure out how to make Zapper stop shooting idle in our digital world. Share your decisions in the comments.