Overworld graphics bank swap to Zelda 1 MMC3 conversion?

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

Post Reply
ShadowOne333
Posts: 2
Joined: Fri Sep 11, 2020 10:38 am

Overworld graphics bank swap to Zelda 1 MMC3 conversion?

Post by ShadowOne333 » Fri Sep 11, 2020 11:58 am

Good day, everyone.
First of all, pardon me if this is the wrong place to post this thread, please move it appropriately if it's in the wrong place.

I've been working on a Zelda 1 hack for quite some time already, called Zelda 1 Redux:
https://www.romhacking.net/forum/index.php?topic=29403

Right now, I'm almost in the finishing touches of the game.
There's only 3 points left to be done to finish the hack, and one of those 3 points is being able to make animated tiles for water in the overworld.
From what I know and researched, the best way to tackle this would be to make a mapper conversion of Zelda 1 from MMC1 to somthing like MMC3 or MMC5.

I have disassembled infidelity's MMC3 conversion of Zelda 1, which can be seen here (alongside the rest of the code for the project):
https://github.com/ShadowOne333/The-Leg ... e/MMC3.asm

If you compile that MMC3.asm file directly into a clean Zelda 1 ROM, it works just fine and it loads as a MMC3 ROM.
However, the one thing that's missing is basic bank switching support for the graphics.

This is where I am stuck, as I have no clue as to how to accomplish such a thing.
I already have the graphics separated properly, and I'll I'm seeking is a way to make a new Overworld background graphics bank that gets swapped every second or so.

From what I gathered about the Overworld graphics, I seem to have found the pointers, which apparently load the Overworld background graphics themselves, as well as the routine that handles it:

Code: Select all

C091: AD 1D05  LDA $051D
C094: 0A       ASL
C095: AA       TAX
C096: BD 2C80  LDA $802C,X
C099: 85 00    STA $00
C09B: BD 3880  LDA $8038,X
C09E: 85 02    STA $02
C0A0: E8       INX
C0A1: BD 2C80  LDA $802C,X
C0A4: 85 01    STA $01
C0A6: BD 3880  LDA $8038,X
C0A9: 85 03    STA $03
C0AB: 60       RTS
For reference, this is what's at $802C (or $C02C)

Code: Select all

3B89 -> C93B    Overworld Background
5B91 -> D15B    Overworld Sprites
I feel like I'm close, but my complete ignorance about MMC3 and the bank swapping really puts me to a stop.
Which is why I wanted to ask for help in here.
If anyone could please help with making the bank switching for the overworld background sprites, I'd be really grateful!
This is one of the very last things to do so I can make a proper release of the hack.

And if it's possible to do the same for Dungeon graphics, that'd be a plus :P
Thanks in advance to anyone who jumps in to help with this!

The disassembly by Trax for Zelda 1 could help as well:
http://www.bwass.org/romhack/zelda1/zelda1bank3.txt

Fiskbit
Posts: 153
Joined: Sat Nov 18, 2017 9:15 pm

Re: Overworld graphics bank swap to Zelda 1 MMC3 conversion?

Post by Fiskbit » Fri Sep 11, 2020 3:43 pm

Don't choose MMC5. MMC3 does what you need and new MMC3 clone hardware is being made today.

You just need to write to the appropriate MMC3 registers to do a CHR bankswap. Registers are documented on the wiki page here: https://wiki.nesdev.com/w/index.php/MMC3. You write to the bank select register at $8000 where the low 3 bits select which CHR bank you want to swap. The other bits should match what is normally written to $8000 elsewhere in the MMC3 hack; I expect bit 6 to be 0, and it looks in that disassembly like bit 7 is 1. Whether the background table (on the right) is swapped in 64 or 128 tile chunks depends on what the MMC3 hack has chosen for bit 7, with 1 making the right table swap in 128 tile (2KB) chunks. Then you write the bank number you're swapping in to $8001. That's it.

To time it, you can use the game's frame counter, located at $15. To time it to approximately a second, check for where the bottom 6 bits are 0.

Code: Select all

LDA $15
AND #$3F
BNE +
LDA #your_bank_select_value
STA $8000
LDA your_target_bank
STA $8001
+

User avatar
never-obsolete
Posts: 380
Joined: Wed Sep 07, 2005 9:55 am
Location: Phoenix, AZ

Re: Overworld graphics bank swap to Zelda 1 MMC3 conversion?

Post by never-obsolete » Fri Sep 11, 2020 6:38 pm

If you want to dig around the code, I can send you the source to this. It uses FME-7 instead of MMC3, but the idea should be the same.

A warning, the code is a cluster f*** of hacks upon hacks.
. That's just like, your opinion, man .

ShadowOne333
Posts: 2
Joined: Fri Sep 11, 2020 10:38 am

Re: Overworld graphics bank swap to Zelda 1 MMC3 conversion?

Post by ShadowOne333 » Mon Sep 14, 2020 1:32 pm

Fiskbit wrote:
Fri Sep 11, 2020 3:43 pm
Don't choose MMC5. MMC3 does what you need and new MMC3 clone hardware is being made today.

You just need to write to the appropriate MMC3 registers to do a CHR bankswap. Registers are documented on the wiki page here: https://wiki.nesdev.com/w/index.php/MMC3. You write to the bank select register at $8000 where the low 3 bits select which CHR bank you want to swap. The other bits should match what is normally written to $8000 elsewhere in the MMC3 hack; I expect bit 6 to be 0, and it looks in that disassembly like bit 7 is 1. Whether the background table (on the right) is swapped in 64 or 128 tile chunks depends on what the MMC3 hack has chosen for bit 7, with 1 making the right table swap in 128 tile (2KB) chunks. Then you write the bank number you're swapping in to $8001. That's it.

To time it, you can use the game's frame counter, located at $15. To time it to approximately a second, check for where the bottom 6 bits are 0.

-snip-
Interesting.
I also forgot to post Infidelity's documentation about his MMC3 conversion:
https://www.romhacking.net/hacks/nes/pa ... readme.txt

He mentions that the bank swap routines are located $BFAC of each of the corresponding banks.
So 3FAC, 7FAC, etc...
I'm not sure what exactly the routines there are doing right now, but the corresponding part for the MMC3 disassembly would start here for bank 3:
https://github.com/ShadowOne333/The-Leg ... 3.asm#L214

Code: Select all

org $BFAC	// 0x0FFBC
	asl
	pha
	lda.b #$86
	sta.w $8000
	pla
	sta.w $8001
	ora.b #$01
	pha
	lda.b #$87
	sta.w $8000
	pla
	sta.w $8001
	rts
	sta.w $0302
	lda.b #$01
	sta.w $A000
	rts
Does that mean that I'd only need to modify that routine and add the stuff you mention?

Also, I wanted to ask 2 things regarding bank swapping:

1) When doing bank swapping, do I need to move the ENTIRETY of, let's say, bank 3 into another bank? Or can I just move a certain section and be that section the one that swaps? As I only seek to swap the graphics each second or so, not the entire bank.
2) By implementing the MMC3 hack into my hack, I ran into the problem that the little free space I had in bank 7 (around FFC0) is already taken up by another hack (Automap by Snarfblam). So my question here would be, what can I do here to make space for both the original Automap hack and also add the MMC3 hack into there?
never-obsolete wrote:
Fri Sep 11, 2020 6:38 pm
If you want to dig around the code, I can send you the source to this. It uses FME-7 instead of MMC3, but the idea should be the same.

A warning, the code is a cluster f*** of hacks upon hacks.
Oh wow!
That hack looks like quite great! Like a full proper revamp of Zelda 1, animations and all!
Fantastic work there. How did you manage to get around the column/tile limitation of the original?

And sure! If you are willing to share the code or part of it to set the example, that'd be neat, thanks!

Post Reply