SNES clock change

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

SNES clock change

Post by Oziphantom »

So the SNES does
3.5
2.8
1.8 ish right.
And if you access the CPU regs or the Common RAM it goes at 1.8 but if you hit upper RAM or ROM it goes at 3.5 or 2.8...

Does it switch the clocks on the barrier or does it clock stretch to the clocks running at lower frequencies?
say you have a 3.5 to a 1.8 does it do

Code: Select all

__    ____      __
  |__|    |____|  |__
or does the machine have
1.8      ____      ____
    ____|    |____|    |____
3.5   __   __   __   __   __
    _|  |_|  |_|  |_|  |_|
so when you switch from 3.5 to 1.8 on an odd clock it stretches
      _______      __   __   __
    _|       |____|  |_|  |_|
     ^ do 1.8 access here 
creaothceann
Posts: 611
Joined: Mon Jan 23, 2006 7:47 am
Location: Germany
Contact:

Re: SNES clock change

Post by creaothceann »

The master clock always runs at 1890/88 = 21.47{72}MHz. The 5A22 contains (among other things) the 65c816 CPU and an address decoder, which translates the 65c816's bus address into SNES bus addresses, and determines the memory map region. The clock signal for the internal 65c816 is then simply held for 6, 8 or 12 master clock cycles while the rest of the 5A22 (e.g. DMA controller) and the system continues.
My current setup:
Super Famicom ("2/1/3" SNS-CPU-GPM-02) → SCART → OSSC → StarTech USB3HDCAP → AmaRecTV 3.10
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: SNES clock change

Post by lidnariq »

In 6502 terms, the SNES's φ2 cycle is 3, 5, or 9 master clock cycles depending on the specific address accessed, while φ1 is always 3 master clock cycles.

(Ridiculous exception: DMA access is actually φ1=φ2=4 master clock cycles)
93143
Posts: 1717
Joined: Fri Jul 04, 2014 9:31 pm

Re: SNES clock change

Post by 93143 »

Oziphantom wrote:if you access the CPU regs or the Common RAM it goes at 1.8 but if you hit upper RAM or ROM it goes at 3.5 or 2.8
No.

Only the serial ports are XSlow (12 master clocks per byte, or 3 for φ1 and 9 for φ2). And you should never need to touch those unless you're using a nonstandard controller, or perhaps porting a NES game, because autopoll does it for you in the background.

All RAM in the system is Slow (φ2 = 5 master clocks), as is all ROM unless $420D is set to 1, in which case ROM in the upper half of the memory map ($8000-$FFFF in banks $80-$BF and $0000-$FFFF in banks $C0-$FF) is Fast (φ2 = 3 master clocks).

Internal CPU cycles (no bus access) and MMIO registers other than the controller ports are always Fast.

This is documented more precisely in Anomie's SNES Memory Mapping Doc:

Code: Select all

The 'Speed' column indicates the memory access speed for that area of memory.
The SNES master clock runs at about 21MHz (probably as close to 1.89e9/88 Hz as
possible). Internal operation CPU cycles always take 6 master cycles. Fast
memory access cycles also take 6 master cycles, Slow memory access cycles take
8 master cycles, and XSlow memory access cycles take 12 master cycles.


  Banks  |  Addresses  | Speed | Mapping
---------+-------------+-------+---------
 $00-$3F | $0000-$1FFF | Slow  | Address Bus A + /WRAM (mirror $7E:0000-$1FFF)
         | $2000-$20FF | Fast  | Address Bus A
         | $2100-$21FF | Fast  | Address Bus B
         | $2200-$3FFF | Fast  | Address Bus A
         | $4000-$41FF | XSlow | Internal CPU registers (see Note 1 below)
         | $4200-$43FF | Fast  | Internal CPU registers (see Note 1 below)
         | $4400-$5FFF | Fast  | Address Bus A
         | $6000-$7FFF | Slow  | Address Bus A
         | $8000-$FFFF | Slow  | Address Bus A + /CART
---------+-------------+-------+---------
 $40-$7D | $0000-$FFFF | Slow  | Address Bus A + /CART
---------+-------------+-------+---------
 $7E-$7F | $0000-$FFFF | Slow  | Address Bus A + /WRAM
---------+-------------+-------+---------
 $80-$BF | $0000-$1FFF | Slow  | Address Bus A + /WRAM (mirror $7E:0000-$1FFF)
         | $2000-$20FF | Fast  | Address Bus A
         | $2100-$21FF | Fast  | Address Bus B
         | $2200-$3FFF | Fast  | Address Bus A
         | $4000-$41FF | XSlow | Internal CPU registers (see Note 1 below)
         | $4200-$43FF | Fast  | Internal CPU registers (see Note 1 below)
         | $4400-$5FFF | Fast  | Address Bus A
         | $6000-$7FFF | Slow  | Address Bus A
         | $8000-$FFFF | Note2 | Address Bus A + /CART
---------+-------------+-------+---------
 $C0-$FF | $0000-$FFFF | Note2 | Address Bus A + /CART

Note 1: The address for internal CPU registers may go out Address Bus A,
  however the CPU ignores the data bus. It is unknown whether the data bus
  is ignored for the whole memory region, or just for those addresses which
  are actually registers. It is also unknown whether CPU writes show up on
  the data bus or not. Current theory is that addresses and writes will show
  up, but reads may or may not, and the data bus is only ignored for those
  bits of those registers actually mapped (e.g., data bus is ignored for only
  bit 7 of $4211).

Note 2: If bit 0 of CPU register $420d is set, the speed is Fast, otherwise
  it is Slow.
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: SNES clock change

Post by Oziphantom »

Nice doc thanks for the link.

Ah keeping Phi1 the same simplifies it a bit, nice trick ;) So the clocks are

Code: Select all

__    __    __    __    __    __    __    __
  |__|  |__|  |__|  |__|  |__|  |__|  |__|  |__| 3.5
  
_____    _____    _____    _____    _____    _____
     |__|     |__|     |__|     |__|     |__|     |__| 2.8
     
________    ________    ________    ________
        |__|        |__|        |__|        |__| 1.8
As we don't need to worry about 1.8 ;)

That still puts the 2.8 and 3.5 at odds every other cycle. But does the SNES keep the divides and switch or does it use have a loadable cycle counter so it doesn't need to stretch?
AWJ
Posts: 433
Joined: Mon Nov 10, 2008 3:09 pm

Re: SNES clock change

Post by AWJ »

Oziphantom wrote:Nice doc thanks for the link.

Ah keeping Phi1 the same simplifies it a bit, nice trick ;) So the clocks are

Code: Select all

__    __    __    __    __    __    __    __
  |__|  |__|  |__|  |__|  |__|  |__|  |__|  |__| 3.5
  
_____    _____    _____    _____    _____    _____
     |__|     |__|     |__|     |__|     |__|     |__| 2.8
     
________    ________    ________    ________
        |__|        |__|        |__|        |__| 1.8
As we don't need to worry about 1.8 ;)

That still puts the 2.8 and 3.5 at odds every other cycle. But does the SNES keep the divides and switch or does it use have a loadable cycle counter so it doesn't need to stretch?
The graph you've drawn is wrong, you've made φ2 6 clocks instead of 5. This is correct:

Code: Select all

__    __    __    __    __    __    __    __
  |__|  |__|  |__|  |__|  |__|  |__|  |__|  |__| 3.5
  
____    ____    ____    ____    ____    ____
    |__|    |__|    |__|    |__|    |__|    |__| 2.8
There's no penalty when switching between slow and fast cycles, which is what I think you're asking? Each cycle of a single instruction can be (and frequently is) a different speed, and you just add the cycle lengths up to get the total time. However, there is a synchronization penalty of 2-8 master clocks when switching between instruction execution (variable length) and DMA (always 8 clocks per byte).
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: SNES clock change

Post by Oziphantom »

Awesome thanks.

Mostly just to see if there was a slide here or there as they can sometimes be useful and others a total PIA, and also to figure out how they did it.
creaothceann
Posts: 611
Joined: Mon Jan 23, 2006 7:47 am
Location: Germany
Contact:

Re: SNES clock change

Post by creaothceann »

lidnariq wrote:In 6502 terms, the SNES's φ2 cycle is 3, 5, or 9 master clock cycles depending on the specific address accessed, while φ1 is always 3 master clock cycles.

(Ridiculous exception: DMA access is actually φ1=φ2=4 master clock cycles)
Do you know if the address bus value is set in cycle 1, cycle 2, or cycle 3?
Assuming it's not immediate then if it's already set in cycle 1, the 5A22 would have ~9 master clock cycles (or more in case of DMA) to decode the address and decide if it should extend the 65c816's cycle.

Code: Select all

+---------------+---------------+------------------+
| master clock  |    65c816     |       5A22       |
+-------+-------+-------+-------+------------------+
| cycle | phase | cycle | phase | address decoding |
+-------+-------+-------+-------+------------------+
|   1   |   1   |       |   1   |                  |
|       |   2   |       |   ?   |        ?         |
+-------+-------+       +-------+------------------+
|   2   |   1   |       |   ?   |        ?         |
|       |   2   |       |   ?   |        ?         |
+-------+-------+       +-------+------------------+
|   3   |   1   |       |   ?   |        ?         |
|       |   2   |       |   ?   |        ?         |
+-------+-------+       +-------+------------------+
|   4   |   1   |       |       |                  |
|       |   2   |       |       |                  |
+-------+-------+       |       |                  |
|   5   |   1   |       |       |                  |
|       |   2   |       |       |                  |
+-------+-------+       |       |                  |
|   6   |   1   |       |       |                  |
|       |   2   |       |       |                  |
+-------+-------+   1   |       |                  |
|   7   |   1   |       |       |                  |
|       |   2   |       |       |                  |
+-------+-------+       |       |                  |
|   8   |   1   |       |   2   |                  |
|       |   2   |       |       |                  |
+-------+-------+       |       |                  |
|   9   |   1   |       |       |                  |
|       |   2   |       |       |                  |
+-------+-------+       |       |                  |
|  10   |   1   |       |       |                  |
|       |   2   |       |       |                  |
+-------+-------+       |       |                  |
|  11   |   1   |       |       |                  |
|       |   2   |       |       |                  |
+-------+-------+       |       |                  |
|  12   |   1   |       |       |                  |
|       |   2   |       |       |                  |
+-------+-------+-------+-------+------------------+
Also, is there more low-level info like that written down anywhere?
My current setup:
Super Famicom ("2/1/3" SNS-CPU-GPM-02) → SCART → OSSC → StarTech USB3HDCAP → AmaRecTV 3.10
creaothceann
Posts: 611
Joined: Mon Jan 23, 2006 7:47 am
Location: Germany
Contact:

Re: SNES clock change

Post by creaothceann »

*bump*

Seems that the 65c816's PHI1 really takes 3 full master clock cycles.


I've also found some info about why the 65c816 might not have been clocked faster than ~3.58MHz: "REP and SEP had timing problems, possibly due to layout (rather than, say, logical design, or a pipelining mistake)". They "take 250ns to operate so you have to put a NOP after each one OR you have to stretch the clock [...] WDC has admitted that this is caused by very long signal lines".

250ns would be 4MHz; using 5 instead of 6 master clock cycles in the SNES would increase the CPU speed to 4.29{54}MHz.

"apparently another usenet post 'claims WDC fixed the REP/SEP timing issues in 1992'". I don't know when WDC switched to 14MHz - but the first games with the SA1 (10.74MHz) hit the shelves in 1995.
My current setup:
Super Famicom ("2/1/3" SNS-CPU-GPM-02) → SCART → OSSC → StarTech USB3HDCAP → AmaRecTV 3.10
Post Reply