Skip to content

Commit

Permalink
Changed the NMI and IRQ handlers to bool values instead of methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronmell committed Nov 3, 2017
1 parent 2d8cf92 commit bd86c07
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions Processor/Processor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ public class Processor
private static readonly ILogger _logger = LogManager.GetLogger("Processor");
private int _programCounter;
private int _stackPointer;
private int _cycleCount;
private bool _nmiTriggered;
private bool _irqTriggered;
#endregion
private int _cycleCount;
#endregion

//All of the properties here are public and read only to facilitate ease of debugging and testing.
#region Properties
//All of the properties here are public and read only to facilitate ease of debugging and testing.
#region Properties
/// <summary>
/// The memory
/// </summary>
Expand Down Expand Up @@ -116,13 +114,21 @@ private set
/// In shift operations the sign holds the carry.
/// </summary>
public bool NegativeFlag { get; private set; }
#endregion

#region Public Methods
/// <summary>
/// Default Constructor, Instantiates a new instance of the processor.
/// </summary>
public Processor()
/// <summary>
/// Set to true when an NMI has occurred and is being processed by the CPU
/// </summary>
public bool NMIOcurring { get; private set; }

/// Set to true when an IRQ has occurred and is being processed by the CPU
public bool IRQOccurring { get; private set; }
#endregion

#region Public Methods
/// <summary>
/// Default Constructor, Instantiates a new instance of the processor.
/// </summary>
public Processor()
{
Memory = new byte[0x10000];
StackPointer = 0x100;
Expand Down Expand Up @@ -163,15 +169,15 @@ public void NextStep()
//Grabbing this at the end, ensure thats when we read the CurrentOp Code field, that we have the correct OpCode for the instruction we are going to execute Next.
CurrentOpCode = ReadMemoryValue(ProgramCounter);

if (_nmiTriggered)
if (NMIOcurring)
{
NmiOccurred();
_nmiTriggered = false;
ProcessNMI();
NMIOcurring = false;
}
else if (_irqTriggered)
else if (IRQOccurring)
{
IrqTriggered();
_irqTriggered = false;
ProcessIRQ();
IRQOccurring = false;
}
else
{
Expand Down Expand Up @@ -225,15 +231,15 @@ public void LoadProgram(int offset, byte[] program)
/// </summary>
public void InterruptRequest()
{
_irqTriggered = true;
IRQOccurring = true;
}

/// <summary>
/// The InterruptRequest or IRQ
/// </summary>
public void NonMaskableInterrupt()
{
_nmiTriggered = true;
NMIOcurring = true;
}

/// <summary>
Expand Down Expand Up @@ -2493,7 +2499,7 @@ private void ReturnFromInterruptOperation()
/// <summary>
/// This is ran anytime an NMI occurrs
/// </summary>
private void NmiOccurred()
private void ProcessNMI()
{
ProgramCounter--;
BreakOperation(false, 0xFFFA);
Expand All @@ -2505,7 +2511,7 @@ private void NmiOccurred()
/// <summary>
/// This is ran anytime an IRQ occurrs
/// </summary>
private void IrqTriggered()
private void ProcessIRQ()
{
if (DisableInterruptFlag)
return;
Expand Down

0 comments on commit bd86c07

Please sign in to comment.