| 1 | /* FCE Ultra - NES/Famicom Emulator\r |
| 2 | *\r |
| 3 | * Copyright notice for this file:\r |
| 4 | * Copyright (C) 2005 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r |
| 19 | *\r |
| 20 | * Family Study Box by Fukutake Shoten\r |
| 21 | */\r |
| 22 | \r |
| 23 | #include "mapinc.h"\r |
| 24 | \r |
| 25 | static uint8 SWRAM[2816];\r |
| 26 | static uint8 *WRAM=NULL;\r |
| 27 | static uint8 regs[4];\r |
| 28 | \r |
| 29 | static SFORMAT StateRegs[]=\r |
| 30 | {\r |
| 31 | {regs, 4, "DREG"},\r |
| 32 | {SWRAM, 2816, "SWRM"},\r |
| 33 | {0}\r |
| 34 | };\r |
| 35 | \r |
| 36 | static void Sync(void)\r |
| 37 | {\r |
| 38 | setprg8r(0x10,0x6000,regs[0]>>6);\r |
| 39 | setprg16(0x8000,regs[1]);\r |
| 40 | setprg16(0xc000,0);\r |
| 41 | }\r |
| 42 | \r |
| 43 | static DECLFW(M186Write)\r |
| 44 | {\r |
| 45 | if(A&0x4203) regs[A&3]=V;\r |
| 46 | Sync();\r |
| 47 | }\r |
| 48 | \r |
| 49 | static DECLFR(M186Read)\r |
| 50 | {\r |
| 51 | switch(A)\r |
| 52 | {\r |
| 53 | case 0x4200: return 0x00; break;\r |
| 54 | case 0x4201: return 0x00; break;\r |
| 55 | case 0x4202: return 0x40; break;\r |
| 56 | case 0x4203: return 0x00; break;\r |
| 57 | }\r |
| 58 | return 0xFF;\r |
| 59 | }\r |
| 60 | \r |
| 61 | static DECLFR(ASWRAM)\r |
| 62 | {\r |
| 63 | return(SWRAM[A-0x4400]);\r |
| 64 | }\r |
| 65 | static DECLFW(BSWRAM)\r |
| 66 | {\r |
| 67 | SWRAM[A-0x4400]=V;\r |
| 68 | }\r |
| 69 | \r |
| 70 | static void M186Power(void)\r |
| 71 | {\r |
| 72 | setchr8(0);\r |
| 73 | SetReadHandler(0x6000,0xFFFF,CartBR);\r |
| 74 | SetWriteHandler(0x6000,0xFFFF,CartBW);\r |
| 75 | SetReadHandler(0x4200,0x43FF,M186Read);\r |
| 76 | SetWriteHandler(0x4200,0x43FF,M186Write);\r |
| 77 | SetReadHandler(0x4400,0x4EFF,ASWRAM);\r |
| 78 | SetWriteHandler(0x4400,0x4EFF,BSWRAM);\r |
| 79 | regs[0]=regs[1]=regs[2]=regs[3];\r |
| 80 | Sync();\r |
| 81 | }\r |
| 82 | \r |
| 83 | static void M186Close(void)\r |
| 84 | {\r |
| 85 | if(WRAM)\r |
| 86 | FCEU_gfree(WRAM);\r |
| 87 | WRAM=NULL;\r |
| 88 | }\r |
| 89 | \r |
| 90 | static void M186Restore(int version)\r |
| 91 | {\r |
| 92 | Sync();\r |
| 93 | }\r |
| 94 | \r |
| 95 | void Mapper186_Init(CartInfo *info)\r |
| 96 | {\r |
| 97 | info->Power=M186Power;\r |
| 98 | info->Close=M186Close;\r |
| 99 | GameStateRestore=M186Restore;\r |
| 100 | WRAM=(uint8*)FCEU_gmalloc(32768);\r |
| 101 | SetupCartPRGMapping(0x10,WRAM,32768,1);\r |
| 102 | AddExState(WRAM, 32768, 0, "WRAM");\r |
| 103 | AddExState(StateRegs, ~0, 0, 0);\r |
| 104 | }\r |