pub fn try_interrupt(&mut self, interrupt: InterruptType) -> bool {
        if !self.interrupts_enabled && !self.halted {
            return false;
        }

        // TODO: 20 cycle event
        self.halted = false; // TODO: extra 4 cycles if true
        self.stopped = false;

        if !self.interrupts_enabled {
            return true;
        }

        self.mem.ioregs.iflag &= !(1 << interrupt as u8);

        self.interrupts_enabled = false;

        //println!("Throwing interrupt: {:?}", interrupt);

        // Push PC to stack
        self.regs.sp -= 2;
        self.mem.write_short(self.regs.sp, self.regs.pc);

        // Jump to interrupt service
        self.regs.pc = match interrupt {
            InterruptType::VBLANK => 0x0040,
            InterruptType::LCDC => 0x0048,
            InterruptType::TIMER => 0x0050,
            InterruptType::SERIAL => 0x0058,
            InterruptType::KEYPAD => 0x0060,
        };

        true
    }
/// Callback from memory to try to throw a memory interrupt.
Callback from memory to try to throw a memory interrupt.
Callback from memory to try to throw a memory interrupt .
pub fn try_interrupt(&mut self, interrupt: InterruptType) -> bool {
        if !self.interrupts_enabled && !self.halted {
            return false;
        }
        // TODO: 20 cycle event
        self.halted = false; // TODO: extra 4 cycles if true
        self.stopped = false;
        if !self.interrupts_enabled {
            return true;
        }
        self.mem.ioregs.iflag &= !(1 << interrupt as u8);
        self.interrupts_enabled = false;
        //println!("Throwing interrupt: {:?}", interrupt);
        // Push PC to stack
        self.regs.sp -= 2;
        self.mem.write_short(self.regs.sp, self.regs.pc);
        // Jump to interrupt service
        self.regs.pc = match interrupt {
            InterruptType::VBLANK => 0x0040,
            InterruptType::LCDC => 0x0048,
            InterruptType::TIMER => 0x0050,
            InterruptType::SERIAL => 0x0058,
            InterruptType::KEYPAD => 0x0060,
        };
        true
    }
pub fn try_interrupt ( & mut self , interrupt : InterruptType ) -> bool { if ! self . interrupts_enabled && ! self . halted { return false ; } // TODO: 20 cycle event self . halted = false ; // TODO: extra 4 cycles if true self . stopped = false ; if ! self . interrupts_enabled { return true ; } self . mem . ioregs . iflag &= ! ( 1 << interrupt as u8 ) ; self . interrupts_enabled = false ; //println!("Throwing interrupt: {:?}", interrupt); // Push PC to stack self . regs . sp -= 2 ; self . mem . write_short ( self . regs . sp , self . regs . pc ) ; // Jump to interrupt service self . regs . pc = match interrupt { InterruptType :: VBLANK => 0x0040 , InterruptType :: LCDC => 0x0048 , InterruptType :: TIMER => 0x0050 , InterruptType :: SERIAL => 0x0058 , InterruptType :: KEYPAD => 0x0060 , } ; true }
Callback from memory to try to throw a memory interrupt.
Callback from memory to try to throw a memory interrupt .
&mut self
interrupt
InterruptType
&mut self
interrupt
InterruptType