2011-02-28 07:53:19 +00:00
using System ;
2013-11-04 00:36:15 +00:00
using BizHawk.Common ;
2011-02-28 07:53:19 +00:00
2013-11-14 13:15:41 +00:00
namespace BizHawk.Emulation.Cores.Nintendo.NES
2011-02-28 07:53:19 +00:00
{
2011-02-28 09:13:27 +00:00
//generally mapper2
2011-03-01 09:32:12 +00:00
//Mega Man
//Castlevania
//Contra
//Duck Tales
//Metal Gear
2011-03-02 02:54:06 +00:00
//TODO - look for a mirror=H UNROM--maybe there are none? this may be fixed to the board type.
2011-02-28 10:16:07 +00:00
2014-01-15 18:18:49 +00:00
// why are there no bus conflicts in here???????
2012-10-17 00:25:46 +00:00
[NES.INESBoardImplPriority]
2013-08-25 01:08:17 +00:00
public sealed class UxROM : NES . NESBoardBase
2011-02-28 07:53:19 +00:00
{
2011-03-01 09:32:12 +00:00
//configuration
2011-03-02 02:54:06 +00:00
int prg_mask ;
2011-03-21 06:03:58 +00:00
int vram_byte_mask ;
2011-09-25 02:52:53 +00:00
Func < int , int > adjust_prg ;
2011-03-01 09:32:12 +00:00
//state
int prg ;
2016-10-30 23:31:41 +00:00
//the VS actually does have 2 KB of nametable address space
//let's make the extra space here, instead of in the main NES to avoid confusion
byte [ ] CIRAM_VS = new byte [ 0x800 ] ;
2011-03-20 02:12:10 +00:00
public override bool Configure ( NES . EDetectionOrigin origin )
2011-02-28 07:53:19 +00:00
{
2011-09-25 02:52:53 +00:00
adjust_prg = ( x ) = > x ;
2011-03-07 10:41:46 +00:00
//configure
2011-03-08 07:25:35 +00:00
switch ( Cart . board_type )
2011-03-07 10:41:46 +00:00
{
2016-12-11 21:38:13 +00:00
case "MAPPER0002-00" :
2016-12-11 23:41:20 +00:00
//probably a mistake.
//but (for chrram): "Use of $00 with no CHR ROM implies that the game is wired to map nametable memory in CHR space. The value $00 MUST NOT be used if a mapper isn't defined to allow this. "
//well, i'm not going to do that now. we'll save it for when it's needed
//"it's only mapper 218 and no other mappers"
//so, dont assume this
//Cart.vram_size = 8;
2016-12-11 21:38:13 +00:00
break ;
2012-04-01 15:41:51 +00:00
case "MAPPER002" :
2014-01-17 22:55:48 +00:00
AssertChr ( 0 ) ; Cart . vram_size = 8 ;
2012-03-22 06:20:10 +00:00
break ;
2011-03-08 07:25:35 +00:00
case "NES-UNROM" : //mega man
2011-03-07 10:41:46 +00:00
case "HVC-UNROM" :
case "KONAMI-UNROM" :
2014-01-15 17:00:02 +00:00
case "NES-UNEPROM" : // proto
2014-01-15 18:18:49 +00:00
case "IREM-UNROM" :
2014-01-16 00:22:40 +00:00
case "TAITO-UNROM" :
2011-06-07 20:52:30 +00:00
AssertPrg ( 128 ) ; AssertChr ( 0 ) ; AssertVram ( 8 ) ;
//AssertWram(0); //JJ - Tobidase Daisakusen Part 2 (J) includes WRAM
2011-03-07 10:41:46 +00:00
break ;
2011-09-25 02:52:53 +00:00
case "HVC-UN1ROM" :
AssertPrg ( 128 ) ; AssertChr ( 0 ) ; AssertWram ( 0 ) ; AssertVram ( 8 ) ;
adjust_prg = ( x ) = > ( ( x > > 2 ) & 7 ) ;
break ;
2011-02-28 07:53:19 +00:00
2011-03-08 07:25:35 +00:00
case "NES-UOROM" : //paperboy 2
2011-03-07 10:41:46 +00:00
case "HVC-UOROM" :
2014-01-18 15:57:43 +00:00
case "JALECO-JF-15" :
2014-01-15 18:18:49 +00:00
case "JALECO-JF-18" :
2011-03-08 07:25:35 +00:00
AssertPrg ( 256 ) ; AssertChr ( 0 ) ; AssertVram ( 8 ) ; AssertWram ( 0 ) ;
2011-03-07 10:41:46 +00:00
break ;
2016-10-30 23:31:41 +00:00
case "NES-UNROM_VS" :
2016-11-04 01:57:47 +00:00
//update the state of the dip switches
//this is only done at power on
NES . VS_dips [ 0 ] = ( byte ) ( NES . SyncSettings . VSDipswitches . Dip_Switch_1 ? 1 : 0 ) ;
2016-11-10 13:53:14 +00:00
NES . VS_dips [ 1 ] = ( byte ) ( NES . SyncSettings . VSDipswitches . Dip_Switch_2 ? 1 : 0 ) ;
NES . VS_dips [ 2 ] = ( byte ) ( NES . SyncSettings . VSDipswitches . Dip_Switch_3 ? 1 : 0 ) ;
NES . VS_dips [ 3 ] = ( byte ) ( NES . SyncSettings . VSDipswitches . Dip_Switch_4 ? 1 : 0 ) ;
NES . VS_dips [ 4 ] = ( byte ) ( NES . SyncSettings . VSDipswitches . Dip_Switch_5 ? 1 : 0 ) ;
NES . VS_dips [ 5 ] = ( byte ) ( NES . SyncSettings . VSDipswitches . Dip_Switch_6 ? 1 : 0 ) ;
NES . VS_dips [ 6 ] = ( byte ) ( NES . SyncSettings . VSDipswitches . Dip_Switch_7 ? 1 : 0 ) ;
NES . VS_dips [ 7 ] = ( byte ) ( NES . SyncSettings . VSDipswitches . Dip_Switch_8 ? 1 : 0 ) ;
2016-10-30 23:31:41 +00:00
NES . _isVS = true ;
break ;
2011-03-07 10:41:46 +00:00
default :
return false ;
}
2011-03-21 06:03:58 +00:00
//these boards always have 8KB of VRAM
vram_byte_mask = ( Cart . vram_size * 1024 ) - 1 ;
2011-03-08 07:25:35 +00:00
prg_mask = ( Cart . prg_size / 16 ) - 1 ;
SetMirrorType ( Cart . pad_h , Cart . pad_v ) ;
2011-03-07 10:41:46 +00:00
return true ;
2011-02-28 07:53:19 +00:00
}
2011-03-07 10:41:46 +00:00
2011-02-28 07:53:19 +00:00
public override byte ReadPRG ( int addr )
{
int block = addr > > 14 ;
2011-03-02 02:54:06 +00:00
int page = block = = 1 ? prg_mask : prg ;
2011-02-28 07:53:19 +00:00
int ofs = addr & 0x3FFF ;
2011-03-07 10:41:46 +00:00
return ROM [ ( page < < 14 ) | ofs ] ;
2011-02-28 07:53:19 +00:00
}
public override void WritePRG ( int addr , byte value )
{
2011-09-25 02:52:53 +00:00
prg = adjust_prg ( value ) & prg_mask ;
2011-02-28 07:53:19 +00:00
}
public override byte ReadPPU ( int addr )
{
if ( addr < 0x2000 )
{
2011-03-21 06:03:58 +00:00
return VRAM [ addr & vram_byte_mask ] ;
2011-02-28 07:53:19 +00:00
}
2016-10-30 23:31:41 +00:00
else
{
if ( NES . _isVS )
{
addr = addr - 0x2000 ;
if ( addr < 0x800 )
{
return NES . CIRAM [ addr ] ;
}
else
{
return CIRAM_VS [ addr - 0x800 ] ;
}
}
else
return base . ReadPPU ( addr ) ;
}
2011-02-28 07:53:19 +00:00
}
public override void WritePPU ( int addr , byte value )
{
if ( addr < 0x2000 )
{
2011-03-21 06:03:58 +00:00
VRAM [ addr & vram_byte_mask ] = value ;
2011-02-28 07:53:19 +00:00
}
2016-10-30 23:31:41 +00:00
else if ( NES . _isVS )
{
// The game VS Castlevania apparently scans for more CIRAM then actually exists, so we have to mask out nonsensical values
addr & = 0x2FFF ;
addr = addr - 0x2000 ;
if ( addr < 0x800 )
{
NES . CIRAM [ addr ] = value ;
}
else
{
CIRAM_VS [ addr - 0x800 ] = value ;
}
}
else
base . WritePPU ( addr , value ) ;
2011-02-28 07:53:19 +00:00
}
2011-04-17 22:51:53 +00:00
public override void SyncState ( Serializer ser )
2011-03-01 09:32:12 +00:00
{
2011-04-17 22:51:53 +00:00
base . SyncState ( ser ) ;
ser . Sync ( "prg" , ref prg ) ;
2016-10-30 23:31:41 +00:00
if ( NES . IsVS )
2016-10-31 14:59:20 +00:00
{
2016-10-30 23:31:41 +00:00
ser . Sync ( "VS_CIRAM" , ref CIRAM_VS , false ) ;
2016-10-31 14:59:20 +00:00
}
2011-03-01 09:32:12 +00:00
}
2011-02-28 07:53:19 +00:00
}
2016-11-10 13:53:14 +00:00
}