| 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 | * CAI Shogakko no Sansu\r |
| 21 | */\r |
| 22 | \r |
| 23 | #include "mapinc.h"\r |
| 24 | \r |
| 25 | static uint8 *CHRRAM=NULL;\r |
| 26 | static uint8 SWRAM[4096];\r |
| 27 | \r |
| 28 | static uint8 regs[16];\r |
| 29 | static uint8 WRAM[4096];\r |
| 30 | static SFORMAT StateRegs[]=\r |
| 31 | {\r |
| 32 | {®s, 16, "REGS"},\r |
| 33 | {WRAM, 4096, "WRAM"},\r |
| 34 | {0}\r |
| 35 | };\r |
| 36 | \r |
| 37 | static void Sync(void)\r |
| 38 | {\r |
| 39 | if(regs[5]&0x40)\r |
| 40 | {\r |
| 41 | setchr4r(0,0x1000,regs[5]&0x3F);\r |
| 42 | }\r |
| 43 | else\r |
| 44 | {\r |
| 45 | setchr4r(0x10,0x0000,regs[5]);\r |
| 46 | setchr4r(0x10,0x1000,regs[5]^1);\r |
| 47 | }\r |
| 48 | setprg8r((regs[2]>>6)&1,0x8000,(regs[2]&0x3F));\r |
| 49 | setprg8r((regs[3]>>6)&1,0xA000,(regs[3]&0x3F));\r |
| 50 | setprg8r((regs[4]>>6)&1,0xC000,(regs[4]&0x3F));\r |
| 51 | setprg8r(1,0xE000,~0);\r |
| 52 | setmirror((regs[0xA]&3));\r |
| 53 | }\r |
| 54 | \r |
| 55 | static DECLFW(M190Write)\r |
| 56 | {\r |
| 57 | // FCEU_printf("write %04x:%04x %d, %d\n",A,V,scanline,timestamp);\r |
| 58 | regs[(A&0x0F00)>>8]=V;\r |
| 59 | Sync();\r |
| 60 | }\r |
| 61 | \r |
| 62 | static DECLFR(M190Read)\r |
| 63 | {\r |
| 64 | // FCEU_printf("read %04x:%04x %d, %d\n",A,regs[(A&0x0F00)>>8],scanline,timestamp);\r |
| 65 | return regs[(A&0x0F00)>>8];\r |
| 66 | }\r |
| 67 | \r |
| 68 | static DECLFR(AWRAM)\r |
| 69 | {\r |
| 70 | return(WRAM[A-0x7000]);\r |
| 71 | }\r |
| 72 | static DECLFW(BWRAM)\r |
| 73 | {\r |
| 74 | WRAM[A-0x7000]=V;\r |
| 75 | }\r |
| 76 | \r |
| 77 | static DECLFR(ASWRAM)\r |
| 78 | {\r |
| 79 | return(SWRAM[A-0x6000]);\r |
| 80 | }\r |
| 81 | static DECLFW(BSWRAM)\r |
| 82 | {\r |
| 83 | SWRAM[A-0x6000]=V;\r |
| 84 | }\r |
| 85 | \r |
| 86 | static void M190Power(void)\r |
| 87 | {\r |
| 88 | setvram8(CHRRAM);\r |
| 89 | SetReadHandler(0x8000,0xFFFF,CartBR);\r |
| 90 | SetWriteHandler(0x8000,0xFFFF,M190Write);\r |
| 91 | // SetReadHandler(0xDA00,0xDA00,M190Read);\r |
| 92 | // SetReadHandler(0xDB00,0xDB00,M190Read);\r |
| 93 | SetReadHandler(0xDC00,0xDC00,M190Read);\r |
| 94 | SetReadHandler(0xDD00,0xDD00,M190Read);\r |
| 95 | SetReadHandler(0x7000,0x7FFF,AWRAM);\r |
| 96 | SetWriteHandler(0x7000,0x7FFF,BWRAM);\r |
| 97 | SetReadHandler(0x6000,0x6FFF,ASWRAM);\r |
| 98 | SetWriteHandler(0x6000,0x6FFF,BSWRAM);\r |
| 99 | Sync();\r |
| 100 | }\r |
| 101 | \r |
| 102 | static void M190Close(void)\r |
| 103 | {\r |
| 104 | if(CHRRAM)\r |
| 105 | FCEU_gfree(CHRRAM);\r |
| 106 | CHRRAM=NULL;\r |
| 107 | }\r |
| 108 | \r |
| 109 | static void StateRestore(int version)\r |
| 110 | {\r |
| 111 | Sync();\r |
| 112 | }\r |
| 113 | \r |
| 114 | void Mapper190_Init(CartInfo *info)\r |
| 115 | {\r |
| 116 | info->Power=M190Power;\r |
| 117 | info->Close=M190Close;\r |
| 118 | if(info->battery)\r |
| 119 | {\r |
| 120 | info->SaveGame[0]=SWRAM;\r |
| 121 | info->SaveGameLen[0]=4096;\r |
| 122 | }\r |
| 123 | GameStateRestore=StateRestore;\r |
| 124 | CHRRAM=(uint8*)FCEU_gmalloc(8192);\r |
| 125 | SetupCartCHRMapping(0x10,CHRRAM,8192,1);\r |
| 126 | AddExState(CHRRAM, 8192, 0, "CHRRAM");\r |
| 127 | AddExState(&StateRegs, ~0, 0, 0);\r |
| 128 | }\r |