Writing Software That Runs Right on PAL and NTSC Ataris
Atari 8-bit computers were sold in two video standards. NTSC machines in North America draw 60 frames a second, while PAL machines in Europe and elsewhere draw 50. Almost everything else is the same, which is exactly why the differences catch people out. A game written in Poland plays 20% too fast in the USA. A demo written in the USA crashes in Germany, or the reverse. Music written on one sounds slightly sharp or flat on the other. This guide lists what really differs, how a program can tell, and two tested ways to make movement keep the same real-world speed on both.
What you'll learn: the timing numbers for both standards, the vertical blank time difference and the VCOUNT trap, the pitch and colour differences, detecting the standard, frame-skipping versus scaled steps, and how music players handle it.
What you need: MADS and an emulator that can switch between PAL and NTSC (atari800 takes -pal and -ntsc; Altirra has the setting under System > Video). The example was assembled with MADS and run in atari800 in both modes.
1. What actually differs
| NTSC | PAL | |
|---|---|---|
| Machine clock | 1.789773 MHz | 1.773447 MHz |
| Scan lines per frame | 262 | 312 |
| Frames per second | 59.92 | 49.86 |
| Cycles per scan line | 114 | 114 |
| Cycles per frame | 29,868 | 35,568 |
| Highest VCOUNT | $82 (130) | $9B (155) |
| GTIA PAL register ($D014) bits 1–3 | 111 | 000 |
The visible picture can only occupy scan lines 8 to 247 on either system. The difference is all in the vertical blank: after the VBI at line 248, an NTSC machine reaches line 8 of the next frame 22 lines later, while a PAL machine has 72 lines. That is about 2,500 cycles of vertical blank time on NTSC, against about 8,200 on PAL, before the display starts again.
2. The consequences
Speed. Anything counted in frames runs 20% faster on NTSC: game movement in a VBI, delays made with RTCLOK, animation timers and, above all, music players called once per frame.
Vertical blank budget. Code that fits comfortably into a PAL vertical blank (music, sprite multiplexing setup, scrolling) may still be running when the NTSC display starts, which causes tearing or worse.
VCOUNT loops. A loop that waits for VCOUNT = $9B waits forever on NTSC, because the count stops at $82. This is a common cause of programs written for PAL locking up on NTSC. Compare with "greater or equal" instead. The same applies to any test for a line near the bottom.
Pitch. POKEY derives its sound clocks from the machine clock, so the same AUDF value produces a note about 0.9% lower on PAL, roughly a sixth of a semitone. Musicians on AtariAge have noted that the only true fix is a separate frequency table for each standard.
Colours. PAL GTIA encodes the 16 hues differently from NTSC GTIA, so the same colour number does not give the same shade on both. Artists who care pick colours per standard, or test on both.
Mixed machines. Some machines combine an NTSC ANTIC with a PAL GTIA, or the reverse. In those, ANTIC sets the timing and GTIA sets the PAL register, so the register alone can mislead (see section 3).
3. Detecting the standard
There are two ways, and they answer different questions:
- GTIA's PAL register at $D014:
LDA $D014 : AND #$0Egives 0 on a PAL or SECAM GTIA and $0E on NTSC. This tells you the colour system. - ANTIC's line count: watch VCOUNT for a frame and note the highest value: $82 for 262 lines, $9B for 312. This tells you the frame rate, which is what timing code needs.
Detecting the Hardware: One Routine for PAL/NTSC, OS, Memory, Stereo and VBXE has a tested routine that does both. The example below uses the GTIA test for brevity.
4. Two ways to keep the speed
Suppose an object should move 50 pixels per second, updated in the vertical blank.
Method 1: skip frames on NTSC. Write the game for 50 updates per second, and on NTSC simply skip every sixth frame: 60 × 5/6 = 50. It is the simplest fix and needs no other change. Developers of music players have used it for NTSC playback. The drawback is that every sixth frame nothing moves, which can make fast scrolling visibly judder.
Method 2: scale the step. Keep updating every frame, but move by a different amount per frame: 1 pixel on PAL, 50/60 of a pixel on NTSC. Fractions need fixed-point arithmetic: here the position is a 24-bit 8.8 number (whole pixels in the upper two bytes) and the NTSC step is $00D5, which is 213/256 = 0.832 pixels per frame. Motion stays smooth on both systems, at the cost of a little arithmetic.
5. The test program
The program detects the standard, sets the step and the 10-second frame limit (500 or 600 frames), installs a deferred VBI that updates both methods each frame, and stops after 10 seconds to print the results.
; Same speed on PAL and NTSC: two ways to move "50 pixels per second"
; in a VBI, run for 10 seconds, then report how far each one got.
SAVMSC = $58
PAL = $D014
SETVBV = $E45C
XITVBV = $E462
PTR = $CB
org $3000
start lda PAL ; bits 1-3: 000 = PAL, 111 = NTSC
and #$0E
bne ntsc
lda #1
sta ispal
lda #<500 ; 10 seconds = 500 PAL frames
sta limit
lda #>500
sta limit+1
lda #$00 ; 1.0 pixel per frame (8.8 fixed point)
sta step
lda #$01
sta step+1
jmp go
ntsc lda #<600 ; 10 seconds = 600 NTSC frames
sta limit
lda #>600
sta limit+1
lda #$D5 ; 50/60 = 0.833 pixel per frame ($00D5/256)
sta step
lda #$00
sta step+1
go ldy #<vbi
ldx #>vbi
lda #7 ; deferred VBI
jsr SETVBV
wait lda done
beq wait
jsr report
jmp *
vbi lda done ; stop after 10 seconds
bne vx
inc frames ; count frames
bne v1
inc frames+1
v1 lda ispal ; method 1: one pixel per update, but on
bne upd ; NTSC skip every 6th frame (60 -> 50)
inc skipc
lda skipc
cmp #6
bne upd
lda #0
sta skipc
beq v2
upd inc posa
bne v2
inc posa+1
v2 clc ; method 2: add a per-standard step
lda posb ; (8.8 fixed point: posb+1/posb+2 = pixels)
adc step
sta posb
lda posb+1
adc step+1
sta posb+1
bcc v3
inc posb+2
v3 lda frames ; 10 seconds yet?
cmp limit
lda frames+1
sbc limit+1
bcc vx
lda #1
sta done
vx jmp XITVBV
report lda SAVMSC
sta PTR
lda SAVMSC+1
sta PTR+1
ldy #0
r1 lda text,y
sta (PTR),y
iny
cpy #textlen
bne r1
lda ispal ; standard name
asl
asl
tax
ldy #10
r2 lda stdname,x
sta (PTR),y
inx
iny
cpy #14
bne r2
lda frames
ldx frames+1
ldy #40+24
jsr dec5
lda posa
ldx posa+1
ldy #80+24
jsr dec5
lda posb+1
ldx posb+2
ldy #120+24
jsr dec5
rts
dec5 sta num ; A/X as 5 decimal digits at (PTR),Y
stx num+1
ldx #0
d1 lda #$10
sta digit
d2 lda num
sec
sbc p10lo,x
sta tmp
lda num+1
sbc p10hi,x
bcc d3
sta num+1
lda tmp
sta num
inc digit
bne d2
d3 lda digit
sta (PTR),y
iny
inx
cpx #5
bne d1
rts
p10lo dta <10000,<1000,<100,<10,<1
p10hi dta >10000,>1000,>100,>10,>1
text dta d'STANDARD: '
dta d'FRAMES IN 10 SECONDS: '
dta d'FRAME-SKIP METHOD (PX): '
dta d'SCALED-STEP METHOD (PX): '
textlen = *-text
stdname dta d'NTSC'
dta d'PAL '
ispal dta 0
done dta 0
frames dta a(0)
limit dta a(0)
step dta a(0)
skipc dta 0
posa dta a(0)
posb dta 0,0,0
num dta a(0)
digit dta 0
tmp dta 0
run start
Results, as in the screenshot:
| Frames in 10 s | Frame-skip method | Scaled-step method | |
|---|---|---|---|
| NTSC | 600 | 500 pixels | 499 pixels |
| PAL | 500 | 500 pixels | 500 pixels |
Both methods reached the same distance on both systems. The scaled step ended one pixel short on NTSC, because $D5/256 is slightly less than 5/6. A step of $D6 would overshoot by about the same amount. Over a whole game, a pixel in 10 seconds doesn't matter, but if two objects must stay exactly in step, keep the fractional part in more bits, or reset positions at known points.
6. Practical rules
- Decide which standard is "native" and convert on the other. If you develop on PAL, NTSC is the one that skips or scales, and vice versa.
- Time with frames, but convert: multiply delays by 6/5 on NTSC, or keep a lookup table of per-standard constants (step sizes, frames per second, music speed).
- Write VCOUNT tests with ≥ and ≤, never with equality near the bottom of the frame.
- Keep the vertical blank short. Budget for NTSC's 22 lines and move heavier work into the display time, for example with a DLI or into the main loop.
- Test on both. Emulators make this a single switch.
Troubleshooting
- Game too fast on NTSC, music too fast: frame-counted timing without compensation.
- Hang at start-up on NTSC only: a VCOUNT equality test for a value above $82, or a VBI routine that is too long.
- Tearing or flicker only on NTSC: the VBI work overruns into the visible display. Move it or shorten it.
- Detection says PAL, but timing is 60 Hz: a mixed ANTIC/GTIA machine or emulator setting. Use the VCOUNT test for timing decisions.
- Notes slightly out of tune between systems: expected. Use a separate frequency table for each standard if it matters.
Further reading
- Avery Lee, Altirra Hardware Reference Manual: section 4.2 (display timing and mixed systems), section 4.10 (VCOUNT), section 5.4 (POKEY clock frequencies), section 6.1 (the PAL register) and the PAL colour encoding table.
- On this site: Detecting the Hardware: One Routine for PAL/NTSC, OS, Memory, Stereo and VBXE, Keeping Time: RTCLOK, System Timers and POKEY Hardware Timers, Vertical Blank Interrupts: Running Code 60 Times a Second, ANTIC DMA and Cycle Timing: Where the CPU's Time Goes, Signed Numbers on the 6502: Two's Complement, Overflow and Signed Comparisons (fixed-point motion).
Credits
- Picture: The example on an emulated NTSC machine (top) and PAL machine (bottom): different frame counts, the same distance travelled. — Program authors; screenshot by the site
- Altirra Hardware Reference Manual — 4.2 Display timing (clocks, 262/312 lines, mixed ANTIC/GTIA), 4.10 VCOUNT ($82/$9B, PAL programs locking up on NTSC), 4.13 visible region 8-247, 5.4 POKEY clock frequencies, 6.1 PAL register, Table 14 PAL colour encodings — Avery Lee (Altirra)
- AtariAge forum — Pitch values (PAL pitches lower; every 6th frame skipped for NTSC player timing; separate tables needed) — AtariAge forum members
