Class: Zemu::Config::Timer
- Inherits:
-
BusDevice
- Object
- Zemu::ConfigObject
- BusDevice
- Zemu::Config::Timer
- Defined in:
- lib/zemu/config.rb
Overview
Non-Maskable Interrupt Timer
Represents a timer device, the period of which can be controlled by the CPU through an IO port. The timer generates an NMI once this period has expired. The timer can be reset via a control port.
Constant Summary collapse
- RUNNING =
Timer is running - count decrements once per clock cycle.
0x01- STOPPED =
Timer is stopped - count does not change on clock cycle.
0x00
Instance Method Summary collapse
-
#clock(cycles) ⇒ Object
Clock handler.
-
#initialize ⇒ Timer
constructor
A new instance of Timer.
-
#io_write(port, value) ⇒ Object
IO bus write handler.
-
#params ⇒ Object
Valid parameters for a Timer, along with those defined in [Zemu::Config::IOPort].
Methods inherited from BusDevice
#functions, #interrupt, #interrupt?, #io_read, #mem_read, #mem_write, #memory, #nmi, #nmi?, #when_setup
Methods inherited from Zemu::ConfigObject
Constructor Details
#initialize ⇒ Timer
Returns a new instance of Timer.
681 682 683 684 685 686 |
# File 'lib/zemu/config.rb', line 681 def initialize super @count = 0 @running = false end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Zemu::ConfigObject
Instance Method Details
#clock(cycles) ⇒ Object
Clock handler.
Handles a clock cycle for this device. Sets NMI active if the count reaches 0.
706 707 708 709 710 711 712 713 714 |
# File 'lib/zemu/config.rb', line 706 def clock(cycles) if @running == RUNNING if @count > 0 @count -= cycles else nmi(true) end end end |
#io_write(port, value) ⇒ Object
IO bus write handler.
Handles write access via the IO bus to this device.
694 695 696 697 698 699 700 |
# File 'lib/zemu/config.rb', line 694 def io_write(port, value) if port == count_port @count = value elsif port == control_port @running = if value == 0 then STOPPED else RUNNING end end end |
#params ⇒ Object
Valid parameters for a Timer, along with those defined in [Zemu::Config::IOPort].
718 719 720 |
# File 'lib/zemu/config.rb', line 718 def params super + %w(count_port control_port) end |