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

ShadowOne333
Posts: 12
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: 240
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: 397
Joined: Wed Sep 07, 2005 9:55 am
Location: Phoenix, AZ
Contact:

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: 12
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!

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

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

Post by never-obsolete » Sun Sep 20, 2020 1:43 pm

ShadowOne333 wrote:
Mon Sep 14, 2020 1:32 pm
How did you manage to get around the column/tile limitation of the original?
I hacked in my own map loader that did away with the original format and allows for each screen to be completely unique. I had also began working on doing the same for enemy placement, but never finished it.

old zip file removed
. That's just like, your opinion, man .

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

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

Post by never-obsolete » Fri Oct 09, 2020 8:25 pm

I was asked how to build this:

You need the US version with a crc32 of 0x3FE272FB, an xdelta patcher, and asm6n.

The new zip has an xdelta patch included that expands the rom and changes it to FME7, and a batch file will apply the patch and then assemble the hack. TOOLPATH in Makefile.bat will need to be changed before running.
Attachments
loz-dx.zip
(229.95 KiB) Downloaded 73 times
. That's just like, your opinion, man .

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

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

Post by ShadowOne333 » Fri Nov 06, 2020 7:39 pm

never-obsolete wrote:
Fri Oct 09, 2020 8:25 pm
Thanks for sharing that!
I'll give it a good look and see what I can gather of it.

----------------------------------------------------------------------

As a side question.
From what I know, Zelda 1 seems to be using CHR-RAM.

I was wondering, how feasible is it to achieve the animated water tiles for Zelda by using the original mapper of CHR-RAM?
How difficult would that be?

And if not, would it be feasible by changing it to CHR-ROM and doing bank switching instead?
I want to avoid changing mapper if possible, so that it can still be played with the same hardware as the original Zelda 1.

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

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

Post by ShadowOne333 » Fri Dec 18, 2020 4:37 pm

I'm bumping this thread to bring it up to the current status.
Romhacking.net's user @Bogaa worked over the MMC5 disassembly I did some months ago, and managed to get bank swapping working to make overworld animation possible.

The only downside of this, is that the Automap hack by snarfblam isn't fully working at the moment.
The only thing missing for Automap to fully work with MMC5 is for the minimap tiles of Automap to be updated properly.

The whole source of the MMC5 conversion (and Redux alongside it) can be found here:
https://www.romhacking.net/forum/index. ... #msg405878

Once the Automap stuff is fixed, it should be a fully compatible version of Zelda 1 with MMC5 bank swapping working for Overworld (Dungeon graphics aren't animated, as I have no use for it, but should be doable as well).

frantik
Posts: 370
Joined: Tue Mar 03, 2009 3:56 pm

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

Post by frantik » Sat Dec 19, 2020 12:38 pm

if you just needed to add animation, you could have kept the mapper on MMC1

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

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

Post by ShadowOne333 » Sat Dec 19, 2020 8:45 pm

frantik wrote:
Sat Dec 19, 2020 12:38 pm
if you just needed to add animation, you could have kept the mapper on MMC1
How could it be done?
I read something about tile transfers to PPU/RAM, but limited to only two 16x16 tiles, and I needed around 4 to 6 I believe.

frantik
Posts: 370
Joined: Tue Mar 03, 2009 3:56 pm

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

Post by frantik » Sat Dec 19, 2020 10:27 pm

With MMC1 you can change the entire CHR bank at once. You will end up with a lot of duplicate tiles but it allows you to animate any tile you like

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

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

Post by Fiskbit » Sat Dec 19, 2020 11:10 pm

Zelda 1 uses 8 KB of CHR-RAM, not CHR-ROM, so it'd have to be converted to CHR-ROM to allow the swapping necessary for this (though I don't know if there's anything aside from emulator compatibility that would prevent you from having bankable CHR-RAM on MMC1). CHR-ROM, though, doesn't seem very compatible with the automap hack, which fills the map into CHR-RAM as you explore the world. The problem is that it does 4 screens per tile, so you can't just update the nametables to use the proper tile as you explore.

I guess you could use CHR-ROM, have all the permutations of the various tiles in each row of the map, and use a scanline timer to swap banks every row of minimap tiles so you can fit everything. Still not ideal, though.

I don't know what the MMC5 solution is that was settled on, but I'm disappointed to see yet another hack using MMC5 instead of MMC3, since repro'ers end up buying up tons of the small selection of MMC5 carts to harvest parts from them to make physical copies of these hacks. Very few hacks actually need the unique features of MMC5. MMC3, meanwhile, has modern clones and doesn't require destroying games.

lidnariq
Posts: 10104
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

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

Post by lidnariq » Sat Dec 19, 2020 11:12 pm

Fiskbit wrote:
Sat Dec 19, 2020 11:10 pm
(I don't know if there's anything aside from emulator compatibility that would prevent you from having bankable CHR-RAM on MMC1).
Nope, that's it. As far as I can tell every hardware mapper should support CHR RAM in lieu of CHR ROM.

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

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

Post by ShadowOne333 » Sun Dec 20, 2020 3:31 pm

Yep, as @Fiskbit mentions, Zelda 1 uses CHR-RAM, not CHR-ROM.
Doing bank swaps was possible in Zelda 2 because that game uses CHR-ROM, but Zelda 1 is CHR-RAM only.

I did do some CHR-RAM -> CHR-ROM tests around last month only for a couple days, and I was able to convert the ROM to CHR-ROM and have the title screen and file selection working with the conversion, but I didn't follow through to try to make overworld and the specific graphics load with CHR-ROM, as I lack any kind of knowledge of proper mapping stuff for NES.

As for the reason of the conversion to MMC5, well it was something already being worked on by another user, bogaa, and he did finish the whole conversion up with working bank swaps and all, so I couldn't really pass on to that. Though, I do agree that for reproduction purposes, harvesting real NES MMC5 cartridges could be a big no-no.

I still have the MMC3 conversion by Infidelity completely disassembled by me available in my GitHub repo for the project:
https://github.com/ShadowOne333/The-Leg ... e/MMC3.asm

it works 100% with no issues. The only problem would be to create the bank swapping stuff properly for the overworld for MMC3, and also make Automap working for MMC3.
Automap disassembly is also available in that repo:
https://github.com/ShadowOne333/The-Leg ... utomap.asm

For a different apprpoach, what would be required to make the shift from CHR-RAM to CHR-ROM properly?

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

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

Post by Fiskbit » Mon Dec 21, 2020 1:05 am

I spent about 4 hours putting together a proof of concept using MMC1 and 32 KB of CHR-RAM, currently just animating the waterfall. It targets PRG0 (PRG1 will likely require changing some addresses). It uses 4 KB CHR mode and swaps the entire background table at once (between banks 1-4). The automap will theoretically work with it, but they may have conflicts that need to be resolved, and the automap graphics will have to be drawn into all 4 banks, which may be a pain when doing a scroll. I leave further work as an exercise to the reader. I'm maybe half confident the code is bug-free, but make no promises or guarantees. Anyone is free to use this code for any purpose, commercial or otherwise. I've included the targeted assembler, snarfblasm; I believe this is the version we use for Z1M1. Usage is "snarfblasm.exe animate.asm".

Edit: One thing that could prove to be an issue in the code as-is is the location I hijacked to do the bankswapping. It's actually further into rendering than I expected, though it does seem to only ever happen in the HUD. Might be best to do that earlier and with an explicit mode and pause check. It's not a problem now, but could be a pain depending on how you do the automap or how much code you add before the current swap.
Attachments
Zelda MMC1 Animation.zip
(50.86 KiB) Downloaded 32 times

Post Reply