X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=boards%2F8237.c;h=3c401e66488e3c4068168e5aabdd53e00bd9c0f4;hb=0d6a66c2a80f50ae51327cd406f9df14d99ad02e;hp=5b4e2df19f85266c62495cd88d4c1bae155fcb47;hpb=d97315ac0bca825d2d50a44453bc5652946e2c67;p=fceu.git diff --git a/boards/8237.c b/boards/8237.c index 5b4e2df..3c401e6 100644 --- a/boards/8237.c +++ b/boards/8237.c @@ -1,7 +1,7 @@ /* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: - * Copyright (C) 2005 CaH4e3 + * Copyright (C) 2011 CaH4e3 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,52 +16,153 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Super Game (Sugar Softec) protected mapper + * Pocahontas 2 (Unl) [U][!], etc. + * TODO: 9in1 LION KING HANGS! */ #include "mapinc.h" #include "mmc3.h" static uint8 cmdin; -static uint8 UNL8237_perm[8] = {0, 2, 6, 1, 7, 3, 4, 5}; + +static uint8 regperm[8][8] = + { + {0, 1, 2, 3, 4, 5, 6, 7}, + {0, 2, 6, 1, 7, 3, 4, 5}, + {0, 5, 4, 1, 7, 2, 6, 3}, // unused + {0, 6, 3, 7, 5, 2, 4, 1}, + {0, 2, 5, 3, 6, 1, 7, 4}, + {0, 1, 2, 3, 4, 5, 6, 7}, // empty + {0, 1, 2, 3, 4, 5, 6, 7}, // empty + {0, 1, 2, 3, 4, 5, 6, 7}, // empty + }; + +static uint8 adrperm[8][8] = + { + {0, 1, 2, 3, 4, 5, 6, 7}, + {3, 2, 0, 4, 1, 5, 6, 7}, + {0, 1, 2, 3, 4, 5, 6, 7}, // unused + {5, 0, 1, 2, 3, 7, 6, 4}, + {3, 1, 0, 5, 2, 4, 6, 7}, + {0, 1, 2, 3, 4, 5, 6, 7}, // empty + {0, 1, 2, 3, 4, 5, 6, 7}, // empty + {0, 1, 2, 3, 4, 5, 6, 7}, // empty + }; static void UNL8237CW(uint32 A, uint8 V) { - setchr1(A,((EXPREGS[1]&4)<<6)|V); + if(EXPREGS[0]&0x40) + setchr1(A,((EXPREGS[1]&0xc)<<6)|(V&0x7F)|((EXPREGS[1]&0x20)<<2)); + else + setchr1(A,((EXPREGS[1]&0xc)<<6)|V); } static void UNL8237PW(uint32 A, uint8 V) { - if(EXPREGS[0]&0x80) + if(EXPREGS[0]&0x40) { - if(EXPREGS[0]&0x20) - setprg32(0x8000,(EXPREGS[0]&0xF)>>1); + uint8 sbank = (EXPREGS[1]&0x10); + if(EXPREGS[0]&0x80) + { + uint8 bank = ((EXPREGS[1]&3)<<4)|(EXPREGS[0]&0x7)|(sbank>>1); + if(EXPREGS[0]&0x20) + setprg32(0x8000,bank>>1); + else + { + setprg16(0x8000,bank); + setprg16(0xC000,bank); + } + } else + setprg8(A,((EXPREGS[1]&3)<<5)|(V&0x0F)|sbank); + } + else + { + if(EXPREGS[0]&0x80) { - setprg16(0x8000,(EXPREGS[0]&0x1F)); - setprg16(0xC000,(EXPREGS[0]&0x1F)); + uint8 bank = ((EXPREGS[1]&3)<<4)|(EXPREGS[0]&0xF); + if(EXPREGS[0]&0x20) + setprg32(0x8000,bank>>1); + else + { + setprg16(0x8000,bank); + setprg16(0xC000,bank); + } } + else + setprg8(A,((EXPREGS[1]&3)<<5)|(V&0x1F)); } +} + +static void UNL8237ACW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x40) + setchr1(A,((EXPREGS[1]&0xE)<<7)|(V&0x7F)|((EXPREGS[1]&0x20)<<2)); else - setprg8(A,V&0x3F); + setchr1(A,((EXPREGS[1]&0xE)<<7)|V); } +static void UNL8237APW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x40) + { + uint8 sbank = (EXPREGS[1]&0x10); + if(EXPREGS[0]&0x80) + { + uint8 bank = ((EXPREGS[1]&3)<<4)|((EXPREGS[1]&8)<<3)|(EXPREGS[0]&0x7)|(sbank>>1); + if(EXPREGS[0]&0x20) { +// FCEU_printf("8000:%02X\n",bank>>1); + setprg32(0x8000,bank>>1); + } + else + { +// FCEU_printf("8000-C000:%02X\n",bank); + setprg16(0x8000,bank); + setprg16(0xC000,bank); + } + } + else { +// FCEU_printf("%04x:%02X\n",A,((EXPREGS[1]&3)<<5)|((EXPREGS[1]&8)<<4)|(V&0x0F)|sbank); + setprg8(A,((EXPREGS[1]&3)<<5)|((EXPREGS[1]&8)<<4)|(V&0x0F)|sbank); + } + } + else + { + if(EXPREGS[0]&0x80) + { + uint8 bank = ((EXPREGS[1]&3)<<4)|((EXPREGS[1]&8)<<3)|(EXPREGS[0]&0xF); + if(EXPREGS[0]&0x20) { +// FCEU_printf("8000:%02X\n",(bank>>1)&0x07); + setprg32(0x8000,bank>>1); + } + else + { +// FCEU_printf("8000-C000:%02X\n",bank&0x0F); + setprg16(0x8000,bank); + setprg16(0xC000,bank); + } + } + else { +// FCEU_printf("%04X:%02X\n",A,(((EXPREGS[1]&3)<<5)|((EXPREGS[1]&8)<<4)|(V&0x1F))&0x1F); + setprg8(A,((EXPREGS[1]&3)<<5)|((EXPREGS[1]&8)<<4)|(V&0x1F)); + } + } +} static DECLFW(UNL8237Write) { - if((A&0xF000)==0xF000) - IRQCount=V; - else if((A&0xF000)==0xE000) - X6502_IRQEnd(FCEU_IQEXT); - else switch(A&0xE001) + uint8 dat = V; + uint8 adr = adrperm[EXPREGS[2]][((A>>12)&6)|(A&1)]; + uint16 addr = (adr & 1)|((adr & 6)<<12)|0x8000; + if(adr < 4) { - case 0x8000: setmirror(((V|(V>>7))&1)^1); break; - case 0xA000: MMC3_CMDWrite(0x8000,(V&0xC0)|(UNL8237_perm[V&7])); cmdin=1; break; - case 0xC000: if(cmdin) - { - MMC3_CMDWrite(0x8001,V); - cmdin=0; - } - break; + if(!adr) + dat = (dat & 0xC0)|(regperm[EXPREGS[2]][dat & 7]); + MMC3_CMDWrite(addr,dat); } + else + MMC3_IRQWrite(addr,dat); } static DECLFW(UNL8237ExWrite) @@ -69,14 +170,15 @@ static DECLFW(UNL8237ExWrite) switch(A) { case 0x5000: EXPREGS[0]=V; FixMMC3PRG(MMC3_cmd); break; - case 0x5001: EXPREGS[1]=V; FixMMC3CHR(MMC3_cmd); break; + case 0x5001: EXPREGS[1]=V; FixMMC3PRG(MMC3_cmd); FixMMC3CHR(MMC3_cmd); break; + case 0x5007: EXPREGS[2]=V; break; } } static void UNL8237Power(void) { - IRQa=1; - EXPREGS[0]=EXPREGS[1]=0; + EXPREGS[0]=EXPREGS[2]=0; + EXPREGS[1]=3; GenMMC3Power(); SetWriteHandler(0x8000,0xFFFF,UNL8237Write); SetWriteHandler(0x5000,0x7FFF,UNL8237ExWrite); @@ -89,5 +191,15 @@ void UNL8237_Init(CartInfo *info) pwrap=UNL8237PW; info->Power=UNL8237Power; AddExState(EXPREGS, 3, 0, "EXPR"); - AddExState(&cmdin, 1, 0, "CMDIN"); + AddExState(&cmdin, 1, 0, "CMDI"); +} + +void UNL8237A_Init(CartInfo *info) +{ + GenMMC3_Init(info, 256, 256, 0, 0); + cwrap=UNL8237ACW; + pwrap=UNL8237APW; + info->Power=UNL8237Power; + AddExState(EXPREGS, 3, 0, "EXPR"); + AddExState(&cmdin, 1, 0, "CMDI"); }