mirror of
https://github.com/romychs/Ocean-240.2-Emulator.git
synced 2026-11-02 12:47:33 +03:00
Refactoring PC components
This commit is contained in:
1 parent
231ae7a840
commit
42fb80813c
11 files changed
+469
-308
No files matched your search
@@ -0,0 +1,54 @@
|
||||
package pic
|
||||
|
||||
/*
|
||||
Programmable Interrupt Controller
|
||||
i8058, MSM82C59, КР580ВН59
|
||||
|
||||
By Romych, 2025.03.05
|
||||
*/
|
||||
|
||||
import log "github.com/sirupsen/logrus"
|
||||
|
||||
type I8259 struct {
|
||||
irr byte
|
||||
}
|
||||
|
||||
type I8259Interface interface {
|
||||
SetIRQ(irq byte)
|
||||
IRR() byte
|
||||
}
|
||||
|
||||
func (c *I8259) IRR() byte {
|
||||
irr := c.irr
|
||||
// Reset the highest IR bit
|
||||
if irr&0x80 != 0 {
|
||||
c.irr &= 0x7F
|
||||
} else if irr&0x40 != 0 {
|
||||
c.irr &= 0x3F
|
||||
} else if irr&0x20 != 0 {
|
||||
c.irr &= 0x1F
|
||||
} else if irr&0x08 != 0 {
|
||||
c.irr &= 0x07
|
||||
} else if irr&0x04 != 0 {
|
||||
c.irr &= 0x03
|
||||
} else if irr&0x02 != 0 {
|
||||
c.irr &= 0x1
|
||||
} else {
|
||||
c.irr = 0
|
||||
}
|
||||
return irr
|
||||
}
|
||||
|
||||
func (c *I8259) SetIRQ(irq byte) {
|
||||
if irq < 8 {
|
||||
c.irr |= 1 << irq
|
||||
} else {
|
||||
log.Warnf("SetIRQ out of range [0..7]: %d", irq)
|
||||
}
|
||||
}
|
||||
|
||||
func NewI8259() *I8259 {
|
||||
return &I8259{
|
||||
irr: 0,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user