public void Write(ushort address, byte value) { if (address >= 0x0000 && address <= 0x1FFF) { ramEnable = (value & 0x0F) == 0x0A; } else if (address >= 0x2000 && address <= 0x3FFF) { romBank = (byte)((romBank & 0x80) | (value & 0x7F)); romBank &= (byte)((romData.Length >> 14) - 1); if (romBank == 0x00) { romBank = 0x01; } } else if (address >= 0x4000 && address <= 0x5FFF) { if (value >= 0x00 && value <= 0x07) { rtc.IsSelected = false; ramBank = (byte)(value & 0x07); } else if (value >= 0x08 && value <= 0x0C) { rtc.IsSelected = true; rtc.SelectedRegister = (byte)(value - 0x08); } } else if (address >= 0x6000 && address <= 0x7FFF) { if (value == 0x00 && rtc.IsLatched) { rtc.IsLatched = false; } else if (value == 0x01 && !rtc.IsLatched) { rtc.Update(); for (var i = 0; i < RTC.NumRegisters; i++) { rtc.LatchedRegisters[i] = rtc.BaseRegisters[i]; } rtc.IsLatched = true; } } else if (address >= 0xA000 && address <= 0xBFFF) { if (rtc.IsSelected) { rtc.Update(); rtc.BaseRegisters[rtc.SelectedRegister] = value; } else if (ramEnable) { ramData[(ramBank << 13) | (address & 0x1FFF)] = value; } } }