386f5371 |
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 |
43725da7 |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r |
19 | *\r |
20 | * SL1632 2-in-1 protected board, similar to SL12\r |
21 | * Samurai Spirits Rex (Full)\r |
22 | *\r |
386f5371 |
23 | */\r |
24 | \r |
25 | #include "mapinc.h"\r |
26 | #include "mmc3.h"\r |
27 | \r |
386f5371 |
28 | static uint8 chrcmd[8], prg0, prg1, bbrk, mirr, swap;\r |
29 | static SFORMAT StateRegs[]=\r |
30 | {\r |
43725da7 |
31 | {chrcmd, 8, "CHRC"},\r |
386f5371 |
32 | {&prg0, 1, "PRG0"},\r |
33 | {&prg1, 1, "PRG1"},\r |
34 | {&bbrk, 1, "BRK"},\r |
35 | {&mirr, 1, "MIRR"},\r |
36 | {&swap, 1, "SWAP"},\r |
37 | {0}\r |
38 | };\r |
39 | \r |
40 | static void Sync(void)\r |
41 | {\r |
42 | int i;\r |
43 | setprg8(0x8000,prg0);\r |
44 | setprg8(0xA000,prg1);\r |
45 | setprg8(0xC000,~1);\r |
46 | setprg8(0xE000,~0);\r |
47 | for(i=0; i<8; i++)\r |
48 | setchr1(i<<10,chrcmd[i]);\r |
49 | setmirror(mirr^1);\r |
50 | }\r |
51 | \r |
52 | static void UNLSL1632CW(uint32 A, uint8 V)\r |
53 | {\r |
54 | int cbase=(MMC3_cmd&0x80)<<5;\r |
55 | int page0=(bbrk&0x08)<<5;\r |
56 | int page1=(bbrk&0x20)<<3;\r |
57 | int page2=(bbrk&0x80)<<1;\r |
58 | setchr1(cbase^0x0000,page0|(DRegBuf[0]&(~1)));\r |
59 | setchr1(cbase^0x0400,page0|DRegBuf[0]|1);\r |
60 | setchr1(cbase^0x0800,page0|(DRegBuf[1]&(~1)));\r |
61 | setchr1(cbase^0x0C00,page0|DRegBuf[1]|1);\r |
62 | setchr1(cbase^0x1000,page1|DRegBuf[2]);\r |
63 | setchr1(cbase^0x1400,page1|DRegBuf[3]);\r |
64 | setchr1(cbase^0x1800,page2|DRegBuf[4]);\r |
65 | setchr1(cbase^0x1c00,page2|DRegBuf[5]);\r |
66 | }\r |
67 | \r |
68 | static DECLFW(UNLSL1632CMDWrite)\r |
69 | {\r |
70 | if(A==0xA131)\r |
71 | {\r |
72 | bbrk=V;\r |
73 | }\r |
74 | if(bbrk&2)\r |
75 | {\r |
76 | FixMMC3PRG(MMC3_cmd);\r |
77 | FixMMC3CHR(MMC3_cmd);\r |
78 | if(A<0xC000)\r |
79 | MMC3_CMDWrite(A,V);\r |
80 | else\r |
81 | MMC3_IRQWrite(A,V);\r |
82 | }\r |
83 | else\r |
84 | {\r |
85 | if((A>=0xB000)&&(A<=0xE003))\r |
86 | {\r |
87 | int ind=((((A&2)|(A>>10))>>1)+2)&7;\r |
88 | int sar=((A&1)<<2);\r |
89 | chrcmd[ind]=(chrcmd[ind]&(0xF0>>sar))|((V&0x0F)<<sar);\r |
90 | }\r |
91 | else\r |
92 | switch(A&0xF003)\r |
93 | {\r |
94 | case 0x8000: prg0=V; break;\r |
95 | case 0xA000: prg1=V; break;\r |
96 | case 0x9000: mirr=V&1; break;\r |
97 | }\r |
98 | Sync();\r |
99 | }\r |
100 | }\r |
101 | \r |
102 | static void StateRestore(int version)\r |
103 | {\r |
104 | if(bbrk&2)\r |
105 | {\r |
106 | FixMMC3PRG(MMC3_cmd);\r |
107 | FixMMC3CHR(MMC3_cmd);\r |
108 | }\r |
109 | else\r |
110 | Sync();\r |
111 | }\r |
112 | \r |
113 | static void UNLSL1632Power(void)\r |
114 | {\r |
115 | GenMMC3Power();\r |
386f5371 |
116 | SetWriteHandler(0x4100,0xFFFF,UNLSL1632CMDWrite);\r |
117 | }\r |
118 | \r |
119 | void UNLSL1632_Init(CartInfo *info)\r |
120 | {\r |
121 | GenMMC3_Init(info, 256, 512, 0, 0);\r |
122 | cwrap=UNLSL1632CW;\r |
123 | info->Power=UNLSL1632Power;\r |
124 | GameStateRestore=StateRestore;\r |
125 | AddExState(&StateRegs, ~0, 0, 0);\r |
126 | }\r |