| 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r |
| 19 | *\r |
| 20 | * Super Bros. Pocker Mali (VRC4 mapper)\r |
| 21 | */\r |
| 22 | \r |
| 23 | #include "mapinc.h"\r |
| 24 | \r |
| 25 | static uint8 IRQCount;//, IRQPre;\r |
| 26 | static uint8 IRQa;\r |
| 27 | static uint8 prg_reg[2];\r |
| 28 | static uint8 chr_reg[8];\r |
| 29 | static uint8 mirr;\r |
| 30 | \r |
| 31 | static SFORMAT StateRegs[]=\r |
| 32 | {\r |
| 33 | {&IRQCount, 1, "IRQC"},\r |
| 34 | {&IRQa, 1, "IRQA"},\r |
| 35 | {prg_reg, 2, "PRG"},\r |
| 36 | {chr_reg, 8, "CHR"},\r |
| 37 | {&mirr, 1, "MIRR"},\r |
| 38 | {0}\r |
| 39 | };\r |
| 40 | \r |
| 41 | /*\r |
| 42 | static void UNLAX5705IRQ(void)\r |
| 43 | {\r |
| 44 | if(IRQa)\r |
| 45 | {\r |
| 46 | IRQCount++;\r |
| 47 | if(IRQCount>=238)\r |
| 48 | {\r |
| 49 | X6502_IRQBegin(FCEU_IQEXT);\r |
| 50 | // IRQa=0;\r |
| 51 | }\r |
| 52 | }\r |
| 53 | }*/\r |
| 54 | \r |
| 55 | static void Sync(void)\r |
| 56 | {\r |
| 57 | setprg8(0x8000,prg_reg[0]);\r |
| 58 | setprg8(0xA000,prg_reg[1]);\r |
| 59 | setprg8(0xC000,~1);\r |
| 60 | setprg8(0xE000,~0);\r |
| 61 | int i;\r |
| 62 | for(i=0; i<8; i++)\r |
| 63 | setchr1(i<<10,chr_reg[i]); \r |
| 64 | setmirror(mirr^1); \r |
| 65 | }\r |
| 66 | \r |
| 67 | static DECLFW(UNLAX5705Write)\r |
| 68 | {\r |
| 69 | // if((A>=0xA008)&&(A<=0xE003))\r |
| 70 | // {\r |
| 71 | // int ind=(((A>>11)-6)|(A&1))&7;\r |
| 72 | // int sar=((A&2)<<1);\r |
| 73 | // chr_reg[ind]=(chr_reg[ind]&(0xF0>>sar))|((V&0x0F)<<sar);\r |
| 74 | // SyncChr();\r |
| 75 | // }\r |
| 76 | // else \r |
| 77 | switch(A&0xF00F)\r |
| 78 | {\r |
| 79 | case 0x8000: prg_reg[0]=((V&2)<<2)|((V&8)>>2)|(V&5); break; // EPROM dump have mixed PRG and CHR banks, data lines to mapper seems to be mixed\r |
| 80 | case 0x8008: mirr=V&1; break;\r |
| 81 | case 0xA000: prg_reg[1]=((V&2)<<2)|((V&8)>>2)|(V&5); break;\r |
| 82 | case 0xA008: chr_reg[0]=(chr_reg[0]&0xF0)|(V&0x0F); break;\r |
| 83 | case 0xA009: chr_reg[0]=(chr_reg[0]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;\r |
| 84 | case 0xA00A: chr_reg[1]=(chr_reg[1]&0xF0)|(V&0x0F); break;\r |
| 85 | case 0xA00B: chr_reg[1]=(chr_reg[1]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;\r |
| 86 | case 0xC000: chr_reg[2]=(chr_reg[2]&0xF0)|(V&0x0F); break;\r |
| 87 | case 0xC001: chr_reg[2]=(chr_reg[2]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;\r |
| 88 | case 0xC002: chr_reg[3]=(chr_reg[3]&0xF0)|(V&0x0F); break;\r |
| 89 | case 0xC003: chr_reg[3]=(chr_reg[3]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;\r |
| 90 | case 0xC008: chr_reg[4]=(chr_reg[4]&0xF0)|(V&0x0F); break;\r |
| 91 | case 0xC009: chr_reg[4]=(chr_reg[4]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;\r |
| 92 | case 0xC00A: chr_reg[5]=(chr_reg[5]&0xF0)|(V&0x0F); break;\r |
| 93 | case 0xC00B: chr_reg[5]=(chr_reg[5]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;\r |
| 94 | case 0xE000: chr_reg[6]=(chr_reg[6]&0xF0)|(V&0x0F); break;\r |
| 95 | case 0xE001: chr_reg[6]=(chr_reg[6]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;\r |
| 96 | case 0xE002: chr_reg[7]=(chr_reg[7]&0xF0)|(V&0x0F); break;\r |
| 97 | case 0xE003: chr_reg[7]=(chr_reg[7]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;\r |
| 98 | // case 0x800A: X6502_IRQEnd(FCEU_IQEXT); IRQa=0; break;\r |
| 99 | // case 0xE00B: X6502_IRQEnd(FCEU_IQEXT); IRQa=IRQCount=V; /*if(scanline<240) IRQCount-=8; else IRQCount+=4;*/ break;\r |
| 100 | }\r |
| 101 | Sync();\r |
| 102 | }\r |
| 103 | \r |
| 104 | static void UNLAX5705Power(void)\r |
| 105 | {\r |
| 106 | Sync();\r |
| 107 | SetReadHandler(0x8000,0xFFFF,CartBR);\r |
| 108 | SetWriteHandler(0x8000,0xFFFF,UNLAX5705Write);\r |
| 109 | }\r |
| 110 | \r |
| 111 | static void StateRestore(int version)\r |
| 112 | {\r |
| 113 | Sync();\r |
| 114 | }\r |
| 115 | \r |
| 116 | void UNLAX5705_Init(CartInfo *info)\r |
| 117 | {\r |
| 118 | info->Power=UNLAX5705Power;\r |
| 119 | // GameHBIRQHook=UNLAX5705IRQ;\r |
| 120 | GameStateRestore=StateRestore;\r |
| 121 | AddExState(&StateRegs, ~0, 0, 0);\r |
| 122 | }\r |