Add mapper 406, together with generic self-flashing code.
This commit is contained in:
committed by
LibretroAdmin
parent
f922972898
commit
a8b7a63536
55
src/boards/406.c
Normal file
55
src/boards/406.c
Normal file
@@ -0,0 +1,55 @@
|
||||
/* FCEUmm - NES/Famicom Emulator
|
||||
*
|
||||
* Copyright notice for this file:
|
||||
* Copyright (C) 2025 NewRisingSun
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include "mapinc.h"
|
||||
#include "mmc3.h"
|
||||
#include "flashrom.h"
|
||||
|
||||
uint8 submapper;
|
||||
|
||||
static DECLFW(Write) {
|
||||
flashrom_write(A &0x1FFF | (Page[A >>11] +A -PRGptr[0]) &~0x1FFF, V);
|
||||
|
||||
if (submapper ==1)
|
||||
A =A <0xA000 || A >=0xE000? (A ^0x6000): A;
|
||||
else
|
||||
A =A &0xE000 | A >>1 &0x0001;
|
||||
|
||||
if (A &0x4000)
|
||||
MMC3_IRQWrite(A, V);
|
||||
else
|
||||
MMC3_CMDWrite(A, V);
|
||||
}
|
||||
|
||||
static void Power(void) {
|
||||
GenMMC3Power();
|
||||
SetReadHandler(0x8000, 0xFFFF, flashrom_read);
|
||||
SetWriteHandler(0x8000, 0xFFFF, Write);
|
||||
}
|
||||
|
||||
void Mapper406_Init(CartInfo *info) {
|
||||
submapper =info->submapper;
|
||||
GenMMC3_Init(info, 512, 256, 0, 0);
|
||||
flashrom_init (submapper ==1? 0x01: 0xC2, 0xA4, 65536, 0x5555, 0x2AAA, 0x7FFF); /* Macronix MX29F040 (0)/AMD AM29F040 (1) */
|
||||
info->Power =Power;
|
||||
info->SaveGame[0] =PRGptr[0];
|
||||
info->SaveGameLen[0] =PRGsize[0];
|
||||
MapIRQHook =flashrom_cpuCycle;
|
||||
}
|
||||
60
src/boards/flashrom.c
Normal file
60
src/boards/flashrom.c
Normal file
@@ -0,0 +1,60 @@
|
||||
#include "flashrom.h"
|
||||
void flashrom_init (uint8 manufacturerID, uint8 modelID, uint32 sectorSize, uint32 magicAddr1, uint32 magicAddr2, uint32 magicMask) {
|
||||
flashrom_manufacturerID =manufacturerID;
|
||||
flashrom_modelID =modelID;
|
||||
flashrom_sectorSize =sectorSize;
|
||||
flashrom_magicAddr1 =magicAddr1;
|
||||
flashrom_magicAddr2 =magicAddr2;
|
||||
flashrom_magicMask =magicMask;
|
||||
}
|
||||
|
||||
uint8 flashrom_read (uint32 A) {
|
||||
if (flashrom_state ==0x90) /* software ID */
|
||||
return A &1? flashrom_modelID: flashrom_manufacturerID;
|
||||
else
|
||||
if (flashrom_timeOut)
|
||||
return (CartBR(A) ^(flashrom_timeOut &1? 0x40: 0x00)) &~0x88;
|
||||
else
|
||||
return CartBR(A);
|
||||
}
|
||||
|
||||
void flashrom_write (uint32 fullAddress, uint8 V) {
|
||||
uint32 i;
|
||||
uint8* sector =NULL;
|
||||
uint32 compare =fullAddress &flashrom_magicMask;
|
||||
fullAddress &=PRGsize[0] -1;
|
||||
switch (flashrom_state) {
|
||||
/* command start */
|
||||
default: if (compare ==flashrom_magicAddr1 && V ==0xAA) flashrom_state++; break;
|
||||
case 0x01: if (compare ==flashrom_magicAddr2 && V ==0x55) flashrom_state++; break;
|
||||
case 0x02: if (compare ==flashrom_magicAddr1) flashrom_state =V; break;
|
||||
/* sector or chip erase */
|
||||
case 0x80: if (compare ==flashrom_magicAddr1 && V ==0xAA) flashrom_state++; break;
|
||||
case 0x81: if (compare ==flashrom_magicAddr2 && V ==0x55) flashrom_state++; break;
|
||||
case 0x82: if (V ==0x30) { /* sector erase */
|
||||
/* Determine the actual sector start by masking with the sector size */
|
||||
fullAddress &=~(flashrom_sectorSize -1);
|
||||
sector =PRGptr[0] +fullAddress;
|
||||
for (i =0; i <flashrom_sectorSize; i++) sector[i] =0xFF;
|
||||
flashrom_timeOut =flashrom_sectorSize;
|
||||
} else
|
||||
if (V ==0x10 && compare ==flashrom_magicAddr1) { /* chip erase */
|
||||
for (i =0; i<=PRGsize[0]; i++) PRGptr[0][i] =0xFF;
|
||||
flashrom_timeOut =PRGsize[0];
|
||||
} else
|
||||
if (V ==0xF0) flashrom_state =0;
|
||||
break;
|
||||
/* software ID */
|
||||
case 0x90: if (V ==0xF0) flashrom_state =0; break;
|
||||
/* byte program */
|
||||
case 0xA0: PRGptr[0][fullAddress] =V;
|
||||
flashrom_state =0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void FP_FASTAPASS(1) flashrom_cpuCycle(int a) {
|
||||
while (a--) {
|
||||
if (flashrom_timeOut && !--flashrom_timeOut) flashrom_state =0;
|
||||
}
|
||||
}
|
||||
19
src/boards/flashrom.h
Normal file
19
src/boards/flashrom.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef _FLASHROM_H
|
||||
#define _FLASHROM_H
|
||||
#include "mapinc.h"
|
||||
|
||||
uint8 flashrom_manufacturerID;
|
||||
uint8 flashrom_modelID;
|
||||
int flashrom_state;
|
||||
uint32 flashrom_sectorSize;
|
||||
int flashrom_timeOut;
|
||||
uint32 flashrom_magicAddr1;
|
||||
uint32 flashrom_magicAddr2;
|
||||
uint32 flashrom_magicMask;
|
||||
|
||||
void flashrom_init (uint8, uint8, uint32, uint32, uint32, uint32);
|
||||
uint8 flashrom_read (uint32);
|
||||
void flashrom_write (uint32, uint8);
|
||||
void FP_FASTAPASS(1) flashrom_cpuCycle(int);
|
||||
|
||||
#endif
|
||||
@@ -840,6 +840,7 @@ INES_BOARD_BEGIN()
|
||||
INES_BOARD( "831019C J-2282", 402, J2282_Init )
|
||||
INES_BOARD( "89433", 403, Mapper403_Init )
|
||||
INES_BOARD( "JY012005", 404, Mapper404_Init )
|
||||
INES_BOARD( "Impact Soft", 406, Mapper406_Init )
|
||||
INES_BOARD( "retroUSB DPCMcart", 409, Mapper409_Init )
|
||||
INES_BOARD( "JY-302", 410, Mapper410_Init )
|
||||
INES_BOARD( "A88S-1", 411, Mapper411_Init )
|
||||
|
||||
@@ -319,6 +319,7 @@ void Mapper399_Init(CartInfo *);
|
||||
void Mapper401_Init(CartInfo *);
|
||||
void Mapper403_Init(CartInfo *);
|
||||
void Mapper404_Init(CartInfo *);
|
||||
void Mapper406_Init(CartInfo *);
|
||||
void Mapper409_Init(CartInfo *);
|
||||
void Mapper410_Init(CartInfo *);
|
||||
void Mapper411_Init(CartInfo *);
|
||||
|
||||
Reference in New Issue
Block a user