Struct spectrusty_formats::snapshot::Extensions
source · pub struct Extensions { /* private fields */ }
Implementations§
source§impl Extensions
impl Extensions
pub const NONE: Self = _
pub const IF1: Self = _
pub const PLUS_D: Self = _
pub const DISCIPLE: Self = _
pub const SAM_RAM: Self = _
pub const ULA_PLUS: Self = _
pub const TR_DOS: Self = _
pub const RESERVED: Self = _
sourcepub const fn empty() -> Self
pub const fn empty() -> Self
Returns an empty set of flags.
Examples found in repository?
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
fn select_hw_model(version: Z80Version, head_ex: &HeaderEx) -> Option<(ComputerModel, Extensions)> {
let hw_mode = head_ex.hw_mode;
let flags3 = Flags3::from(head_ex.flags3);
let mgt_type = head_ex.mgt_type;
use ComputerModel::*;
use Z80Version::*;
Some(match (hw_mode, version) {
(0, _) if flags3.is_alt_hw_mode() => (Spectrum16, Extensions::empty()),
(0, _) => (Spectrum48, Extensions::empty()),
(1, _) if flags3.is_alt_hw_mode() => (Spectrum16, Extensions::IF1),
(1, _) => (Spectrum48, Extensions::IF1),
(2, _) => (Spectrum48, Extensions::SAM_RAM),
(3, V2)|(4, V3) if flags3.is_alt_hw_mode() => (SpectrumPlus2, Extensions::empty()),
(3, V2)|(4, V3) => (Spectrum128, Extensions::empty()),
(3, V3) if flags3.is_alt_hw_mode() && mgt_type == 16 => (Spectrum16, Extensions::PLUS_D),
(3, V3) if flags3.is_alt_hw_mode() && mgt_type <= 1 => (Spectrum16, Extensions::DISCIPLE),
(3, V3) if mgt_type == 16 => (Spectrum48, Extensions::PLUS_D),
(3, V3) if mgt_type <= 1 => (Spectrum48, Extensions::DISCIPLE),
(4, V2)|(5, V3) => (Spectrum128, Extensions::IF1),
(6, V3) if mgt_type == 16 => (Spectrum128, Extensions::PLUS_D),
(6, V3) if mgt_type <= 1 => (Spectrum128, Extensions::DISCIPLE),
(7, _)|(8, _) if flags3.is_alt_hw_mode() => (SpectrumPlus2A, Extensions::empty()),
(7, _)|(8, _) => (SpectrumPlus3, Extensions::empty()),
// (9, _) => (Pentagon128, Extensions::empty()),
// (10, _) => (Scorpion256, Extensions::empty()),
// (11, _) => (DidaktikKompakt, Extensions::empty()),
(12, _) => (SpectrumPlus2, Extensions::empty()),
(13, _) => (SpectrumPlus2A, Extensions::empty()),
(14, _) => (TimexTC2048, Extensions::empty()),
(15, _) => (TimexTC2068, Extensions::empty()),
(128, _) => (TimexTS2068, Extensions::empty()),
_ => return None
})
}
sourcepub const fn from_bits(bits: u64) -> Option<Self>
pub const fn from_bits(bits: u64) -> Option<Self>
Convert from underlying bit representation, unless that representation contains bits that do not correspond to a flag.
sourcepub const fn from_bits_truncate(bits: u64) -> Self
pub const fn from_bits_truncate(bits: u64) -> Self
Convert from underlying bit representation, dropping any bits that do not correspond to flags.
sourcepub const unsafe fn from_bits_unchecked(bits: u64) -> Self
pub const unsafe fn from_bits_unchecked(bits: u64) -> Self
Convert from underlying bit representation, preserving all bits (even those not corresponding to a defined flag).
Safety
The caller of the bitflags!
macro can chose to allow or
disallow extra bits for their bitflags type.
The caller of from_bits_unchecked()
has to ensure that
all bits correspond to a defined flag or that extra bits
are valid for this bitflags type.
sourcepub const fn intersects(&self, other: Self) -> bool
pub const fn intersects(&self, other: Self) -> bool
Returns true
if there are flags common to both self
and other
.
Examples found in repository?
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
pub fn validate_extensions(self, ext: Extensions) -> Result<(), Extensions> {
use ComputerModel::*;
match self {
Spectrum128|SpectrumPlus2|SpectrumSE if ext.intersects(Extensions::SAM_RAM) => Err(Extensions::SAM_RAM),
SpectrumPlus2A|SpectrumPlus3|SpectrumPlus3e
if ext.intersects(Extensions::SAM_RAM|Extensions::IF1|Extensions::PLUS_D|Extensions::DISCIPLE) => {
Err(ext & (Extensions::SAM_RAM|Extensions::IF1|Extensions::PLUS_D|Extensions::DISCIPLE))
}
TimexTC2068|TimexTS2068 if ext.intersects(Extensions::SAM_RAM) => Err(Extensions::SAM_RAM),
_ => Ok(())
}
}
}
impl From<ComputerModel> for &str {
fn from(model: ComputerModel) -> Self {
use ComputerModel::*;
match model {
Spectrum16 => "ZX Spectrum 16k",
Spectrum48 => "ZX Spectrum 48k",
SpectrumNTSC => "ZX Spectrum NTSC",
Spectrum128 => "ZX Spectrum 128k",
SpectrumPlus2 => "ZX Spectrum +2",
SpectrumPlus2A => "ZX Spectrum +2A",
SpectrumPlus3 => "ZX Spectrum +3",
SpectrumPlus3e => "ZX Spectrum +3e",
SpectrumSE => "ZX Spectrum SE",
TimexTC2048 => "Timex TC2048",
TimexTC2068 => "Timex TC2068",
TimexTS2068 => "Timex TS2068",
}
}
}
impl From<&'_ ComputerModel> for &'static str {
fn from(model: &ComputerModel) -> Self {
(*model).into()
}
}
impl fmt::Display for ComputerModel {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
<&str>::from(self).fmt(f)
}
}
impl fmt::Display for Extensions {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.intersects(Extensions::IF1) {
f.write_str(" + IF1")?;
}
if self.intersects(Extensions::ULA_PLUS) {
f.write_str(" + ULAPlus")?;
}
if self.intersects(Extensions::PLUS_D) {
f.write_str(" + MGT+D")?;
}
if self.intersects(Extensions::DISCIPLE) {
f.write_str(" + DISCiPLE")?;
}
if self.intersects(Extensions::SAM_RAM) {
f.write_str(" + SamRam")?;
}
Ok(())
}
More examples
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
fn mem_page_to_range(page: u8, model: ComputerModel, ext: Extensions) -> Option<MemoryRange> {
use ComputerModel::*;
match model {
Spectrum16|Spectrum48|
TimexTC2048|TimexTS2068|TimexTC2068 => {
Some(match page {
0 => MemoryRange::Rom(0..PAGE_SIZE),
1 if ext.intersects(Extensions::IF1) => MemoryRange::Interface1Rom,
1 if ext.intersects(Extensions::PLUS_D) => MemoryRange::PlusDRom,
1 if ext.intersects(Extensions::DISCIPLE) => MemoryRange::DiscipleRom,
2 if ext.intersects(Extensions::SAM_RAM) => MemoryRange::SamRamRom(0..PAGE_SIZE),
3 if ext.intersects(Extensions::SAM_RAM) => MemoryRange::SamRamRom(PAGE_SIZE..2*PAGE_SIZE),
4 => MemoryRange::Ram( PAGE_SIZE..2*PAGE_SIZE),
5 => MemoryRange::Ram(2*PAGE_SIZE..3*PAGE_SIZE),
6 if ext.intersects(Extensions::SAM_RAM) => MemoryRange::Ram(3*PAGE_SIZE..4*PAGE_SIZE),
7 if ext.intersects(Extensions::SAM_RAM) => MemoryRange::Ram(4*PAGE_SIZE..5*PAGE_SIZE),
8 => MemoryRange::Ram(0..PAGE_SIZE),
11 => MemoryRange::MultifaceRom,
_ => return None
})
}
Spectrum128|SpectrumPlus2|
SpectrumPlus2A|SpectrumPlus3|SpectrumPlus3e|
SpectrumSE => {
Some(match page {
0 => MemoryRange::Rom(PAGE_SIZE..2*PAGE_SIZE),
1 if ext.intersects(Extensions::IF1) => MemoryRange::Interface1Rom,
1 if ext.intersects(Extensions::PLUS_D) => MemoryRange::PlusDRom,
1 if ext.intersects(Extensions::DISCIPLE) => MemoryRange::DiscipleRom,
2 => MemoryRange::Rom(0..PAGE_SIZE),
3..=10 => {
let address = (page - 3) as usize * PAGE_SIZE;
MemoryRange::Ram(address..address + PAGE_SIZE)
}
11..=18 if model == SpectrumSE => {
let address = (page - 11) as usize * PAGE_SIZE;
MemoryRange::Ram(address..address + PAGE_SIZE)
}
11 => MemoryRange::MultifaceRom,
_ => return None
})
}
_ => None
}
}
fn create_cpu(head: &Header) -> Result<Z80NMOS> {
let mut cpu = Z80NMOS::default();
cpu.reset();
cpu.set_i(head.i);
cpu.set_reg16(StkReg16::HL, u16::from_le_bytes(head.hl_alt));
cpu.set_reg16(StkReg16::DE, u16::from_le_bytes(head.de_alt));
cpu.set_reg16(StkReg16::BC, u16::from_le_bytes(head.bc_alt));
cpu.exx();
cpu.set_acc(head.a_alt);
cpu.set_flags(CpuFlags::from_bits_truncate(head.f_alt));
cpu.ex_af_af();
cpu.set_reg16(StkReg16::HL, u16::from_le_bytes(head.hl));
cpu.set_reg16(StkReg16::DE, u16::from_le_bytes(head.de));
cpu.set_reg16(StkReg16::BC, u16::from_le_bytes(head.bc));
cpu.set_index16(Prefix::Yfd, u16::from_le_bytes(head.iy));
cpu.set_index16(Prefix::Xdd, u16::from_le_bytes(head.ix));
cpu.set_iffs(head.iff1 != 0, head.iff2 != 0);
cpu.set_r(Flags1::from(head.flags1).mix_r(head.r7));
cpu.set_acc(head.a);
cpu.set_flags(CpuFlags::from_bits_truncate(head.f));
cpu.set_sp(u16::from_le_bytes(head.sp));
cpu.set_im(Flags2::from(head.flags2).interrupt_mode()?);
cpu.set_pc(u16::from_le_bytes(head.pc));
Ok(cpu)
}
/// Loads a **Z80** file from `rd` into the provided snapshot `loader` implementing [SnapshotLoader].
///
/// # Errors
/// This function will return an error if the file size is incorrect or there is something wrong
/// with the format.
/// Other errors may also be returned from attempts to read the file.
pub fn load_z80<R: Read, S: SnapshotLoader>(
mut rd: R,
loader: &mut S
) -> Result<()>
{
use ComputerModel::*;
let header = Header::read_new_struct(rd.by_ref())?;
let mut version = Z80Version::V1;
let mut model = ComputerModel::Spectrum48;
let mut extensions = Extensions::default();
let mut cpu = create_cpu(&header)?;
let header_ex = if cpu.get_pc() == 0 {
let (ver, head_ex) = load_header_ex(rd.by_ref())?;
version = ver;
cpu.set_pc(u16::from_le_bytes(head_ex.pc));
let (mdl, ext) = select_hw_model(version, &head_ex).ok_or_else(||
io::Error::new(io::ErrorKind::InvalidData, "unsupported model")
)?;
model = mdl;
extensions = ext;
Some(head_ex)
}
else {
None
};
let flags1 = Flags1::from(header.flags1);
let border = flags1.border_color();
let flags2 = Flags2::from(header.flags2);
let joystick = flags2.joystick_model();
let issue = model.applicable_issue(
if flags2.is_issue2_emulation() {
ReadEarMode::Issue2
}
else {
ReadEarMode::Issue3
}
);
loader.select_model(model, extensions, border, issue)
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
loader.select_joystick(joystick);
loader.assign_cpu(CpuModel::NMOS(cpu));
// clippy false positive: https://github.com/rust-lang/rust-clippy/issues/9274
#[allow(clippy::read_zero_byte_vec)] {
let mut buf = Vec::new();
if version == Z80Version::V1 {
if flags1.is_mem_compressed() {
rd.read_to_end(&mut buf)?;
let buf = match buf.get(buf.len() - 4..) {
Some(MEMORY_V1_TERM) => &buf[..buf.len() - 4],
_ => &buf[..]
};
let decompress = MemDecompress::new(buf);
loader.read_into_memory(MemoryRange::Ram(0..3*PAGE_SIZE), decompress)?;
}
else {
loader.read_into_memory(MemoryRange::Ram(0..3*PAGE_SIZE), rd)?;
}
}
else {
while let Some((len, page, is_compressed)) = load_mem_header(rd.by_ref())? {
let range = mem_page_to_range(page, model, extensions).ok_or_else(||
io::Error::new(io::ErrorKind::InvalidData, "unsupported memory page")
)?;
if is_compressed {
buf.resize(len, 0);
rd.read_exact(&mut buf)?;
let decompress = MemDecompress::new(&buf);
loader.read_into_memory(range, decompress)?;
}
else {
loader.read_into_memory(range, rd.by_ref().take(len as u64))?;
}
}
}}
if let Some(head_ex) = header_ex {
if let Some(choice) = select_ay_model(model, Flags3::from(head_ex.flags3)) {
loader.setup_ay(choice, head_ex.ay_sel_reg.into(), &head_ex.ay_regs);
}
if version == Z80Version::V3 {
let ts = z80_to_cycles(u16::from_le_bytes(head_ex.ts_lo), head_ex.ts_hi, model);
loader.set_clock(ts);
let data = head_ex.port2;
if data != 0 {
match model {
SpectrumPlus2A|SpectrumPlus3|SpectrumPlus3e|
SpectrumSE => {
loader.write_port(0x1ffd, data);
}
_ => {}
}
}
}
match model {
TimexTC2048|TimexTS2068|TimexTC2068 => {
loader.write_port(0xf4, head_ex.port1);
}
Spectrum128|SpectrumPlus2|
SpectrumPlus2A|SpectrumPlus3|SpectrumPlus3e|
SpectrumSE => {
loader.write_port(0x7ffd, head_ex.port1);
}
_ => {}
}
match model {
TimexTC2048|TimexTS2068|TimexTC2068 => {
loader.write_port(0xff, head_ex.ifrom);
}
Spectrum16|Spectrum48|
Spectrum128|SpectrumPlus2|
SpectrumPlus2A|SpectrumPlus3|SpectrumPlus3e|
SpectrumSE
if head_ex.ifrom == 0xff && extensions.intersects(Extensions::IF1) => {
loader.interface1_rom_paged_in();
}
_ => {}
}
}
Ok(())
}
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
fn select_hw_model_v2<S: SnapshotCreator>(
model: ComputerModel,
ext: Extensions,
snapshot: &S,
result: &mut SnapshotResult
) -> Result<(u8, bool)>
{
use ComputerModel::*;
if ext.intersects(Extensions::PLUS_D) && snapshot.is_plus_d_rom_paged_in()
|| ext.intersects(Extensions::DISCIPLE) && snapshot.is_disciple_rom_paged_in()
|| ext.intersects(Extensions::TR_DOS) && snapshot.is_tr_dos_rom_paged_in()
|| ext.contains(Extensions::IF1|Extensions::SAM_RAM) && snapshot.is_interface1_rom_paged_in()
{
return Err(io::Error::new(io::ErrorKind::InvalidInput,
"Z80: can't create a version 2 snapshot with the external ROM paged in"))
}
if (ext&!(Extensions::IF1|Extensions::SAM_RAM)) != Extensions::NONE
|| ext.contains(Extensions::IF1|Extensions::SAM_RAM)
{
result.insert(SnapshotResult::EXTENSTION_NSUP);
}
Ok(match model {
Spectrum16 if ext.intersects(Extensions::SAM_RAM) => (2, true),
Spectrum16 if ext.intersects(Extensions::IF1) => (1, true),
Spectrum16 => (0, true),
Spectrum48 if ext.intersects(Extensions::SAM_RAM) => (2, false),
Spectrum48 if ext.intersects(Extensions::IF1) => (1, false),
Spectrum48 => (0, false),
SpectrumNTSC => {
result.insert(SnapshotResult::MODEL_NSUP);
(if ext.intersects(Extensions::SAM_RAM) { 2 }
else { ext.intersects(Extensions::IF1) as u8 }, false)
}
Spectrum128 if ext.intersects(Extensions::IF1) => (4, false),
Spectrum128 => (3, false),
SpectrumPlus2 if ext.intersects(Extensions::IF1) => (4, true),
SpectrumPlus2 => (3, true),
SpectrumPlus2A => (7, true),
SpectrumPlus3 => (7, false),
SpectrumPlus3e => {
result.insert(SnapshotResult::MODEL_NSUP);
(7, false)
}
SpectrumSE => {
return Err(io::Error::new(io::ErrorKind::InvalidInput,
"Z80: can't create a snapshot of SpectrumSE"))
}
TimexTC2048|TimexTC2068|TimexTS2068 if ext.intersects(Extensions::IF1)
&& snapshot.is_interface1_rom_paged_in() => {
return Err(io::Error::new(io::ErrorKind::InvalidInput,
"Z80: can't create a snapshot of Timex + IF1 with IF1 ROM paged in"))
}
TimexTC2048 => (14, false),
TimexTC2068 => (15, false),
TimexTS2068 => (128, false),
})
}
fn select_hw_model_v3<S: SnapshotCreator>(
model: ComputerModel,
ext: Extensions,
snapshot: &S,
result: &mut SnapshotResult
) -> Result<(u8, bool)>
{
use ComputerModel::*;
if ext.intersects(Extensions::TR_DOS) && snapshot.is_tr_dos_rom_paged_in()
|| ext.contains(Extensions::IF1|Extensions::SAM_RAM) && snapshot.is_interface1_rom_paged_in()
{
return Err(io::Error::new(io::ErrorKind::InvalidInput,
"Z80: can't create a version 3 snapshot with the external ROM paged in"))
}
if ext.contains(Extensions::IF1|Extensions::SAM_RAM) {
result.insert(SnapshotResult::EXTENSTION_NSUP);
}
Ok(match model {
Spectrum16 if ext.intersects(Extensions::SAM_RAM) => (2, true),
Spectrum16 if ext.intersects(Extensions::IF1) => (1, true),
Spectrum16 if ext.intersects(Extensions::PLUS_D|Extensions::DISCIPLE) => (3, true),
Spectrum16 => (0, true),
Spectrum48 if ext.intersects(Extensions::SAM_RAM) => (2, false),
Spectrum48 if ext.intersects(Extensions::IF1) => (1, false),
Spectrum48 if ext.intersects(Extensions::PLUS_D|Extensions::DISCIPLE) => (3, false),
Spectrum48 => (0, false),
SpectrumNTSC => {
result.insert(SnapshotResult::MODEL_NSUP);
(if ext.intersects(Extensions::SAM_RAM) { 2 }
else if ext.intersects(Extensions::IF1) { 1 }
else if ext.intersects(Extensions::PLUS_D|Extensions::DISCIPLE) { 3 }
else { 0 }, false)
}
Spectrum128 if ext.intersects(Extensions::IF1) => (5, false),
Spectrum128 if ext.intersects(Extensions::PLUS_D|Extensions::DISCIPLE) => (6, false),
Spectrum128 => (4, false),
SpectrumPlus2 if ext.intersects(Extensions::IF1) => (5, true),
SpectrumPlus2 if ext.intersects(Extensions::PLUS_D|Extensions::DISCIPLE) => (6, true),
SpectrumPlus2 => (4, true),
SpectrumPlus2A => (7, true),
SpectrumPlus3 => (7, false),
SpectrumPlus3e => {
result.insert(SnapshotResult::MODEL_NSUP);
(7, false)
}
SpectrumSE => {
return Err(io::Error::new(io::ErrorKind::InvalidInput,
"Z80: can't create a snapshot of SpectrumSE"))
}
TimexTC2048|TimexTC2068|TimexTS2068 if (ext.intersects(Extensions::IF1) && snapshot.is_interface1_rom_paged_in())
|| (ext.intersects(Extensions::PLUS_D) && snapshot.is_plus_d_rom_paged_in())
|| (ext.intersects(Extensions::DISCIPLE) && snapshot.is_disciple_rom_paged_in())
=> {
return Err(io::Error::new(io::ErrorKind::InvalidInput,
"Z80: can't create a snapshot of Timex with extension ROM paged in"))
}
TimexTC2048 => (14, false),
TimexTC2068 => (15, false),
TimexTS2068 => (128, false),
})
}
type HwModelSelector<S> = fn(
ComputerModel, Extensions, &S, &mut SnapshotResult
) -> Result<(u8, bool)>;
fn init_z80_header_ex<S: SnapshotCreator, C: Cpu>(
head_ex: &mut HeaderEx,
cpu: C,
model: ComputerModel,
ext: Extensions,
snapshot: &S,
select_hw_model: HwModelSelector<S>,
result: &mut SnapshotResult
) -> Result<()>
{
use ComputerModel::*;
head_ex.pc = cpu.get_pc().to_le_bytes();
let (hw_mode, alt_hw) = select_hw_model(model, ext, snapshot, result)?;
let mut flags3 = Flags3::empty();
flags3.set(Flags3::ALT_HW_MODE, alt_hw);
head_ex.hw_mode = hw_mode;
let res = if let Some(res) = snapshot.ay_state(Ay3_891xDevice::Ay128k) {
if snapshot.ay_state(Ay3_891xDevice::FullerBox).is_some()
|| snapshot.ay_state(Ay3_891xDevice::Melodik).is_some()
{
result.insert(SnapshotResult::SOUND_CHIP_NSUP);
}
Some(res)
}
else if let Some(res) = snapshot.ay_state(Ay3_891xDevice::FullerBox) {
flags3.insert(Flags3::AY_SOUND_EMU|Flags3::AY_FULLER_BOX);
Some(res)
}
else if let Some(res) = snapshot.ay_state(Ay3_891xDevice::Melodik) {
flags3.insert(Flags3::AY_SOUND_EMU);
Some(res)
}
else {
snapshot.ay_state(Ay3_891xDevice::Timex)
};
if let Some((ay_sel_reg, ay_regs)) = res {
head_ex.ay_sel_reg = ay_sel_reg.into();
head_ex.ay_regs = *ay_regs;
}
head_ex.port1 = match model {
Spectrum128|SpectrumPlus2|SpectrumPlus2A|SpectrumPlus3|SpectrumPlus3e|
SpectrumSE => snapshot.ula128_flags().bits(),
TimexTC2048|TimexTC2068|TimexTS2068 => snapshot.timex_memory_banks(),
_ => 0
};
head_ex.ifrom = match model {
TimexTC2048|TimexTS2068|TimexTC2068 => {
if ext.intersects(Extensions::IF1|Extensions::PLUS_D|Extensions::DISCIPLE) {
result.insert(SnapshotResult::EXTENSTION_NSUP);
}
snapshot.timex_flags().bits()
}
_ if ext.intersects(Extensions::IF1) && snapshot.is_interface1_rom_paged_in() => {
!0
}
_ => 0
};
head_ex.flags3 = flags3.bits();
Ok(())
}
fn save_ram_pages<W: Write, S: SnapshotCreator, I: Iterator<Item=(u8, usize)>>(
mut wr: W,
snapshot: &S,
pages: I
) -> Result<()>
{
let mut buf = Vec::with_capacity(0x1000);
for (ptype, page) in pages {
buf.clear();
let mem_slice = snapshot.memory_ref(MemoryRange::Ram(page * PAGE_SIZE..(page + 1) * PAGE_SIZE))?;
compress_write_all(mem_slice, &mut buf)?;
let (mem_head, slice) = match buf.len().try_into() {
Ok(core::u16::MAX)|Err(..) => {
(MemoryHeader::new(core::u16::MAX, ptype), mem_slice)
}
Ok(length) => (MemoryHeader::new(length, ptype), &buf[..]),
};
mem_head.write_struct(wr.by_ref())?;
wr.write_all(slice)?;
}
wr.flush()
}
fn save_all_v2v3<W: Write, S: SnapshotCreator>(
version: Z80Version,
snapshot: &S,
model: ComputerModel,
header: &Header,
head_ex: &HeaderEx,
mut wr: W
) -> Result<()>
{
use ComputerModel::*;
header.write_struct(wr.by_ref())?;
let ex_len: u16 = match version {
Z80Version::V2 => 23,
Z80Version::V3 if head_ex.port2 != 0 => 55,
Z80Version::V3 => 54,
_ => unreachable!()
};
wr.write_all(&ex_len.to_le_bytes()[..])?;
head_ex.write_struct_with_limit(wr.by_ref(), ex_len as usize)?;
match model {
Spectrum16 => {
save_ram_pages(wr, snapshot, iter::once((8, 0)))
}
Spectrum48|SpectrumNTSC|TimexTC2048|TimexTS2068|TimexTC2068 => {
save_ram_pages(wr, snapshot,
[(8, 0), (4, 1), (5, 2)].iter().copied())
}
Spectrum128|SpectrumPlus2|SpectrumPlus2A|SpectrumPlus3|SpectrumPlus3e => {
save_ram_pages(wr, snapshot,
(0..8).map(|page| (page as u8 + 3, page))
)
}
_ => unreachable!()
}
}
fn get_nmos_cpu(cpu: CpuModel, result: &mut SnapshotResult) -> Z80NMOS {
match cpu {
CpuModel::NMOS(cpu) => cpu,
CpuModel::CMOS(cpu) => {
result.insert(SnapshotResult::CPU_MODEL_NSUP);
cpu.into_flavour()
},
CpuModel::BM1(cpu) => {
result.insert(SnapshotResult::CPU_MODEL_NSUP);
cpu.into_flavour()
}
}
}
/// Saves a **Z80** file version 1 into `wr` from the provided reference to a `snapshot` struct
/// implementing [SnapshotCreator].
///
/// # Errors
/// This function may return an error from attempts to write the file or if for some reason
/// a snapshot could not be created.
pub fn save_z80v1<C: SnapshotCreator, W: Write>(
snapshot: &C,
mut wr: W
) -> Result<SnapshotResult>
{
use ComputerModel::*;
let mut result = SnapshotResult::OK;
let model = snapshot.model();
match model {
Spectrum48 => {},
Spectrum16|SpectrumNTSC|TimexTC2048 => {
result.insert(SnapshotResult::MODEL_NSUP);
}
_ => return Err(io::Error::new(io::ErrorKind::InvalidInput,
"Z80: can't create a version 1 snapshot of this computer model"))
};
let extensions = snapshot.extensions();
if let Err(bad_ext) = model.validate_extensions(extensions) {
return Err(io::Error::new(io::ErrorKind::InvalidInput,
format!("Z80: the model {} can't be saved with {}", model, bad_ext)))
}
if extensions.intersects(Extensions::IF1) && snapshot.is_interface1_rom_paged_in()
|| extensions.intersects(Extensions::PLUS_D) && snapshot.is_plus_d_rom_paged_in()
|| extensions.intersects(Extensions::DISCIPLE) && snapshot.is_disciple_rom_paged_in()
|| extensions.intersects(Extensions::TR_DOS) && snapshot.is_tr_dos_rom_paged_in()
{
return Err(io::Error::new(io::ErrorKind::InvalidInput,
"Z80: can't create a version 1 snapshot with the external ROM paged in"))
}
if extensions != Extensions::NONE {
result.insert(SnapshotResult::EXTENSTION_NSUP);
}
let cpu = get_nmos_cpu(snapshot.cpu(), &mut result);
let border = snapshot.border_color();
let issue = snapshot.issue();
let joystick = snapshot.joystick();
if snapshot.ay_state(Ay3_891xDevice::Ay128k).is_some()
|| snapshot.ay_state(Ay3_891xDevice::Melodik).is_some()
|| snapshot.ay_state(Ay3_891xDevice::FullerBox).is_some()
|| snapshot.ay_state(Ay3_891xDevice::Timex).is_some()
{
result.insert(SnapshotResult::SOUND_CHIP_NSUP);
}
let mut header = Header::default();
init_z80_header(
&mut header,
Z80Version::V1,
&cpu,
border,
issue,
joystick,
&mut result
);
header.write_struct(wr.by_ref())?;
let is_16k = model == ComputerModel::Spectrum16;
let ramend = if is_16k { 0x4000 } else { 0xC000 };
let mem_slice = snapshot.memory_ref(MemoryRange::Ram(0..ramend))?;
compress_write_all(mem_slice, wr.by_ref())?;
if is_16k {
compress_repeat_write_all(!0, 0x8000, wr.by_ref())?;
}
wr.write_all(MEMORY_V1_TERM)?;
wr.flush()?;
Ok(result)
}
/// Saves a **Z80** file version 2 into `wr` from the provided reference to a `snapshot` struct
/// implementing [SnapshotCreator].
///
/// # Errors
/// This function may return an error from attempts to write the file or if for some reason
/// a snapshot could not be created.
pub fn save_z80v2<C: SnapshotCreator, W: Write>(
snapshot: &C,
wr: W
) -> Result<SnapshotResult>
{
let mut result = SnapshotResult::OK;
let model = snapshot.model();
let ext = snapshot.extensions();
let border = snapshot.border_color();
let issue = snapshot.issue();
let joystick = snapshot.joystick();
let cpu = get_nmos_cpu(snapshot.cpu(), &mut result);
if !is_cpu_safe_for_snapshot(&cpu) {
return Err(io::Error::new(io::ErrorKind::InvalidInput, "Z80: can't safely snapshot the CPU state"))
}
if let Err(bad_ext) = model.validate_extensions(ext) {
return Err(io::Error::new(io::ErrorKind::InvalidInput,
format!("Z80: the model {} can't be saved with {}", model, bad_ext)))
}
let mut header = Header::default();
init_z80_header(
&mut header,
Z80Version::V2,
&cpu,
border,
issue,
joystick,
&mut result
);
let mut head_ex = HeaderEx::default();
init_z80_header_ex(
&mut head_ex,
cpu,
model,
ext,
snapshot,
select_hw_model_v2,
&mut result
)?;
save_all_v2v3(Z80Version::V2, snapshot, model, &header, &head_ex, wr)?;
Ok(result)
}
/// Saves a **Z80** file version 3 into `wr` from the provided reference to a `snapshot` struct
/// implementing [SnapshotCreator].
///
/// # Errors
/// This function may return an error from attempts to write the file or if for some reason
/// a snapshot could not be created.
pub fn save_z80v3<C: SnapshotCreator, W: Write>(
snapshot: &C,
wr: W
) -> Result<SnapshotResult>
{
use ComputerModel::*;
let mut result = SnapshotResult::OK;
let model = snapshot.model();
let ext = snapshot.extensions();
let border = snapshot.border_color();
let issue = snapshot.issue();
let joystick = snapshot.joystick();
let cpu = get_nmos_cpu(snapshot.cpu(), &mut result);
if !is_cpu_safe_for_snapshot(&cpu) {
return Err(io::Error::new(io::ErrorKind::InvalidInput, "Z80: can't safely snapshot the CPU state"))
}
if let Err(bad_ext) = model.validate_extensions(ext) {
return Err(io::Error::new(io::ErrorKind::InvalidInput,
format!("Z80: the model {} can't be saved with {}", model, bad_ext)))
}
let mut header = Header::default();
init_z80_header(
&mut header,
Z80Version::V3,
&cpu,
border,
issue,
joystick,
&mut result
);
let mut head_ex = HeaderEx::default();
init_z80_header_ex(
&mut head_ex,
cpu,
model,
ext,
snapshot,
select_hw_model_v3,
&mut result
)?;
let (ts_lo, ts_hi) = cycles_to_z80(snapshot.current_clock(), model);
head_ex.ts_lo = ts_lo.to_le_bytes();
head_ex.ts_hi = ts_hi;
if (ext.intersects(Extensions::PLUS_D) && snapshot.is_plus_d_rom_paged_in())
|| (ext.intersects(Extensions::DISCIPLE) && snapshot.is_disciple_rom_paged_in())
{
head_ex.mgt_rom = !0;
}
if let Some(JoystickModel::Sinclair2) = joystick {
head_ex.joy_bindings = [ 3, 1, 3, 2, 3, 4, 3, 8, 3,10];
head_ex.joy_ascii = [31, 0,32, 0,33, 0,34, 0,35, 0];
}
match model {
SpectrumPlus2A|SpectrumPlus3|SpectrumPlus3e => {
head_ex.port2 = snapshot.ula3_flags().bits();
}
_ => {
head_ex.fn1 = !0;
if !(ext.intersects(Extensions::PLUS_D) && snapshot.is_plus_d_rom_paged_in()) {
head_ex.fn2 = !0;
}
}
}
if ext.intersects(Extensions::PLUS_D) {
head_ex.mgt_type = 16;
}
// head_ex.flags4 = 0;
// head_ex.disciple1 = 0;
// head_ex.disciple2 = 0;
save_all_v2v3(Z80Version::V3, snapshot, model, &header, &head_ex, wr)?;
Ok(result)
}
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
pub fn save_sna<C: SnapshotCreator, W: Write>(
snapshot: &C,
mut wr: W
) -> Result<SnapshotResult>
{
use ComputerModel::*;
let mut result = SnapshotResult::KEYB_ISSUE_NSUP;
let model = snapshot.model();
let is_128 = match model {
Spectrum48 => false,
Spectrum128 => true,
SpectrumPlus2|SpectrumPlus2A|SpectrumPlus3|SpectrumPlus3e|SpectrumSE => {
result.insert(SnapshotResult::MODEL_NSUP);
true
}
Spectrum16|SpectrumNTSC|TimexTC2048|TimexTC2068|TimexTS2068 => {
result.insert(SnapshotResult::MODEL_NSUP);
false
}
};
let extensions = snapshot.extensions();
if extensions.intersects(Extensions::IF1) && snapshot.is_interface1_rom_paged_in()
|| extensions.intersects(Extensions::PLUS_D) && snapshot.is_plus_d_rom_paged_in()
{
return Err(Error::new(ErrorKind::InvalidInput,
"SNA: can't create a snapshot with the external ROM paged in"))
}
if extensions != Extensions::NONE && extensions != Extensions::TR_DOS {
result.insert(SnapshotResult::EXTENSTION_NSUP);
}
let cpu = match snapshot.cpu() {
CpuModel::NMOS(cpu) => cpu,
CpuModel::CMOS(cpu) => {
result.insert(SnapshotResult::CPU_MODEL_NSUP);
cpu.into_flavour()
},
CpuModel::BM1(cpu) => {
result.insert(SnapshotResult::CPU_MODEL_NSUP);
cpu.into_flavour()
}
};
if !is_cpu_safe_for_snapshot(&cpu) {
return Err(Error::new(ErrorKind::InvalidInput, "SNA: can't safely snapshot the CPU state"))
}
let mut sna = make_header(&cpu);
sna.border = snapshot.border_color().into();
if snapshot.joystick().is_some() {
result.insert(SnapshotResult::JOYSTICK_NSUP);
}
if is_128 || snapshot.ay_state(Ay3_891xDevice::Melodik).is_some()
|| snapshot.ay_state(Ay3_891xDevice::FullerBox).is_some()
|| snapshot.ay_state(Ay3_891xDevice::Timex).is_some() {
result.insert(SnapshotResult::SOUND_CHIP_NSUP);
}
if !is_128 {
return save_sna48(snapshot, cpu, model == ComputerModel::Spectrum16, sna, wr, result)
}
let memflags = snapshot.ula128_flags();
let mut sna_ext = SnaHeader128 {
pc: cpu.get_pc().to_le_bytes(),
port_data: memflags.bits(),
..Default::default()
};
if extensions.intersects(Extensions::TR_DOS) {
sna_ext.trdos_rom = snapshot.is_tr_dos_rom_paged_in().into();
}
sna.write_struct(wr.by_ref())?;
let last_page: usize = memflags.last_ram_page_bank();
let index48 = [5,2,last_page];
for page in index48.iter() {
wr.write_all(
snapshot.memory_ref(MemoryRange::Ram(page * PAGE_SIZE..(page + 1) * PAGE_SIZE))?
)?;
}
sna_ext.write_struct(wr.by_ref())?;
for page in (0..8).filter(|n| !index48.contains(n) && *n != last_page) {
wr.write_all(
snapshot.memory_ref(MemoryRange::Ram(page * PAGE_SIZE..(page + 1) * PAGE_SIZE))?
)?;
}
wr.flush()?;
Ok(result)
}
sourcepub const fn contains(&self, other: Self) -> bool
pub const fn contains(&self, other: Self) -> bool
Returns true
if all of the flags in other
are contained within self
.
Examples found in repository?
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
fn select_hw_model_v2<S: SnapshotCreator>(
model: ComputerModel,
ext: Extensions,
snapshot: &S,
result: &mut SnapshotResult
) -> Result<(u8, bool)>
{
use ComputerModel::*;
if ext.intersects(Extensions::PLUS_D) && snapshot.is_plus_d_rom_paged_in()
|| ext.intersects(Extensions::DISCIPLE) && snapshot.is_disciple_rom_paged_in()
|| ext.intersects(Extensions::TR_DOS) && snapshot.is_tr_dos_rom_paged_in()
|| ext.contains(Extensions::IF1|Extensions::SAM_RAM) && snapshot.is_interface1_rom_paged_in()
{
return Err(io::Error::new(io::ErrorKind::InvalidInput,
"Z80: can't create a version 2 snapshot with the external ROM paged in"))
}
if (ext&!(Extensions::IF1|Extensions::SAM_RAM)) != Extensions::NONE
|| ext.contains(Extensions::IF1|Extensions::SAM_RAM)
{
result.insert(SnapshotResult::EXTENSTION_NSUP);
}
Ok(match model {
Spectrum16 if ext.intersects(Extensions::SAM_RAM) => (2, true),
Spectrum16 if ext.intersects(Extensions::IF1) => (1, true),
Spectrum16 => (0, true),
Spectrum48 if ext.intersects(Extensions::SAM_RAM) => (2, false),
Spectrum48 if ext.intersects(Extensions::IF1) => (1, false),
Spectrum48 => (0, false),
SpectrumNTSC => {
result.insert(SnapshotResult::MODEL_NSUP);
(if ext.intersects(Extensions::SAM_RAM) { 2 }
else { ext.intersects(Extensions::IF1) as u8 }, false)
}
Spectrum128 if ext.intersects(Extensions::IF1) => (4, false),
Spectrum128 => (3, false),
SpectrumPlus2 if ext.intersects(Extensions::IF1) => (4, true),
SpectrumPlus2 => (3, true),
SpectrumPlus2A => (7, true),
SpectrumPlus3 => (7, false),
SpectrumPlus3e => {
result.insert(SnapshotResult::MODEL_NSUP);
(7, false)
}
SpectrumSE => {
return Err(io::Error::new(io::ErrorKind::InvalidInput,
"Z80: can't create a snapshot of SpectrumSE"))
}
TimexTC2048|TimexTC2068|TimexTS2068 if ext.intersects(Extensions::IF1)
&& snapshot.is_interface1_rom_paged_in() => {
return Err(io::Error::new(io::ErrorKind::InvalidInput,
"Z80: can't create a snapshot of Timex + IF1 with IF1 ROM paged in"))
}
TimexTC2048 => (14, false),
TimexTC2068 => (15, false),
TimexTS2068 => (128, false),
})
}
fn select_hw_model_v3<S: SnapshotCreator>(
model: ComputerModel,
ext: Extensions,
snapshot: &S,
result: &mut SnapshotResult
) -> Result<(u8, bool)>
{
use ComputerModel::*;
if ext.intersects(Extensions::TR_DOS) && snapshot.is_tr_dos_rom_paged_in()
|| ext.contains(Extensions::IF1|Extensions::SAM_RAM) && snapshot.is_interface1_rom_paged_in()
{
return Err(io::Error::new(io::ErrorKind::InvalidInput,
"Z80: can't create a version 3 snapshot with the external ROM paged in"))
}
if ext.contains(Extensions::IF1|Extensions::SAM_RAM) {
result.insert(SnapshotResult::EXTENSTION_NSUP);
}
Ok(match model {
Spectrum16 if ext.intersects(Extensions::SAM_RAM) => (2, true),
Spectrum16 if ext.intersects(Extensions::IF1) => (1, true),
Spectrum16 if ext.intersects(Extensions::PLUS_D|Extensions::DISCIPLE) => (3, true),
Spectrum16 => (0, true),
Spectrum48 if ext.intersects(Extensions::SAM_RAM) => (2, false),
Spectrum48 if ext.intersects(Extensions::IF1) => (1, false),
Spectrum48 if ext.intersects(Extensions::PLUS_D|Extensions::DISCIPLE) => (3, false),
Spectrum48 => (0, false),
SpectrumNTSC => {
result.insert(SnapshotResult::MODEL_NSUP);
(if ext.intersects(Extensions::SAM_RAM) { 2 }
else if ext.intersects(Extensions::IF1) { 1 }
else if ext.intersects(Extensions::PLUS_D|Extensions::DISCIPLE) { 3 }
else { 0 }, false)
}
Spectrum128 if ext.intersects(Extensions::IF1) => (5, false),
Spectrum128 if ext.intersects(Extensions::PLUS_D|Extensions::DISCIPLE) => (6, false),
Spectrum128 => (4, false),
SpectrumPlus2 if ext.intersects(Extensions::IF1) => (5, true),
SpectrumPlus2 if ext.intersects(Extensions::PLUS_D|Extensions::DISCIPLE) => (6, true),
SpectrumPlus2 => (4, true),
SpectrumPlus2A => (7, true),
SpectrumPlus3 => (7, false),
SpectrumPlus3e => {
result.insert(SnapshotResult::MODEL_NSUP);
(7, false)
}
SpectrumSE => {
return Err(io::Error::new(io::ErrorKind::InvalidInput,
"Z80: can't create a snapshot of SpectrumSE"))
}
TimexTC2048|TimexTC2068|TimexTS2068 if (ext.intersects(Extensions::IF1) && snapshot.is_interface1_rom_paged_in())
|| (ext.intersects(Extensions::PLUS_D) && snapshot.is_plus_d_rom_paged_in())
|| (ext.intersects(Extensions::DISCIPLE) && snapshot.is_disciple_rom_paged_in())
=> {
return Err(io::Error::new(io::ErrorKind::InvalidInput,
"Z80: can't create a snapshot of Timex with extension ROM paged in"))
}
TimexTC2048 => (14, false),
TimexTC2068 => (15, false),
TimexTS2068 => (128, false),
})
}
sourcepub fn set(&mut self, other: Self, value: bool)
pub fn set(&mut self, other: Self, value: bool)
Inserts or removes the specified flags depending on the passed value.
sourcepub const fn intersection(self, other: Self) -> Self
pub const fn intersection(self, other: Self) -> Self
Returns the intersection between the flags in self
and
other
.
Specifically, the returned set contains only the flags which are
present in both self
and other
.
This is equivalent to using the &
operator (e.g.
ops::BitAnd
), as in flags & other
.
sourcepub const fn union(self, other: Self) -> Self
pub const fn union(self, other: Self) -> Self
Returns the union of between the flags in self
and other
.
Specifically, the returned set contains all flags which are
present in either self
or other
, including any which are
present in both (see Self::symmetric_difference
if that
is undesirable).
This is equivalent to using the |
operator (e.g.
ops::BitOr
), as in flags | other
.
sourcepub const fn difference(self, other: Self) -> Self
pub const fn difference(self, other: Self) -> Self
Returns the difference between the flags in self
and other
.
Specifically, the returned set contains all flags present in
self
, except for the ones present in other
.
It is also conceptually equivalent to the “bit-clear” operation:
flags & !other
(and this syntax is also supported).
This is equivalent to using the -
operator (e.g.
ops::Sub
), as in flags - other
.
sourcepub const fn symmetric_difference(self, other: Self) -> Self
pub const fn symmetric_difference(self, other: Self) -> Self
Returns the symmetric difference between the flags
in self
and other
.
Specifically, the returned set contains the flags present which
are present in self
or other
, but that are not present in
both. Equivalently, it contains the flags present in exactly
one of the sets self
and other
.
This is equivalent to using the ^
operator (e.g.
ops::BitXor
), as in flags ^ other
.
sourcepub const fn complement(self) -> Self
pub const fn complement(self) -> Self
Returns the complement of this set of flags.
Specifically, the returned set contains all the flags which are
not set in self
, but which are allowed for this type.
Alternatively, it can be thought of as the set difference
between Self::all()
and self
(e.g. Self::all() - self
)
This is equivalent to using the !
operator (e.g.
ops::Not
), as in !flags
.
Trait Implementations§
source§impl Binary for Extensions
impl Binary for Extensions
source§impl BitAnd<Extensions> for Extensions
impl BitAnd<Extensions> for Extensions
source§impl BitAndAssign<Extensions> for Extensions
impl BitAndAssign<Extensions> for Extensions
source§fn bitand_assign(&mut self, other: Self)
fn bitand_assign(&mut self, other: Self)
Disables all flags disabled in the set.
source§impl BitOr<Extensions> for Extensions
impl BitOr<Extensions> for Extensions
source§fn bitor(self, other: Extensions) -> Self
fn bitor(self, other: Extensions) -> Self
Returns the union of the two sets of flags.
§type Output = Extensions
type Output = Extensions
|
operator.source§impl BitOrAssign<Extensions> for Extensions
impl BitOrAssign<Extensions> for Extensions
source§fn bitor_assign(&mut self, other: Self)
fn bitor_assign(&mut self, other: Self)
Adds the set of flags.
source§impl BitXor<Extensions> for Extensions
impl BitXor<Extensions> for Extensions
source§impl BitXorAssign<Extensions> for Extensions
impl BitXorAssign<Extensions> for Extensions
source§fn bitxor_assign(&mut self, other: Self)
fn bitxor_assign(&mut self, other: Self)
Toggles the set of flags.
source§impl Clone for Extensions
impl Clone for Extensions
source§fn clone(&self) -> Extensions
fn clone(&self) -> Extensions
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for Extensions
impl Debug for Extensions
source§impl Default for Extensions
impl Default for Extensions
source§fn default() -> Extensions
fn default() -> Extensions
source§impl Display for Extensions
impl Display for Extensions
source§impl Extend<Extensions> for Extensions
impl Extend<Extensions> for Extensions
source§fn extend<T: IntoIterator<Item = Self>>(&mut self, iterator: T)
fn extend<T: IntoIterator<Item = Self>>(&mut self, iterator: T)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl FromIterator<Extensions> for Extensions
impl FromIterator<Extensions> for Extensions
source§fn from_iter<T: IntoIterator<Item = Self>>(iterator: T) -> Self
fn from_iter<T: IntoIterator<Item = Self>>(iterator: T) -> Self
source§impl Hash for Extensions
impl Hash for Extensions
source§impl LowerHex for Extensions
impl LowerHex for Extensions
source§impl Not for Extensions
impl Not for Extensions
source§impl Octal for Extensions
impl Octal for Extensions
source§impl Ord for Extensions
impl Ord for Extensions
source§fn cmp(&self, other: &Extensions) -> Ordering
fn cmp(&self, other: &Extensions) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq<Extensions> for Extensions
impl PartialEq<Extensions> for Extensions
source§fn eq(&self, other: &Extensions) -> bool
fn eq(&self, other: &Extensions) -> bool
source§impl PartialOrd<Extensions> for Extensions
impl PartialOrd<Extensions> for Extensions
source§fn partial_cmp(&self, other: &Extensions) -> Option<Ordering>
fn partial_cmp(&self, other: &Extensions) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl Sub<Extensions> for Extensions
impl Sub<Extensions> for Extensions
source§impl SubAssign<Extensions> for Extensions
impl SubAssign<Extensions> for Extensions
source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
Disables all flags enabled in the set.
source§impl UpperHex for Extensions
impl UpperHex for Extensions
impl Copy for Extensions
impl Eq for Extensions
impl StructuralEq for Extensions
impl StructuralPartialEq for Extensions
Auto Trait Implementations§
impl RefUnwindSafe for Extensions
impl Send for Extensions
impl Sync for Extensions
impl Unpin for Extensions
impl UnwindSafe for Extensions
Blanket Implementations§
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
source§impl<S, T> IntoSample<S> for Twhere
S: FromSample<T>,
impl<S, T> IntoSample<S> for Twhere
S: FromSample<T>,
source§fn into_sample(self) -> S
fn into_sample(self) -> S
S
a sample type from self
.§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds. Read more§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
.tap_borrow()
only in debug builds, and is erased in release
builds. Read more§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
.tap_borrow_mut()
only in debug builds, and is erased in release
builds. Read more§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
.tap_ref()
only in debug builds, and is erased in release
builds. Read more§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
.tap_ref_mut()
only in debug builds, and is erased in release
builds. Read more