| 1 | /* FCE Ultra - NES/Famicom Emulator |
| 2 | * |
| 3 | * Copyright notice for this file: |
| 4 | * Copyright (C) 2005 CaH4e3 |
| 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 | #include "mapinc.h" |
| 22 | |
| 23 | static uint16 addrreg; |
| 24 | static uint8 datareg; |
| 25 | static uint8 busy; |
| 26 | static SFORMAT StateRegs[]= |
| 27 | { |
| 28 | {&addrreg, 2, "ADDRREG"}, |
| 29 | {&datareg, 1, "DATAREG"}, |
| 30 | {&busy, 1, "BUSY"}, |
| 31 | {0} |
| 32 | }; |
| 33 | |
| 34 | static void Sync(void) |
| 35 | { |
| 36 | setprg16(0x8000,(datareg&7)|((addrreg&0x60)>>2)|((addrreg&0x100)>>3)); |
| 37 | setprg16(0xC000,7|((addrreg&0x60)>>2)|((addrreg&0x100)>>3)); |
| 38 | setmirror(((addrreg&2)>>1)^1); |
| 39 | } |
| 40 | |
| 41 | static DECLFW(BMCT262Write) |
| 42 | { |
| 43 | if(busy||(A==0x8000)) |
| 44 | datareg=V; |
| 45 | else |
| 46 | { |
| 47 | addrreg=A; |
| 48 | busy=1; |
| 49 | } |
| 50 | Sync(); |
| 51 | } |
| 52 | |
| 53 | static void BMCT262Power(void) |
| 54 | { |
| 55 | setchr8(0); |
| 56 | SetWriteHandler(0x8000,0xFFFF,BMCT262Write); |
| 57 | SetReadHandler(0x8000,0xFFFF,CartBR); |
| 58 | busy=0; |
| 59 | addrreg=0; |
| 60 | datareg=0; |
| 61 | Sync(); |
| 62 | } |
| 63 | |
| 64 | static void BMCT262Reset(void) |
| 65 | { |
| 66 | busy=0; |
| 67 | addrreg=0; |
| 68 | datareg=0; |
| 69 | Sync(); |
| 70 | } |
| 71 | |
| 72 | static void BMCT262Restore(int version) |
| 73 | { |
| 74 | Sync(); |
| 75 | } |
| 76 | |
| 77 | void BMCT262_Init(CartInfo *info) |
| 78 | { |
| 79 | info->Power=BMCT262Power; |
| 80 | info->Reset=BMCT262Reset; |
| 81 | GameStateRestore=BMCT262Restore; |
| 82 | AddExState(&StateRegs, ~0, 0, 0); |
| 83 | } |