| 1 | /* FCE Ultra - NES/Famicom Emulator\r |
| 2 | *\r |
| 3 | * Copyright notice for this file:\r |
| 4 | * Copyright (C) 2006 CaH4e3\r |
| 5 | *\r |
| 6 | * This program is free software; you can redistribute it and/or modify\r |
| 7 | * it under the terms of the GNU General Public License as published by\r |
| 8 | * the Free Software Foundation; either version 2 of the License, or\r |
| 9 | * (at your option) any later version.\r |
| 10 | *\r |
| 11 | * This program is distributed in the hope that it will be useful,\r |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of\r |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r |
| 14 | * GNU General Public License for more details.\r |
| 15 | *\r |
| 16 | * You should have received a copy of the GNU General Public License\r |
| 17 | * along with this program; if not, write to the Free Software\r |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\r |
| 19 | */\r |
| 20 | \r |
| 21 | #include "mapinc.h"\r |
| 22 | #include "mmc3.h"\r |
| 23 | \r |
| 24 | static uint8 *CHRRAM; // there is no more extern CHRRAM in mmc3.h |
| 25 | // I need chrram here and local static == local\r |
| 26 | static uint8 tekker;\r |
| 27 | \r |
| 28 | static void MSHCW(uint32 A, uint8 V)\r |
| 29 | {\r |
| 30 | if(EXPREGS[0]&0x40)\r |
| 31 | setchr8r(0x10,0);\r |
| 32 | else\r |
| 33 | {\r |
| 34 | if(A<0x800)\r |
| 35 | setchr1(A,V|((EXPREGS[0]&8)<<5));\r |
| 36 | else if(A<0x1000)\r |
| 37 | setchr1(A,V|((EXPREGS[0]&4)<<6));\r |
| 38 | else if(A<0x1800)\r |
| 39 | setchr1(A,V|((EXPREGS[0]&1)<<8));\r |
| 40 | else\r |
| 41 | setchr1(A,V|((EXPREGS[0]&2)<<7));\r |
| 42 | }\r |
| 43 | }\r |
| 44 | \r |
| 45 | static DECLFW(MSHWrite)\r |
| 46 | {\r |
| 47 | EXPREGS[0]=V;\r |
| 48 | FixMMC3CHR(MMC3_cmd);\r |
| 49 | }\r |
| 50 | \r |
| 51 | static DECLFR(MSHRead)\r |
| 52 | {\r |
| 53 | return(tekker);\r |
| 54 | }\r |
| 55 | \r |
| 56 | static void MSHReset(void)\r |
| 57 | {\r |
| 58 | MMC3RegReset();\r |
| 59 | tekker^=0xFF; \r |
| 60 | }\r |
| 61 | \r |
| 62 | static void MSHPower(void)\r |
| 63 | {\r |
| 64 | tekker=0x00;\r |
| 65 | GenMMC3Power();\r |
| 66 | SetWriteHandler(0x4100,0x4100,MSHWrite);\r |
| 67 | SetReadHandler(0x4100,0x4100,MSHRead);\r |
| 68 | }\r |
| 69 | \r |
| 70 | static void MSHClose(void)\r |
| 71 | {\r |
| 72 | if(CHRRAM)\r |
| 73 | FCEU_gfree(CHRRAM);\r |
| 74 | CHRRAM=NULL;\r |
| 75 | }\r |
| 76 | \r |
| 77 | void UNLSHeroes_Init(CartInfo *info)\r |
| 78 | {\r |
| 79 | GenMMC3_Init(info, 256, 512, 0, 0);\r |
| 80 | cwrap=MSHCW;\r |
| 81 | info->Power=MSHPower;\r |
| 82 | info->Reset=MSHReset;\r |
| 83 | info->Close=MSHClose;\r |
| 84 | CHRRAM = (uint8*)FCEU_gmalloc(8192);\r |
| 85 | SetupCartCHRMapping(0x10, CHRRAM, 8192, 1);\r |
| 86 | AddExState(EXPREGS, 4, 0, "EXPR");\r |
| 87 | AddExState(&tekker, 1, 0, "DIPSW");\r |
| 88 | }\r |