User Tools

Site Tools


base:detect_pal_ntsc

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
base:detect_pal_ntsc [2016-09-27 17:49] sokratesbase:detect_pal_ntsc [2018-10-29 10:50] – [Sokrates' variant] mrr19121970
Line 1: Line 1:
-====== Detect PAL/NTSC ======+====== Detect NTSC/PAL ======
  
-Since you cannot rely on $02a6 to detect PAL/NTSC, you better do the check yourself. The theory behind these checks is simply that PAL and NTSC systems have different ammounts of rasterlines, which can thus serve as the basis for a detection check.+Since you cannot rely on $02a6 to detect NTSC/PAL, you better do the check yourself. The theory behind these checks is simply that PAL and NTSC systems have different amounts of rasterlines, which can thus serve as the basis for a detection check.
  
 ===== J0x variant ===== ===== J0x variant =====
Line 67: Line 67:
  
 <code> <code>
 +    SEI
     LDX #$00     LDX #$00
 w0  LDA $D012 w0  LDA $D012
Line 611: Line 612:
 ; eof ; eof
 </code> </code>
 +
 +
 +===== TWW's Variant =====
 +
 +Count's number of cycles on one scan with CIA timer and uses the 2 LSBs from the high byte of the CIA Timer to determine model. This reliably detects PAL, NTSC, NTSC2 and DREAN. routine exits with result in A. Make sure no interrupts occur during the runtime of the routine.
 +
 +<code>
 +    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 +    // Detect PAL/NTSC
 +    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 +    // 312 rasterlines -> 63 cycles per line PAL        => 312 * 63 = 19656 Cycles / VSYNC  => #>76  %00
 +    // 262 rasterlines -> 64 cycles per line NTSC V1    => 262 * 64 = 16768 Cycles / VSYNC  => #>65  %01
 +    // 263 rasterlines -> 65 cycles per line NTSC V2    => 263 * 65 = 17095 Cycles / VSYNC  => #>66  %10
 +    // 312 rasterlines -> 65 cycles per line PAL DREAN  => 312 * 65 = 20280 Cycles / VSYNC  => #>79  %11
 +
 +DetectC64Model:
 +
 +    // Use CIA #1 Timer B to count cycled in a frame
 +    lda #$ff
 +    sta $dc06
 +    sta $dc07  // Latch #$ffff to Timer B
 +
 +    bit $d011
 +    bpl *-3    // Wait untill Raster > 256
 +    bit $d011
 +    bmi *-3    // Wait untill Raster = 0
 +
 +    ldx #%00011001
 +    stx $dc0f  // Start Timer B (One shot mode (Timer stops automatically when underflow))
 +
 +    bit $d011
 +    bpl *-3    // Wait untill Raster > 256
 +    bit $d011
 +    bmi *-3    // Wait untill Raster = 0
 +
 +    sec
 +    sbc $dc07  // Hibyte number of cycles used
 +    and #%00000011
 +    rts
 +</code>
 +
  
 ===== Older routine ===== ===== Older routine =====
base/detect_pal_ntsc.txt · Last modified: 2020-11-11 01:49 by copyfault