Merge pull request #457 from NRS-NewRisingSun/mappers-16x
Mappers 162/163/164/558
This commit is contained in:
101
src/boards/162.c
Normal file
101
src/boards/162.c
Normal file
@@ -0,0 +1,101 @@
|
||||
/* FCE Ultra - NES/Famicom Emulator
|
||||
*
|
||||
* Copyright notice for this file:
|
||||
* Copyright (C) 2002 Xodnizel
|
||||
* Copyright (C) 2005 CaH4e3
|
||||
* Copyright (C) 2019 Libretro Team
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/* Waixing FS304 PCB */
|
||||
|
||||
#include "mapinc.h"
|
||||
#include "../ines.h"
|
||||
|
||||
static uint8 reg[4];
|
||||
static SFORMAT StateRegs[] =
|
||||
{
|
||||
{ reg, 4, "REGS" },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
static void sync()
|
||||
{
|
||||
setprg32(0x8000, reg[2] <<4 | reg[0] &0x0C /* PRG A17-A20 always normal from $5000 and $5200 */
|
||||
| ( reg[3] &0x04 ? 0x00 : 0x02) /* PRG A16 is 1 if $5300.2=0 */
|
||||
| ( reg[3] &0x04 ?(reg[0] &0x02): 0x00) /* PRG A16 is $5000.1 if %5300.2=1 */
|
||||
| ( reg[3] &0x01? 0x00 : reg[1] >>1 &0x01) /* PRG A15 is $5100.1 if $5300.0=0 */
|
||||
| (~reg[3] &0x04 && reg[3] &0x01? 0x01 : 0x00) /* PRG A15 is 1 if $5300.2=0 and $5300.0=1 */
|
||||
| ( reg[3] &0x04 && reg[3] &0x01?(reg[0] &0x01): 0x00) /* PRG A15 is $5000.0 if $5300.2=1 and $5300.0=1 */
|
||||
);
|
||||
setprg8r(0x10, 0x6000, 0);
|
||||
if (~reg[0] &0x80)
|
||||
setchr8(0);
|
||||
}
|
||||
|
||||
static void hblank(void) {
|
||||
if (reg[0] &0x80 && scanline <239)
|
||||
{ /* Actual hardware cannot look at the current scanline number, but instead latches PA09 on PA13 rises. This does not seem possible with the current PPU emulation however. */
|
||||
setchr4(0x0000, scanline >=127? 1: 0);
|
||||
setchr4(0x1000, scanline >=127? 1: 0);
|
||||
}
|
||||
else
|
||||
setchr8(0);
|
||||
}
|
||||
|
||||
static DECLFR(readReg)
|
||||
{
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
static DECLFW(writeReg)
|
||||
{
|
||||
reg[A >>8 &3] = V;
|
||||
sync();
|
||||
}
|
||||
|
||||
static void power(void)
|
||||
{
|
||||
memset(reg, 0, sizeof(reg));
|
||||
sync();
|
||||
SetReadHandler (0x5000, 0x57FF, readReg);
|
||||
SetWriteHandler(0x5000, 0x57FF, writeReg);
|
||||
SetReadHandler (0x6000, 0xFFFF, CartBR);
|
||||
SetWriteHandler(0x6000, 0x7FFF, CartBW);
|
||||
}
|
||||
|
||||
static void reset()
|
||||
{
|
||||
memset(reg, 0, sizeof(reg));
|
||||
sync();
|
||||
}
|
||||
|
||||
void Mapper162_Init (CartInfo *info)
|
||||
{
|
||||
uint32 WRAMSIZE = info->iNES2? (info->PRGRamSize + info->PRGRamSaveSize): 8192;
|
||||
info->Power = power;
|
||||
info->Reset = reset;
|
||||
GameHBIRQHook = hblank;
|
||||
AddExState(StateRegs, ~0, 0, 0);
|
||||
|
||||
uint8* WRAM = (uint8*) FCEU_gmalloc(WRAMSIZE);
|
||||
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
|
||||
FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM);
|
||||
if (info->battery) {
|
||||
info->SaveGame[0] = WRAM;
|
||||
info->SaveGameLen[0] = info->PRGRamSaveSize;
|
||||
}
|
||||
}
|
||||
106
src/boards/163.c
Normal file
106
src/boards/163.c
Normal file
@@ -0,0 +1,106 @@
|
||||
/* FCE Ultra - NES/Famicom Emulator
|
||||
*
|
||||
* Copyright notice for this file:
|
||||
* Copyright (C) 2002 Xodnizel
|
||||
* Copyright (C) 2005 CaH4e3
|
||||
* Copyright (C) 2019 Libretro Team
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/* Nanjing FC-001 PCB */
|
||||
|
||||
#include "mapinc.h"
|
||||
#include "../ines.h"
|
||||
|
||||
static uint8 reg[4];
|
||||
static SFORMAT StateRegs[] =
|
||||
{
|
||||
{ reg, 4, "REGS" },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
static void sync()
|
||||
{
|
||||
setprg32(0x8000, reg[2] <<4 | reg[0] &0xF | (reg[3] &0x04? 0x00: 0x03));
|
||||
setprg8r(0x10, 0x6000, 0);
|
||||
if (~reg[0] &0x80)
|
||||
setchr8(0);
|
||||
}
|
||||
|
||||
static void hblank(void) {
|
||||
if (reg[0] &0x80 && scanline <239)
|
||||
{ /* Actual hardware cannot look at the current scanline number, but instead latches PA09 on PA13 rises. This does not seem possible with the current PPU emulation however. */
|
||||
setchr4(0x0000, scanline >=127? 1: 0);
|
||||
setchr4(0x1000, scanline >=127? 1: 0);
|
||||
}
|
||||
else
|
||||
setchr8(0);
|
||||
}
|
||||
|
||||
static DECLFR(readReg)
|
||||
{
|
||||
return ~reg[1] &0x04;
|
||||
}
|
||||
|
||||
static DECLFW(writeReg)
|
||||
{
|
||||
uint8 index = A >>8 &3;
|
||||
|
||||
/* Swap bits of registers 0-2 again if the "swap bits" bit is set. Exclude register 2 on when PRG-ROM is 1 MiB. */
|
||||
if (reg[3] &0x01 && index <= (ROM_size == 64? 1: 2))
|
||||
V = V &~3 | V >>1 &1 | V <<1 &2;
|
||||
|
||||
if (A &1)
|
||||
{
|
||||
if (reg[1] &0x01 && ~V &0x01) reg[1] ^=0x04; /* If A0=1, flip feedback bit on falling edges of D0 */
|
||||
} /* If A0=0, write to register */
|
||||
else
|
||||
reg[index] = V;
|
||||
sync();
|
||||
}
|
||||
|
||||
static void power(void)
|
||||
{
|
||||
memset(reg, 0, sizeof(reg));
|
||||
sync();
|
||||
SetReadHandler (0x5000, 0x57FF, readReg);
|
||||
SetWriteHandler(0x5000, 0x57FF, writeReg);
|
||||
SetReadHandler (0x6000, 0xFFFF, CartBR);
|
||||
SetWriteHandler(0x6000, 0x7FFF, CartBW);
|
||||
}
|
||||
|
||||
static void reset()
|
||||
{
|
||||
memset(reg, 0, sizeof(reg));
|
||||
sync();
|
||||
}
|
||||
|
||||
void Mapper163_Init (CartInfo *info)
|
||||
{
|
||||
uint32 WRAMSIZE = info->iNES2? (info->PRGRamSize + info->PRGRamSaveSize): 8192;
|
||||
info->Power = power;
|
||||
info->Reset = reset;
|
||||
GameHBIRQHook = hblank;
|
||||
AddExState(StateRegs, ~0, 0, 0);
|
||||
|
||||
uint8* WRAM = (uint8*) FCEU_gmalloc(WRAMSIZE);
|
||||
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
|
||||
FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM);
|
||||
if (info->battery) {
|
||||
info->SaveGame[0] = WRAM;
|
||||
info->SaveGameLen[0] = info->PRGRamSaveSize;
|
||||
}
|
||||
}
|
||||
277
src/boards/164.c
277
src/boards/164.c
@@ -1,7 +1,9 @@
|
||||
/* FCE Ultra - NES/Famicom Emulator
|
||||
*
|
||||
* Copyright notice for this file:
|
||||
* Copyright (C) 2002 Xodnizel 2006 CaH4e3
|
||||
* Copyright (C) 2002 Xodnizel
|
||||
* Copyright (C) 2005 CaH4e3
|
||||
* Copyright (C) 2019 Libretro Team
|
||||
*
|
||||
* 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,217 +18,102 @@
|
||||
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* It seems that 162/163/164 mappers are the same mapper with just different
|
||||
* mapper modes enabled or disabled in software or hardware, need more nanjing
|
||||
* carts
|
||||
*/
|
||||
|
||||
/* Dongda PEC-9588 educational computer. Provides the same 1bpp all-points-addressable graphics mode.
|
||||
Its chipset was later used for the Yancheng cy2000-3 PCB, used on most of the games that display "Union Bond" at the start.
|
||||
Some of them also use the 1bpp mode for a few screens!
|
||||
*/
|
||||
|
||||
#include "mapinc.h"
|
||||
#include "eeprom_93C66.h"
|
||||
|
||||
static uint8 laststrobe, trigger;
|
||||
static uint8 reg[8];
|
||||
static uint8 *WRAM = NULL;
|
||||
static uint32 WRAMSIZE;
|
||||
|
||||
static writefunc pcmwrite;
|
||||
|
||||
static void (*WSync)(void);
|
||||
|
||||
static uint8 eeprom_data[512];
|
||||
static SFORMAT StateRegs[] =
|
||||
{
|
||||
{ &laststrobe, 1, "STB" },
|
||||
{ &trigger, 1, "TRG" },
|
||||
{ reg, 8, "REGS" },
|
||||
{ 0 }
|
||||
{ reg, 8, "REGS" },
|
||||
{ eeprom_data, 512, "EEPR" },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
static void Sync(void) {
|
||||
setprg8r(0x10, 0x6000, 0);
|
||||
setprg32(0x8000, (reg[0] << 4) | (reg[1] & 0xF));
|
||||
setchr8(0);
|
||||
static void sync()
|
||||
{
|
||||
uint8 prgLow = reg[0] &0x0F | reg[0] >>1 &0x10;
|
||||
uint8 prgHigh = reg[1] <<5;
|
||||
switch (reg[0] >>5 &2 | reg[0] >>4 &1)
|
||||
{
|
||||
case 0: /* UNROM-512 */
|
||||
setprg16(0x8000, prgHigh | prgLow);
|
||||
setprg16(0xC000, prgHigh | 0x1F);
|
||||
break;
|
||||
case 1: /* Open Bus on Yancheng cy2000-3 PCB, expansion cartridge on the Dongda PEC-9588 */
|
||||
break;
|
||||
case 2: /* UNROM-448+64. Very strange mode, used for the LOGO program on the Dongda PEC-9588 */
|
||||
setprg16(0x8000, prgHigh | prgLow);
|
||||
setprg16(0xC000, prgHigh |(prgLow >=0x1C? 0x1C: 0x1E));
|
||||
break;
|
||||
case 3: /* UNROM-128 or BNROM */
|
||||
if (prgLow &0x10)
|
||||
{
|
||||
setprg16(0x8000, prgHigh | prgLow <<1 &0x10 | prgLow &0x0F);
|
||||
setprg16(0xC000, prgHigh | prgLow <<1 &0x10 | 0x0F);
|
||||
}
|
||||
else
|
||||
setprg32(0x8000, prgHigh >>1 | prgLow);
|
||||
break;
|
||||
}
|
||||
setprg8r(0x10, 0x6000, 0);
|
||||
|
||||
setchr8(0);
|
||||
PEC586Hack = !!(reg[0] &0x80);
|
||||
|
||||
setmirror(reg[0] &0x10 && ~reg[3] &0x80? MI_H: MI_V);
|
||||
|
||||
eeprom_93C66_write(reg[2] &0x10, reg[2] &0x04, reg[2] &0x01);
|
||||
}
|
||||
|
||||
static void StateRestore(int version) {
|
||||
WSync();
|
||||
static DECLFR(readReg)
|
||||
{
|
||||
return eeprom_93C66_read()? 0x00: 0x04;
|
||||
}
|
||||
|
||||
static DECLFR(ReadLow) {
|
||||
switch (A & 0x7700) {
|
||||
case 0x5100: return reg[2] | reg[0] | reg[1] | (reg[3] ^ 0xff); break;
|
||||
case 0x5500:
|
||||
if (trigger)
|
||||
return reg[2] | reg[1]; /* Lei Dian Huang Bi Ka Qiu Chuan Shuo (NJ046) may broke other games */
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
return 4;
|
||||
static DECLFW(writeReg)
|
||||
{
|
||||
reg[A >>8 &7] = V;
|
||||
sync();
|
||||
}
|
||||
|
||||
static void M163HB(void) {
|
||||
if (reg[1] & 0x80) {
|
||||
if (scanline == 239) {
|
||||
setchr4(0x0000, 0);
|
||||
setchr4(0x1000, 0);
|
||||
} else if (scanline == 127) {
|
||||
setchr4(0x0000, 1);
|
||||
setchr4(0x1000, 1);
|
||||
}
|
||||
#if 0
|
||||
if(scanline>=127) /* Hu Lu Jin Gang (NJ039) (Ch) [!] don't like it */
|
||||
{
|
||||
setchr4(0x0000,1);
|
||||
setchr4(0x1000,1);
|
||||
}
|
||||
else
|
||||
{
|
||||
setchr4(0x0000,0);
|
||||
setchr4(0x1000,0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
static void power(void)
|
||||
{
|
||||
memset(reg, 0, sizeof(reg));
|
||||
eeprom_93C66_init();
|
||||
sync();
|
||||
SetReadHandler (0x5400, 0x57FF, readReg);
|
||||
SetWriteHandler(0x5000, 0x57FF, writeReg);
|
||||
SetReadHandler (0x6000, 0xFFFF, CartBR);
|
||||
SetWriteHandler(0x6000, 0x7FFF, CartBW);
|
||||
}
|
||||
|
||||
static DECLFW(Write) {
|
||||
switch (A & 0x7300) {
|
||||
case 0x5100: reg[0] = V; WSync(); break;
|
||||
case 0x5000: reg[1] = V; WSync(); break;
|
||||
case 0x5300: reg[2] = V; break;
|
||||
case 0x5200: reg[3] = V; WSync(); break;
|
||||
}
|
||||
static void reset()
|
||||
{
|
||||
memset(reg, 0, sizeof(reg));
|
||||
sync();
|
||||
}
|
||||
|
||||
static void Power(void) {
|
||||
memset(reg, 0, 8);
|
||||
reg[1] = 0xFF;
|
||||
SetWriteHandler(0x5000, 0x5FFF, Write);
|
||||
SetReadHandler(0x6000, 0xFFFF, CartBR);
|
||||
SetWriteHandler(0x6000, 0x7FFF, CartBW);
|
||||
FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM);
|
||||
WSync();
|
||||
}
|
||||
|
||||
static void Close(void) {
|
||||
if (WRAM)
|
||||
FCEU_gfree(WRAM);
|
||||
WRAM = NULL;
|
||||
}
|
||||
|
||||
void Mapper164_Init(CartInfo *info) {
|
||||
info->Power = Power;
|
||||
info->Close = Close;
|
||||
WSync = Sync;
|
||||
|
||||
WRAMSIZE = 8192;
|
||||
WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE);
|
||||
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
|
||||
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
|
||||
|
||||
if (info->battery) {
|
||||
info->SaveGame[0] = WRAM;
|
||||
info->SaveGameLen[0] = WRAMSIZE;
|
||||
}
|
||||
|
||||
GameStateRestore = StateRestore;
|
||||
AddExState(&StateRegs, ~0, 0, 0);
|
||||
}
|
||||
|
||||
static DECLFW(Write2) {
|
||||
if (A == 0x5101) {
|
||||
if (laststrobe && !V) {
|
||||
trigger ^= 1;
|
||||
}
|
||||
laststrobe = V;
|
||||
} else if (A == 0x5100 && V == 6) /* damn those protected games */
|
||||
setprg32(0x8000, 3);
|
||||
else
|
||||
switch (A & 0x7300) {
|
||||
case 0x5200: reg[0] = V; WSync(); break;
|
||||
case 0x5000: reg[1] = V; WSync(); if (!(reg[1] & 0x80) && (scanline < 128)) setchr8(0); /* setchr8(0); */ break;
|
||||
case 0x5300: reg[2] = V; break;
|
||||
case 0x5100: reg[3] = V; WSync(); break;
|
||||
}
|
||||
}
|
||||
|
||||
static void Power2(void) {
|
||||
memset(reg, 0, 8);
|
||||
laststrobe = 1;
|
||||
pcmwrite = GetWriteHandler(0x4011);
|
||||
SetReadHandler(0x5000, 0x5FFF, ReadLow);
|
||||
SetWriteHandler(0x5000, 0x5FFF, Write2);
|
||||
SetReadHandler(0x6000, 0xFFFF, CartBR);
|
||||
SetWriteHandler(0x6000, 0x7FFF, CartBW);
|
||||
FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM);
|
||||
WSync();
|
||||
}
|
||||
|
||||
void Mapper163_Init(CartInfo *info) {
|
||||
info->Power = Power2;
|
||||
info->Close = Close;
|
||||
WSync = Sync;
|
||||
GameHBIRQHook = M163HB;
|
||||
|
||||
WRAMSIZE = 8192;
|
||||
WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE);
|
||||
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
|
||||
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
|
||||
|
||||
if (info->battery) {
|
||||
info->SaveGame[0] = WRAM;
|
||||
info->SaveGameLen[0] = WRAMSIZE;
|
||||
}
|
||||
GameStateRestore = StateRestore;
|
||||
AddExState(&StateRegs, ~0, 0, 0);
|
||||
}
|
||||
|
||||
static void Sync3(void) {
|
||||
setchr8(0);
|
||||
setprg8r(0x10, 0x6000, 0);
|
||||
switch (reg[3] & 7) {
|
||||
case 0:
|
||||
case 2: setprg32(0x8000, (reg[0] & 0xc) | (reg[1] & 2) | ((reg[2] & 0xf) << 4)); break;
|
||||
case 1:
|
||||
case 3: setprg32(0x8000, (reg[0] & 0xc) | (reg[2] & 0xf) << 4); break;
|
||||
case 4:
|
||||
case 6: setprg32(0x8000, (reg[0] & 0xe) | ((reg[1] >> 1) & 1) | ((reg[2] & 0xf) << 4)); break;
|
||||
case 5:
|
||||
case 7: setprg32(0x8000, (reg[0] & 0xf) | ((reg[2] & 0xf) << 4)); break;
|
||||
}
|
||||
}
|
||||
|
||||
static DECLFW(Write3) {
|
||||
/* FCEU_printf("bs %04x %02x\n",A,V); */
|
||||
reg[(A >> 8) & 3] = V;
|
||||
WSync();
|
||||
}
|
||||
|
||||
static void Power3(void) {
|
||||
reg[0] = 3;
|
||||
reg[1] = 0;
|
||||
reg[2] = 0;
|
||||
reg[3] = 7;
|
||||
SetWriteHandler(0x5000, 0x5FFF, Write3);
|
||||
SetReadHandler(0x6000, 0xFFFF, CartBR);
|
||||
SetWriteHandler(0x6000, 0x7FFF, CartBW);
|
||||
FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM);
|
||||
WSync();
|
||||
}
|
||||
|
||||
void UNLFS304_Init(CartInfo *info) {
|
||||
info->Power = Power3;
|
||||
info->Close = Close;
|
||||
WSync = Sync3;
|
||||
|
||||
WRAMSIZE = 8192;
|
||||
WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE);
|
||||
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
|
||||
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
|
||||
|
||||
if (info->battery) {
|
||||
info->SaveGame[0] = WRAM;
|
||||
info->SaveGameLen[0] = WRAMSIZE;
|
||||
}
|
||||
|
||||
GameStateRestore = StateRestore;
|
||||
AddExState(&StateRegs, ~0, 0, 0);
|
||||
void Mapper164_Init (CartInfo *info)
|
||||
{
|
||||
uint32 WRAMSIZE = info->iNES2? (info->PRGRamSize + (info->PRGRamSaveSize &~0x7FF)): 8192;
|
||||
info->Power = power;
|
||||
info->Reset = reset;
|
||||
AddExState(StateRegs, ~0, 0, 0);
|
||||
|
||||
uint8* WRAM = (uint8*) FCEU_gmalloc(WRAMSIZE);
|
||||
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
|
||||
FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM);
|
||||
|
||||
eeprom_93C66_storage = eeprom_data;
|
||||
info->battery = 1;
|
||||
info->SaveGame[0] = eeprom_data;
|
||||
info->SaveGameLen[0] = 512;
|
||||
}
|
||||
|
||||
125
src/boards/558.c
Normal file
125
src/boards/558.c
Normal file
@@ -0,0 +1,125 @@
|
||||
/* FCE Ultra - NES/Famicom Emulator
|
||||
*
|
||||
* Copyright notice for this file:
|
||||
* Copyright (C) 2002 Xodnizel
|
||||
* Copyright (C) 2005 CaH4e3
|
||||
* Copyright (C) 2019 Libretro Team
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/* Yancheng YC-03-09/Waixing FS??? PCB */
|
||||
|
||||
#include "mapinc.h"
|
||||
#include "eeprom_93C66.h"
|
||||
#include "../ines.h"
|
||||
|
||||
static uint8 reg[4];
|
||||
static uint8 haveEEPROM;
|
||||
static uint8 eeprom_data[512];
|
||||
static SFORMAT StateRegs[] =
|
||||
{
|
||||
{ reg, 4, "REGS" },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
static void sync()
|
||||
{
|
||||
setprg32(0x8000, reg[1] <<4 | reg[0] &0xF | (reg[3] &0x04? 0x00: 0x03));
|
||||
setprg8r(0x10, 0x6000, 0);
|
||||
if (~reg[0] &0x80)
|
||||
setchr8(0);
|
||||
|
||||
if (haveEEPROM)
|
||||
eeprom_93C66_write(reg[2] &0x04, reg[2] &0x02, reg[2] &0x01);
|
||||
}
|
||||
|
||||
static void hblank(void) {
|
||||
if (reg[0] &0x80 && scanline <239)
|
||||
{ /* Actual hardware cannot look at the current scanline number, but instead latches PA09 on PA13 rises. This does not seem possible with the current PPU emulation however. */
|
||||
setchr4(0x0000, scanline >=127? 1: 0);
|
||||
setchr4(0x1000, scanline >=127? 1: 0);
|
||||
}
|
||||
else
|
||||
setchr8(0);
|
||||
}
|
||||
|
||||
static DECLFR(readReg)
|
||||
{
|
||||
if (haveEEPROM)
|
||||
return eeprom_93C66_read()? 0x04: 0x00;
|
||||
else
|
||||
return reg[2] &0x04;
|
||||
}
|
||||
|
||||
static DECLFW(writeReg)
|
||||
{
|
||||
uint8 index = A >>8 &3;
|
||||
|
||||
/* D0 and D1 are connected to the ASIC in reverse order, so swap once */
|
||||
V = V &~3 | V >>1 &1 | V <<1 &2;
|
||||
|
||||
/* Swap bits of registers 0-2 again if the "swap bits" bit is set. Exclude register 2 on when PRG-ROM is 1 MiB. */
|
||||
if (reg[3] &0x02 && index <= (ROM_size == 64? 1: 2))
|
||||
V = V &~3 | V >>1 &1 | V <<1 &2;
|
||||
|
||||
reg[index] = V;
|
||||
sync();
|
||||
}
|
||||
|
||||
static void power(void)
|
||||
{
|
||||
memset(reg, 0, sizeof(reg));
|
||||
if (haveEEPROM)
|
||||
eeprom_93C66_init();
|
||||
sync();
|
||||
SetReadHandler (0x5000, 0x57FF, readReg);
|
||||
SetWriteHandler(0x5000, 0x57FF, writeReg);
|
||||
SetReadHandler (0x6000, 0xFFFF, CartBR);
|
||||
SetWriteHandler(0x6000, 0x7FFF, CartBW);
|
||||
}
|
||||
|
||||
static void reset()
|
||||
{
|
||||
memset(reg, 0, sizeof(reg));
|
||||
sync();
|
||||
}
|
||||
|
||||
void Mapper558_Init (CartInfo *info)
|
||||
{
|
||||
uint32 WRAMSIZE = info->PRGRamSize + (info->PRGRamSaveSize &~0x7FF);
|
||||
info->Power = power;
|
||||
info->Reset = reset;
|
||||
GameHBIRQHook = hblank;
|
||||
AddExState(StateRegs, ~0, 0, 0);
|
||||
|
||||
uint8* WRAM = (uint8*) FCEU_gmalloc(WRAMSIZE);
|
||||
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
|
||||
FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM);
|
||||
haveEEPROM =!!(info->PRGRamSaveSize &0x200);
|
||||
if (haveEEPROM)
|
||||
{
|
||||
eeprom_93C66_storage = eeprom_data;
|
||||
info->battery = 1;
|
||||
info->SaveGame[0] = eeprom_data;
|
||||
info->SaveGameLen[0] = 512;
|
||||
}
|
||||
else
|
||||
if (info->battery)
|
||||
{
|
||||
info->SaveGame[0] = WRAM;
|
||||
info->SaveGameLen[0] = (info->PRGRamSaveSize &~0x7FF);
|
||||
}
|
||||
}
|
||||
135
src/boards/eeprom_93C66.c
Normal file
135
src/boards/eeprom_93C66.c
Normal file
@@ -0,0 +1,135 @@
|
||||
#include "eeprom_93C66.h"
|
||||
|
||||
uint8* eeprom_93C66_storage;
|
||||
uint8 eeprom_93C66_opcode;
|
||||
uint8 eeprom_93C66_data;
|
||||
uint16 eeprom_93C66_address;
|
||||
uint8 eeprom_93C66_state;
|
||||
uint8 eeprom_93C66_lastCLK;
|
||||
uint8 eeprom_93C66_writeEnabled;
|
||||
uint8 eeprom_93C66_output;
|
||||
|
||||
#define OPCODE_MISC 0
|
||||
#define OPCODE_WRITE 1
|
||||
#define OPCODE_READ 2
|
||||
#define OPCODE_ERASE 3
|
||||
#define OPCODE_WRITEDISABLE 10
|
||||
#define OPCODE_WRITEALL 11
|
||||
#define OPCODE_ERASEALL 12
|
||||
#define OPCODE_WRITEENABLE 13
|
||||
|
||||
#define STATE_STANDBY 0
|
||||
#define STATE_STARTBIT 1
|
||||
#define STATE_OPCODE 3
|
||||
#define STATE_ADDRESS 12
|
||||
#define STATE_DATA 20
|
||||
#define STATE_FINISHED 99
|
||||
|
||||
void eeprom_93C66_init ()
|
||||
{
|
||||
eeprom_93C66_address =0;
|
||||
eeprom_93C66_state =STATE_STANDBY;
|
||||
eeprom_93C66_lastCLK =0;
|
||||
eeprom_93C66_writeEnabled =0;
|
||||
}
|
||||
|
||||
uint8 eeprom_93C66_read ()
|
||||
{
|
||||
return eeprom_93C66_output;
|
||||
}
|
||||
|
||||
void eeprom_93C66_write (uint8 CS, uint8 CLK, uint8 DAT)
|
||||
{
|
||||
if (!CS && eeprom_93C66_state <= STATE_ADDRESS)
|
||||
eeprom_93C66_state =STATE_STANDBY;
|
||||
else
|
||||
if (eeprom_93C66_state ==STATE_STANDBY && CS && CLK)
|
||||
{
|
||||
eeprom_93C66_state =STATE_STARTBIT;
|
||||
eeprom_93C66_opcode =0;
|
||||
eeprom_93C66_address =0;
|
||||
eeprom_93C66_output =1;
|
||||
}
|
||||
else
|
||||
if (CLK && !eeprom_93C66_lastCLK)
|
||||
{
|
||||
if (eeprom_93C66_state >=STATE_STARTBIT && eeprom_93C66_state <STATE_OPCODE)
|
||||
eeprom_93C66_opcode =(eeprom_93C66_opcode <<1) | (DAT? 1: 0);
|
||||
else
|
||||
if (eeprom_93C66_state >=STATE_OPCODE && eeprom_93C66_state <STATE_ADDRESS)
|
||||
eeprom_93C66_address =(eeprom_93C66_address <<1) | (DAT? 1: 0);
|
||||
else
|
||||
if (eeprom_93C66_state >=STATE_ADDRESS && eeprom_93C66_state <STATE_DATA)
|
||||
{
|
||||
if (eeprom_93C66_opcode ==OPCODE_WRITE || eeprom_93C66_opcode ==OPCODE_WRITEALL)
|
||||
eeprom_93C66_data =(eeprom_93C66_data <<1) | (DAT? 1: 0);
|
||||
else
|
||||
if (eeprom_93C66_opcode ==OPCODE_READ)
|
||||
{
|
||||
eeprom_93C66_output =!!(eeprom_93C66_data &0x80);
|
||||
eeprom_93C66_data = eeprom_93C66_data <<1;
|
||||
}
|
||||
}
|
||||
eeprom_93C66_state++;
|
||||
if (eeprom_93C66_state ==STATE_ADDRESS) {
|
||||
switch (eeprom_93C66_opcode)
|
||||
{
|
||||
case OPCODE_MISC:
|
||||
eeprom_93C66_opcode =(eeprom_93C66_address >>7) + 10;
|
||||
switch (eeprom_93C66_opcode)
|
||||
{
|
||||
case OPCODE_WRITEDISABLE:
|
||||
eeprom_93C66_writeEnabled = 0;
|
||||
eeprom_93C66_state = STATE_FINISHED;
|
||||
break;
|
||||
case OPCODE_WRITEENABLE:
|
||||
eeprom_93C66_writeEnabled = 1;
|
||||
eeprom_93C66_state = STATE_FINISHED;
|
||||
break;
|
||||
case OPCODE_ERASEALL:
|
||||
if (eeprom_93C66_writeEnabled) for (int i =0; i <512; i++) eeprom_93C66_storage[i] = 0xFF;
|
||||
eeprom_93C66_state = STATE_FINISHED;
|
||||
break;
|
||||
case OPCODE_WRITEALL:
|
||||
eeprom_93C66_address = 0;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case OPCODE_ERASE:
|
||||
if (eeprom_93C66_writeEnabled) eeprom_93C66_storage[eeprom_93C66_address] = 0xFF;
|
||||
eeprom_93C66_state = STATE_FINISHED;
|
||||
break;
|
||||
case OPCODE_READ:
|
||||
eeprom_93C66_data = eeprom_93C66_storage[eeprom_93C66_address++];
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
if (eeprom_93C66_state ==STATE_DATA)
|
||||
{
|
||||
if (eeprom_93C66_opcode ==OPCODE_WRITE)
|
||||
{
|
||||
eeprom_93C66_storage[eeprom_93C66_address++] = eeprom_93C66_data;
|
||||
eeprom_93C66_state = STATE_FINISHED;
|
||||
}
|
||||
else
|
||||
if (eeprom_93C66_opcode ==OPCODE_WRITEALL)
|
||||
{
|
||||
eeprom_93C66_storage[eeprom_93C66_address++] = eeprom_93C66_data;
|
||||
eeprom_93C66_state = CS && eeprom_93C66_address <512? STATE_ADDRESS: STATE_FINISHED;
|
||||
}
|
||||
else
|
||||
if (eeprom_93C66_opcode ==OPCODE_READ)
|
||||
{
|
||||
if (eeprom_93C66_address <512) eeprom_93C66_data = eeprom_93C66_storage[eeprom_93C66_address];
|
||||
eeprom_93C66_state = CS && ++eeprom_93C66_address <=512? STATE_ADDRESS: STATE_FINISHED;
|
||||
}
|
||||
}
|
||||
if (eeprom_93C66_state == STATE_FINISHED)
|
||||
{
|
||||
eeprom_93C66_output = 0;
|
||||
eeprom_93C66_state = STATE_STANDBY;
|
||||
}
|
||||
}
|
||||
eeprom_93C66_lastCLK = CLK;
|
||||
}
|
||||
10
src/boards/eeprom_93C66.h
Normal file
10
src/boards/eeprom_93C66.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef _EEPROM_93C66_H
|
||||
#define _EEPROM_93C66_H
|
||||
#include "mapinc.h"
|
||||
|
||||
extern uint8* eeprom_93C66_storage;
|
||||
|
||||
void eeprom_93C66_init ();
|
||||
uint8 eeprom_93C66_read ();
|
||||
void eeprom_93C66_write (uint8 CS, uint8 CLK, uint8 DAT);
|
||||
#endif
|
||||
Reference in New Issue
Block a user