src/memory/mappers/sxrom.cc
/*
 * Creates a ram space with the amount of memory requested by the mapper.
 * If an INES header is used, the size is not defined and is created
 * based on the number of free bits in the CHR bank mask.
 *
 * If a NES2.0 header is specified, and the requested amount of PRG-RAM
 * conflicts with the CHR bank mask, this function aborts.
 *
 * Assumes the calling object was provided a valid header during initialization.
 * Assumes CHR data has been initialized for the calling object.
 */
Creates a ram space with the amount of memory requested by the mapper.
If an INES header is used, the size is not defined and is created
based on the number of free bits in the CHR bank mask.

If a NES2.0 header is specified, and the requested amount of PRG-RAM
conflicts with the CHR bank mask, this function aborts.

Assumes the calling object was provided a valid header during initialization.
Assumes CHR data has been initialized for the calling object.
Creates a ram space with the amount of memory requested by the mapper . If an INES header is used the size is not defined and is created based on the number of free bits in the CHR bank mask . If a NES2 . 0 header is specified and the requested amount of PRG - RAM conflicts with the CHR bank mask this function aborts . Assumes the calling object was provided a valid header during initialization . Assumes CHR data has been initialized for the calling object .
void Sxrom::LoadPrgRam(void) {
  if (header_->header_type != NES2) {
    if (chr_bank_mask_ <= 0x03U) {
      num_prg_ram_banks_ = SXROM_MAX_RAM_BANKS;
    } else if (chr_bank_mask_ <= 0x07U) {
      num_prg_ram_banks_ = SXROM_MAX_RAM_BANKS / 2U;
    } else {
      num_prg_ram_banks_ = 1U;
    }
  } else {
    num_prg_ram_banks_ = header_->prg_ram_size / RAM_BANK_SIZE;
  }
  prg_ram_bank_mask_ = CreateMask(num_prg_ram_banks_);
  prg_ram_bank_shift_ = (num_prg_ram_banks_ > 2U) ? 2U : 3U;
  prg_ram_bank_mask_ <<= prg_ram_bank_shift_;
  if (prg_ram_bank_mask_ & chr_bank_mask_) {
    fprintf(stderr, "Error: the requested amount of PRG-RAM cannot be"
                    " addressed with the given CHR size.\n");
    abort();
  }
  for (size_t i = 0; i < num_prg_ram_banks_; i++) {
    prg_ram_[i] = RandNew(RAM_BANK_SIZE);
  }
  return;
}
void Sxrom :: LoadPrgRam ( void ) { if ( header_ -> header_type != NES2 ) { if ( chr_bank_mask_ <= 0x03U ) { num_prg_ram_banks_ = SXROM_MAX_RAM_BANKS ; } else if ( chr_bank_mask_ <= 0x07U ) { num_prg_ram_banks_ = SXROM_MAX_RAM_BANKS / 2U ; } else { num_prg_ram_banks_ = 1U ; } } else { num_prg_ram_banks_ = header_ -> prg_ram_size / RAM_BANK_SIZE ; } prg_ram_bank_mask_ = CreateMask ( num_prg_ram_banks_ ) ; prg_ram_bank_shift_ = ( num_prg_ram_banks_ > 2U ) ? 2U : 3U ; prg_ram_bank_mask_ <<= prg_ram_bank_shift_ ; if ( prg_ram_bank_mask_ & chr_bank_mask_ ) { fprintf ( stderr , " " " \n " ) ; abort ( ) ; } for ( size_t i = 0 ; i < num_prg_ram_banks_ ; i ++ ) { prg_ram_ [ i ] = RandNew ( RAM_BANK_SIZE ) ; } return ; }
Creates a ram space with the amount of memory requested by the mapper.
Creates a ram space with the amount of memory requested by the mapper .
// Determine if the rom supplied a valid PRG-RAM size. // Determine the max amount of ram that can be given to the rom from // the number of CHR banks used. // The mapper is NES 2.0, so we can use the specified PRG-RAM size. // Create the bank mask/shift from the number of banks. // The bank mask will use bits 3/2 of the chr registers, depending on space. // Check for a conflict with CHR bank selection mask. // Allocate the PRG-RAM banks.