Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
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
2003-01-29 20:02
Perff
Administrator

Posts: 1665
I know it's not in the 'hardcore' coding-spirit, but isn't it easier just to ask the system?

One thing you could do is check the IRQ-timer which is different for PAL & NTSC even though I can't remember the values.
This ofcourse only work is you come straight from basic, and/or nothing has tampered with the IRQ-timing.

Another thing is to check the PAL/NTSC variable.
The address $02A6 is 0 for NTSC and 1 for PAL set by the ROM but this again could be overwritten by something.
But the ROM can't. In the ROM somwhere I think it says something like:
lda #$01
sta $02A6
for PAL and lda #$00 for NTSC. Why not just check that? (yes. It might not be at the same location in each ROM-version)

I'm not 100% sure of this information though. Just something I think I remember. Please correct me if I'm wrong. :)

/Perff
2003-01-30 11:38
Ninja

Registered: Jan 2002
Posts: 404
Perff: There is no PAL or NTSC-specific ROM. So any ROM checks for PAL/NTSC (counting rasterlines, see $FF5E...) and sets $02A6 depending on the result. And while we are just at it: Checking $02A6 is a poor way of detecting IMHO, because this location can easily be messed up. Those few bytes for a true PAL/NTSC-detection do not hurt, I think.

Dr Jay: What about this?

...
bne synch1
lda $d011
cli
rts

Bit 7 is set when PAL and cleared when NTSC. And I guess the LDY #$00 can be removed, too.
2003-01-30 11:48
Dr. Jay
Account closed

Registered: Jan 2003
Posts: 32
LOL. I saw the LDY after I posted it ... artifact from an earlier attempt. Yes, I like the LDA $D011 ... much more elegant. And as for the ROM issue ... everything I've come to understand says that checking the $02a6 etc is unreliable as different versions, mods, carts, etc. may change this ... but I'm stuck in NTSC-land with a 64C so I haven't had the opportunity to try this on many other stock machines.

2003-01-30 13:21
Ninja

Registered: Jan 2002
Posts: 404
I think the main problem with $02A6 is, that it is set after a reset only. So, load some scene-production which doesn't care about KERNAL-variables and maybe exits with a plain RTS, and $02A6 is as reliable as your house-number :)
Also, the KERNAL-method does not work with accelerators.

False detections because of $02A6 are really annoying; especially as PAL/NTSC-checks are public and easy to implement.

So much for the preaching... ;)
2003-01-30 13:29
Perff
Administrator

Posts: 1665
ninjadrm: Ok sorry for my "lame" idea. I just thought I remembered that somewhere in the ROM it said lda #$X sta $02A6 and thought of that as a 100% way to determin PAL/NTSC

Well.. I was wrong. You're right. Sorry. :)
2003-01-30 13:47
Ninja

Registered: Jan 2002
Posts: 404
Perff: No need to be sorry or to excuse for a "lame" idea; it was just meant to be constructive criticism :)
2003-02-02 22:34
Graham
Account closed

Registered: Dec 2002
Posts: 990
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.
2009-02-01 13:02
AlexC

Registered: Jan 2008
Posts: 293
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: 11110
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: 293
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.
 
... 67 posts hidden. Click here to view all posts....
 
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
kbs/Pht/Lxt
Mike
Alakran_64
t0m3000/ibex-crew
Fungus/Nostalgia
Guests online: 160
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Bromance  (9.6)
10 Memento Mori  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 Rainbow Connection  (9.5)
6 TRSAC, Gabber & Pebe..  (9.5)
7 Onscreen 5k  (9.5)
8 Wafer Demo  (9.5)
9 Dawnfall V1.1  (9.5)
10 Quadrants  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Fullscreen Graphicians
1 Carrion  (9.8)
2 Joe  (9.8)
3 Duce  (9.8)
4 Mirage  (9.7)
5 Facet  (9.7)

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