Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user Harvey ! (Registered 2024-11-25) You are not logged in - nap
CSDb User Forums


Forums > C64 Productions > PAL/NTSC detect
2003-01-29 18:35
Dr. Jay
Account closed

Registered: Jan 2003
Posts: 32
PAL/NTSC detect

Just wanted to share a quick routine that detects PAL/NTSC WITHOUT using interrupts or latches.

;pal/NTSC detect - 0 = PAL, non-zero = NTSC

palntsc
sei ; disable interrupts
wait
lda $d012
bne wait ; wait for rasterline 0 or 256
wait1
lda $d011 ; Is rasterbeam in the area
bpl wait1 ; 0-255? if yes, wait
wait2
ldy #$00
synch1 lda $d012
cmp #$37 ; top PAL rasterline
bne synch1
lda $d012 ; if next is 0, then PAL
synch2 cmp $d012
beq synch2
lda $d012
cli ; enable interrupts
rts ; return
 
... 67 posts hidden. Click here to view all posts....
 
2009-02-01 13:02
AlexC

Registered: Jan 2008
Posts: 298
Quote: do NOT use the pal/ntsc flag since it is unreliable, even without any kind of extensions. the best way is really to check if certain rasterlines exist or not.


Does it mean that original ROM can set this flag wrongly? Haven't studied this part of ROM but I remember that the detection routine used is quite short.
2009-02-01 15:10
chatGPZ

Registered: Dec 2001
Posts: 11360
yes, the rom routine has a flaw that sometimes makes it report ntsc when the machine is infact pal. (atleast thats how i remember it =D)
2009-02-03 20:57
AlexC

Registered: Jan 2008
Posts: 298
Quote: yes, the rom routine has a flaw that sometimes makes it report ntsc when the machine is infact pal. (atleast thats how i remember it =D)

Thanks for clearing it up for me. I need to get NTSC machine to experiment a bit.
2009-02-14 12:15
Devia

Registered: Oct 2004
Posts: 401
So the shortest/fastes routine for reliable detection would be something like:

PALNTSC
	sei
	lda	$01
	pha
	lda	#<INT_NMI
	sta	$fffa
	lda	#>INT_NMI
	sta	$fffb
	lda	#$35
	sta	$01

;---important stuff start
:	bit	$d011
	bpl	:-
:	lda	$d012
	cmp	#<263
	bcs	:+	;Result >= 0 then PAL
	bit	$d011
	bmi	:-
	clc		;NTSC	
:
;---important stuff end

	pla
	sta	$01
	rts

INT_NMI
	rti


2009-02-14 12:25
tlr

Registered: Sep 2003
Posts: 1787
I came to basically the same conclusion:
http://codebase64.org/doku.php?id=bae:dtv_detect (scroll down)
2009-02-14 13:54
Devia

Registered: Oct 2004
Posts: 401
ahh... The first lda $d011, bmi *-3 seems obsolete, though - unless I'm missing something?
Is there any particular reason for waiting for line 288?

2009-02-14 14:24
TNT
Account closed

Registered: Oct 2004
Posts: 189
Quote: ahh... The first lda $d011, bmi *-3 seems obsolete, though - unless I'm missing something?
Is there any particular reason for waiting for line 288?



2009-02-14 17:15
Frantic

Registered: Mar 2003
Posts: 1647
Just wanted to say that TLR missed one letter in his link to codebase... the link is:

http://codebase64.org/doku.php?id=base:dtv_detect

Also, don't hesitate to update the current NTSC/PAL detection routine if you come up something better:

http://codebase64.org/doku.php?id=base:detect_pal_ntsc
2009-02-14 17:37
tlr

Registered: Sep 2003
Posts: 1787
Quote: ahh... The first lda $d011, bmi *-3 seems obsolete, though - unless I'm missing something?
Is there any particular reason for waiting for line 288?



So what happens if your version starts within 6 cycles of the raster counter wrapping to 0? ;)

288 is just about halfway between the max number of raster lines on PAL and NTSC respectively.
2009-02-14 21:22
Devia

Registered: Oct 2004
Posts: 401
Quote: So what happens if your version starts within 6 cycles of the raster counter wrapping to 0? ;)

288 is just about halfway between the max number of raster lines on PAL and NTSC respectively.


Well in that case it's apparently an NTSC machine ;-)

So, yes..

:	bit	$d011
	bmi	:-
:	bit	$d011
	bpl	:-
:	lda	$d012
	cmp	#<263
	bcs	:+	;Result >= 0 then PAL
	bit	$d011
	bmi	:-
	clc		;NTSC	
:


Any more pitfalls then?
Previous - 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Paladin/G★P
katon/Lepsi De
Krill/Plush
bugjam
Bieno/Commodore Plus
Alakran_64
Scooby/G★P/Light
Wayne/Art Ravers
Flex/Artline Designs
Nordischsound/Hokuto..
rexbeng
REBEL 1/HF
Mythus/Delysid
Chesoner/House Designs
csabanw
Guests online: 105
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Mojo  (9.6)
6 The Demo Coder  (9.6)
7 What Is The Matrix 2  (9.6)
8 Uncensored  (9.6)
9 Wonderland XIV  (9.6)
10 Comaland 100%  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 Party Elk 2  (9.6)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.6)
5 Libertongo  (9.5)
6 Rainbow Connection  (9.5)
7 Onscreen 5k  (9.5)
8 Morph  (9.5)
9 Dawnfall V1.1  (9.5)
10 It's More Fun to Com..  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Nostalgia  (9.3)
5 Triad  (9.2)
Top Musicians
1 Rob Hubbard  (9.7)
2 Jeroen Tel  (9.7)
3 Mutetus  (9.7)
4 Jammer  (9.6)
5 Linus  (9.6)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.062 sec.