English Amiga Board

English Amiga Board (https://eab.abime.net/index.php)
-   Coders. Asm / Hardware (https://eab.abime.net/forumdisplay.php?f=112)
-   -   How to find out if we are on PAL or NTSC? (https://eab.abime.net/showthread.php?t=105811)

orangespider 13 February 2021 05:38

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.

ross 13 February 2021 09:17

Check VPOSR http://www.winnicki.net/amiga/memmap/VPOSR.html

Thomas Richter 13 February 2021 09:51

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.

ross 13 February 2021 10:21

Quote:

Originally Posted by Thomas Richter (Post 1461987)
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.

orangespider 13 February 2021 10:39

Quote:

Originally Posted by ross (Post 1461980)

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


ross 13 February 2021 10:50

Quote:

Originally Posted by orangespider (Post 1461994)
If I understood it correctly, this should do the trick?

:agree

ross 13 February 2021 11:12

Just noticed.. you sure used values are perfect?

In literature are reported values for PAL CCK = 3546895 and for NTSC = 3579545

orangespider 13 February 2021 16:39

Quote:

Originally Posted by ross (Post 1462001)
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.

ross 13 February 2021 16:45

Quote:

Originally Posted by orangespider (Post 1462071)
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 :)

orangespider 13 February 2021 16:49

Quote:

Originally Posted by ross (Post 1462073)
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.

ross 13 February 2021 16:57

Quote:

Originally Posted by orangespider (Post 1462076)
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?

orangespider 13 February 2021 17:57

Quote:

Originally Posted by ross (Post 1462080)
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.

sparhawk 13 February 2021 22:55

In my library, I do it this way: https://github.com/skeetor/amiga-uti...stemTakeover.s (line 21)

mark_k 14 February 2021 08:32

Quote:

Originally Posted by orangespider (Post 1461961)
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.

orangespider 14 February 2021 09:35

Quote:

Originally Posted by mark_k (Post 1462217)
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.

ross 14 February 2021 11:35

Quote:

Originally Posted by sparhawk (Post 1462145)
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 (Post 1462217)
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 (Post 1462219)
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..

8bitbubsy 14 February 2021 12:49

Quote:

Originally Posted by orangespider (Post 1462071)
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)

mark_k 14 February 2021 18:20

Quote:

Originally Posted by ross (Post 1462241)
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.

ross 14 February 2021 18:29

Quote:

Originally Posted by mark_k (Post 1462358)
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.

Photon 19 February 2021 01:20

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.


All times are GMT +2. The time now is 17:46.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.

Page generated in 0.04771 seconds with 11 queries