2014-06-24 02:47:32 -04:00
# include "stdafx.h"
2014-06-24 21:59:58 -04:00
# include "ROMLoader.h"
2014-06-26 23:13:02 -04:00
# include "AXROM.h"
2014-06-24 21:59:58 -04:00
# include "CNROM.h"
2014-06-28 21:10:50 -04:00
# include "ColorDreams.h"
2014-06-24 02:47:32 -04:00
# include "MMC1.h"
2014-06-28 18:50:01 -04:00
# include "MMC2.h"
2014-06-24 21:59:58 -04:00
# include "MMC3.h"
# include "NROM.h"
2014-06-24 14:28:19 -04:00
# include "UNROM.h"
2014-06-24 02:47:32 -04:00
class MapperFactory
{
2014-06-26 23:13:02 -04:00
private :
static BaseMapper * GetMapperFromID ( uint8_t mapperID )
{
switch ( mapperID ) {
case 0 : return new NROM ( ) ;
case 1 : return new MMC1 ( ) ;
case 2 : return new UNROM ( ) ;
case 3 : return new CNROM ( ) ;
case 4 : return new MMC3 ( ) ;
2014-06-28 21:10:50 -04:00
case 5 : break ; //11 games
2014-06-26 23:13:02 -04:00
case 7 : return new AXROM ( ) ;
2014-06-28 18:50:01 -04:00
case 9 : return new MMC2 ( ) ;
2014-06-28 21:10:50 -04:00
case 11 : return new ColorDreams ( ) ; break ;
case 16 : break ; //18 games
case 19 : break ; //16 games
2014-06-28 18:50:01 -04:00
case 71 : return new UNROM ( ) ; //TODO: "It's largely a clone of UNROM, and Camerica games were initially emulated under iNES Mapper 002 before 071 was assigned."
2014-06-26 23:13:02 -04:00
}
throw std : : exception ( " Unsupported mapper " ) ;
return nullptr ;
}
2014-06-24 02:47:32 -04:00
public :
static shared_ptr < BaseMapper > InitializeFromFile ( wstring filename )
{
ROMLoader loader ( filename ) ;
2014-06-24 10:19:24 -04:00
uint8_t mapperID = loader . GetMapperID ( ) ;
2014-06-24 02:47:32 -04:00
2014-06-26 23:13:02 -04:00
BaseMapper * mapper = GetMapperFromID ( mapperID ) ;
2014-06-24 10:19:24 -04:00
mapper - > Initialize ( loader ) ;
2014-06-24 02:47:32 -04:00
return shared_ptr < BaseMapper > ( mapper ) ;
}
} ;