- if ( cpu8051_ReadD( _IE_ ) & 0x80 ) {
- for ( i = 1; i >= 0; i-- )
- if ( cpu8051.active_priority < i ) {
- //------------------------- External interrupt 0 ----------------------------
- // if ( ( cpu8051_ReadD( _IE_ ) & 0x01 ) && ( ( cpu8051_ReadD( _IP_ ) & 0x01 ) ? i : !i ) && pin0 )
- //-------------------------- Interrupt timer 0 -------------------------------
- if ( ( cpu8051_ReadD( _IE_ ) & 0x02 ) && ( ( cpu8051_ReadD( _IP_ & 0x02 ) ? i : !i ) && ( cpu8051_ReadD( _TCON_ ) & 0x20 ) ) ){
- cpu8051_WriteD( _TCON_, cpu8051_ReadD( _TCON_ ) & 0xDF );
- SP = cpu8051_ReadD( _SP_ );
- cpu8051_WriteI( ++SP, ( cpu8051.pc & 0xFF ) );
- cpu8051_WriteI( ++SP, ( cpu8051.pc >> 8 ) );
- cpu8051_WriteD( _SP_, SP );
- cpu8051.pc = 0x0B;
- cpu8051.active_priority = i;
- return;
- }
- //-------------------------- External interrupt 1 ----------------------------
- // if ( ( cpu8051_ReadD( _IE_ ) & 0x04 ) && ( ( cpu8051_ReadD( _IP_ ) & 0x04 ) ? i : !i ) && pin1 )
- //-------------------------- Interrupt timer 1 -------------------------------
- if ( ( cpu8051_ReadD( _IE_ ) & 0x08 ) && ( ( cpu8051_ReadD( _IP_ ) & 0x08 ) ? i : !i ) && ( cpu8051_ReadD( _TCON_ ) & 0x80 ) ) {
- cpu8051_WriteD( _TCON_, cpu8051_ReadD( _TCON_ ) & 0x7F );
- SP = cpu8051_ReadD( _SP_ );
- cpu8051_WriteI( ++SP, ( cpu8051.pc & 0xFF ) );
- cpu8051_WriteI( ++SP, ( cpu8051.pc >> 8 ) );
- cpu8051_WriteD( _SP_, SP );
- cpu8051.pc = 0x1B;
- cpu8051.active_priority = i;
- return;
- }
- //-------------------------- Serial Interrupts -------------------------------
- if ( ( cpu8051_ReadD( _IE_ ) & 0x10 ) && ( ( cpu8051_ReadD( _IP_ ) & 0x10 ) ? i : !i ) && ( cpu8051_ReadD( _SCON_ ) & 0x03 ) ) {
- SP = cpu8051_ReadD( _SP_ );
- cpu8051_WriteI( ++SP, ( cpu8051.pc & 0xFF ) );
- cpu8051_WriteI( ++SP, ( cpu8051.pc >> 8 ) );
- cpu8051_WriteD( _SP_, SP );
- cpu8051.pc = 0x23;
- cpu8051.active_priority = i;
- return;
- }
- //-------------------------- Interrupt timer 2 -------------------------------
- if ( ( cpu8051_ReadD( _IE_ ) & 0x20 ) && ( ( cpu8051_ReadD( _IP_ ) & 0x20 ) ? i : !i ) && ( cpu8051_ReadD( _T2CON_ ) & 0x80 ) ) {
- SP = cpu8051_ReadD( _SP_ );
- cpu8051_WriteI( ++SP, ( cpu8051.pc & 0xFF ) );
- cpu8051_WriteI( ++SP, ( cpu8051.pc >> 8 ) );
- cpu8051_WriteD( _SP_, SP );
- cpu8051.pc = 0x2B;
- cpu8051.active_priority = i;
- return;
- }
+ if ((cpu8051_ReadD(_IE_) & 0x80) == 0)
+ return;
+
+ for (i = 1; i >= 0; i--) {
+ if (cpu8051.active_priority < i) {
+ /* Interrupt timer 0 */
+ if ((cpu8051_ReadD(_IE_) & 0x02) &&
+ ((cpu8051_ReadD(_IP_ & 0x02) ? i : !i) &&
+ (cpu8051_ReadD(_TCON_) & 0x20))) {
+ cpu8051_WriteD(_TCON_,
+ cpu8051_ReadD(_TCON_) & 0xDF);
+ cpu8051_process_interrupt(0x0B, i);
+ return;
+ }
+ /* Interrupt timer 1 */
+ if ((cpu8051_ReadD(_IE_) & 0x08) &&
+ ((cpu8051_ReadD(_IP_) & 0x08) ? i : !i) &&
+ (cpu8051_ReadD(_TCON_) & 0x80)) {
+ cpu8051_WriteD(_TCON_,
+ cpu8051_ReadD(_TCON_) & 0x7F);
+ cpu8051_process_interrupt(0x1B, i);
+ return;
+ }
+ /* Serial Interrupts */
+ if ((cpu8051_ReadD(_IE_) & 0x10) &&
+ ((cpu8051_ReadD(_IP_) & 0x10) ? i : !i) &&
+ (cpu8051_ReadD(_SCON_) & 0x03)) {
+ cpu8051_process_interrupt(0x23, i);
+ return;
+ }
+ /* Interrupt timer 2 */
+ if ((cpu8051_ReadD(_IE_) & 0x20) &&
+ ((cpu8051_ReadD(_IP_) & 0x20) ? i : !i) &&
+ (cpu8051_ReadD(_T2CON_) & 0x80)) {
+ cpu8051_process_interrupt(0x2B, i);
+ return;