Saturday, October 11, 2014

Atari 2600 Simulation

Full source code and data for our transistor-level simulation of the Atari 2600 is up on github:
https://github.com/gregjames/Sim2600

This Python version uses the same 6502 circuit node names and ids as our web-based javascript version but has no polygon geometry.  It includes our full netlist model of the Atari TIA and a simple emulation of the PIA, aka RIOT, and program ROM.  Leave it running long enough, and it'll render frames from classic games.




The simulation provides a cycle-accurate picture of what the console is doing based on the physical parts of its microchips.


8 comments:

  1. Awesome achievement! The Pitfall! screenshot shows there's a small bug. Looks like the sprites are being display 2 pixels too soon relative to the background. Notice how the latter is not centered and the finer limbs of the trees are not centered over the trunks.

    After thinking about this a bit, I would guess it is due to some phase offset between the 6502 and TIA clocks. The TIA outputs 3 pixels for each 6502 clock so it seems likely that the two of them are not in the correct phase. Though I haven't the foggiest notion what establishes that phase in the 2600.

    ReplyDelete
  2. Good eye. The simulation code transfers bits and the clock between the 6502 and TIA at each TIA half clock cycle. I'll look into which things happen on phase of the clocks.
    The 6502 clock is driven by an output of the TIA. The TIA takes the master clock, divides it by three, and sends it to the 6502. The TIA also controls the 6502 RDY pad in response to delays that the 6502 program sets up.

    ReplyDelete
  3. I believe the divide by three circuit in the TIA results in a 33.333% duty cycle for the 6502's clock. See http://www.indiabix.com/electronics-circuits/divide-by-3/

    Does the simulation account for that or does it assume a 50% duty cycle?

    ReplyDelete
  4. Yes - our model of the TIA drives the 6502 clock, and the TIA’s clock divider is captured in our netlist for the chip. It could be that we’re not transferring signals between the 6502 and TIA simulations at the correct phase of the TIA clock, or that our emulation of the RIOT timer is not correct. Our gate-level model of the RIOT is only about ⅓ complete, and we’re not using it here.

    ReplyDelete
  5. I had written an Atari 2600 emulator.
    https://youtu.be/anf3ftvWo24

    The bug also appeared in one of my development version. Unfortunately, that version was not retained. Instead, i had made a diff video to the version before and after that missing version.
    https://youtu.be/R7e2BtHAxLo

    The differences between the two versions contains two major parts. One is how WSYNC and VSYNC work, the other is how RESXXs works. I believe the bug is because of how RESXXs works. According to the spec
    http://problemkaputt.de/2k6specs.htm#videomobhorizontalpositioning

    RESXXs will set their positions to some strange values. Do not reference the code in the diff video because that is still wrong and i am not sure how to done it 100% correctly. Hope this message can help you fix the emulator.

    There is one question i would like to ask. How long could the emulator renders a frame? Is that more than one hour?

    ReplyDelete
  6. Conventions of pixies have existed in exceedingly differing societies around the globe for quite a long time. Pixies and pixie like creatures are otherwise called nature spirits, house spirits, dwarves, mythical people, little persons, mermaids and leprechauns. Perused more about the entrancing customs of pixies here. http://www.mordocrosswords.com/2016/02/acts-like-raptor.html

    ReplyDelete