| 1 | /* FCE Ultra - NES/Famicom Emulator\r |
| 2 | *\r |
| 3 | * Copyright notice for this file:\r |
| 4 | * Copyright (C) 2002 Xodnizel\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 FFEmode;\r |
| 24 | \r |
| 25 | #define FVRAM_BANK8(A,V) {VPage[0]=VPage[1]=VPage[2]=VPage[3]=VPage[4]=VPage[5]=VPage[6]=VPage[7]=V?&MapperExRAM[(V)<<13]-(A):&CHRRAM[(V)<<13]-(A);CHRBankList[0]=((V)<<3);CHRBankList[1]=((V)<<3)+1;CHRBankList[2]=((V)<<3)+2;CHRBankList[3]=((V)<<3)+3;CHRBankList[4]=((V)<<3)+4;CHRBankList[5]=((V)<<3)+5;CHRBankList[6]=((V)<<3)+6;CHRBankList[7]=((V)<<3)+7;PPUCHRRAM=0xFF;}\r |
| 26 | \r |
| 27 | static void FP_FASTAPASS(1) FFEIRQHook(int a)\r |
| 28 | {\r |
| 29 | if(IRQa)\r |
| 30 | {\r |
| 31 | IRQCount+=a;\r |
| 32 | if(IRQCount>=0x10000)\r |
| 33 | {\r |
| 34 | X6502_IRQBegin(FCEU_IQEXT);\r |
| 35 | IRQa=0;\r |
| 36 | IRQCount=0;\r |
| 37 | }\r |
| 38 | }\r |
| 39 | }\r |
| 40 | \r |
| 41 | DECLFW(Mapper6_write)\r |
| 42 | {\r |
| 43 | if(A<0x8000)\r |
| 44 | {\r |
| 45 | switch(A){\r |
| 46 | case 0x42FF:MIRROR_SET((V>>4)&1);break;\r |
| 47 | case 0x42FE:onemir((V>>3)&2); FFEmode=V&0x80;break;\r |
| 48 | case 0x4501:IRQa=0;X6502_IRQEnd(FCEU_IQEXT);break;\r |
| 49 | case 0x4502:IRQCount&=0xFF00;IRQCount|=V;break;\r |
| 50 | case 0x4503:IRQCount&=0xFF;IRQCount|=V<<8;IRQa=1;break;\r |
| 51 | }\r |
| 52 | } else {\r |
| 53 | switch (FFEmode)\r |
| 54 | {\r |
| 55 | case 0x80: setchr8(V); break;\r |
| 56 | default: ROM_BANK16(0x8000,V>>2);\r |
| 57 | FVRAM_BANK8(0x0000,V&3);\r |
| 58 | }\r |
| 59 | }\r |
| 60 | }\r |
| 61 | void Mapper6_StateRestore(int version)\r |
| 62 | {\r |
| 63 | int x;\r |
| 64 | for(x=0;x<8;x++)\r |
| 65 | if(PPUCHRRAM&(1<<x))\r |
| 66 | {\r |
| 67 | if(CHRBankList[x]>7)\r |
| 68 | VPage[x]=&MapperExRAM[(CHRBankList[x]&31)*0x400]-(x*0x400);\r |
| 69 | else VPage[x]=&CHRRAM[(CHRBankList[x]&7)*0x400]-(x*0x400);\r |
| 70 | }\r |
| 71 | }\r |
| 72 | void Mapper6_init(void)\r |
| 73 | {\r |
| 74 | MapIRQHook=FFEIRQHook;\r |
| 75 | ROM_BANK16(0xc000,7);\r |
| 76 | \r |
| 77 | SetWriteHandler(0x4020,0x5fff,Mapper6_write);\r |
| 78 | SetWriteHandler(0x8000,0xffff,Mapper6_write);\r |
| 79 | MapStateRestore=Mapper6_StateRestore;\r |
| 80 | }\r |