Detecting video standard

From NESdev Wiki
Revision as of 16:15, 2 March 2006 by Tepples (talk | contribs) (import)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Simple way to detect if program is running on PAL or NTSC system.

;
; Detects the video standard under which the program is running.
; Out:  A = 0 for 60 Hz (NTSC or PAL/M) or 1 for 50 Hz (PAL)
; Trash:@vdh, @vdl (variables on zeropage)
;
detectpalntsc:

  @vdl = $00
  @vdh = $01

  lda $2002
  bpl detectpalntsc
  lda #$00
  sta @vdh
  sta @vdl
@vdc:   
    lda @vdl
    clc
    adc #$01
    sta @vdl
    lda @vdh
    adc #$00
    sta @vdh
    lda $2002
    bpl @vdc
  lda @vdh
  sbc #$03
  rts