src/memory/mappers/sxrom.cc
/*
 * Updates the controlling registers for the calling object using the
 * given address and values.
 */
Updates the controlling registers for the calling object using the
given address and values.
Updates the controlling registers for the calling object using the given address and values .
void Sxrom::UpdateRegisters(DoubleWord addr, DataWord val) {
  if (val & FLAG_CONTROL_RESET) {
    shift_reg_ = SXROM_SHIFT_BASE;
    control_reg_ = control_reg_ | CONTROL_RESET_MASK;
    return;
  }
  if ((shift_reg_ & 1) != 1) {
    shift_reg_ = ((shift_reg_ >> 1U) & 0xFU) | ((val & 1U) << 4U);
    return;
  }
  DataWord update = ((shift_reg_ >> 1U) & 0xFU) | ((val & 1U) << 4U);
  shift_reg_ = SXROM_SHIFT_BASE;
  if ((CONTROL_UPDATE_OFFSET <= addr) && (addr < CHR_A_UPDATE_OFFSET)) {
    UpdateControl(update);
  } else if ((CHR_A_UPDATE_OFFSET <= addr) && (addr < CHR_B_UPDATE_OFFSET)) {
    chr_a_reg_ = update;
    chr_b_reg_ = (chr_b_reg_ & chr_bank_mask_) | (chr_a_reg_
               & (prg_ram_bank_mask_ | prg_rom_high_mask_));
    UpdateChrBanks();
    prg_ram_bank_ = (chr_a_reg_ & prg_ram_bank_mask_) >> prg_ram_bank_shift_;
  } else if ((CHR_B_UPDATE_OFFSET <= addr) && (addr < PRG_UPDATE_OFFSET)) {
    chr_b_reg_ = update;
    chr_a_reg_ = (chr_a_reg_ & chr_bank_mask_) | (chr_b_reg_
               & (prg_ram_bank_mask_ | prg_rom_high_mask_));
    UpdateChrBanks();
    prg_ram_bank_ = (chr_b_reg_ & prg_ram_bank_mask_) >> prg_ram_bank_shift_;
  } else if (addr >= PRG_UPDATE_OFFSET) {
    prg_reg_ = update;
    UpdatePrgRomBanks();
  }
  return;
}
void Sxrom :: UpdateRegisters ( DoubleWord addr , DataWord val ) { if ( val & FLAG_CONTROL_RESET ) { shift_reg_ = SXROM_SHIFT_BASE ; control_reg_ = control_reg_ | CONTROL_RESET_MASK ; return ; } if ( ( shift_reg_ & 1 ) != 1 ) { shift_reg_ = ( ( shift_reg_ >> 1U ) & 0xFU ) | ( ( val & 1U ) << 4U ) ; return ; } DataWord update = ( ( shift_reg_ >> 1U ) & 0xFU ) | ( ( val & 1U ) << 4U ) ; shift_reg_ = SXROM_SHIFT_BASE ; if ( ( CONTROL_UPDATE_OFFSET <= addr ) && ( addr < CHR_A_UPDATE_OFFSET ) ) { UpdateControl ( update ) ; } else if ( ( CHR_A_UPDATE_OFFSET <= addr ) && ( addr < CHR_B_UPDATE_OFFSET ) ) { chr_a_reg_ = update ; chr_b_reg_ = ( chr_b_reg_ & chr_bank_mask_ ) | ( chr_a_reg_ & ( prg_ram_bank_mask_ | prg_rom_high_mask_ ) ) ; UpdateChrBanks ( ) ; prg_ram_bank_ = ( chr_a_reg_ & prg_ram_bank_mask_ ) >> prg_ram_bank_shift_ ; } else if ( ( CHR_B_UPDATE_OFFSET <= addr ) && ( addr < PRG_UPDATE_OFFSET ) ) { chr_b_reg_ = update ; chr_a_reg_ = ( chr_a_reg_ & chr_bank_mask_ ) | ( chr_b_reg_ & ( prg_ram_bank_mask_ | prg_rom_high_mask_ ) ) ; UpdateChrBanks ( ) ; prg_ram_bank_ = ( chr_b_reg_ & prg_ram_bank_mask_ ) >> prg_ram_bank_shift_ ; } else if ( addr >= PRG_UPDATE_OFFSET ) { prg_reg_ = update ; UpdatePrgRomBanks ( ) ; } return ; }
Updates the controlling registers for the calling object using the
 given address and values.
Updates the controlling registers for the calling object using the given address and values .
// Check if this update requested to reset the shift register and PRG-ROM // bank selection. // If this update does not fill the shift register, we simply apply it // and return. // Shift the LSB of the value into the MSB of the 5-bit shift register. // Otherwise, we reset the shift register and apply the requested update. // Update the control register. // Update the CHR0 register and copy the PRG selections to CHR1. // Update the bank selections. // Update the CHR1 register and copy the PRG selections to CHR0. // Update the bank selections. // Update the PRG register.