                     _            _
  _ __  _ __  ___   (_) ___  ___ | |_
 | '_ \| '__|/ _ \  | |/ _ \/ __|| __|
 | |_) | |  | (_) | | |  __| (__ | |_
 | .__/|_|   \___/ _/ |\___|\___| \__|
 |_|              |__/ 
            dddddddd                    
            d::::::d                    
            d::::::d                    
            d::::::d                    
            d:::::d                     
    ddddddddd:::::d xxxxxxx      xxxxxxx
  dd::::::::::::::d  x:::::x    x:::::x 
 d::::::::::::::::d   x:::::x  x:::::x  
d:::::::ddddd:::::d    x:::::xx:::::x   
d::::::d    d:::::d     x::::::::::x    
d:::::d     d:::::d      x::::::::x     
d:::::d     d:::::d      x::::::::x     
d:::::d     d:::::d     x::::::::::x    
d::::::ddddd::::::dd   x:::::xx:::::x   
 d:::::::::::::::::d  x:::::x  x:::::x  
  d:::::::::ddd::::d x:::::x    x:::::x 
   ddddddddd   dddddxxxxxxx      xxxxxxx


Forbidden Four Multicart
A demonstration of how to create an MMC1 multicart containing three
NROM games and one MMC1 game

Animal Crossing Population Growing, a game for Nintendo GameCube,
contains several emulated NES games originally published by Nintendo.
Using the third-party Action Replay accessory, ROM hackers have found
the data for several games that are never unlocked in the normal
course of a run through ACPG. These four games are Mario Bros.,
Ice Climber, Super Mario Bros., and The Legend of Zelda, which
are called the "forbidden four" among Animal Crossing players.

Forbidden Four Multicart allows the user to put these games (or in
theory any other NES games) into a single ROM.


== How to build a ROM ==

  1. Put two NROM-128 games in iNES format named "bros.nes" and
     "ice.nes" in the same folder as "menu.nes".
  2. Put one NROM-256 game named "smb1.nes" in the same folder.
  3. Put The Legend of Zelda (or possibly other select games)
     named "loz.nes" in the same folder.
  4. Run "Build Multicart.bat".

The files "bros.nes", "ice.nes", "smb1.nes", and "loz.nes" are
NOT included.  If you ask me where to get NES ROMs, and I'm in
a bad mood, I just might report you to the anti-piracy police.

  
== Technical specifics ==

Forbidden Four is a multicart engine that can take any four
NES ROMs that fit the following criteria:
  * Any NROM-128 game, called "Bros"
  * A second NROM-128 game, called "Ice"
  * Any NROM-256 game, called "SMB1"
  * The Legend of Zelda, called "LoZ", or any other 1 Mbit
    SNROM game with the same init code

Two further restrictions: The NROM code must not write to ROM,
as this will trigger an unexpected bankswitch and possibly crash
the game.  The NROM-128 games also must not depend on values
read from the ROM mirror at $8000-$BFFF because this ROM mirror
does not exist in the multicart.

This SNROM has 256 KiB of PRG ROM, 8 KiB of CHR RAM, and 8 KiB of
battery-backed PRG RAM.  The ROM of any MMC1 based game is divided
into 16 KiB banks.  There are sixteen such banks in Forbidden Four:

 0  LoZ PRG 0
 1  LoZ PRG 1
 2  LoZ PRG 2
 3  LoZ PRG 3
 4  LoZ PRG 4
 5  LoZ PRG 5
 6  LoZ PRG 6
 7  LoZ PRG 7
 8  SMB1 PRG 0
 9  SMB1 PRG 1
10  Bros CHR and SMB1 CHR
11  Bros PRG
12  Ice CHR and menu CHR
13  Ice PRG
14  Menu PRG
15  LoZ PRG 7 (duplicate for vectors)

The last bank of LoZ PRG is duplicated because the game expects to
find it in both bank 7 and the MMC1's fixed bank.

The first 256 bytes of Menu contain
  1. a jump table with four entries,
  2. code to copy a CHR RAM loader and a jump table manager into
     CPU RAM at $0300, and
  3. the CHR RAM loader and jump table manager.

The four entries in the jump table specify which CHR page to load,
which PRG page to load, how to set up the memory mapping and the
mirroring, and where to put the program counter.

From the mapper init code of LoZ:

setMMC1CTRL = $FF98
setMMC1PRG = $FFAC
$FF76:A9 0F     LDA #$0F
$FF78:20 98 FF  JSR setMMC1CTRL
; Omitted code: set CHR bank to 0
$FF90:A9 07     LDA #$07
$FF92:20 AC FF  JSR setMMC1PRG
$FF95:4C 40 E4  JMP $E440

So in order to intercept Zelda's boot sequence, we need to change the
start bank and start address to point to our boot sequence at $8020,
and make sure it ends up at ctrl=$0F bank=$07 PC=$E440 by the time
Zelda starts.

$FF91: 0E
$FF96: 20
$FF97: 80

This passes control to the first 256 bytes of Menu, which sets up
CPU RAM and starts the menu using a mechanism similar to the jump
table.  This is done because the first 256 bytes of Menu are designed
to run from $8000-$80FF, so that LoZ can pass control to it, while
the rest of Menu runs from $C100-$FFFF, so that it can take over the
vertical blank NMI for display timing.

If you are building this on top of an SNROM base game other than
LoZ, you will need to change the addresses a bit in buildf4.c and
then use GCC to rebuild buildf4.exe.


== Legal ==

Forbidden Four Multicart
Copyright 2007 Damian Yerrick

This work is provided 'as-is', without any express or implied
warranty.  In no event will the authors be held liable for any
damages arising from the use of this work.

"Source" refers to the preferred form for making changes to a work.

Permission is granted to anyone to use this work for any purpose,
including commercial applications, and to alter it and redistribute
it freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must
     not claim that you wrote the original work. If you use this work
     in a product, an acknowledgment in the product documentation
     would be appreciated but is not required.
  2. Altered source versions must be plainly marked as such, and must
     not be misrepresented as being the original work.
  3. This notice may not be removed or altered from any source
     distribution.

