fn decode_execute(&mut self, instruction: (u8, u8)) {
        // nibble 1. type of instruction.
        let itype: u8 = (instruction.0 & 0xF0) >> 4;
        // nibble 2. Used to look up one of 16 registers V0-VF.
        let x: u8 = instruction.0 & 0x0F;
        // nibble 3. Used to look up one of 16 registers V0-VF.
        let y: u8 = (instruction.1 & 0xF0) >> 4;
        // nibble 4. 4-bit number.
        let n: u8 = instruction.1 & 0x0F;
        // second byte (nibble 3 and 4). 8-bit immediate number.
        let nn: u8 = instruction.1;
        // nibble 2, 3, and 4. 12-bit immediate memory address
        let nnn: u16 = (x as u16) << 8 | (y as u16) << 4 | (n as u16);

        match itype {
            // 00E0 - Clear screen.
            0x0 => self.display.clear(),
            // 1NNN - Jump. Set the program counter to nnn.
            0x1 => match nnn {
                _ => self.program_counter = nnn,
            },
            // 6XNN - Set register VX to nn.
            0x6 => self.variable[x as usize] = nn,
            // 7XNN - Add value nn to VX.
            0x7 => {
                // TODO: Overflow???
                if self.variable[0] == 0xFF {
                    self.variable[x as usize] += nn;
                }
            }
            // ANNN - Set index register I to nnn.
            0xA => self.index = nnn,
            // DXYN - Display/Draw
            // TODO: Call a method in Display to handle this.
            0xD => println!("D"),
            _ => panic!("error: unknown instruction {:x}", itype),
        };
    }
/// Decodes and executes the given instruction.
Decodes and executes the given instruction.
Decodes and executes the given instruction .
fn decode_execute(&mut self, instruction: (u8, u8)) {
        // nibble 1. type of instruction.
        let itype: u8 = (instruction.0 & 0xF0) >> 4;
        // nibble 2. Used to look up one of 16 registers V0-VF.
        let x: u8 = instruction.0 & 0x0F;
        // nibble 3. Used to look up one of 16 registers V0-VF.
        let y: u8 = (instruction.1 & 0xF0) >> 4;
        // nibble 4. 4-bit number.
        let n: u8 = instruction.1 & 0x0F;
        // second byte (nibble 3 and 4). 8-bit immediate number.
        let nn: u8 = instruction.1;
        // nibble 2, 3, and 4. 12-bit immediate memory address
        let nnn: u16 = (x as u16) << 8 | (y as u16) << 4 | (n as u16);
        match itype {
            // 00E0 - Clear screen.
            0x0 => self.display.clear(),
            // 1NNN - Jump. Set the program counter to nnn.
            0x1 => match nnn {
                _ => self.program_counter = nnn,
            },
            // 6XNN - Set register VX to nn.
            0x6 => self.variable[x as usize] = nn,
            // 7XNN - Add value nn to VX.
            0x7 => {
                // TODO: Overflow???
                if self.variable[0] == 0xFF {
                    self.variable[x as usize] += nn;
                }
            }
            // ANNN - Set index register I to nnn.
            0xA => self.index = nnn,
            // DXYN - Display/Draw
            // TODO: Call a method in Display to handle this.
            0xD => println!("D"),
            _ => panic!("error: unknown instruction {:x}", itype),
        };
    }
fn decode_execute ( & mut self , instruction : ( u8 , u8 ) ) { // nibble 1. type of instruction. let itype : u8 = ( instruction . 0 & 0xF0 ) >> 4 ; // nibble 2. Used to look up one of 16 registers V0-VF. let x : u8 = instruction . 0 & 0x0F ; // nibble 3. Used to look up one of 16 registers V0-VF. let y : u8 = ( instruction . 1 & 0xF0 ) >> 4 ; // nibble 4. 4-bit number. let n : u8 = instruction . 1 & 0x0F ; // second byte (nibble 3 and 4). 8-bit immediate number. let nn : u8 = instruction . 1 ; // nibble 2, 3, and 4. 12-bit immediate memory address let nnn : u16 = ( x as u16 ) << 8 | ( y as u16 ) << 4 | ( n as u16 ) ; match itype { // 00E0 - Clear screen. 0x0 => self . display . clear ( ) , // 1NNN - Jump. Set the program counter to nnn. 0x1 => match nnn { _ => self . program_counter = nnn , } , // 6XNN - Set register VX to nn. 0x6 => self . variable [ x as usize ] = nn , // 7XNN - Add value nn to VX. 0x7 => { // TODO: Overflow??? if self . variable [ 0 ] == 0xFF { self . variable [ x as usize ] += nn ; } } // ANNN - Set index register I to nnn. 0xA => self . index = nnn , // DXYN - Display/Draw // TODO: Call a method in Display to handle this. 0xD => println ! ( " " ) , _ => panic ! ( " " itype ) , } ; }
Decodes and executes the given instruction.
Decodes and executes the given instruction .
&mut self
instruction
(u8, u8)
&mut self
instruction
(u8, u8)