9b9dcbc362016ca0167f6918770e57d5835c4e59
[fceu.git] / boards / h2288.c
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
25 static uint8 cmd;
26 static uint8 regs[8];
27
28 static 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
46 static 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
59 static 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);
67               cmd=V;DoPRG();DoCHR();
68               X6502_Rebase();break;
69   case 0x8001:regs[cmd&7]=V;
70               if((cmd&7)==4 || (cmd&7)==5) {
71                DoPRG();
72                X6502_Rebase();
73               } else
74                DoCHR();
75               break;
76  }
77 }
78
79 static DECLFR(H2288Read)
80 {
81  //printf("Rd: $%04x, $%04x\n",A,X.PC.W);
82  return((X.DB&0xFE)|(A&(A>>8)));
83 }
84
85 static 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
98 void H2288_Init(void)
99 {
100   BoardPower=H2288Reset;
101 }