map041.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  ** map041.c
 21  **
 22  ** Mapper #41 (Caltron 6 in 1)
 23  ** Implementation by Firebug
 24  ** Mapper information courtesy of Kevin Horton
 25  ** $Id: map041.c,v 1.2 2001/04/27 14:37:11 neil Exp $
 26  **
 27  */
 28  
 29  #include "noftypes.h"
 30  #include "nes_mmc.h"
 31  #include "nes.h"
 32  #include "libsnss.h"
 33  #include "log.h"
 34  
 35  static uint8 register_low;
 36  static uint8 register_high;
 37  
 38  /*****************************************************/
 39  /* Set 8K CHR bank from the combined register values */
 40  /*****************************************************/
 41  static void map41_set_chr (void)
 42  {
 43    /* Set the CHR bank from the appropriate register bits */
 44    mmc_bankvrom (8, 0x0000, ((register_low >> 1) & 0x0C) | (register_high));
 45  
 46    /* Done */
 47    return;
 48  }
 49  
 50  /******************************/
 51  /* Mapper #41: Caltron 6 in 1 */
 52  /******************************/
 53  static void map41_init (void)
 54  {
 55    /* Both registers set to zero at power on */
 56    /* TODO: Registers should also be cleared on a soft reset */
 57    register_low = 0x00;
 58    register_high = 0x00;
 59    mmc_bankrom (32, 0x8000, 0x00);
 60    map41_set_chr ();
 61  
 62    /* Done */
 63    return;
 64  }
 65  
 66  /******************************************/
 67  /* Mapper #41 write handler ($6000-$67FF) */
 68  /******************************************/
 69  static void map41_low_write (uint32 address, uint8 value)
 70  {
 71    /* Within this range the value written is irrelevant */
 72    UNUSED (value);
 73  
 74    /* $6000-$67FF: A5    = mirroring (1=horizontal, 0=vertical)      */
 75    /*              A4-A3 = high two bits of 8K CHR bank              */
 76    /*              A2    = register 1 enable (0=disabled, 1=enabled) */
 77    /*              A2-A0 = 32K PRG bank                              */
 78    register_low = (uint8) (address & 0x3F);
 79    mmc_bankrom (32, 0x8000, register_low & 0x07);
 80    map41_set_chr ();
 81    if (register_low & 0x20) ppu_mirror(0, 0, 1, 1); /* horizontal */
 82    else                     ppu_mirror(0, 1, 0, 1); /* vertical */
 83  
 84    /* Done */
 85    return;
 86  }
 87  
 88  /******************************************/
 89  /* Mapper #41 write handler ($8000-$FFFF) */
 90  /******************************************/
 91  static void map41_high_write (uint32 address, uint8 value)
 92  {
 93    /* Address doesn't matter within this range */
 94    UNUSED (address);
 95  
 96    /* $8000-$FFFF: D1-D0 = low two bits of 8K CHR bank */
 97    if (register_low & 0x04)
 98    {
 99      register_high = value & 0x03;
100      map41_set_chr ();
101    }
102  
103    /* Done */
104    return;
105  }
106  
107  /****************************************************/
108  /* Shove extra mapper information into a SNSS block */
109  /****************************************************/
110  static void map41_setstate (SnssMapperBlock *state)
111  {
112    /* TODO: Store SNSS information */
113    UNUSED (state);
114  
115    /* Done */
116    return;
117  }
118  
119  /*****************************************************/
120  /* Pull extra mapper information out of a SNSS block */
121  /*****************************************************/
122  static void map41_getstate (SnssMapperBlock *state)
123  {
124    /* TODO: Retrieve SNSS information */
125    UNUSED (state);
126  
127    /* Done */
128    return;
129  }
130  
131  static const map_memwrite map41_memwrite [] =
132  {
133     { 0x6000, 0x67FF, map41_low_write },
134     { 0x8000, 0xFFFF, map41_high_write },
135     {     -1,     -1, NULL }
136  };
137  
138  const mapintf_t map41_intf =
139  {
140     41,                               /* Mapper number */
141     "Caltron 6 in 1",                 /* Mapper name */
142     map41_init,                       /* Initialization routine */
143     NULL,                             /* VBlank callback */
144     NULL,                             /* HBlank callback */
145     map41_getstate,                   /* Get state (SNSS) */
146     map41_setstate,                   /* Set state (SNSS) */
147     NULL,                             /* Memory read structure */
148     map41_memwrite,                   /* Memory write structure */
149     NULL                              /* External sound device */
150  };
151  
152  /*
153  ** $Log: map041.c,v $
154  ** Revision 1.2  2001/04/27 14:37:11  neil
155  ** wheeee
156  **
157  ** Revision 1.1  2001/04/27 12:54:40  neil
158  ** blah
159  **
160  ** Revision 1.1  2001/04/27 10:57:41  neil
161  ** wheee
162  **
163  ** Revision 1.1  2000/12/30 00:33:15  firebug
164  ** initial revision
165  **
166  **
167  */