fn calc_ppu_nametable_addr_with_mirroring(mut addr: u16, hor_mirroring: bool) -> u16 {
    debug_assert!(matches!(addr, 0x2000..=0x3eff));

    addr &= !0x3000;

    // apply horizontal nametable mirroring
    if hor_mirroring {
        let high_bits = addr & 0b110000000000;
        addr -= (high_bits.count_ones() as u16) << 10;
    }

    addr & 0x7ff
}
// assumes 'addr' points to a nametable in ppu memory
// (0x2000-0x3eff) and applies proper mirroring to it.
// returns a value in the range 0-0x7ff.
// NOTE: this assumes either horizontal or vertical
// mirroring, and doesn't work when both are disabled
assumes 'addr' points to a nametable in ppu memory
(0x2000-0x3eff) and applies proper mirroring to it.
returns a value in the range 0-0x7ff.
NOTE: this assumes either horizontal or vertical
mirroring, and doesn't work when both are disabled
assumes ' addr ' points to a nametable in ppu memory ( 0x2000 - 0x3eff ) and applies proper mirroring to it . returns a value in the range 0 - 0x7ff . NOTE : this assumes either horizontal or vertical mirroring and doesn ' t work when both are disabled
fn calc_ppu_nametable_addr_with_mirroring(mut addr: u16, hor_mirroring: bool) -> u16 {
    debug_assert!(matches!(addr, 0x2000..=0x3eff));
    addr &= !0x3000;
    // apply horizontal nametable mirroring
    if hor_mirroring {
        let high_bits = addr & 0b110000000000;
        addr -= (high_bits.count_ones() as u16) << 10;
    }
    addr & 0x7ff
}
fn calc_ppu_nametable_addr_with_mirroring ( mut addr : u16 , hor_mirroring : bool ) -> u16 { debug_assert ! ( matches ( addr 0x2000 0x3eff ) ) ; addr &= ! 0x3000 ; // apply horizontal nametable mirroring if hor_mirroring { let high_bits = addr & 0b110000000000 ; addr -= ( high_bits . count_ones ( ) as u16 ) << 10 ; } addr & 0x7ff }
assumes 'addr' points to a nametable in ppu memory
(0x2000-0x3eff) and applies proper mirroring to it.
assumes ' addr ' points to a nametable in ppu memory ( 0x2000 - 0x3eff ) and applies proper mirroring to it .
addr
u16
hor_mirroring
bool
addr
u16
hor_mirroring
bool