Need guidance with nes to snes. UPDATE: Port Complete of Mega Man IV + MSU-1

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
infidelity
Posts: 490
Joined: Fri Mar 01, 2013 4:46 am

Need guidance with nes to snes. UPDATE: Port Complete of Mega Man IV + MSU-1

Post by infidelity »

I'd like to start slow and attempt to port an NROM title to the snes. I know someone ported Super Mario Bros., but I'd like to do the same as that game being my first port. Before I learned of that, i was jotting down notes of what the nes ppu addresses are, and what the snes equivalents would be. EDIT - March 2021: Decided to port an mmc3 game, I decided not to do something that has already been ported.

My notes are kinda messy, but I wanted to know if my notes are correct, and if not could I please be given the correct equivalent(s)?

Thank you!

Code: Select all

NES PPU (bits from leftmost to rightmost)

SNES PPU (equivalent is " ... " if more than 1 bit is listed, look up address to see what each bit does)


$2000 PPUCTRL
8#: NMI
"8# in $4200"

4#: PPU Master/Slave 
"2# in $213E"

2#: Sprite Size
"E# in $2101"

1#: BG Pattern Table Address
"#F in $210B for BG1, F# in $210B for BG2"
"#F in $210C for BG3, F# in $210C for BG4"

#8: Sprite Pattern Table Address
"#7 in $2101"

#4: VRAM Increment (+1 across or +32 down)
"#3 in $2115"

#3: Base Nametable Address
"$2107-$210A is BG1-4
FC in $2107-$210A is tile map address 
#3 in $2107-$210A is screen size
00=32x32, 01=64x32, 10=32x64, 11=64x64"
END END END

$2001 PPUMASK
8#: Emphasize Blue
"8# in $2132"

4#: Emphasize Green
"4# in $2132"

2#: Emphasize Red
"2# in $2132"

1#: Show Sprites
"1#in $212C"

#8: Show BG
"#8 in $212C BG4"
"#4 in $212C BG3"
"#2 in $212C BG2"
"#1 in $212C BG1"

#4: Show Sprites Leftmost 8 Pixels
"NOT USED?"

#2: Show BG Leftmost 8 Pixels
"NOT USED?"

#1: Greyscale
"NOT USED?"
END END END

$2002 PPUSTATUS 
("for read only, use $213E and $213F
if nes does AD0220, for snes use AD3E21 AD3F21")
8#: vBlank
"8# in $4212"

4#: Sprite 0 Hit
"NOT USED?"

2#: Sprite Overflow
"NOT USED?"

1F: Least Significant Bits
"NOT USED?"
END END END 

$2003 OAMADDR
"$2102 x2"
END END END

$2004 OAMDATA
"$2104"
END END END

$2005 PPUSCROLL x2
"$210D-$2114 x2, for all 4 BG's"
END END END

$2006 PPUADDR x2
"OAM $2102 $2103"
"VRAM $2016 $2017"
"CGRAM $2121"
END END END

$2007 PPUDATA
"OAM $2104"
"VRAM $2118 $2119"
"CGRAM $2122"
END END END

$4014 OAMDMA
"???"
END END END
Last edited by infidelity on Tue Dec 21, 2021 4:45 am, edited 4 times in total.
Myself086
Posts: 158
Joined: Sat Nov 10, 2018 2:49 pm

Re: Need guidance with nes to snes.

Post by Myself086 »

I am working on a NES emulator for SNES.

Here are some additional notes for you:
- Sprite size 8x16 is not found on the SNES and has to be 2x 8x8. SNES supports 128 sprites on screen instead of 64 so it isn't a major problem.
- Sprite pattern table can't be swapped since the second table is a limited offset from the first. My emulator does the swap during transfer instead of by hardware.
- $2000.0 and $2000.1 should be scroll values bit 8.
- Sprite overflow can be found at $213E.6 and $213E.7 but the limit is 32 objects or 34 tiles per scanline instead of 8.
- Showing leftmost 8 pixels can be done by using windows and has more options than on NES.
- OAM DMA can be done on SNES but requires more settings. The OAM data itself is a bit different. Byte order is X,Y,T,A instead of Y,T,A,X and A is different enough that I use a lookup table.
- While sprite zero hit is not supported by SNES, I was able to emulate it. You can use alternatives like IRQ or HDMA to achieve the desired result.
93143
Posts: 1715
Joined: Fri Jul 04, 2014 9:31 pm

Re: Need guidance with nes to snes.

Post by 93143 »

Myself086 wrote: Mon Feb 22, 2021 9:08 am- Sprite pattern table can't be swapped since the second table is a limited offset from the first.
Doesn't it wrap? The address formula given here does & 0x7fff to the result, which implies that it does. Max offset is 24 KB (or 32 if you include the size of table 0), so you should be able to put table 0 halfway up VRAM and table 1 at the bottom.
infidelity
Posts: 490
Joined: Fri Mar 01, 2013 4:46 am

Re: Need guidance with nes to snes.

Post by infidelity »

Myself086 wrote: Mon Feb 22, 2021 9:08 am - $2000.0 and $2000.1 should be scroll values bit 8.
I'm confused by this remark. Is this in regards to NES or SNES?

And thank you for the additional notes.
User avatar
dougeff
Posts: 3078
Joined: Fri May 08, 2015 7:17 pm

Re: Need guidance with nes to snes.

Post by dougeff »

The graphics (CHR ROM) is a different format from NES to SNES, and you have to load it manually to the VRAM on the SNES.

In YYCHR, you can convert fro NES to SNES, by loading the CHR in NES mode, select all, copy, change to SNES 2bpp (might be called GB or Gameboy 2bpp), then paste, then save the file.

You probably want Mode 0. That's 4 colors per tile. All those BG are 2bpp.

Sprites, however, are always 4bpp. You would have to convert the Sprite CHRROM to 4bpp SNES format.
nesdoug.com -- blog/tutorial on programming for the NES
93143
Posts: 1715
Joined: Fri Jul 04, 2014 9:31 pm

Re: Need guidance with nes to snes.

Post by 93143 »

dougeff wrote: Mon Feb 22, 2021 12:19 pmYou would have to convert the Sprite CHRROM to 4bpp SNES format.
You can set DMA to write repeatedly to only half of the 16-bit VRAM data port, and you can set the VRAM port to increment the VRAM word address after a write to either byte. This means you can easily DMA to half the bitplanes in a tileset.

With a 4bpp destination format, the source data format implied by this procedure is exactly NES format. In fact, it might be advantageous to simply leave the BG graphics in NES format too and use Mode 1...

The only disadvantage I can see is that the palette ends up non-contiguous and spread over about four times the area in CGRAM, which wastes a small amount of VBlank when you change it. But changing out more than about a dozen sprite tiles at 4bpp instead of 2bpp would waste more time than rewriting the entire palette.
Pokun
Posts: 2675
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Need guidance with nes to snes.

Post by Pokun »

#4: Show Sprites Leftmost 8 Pixels
"NOT USED?"

#2: Show BG Leftmost 8 Pixels
"NOT USED?"

#1: Greyscale
"NOT USED?"

4#: Sprite 0 Hit
"NOT USED?"

2#: Sprite Overflow
"NOT USED?"
The leftmost 8 pixels are always shown for sprites on the SNES. The SNES solves the problem that sprites can't be partly displayed on the left edge of the screen (as X=0 wraps to X=255 when decrementing an 8-bit X-coordinate) by giving sprites a 9th X-coordinate bit. So there is like an entire extra virtual screen of sprite space horizontally to the visible screen, more than enough to let sprites smoothly slide off the screen at the left edge. It can also be used to hide sprites of any size on (by setting X=257, don't set to X=256 as that counts toward the sprites/scanline limit while hiding the sprite).

The BG can be clipped using the Window function, which allows much more advanced clipping of any part of the screen, instead of just the left edge like the NES PPU do.
The SNES has the option to limit the screen height to 224 lines instead of 240 lines, which does mask the bottom lines for both sprites and backgrounds. This also increases vblank time with as many lines, but if you are porting a NES game you probably want the 239-line mode.

I don't think there is a greyscale mode on the SNES, unless I forgot or overlooked it. You have to change the palette manually.

Sprite 0 is not special on the SNES. HDMA is used for raster effects instead, and since you have so many background layers there is less need to split the screen anyway. Usually the status bar is made using BG3 as a HUD, while BG1 and BG2 are for the play field and a parallax background respectively (background mode 1 is normally used for this, but since you are porting a NES game mode 0 probably makes more sense). Bit 3 of $2105 is used to give extra priority to BG3, overriding other priority settings so that it can be used as an overlaying HUD.

Sprite limits are now 128 sprites/frame, 32 sprites/scanline and also 34 8x8 sprite patterns per scanline. 33 sprites or more on a scanline triggers the "33's Range Over" flag and 35 8x8 sprite patterns or more on the same scanline triggers the "35's Time Over" flag. These flags are bit 6 and 7 of $213E respectively. Unlike the NES PPU's Sprite Overflow flag, these flags actually work like they should AFAIK.
As I said before, hidden sprites with X-coordinate 257 or higher do not count towards the scanline limits (I'm not sure about sprites that has an X-coordinate so high that they show up on the left edge though).


Other new features:
DMA can now not only be used for OAM, but also for VRAM, CGRAM and WRAM. There's also HDMA which can do things line per line.

Sprite multiplexing can now be done in hardware, so you don't need to cycle the OAM like on the NES to increase the sprites/scanline limit. This is called Priority Order Rotation and done with bit 7 of $2103. Many games don't see to bother with this though, as sprite dropout is less common than on the NES due to more generous sprite limitations. This can be seen in some games like Assault Suits Valken when there are lots of bullets on screen so that the portrait faces in dialogue are missing sprite parts.
If you are porting a NES game you probably don't need to bother with sprite multiplexing at all, and must find another solution if the game is using the NES 8 sprites/scanline limit for partly clipping sprites.
Last edited by Pokun on Wed Feb 24, 2021 5:27 pm, edited 1 time in total.
Myself086
Posts: 158
Joined: Sat Nov 10, 2018 2:49 pm

Re: Need guidance with nes to snes.

Post by Myself086 »

93143 wrote: Mon Feb 22, 2021 11:12 am
Myself086 wrote: Mon Feb 22, 2021 9:08 am- Sprite pattern table can't be swapped since the second table is a limited offset from the first.
Doesn't it wrap? The address formula given here does & 0x7fff to the result, which implies that it does. Max offset is 24 KB (or 32 if you include the size of table 0), so you should be able to put table 0 halfway up VRAM and table 1 at the bottom.
The gap between table 0 and table 1 is decided by 2 bits multiplied by 4K-word, meaning that you can only reach 16K-word instead of the 24K-word that you need for recreating the table swap.
infidelity wrote: Mon Feb 22, 2021 11:51 am
Myself086 wrote: Mon Feb 22, 2021 9:08 am - $2000.0 and $2000.1 should be scroll values bit 8.
I'm confused by this remark. Is this in regards to NES or SNES?

And thank you for the additional notes.
These 2 bits on NES represent scroll value bit 8 on SNES. The name tables are fixed on NES but in your notes reference changing the base address of the name tables on SNES which isn't the same as the bottom 2 bits of $2000 on NES.
93143
Posts: 1715
Joined: Fri Jul 04, 2014 9:31 pm

Re: Need guidance with nes to snes.

Post by 93143 »

Myself086 wrote: Mon Feb 22, 2021 3:25 pm
93143 wrote: Mon Feb 22, 2021 11:12 am Doesn't it wrap? The address formula given here does & 0x7fff to the result, which implies that it does. Max offset is 24 KB (or 32 if you include the size of table 0), so you should be able to put table 0 halfway up VRAM and table 1 at the bottom.
The gap between table 0 and table 1 is decided by 2 bits multiplied by 4K-word, meaning that you can only reach 16K-word instead of the 24K-word that you need for recreating the table swap.
What do you mean by swap? My idea was this (all addresses word):

1) OBSEL = sss11000 -> base = $0000, offset $3000 -> table 1 at $0000, table 2 at $1000+$3000 = $4000

2) OBSEL = sss11010 -> base = $4000, offset $3000 -> table 1 at $4000, table 2 at $5000+$3000 = $8000 = $0000
infidelity
Posts: 490
Joined: Fri Mar 01, 2013 4:46 am

Re: Need guidance with nes to snes.

Post by infidelity »

@Myself086, I see what you're saying regarding $2000. I always went by those bits as, $2000, $2400, $2800, $2C00 for nes Nametable selection. But I understand and agree that what its doing is moving the scan line that many lines instantaneously. So thank you for clearing that up for me.
infidelity
Posts: 490
Joined: Fri Mar 01, 2013 4:46 am

Re: Need guidance with nes to snes.

Post by infidelity »

I'm not sure if I have the nes ppu rendering ($2001.4 $2001.3) equivalents correct in my notes. Would someone take a look and see if that is correct? I'm worried the equivalent i have listed is just simply turning off the SNES bg layers visually, and not actually turning them off so that the snes can draw huge swaths of gfx to those BG layers.
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Need guidance with nes to snes.

Post by tepples »

The equivalent to turning everything off is writing a negative value ($80-$FF) to brightness ($2100).
turboxray
Posts: 348
Joined: Thu Oct 31, 2019 12:56 am

Re: Need guidance with nes to snes.

Post by turboxray »

tepples wrote: Wed Feb 24, 2021 8:22 am The equivalent to turning everything off is writing a negative value ($80-$FF) to brightness ($2100).
That wouldn't be the same if you needed full vram bandwidth for an entire screen length (or more) with the rendering turned off.
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Need guidance with nes to snes.

Post by tepples »

On Super NES, setting brightness to negative turns rendering off (also called "forced blanking"). I'm not sure I understand what you mean.
infidelity
Posts: 490
Joined: Fri Mar 01, 2013 4:46 am

Re: Need guidance with nes to snes.

Post by infidelity »

tepples wrote: Wed Feb 24, 2021 8:22 am The equivalent to turning everything off is writing a negative value ($80-$FF) to brightness ($2100).
Thank you, just updated my notes.
Post Reply