43725da7 |
1 | /* FCE Ultra - NES/Famicom Emulator\r |
2 | *\r |
3 | * Copyright notice for this file:\r |
4 | * Copyright (C) 2009 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 | \r |
21 | #include "mapinc.h"\r |
22 | \r |
23 | static uint8 reg[7];\r |
24 | static uint8 *WRAM=NULL;\r |
25 | static uint32 WRAMSIZE;\r |
26 | \r |
27 | static SFORMAT StateRegs[]=\r |
28 | {\r |
29 | {reg, 2, "REG"},\r |
30 | {0}\r |
31 | };\r |
32 | \r |
33 | static uint8 bs_tbl[128] = {\r |
34 | 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33,\r |
35 | 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67,\r |
36 | 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33,\r |
37 | 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67,\r |
38 | 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32,\r |
39 | 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67,\r |
40 | 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x00, 0x10, 0x20, 0x30,\r |
41 | 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67,\r |
42 | };\r |
43 | \r |
44 | static uint8 br_tbl[16] = {\r |
45 | 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, \r |
46 | };\r |
47 | \r |
48 | static void Sync(void)\r |
49 | {\r |
50 | // setchr4(0x0000,(reg[0]&0x80) >> 7);\r |
51 | // setchr4(0x1000,(reg[0]&0x80) >> 7);\r |
52 | setchr8(0);\r |
53 | setprg8r(0x10,0x6000,0);\r |
54 | setprg16(0x8000,bs_tbl[reg[0]&0x7f]>>4);\r |
55 | setprg16(0xc000,bs_tbl[reg[0]&0x7f]&0xf);\r |
56 | setmirror(MI_V);\r |
57 | }\r |
58 | \r |
59 | static DECLFW(UNLPEC586Write)\r |
60 | {\r |
61 | reg[(A&0x700)>>8]=V;\r |
62 | FCEU_printf("bs %04x %02x\n",A,V);\r |
63 | Sync();\r |
64 | }\r |
65 | \r |
66 | static DECLFR(UNLPEC586Read)\r |
67 | {\r |
68 | FCEU_printf("read %04x\n",A);\r |
69 | return (X.DB & 0xD8) | br_tbl[reg[4]>>4];\r |
70 | }\r |
71 | \r |
72 | static void UNLPEC586Power(void)\r |
73 | {\r |
74 | reg[0]=0x0E;\r |
75 | Sync();\r |
76 | setchr8(0);\r |
77 | SetReadHandler(0x6000,0x7FFF,CartBR);\r |
78 | SetWriteHandler(0x6000,0x7FFF,CartBW);\r |
79 | SetReadHandler(0x8000,0xFFFF,CartBR);\r |
80 | SetWriteHandler(0x5000,0x5fff,UNLPEC586Write);\r |
81 | SetReadHandler(0x5000,0x5fff,UNLPEC586Read);\r |
82 | }\r |
83 | \r |
84 | static void UNLPEC586IRQ(void)\r |
85 | {\r |
86 | // if(reg[0]&0x80)\r |
87 | {\r |
88 | if(scanline==128) {\r |
89 | setchr4(0x0000,1);\r |
90 | setchr4(0x1000,0);\r |
91 | }\r |
92 | else {\r |
93 | setchr4(0x0000,0);\r |
94 | setchr4(0x1000,1);\r |
95 | }\r |
96 | }\r |
97 | }\r |
98 | \r |
99 | static void UNLPEC586Close(void)\r |
100 | {\r |
101 | if(WRAM)\r |
102 | FCEU_gfree(WRAM);\r |
103 | WRAM=NULL;\r |
104 | }\r |
105 | \r |
106 | static void StateRestore(int version)\r |
107 | {\r |
108 | Sync();\r |
109 | }\r |
110 | \r |
111 | void UNLPEC586Init(CartInfo *info)\r |
112 | {\r |
113 | info->Power=UNLPEC586Power;\r |
114 | info->Close=UNLPEC586Close;\r |
115 | GameHBIRQHook=UNLPEC586IRQ;\r |
116 | GameStateRestore=StateRestore;\r |
117 | \r |
118 | WRAMSIZE=8192;\r |
119 | WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r |
120 | SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r |
121 | AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r |
122 | \r |
123 | AddExState(&StateRegs, ~0, 0, 0);\r |
124 | }\r |