Synchronization between CPU and PPU In the FC/nes Simulator

Source: Internet
Author: User

How can we synchronize CPU and PPU? (You can see from the information that the CPU and PPU use the same oscillator, and the system runs at the same time.) Here, we will record our guesses. To do this, we still need to test the practice.

It is feasible to use a PC to simulate FC, because the speed of the PC is much higher than that of the FC. If you use a PC to run FC at full speed, the fcgame will be unable to play quickly. So we wantProgramWhat is the purpose of the speed limiter when "speed limiter" is added? Let the FC run at the appropriate speed.

Here, I use the pal FC (50 frames per second, 32*30 blocks, 312 scanned lines, and 1362 of the total scanning cycle) as the discussion object.

First, if we want the simulator to generate 50 frames of images per second, we must return the remaining 1 second to the system after "50 frames of images generated. If it takes a second to 50 frames, return (1-A) seconds to the system (you must know that A is very small ).

This is not enough, because each frame of the image will produce an important "vblank interruption", so we 'd better make the interval of each frame of the image as long as possible, that is, the image is evenly distributed to "Every 1/50 seconds ". if it takes B seconds for each frame of the image, it will be returned to the system (1/50-B) seconds.

Now, at least stable vblank interruptions can be generated, but not enough, because someCodeIt is to deal with "Horizontal blanking", so it is necessary to allocate the average time to the scanning line. Query Information. In pal mode, there are 312 scanning lines. Therefore, we need to divide the scanning lines into 1/15600 seconds on average ", and return the remaining time to the system (the purpose of returning the system is to "enable the interval ").

Not enough, because to achieve accurate "Genie Collision", You need to divide "pixels" evenly to "1/(15600*1362) seconds ".

The conclusion is that the time "1/(15600*1362) seconds" is converted to the number of CPU instruction cycles. For every PPU image "one pixel", the CPU executes some commands. The calculation result is 1/21247200, which is close to the fundamental frequency of the PAL system "21281362.0Hz", which is the time required by each pixel.

The CPU is 1/12 of this frequency, which is 1773447Hz. That is, there are 1773447 cycles per second, which are provided to the CPU. We also set this cycle according to the previousAlgorithmOnce calculated, 1773447/50 = 35468.94 (exactly the same as "frame IRQ cycle 35469"). 1773447/50/312 = 113.6825, that is, each scanning line is equivalent to 113.6825 CPU cycles.

For convenience, the scanning line can be used as the unit, which is better processing. PPU renders a scanning line for every 113.6825 cycles of CPU operation.

From: http://zjdddd.blog.163.com/blog/static/18028530820111202479457/
Girl does not cry (QQ: 191035066) @ 02:38:27

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.