- I will make a simple calculation to predict the performance requirements for Atari 2600 emulator to avoid the next failure. The Atari 2600 emulator mainly contains three parts. The first part is CPU, which can execute the instructions of a game. The second part is TIA, which is used to display colors to TV by pixels. The third part is timer, which could let the programmers program easier.
The CPU of Atari 2600 is MOS 6507 with a clock rate of 1194720(1.19M) Hz. Using instruction TAX for example, it takes 2 clock cycle to transfers data in register A to register X and changes flag N and Z. The emulator needs to read PC, read memory according to PC to get opcode, identify opcode, call the instruction function, read from register A, write to register X, check if data is less than zero, write to flag N, check if data is equal to zero, write to flag Z, calculate next PC, write to PC. The above actions takes a total of 3 reads, 4 writes, 1 hash, 1 function call, 2 ifs, 1 add, and these actions must be finished in 1.67 ns.
- TIA The TIA of Atari 2600 draws one pixel in each cycle with a clock rate of 3584160(3.58M) Hz. The implementation of TIA affects performance a lot because it's likes a state machine. If you don't change its state, it will continue drawing the same color. Assuming the TIA reads the position of electron gun, reads color, writes color to the position, calculates the next position of electron gun, update the position of electron gun. The above actions takes a total of 2 reads, 2 writes, 1 add, and these actions must be finished in 0.27 ns.
The Atari 2600 contains a timer with 4 different speeds. The fastest speed equals to the clock rate of MOS 6507. Assuming the timer reads, calculates, and write once. The above actions take a total of 1 read, 1 sub, and 1 write, and these actions must be finished in 0.84 ns.
- I made a lot of miscalculations because i was not familiar with Atari 2600 at that moment. Here is a recalculation for TIA. It needs to calculate every object in each clock cycle to make sure if there are collisions or not. The objects have six types, which are PLAYER0, PLAYER1, MISSILE0, MISSILE1, BALL, and PLAYFIELD, and each has its own status, so one object needs at least 3 reads and compares (data, status, color), six objects needs 36 actions. There are fifteen possible collisions for objects and each collision detection need to read two object and do one comparison, so that's a total of 45 actions. The electron gun is easier to emulate by using two dimension indexes, so it needs three more actions than the prediction before, which is a total of 8 actions. By the calculation above, the CPU needs to finish 12 actions, the TIA need to finish 534 actions, and the timer needs to finish 6 actions in 1.67 ns. If each action takes only one clock cycle, the Atari 2600 emulator would require a CPU with clock rate 327353280(327.35M) Hz to run at full speed. Since Python is about 100 times slower than C++, pure python could never achieve the goal.
- My Atari 2600 emulator written in Python failure version 1
- Prediction for Atari 2600 emulator performance requirements
- The performance comparison for Atari 2600 instruction TAX
- My Atari 2600 emulator written in Python failure version 2
- My Atari 2600 emulator written in Python failure version 3
- My Atari 2600 emulator written in Python success version 1
- My Atari 2600 sound device emulator written in Python
- My Atari 2600 emulator written in Python success version 2