Skip to content

Commit 24149f9

Browse files
authored
Merge pull request #2516 from terminal-cs/master
Allow un and re-masking of IRQs.
2 parents 537a034 + d62e896 commit 24149f9

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

source/Cosmos.Core/INTs.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,30 @@ public struct IRQContext {
239239
/// </summary>
240240
private static IRQDelegate[] mIRQ_Handlers = new IRQDelegate[256];
241241

242+
/// Masks or Un-Masks an interupt address.
243+
/// Source: https://wiki.osdev.org/8259_PIC
244+
/// </summary>
245+
/// <param name="aIRQLine">Interupt to unmask.</param>
246+
/// <param name="aDoMask">True = Mask, False = Unmask.</param>
247+
public static void SetIRQMaskState(byte aIRQLine, bool aDoMask)
248+
{
249+
ushort Port = (ushort)(aIRQLine < 8 ? 0x21 : 0xA1);
250+
251+
if (aIRQLine >= 8)
252+
{
253+
aIRQLine -= 8;
254+
}
255+
256+
if (aDoMask)
257+
{
258+
IOPort.Write8(Port, (byte)(IOPort.Read8(Port) | (1 << aIRQLine)));
259+
}
260+
else
261+
{
262+
IOPort.Write8(Port, (byte)(IOPort.Read8(Port) & ~(1 << aIRQLine)));
263+
}
264+
}
265+
242266
// We used to use:
243267
//Interrupts.IRQ01 += HandleKeyboardInterrupt;
244268
// But at one point we had issues with multi cast delegates, so we changed to this single cast option.

0 commit comments

Comments
 (0)