Class: PSX::Interrupts
- Inherits:
-
Object
- Object
- PSX::Interrupts
- Defined in:
- lib/psx/interrupts.rb
Overview
Interrupt Controller Manages hardware interrupts via I_STAT and I_MASK registers
Constant Summary collapse
- IRQ_VBLANK =
Interrupt bits
0x001- IRQ_GPU =
Vertical blank
0x002- IRQ_CDROM =
GPU ready
0x004- IRQ_DMA =
CD-ROM
0x008- IRQ_TIMER0 =
DMA transfer complete
0x010- IRQ_TIMER1 =
Timer 0
0x020- IRQ_TIMER2 =
Timer 1
0x040- IRQ_CONTROLLER =
Timer 2
0x080- IRQ_SIO =
Controller/memory card
0x100- IRQ_SPU =
Serial I/O
0x200- IRQ_LIGHTPEN =
Sound
0x400
Instance Attribute Summary collapse
-
#mask ⇒ Object
readonly
Lightpen (directly active).
-
#stat ⇒ Object
readonly
Lightpen (directly active).
Instance Method Summary collapse
-
#dma! ⇒ Object
Trigger DMA interrupt.
-
#gpu! ⇒ Object
Trigger GPU interrupt.
-
#initialize ⇒ Interrupts
constructor
A new instance of Interrupts.
-
#pending? ⇒ Boolean
Check if any unmasked interrupt is pending.
- #read_mask ⇒ Object
- #read_stat ⇒ Object
-
#request(irq) ⇒ Object
Request an interrupt.
-
#timer!(n) ⇒ Object
Trigger timer interrupt.
-
#vblank! ⇒ Object
Trigger VBlank interrupt.
- #write_mask(value) ⇒ Object
- #write_stat(value) ⇒ Object
Constructor Details
#initialize ⇒ Interrupts
Returns a new instance of Interrupts.
22 23 24 25 |
# File 'lib/psx/interrupts.rb', line 22 def initialize @stat = 0 # I_STAT - interrupt status (active interrupts) @mask = 0 # I_MASK - interrupt mask (enabled interrupts) end |
Instance Attribute Details
#mask ⇒ Object (readonly)
Lightpen (directly active)
20 21 22 |
# File 'lib/psx/interrupts.rb', line 20 def mask @mask end |
#stat ⇒ Object (readonly)
Lightpen (directly active)
20 21 22 |
# File 'lib/psx/interrupts.rb', line 20 def stat @stat end |
Instance Method Details
#dma! ⇒ Object
Trigger DMA interrupt
66 67 68 |
# File 'lib/psx/interrupts.rb', line 66 def dma! request(IRQ_DMA) end |
#gpu! ⇒ Object
Trigger GPU interrupt
61 62 63 |
# File 'lib/psx/interrupts.rb', line 61 def gpu! request(IRQ_GPU) end |
#pending? ⇒ Boolean
Check if any unmasked interrupt is pending
51 52 53 |
# File 'lib/psx/interrupts.rb', line 51 def pending? (@stat & @mask) != 0 end |
#read_mask ⇒ Object
31 32 33 |
# File 'lib/psx/interrupts.rb', line 31 def read_mask @mask end |
#read_stat ⇒ Object
27 28 29 |
# File 'lib/psx/interrupts.rb', line 27 def read_stat @stat end |
#request(irq) ⇒ Object
Request an interrupt
46 47 48 |
# File 'lib/psx/interrupts.rb', line 46 def request(irq) @stat |= irq end |
#timer!(n) ⇒ Object
Trigger timer interrupt
71 72 73 74 75 76 77 |
# File 'lib/psx/interrupts.rb', line 71 def timer!(n) case n when 0 then request(IRQ_TIMER0) when 1 then request(IRQ_TIMER1) when 2 then request(IRQ_TIMER2) end end |
#vblank! ⇒ Object
Trigger VBlank interrupt
56 57 58 |
# File 'lib/psx/interrupts.rb', line 56 def vblank! request(IRQ_VBLANK) end |
#write_mask(value) ⇒ Object
41 42 43 |
# File 'lib/psx/interrupts.rb', line 41 def write_mask(value) @mask = value & 0x7FF end |
#write_stat(value) ⇒ Object
35 36 37 38 39 |
# File 'lib/psx/interrupts.rb', line 35 def write_stat(value) # Writing to I_STAT acknowledges (clears) interrupts. # On PSX: write 0 to a bit clears it (ack), write 1 leaves it unchanged. @stat &= value end |