I also worked on this a bit, checked a few things, then rechecked, ohya, Rybags said
the VCOUNT can differ sometimes for one clock cycle... So taking that into effect, I offer
for your amusement :-)
Technically I did not test this routine....
;
; ntsc/pal detect on atari gtia
;
; uses A X and Carry
;
detectgtiamode
.stage1
lda VCOUNT ; does not interfere with DLI's!
rol ; waits for VCOUNT => 128, shifting msb to carry for looping.
bcc .stage1
sei ; interrupts off when beam almost off screen, VCOUNT=128+, no more DLI
.stage2
tax ; store old vcount in X
lda VCOUNT ; load new vcount
bne .stage2 ; if zero,then X contains max vcount value and drop out of loop
cli ; interrupts on ... DLI back
txa ; X should be aprox 131 or 156 decimal
sbc #16 ; even out the #'s. allows for tiny variations!!
rol ; we can use msb into carry to tell video mode
rts ; assuming a jsr?
;
; on exit
; carry 0 = ntsc, carry 1 = pal, X contains max VCOUNT aprox 131 or 156
; end detectgtiamode