pub fn new(rom: &[u8]) -> Self {
        if rom.len() > RAM_SIZE - PROGRAM_START {
            panic!("ROM is too large to fit in RAM");
        }

        let mut mem = [0; RAM_SIZE];
        for (i, &b) in CHIP8_FONT.iter().enumerate() { mem[i] = b; }
        for (i, &b) in rom.iter().enumerate() { mem[PROGRAM_START + i] = b; }

        Chip8 {
            state: Rc::new(RefCell::new(ChipState {
                mem: mem,
                regs: [0; 16],
                pc: PROGRAM_START as u16,
                i: 0,
                stack: [0; 16],
                sp: 0,
                delay_timer: 0,
                sound_timer: 0,
                fb: [false; 64 * 32],
                inv_start: 0,
                inv_len: 0,
                win: Window::new("KOOL-8", 64, 32, WindowOptions {
                    borderless: false,
                    title: true,
                    resize: false,
                    scale: Scale::FitScreen,
                }).unwrap(),
                _priv: (),
            })),
            cache: CodeCache::new(),
            last_tick: Instant::now(),
            ops: 0,
        }
    }
/// Creates a new CHIP-8 emulator loading the given ROM. The ROM must not be larger than 3584
/// Bytes.
Creates a new CHIP-8 emulator loading the given ROM. The ROM must not be larger than 3584
Bytes.
Creates a new CHIP - 8 emulator loading the given ROM . The ROM must not be larger than 3584 Bytes .
pub fn new(rom: &[u8]) -> Self {
        if rom.len() > RAM_SIZE - PROGRAM_START {
            panic!("ROM is too large to fit in RAM");
        }
        let mut mem = [0; RAM_SIZE];
        for (i, &b) in CHIP8_FONT.iter().enumerate() { mem[i] = b; }
        for (i, &b) in rom.iter().enumerate() { mem[PROGRAM_START + i] = b; }
        Chip8 {
            state: Rc::new(RefCell::new(ChipState {
                mem: mem,
                regs: [0; 16],
                pc: PROGRAM_START as u16,
                i: 0,
                stack: [0; 16],
                sp: 0,
                delay_timer: 0,
                sound_timer: 0,
                fb: [false; 64 * 32],
                inv_start: 0,
                inv_len: 0,
                win: Window::new("KOOL-8", 64, 32, WindowOptions {
                    borderless: false,
                    title: true,
                    resize: false,
                    scale: Scale::FitScreen,
                }).unwrap(),
                _priv: (),
            })),
            cache: CodeCache::new(),
            last_tick: Instant::now(),
            ops: 0,
        }
    }
pub fn new ( rom : & [ u8 ] ) -> Self { if rom . len ( ) > RAM_SIZE - PROGRAM_START { panic ! ( " " ) ; } let mut mem = [ 0 ; RAM_SIZE ] ; for ( i , & b ) in CHIP8_FONT . iter ( ) . enumerate ( ) { mem [ i ] = b ; } for ( i , & b ) in rom . iter ( ) . enumerate ( ) { mem [ PROGRAM_START + i ] = b ; } Chip8 { state : Rc :: new ( RefCell :: new ( ChipState { mem : mem , regs : [ 0 ; 16 ] , pc : PROGRAM_START as u16 , i : 0 , stack : [ 0 ; 16 ] , sp : 0 , delay_timer : 0 , sound_timer : 0 , fb : [ false ; 64 * 32 ] , inv_start : 0 , inv_len : 0 , win : Window :: new ( " " , 64 , 32 , WindowOptions { borderless : false , title : true , resize : false , scale : Scale :: FitScreen , } ) . unwrap ( ) , _priv : ( ) , } ) ) , cache : CodeCache :: new ( ) , last_tick : Instant :: now ( ) , ops : 0 , } }
Creates a new CHIP-8 emulator loading the given ROM.
Creates a new CHIP - 8 emulator loading the given ROM .
rom
&[u8]
rom
&[u8]