English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 13 February 2021, 05:38   #1
orangespider
Registered User
 
Join Date: Feb 2021
Location: Becej / Serbia
Posts: 120
How to find out if we are on PAL or NTSC?

I am trying to write a function that gets an audio frequency and then returns the nearest AUDxPER value to be used for that frequency. It works like this:
Code:
; PAL VERSION
; d0 - frequency*100 (unsigned longword)
	move.l	d0, d1
	lsr.l	#1, d1
	move.l	#354687500, d2
	add.l	d1, d2
	divu.l	d0, d2
; d2 - AUDxPER


; NTSC VERSION
; d0 - frequency*100 (unsigned longword)
	move.l	d0, d1
	lsr.l	#1, d1
	move.l	#357954600, d2
	add.l	d1, d2
	divu.l	d0, d2
; d2 - AUDxPER
However, I couldn't find any way to find out if I am in PAL or NTSC. Alternatively something that gives the cycles/second could work as well, since then I would just send cycles/second to the function and it would still work. The only thing I was able to find is to read VBlankFrequency and check if it's 50 or 60. But this won't work for doublescan resolutions or custom resolutions, I am not interested in the screen framerate, I want to know the number of cycles per second.
orangespider is offline  
Old 13 February 2021, 09:17   #2
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Check VPOSR http://www.winnicki.net/amiga/memmap/VPOSR.html
ross is offline  
Old 13 February 2021, 09:51   #3
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,215
That tells you the vertical frequency of the currently active screen mode (and only so if this is a native screen mode), but not the system clock frequency. To check for PALN/NTSC, please read the graphics/gfxbase.h include file, there is a flag for it. One is dynamic and changes with the active monitor, but for the system clock frequency, there is a flag named something like REALLYPAL that corresponds to the installed crystal.
Thomas Richter is offline  
Old 13 February 2021, 10:21   #4
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Quote:
Originally Posted by Thomas Richter View Post
That tells you the vertical frequency of the currently active screen mode ..
What?!
It tells you which version of Agnus/Alice you have installed, and usually is supposed to have its associated crystal.
It has nothing to do with active video mode, as with both crystals and versions of Agnus-hr/Alice you can have NTSC or PAL lines.
ross is offline  
Old 13 February 2021, 10:39   #5
orangespider
Registered User
 
Join Date: Feb 2021
Location: Becej / Serbia
Posts: 120
Quote:
Originally Posted by ross View Post
If I understood it correctly, this should do the trick?
Code:
; d0 - frequency*100
	move.l	#354687500, d2
	move.w	vposr, d1
	and.w	#$1000, d1
	beq	.skip
	move.l	#357954600, d2
.skip:
	move.l	d0, d1
	lsr.l	#1, d1
	add.l	d1, d2
	divu.l	d0, d2
; d2 - AUDxPER
orangespider is offline  
Old 13 February 2021, 10:50   #6
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Quote:
Originally Posted by orangespider View Post
If I understood it correctly, this should do the trick?
ross is offline  
Old 13 February 2021, 11:12   #7
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Just noticed.. you sure used values are perfect?

In literature are reported values for PAL CCK = 3546895 and for NTSC = 3579545
ross is offline  
Old 13 February 2021, 16:39   #8
orangespider
Registered User
 
Join Date: Feb 2021
Location: Becej / Serbia
Posts: 120
Quote:
Originally Posted by ross View Post
Just noticed.. you sure used values are perfect?

In literature are reported values for PAL CCK = 3546895 and for NTSC = 3579545
I calculated the PAL one, don't remember where I got the NTSC from. Got the PAL as 227*15625 = 3546875. Think I'll go with your values instead, they are probably the correct ones.

Last edited by orangespider; 13 February 2021 at 16:45.
orangespider is offline  
Old 13 February 2021, 16:45   #9
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Quote:
Originally Posted by orangespider View Post
I calculated the PAL one, don't remember where I got the NTSC from. Got the PAL as 227*15625 = 3546875. They so I'll go with your values instead, they are probably the correct ones.
Yep, PAL h-freq on Amiga is not exactly 15625 but 15625,0881Hz
On NTSC is even more different due to alternating length lines (it only average to 64us EDIT:~63,56us).
So use my posted values

Last edited by ross; 13 February 2021 at 16:58.
ross is offline  
Old 13 February 2021, 16:49   #10
orangespider
Registered User
 
Join Date: Feb 2021
Location: Becej / Serbia
Posts: 120
Quote:
Originally Posted by ross View Post
Yep, PAL h-freq on Amiga is not exactly 15625 but 15625,0881Hz
On NTSC is even more different due to alternating length lines (it only average to 64us).
So use my posted values
I just got to those alternating length lines. I'm tying the timing of the phase shift to those cycles and it just gets more and more complicated as I read the documentation.
orangespider is offline  
Old 13 February 2021, 16:57   #11
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Quote:
Originally Posted by orangespider View Post
I just got to those alternating length lines. I'm tying the timing of the phase shift to those cycles and it just gets more and more complicated as I read the documentation.
Well, alternating lines are neutral in regard to your phase shift, only CCK is significant. Or I'm missing something?
ross is offline  
Old 13 February 2021, 17:57   #12
orangespider
Registered User
 
Join Date: Feb 2021
Location: Becej / Serbia
Posts: 120
Quote:
Originally Posted by ross View Post
Well, alternating lines are neutral in regard to your phase shift, only CCK is significant. Or I'm missing something?
Well, it's about the way I am synching the channels.

The current idea I am working on is:
1) find a vposr/hvposr nearby that we will use to start the whole thing
2) precalculate vposr/hvposr for all the next steps knowing the delays we want to have
3) vposr/hvposr wait to: start up the dma
4) vposr/hvposr wait to: stop the dma when we started playing the 2nd sample from the first pair
5) vposr/hvposr wait to: write to channel 0 when all of the channels are on idle
6) vposr/hvposr wait to: write to channel 1 at 90 degrees
7) vposr/hvposr wait to: write to channel 3 at 180 degrees
8) vposr/hvposr wait to: write to channel 2 at 270 degrees
9) fire up the audio DMA again

So the uneven scanlines are a problem, yes.
orangespider is offline  
Old 13 February 2021, 22:55   #13
sparhawk
Registered User
 
sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
In my library, I do it this way: https://github.com/skeetor/amiga-uti...stemTakeover.s (line 21)
sparhawk is offline  
Old 14 February 2021, 08:32   #14
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 3,335
Quote:
Originally Posted by orangespider View Post
However, I couldn't find any way to find out if I am in PAL or NTSC. Alternatively something that gives the cycles/second could work as well, since then I would just send cycles/second to the function and it would still work. The only thing I was able to find is to read VBlankFrequency and check if it's 50 or 60. But this won't work for doublescan resolutions or custom resolutions, I am not interested in the screen framerate, I want to know the number of cycles per second.
If running under Kickstart 2.0 or later you can check the EClockFrequency field in ExecBase.
mark_k is online now  
Old 14 February 2021, 09:35   #15
orangespider
Registered User
 
Join Date: Feb 2021
Location: Becej / Serbia
Posts: 120
Quote:
Originally Posted by mark_k View Post
If running under Kickstart 2.0 or later you can check the EClockFrequency field in ExecBase.
That seems to work. Just need to multiply those values by 5 and get the clock for the audio.
orangespider is offline  
Old 14 February 2021, 11:35   #16
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Quote:
Originally Posted by sparhawk View Post
In my library, I do it this way: https://github.com/skeetor/amiga-uti...stemTakeover.s (line 21)
This only indicates the power supply frequency which may or may not correspond to a PAL or NTSC system,
furthermore I seem to remember that in some condition there is a bug in the KS1.x in reporting this value.

Quote:
Originally Posted by mark_k View Post
If running under Kickstart 2.0 or later you can check the EClockFrequency field in ExecBase.
Yep, this is good , the only drawback is that is not working on KS1.x

Quote:
Originally Posted by orangespider View Post
That seems to work. Just need to multiply those values by 5 and get the clock for the audio.
Your audio value is not CCK*100?
As EClockFrequency (the base clock for CIA chips) is CCK/5 then you need EClockFrequency*500..
ross is offline  
Old 14 February 2021, 12:49   #17
8bitbubsy
Registered User
 
8bitbubsy's Avatar
 
Join Date: Sep 2009
Location: Norway
Posts: 1,710
Quote:
Originally Posted by orangespider View Post
I calculated the PAL one, don't remember where I got the NTSC from. Got the PAL as 227*15625 = 3546875. Think I'll go with your values instead, they are probably the correct ones.
Just get the master crystal frequency for PAL/NTSC Amigas and divide it by 8 to get the Paula rate. Every clock (except keyboard) is derived from this crystal, even the video clocks.

The crystal frequencies are exactly 28.37516MHz for PAL and ~28.63636363MHz (repeating) for NTSC. These are nominal values, real case frequencies will be off by a small fraction because of crystal tolerances and possibly other external factors.

So nominal Paula rates are:
PAL: exactly 3546895Hz
NTSC: ~3579545.45Hz (repeating)

Last edited by 8bitbubsy; 14 February 2021 at 13:15.
8bitbubsy is offline  
Old 14 February 2021, 18:20   #18
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 3,335
Quote:
Originally Posted by ross View Post
Yep, this is good , the only drawback is that is not working on KS1.x
You could roll your own check, e.g. disable ints, wait for vblank, read e clock. Wait for a certain number of scanlines, read e clock again. The difference between readings should fall within two distinct ranges depending on Amiga crystal frequency.
mark_k is online now  
Old 14 February 2021, 18:29   #19
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Quote:
Originally Posted by mark_k View Post
You could roll your own check, e.g. disable ints, wait for vblank, read e clock. Wait for a certain number of scanlines, read e clock again. The difference between readings should fall within two distinct ranges depending on Amiga crystal frequency.
No unfortunately, because all is tied to master clock.
You need two independent sources to do what you written.
ross is offline  
Old 19 February 2021, 01:20   #20
Photon
Moderator
 
Photon's Avatar
 
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,602
Reading VFreq from Execbase is reliable - to reveal if the motherboard (and therefore the crystal, if Paula is used) is PAL or NTSC.

If you're turning off the system (say, for audio in games or demos), native modes are often used so that this is enough.

If you're running in Workbench, it's best to use system functions for audio if possible, and the user shouldn't have to change his or her Workbench screen mode to play audio correctly. There are both native and expanded high-horizontal-frequency modes.
Photon is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to switch PAL Rev 6A A500 between PAL/NTSC? BarryB support.Hardware 10 03 August 2016 14:41
Pal - Ntsc dr.mushroom New to Emulation or Amiga scene 26 12 April 2014 09:48
NTSC A500 Pal/NTSC mod pics kipper2k Hardware pics 2 29 March 2009 07:56
NTSC to PAL ...what's next? NfernalNfluence support.Hardware 7 28 July 2007 12:19
Ntsc / Pal killergorilla project.SPS (was CAPS) 3 09 July 2003 18:25

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:30.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.16924 seconds with 13 queries