SNES and relocations

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 and relocations

Post by Oziphantom »

In most machines where you can change the Z/B/DP and Stack they put them into their own Address muxing so they always hit RAM. Does the SNES have any logic to keep DP/Stack in RAM. Or does it just map them to whatever is normally at/not at the address?
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: SNES and relocations

Post by tepples »

There is no such logic.

Direct page and stack are always in bank 0. They can be pointed at B bus I/O ($2100), memory controller I/O ($4200 and $4300), or ROM ($8000-$FFFF). There are even special cases where it's useful to point direct page at the DMA controller ($4300) or the PPU ($2100) momentarily. But usually they're pointed somewhere in $0000-$1FFF, which mirrors the first 8 KIB of RAM at $7E0000-$7E1FFF.
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: SNES and relocations

Post by Oziphantom »

Thanks.

One hand Yay faster Register pumps. Other hand boo only 8K for relocating the DP into... and no access to the full 64K..
User avatar
koitsu
Posts: 4201
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: SNES and relocations

Post by koitsu »

Oziphantom wrote:One hand Yay faster Register pumps. Other hand boo only 8K for relocating the DP into... and no access to the full 64K..
I'm not sure I understand this statement.

You can relocate D (direct page) base anywhere within bank $00. Addresses past $FFFF will wrap back around to $0000 within the same bank. Several games do in fact set D to something other than $0000, and tepples gave some examples of non-$0000 D values that are used (particularly the base addresses of SNES memory-mapped registers).

tepples was simply telling you that the SNES's memory map contains RAM at $0000-1FFF in bank $00. That's completely independent of the D register's location/value. If you don't like it, you can invent a time machine to go back in time and visit Nintendo Co. Ltd's headquarters prior to the SNES's design and tell them to do it differently -- or alternately, go back in time and tell Bill Mench that D should be a 24-bit register.

You can access a full linear 128KB of RAM (banks $7E through $7F) using 24-bit long addressing, or by changing B and using 16-bit addressing. That's all the RAM the system has. $7E0000-7E1FFF is a mirror of $000000-001FFF (or maybe the other way around; doesn't matter, it's functionally the same).
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: SNES and relocations

Post by Oziphantom »

Registers = PPU, DMA controller etc registers.
So if you put the DP into 21XX then any read/write to 21XX is faster as its a DP not ABS16
thus Faster Register Pumps

While you can get the full 128K with 7E/7FXXXX you can only see 8K within the Normal banking and you can only move DP or SP in the lower 8K. If you could move them above $2000 and it was mapped to RAM you could use it as a fast window into the first 64K also giving you 256 DPages. Also if it was RAM mapped, you could say put the DP into some open bus area, say $3000 for example, and then put the Stack at $3100 to which you then get a full 8K + DP + Stack in 16ABS basically giving you 512 bytes back in the "mapped" RAM.
Thus limited to 8K and no access to the full 64K for relocation.
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: SNES and relocations

Post by lidnariq »

... but only the stack and direct page are forced to be from bank 0? Everything else is either an absolute long address, from the K bank, or from the B bank.

I mean, not that more RAM isn't better, but I don't think the resource contention you describe exists...?
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: SNES and relocations

Post by Oziphantom »

You can only get the Stack or DP into the first 8K right? It is limited to 8K ?
User avatar
koitsu
Posts: 4201
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: SNES and relocations

Post by koitsu »

You're either being pedantic over wording, intentionally difficult, or there's a language barrier. I can't decide which.

This has nothing to do with the 65816's direct page or stack. You can move those around TO ANY ADDRESS within bank $00. Nothing stops you from doing rep #$30 / ldx #$1234 / txs / lda #$FFF0 / tcd -- sticking the stack in the middle of the RAM region, and sticking direct page in ROM in the vector area. Is it practical/helpful? Probably not. But nothing stops you from doing it. CPU will do what you tell it.

Said "8K limit" (your phrasing) -- that is, the only RAM in bank $00 being between $0000-1FFFF -- is a result of the SNES memory map, not something specific to the 65816, direct page, or the stack. Here is mode 20 and mode 21, and here is mode 25.

I'm going to repeat myself one more time, and that's it: the "8K limit" (your phrasing) is a result of the SNES memory map, i.e. Nintendo's choice, and has nothing to do with the CPU (re: direct page, stack, etc.). You can move D and S around wherever you want in bank $00.

If you want to access the 128KB of RAM in banks $7E and $7F, you either a) switch banks by changing the B or DB register (which term varies per person; i.e. phb/plb) and use 16-bit addressing, b) use 24-bit long addressing, c) use a cartridge that has SRAM on it and mode 21 (the first 8KB of SRAM will be mapped in bank $00 from $6000-7FFF, in addition to normal console RAM being at $0000-1FFF -- i.e. you now have 16KB of RAM to play with and can lda #$6000 / tcd or lda #$0000 / tcd to your heart's content), or d) invent a time machine and lecture Nintendo. Those are your options. :-)
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: SNES and relocations

Post by Oziphantom »

SNES and relocations
At no point have I said 65816, and yes you can move the DP and SP into any address in the first 64K of Address space as seen by a 65816( and by a SNES ) . I'm not talking about a 65816 I'm talking about a SNES, and I'm talking about RAM and Direct Page + Stack Page. So to be fully clear. the DP and SP on a SNES can only be moved such that it is capable of seeing 8K of RAM, that RAM being 00:0000 to 00:1FFF, to which this places an 8K limit on the amount of RAM you can make the DP or SP occupy. Yes you can put the DP into ROM, which has some uses, and you can put the SP into ROM which is totally useless, but that is ROM. You can also put it into open bus, totally useless in all instances, again not RAM, you can put it into Memory mapped I/O which in the case of DP has some uses, and SP probably not, I can't think of any case where you want to read a bunch of sequential addresses quickly... maybe for transferring a full Mul A B and result.. but anyway I hope me be pedantic about RAM is now clear.

It is also worth mentioned that Tepples's answered my question completely with first line.

The SNES docs I have ( SNES BOOK 1 ) shows RAM in 70:XXXX-7D:XXXX or 30:XXXX-3F:XXXX none of them show SRAM as visible in bank 00. Is this an omission from the docs?
creaothceann
Posts: 611
Joined: Mon Jan 23, 2006 7:47 am
Location: Germany
Contact:

Re: SNES and relocations

Post by creaothceann »

SRAM is in the cartridge's address regions.

http://folk.uio.no/sigurdkn/snes/memmap.txt
My current setup:
Super Famicom ("2/1/3" SNS-CPU-GPM-02) → SCART → OSSC → StarTech USB3HDCAP → AmaRecTV 3.10
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: SNES and relocations

Post by Oziphantom »

So basically wherever the Cart puts it?
User avatar
koitsu
Posts: 4201
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: SNES and relocations

Post by koitsu »

Oziphantom wrote:The SNES docs I have ( SNES BOOK 1 ) shows RAM in 70:XXXX-7D:XXXX or 30:XXXX-3F:XXXX none of them show SRAM as visible in bank 00. Is this an omission from the docs?
Sorry I'm incorrect -- SRAM does not reside in bank $00 in mode 21. Nintendo used similar crosshatching line patterns between SRAM and DSP, and when viewed at small resolutions, they look similar. My previous statement/option (c) is false, and for that I apologise.

Most of the online SNES memory map documents I've seen, barring official, all vary greatly in layout, style, and overall presentation of the information. Half are written by hardware-focused people, the other half are just bizarre; none seem to be written with programmers in mind. This has resulted in literally decades of confusion. As such, please refer to pages 1-2-24 through 1-2-35, and pages 2-21-1 through 2-21-5, in the official documentation. The different SNES memory modes (20, 21, 25), which the cartridge is responsible for (they're different PCB designs -- you'll see this denoted in pages 1-2-24 to 1-2-35), are ultimately what define large portions of the memory map.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: SNES and relocations

Post by tepples »

tl;dr: A cart could put RAM in $006000-$007FFF. But no Super NES carts made by Nintendo did so.
creaothceann
Posts: 611
Joined: Mon Jan 23, 2006 7:47 am
Location: Germany
Contact:

Re: SNES and relocations

Post by creaothceann »

tepples wrote:tl;dr: A cart could put RAM in $006000-$007FFF. But no Super NES carts made by Nintendo did so.
Well, technically some did...
My current setup:
Super Famicom ("2/1/3" SNS-CPU-GPM-02) → SCART → OSSC → StarTech USB3HDCAP → AmaRecTV 3.10
Post Reply