src/memory/memory.cc
/*
 * Decodes the header of the provided rom file, and creates the appropriate
 * memory class for it.
 *
 * On success, the returned value is a memory mapper object cast to Memory.
 * On failure, returns NULL.
 *
 * Assumes the provided rom file is non-null and a valid NES rom.
 */
Decodes the header of the provided rom file, and creates the appropriate
memory class for it.

On success, the returned value is a memory mapper object cast to Memory.
On failure, returns NULL.

Assumes the provided rom file is non-null and a valid NES rom.
Decodes the header of the provided rom file and creates the appropriate memory class for it . On success the returned value is a memory mapper object cast to Memory . On failure returns NULL . Assumes the provided rom file is non - null and a valid NES rom .
Memory *Memory::Create(FILE *rom_file, Config *config) {
  RomHeader *header = DecodeHeader(rom_file);
  if (header == NULL) { return NULL; }
  Memory *mem = NULL;
  switch(header->mapper) {
    case NROM:
    case UXROM:
      mem = new StdBanked(rom_file, header, config);
      break;
    case SXROM:
      mem = new Sxrom(rom_file, header, config);
      break;
    default:
      fprintf(stderr, "Error: Rom requires unimplemented mapper: %d\n",
              static_cast<unsigned int>(header->mapper));
      delete header;
      return NULL;
      break;
  }
  return mem;
}
Memory * Memory :: Create ( FILE * rom_file , Config * config ) { RomHeader * header = DecodeHeader ( rom_file ) ; if ( header == NULL ) { return NULL ; } Memory * mem = NULL ; switch ( header -> mapper ) { case NROM : case UXROM : mem = new StdBanked ( rom_file , header , config ) ; break ; case SXROM : mem = new Sxrom ( rom_file , header , config ) ; break ; default : fprintf ( stderr , " \n " , static_cast < unsigned int > ( header -> mapper ) ) ; delete header ; return NULL ; break ; } return mem ; }
Decodes the header of the provided rom file, and creates the appropriate
 memory class for it.
Decodes the header of the provided rom file and creates the appropriate memory class for it .
// Use the provided rom file to create a decoded rom header. // Use the decoded header to decide which memory structure should be created.