Advertisement
Guest User

Untitled

a guest
Aug 16th, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module common.rp6502.interrupts;
  2.  
  3.  
  4. import common.rp6502.pins;
  5.  
  6.  
  7. enum
  8. {
  9.     VECTOR_NMI = 0xfffa,
  10.     VECTOR_RES = 0xfffc,
  11.     VECTOR_IRQ = 0xfffe
  12. }
  13.  
  14. class Interrupts
  15. {
  16.     private Pins pins;
  17.     private bool irq;
  18.     private bool nmi, nmi_latch;
  19.     private bool res;
  20.  
  21.     this(Pins pins)
  22.     {
  23.         this.pins = pins;
  24.     }
  25.  
  26.     public void update()
  27.     {
  28.         irq = pins.irq;
  29.         res = pins.res;
  30.  
  31.         if (pins.nmi & !nmi_latch)
  32.         {
  33.             nmi = 1;
  34.         }
  35.  
  36.         nmi_latch = pins.nmi;
  37.     }
  38.  
  39.     public bool available(bool i)
  40.     {
  41.         return nmi | (irq & !i) | res;
  42.     }
  43.  
  44.     public ushort vector()
  45.     {
  46.         if (res) { res = 0; return VECTOR_RES; }
  47.         if (nmi) { nmi = 0; return VECTOR_NMI; }
  48.         if (irq) { irq = 0; return VECTOR_IRQ; }
  49.  
  50.         return 0;
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement