src/memory/mappers/sxrom.cc
/*
 * Determines if the given rom is using CHR-ROM or CHR-RAM, then creates
 * the necessary banks. Loads in the CHR data if the board is using CHR-ROM.
 * Creates a mask for accessing the CHR control register.
 *
 * This function aborts if the created mask conflicts with the PRG-ROM mask.
 *
 * Assumes the provided rom file is valid.
 * Assumes that the calling object has had its PRG-ROM initialized.
 */
Determines if the given rom is using CHR-ROM or CHR-RAM, then creates
the necessary banks. Loads in the CHR data if the board is using CHR-ROM.
Creates a mask for accessing the CHR control register.

This function aborts if the created mask conflicts with the PRG-ROM mask.

Assumes the provided rom file is valid.
Assumes that the calling object has had its PRG-ROM initialized.
Determines if the given rom is using CHR - ROM or CHR - RAM then creates the necessary banks . Loads in the CHR data if the board is using CHR - ROM . Creates a mask for accessing the CHR control register . This function aborts if the created mask conflicts with the PRG - ROM mask . Assumes the provided rom file is valid . Assumes that the calling object has had its PRG - ROM initialized .
void Sxrom::LoadChr(FILE *rom_file) {
  if (header_->chr_ram_size > 0) {
    is_chr_ram_ = true;
    num_chr_banks_ = header_->chr_ram_size / CHR_BANK_SIZE;
    for (size_t i = 0; i < num_chr_banks_; i++) {
      pattern_table_[i] = RandNew(CHR_BANK_SIZE);
    }
  } else {
    is_chr_ram_ = false;
    num_chr_banks_ = header_->chr_rom_size / CHR_BANK_SIZE;
    fseek(rom_file, HEADER_SIZE + header_->prg_rom_size, SEEK_SET);
    for (size_t i = 0; i < num_chr_banks_; i++) {
      pattern_table_[i] = new DataWord[CHR_BANK_SIZE];
      for (size_t j = 0; j < CHR_BANK_SIZE; j++) {
        pattern_table_[i][j] = fgetc(rom_file);
      }
    }
  }
  chr_bank_mask_ = CreateMask(num_chr_banks_);
  if (chr_bank_mask_ & prg_rom_high_mask_) {
    fprintf(stderr, "Error: The requested amount of PRG-ROM cannot be "
                    "addressed with the given CHR size.\n");
    abort();
  }
  return;
}
void Sxrom :: LoadChr ( FILE * rom_file ) { if ( header_ -> chr_ram_size > 0 ) { is_chr_ram_ = true ; num_chr_banks_ = header_ -> chr_ram_size / CHR_BANK_SIZE ; for ( size_t i = 0 ; i < num_chr_banks_ ; i ++ ) { pattern_table_ [ i ] = RandNew ( CHR_BANK_SIZE ) ; } } else { is_chr_ram_ = false ; num_chr_banks_ = header_ -> chr_rom_size / CHR_BANK_SIZE ; fseek ( rom_file , HEADER_SIZE + header_ -> prg_rom_size , SEEK_SET ) ; for ( size_t i = 0 ; i < num_chr_banks_ ; i ++ ) { pattern_table_ [ i ] = new DataWord [ CHR_BANK_SIZE ] ; for ( size_t j = 0 ; j < CHR_BANK_SIZE ; j ++ ) { pattern_table_ [ i ] [ j ] = fgetc ( rom_file ) ; } } } chr_bank_mask_ = CreateMask ( num_chr_banks_ ) ; if ( chr_bank_mask_ & prg_rom_high_mask_ ) { fprintf ( stderr , " " " \n " ) ; abort ( ) ; } return ; }
Determines if the given rom is using CHR-ROM or CHR-RAM, then creates
 the necessary banks.
Determines if the given rom is using CHR - ROM or CHR - RAM then creates the necessary banks .
// Check if the rom is using CHR-RAM, and allocate it if so. // Otherwise, the rom is using CHR-ROM and we must load it into the mapper. // Calculate the mask to be used to select the CHR banks in the CHR control // register. // Check if the requested rom size conflicts with the requested number of // CHR banks.