Detecting NTSC/PAL VICs

Basic and Machine Language

Moderator: Moderators

Post Reply
brighty
Vic 20 Amateur
Posts: 45
Joined: Wed Jul 02, 2008 2:14 am

Detecting NTSC/PAL VICs

Post by brighty »

Hi All,

I'm sure I saw a mention in the forums some time ago about being able to detect a PAL vs NTSC VIC programatically, but for all my searches I can't find it again :oops:

Does anybody recall which memory location it is and the value it contains PAL vs NTSC?
nippur72
de Lagash
Posts: 574
Joined: Thu Sep 07, 2006 8:35 am

Post by nippur72 »

from the Software Sprite thread:
this address $EDE4 (NTSC=$05, PAL=$0C) [...],
brighty
Vic 20 Amateur
Posts: 45
Joined: Wed Jul 02, 2008 2:14 am

Post by brighty »

nippur72 wrote:from the Software Sprite thread:
this address $EDE4 (NTSC=$05, PAL=$0C) [...],
Thanks! I thought I'd searched this thread, as that was where I recalled I'd seen it. Damn! :oops:
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

Of course if some naughty fellow has replaced the Kernel ROM with one for the wrong machine, it won't work. On the other hand it means the VIC would boot up with an off-centered screen every time. But to this point it is the best/simplest way I can think of. One probably could wait for a certain raster line and set up a timer but it would be more work for the same benefit.
Anders Carlsson

Image Image Image Image Image
tlr
Vic 20 Nerd
Posts: 567
Joined: Mon Oct 04, 2004 10:53 am

Post by tlr »

I thought I'd give an example of the raster line method, which as noted does not rely on the Kernal ROM.
This is the way it is implemented in victracker:
(must have interrupts disabled)

Code: Select all

;**************************************************************************
;*
;* CheckPAL
;* Returns:	 Acc=0 on NTSC-M systems, Acc!=0 on PAL-B systems
;*		 (and sets PAL_Flag accordingly)
;*
;******
CheckPAL:
; find raster line 2
	lda	#2/2
cp_lp1:
	cmp	$9004
	bne	cp_lp1
; now we know that we are past raster line 0, see if we find raster line 268
; before we find raster line 0
cp_lp2:	
	lda	$9004
	beq	cp_ex1
	cmp	#268/2		; This line does not exist on NTSC.
	bne	cp_lp2
cp_ex1:	
	sta	PAL_Flag
	rts
brighty
Vic 20 Amateur
Posts: 45
Joined: Wed Jul 02, 2008 2:14 am

Post by brighty »

Thanks for all the replies. I've gone with the EDE4 method for now, less bytes and I'm not too bothered if my code wont run on custom kernals.

It seems to work fine when testing in VICE (NTSC and PAL) and on a real PAL VIC. I don't have access to an NTSC VIC to test. Would anybody be willing to test out a PRG for me to make sure that there is no flicker and the screen is visible? (It's a game in progress, no interaction yet, requires 8/16K expansion).

Thanks
a1bert
Vic 20 Dabbler
Posts: 96
Joined: Mon Jan 23, 2006 12:49 am

Post by a1bert »

brighty wrote:I'm not too bothered if my code wont run on custom kernals.
Well, there are some machines around that have PAL ROM's but are NTSC-converted...

I used this in VIMM:

Code: Select all

	; detect the system
	lda #0
	sta SYSTEMSEL
0$	lda $9004
	cmp #1
	bne 0$		; wait for line 1
1$	lda $9004
	beq 2$		; line 0 reached -> NTSC
NTSC_LINES = 261
	cmp #NTSC_LINES/2+2
	bne 1$
	inc SYSTEMSEL
2$	; system detected: 0 for NTSC, 1 for PAL
User avatar
amramsey
Vic 20 Hobbyist
Posts: 117
Joined: Sat Apr 14, 2007 9:38 pm

Post by amramsey »

brighty wrote:Would anybody be willing to test out a PRG for me to make sure that there is no flicker and the screen is visible? (It's a game in progress, no interaction yet, requires 8/16K expansion).
I can do it. I've got an NTSC vic with memory expansion. Do you have a link to the file?
brighty
Vic 20 Amateur
Posts: 45
Joined: Wed Jul 02, 2008 2:14 am

Post by brighty »

amramsey wrote:I can do it. I've got an NTSC vic with memory expansion. Do you have a link to the file?
Thanks a million. The PRG can be found here
User avatar
amramsey
Vic 20 Hobbyist
Posts: 117
Joined: Sat Apr 14, 2007 9:38 pm

Post by amramsey »

Looks really good. The screen was centred, no flickering or any funny business. The only problem was that the score at the top was cut off (about half of it) on my TV screen. I tried it out on a 1080 monitor also and the score was completely missing.

There was perhaps enough room at the bottom of the screen for about 1/2 a level of blocks or so. When the baddies jump off the bottom they can be seen right until the plastic on the monitor (ie- no border at the bottom).

Loading on 1080 (to give you an idea of the normal borders on the vic)

Image

Gameplay

Image

15 second video (probably have to right click and save it):
http://aaronramsey.com/public/vic20/qbert.mpg
brighty
Vic 20 Amateur
Posts: 45
Joined: Wed Jul 02, 2008 2:14 am

Post by brighty »

amramsey wrote:Looks really good. The screen was centred, no flickering or any funny business.
First off, a big thanks for putting in the time and effort to help me out, I really appreciate it. I can only test the NTSC version on VICE and this really illustrates the necessity of testing on real hardware.
amramsey wrote:The only problem was that the score at the top was cut off (about half of it) on my TV screen. I tried it out on a 1080 monitor also and the score was completely missing.

There was perhaps enough room at the bottom of the screen for about 1/2 a level of blocks or so. When the baddies jump off the bottom they can be seen right until the plastic on the monitor (ie- no border at the bottom).
I suspected I was pushing the display borders a bit on NTSC trying to display 28 rows. I think I can get away with trimming the top row off and moving the score down. I'll have a play with this over the weekend. I'll add keyboard input for screen centering too (horizontal & vertical), to allow for any differences between TVs and monitors.

Once again, thanks a million for the work you put in, especially with the video and pictures, they truly do speak a 1,000 words.
brighty
Vic 20 Amateur
Posts: 45
Joined: Wed Jul 02, 2008 2:14 am

Post by brighty »

a1bert wrote:
brighty wrote:I'm not too bothered if my code wont run on custom kernals.
Well, there are some machines around that have PAL ROM's but are NTSC-converted...
Ah, I didn't know people swapped ROMs like that :oops: I'll change the detection code over the weekend to use a1bert/tlr's method.

Thanks to both of you for the code and info. My credits list is growing already :)
a1bert
Vic 20 Dabbler
Posts: 96
Joined: Mon Jan 23, 2006 12:49 am

Post by a1bert »

brighty wrote:Ah, I didn't know people swapped ROMs like that
Actually it's the other way around: the ROM's are original, but the video chip has been changed. See http://www.iki.fi/a1bert/Dev/PAL2NTSC.html
Post Reply