debug, unbreaking castlevania 3
[fceu.git] / boards / h2288.c
CommitLineData
c62d2810 1/* FCE Ultra - NES/Famicom Emulator
2 *
3 * Copyright notice for this file:
4 * Copyright (C) 2002 Ben Parnell
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21/* Not finished. Darn evil game... *Mumble*... */
22
23#include "mapinc.h"
24
25static uint8 cmd;
26static uint8 regs[8];
27
28static void DoPRG(void)
29{
30 if(cmd&0x40)
31 {
32 setprg8(0xC000,regs[4]);
33 setprg8(0xA000,regs[5]);
34 setprg8(0x8000,~1);
35 setprg8(0xE000,~0);
36 }
37 else
38 {
39 setprg8(0x8000,regs[4]);
40 setprg8(0xA000,regs[5]);
41 setprg8(0xC000,~1);
42 setprg8(0xE000,~0);
43 }
44}
45
46static void DoCHR(void)
47{
48 uint32 base=(cmd&0x80)<<5;
49
50 setchr2(0x0000^base,regs[0]);
51 setchr2(0x0800^base,regs[2]);
52
53 setchr1(0x1000^base,regs[6]);
54 setchr1(0x1400^base,regs[1]);
55 setchr1(0x1800^base,regs[7]);
56 setchr1(0x1c00^base,regs[3]);
57}
58
59static DECLFW(H2288Write)
60{
61 //printf("$%04x:$%02x, $%04x\n",A,V,X.PC.W);
62 //RAM[0x7FB]=0x60;
63 switch(A&0xE001)
64 {
65 case 0xa000:setmirror((V&1)^1);break;
66 case 0x8000:// DumpMem("out",0x0000,0xFFFF);
c0bf6f9f 67 cmd=V;DoPRG();DoCHR();
68 X6502_Rebase();break;
c62d2810 69 case 0x8001:regs[cmd&7]=V;
c0bf6f9f 70 if((cmd&7)==4 || (cmd&7)==5) {
c62d2810 71 DoPRG();
c0bf6f9f 72 X6502_Rebase();
73 } else
c62d2810 74 DoCHR();
75 break;
76 }
77}
78
79static DECLFR(H2288Read)
80{
81 //printf("Rd: $%04x, $%04x\n",A,X.PC.W);
82 return((X.DB&0xFE)|(A&(A>>8)));
83}
84
85static void H2288Reset(void)
86{
87 int x;
88
89 SetReadHandler(0x5800,0x5FFF,H2288Read);
90 SetReadHandler(0x8000,0xFFFF,CartBR);
91 SetWriteHandler(0x8000,0xFFFF,H2288Write);
92 for(x=0;x<8;x++) regs[x]=0;
93 cmd=0;
94 DoPRG();
95 DoCHR();
96}
97
98void H2288_Init(void)
99{
100 BoardPower=H2288Reset;
101}