<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Thu, 18 Aug 1994 09:33:49 EST
From   : Stephen Quan <quan@...>
Subject: NMI and MI.

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

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".  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??

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?

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.
-- 
Stephen Quan (quan@...                 ), SysAdmin, Analyst/Programmer.
Centre for Spatial Information Studies, University of Tasmania, Hobart.
GPO BOX 252C, Australia, 7001.  Local Tel: (002) 202898 Fax: (002) 240282
International Callers use +6102 instead of (002).
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>