map015.c
  1  /*
  2  ** Nofrendo (c) 1998-2000 Matthew Conte (matt@conte.com)
  3  **
  4  **
  5  ** This program is free software; you can redistribute it and/or
  6  ** modify it under the terms of version 2 of the GNU Library General 
  7  ** Public License as published by the Free Software Foundation.
  8  **
  9  ** This program is distributed in the hope that it will be useful, 
 10  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
 12  ** Library General Public License for more details.  To obtain a 
 13  ** copy of the GNU Library General Public License, write to the Free 
 14  ** Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 15  **
 16  ** Any permitted reproduction of these routines, in whole or in part,
 17  ** must bear this legend.
 18  **
 19  **
 20  ** map15.c
 21  **
 22  ** mapper 15 interface
 23  ** $Id: map015.c,v 1.2 2001/04/27 14:37:11 neil Exp $
 24  */
 25  
 26  #include "noftypes.h"
 27  #include "nes_mmc.h"
 28  #include "nes_ppu.h"
 29  
 30  /* mapper 15: Contra 100-in-1 */
 31  static void map15_write(uint32 address, uint8 value)
 32  {
 33     int bank = value & 0x3F;
 34     uint8 swap = (value & 0x80) >> 7;
 35  
 36     switch (address & 0x3)
 37     {
 38     case 0:
 39        mmc_bankrom(8, 0x8000, (bank << 1) + swap);
 40        mmc_bankrom(8, 0xA000, (bank << 1) + (swap ^ 1));
 41        mmc_bankrom(8, 0xC000, ((bank + 1) << 1) + swap);
 42        mmc_bankrom(8, 0xE000, ((bank + 1) << 1) + (swap ^ 1));
 43  
 44        if (value & 0x40)
 45           ppu_mirror(0, 0, 1, 1); /* horizontal */
 46        else
 47           ppu_mirror(0, 1, 0, 1); /* vertical */
 48        break;
 49  
 50     case 1:
 51        mmc_bankrom(8, 0xC000, (bank << 1) + swap);
 52        mmc_bankrom(8, 0xE000, (bank << 1) + (swap ^ 1));
 53        break;
 54  
 55     case 2:
 56        if (swap)
 57        {
 58           mmc_bankrom(8, 0x8000, (bank << 1) + 1);
 59           mmc_bankrom(8, 0xA000, (bank << 1) + 1);
 60           mmc_bankrom(8, 0xC000, (bank << 1) + 1);
 61           mmc_bankrom(8, 0xE000, (bank << 1) + 1);
 62        }
 63        else
 64        {
 65           mmc_bankrom(8, 0x8000, (bank << 1));
 66           mmc_bankrom(8, 0xA000, (bank << 1));
 67           mmc_bankrom(8, 0xC000, (bank << 1));
 68           mmc_bankrom(8, 0xE000, (bank << 1));
 69        }
 70        break;
 71  
 72     case 3:
 73        mmc_bankrom(8, 0xC000, (bank << 1) + swap);
 74        mmc_bankrom(8, 0xE000, (bank << 1) + (swap ^ 1));
 75  
 76        if (value & 0x40)
 77           ppu_mirror(0, 0, 1, 1); /* horizontal */
 78        else
 79           ppu_mirror(0, 1, 0, 1); /* vertical */
 80        break;
 81  
 82     default:
 83        break;
 84     }
 85  }
 86  
 87  static void map15_init(void)
 88  {
 89     mmc_bankrom(32, 0x8000, 0);
 90  }
 91  
 92  static const map_memwrite map15_memwrite[] =
 93  {
 94     { 0x8000, 0xFFFF, map15_write },
 95     {     -1,     -1, NULL }
 96  };
 97  
 98  const mapintf_t map15_intf =
 99  {
100     15, /* mapper number */
101     "Contra 100-in-1", /* mapper name */
102     map15_init, /* init routine */
103     NULL, /* vblank callback */
104     NULL, /* hblank callback */
105     NULL, /* get state (snss) */
106     NULL, /* set state (snss) */
107     NULL, /* memory read structure */
108     map15_memwrite, /* memory write structure */
109     NULL /* external sound device */
110  };
111  
112  /*
113  ** $Log: map015.c,v $
114  ** Revision 1.2  2001/04/27 14:37:11  neil
115  ** wheeee
116  **
117  ** Revision 1.1  2001/04/27 12:54:40  neil
118  ** blah
119  **
120  ** Revision 1.1.1.1  2001/04/27 07:03:54  neil
121  ** initial
122  **
123  ** Revision 1.1  2000/10/24 12:19:33  matt
124  ** changed directory structure
125  **
126  ** Revision 1.6  2000/10/22 19:17:46  matt
127  ** mapper cleanups galore
128  **
129  ** Revision 1.5  2000/10/22 15:03:13  matt
130  ** simplified mirroring
131  **
132  ** Revision 1.4  2000/10/21 19:33:38  matt
133  ** many more cleanups
134  **
135  ** Revision 1.3  2000/07/10 05:29:03  matt
136  ** cleaned up some mirroring issues
137  **
138  ** Revision 1.2  2000/07/06 02:48:43  matt
139  ** clearly labelled structure members
140  **
141  ** Revision 1.1  2000/07/05 05:05:18  matt
142  ** initial revision
143  **
144  */