base:detect_pal_ntsc
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
base:detect_pal_ntsc [2015-04-17 04:31] – external edit 127.0.0.1 | base:detect_pal_ntsc [2020-11-10 21:56] – [Source Code] copyfault | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Detect PAL/NTSC ====== | + | ====== Detect |
- | + | ||
- | 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, | + | |
+ | 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, | ||
===== J0x variant ===== | ===== J0x variant ===== | ||
Line 62: | Line 61: | ||
EDIT: This check assumes that the machine is not a Drean PAL-N, which has 312 lines and 65 cycles per line. | EDIT: This check assumes that the machine is not a Drean PAL-N, which has 312 lines and 65 cycles per line. | ||
+ | ===== Sokrates' | ||
+ | |||
+ | Graham' | ||
+ | |||
+ | < | ||
+ | SEI | ||
+ | LDX #$00 | ||
+ | w0 LDA $D012 | ||
+ | w1 CMP $D012 | ||
+ | BEQ w1 | ||
+ | BMI w0 | ||
+ | AND #$03 | ||
+ | CMP #$03 | ||
+ | BNE detectionDone ; done for NTSC | ||
+ | TAY | ||
+ | countCycles | ||
+ | INX | ||
+ | LDA $D012 | ||
+ | BPL countCycles | ||
+ | CPX #$5E ; VICE values: PAL-N=$6C PAL=$50 | ||
+ | ; so choose middle value $5E for check | ||
+ | BCC isPAL | ||
+ | INY ; is PAL-N | ||
+ | isPAL | ||
+ | TYA | ||
+ | detectionDone | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | Results in the accumulator: | ||
+ | |||
+ | < | ||
+ | #$01: 262 rasterlines and 64 cycles per line [NTSC: 6567R56A VIC] (OLD NTSC) | ||
+ | #$02: 263 rasterlines and 65 cycles per line [NTSC: 6567R8 VIC] | ||
+ | #$03: 312 rasterlines and 63 cycles per line [PAL: 6569 VIC] | ||
+ | #$04: 312 rasterlines and 65 cycles per line [Drean PAL-N: 6572 VIC] | ||
+ | </ | ||
===== TLR's more advanced variant ===== | ===== TLR's more advanced variant ===== | ||
Line 575: | Line 611: | ||
; eof | ; eof | ||
</ | </ | ||
+ | |||
+ | |||
+ | ===== TWW's Variant ===== | ||
+ | |||
+ | Count' | ||
+ | |||
+ | < | ||
+ | // | ||
+ | // Detect PAL/NTSC | ||
+ | // | ||
+ | // 312 rasterlines -> 63 cycles per line PAL => 312 * 63 = 19656 Cycles / VSYNC => #> | ||
+ | // 262 rasterlines -> 64 cycles per line NTSC V1 => 262 * 64 = 16768 Cycles / VSYNC => #> | ||
+ | // 263 rasterlines -> 65 cycles per line NTSC V2 => 263 * 65 = 17095 Cycles / VSYNC => #> | ||
+ | // 312 rasterlines -> 65 cycles per line PAL DREAN => 312 * 65 = 20280 Cycles / VSYNC => #> | ||
+ | |||
+ | 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 | ||
+ | </ | ||
+ | |||
===== Older routine ===== | ===== Older routine ===== | ||
Line 749: | Line 826: | ||
</ | </ | ||
+ | ===== When size really matters ===== | ||
+ | |||
+ | by Copyfault/ | ||
+ | |||
+ | In the following I'm going to present two routines for detecting PAL/NTSC: the first one is used for telling a EU-PAL-chip (with 63 cycles per line) apart from a "new NTSC" | ||
+ | |||
+ | The 2nd routine is capable of detecting any of the four VIC-types that have been mentioned earlier on this page (EU-PAL, NTSC old _and_ new and the one for the Drean-PAL-system). | ||
+ | |||
+ | ==== Short PAL/NTSC detection ==== | ||
+ | |||
+ | The basic idea is to constantly read the raster beam position and keeping it in a backup register until rasterline==0 (or rasterline==$100) is reached. Then the backup register holds the value of the last line that was read before reaching line 0 (or $100 resp.). | ||
+ | |||
+ | In case the last line was $ff, it does not tell much about the system at hand. Thus, the rasterline-read-and-backup-procedure is repeated until the backup value is not $ff afterwards. | ||
+ | |||
+ | The well-known table of VIC-specs now reveals that the backup value must be one of the following: | ||
+ | < | ||
+ | #$37 -> 312 rasterlines -> PAL | ||
+ | #$06 -> 263 rasterlines -> new NTSC | ||
+ | #$05 -> 262 rasterlines -> old NTSC | ||
+ | </ | ||
+ | |||
+ | It's even possible to tell new and old NTSC apart this way (not just PAL vs. NTSC as stated in the preface). The approach is NOT capable to distinguish between the different PAL-variants (PAL N as used in the Drean-systems and EU-PAL) since they have the same number of rasterlines per frame. | ||
+ | |||
+ | |||
+ | === Source Code === | ||
+ | < | ||
+ | chk: | ||
+ | ldx #$aa //$aa = TAX | ||
+ | lda $d012 | ||
+ | bne chk+1 | ||
+ | txa | ||
+ | bmi chk | ||
+ | </ | ||
+ | This routine continuously checks $D012==0 while saving the last read $D012-value in X and repeats the whole procedure when the value stored in X has the MSB set. This luckily suffices to distinguish the case "last line was $ff" from "last line was the last one of the frame", | ||
+ | |||
+ | Why that ['' |
base/detect_pal_ntsc.txt · Last modified: 2020-11-11 01:49 by copyfault