bandai eeprom emulation, enjoy

This commit is contained in:
CaH4e3 2013-05-08 15:41:12 +00:00
parent abcb50e2e3
commit 95b120fcf4
4 changed files with 200 additions and 56 deletions

View File

@ -22,14 +22,9 @@
*
*/
//Famicom Jump 2 should get transformed to m153
//All other games are not supporting EEPROM saving right now.
//We may need to distinguish between 16 and 159 in order to know the EEPROM configuration.
//Until then, we just return 0x00 from the EEPROM read
#include "mapinc.h"
static uint8 reg[16], is153;
static uint8 reg[16], is153, x24c02;
static uint8 IRQa;
static int16 IRQCount, IRQLatch;
@ -41,22 +36,134 @@ static SFORMAT StateRegs[] =
{ reg, 16, "REGS" },
{ &IRQa, 1, "IRQA" },
{ &IRQCount, 2, "IRQC" },
{ &IRQLatch, 2, "IRQL" }, // need for Famicom Jump II - Saikyou no 7 Nin (J) [!]
{ &IRQLatch, 2, "IRQL" }, // need for Famicom Jump II - Saikyou no 7 Nin (J) [!]
{ 0 }
};
static void BandaiIRQHook(int a) {
if (IRQa) {
IRQCount -= a;
if (IRQCount < 0) {
X6502_IRQBegin(FCEU_IQEXT);
IRQa = 0;
IRQCount = -1;
}
}
// x24C0x interface
#define X24C0X_STANDBY 0
#define X24C0X_ADDRESS 1
#define X24C0X_WORD 2
#define X24C0X_READ 3
#define X24C0X_WRITE 4
static uint8 x24c0x_data[256], x24c0x_state;
static uint8 x24c0x_addr, x24c0x_word, x24c0x_latch, x24c0x_bitcount;
static uint8 x24c0x_sda, x24c0x_scl, x24c0x_out, x24c0x_oe;
static SFORMAT x24c01StateRegs[] =
{
{ x24c0x_data, 128, "DATA" },
{ &x24c0x_addr, 1, "ADDR" },
{ &x24c0x_word, 1, "WORD" },
{ &x24c0x_latch, 1, "LATC" },
{ &x24c0x_bitcount, 1, "BITC" },
{ &x24c0x_sda, 1, "SDA" },
{ &x24c0x_scl, 1, "SCL" },
{ &x24c0x_out, 1, "OUT" },
{ &x24c0x_oe, 1, "OE" },
{ &x24c0x_state, 1, "STAT" },
{ 0 }
};
static void x24c0x_init() {
x24c0x_addr = x24c0x_word = x24c0x_latch = x24c0x_bitcount = x24c0x_sda = x24c0x_scl = x24c0x_oe = 0;
x24c0x_state = X24C0X_STANDBY;
}
static void BandaiSync(void) {
static void x24c0x_write(uint8 data) {
uint8 sda = (data >> 6) & 1;
uint8 scl = (data >> 5) & 1;
x24c0x_oe = (data >> 7);
if(x24c0x_scl && scl) {
if(x24c0x_sda && !sda) { // START
x24c0x_state = X24C0X_ADDRESS;
x24c0x_bitcount = 0;
x24c0x_addr = 0;
} else if(!x24c0x_sda && sda) { //STOP
x24c0x_state = X24C0X_STANDBY;
}
} else if(!x24c0x_scl && scl) { // RISING EDGE
switch(x24c0x_state) {
case X24C0X_ADDRESS:
if(x24c0x_bitcount < 7) {
x24c0x_addr <<= 1;
x24c0x_addr |= sda;
} else {
if(!x24c02) // X24C01 mode
x24c0x_word = x24c0x_addr;
if(sda) { // READ COMMAND
x24c0x_state = X24C0X_READ;
} else { // WRITE COMMAND
if(x24c02) // X24C02 mode
x24c0x_state = X24C0X_WORD;
else
x24c0x_state = X24C0X_WRITE;
}
}
x24c0x_bitcount++;
break;
case X24C0X_WORD:
if(x24c0x_bitcount == 8) { // ACK
x24c0x_word = 0;
x24c0x_out = 0;
} else { // WORD ADDRESS INPUT
x24c0x_word <<= 1;
x24c0x_word |= sda;
if(x24c0x_bitcount == 16) { // END OF ADDRESS INPUT
x24c0x_bitcount = 7;
x24c0x_state = X24C0X_WRITE;
}
}
x24c0x_bitcount++;
break;
case X24C0X_READ:
if (x24c0x_bitcount == 8) { // ACK
x24c0x_out = 0;
x24c0x_latch = x24c0x_data[x24c0x_word];
x24c0x_bitcount = 0;
} else { // REAL OUTPUT
x24c0x_out = x24c0x_latch >> 7;
x24c0x_latch <<= 1;
x24c0x_bitcount++;
if(x24c0x_bitcount == 8) {
x24c0x_word++;
x24c0x_word &= 0xff;
}
}
break;
case X24C0X_WRITE:
if (x24c0x_bitcount == 8) { // ACK
x24c0x_out = 0;
x24c0x_latch = 0;
x24c0x_bitcount = 0;
} else { // REAL INPUT
x24c0x_latch <<= 1;
x24c0x_latch |= sda;
x24c0x_bitcount++;
if(x24c0x_bitcount == 8) {
x24c0x_data[x24c0x_word] = x24c0x_latch;
x24c0x_word++;
x24c0x_word &= 0xff;
}
}
break;
}
}
x24c0x_sda = sda;
x24c0x_scl = scl;
}
static uint8 x24c0x_read() {
return x24c0x_out << 4;
}
//
static void Sync(void) {
if (is153) {
int base = (reg[0] & 1) << 4;
setchr8(0);
@ -80,36 +187,71 @@ static DECLFW(BandaiWrite) {
A &= 0x0F;
if (A < 0x0A) {
reg[A & 0x0F] = V;
BandaiSync();
Sync();
} else
switch (A) {
case 0x0A: X6502_IRQEnd(FCEU_IQEXT); IRQa = V & 1; IRQCount = IRQLatch; break;
case 0x0B: IRQLatch &= 0xFF00; IRQLatch |= V; break;
case 0x0C: IRQLatch &= 0xFF; IRQLatch |= V << 8; break;
case 0x0D: break; // Serial EEPROM control port
case 0x0D: x24c0x_write(V); break;
}
}
static DECLFR(BandaiRead) {
return 0xef; // TODO: EEPROM
return (X.DB & 0xEF) | x24c0x_read();
}
static void BandaiIRQHook(int a) {
if (IRQa) {
IRQCount -= a;
if (IRQCount < 0) {
X6502_IRQBegin(FCEU_IQEXT);
IRQa = 0;
IRQCount = -1;
}
}
}
static void BandaiPower(void) {
BandaiSync();
IRQa = 0;
x24c0x_init();
Sync();
SetReadHandler(0x6000, 0x7FFF, BandaiRead);
SetReadHandler(0x8000, 0xFFFF, CartBR);
SetWriteHandler(0x6000, 0xFFFF, BandaiWrite);
}
static void StateRestore(int version) {
BandaiSync();
Sync();
}
void Mapper16_Init(CartInfo *info) {
x24c02 = 1;
is153 = 0;
info->Power = BandaiPower;
MapIRQHook = BandaiIRQHook;
info->battery = 1;
info->SaveGame[0] = x24c0x_data;
info->SaveGameLen[0] = 256;
GameStateRestore = StateRestore;
AddExState(&x24c01StateRegs, ~0, 0, 0);
AddExState(&StateRegs, ~0, 0, 0);
}
void Mapper159_Init(CartInfo *info) {
x24c02 = 0;
is153 = 0;
info->Power = BandaiPower;
MapIRQHook = BandaiIRQHook;
info->battery = 1;
info->SaveGame[0] = x24c0x_data;
info->SaveGameLen[0] = 128;
GameStateRestore = StateRestore;
AddExState(&x24c01StateRegs, ~0, 0, 0);
AddExState(&StateRegs, ~0, 0, 0);
}
@ -121,7 +263,7 @@ void Mapper16_Init(CartInfo *info) {
// last CHR address read).
static void M153Power(void) {
BandaiSync();
Sync();
setprg8r(0x10, 0x6000, 0);
SetReadHandler(0x6000, 0x7FFF, CartBR);
SetWriteHandler(0x6000, 0x7FFF, CartBW);
@ -296,12 +438,13 @@ static DECLFR(BarcodeRead) {
}
static void M157Power(void) {
IRQa = 0;
BarcodeData[0] = 0xFF;
BarcodeReadPos = 0;
BarcodeOut = 0;
BarcodeCycleCount = 0;
BandaiSync();
Sync();
SetWriteHandler(0x6000, 0xFFFF, BandaiWrite);
SetReadHandler(0x6000, 0x7FFF, BarcodeRead);

View File

@ -5,7 +5,7 @@
{0x82f204ae, -1, 1}, /* Liang Shan Ying Xiong (NJ023) (Ch) [!] */
{0x684afccd, -1, 1}, /* Space Hunter (J) */
{0xad9c63e2, -1, 1}, /* Space Shadow (J) */
{0xe1526228, -1, 1}, /* Quest of Ki */
{0xe1526228, -1, 1}, /* Quest of Ki */
{0xaf5d7aa2, -1, 0}, /* Clu Clu Land */
{0xcfb224e6, -1, 1}, /* Dragon Ninja (J) [p1][!].nes */
{0x4f2f1846, -1, 1}, /* Famista '89 - Kaimaku Han!! (J) */
@ -78,19 +78,19 @@
{0xbe939fce, 9, 1}, /* Punchout*/
{0x345d3a1a, 11, 1}, /* Castle of Deceit */
{0x5e66eaea, 13, 1}, /* Videomation */
{0xcd373baa, 14, -1}, /* Samurai Spirits (Rex Soft) */
{0xcd373baa, 14, -1}, /* Samurai Spirits (Rex Soft) */
{0xbfc7a2e9, 16, 8},
{0x6e68e31a, 16, 8}, /* Dragon Ball 3*/
{0x183859d2, 16, -1},
{0x33b899c9, 16, -1}, /* Dragon Ball - Dai Maou Fukkatsu (J) [!] */
{0x286fcd20, 23, -1}, /* Ganbare Goemon Gaiden 2 - Tenka no Zaihou (J) [!] */
{0xe4a291ce, 23, -1}, /* World Hero (Unl) [!] */
{0x51e9cd33, 23, -1}, /* World Hero (Unl) [b1] */
{0x105dd586, 27, -1}, /* Mi Hun Che variations... */
{0xbc9bb6c1, 27, -1}, /* -- */
{0x43753886, 27, -1}, /* -- */
{0x5b3de3d1, 27, -1}, /* -- */
{0x511e73f8, 27, -1}, /* -- */
{0xa262a81f, 16, -1}, /* Rokudenashi Blues (J) */
{0x286fcd20, 23, -1}, /* Ganbare Goemon Gaiden 2 - Tenka no Zaihou (J) [!] */
{0xe4a291ce, 23, -1}, /* World Hero (Unl) [!] */
{0x51e9cd33, 23, -1}, /* World Hero (Unl) [b1] */
{0x105dd586, 27, -1}, /* Mi Hun Che variations... */
{0xbc9bb6c1, 27, -1}, /* -- */
{0x43753886, 27, -1}, /* -- */
{0x5b3de3d1, 27, -1}, /* -- */
{0x511e73f8, 27, -1}, /* -- */
{0x5555fca3, 32, 8},
{0x283ad224, 32, 8}, /* Ai Sensei no Oshiete */
{0x243a8735, 32, 0x10|4}, /* Major League */
@ -101,7 +101,7 @@
{0xf46ef39a, 37, -1}, /* Super Mario Bros. + Tetris + Nintendo World Cup (E) [!] */
{0x7ccb12a3, 43, -1}, /* SMB2j */
{0x6c71feae, 45, -1}, /* Kunio 8-in-1 */
{0xe2c94bc2, 48, -1}, /* Super Bros 8 (Unl) [!] */
{0xe2c94bc2, 48, -1}, /* Super Bros 8 (Unl) [!] */
{0xaebd6549, 48, 8}, /* Bakushou!! Jinsei Gekijou 3 */
{0x6cdc0cd9, 48, 8}, /* Bubble Bobble 2 */
{0x99c395f9, 48, 8}, /* Captain Saver */
@ -180,14 +180,14 @@
{0x0be0a328, 157, 8}, /* Datach SD Gundam Wars */
{0x5b457641, 157, 8}, /* Datach Ultraman Club */
{0xf51a7f46, 157, 8}, /* Datach Yuu Yuu Hakusho */
{0xb7f28915, 159, -1}, /* Magical Taruruuto-kun 2 - Mahou Daibouken (J) */
{0xa262a81f, 159, -1}, /* Rokudenashi Blues (J) */
{0xe170404c, 159, -1}, /* SD Gundam Gaiden - Knight Gundam Monogatari (J) (V1.0) [!] */
{0x276ac722, 159, -1}, /* SD Gundam Gaiden - Knight Gundam Monogatari (J) (V1.1) [!] */
{0xb049a8c4, 159, -1}, /* SD Gundam Gaiden - Knight Gundam Monogatari 2 - Hikari no Kishi (J) [!] */
{0xc2840372, 159, -1}, /* SD Gundam Gaiden - Knight Gundam Monogatari 3 - Densetsu no Kishi Dan (J) [!] */
{0x0cf42e69, 159, -1}, /* Magical Taruruuto-kun - Fantastic World!! (J) (V1.0) [!] */
{0xdcb972ce, 159, -1}, /* Magical Taruruuto-kun - Fantastic World!! (J) (V1.1) [!] */
{0xb7f28915, 159, -1}, /* Magical Taruruuto-kun 2 - Mahou Daibouken (J) */
{0x183859d2, 159, -1}, /* Dragon Ball Z - Kyoushuu! Saiya Jin (J) [!] */
{0x58152b42, 160, 1}, /* Pipe 5 (Sachen) */
{0x1c098942, 162, -1}, /* Xi You Ji Hou Zhuan (Ch) */
{0x1c098942, 162, -1}, /* Xi You Ji Hou Zhuan (Ch) */
{0x081caaff, 163, -1}, /* Commandos (Ch) */
{0x02c41438, 176, -1}, /* Xing He Zhan Shi (C) */
{0x558c0dc3, 178, -1}, /* Super 2in1 (unl)[!] {mapper unsupported} */
@ -200,7 +200,7 @@
{0xa9115bc1, 192, -1},
{0x4c7bbb0e, 192, -1},
{0x98c1cd4b, 192, -1}, /* Ying Lie Qun Xia Zhuan (Chinese) */
{0xee810d55, 192, -1}, /* You Ling Xing Dong (Ch) */
{0xee810d55, 192, -1}, /* You Ling Xing Dong (Ch) */
{0x442f1a29, 192, -1}, /* Young chivalry */
{0x637134e8, 193, 1}, /* Fighting Hero */
{0xa925226c, 194, -1}, /* Dai-2-Ji - Super Robot Taisen (As) */
@ -237,22 +237,22 @@
{0xd323b806, 210, 1}, /* Wagyan Land 3 */
{0xbd523011, 210, 0}, /* Dream Master */
{0x5daae69a, 211, -1}, /* Aladdin - Return of Jaffar, The (Unl) [!] */
{0x1ec1dfeb, 217, -1}, /* 255-in-1 (Cut version) [p1] */
{0x046d70cc, 217, -1}, /* 500-in-1 (Anim Splash, Alt Mapper)[p1][!] */
{0x12f86a4d, 217, -1}, /* 500-in-1 (Static Splash, Alt Mapper)[p1][!] */
{0xd09f778d, 217, -1}, /* 9999999-in-1 (Static Splash, Alt Mapper)[p1][!] */
{0x1ec1dfeb, 217, -1}, /* 255-in-1 (Cut version) [p1] */
{0x046d70cc, 217, -1}, /* 500-in-1 (Anim Splash, Alt Mapper)[p1][!] */
{0x12f86a4d, 217, -1}, /* 500-in-1 (Static Splash, Alt Mapper)[p1][!] */
{0xd09f778d, 217, -1}, /* 9999999-in-1 (Static Splash, Alt Mapper)[p1][!] */
{0x62ef6c79, 232, 8}, /* Quattro Sports -Aladdin */
{0x2705eaeb, 234, -1}, /* Maxi 15 */
{0x6f12afc5, 235, -1}, /* Golden Game 150-in-1 */
{0xfb2b6b10, 241, -1}, /* Fan Kong Jing Ying (Ch) */
{0xb5e83c9a, 241, -1}, /* Xing Ji Zheng Ba (Ch) */
{0x2537b3e6, 241, -1}, /* Dance Xtreme - Prima (Unl) */
{0x11611e89, 241, -1}, /* Darkseed (Unl) [p1] */
{0x81a37827, 241, -1}, /* Darkseed (Unl) [p1][b1] */
{0xc2730c30, 241, -1}, /* Deadly Towers (U) [!] */
{0x368c19a8, 241, -1}, /* LIKO Study Cartridge 3-in-1 (Unl) [!] */
{0xa21e675c, 241, -1}, /* Mashou (J) [!] */
{0x54d98b79, 241, -1}, /* Titanic 1912 (Unl) */
{0x2537b3e6, 241, -1}, /* Dance Xtreme - Prima (Unl) */
{0x11611e89, 241, -1}, /* Darkseed (Unl) [p1] */
{0x81a37827, 241, -1}, /* Darkseed (Unl) [p1][b1] */
{0xc2730c30, 241, -1}, /* Deadly Towers (U) [!] */
{0x368c19a8, 241, -1}, /* LIKO Study Cartridge 3-in-1 (Unl) [!] */
{0xa21e675c, 241, -1}, /* Mashou (J) [!] */
{0x54d98b79, 241, -1}, /* Titanic 1912 (Unl) */
{0x6bea1235, 245, -1}, /* MMC3 cart, but with nobanking applied to CHR-RAM, so let it be there */
{0x345ee51a, 245, -1}, /* DQ4c */
{0x57514c6c, 245, -1}, /* Yong Zhe Dou E Long - Dragon Quest VI (Ch) */

View File

@ -597,13 +597,13 @@ static BMAPPINGLocal bmap[] = {
{"S74LS374N", 150, S74LS374N_Init},
{"", 151, Mapper151_Init},
{"", 152, Mapper152_Init},
{"", 153, Mapper153_Init},
{"BANDAI SRAM", 153, Mapper153_Init}, // Bandai board 16 with SRAM instead of EEPROM
{"", 154, Mapper154_Init},
{"", 155, Mapper155_Init},
{"", 156, Mapper156_Init},
{"", 157, Mapper157_Init},
{"BANDAI BARCODE", 157, Mapper157_Init},
// {"", 158, Mapper158_Init},
{"BANDAI 24C01", 159, Mapper16_Init}, // Different type of EEPROM on bandai board
{"BANDAI 24C01", 159, Mapper159_Init}, // Different type of EEPROM on the bandai board
{"SA009", 160, SA009_Init},
// {"", 161, Mapper161_Init},
{"", 162, UNLFS304_Init},

View File

@ -188,6 +188,7 @@ void Mapper154_Init(CartInfo *);
void Mapper155_Init(CartInfo *);
void Mapper156_Init(CartInfo *);
void Mapper157_Init(CartInfo *);
void Mapper159_Init(CartInfo *);
void Mapper163_Init(CartInfo *);
void Mapper164_Init(CartInfo *);
void Mapper165_Init(CartInfo *);