2011-02-28 09:39:24 +00:00
using System ;
2011-03-01 09:32:12 +00:00
using System.IO ;
2011-02-28 09:39:24 +00:00
using System.Diagnostics ;
2011-03-08 07:25:35 +00:00
namespace BizHawk.Emulation.Consoles.Nintendo
2011-02-28 09:39:24 +00:00
{
//generally mapper7
2012-10-17 00:25:46 +00:00
[NES.INESBoardImplPriority]
2011-02-28 09:39:24 +00:00
public class AxROM : NES . NESBoardBase
{
2011-03-01 09:32:12 +00:00
//configuration
2011-02-28 09:39:24 +00:00
bool bus_conflict ;
2011-03-21 06:03:58 +00:00
int vram_byte_mask ;
2011-02-28 09:39:24 +00:00
int prg_mask ;
2011-03-01 09:32:12 +00:00
//state
2011-02-28 09:39:24 +00:00
int prg ;
2011-03-20 02:12:10 +00:00
public override bool Configure ( NES . EDetectionOrigin origin )
2011-02-28 09:39:24 +00:00
{
2011-03-07 10:41:46 +00:00
//configure
2011-03-08 07:25:35 +00:00
switch ( Cart . board_type )
2011-02-28 09:39:24 +00:00
{
2012-03-22 06:20:10 +00:00
case "MAPPER007" :
bus_conflict = false ;
2012-10-17 01:56:28 +00:00
Cart . vram_size = 8 ;
2012-03-22 06:20:10 +00:00
break ;
2011-03-08 07:25:35 +00:00
case "NES-ANROM" : //marble madness
AssertPrg ( 128 ) ; AssertChr ( 0 ) ; AssertVram ( 8 ) ; AssertWram ( 0 ) ;
2011-03-07 10:41:46 +00:00
bus_conflict = false ;
break ;
2011-03-08 07:25:35 +00:00
case "NES-AN1ROM" : //R.C. Pro-Am
AssertPrg ( 64 ) ; AssertChr ( 0 ) ; AssertVram ( 8 ) ; AssertWram ( 0 ) ;
2012-08-03 14:12:04 +00:00
bus_conflict = false ;
break ;
2011-03-07 10:41:46 +00:00
2011-03-08 07:25:35 +00:00
case "NES-AMROM" : //time lord
AssertPrg ( 128 ) ; AssertChr ( 0 ) ; AssertVram ( 8 ) ; AssertWram ( 0 ) ;
2012-08-03 14:12:04 +00:00
bus_conflict = true ;
break ;
2011-03-07 10:41:46 +00:00
2011-03-08 07:25:35 +00:00
case "NES-AOROM" : //battletoads
2011-03-07 10:41:46 +00:00
case "HVC-AOROM" :
2012-08-03 14:12:04 +00:00
AssertPrg ( 128 , 256 ) ; AssertChr ( 0 ) ; AssertVram ( 8 ) ; AssertWram ( 0 ) ;
2012-08-05 22:02:58 +00:00
bus_conflict = false ; //adelikat: I could not find an example of a game that needs bus conflicts, please enlightening me of a case where a game fails because of the lack of conflicts!
2012-08-03 14:12:04 +00:00
break ;
2011-03-07 10:41:46 +00:00
default :
return false ;
2011-02-28 09:39:24 +00:00
}
2011-03-08 07:25:35 +00:00
prg_mask = ( Cart . prg_size / 16 ) - 1 ;
2011-03-21 06:03:58 +00:00
vram_byte_mask = 8 * 1024 - 1 ; //these boards always have 8KB of VRAM
2011-03-02 03:05:28 +00:00
2011-02-28 10:16:07 +00:00
//it is necessary to write during initialization to set the mirroring
2011-02-28 09:39:24 +00:00
WritePRG ( 0 , 0 ) ;
2011-03-07 10:41:46 +00:00
return true ;
2011-02-28 09:39:24 +00:00
}
public override byte ReadPRG ( int addr )
{
2011-03-07 10:41:46 +00:00
return ROM [ addr + ( prg < < 14 ) ] ;
2011-02-28 09:39:24 +00:00
}
public override void WritePRG ( int addr , byte value )
{
2011-03-07 10:41:46 +00:00
if ( ROM ! = null & & bus_conflict ) value = HandleNormalPRGConflict ( addr , value ) ;
2011-06-06 10:27:42 +00:00
int prg_bank = value & 7 ;
prg = ( prg_bank * 2 ) & prg_mask ;
2011-02-28 09:39:24 +00:00
if ( ( value & 0x10 ) = = 0 )
2011-04-18 22:35:40 +00:00
SetMirrorType ( NES . NESBoardBase . EMirrorType . OneScreenA ) ;
2011-02-28 09:39:24 +00:00
else
2011-04-18 22:35:40 +00:00
SetMirrorType ( NES . NESBoardBase . EMirrorType . OneScreenB ) ;
2011-02-28 09:39:24 +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 09:39:24 +00:00
}
else return base . ReadPPU ( addr ) ;
}
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 09:39:24 +00:00
}
else base . WritePPU ( addr , value ) ;
}
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 ) ;
2011-03-01 09:32:12 +00:00
}
2011-02-28 09:39:24 +00:00
}
}