<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Thu, 18 Aug 1994 09:14:02 +0100
From   : jfid@... (James Fidell)
Subject: Re: NMI and MI.

Stephen Quan wrote:

> Ok, seems like I am missing NMI and MI from my 6502 emulator, does
> anyone know something about interrupts on the 6502????

I think I understand what happens reasonably well...

> The AUG is not very definitive on what happens here.  In one case, it
> says "on a NMI it makes a call to 0xD00 with interrupts disabled", in
> another cases, it says "NMI makes a jump to 0xD00".

This isn't very accurate in either case.  An NMI pushes the PC on the
stack, then the SR with the BRK bit cleared, sets the I flag in the SR
and finally sets the PC to (&FFFA).

In the case of an IRQ it does the same but sets the PC to (&FFFE).

>                                                      Well, in any case,
> what I have done is define two variables, called NMI and MI which
> are normally 0 and changes to 1 when an interrupt is raised, and to
> detect an interrupt, in my 6502 emulator I have :
> 
>    if (NMI == 1)
>    {
>      NMI = 0;
>      pushw(PC);
>      PC = 0xD00;
>      P |= P_I;
>    }
>    if (MI == 1 && (P&P_I) == 0)
>    {
>      MI = 0;
>      pushw(PC);
>      PC = 0xD00;
>      P |= P_I;
>    }
> 
> Well, I know the above is wrong, because my emulator now has hiccups from
> this.  Everytime and interrupt occurs something gets messed up, feels like
> an instruction is missed, not sure.  The manual doesn't say that anything
> should be happening to P, but shouldn't I be throwing P onto the stack??

You need to set it up to do as I've indicated above.  Also, it's quite
legal for several peices of hardware to be generating an IRQ or NMI at
the same time, so you can't just set a flag to 0 or 1.

> Also, when I do a JSR, I throw PC-1 on a stack (since RTS pulls PC and
> adds 1 back to it).  With the interupt I think I just throw PC on the
> stack as the RTI will pull PC *without* adding 1 to it, is this the
> correct behaviour?

Yes.

> I inserted a counter in my code that sets MI to 1 everytime it counts
> to 0x8000 (not very periodic), but I was hoping this would be enough to
> see the 6502 trying to go for the hardware.

If you modify your IRQ handling code then you should see this happening.

I'd suggest that you completely ignore the NMI issues until you want to
play with the DFS.  As far as I know, nothing else uses it.

James.

-- 
 "Yield to temptation --             |
  it may not pass your way again"    |     jfid@...        
                                     |
        - Lazarus Long               |              James Fidell
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>