src/memory/mappers/std_banked.cc
/*
 * Loads the program rom data into the calling StdBanked class during contruction.
 *
 * Assumes the provided rom file is non-null and points to a valid NES rom.
 * Assumes the header field of the class is valid and matches the rom.
 */
Loads the program rom data into the calling StdBanked class during contruction.
Assumes the provided rom file is non-null and points to a valid NES rom.
Assumes the header field of the class is valid and matches the rom.
Loads the program rom data into the calling StdBanked class during contruction . Assumes the provided rom file is non - null and points to a valid NES rom . Assumes the header field of the class is valid and matches the rom .
void StdBanked::LoadPrg(FILE *rom_file) {
  size_t num_banks = static_cast<size_t>(header_->prg_rom_size / BANK_SIZE);
  if ((header_->mapper == NROM) && (num_banks > 2)) {
    fprintf(stderr, "Error: The ROM file requested an invalid amount of "
                    "program memory for its mapper.\n");
    abort();
  }
  fseek(rom_file, HEADER_SIZE, SEEK_SET);
  for (size_t i = 0; i < num_banks; i++) {
    cart_[i] = new DataWord[BANK_SIZE];
    for (size_t j = 0; j < BANK_SIZE; j++) {
      cart_[i][j] = fgetc(rom_file);
    }
  }
  fixed_bank_ = num_banks - 1;
  bank_mask_ = 0;
  if (header_->mapper == UXROM) {
    bank_mask_ = (num_banks > MAX_UNROM_BANKS)
               ? UOROM_BANK_MASK : UNROM_BANK_MASK;
  }
  return;
}
void StdBanked :: LoadPrg ( FILE * rom_file ) { size_t num_banks = static_cast < size_t > ( header_ -> prg_rom_size / BANK_SIZE ) ; if ( ( header_ -> mapper == NROM ) && ( num_banks > 2 ) ) { fprintf ( stderr , " " " \n " ) ; abort ( ) ; } fseek ( rom_file , HEADER_SIZE , SEEK_SET ) ; for ( size_t i = 0 ; i < num_banks ; i ++ ) { cart_ [ i ] = new DataWord [ BANK_SIZE ] ; for ( size_t j = 0 ; j < BANK_SIZE ; j ++ ) { cart_ [ i ] [ j ] = fgetc ( rom_file ) ; } } fixed_bank_ = num_banks - 1 ; bank_mask_ = 0 ; if ( header_ -> mapper == UXROM ) { bank_mask_ = ( num_banks > MAX_UNROM_BANKS ) ? UOROM_BANK_MASK : UNROM_BANK_MASK ; } return ; }
Loads the program rom data into the calling StdBanked class during contruction.
Loads the program rom data into the calling StdBanked class during contruction .
// Calculate and verify the number of PRG-ROM banks. // Load the rom into memory. // Setup the default banks and max banks.