map019.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 ** map19.c 21 ** 22 ** mapper 19 interface 23 ** $Id: map019.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 /* TODO: shouldn't there be an h-blank IRQ handler??? */ 31 32 /* Special mirroring macro for mapper 19 */ 33 #define N_BANK1(table, value) \ 34 { \ 35 if ((value) < 0xE0) \ 36 ppu_setpage(1, (table) + 8, &mmc_getinfo()->vrom[((value) % (mmc_getinfo()->vrom_banks * 8)) << 10] - (0x2000 + ((table) << 10))); \ 37 else \ 38 ppu_setpage(1, (table) + 8, &mmc_getinfo()->vram[((value) & 7) << 10] - (0x2000 + ((table) << 10))); \ 39 ppu_mirrorhipages(); \ 40 } 41 42 static struct 43 { 44 int counter, enabled; 45 } irq; 46 47 static void map19_init(void) 48 { 49 irq.counter = irq.enabled = 0; 50 } 51 52 /* mapper 19: Namcot 106 */ 53 static void map19_write(uint32 address, uint8 value) 54 { 55 int reg = address >> 11; 56 switch (reg) 57 { 58 case 0xA: 59 irq.counter &= ~0xFF; 60 irq.counter |= value; 61 break; 62 63 case 0xB: 64 irq.counter = ((value & 0x7F) << 8) | (irq.counter & 0xFF); 65 irq.enabled = (value & 0x80) ? true : false; 66 break; 67 68 case 0x10: 69 case 0x11: 70 case 0x12: 71 case 0x13: 72 case 0x14: 73 case 0x15: 74 case 0x16: 75 case 0x17: 76 mmc_bankvrom(1, (reg & 7) << 10, value); 77 break; 78 79 case 0x18: 80 case 0x19: 81 case 0x1A: 82 case 0x1B: 83 N_BANK1(reg & 3, value); 84 break; 85 86 case 0x1C: 87 mmc_bankrom(8, 0x8000, value); 88 break; 89 90 case 0x1D: 91 mmc_bankrom(8, 0xA000, value); 92 break; 93 94 case 0x1E: 95 mmc_bankrom(8, 0xC000, value); 96 break; 97 98 default: 99 break; 100 } 101 } 102 103 static void map19_getstate(SnssMapperBlock *state) 104 { 105 state->extraData.mapper19.irqCounterLowByte = irq.counter & 0xFF; 106 state->extraData.mapper19.irqCounterHighByte = irq.counter >> 8; 107 state->extraData.mapper19.irqCounterEnabled = irq.enabled; 108 } 109 110 static void map19_setstate(SnssMapperBlock *state) 111 { 112 irq.counter = (state->extraData.mapper19.irqCounterHighByte << 8) 113 | state->extraData.mapper19.irqCounterLowByte; 114 irq.enabled = state->extraData.mapper19.irqCounterEnabled; 115 } 116 117 static const map_memwrite map19_memwrite[] = 118 { 119 { 0x5000, 0x5FFF, map19_write }, 120 { 0x8000, 0xFFFF, map19_write }, 121 { -1, -1, NULL } 122 }; 123 124 const mapintf_t map19_intf = 125 { 126 19, /* mapper number */ 127 "Namcot 106", /* mapper name */ 128 map19_init, /* init routine */ 129 NULL, /* vblank callback */ 130 NULL, /* hblank callback */ 131 map19_getstate, /* get state (snss) */ 132 map19_setstate, /* set state (snss) */ 133 NULL, /* memory read structure */ 134 map19_memwrite, /* memory write structure */ 135 NULL /* external sound device */ 136 }; 137 138 /* 139 ** $Log: map019.c,v $ 140 ** Revision 1.2 2001/04/27 14:37:11 neil 141 ** wheeee 142 ** 143 ** Revision 1.1 2001/04/27 12:54:40 neil 144 ** blah 145 ** 146 ** Revision 1.1.1.1 2001/04/27 07:03:54 neil 147 ** initial 148 ** 149 ** Revision 1.1 2000/10/24 12:19:33 matt 150 ** changed directory structure 151 ** 152 ** Revision 1.6 2000/10/22 19:17:46 matt 153 ** mapper cleanups galore 154 ** 155 ** Revision 1.5 2000/10/21 19:33:38 matt 156 ** many more cleanups 157 ** 158 ** Revision 1.4 2000/10/10 13:58:17 matt 159 ** stroustrup squeezing his way in the door 160 ** 161 ** Revision 1.3 2000/07/15 23:52:20 matt 162 ** rounded out a bunch more mapper interfaces 163 ** 164 ** Revision 1.2 2000/07/06 02:48:43 matt 165 ** clearly labelled structure members 166 ** 167 ** Revision 1.1 2000/07/06 01:01:56 matt 168 ** initial revision 169 ** 170 */