-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpic.lua
62 lines (51 loc) · 1.18 KB
/
pic.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
-- 8259 PIC
-- TODO: Not actually emulated.
PIC_INTERRUPT_PRINTER = 7
PIC_INTERRUPT_FDD = 6
PIC_INTERRUPT_HDD = 5
PIC_INTERRUPT_COM1 = 4
PIC_INTERRUPT_COM2 = 3
PIC_INTERRUPT_VIDEO = 2
PIC_INTERRUPT_KEYBOARD = 1
PIC_INTERRUPT_MOUSE = 1
PIC_INTERRUPT_RTC = 1
PIC_INTERRUPT_TIMER = 0
local int_mask = 0x00
local pic_irr = 0x00
local pic_isr = 0x00
function pic_interrupt_enabled(i)
return true
-- return (int_mask -band- (1 -blshift- i)) == 0
end
--function pic_interrupt_sent(i)
-- pic_isr = pic_isr -bor- (1 -blshift- i)
--end
local next_20 = 0x00
pic_isr = 0xFF
cpu_port_set(0x20, function(cond, val)
if val then next_20 = val else
if next_20 == 0x0A then
return pic_irr
elseif next_20 == 0x0B then
pic_isr = bit.bxor(pic_isr, 0xFF)
return pic_isr
elseif next_20 == 0x20 then
-- TODO
return 0
else
-- unknown
return 0xFF
end
end
end)
local int_22 = 0
local int_23 = 0
cpu_port_set(0x21, function(cond, val)
if not val then return int_mask else int_mask = val end
end)
cpu_port_set(0x22, function(cond, val)
if not val then return int_22 else int_22 = val end
end)
cpu_port_set(0x23, function(cond, val)
if not val then return int_23 else int_23 = val end
end)