public void Tick() { // If the trap flag is set, trigger interrupt 1 if (CondReg.TrapFlag) { var interrupt = new INT(0, 1, this, Bus); interrupt.Execute(); } // If interrupts are enabled and there is an interrupt waiting, // trigger the next interrupt. Only one interrupt is processed per // tick if multiple are waiting. if (CondReg.InterruptEnable) // && i8259 has an interrupt waiting { // Interrupt( i8259 next interrupt ) ; } // Reset the prefix and base pointer flags. Bus.SegmentOverride = SegmentOverrideState.NoOverride; Bus.UsingBasePointer = false; RepeatMode = RepeatModeEnum.NoRepeat; // Process prefix instructions bool more = false; do { // Retrieve the next instruction and count stats InstructionCount++; CurrentOpCode = Bus.NextImmediate(); Stats.AddOpCode(CurrentOpCode); more = true; switch (CurrentOpCode) { case 0x26: { Bus.SegmentOverride = SegmentOverrideState.UseES; break; } case 0x2e: { Bus.SegmentOverride = SegmentOverrideState.UseCS; break; } case 0x36: { Bus.SegmentOverride = SegmentOverrideState.UseSS; break; } case 0x3e: { Bus.SegmentOverride = SegmentOverrideState.UseDS; break; } case 0xf2: { RepeatMode = RepeatModeEnum.REPNZ; break; } case 0xf3: { RepeatMode = RepeatModeEnum.REP; break; } default: { more = false; break; } } } while (more); // Process the next instruction. if (!instructions.TryGetValue(CurrentOpCode, out var instruction)) { instruction = new InvalidInstruction(CurrentOpCode, this, Bus); } instruction.Execute(); // NOTE: a current minor flaw here is if there is a repeat instruction because the entire loop // will get executed immediately without allowing for any interrupts. Watch for timing issues // with PIT if there is a long loop. // Tick the PIT // i8253.Tick() }
public void Interrupt(int interrupt_num) { var inst = new INT(0, interrupt_num, this, Bus); inst.Execute(); }