map065.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 ** map65.c 21 ** 22 ** mapper 65 interface 23 ** $Id: map065.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 static struct 31 { 32 int counter; 33 bool enabled; 34 int cycles; 35 uint8 low, high; 36 } irq; 37 38 static void map65_init(void) 39 { 40 irq.counter = 0; 41 irq.enabled = false; 42 irq.low = irq.high = 0; 43 irq.cycles = 0; 44 } 45 46 /* TODO: shouldn't there be some kind of HBlank callback??? */ 47 48 /* mapper 65: Irem H-3001*/ 49 static void map65_write(uint32 address, uint8 value) 50 { 51 int range = address & 0xF000; 52 int reg = address & 7; 53 54 switch (range) 55 { 56 case 0x8000: 57 case 0xA000: 58 case 0xC000: 59 mmc_bankrom(8, range, value); 60 break; 61 62 case 0xB000: 63 mmc_bankvrom(1, reg << 10, value); 64 break; 65 66 case 0x9000: 67 switch (reg) 68 { 69 case 4: 70 irq.enabled = (value & 0x01) ? false : true; 71 break; 72 73 case 5: 74 irq.high = value; 75 irq.cycles = (irq.high << 8) | irq.low; 76 irq.counter = (uint8)(irq.cycles / 128); 77 break; 78 79 case 6: 80 irq.low = value; 81 irq.cycles = (irq.high << 8) | irq.low; 82 irq.counter = (uint8)(irq.cycles / 128); 83 break; 84 85 default: 86 break; 87 } 88 break; 89 90 default: 91 break; 92 } 93 } 94 95 static const map_memwrite map65_memwrite[] = 96 { 97 { 0x8000, 0xFFFF, map65_write }, 98 { -1, -1, NULL } 99 }; 100 101 const mapintf_t map65_intf = 102 { 103 65, /* mapper number */ 104 "Irem H-3001", /* mapper name */ 105 map65_init, /* init routine */ 106 NULL, /* vblank callback */ 107 NULL, /* hblank callback */ 108 NULL, /* get state (snss) */ 109 NULL, /* set state (snss) */ 110 NULL, /* memory read structure */ 111 map65_memwrite, /* memory write structure */ 112 NULL /* external sound device */ 113 }; 114 115 /* 116 ** $Log: map065.c,v $ 117 ** Revision 1.2 2001/04/27 14:37:11 neil 118 ** wheeee 119 ** 120 ** Revision 1.1 2001/04/27 12:54:40 neil 121 ** blah 122 ** 123 ** Revision 1.1.1.1 2001/04/27 07:03:54 neil 124 ** initial 125 ** 126 ** Revision 1.1 2000/10/24 12:19:33 matt 127 ** changed directory structure 128 ** 129 ** Revision 1.5 2000/10/22 19:17:46 matt 130 ** mapper cleanups galore 131 ** 132 ** Revision 1.4 2000/10/21 19:33:38 matt 133 ** many more cleanups 134 ** 135 ** Revision 1.3 2000/10/10 13:58:17 matt 136 ** stroustrup squeezing his way in the door 137 ** 138 ** Revision 1.2 2000/07/06 02:48:43 matt 139 ** clearly labelled structure members 140 ** 141 ** Revision 1.1 2000/07/06 01:01:56 matt 142 ** initial revision 143 ** 144 */