1, 2  Next
Understanding PAL color subcarrier ratios 
Author Message
User avatar

Joined: 2014-09-25 13:52
Posts: 8294
 Understanding PAL color subcarrier ratios
I wrote this up earlier today. Curious if anyone has ideas on it.

The issue is that the PAL subcarrier actually used as a multiplier in video game consoles seems to be 80% of the official specification. But that is not the case for NTSC. And I'm trying to find out why that is, and if I should update my Emulator::Constants::Colorburst::PAL variable to be 80% of the official color subcarrier value or not.

Code:
[Color subcarrier constants]
NTSC color subcarrier: 315 / 88 * 1000000 = ~3579545hz
PAL color subcarrier: 283.75 * 15625 + 25 = ~4433618hz
  283.75 = color clock cycles per line
  15625 = line frequency (625 lines * 50hz / 2)
  25 = offset

[Colorburst constants]
NTSC colorburst = NTSC color subcarrier (100% of subcarrier) = ~3579545hz
PAL colorburst = PAL color subcarrier * 4 / 5 (80% of subcarrier) = ~3546895hz

[Notes]
The "colorburst" value is a made up constant. The "subcarrier" is the official specification.
We don't really care about the CPU, APU clock speeds as they aren't tied to video generation.

[Sega Master System]
VDP = colorburst * 15 / 5
  NTSC = 10738635hz; / subcarrier = 3  ; / colorburst = 3
  PAL  = 10640685hz; / subcarrier = 2.4; / colorburst = 3

[Sega Mega Drive]
VDP = colorburst * 15 / 2
  NTSC = 26846588hz; / subcarrier = 7.5; / colorburst = 7.5
  PAL  = 26601713hz; / subcarrier = 6  ; / colorburst = 7.5

[Sega]
colorburst*15
  NTSC = 53693175hz; / subcarrier = 15
  PAL  = 53203425hz; / subcarrier = 12

Here we can at least see that both the NTSC and PAL clock rates are evenly divisible by the subcarriers.
Even if the VDP clocks themselves don't run off an even multiple of the subcarriers.

[Nintendo Famicom + Nintendo Super Famicom]
PPU = colorburst * 6
  NTSC = 21477270hz; / subcarrier = 6
  PAL  = 21281370hz; / subcarrier = 4.8

Here we see that the PAL crystal clock is 4.8x the PAL color subcarrier.
4433618*4.8 = 21281370hz

_________________
What the hell's going on? Can someone tell me please?
Why I'm switching faster than the channels on TV.
I'm black, then I'm white. No, something isn't right.
My enemy's invisible, I don't know how to fight.


2017-06-21 03:37
User avatar

Joined: 2014-10-29 21:24
Posts: 1814
Location: People's Republic of America
 Re: Understanding PAL color subcarrier ratios
I think the Famicom is actually an exception to this rule.

As explained on NesDev, the PAL master clock is 26,601,712 Hz, and the PAL PPU clock divider is 5 instead of 4, which matches up with the "80% of colorburst" statement. However, the CPU and APU's clock divider is not 15 (12 × 5/4), but 16. Nintendo wanted to keep the Johnson counter structure, which requires that the clock divider be an even number (the Dendy uses 15 as its divider, but that's unlicensed hardware that you wouldn't want to emulate).

This makes it impossible to simply multiply PAL colorburst by 4/5 within system.cpp like in the Super Famicom, so instead, I set the clock rate individually in each processor in nSide.

fc/cpu/memory.cpp
Code:
auto CPU::read(uint16 addr) -> uint8 {
  //...
  r.mdr = bus.read(addr, r.mdr);
  step(Region::NTSC() ? 12 : Region::PAL() ? 16 : 15);
  return r.mdr;
}


fc/apu/apu.cpp
Code:
auto APU::tick() -> void {
  if(Region::NTSC ()) Thread::step(12);
  if(Region::PAL  ()) Thread::step(16);
  if(Region::Dendy()) Thread::step(15);
}


fc/ppu/ppu.cpp
Code:
auto PPU::step(uint clocks) -> void {
  //...
  while(clocks--) {
    //...
    Thread::step(Region::NTSC() ? 4 : 5);
    synchronize(cpu);
    //...
  }
}

_________________
bsnes-mcfly: A port of the Qt GUI from v073 to v106.
nSide: A higan fork w/NES boards and peripherals and Sonic & Knuckles Lock-On.
Dragon Quest I & II RPGOne Beran Inn bugfix


2017-06-21 04:17
User avatar

Joined: 2014-09-25 13:52
Posts: 8294
 Re: Understanding PAL color subcarrier ratios
Kind of the wrong thread to ask, but what the hell, heh.

I was going to ask you to look over my Famicom PAL implementation and see what you think? I'm sure some of the really tiny timing details of PPU operations are not correct, but if it's 99% right, I'll be happy.

Sounds like I need to adjust the way I step time. Any other issues than what you've pointed out that's critical?

_________________
What the hell's going on? Can someone tell me please?
Why I'm switching faster than the channels on TV.
I'm black, then I'm white. No, something isn't right.
My enemy's invisible, I don't know how to fight.


2017-06-21 04:38
User avatar

Joined: 2014-10-29 21:24
Posts: 1814
Location: People's Republic of America
 Re: Understanding PAL color subcarrier ratios
Well, your APU class has period tables for both the Noise and DMC channels in PAL, but you're still using the NTSC tables even in PAL mode.

Also,
noisePeriodTablePAL
has an error that NesDev discovered sometime after you first created the Famicom core: change the element at position 1 from 7 to 8.
dmcPeriodTablePAL
has no such error.

Your PPU would probably be fine if you continue to multiply colorburst by 4/5 in system.cpp, but that will make your CPU and APU timings off, so I would change
Thread::step(4);
to
Thread::step(Region::NTSC() ? 4 : 5);
or something similar, then I would make similar changes to the CPU and APU to take 16 cycles per step instead of 12 when running in PAL mode.

My test game for PAL mode was Wario's Woods. Its soundtrack was quite different in its European release compared to the NTSC regions, with only a few shared songs. For example, the Round Game music:



EDIT: I should clarify that I made sure that the YouTube song is actually playing at the correct speed and pitch for PAL. There are other versions of this song on YouTube as well, but some of them were recorded on NTSC and are therefore slightly faster and higher-pitched than they need to be.

_________________
bsnes-mcfly: A port of the Qt GUI from v073 to v106.
nSide: A higan fork w/NES boards and peripherals and Sonic & Knuckles Lock-On.
Dragon Quest I & II RPGOne Beran Inn bugfix


2017-06-21 05:40

Joined: 2016-03-13 23:49
Posts: 67
 Re: Understanding PAL color subcarrier ratios
I'm not sure I correctly understand your initial post, but at least for the Mega Drive the colorburst is 100% of the normal value. The difference between NTSC and PAL systems is the clock divider used to produce it and the precise value of the crystal oscillator. NTSC consoles use a 53.693175 master clock with a /15 divider for colorburst and PAL consoles use a 53.693175 master clock with a /12 divider for colorburst. The frequency the VDP runs at is unrelated to the colorburst frequency apart from the fact that they both are derived from the same master clock source. VDP runs at MCLK/4 or MCLK/5 depending on the video mode (H32 is always MCLK/5, H40 is mostly MCLK/4 with a bit of MCLK/5 to keep the line length the same) with the dot clock running at half that.

I don't know about Nintendo's consoles, but I kind of doubt they're much different on this front. A TV is not going to like it if the colorburst is the wrong frequency.


2017-06-21 05:41

Joined: 2014-09-27 09:27
Posts: 2384
Location: Australia
 Re: Understanding PAL color subcarrier ratios
Mask_of_Destiny wrote:
I don't know about Nintendo's consoles, but I kind of doubt they're much different on this front. A TV is not going to like it if the colorburst is the wrong frequency.

CRT's are pretty lenient it seems. Unlike LCD's.

_________________
Windows 10 Pro x64 | Intel Core i7 920 @ 3.6GHz | ASUS P6T Motherboard | 24GB 1140~MHz DDR3 RAM | MSI Geforce 1070Ti Gamer | Integrated Sound | Samsung 860 Pro 512GB SSD | Corsair AX760 Power Supply | Fractal Design Define R5 PC case


2017-06-21 06:16

Joined: 2016-03-13 23:49
Posts: 67
 Re: Understanding PAL color subcarrier ratios
Franpa wrote:
CRT's are pretty lenient it seems. Unlike LCD's.

A 20% error in a synchronization signal is pretty darn big and I would be surprised if even an older CRT would handle that. I've heard that owners of PAL Megadrives that perform a 60Hz mod need to also modify the divider supplied to the composite encoder if they want color over composite.


2017-06-21 06:59
User avatar

Joined: 2014-09-25 13:52
Posts: 8294
 Re: Understanding PAL color subcarrier ratios
Mask_of_Destiny wrote:
I don't know about Nintendo's consoles, but I kind of doubt they're much different on this front. A TV is not going to like it if the colorburst is the wrong frequency.


Look at the numbers in my first post. The SNES PAL crystal clock used by the CPU and PPU is 21281370hz. Which is 4.8x the official PAL color subcarrier. That seems like a very tough number to make a divider for compared to an even multiple.

_________________
What the hell's going on? Can someone tell me please?
Why I'm switching faster than the channels on TV.
I'm black, then I'm white. No, something isn't right.
My enemy's invisible, I don't know how to fight.


2017-06-21 13:14

Joined: 2016-03-13 23:49
Posts: 67
 Re: Understanding PAL color subcarrier ratios
byuu wrote:
Look at the numbers in my first post. The SNES PAL crystal clock used by the CPU and PPU is 21281370hz. Which is 4.8x the official PAL color subcarrier. That seems like a very tough number to make a divider for compared to an even multiple.

I agree that 4.8 is an unlikely divider value; however, I think your problem is you have the wrong oscillator value for the PAL SNES. A 50/60Hz modding guide I came across suggested that the PAL oscillator is actually 17734476 Hz which is exactly 4x the PAL color carrier frequency. Looking at the markings on the crystals for NTSC and PAL consoles seems to confirm this. NTSC consoles have a crystal marked D21 or D214 followed by a suffix whereas PAL consoles have D17 or D177 followed by a suffix. Since the two clocks are fairly different, this implies that the dividers used for producing the PPU and CPU clocks are different in PAL mode. Not sure how you get a usable pixel clock from a 17734476 Hz crystal though. A /4 divider seems to slow (~4.4Mhz) and a /3 divider seems too fast (~5.9Mhz). The setup on the PAL NES with a 26601712 Hz crystal makes a lot more sense


2017-06-21 17:55
User avatar

Joined: 2014-09-25 13:52
Posts: 8294
 Re: Understanding PAL color subcarrier ratios
> A 50/60Hz modding guide I came across suggested that the PAL oscillator is actually 17734476 Hz which is exactly 4x the PAL color carrier frequency.

That is indeed very possible! I don't know of anyone who has actually measured the PAL oscillator with a logic analyzer to be sure.

But ... math time!

NTSC: 21477272hz
PAL: 17734475hz

Fast speed: NTSC/6 = 3579545hz; PAL/5 = 3546895hz
Slow speed: NTSC/8 = 2684659hz; PAL/6 = 2955746hz; PAL/7 = 2533496hz
Serial speed: NTSC/12 = 1789773hz; PAL/10 = 1773448hz

PAL: 21281370hz

Fast speed: PAL/6 = 3546895hz
Slow speed: PAL/8 = 2660171hz
Serial speed: PAL/12 = 1773448hz

If this is truly the case, then there is no natural divider that will give us the same ratio of speeds as the NTSC SNES.

We would need a divider of 6.666: 17734475hz/6.666 = 2660171hz.

_________________
What the hell's going on? Can someone tell me please?
Why I'm switching faster than the channels on TV.
I'm black, then I'm white. No, something isn't right.
My enemy's invisible, I don't know how to fight.


2017-06-21 18:05
1, 2  Next