Documentation ¶
Index ¶
- type Event
- type EventType
- type Scheduler
- func (s *Scheduler) ChangeSpeed(speed bool)
- func (s *Scheduler) Cycle() uint64
- func (s *Scheduler) DescheduleEvent(eventType EventType)
- func (s *Scheduler) DivAPUBit() uint16
- func (s *Scheduler) DoEvent() uint64
- func (s *Scheduler) DoubleSpeed() bool
- func (s *Scheduler) OverrideDiv(div uint16)
- func (s *Scheduler) RegisterEvent(eventType EventType, fn func())
- func (s *Scheduler) ScheduleEvent(eventType EventType, cycle uint64)
- func (s *Scheduler) Skip()
- func (s *Scheduler) String() string
- func (s *Scheduler) SysClock() uint16
- func (s *Scheduler) SysClockReset()
- func (s *Scheduler) Tick(c uint64)
- func (s *Scheduler) Until(increment EventType) uint64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EventType ¶
type EventType uint8
const ( APUFrameSequencer EventType = iota APUFrameSequencer2 APUChannel1 APUChannel2 APUChannel3 APUSample EIPending EIHaltDelay PPUStartHBlank PPUHBlank PPUHBlankInterrupt PPUStartOAMSearch PPUEndFrame PPUContinueOAMSearch PPUPrepareEndOAMSearch PPUEndOAMSearch PPULine153Continue PPULine153End PPUStartVBlank PPUContinueVBlank PPUVRAMTransfer PPUStartGlitchedLine0 PPUMiddleGlitchedLine0 PPUContinueGlitchedLine0 PPUEndGlitchedLine0 PPUOAMInterrupt DMAStartTransfer DMAEndTransfer DMATransfer TimerTIMAReload TimerTIMAFinishReload TimerTIMAIncrement SerialBitTransfer SerialBitInterrupt CameraShoot )
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler is a simple event scheduler that can be used to schedule events to be executed at a specific cycle.
The scheduler is a linked list of events, sorted by the cycle at which they should be executed. When an event is scheduled, it is inserted into the list in the correct position, and when the scheduler is ticked, the next event is executed and removed from the list, if the event is scheduled for the current cycle.
func NewScheduler ¶
func NewScheduler() *Scheduler
func (*Scheduler) ChangeSpeed ¶
ChangeSpeed informs the scheduler that the speed of the CPU has either gone from normal speed to double speed, or from double speed to normal speed. This is useful for the scheduler to know when to schedule events for the CPU, as events are scheduled for the CPU at a different rate when the CPU is running at double speed.
func (*Scheduler) DescheduleEvent ¶
func (*Scheduler) DivAPUBit ¶
DivAPUBit returns the current bitmask for scheduling the APU frame sequencer. In CGB double speed bit 5 of types.DIV is used, otherwise it is bit 4 (note bit 12/13 of the SysClock)
func (*Scheduler) DoubleSpeed ¶
func (*Scheduler) OverrideDiv ¶
func (*Scheduler) RegisterEvent ¶
RegisterEvent registers a function of the EventType to be called when the event is scheduled for execution. This is to avoid the cost of having to allocate a function for each event, which would frequently invoke the garbage collector, despite the functions always performing the same task.
func (*Scheduler) ScheduleEvent ¶
ScheduleEvent schedules an event to be executed at the given cycle.
func (*Scheduler) Skip ¶
func (s *Scheduler) Skip()
Skip invokes the scheduler to execute the next event, by setting the current cycle to the cycle at which the next event is scheduled to be executed. This is useful when the CPU is halted, and the scheduler should be invoked to execute until the CPU is un-halted by an interrupt.
func (*Scheduler) SysClockReset ¶
func (s *Scheduler) SysClockReset()
SysClockReset resets the internal divider clock. TODO notify timer of reset.
func (*Scheduler) Tick ¶
Tick advances the scheduler by the given number of cycles. This will execute all scheduled events up to the current cycle. If an event is scheduled for the current cycle, it will be executed and removed from the list. If an event is scheduled for a cycle in the future, it will be executed when the scheduler is ticked with the cycle at which it should be executed.