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 # quickerNES Core Configuration
quickerNESCoreDependency = declare_dependency( 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']), include_directories : include_directories(['source', 'source/core', 'extern']),
sources : [ quickerNESCoreSrc, 'extern/metrohash128/metrohash128.cpp' ] 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 ) const char * Nes_Core::open( Nes_Cart const* new_cart )
{ {
close(); close();
RETURN_ERR( init() ); 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 ) if ( !mapper )
return unsupported_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() ) ); RETURN_ERR( ppu.open_chr( new_cart->chr(), new_cart->chr_size() ) );
cart = new_cart; 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 // Storage for the mapper, NULL by default
Nes_Mapper* mapper = NULL; Nes_Mapper* mapper = NULL;
@ -286,10 +283,6 @@ Nes_Mapper* Nes_Mapper::create( Nes_Cart const* cart, Nes_Core* emu )
return NULL; return NULL;
} }
// Assigning backwards pointers to cartdrige and emulator now
mapper->cart_ = cart;
mapper->emu_ = emu;
// Returning successfully created mapper // Returning successfully created mapper
return mapper; return mapper;
} }

View File

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