| 1 | /* FCE Ultra - NES/Famicom Emulator\r |
| 2 | *\r |
| 3 | * Copyright notice for this file:\r |
| 4 | * Copyright (C) 2007 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\r |
| 19 | * Super Mario Bros 2 J alt version\r |
| 20 | * as well as "Voleyball" FDS conversion, bank layot is similar but no bankswitching and CHR ROM present\r |
| 21 | */\r |
| 22 | \r |
| 23 | #include "mapinc.h"\r |
| 24 | \r |
| 25 | static uint8 prg, IRQa;\r |
| 26 | static uint16 IRQCount;\r |
| 27 | \r |
| 28 | static SFORMAT StateRegs[]=\r |
| 29 | {\r |
| 30 | {&prg, 1, "PRG"},\r |
| 31 | {&IRQa, 1, "IRQA"},\r |
| 32 | {&IRQCount, 2, "IRQC"},\r |
| 33 | {0}\r |
| 34 | };\r |
| 35 | \r |
| 36 | static void Sync(void)\r |
| 37 | {\r |
| 38 | setprg4r(1,0x5000,1);\r |
| 39 | setprg8r(1,0x6000,1);\r |
| 40 | setprg32(0x8000,prg);\r |
| 41 | setchr8(0);\r |
| 42 | }\r |
| 43 | \r |
| 44 | static DECLFW(UNLSMB2JWrite)\r |
| 45 | {\r |
| 46 | if(A==0x4022)\r |
| 47 | {\r |
| 48 | prg=V&1;\r |
| 49 | Sync();\r |
| 50 | }\r |
| 51 | if(A==0x4122)\r |
| 52 | {\r |
| 53 | IRQa=V;\r |
| 54 | IRQCount=0;\r |
| 55 | X6502_IRQEnd(FCEU_IQEXT);\r |
| 56 | }\r |
| 57 | }\r |
| 58 | \r |
| 59 | static void UNLSMB2JPower(void)\r |
| 60 | {\r |
| 61 | prg=~0;\r |
| 62 | Sync();\r |
| 63 | SetReadHandler(0x5000,0x7FFF,CartBR);\r |
| 64 | SetReadHandler(0x8000,0xFFFF,CartBR);\r |
| 65 | SetWriteHandler(0x4020,0xffff,UNLSMB2JWrite);\r |
| 66 | }\r |
| 67 | \r |
| 68 | static void UNLSMB2JReset(void)\r |
| 69 | { \r |
| 70 | prg=~0;\r |
| 71 | Sync();\r |
| 72 | }\r |
| 73 | \r |
| 74 | static void UNLSMB2JIRQHook(int a)\r |
| 75 | {\r |
| 76 | if(IRQa)\r |
| 77 | {\r |
| 78 | IRQCount+=a*3;\r |
| 79 | if((IRQCount>>12)==IRQa)\r |
| 80 | X6502_IRQBegin(FCEU_IQEXT);\r |
| 81 | }\r |
| 82 | }\r |
| 83 | \r |
| 84 | static void StateRestore(int version)\r |
| 85 | {\r |
| 86 | Sync();\r |
| 87 | }\r |
| 88 | \r |
| 89 | void UNLSMB2J_Init(CartInfo *info)\r |
| 90 | {\r |
| 91 | info->Reset=UNLSMB2JReset;\r |
| 92 | info->Power=UNLSMB2JPower;\r |
| 93 | MapIRQHook=UNLSMB2JIRQHook;\r |
| 94 | GameStateRestore=StateRestore;\r |
| 95 | AddExState(&StateRegs, ~0, 0, 0);\r |
| 96 | }\r |