Refactoring mapper creation

This commit is contained in:
Sergio Martin 2024-01-14 08:18:23 +01:00
parent dba28a6b98
commit a0062b7002
4 changed files with 20 additions and 15 deletions

View File

@ -41,7 +41,7 @@ quickerNESCoreSrc = [
# quickerNES Core Configuration
quickerNESCoreDependency = declare_dependency(
compile_args : [ '-Wfatal-errors', '-Wall', '-Werror', '-Wno-multichar', '-DNDEBUG' ],
compile_args : [ '-Wfatal-errors', '-Wall', '-Werror', '-Wno-multichar', '-D_NES_MAPPER_002' ],
include_directories : include_directories(['source', 'source/core', 'extern']),
sources : [ quickerNESCoreSrc, 'extern/metrohash128/metrohash128.cpp' ]
)

View File

@ -66,13 +66,19 @@ void Nes_Core::close()
const char * Nes_Core::open( Nes_Cart const* new_cart )
{
close();
RETURN_ERR( init() );
mapper = Nes_Mapper::create( new_cart, this );
// Getting cartdrige mapper code
auto mapperCode = new_cart->mapper_code();
mapper = Nes_Mapper::create(mapperCode);
if ( !mapper )
return unsupported_mapper;
// Assigning backwards pointers to cartdrige and emulator now
mapper->cart_ = new_cart;
mapper->emu_ = this;
RETURN_ERR( ppu.open_chr( new_cart->chr(), new_cart->chr_size() ) );
cart = new_cart;

View File

@ -214,11 +214,8 @@ void Nes_Mapper::mirror_manual( int page0, int page1, int page2, int page3 )
}
Nes_Mapper* Nes_Mapper::create( Nes_Cart const* cart, Nes_Core* emu )
Nes_Mapper* Nes_Mapper::create(const int mapperCode)
{
// Getting cartdrige mapper code
auto mapperCode = cart->mapper_code();
// Storage for the mapper, NULL by default
Nes_Mapper* mapper = NULL;
@ -286,10 +283,6 @@ Nes_Mapper* Nes_Mapper::create( Nes_Cart const* cart, Nes_Core* emu )
return NULL;
}
// Assigning backwards pointers to cartdrige and emulator now
mapper->cart_ = cart;
mapper->emu_ = emu;
// Returning successfully created mapper
return mapper;
}

View File

@ -17,7 +17,7 @@ class Nes_Core;
class Nes_Mapper {
public:
// Create mapper appropriate for cartridge. Returns NULL if it uses unsupported mapper.
static Nes_Mapper* create( Nes_Cart const*, Nes_Core* );
static Nes_Mapper* create(const int mapperCode );
virtual ~Nes_Mapper();
@ -159,11 +159,17 @@ protected:
virtual void reset_state() { }
// End of general interface
public:
Nes_Cart const* cart_;
Nes_Core* emu_;
private:
Nes_Core* emu_;
void* state;
unsigned state_size;
Nes_Cart const* cart_;
void default_reset_state();
};