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
Last revisionBoth sides next revision
base:detect_pal_ntsc [2019-05-15 20:11] – [Detect NTSC/PAL] silverdrbase:detect_pal_ntsc [2020-11-10 21:59] copyfault
Line 826: Line 826:
 </code> </code>
  
 +===== When size really matters =====
 +
 +by Copyfault/The Solution/The Obsessed Maniacs
 +
 +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"-chip (with 65cycles/line). This suffices in most cases since the mentioned systems were the most common in EU or US, resp.
 +
 +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:
 +<code>
 +#$37 -> 312 rasterlines -> PAL
 +#$06 -> 263 rasterlines -> new NTSC 
 +#$05 -> 262 rasterlines -> old NTSC
 +</code>
 +
 +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 ===
 +<code>
 +chk:          
 +              ldx #$aa   //$aa = TAX
 +              lda $d012
 +              bne chk+1
 +              txa
 +              bmi chk
 +</code>
 +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", since the highest possible value is $37 (on PAL).
 +
 +Why that [''ldx #$aa'']? There's a small probability that the routine starts when we accidently **are** on line $0 (or $100). The [''bne chk+1''] would not branch, i.e. the check-for-line$0-loop would end promptly, without any backup value stored in X yet. Thus, we need an init value for X that forces the line$0-check to be repeated in this rare case. It could by any value with MSB set, but using $aa (=TAX as opcode) contributes to making the whole routine as short as possbile.
 +
 +
 +===== Very short full VIC-type detection =====
 +
 +Count cycles galore
 +
 +=== Source Code ===
 +<code>
 +yet
 +to
 +come
 +</code>
base/detect_pal_ntsc.txt · Last modified: 2020-11-11 01:49 by copyfault