bastetfurry, on Mon Jan 2, 2012 8:51 AM, said:
3. Is there some way to detect on what machine my game is running?
As far as I know, there's nothing your game can use internally to determine which variety of 2600 console it's running on. However, it is possible to determine whether it's running on a 2600 or a 7800, based on the initial values found in certain RAM locations-- although I should think this isn't 100% certain, because the 2600 powers up in a random state, so it isn't inconceivable that it could randomly power up with the values expected for a 7800.
The safest way would be to simply ask the player to specify which console is being used. And this assumes your game contains alternate code for the different consoles.
The simplest solution-- which was the one the game companies used, and that most homebrewers still use-- is to produce different versions of your game for the different consoles, or (if you can't afford to code and manufacture more than one version) to just specify up front that your game is intended to be played on a certain console.
If you're interested in a one-cartridge-works-on-all-consoles solution (which is a nice ideal to shoot for), you'll need whatever alternate code is required to compensate for the differences between the consoles. That means you need to know what all the differences are. I don't know if there's a definitive list anywhere-- it would be great if we could put one together-- but some of them are as follows:
The NTSC TIA has a blanking pin and an audio1 pin, but on the PAL TIA those pins are used for PAL-I and PAL-S connections. This generally has no impact on games, unless your game is designed to capitalize on an AV mod that sends the audio0 and audio1 outputs to different speakers for stereo sound.
PAL/SECAM 2600s have a slightly slower oscillator speed (3546894 Hz) than NTSC 2600s (3579575 Hz), which affects their audio frequencies, therefore you may want to use different frequency values in any music your game might have so it sounds as identical as possible on different consoles.
PAL/SECAM games normally have 312 scan lines per frame, but NTSC games normally have 262 scan lines per frame. This means the PAL/SECAM frame rate is about 50 Hz, whereas the NTSC frame rate is about 60 Hz. If your game updates a counter once per frame for keeping time or some similar purpose, you'll need to compensate or the game will run faster or slower depending on which console is being used.
The NTSC, PAL, and SECAM consoles have different color palettes, so your game will need to use different color values depending on the console.
The 2600's TV type switch flips up and down like the two difficulty switches, but the 7800's pause switch (which replaced the TV type switch) works like the game select and game reset switches-- you can press it down, but then it comes back up again. If your game uses the TV type or pause switches for anything, you'll need to program them differently to compensate for the way they work.
Some models of the 2600, or some clones, have slight timing differences in things like how soon changes to the graphical registers show up on the screen, so you might need to make adjustments in your kernel if you're drawing an asymmetrical playfield by updating the playfield registers as the scan lines are being drawn, or if the timing differences affect your score display, and so on.
Some consoles may differ in whether "illegal" opcodes will be executed as expected, so you might need to compensate for that-- or avoid using "illegal" opcodes at all.
Some cartridges don't fit easily into the cartridge slots of some consoles, so you might want to keep that in mind when choosing a cartridge housing for your game.
And while it isn't a difference related to consoles, some modern TVs drawn standard-definition displays (especially non-interlaced displays) differently. For example, my high-definition Samsung TV automatically converts a non-interlaced display to an interlaced display, which means flickered colors (and thus, flickered objects) are drawn as flicker-free interlaced colors. You could conceivably capitalize on this by letting the players choose between different kernel settings to get the best-looking display for their particular TV.
As far as asking players to select which console they're using, you could have an options menu that lists different choices for them to select from.
Another possibility is to use one or more of the console switches for selecting between different color palettes, number of scan lines, and so on. For example, you could program the difficulty switches to select the display type depending on whether they're up or down; or you could program the game select switch to cycle between each of the different display types.
Or if you want to be more creative, you could possibly include a sort of mini-game at startup, such as displaying blocks of color that will be different depending on which color palette the console uses, and asking the player to shoot the yellow block, or the red block, and so on, so you could tell which color palette is being used.
bastetfurry, on Mon Jan 2, 2012 8:51 AM, said:
4. When does the TIA set its registers in stone? At draw or some time before that? (Changing COLUBK in the middle of a line and stuff.

)
None of the register changes are instantaneous, at least not internally, since there's usually a slight lag between when a register receives its new value and when the change actually affects the output, as determined by whether or not a given line (such as a clock line) must go high or low first, or whether the signal from the register must pass through any inverters and other logic gates (or rather, how many it must pass through, since most everything goes through at least an inverter or two), how much delay is added by each gate, and things like that.
However, most of these internal delays are transparent to the programmer, because if most everything is delayed by the same amount (as controlled by the clock lines), then you have no way to tell that there's actually (say) a 1.5 color clock delay inside the TIA before a given 6507 instruction finishes executing, the new value is updated to the register, and the new value begins to affect the output. So as far as the programmer is concerned, most register changes appear to be instantaneous, except the ones that require more time than usual. Thus, changes to the color registers and player/missile graphics seem to take place as soon as the instructions have completed. There's a slight delay of (if I remember correctly) 2 or 3 color clocks before changes to the playfield graphics seem to take effect, depending on the console (most 2600s have the 2-clock delay, but some later and some clones may have the 3-clock delay). Changes to the VBLANK register take 1 extra color cycle. But the longest delays are probably with the audio registers. When you change the audio frequency, if the frequency counter has already passed the new value then it will continue counting up until it wraps around and finally hits the new value, which could take several scan lines. When you change the audio control register, the existing values in the polynomial counters need to keep shifting before their output bits begin to reflect the new control value.
So as far as the graphics are concerned, you can pretty much assume that any changes are instantaneous, except for the small lag with the playfield registers (which is normally irrelevant unless your kernel is updating the playfield while the line is being drawn), or the tiny lag with the VBLANK (which is also irrelevant unless your kernel is using VBLANK to blank portions of the active scan lines). And the audio register changes are usually irrelevant unless your kernel is making a series of rapid changes to the frequency registers to produce a sound effect, in which case the results you get from an actual console may differ dramatically from an emulator.
bastetfurry, on Mon Jan 2, 2012 8:51 AM, said:
5. When i issue STA WSYNC, where is the TIA giving back control to the CPU? At the start of next HBlank or the start of the next picture line? In essence, how many cycles till the TIA draws its first pixel/expects valid data.

When you strobe WSYNC, the TIA stops the 6507 until the leading edge of the next horizontal blank, so you have the entire horizontal blank period (68 color clocks, or 22 and 2/3 machine cycles) before the active portion of the line begins.