scheduler

package
v0.0.0-...-77df42f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	// contains filtered or unexported fields
}

type EventType

type EventType uint8
const (
	APUFrameSequencer EventType = iota
	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

	JoypadA
	JoypadB
	JoypadSelect
	JoypadStart
	JoypadRight
	JoypadLeft
	JoypadUp
	JoypadDown

	JoypadARelease
	JoypadBRelease
	JoypadSelectRelease
	JoypadStartRelease
	JoypadRightRelease
	JoypadLeftRelease
	JoypadUpRelease
	JoypadDownRelease
)

func (EventType) String

func (e EventType) String() string

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

func (s *Scheduler) ChangeSpeed(speed bool)

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) Cycle

func (s *Scheduler) Cycle() uint64

func (*Scheduler) DescheduleEvent

func (s *Scheduler) DescheduleEvent(eventType EventType)

func (*Scheduler) DivAPUBit

func (s *Scheduler) DivAPUBit() uint16

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) DoEvent

func (s *Scheduler) DoEvent() uint64

TODO pass in event type to avoid BCE in the loop TODO

func (*Scheduler) DoubleSpeed

func (s *Scheduler) DoubleSpeed() bool

func (*Scheduler) OverrideDiv

func (s *Scheduler) OverrideDiv(div uint16)

func (*Scheduler) RegisterEvent

func (s *Scheduler) RegisterEvent(eventType EventType, fn func())

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

func (s *Scheduler) ScheduleEvent(eventType EventType, cycle uint64)

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) String

func (s *Scheduler) String() string

func (*Scheduler) SysClock

func (s *Scheduler) SysClock() uint16

SysClock returns the internal divider clock of the Game Boy.

func (*Scheduler) SysClockReset

func (s *Scheduler) SysClockReset()

SysClockReset resets the internal divider clock. TODO notify timer of reset.

func (*Scheduler) Tick

func (s *Scheduler) Tick(c uint64)

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.

func (*Scheduler) Until

func (s *Scheduler) Until(increment EventType) uint64

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL