<commit_before>package dcpu

import "time"

// Clock implements Generic Clock (compatible).
type Clock struct {
	DCPU     *DCPU
	Interval uint16
	Message  uint16
	Ticks    uint16

	lastTick time.Time
}

const (
	duration  = time.Second / frequency
	frequency = 60
	id        = 0x12d0b402
	version   = 0x0001
)

// Execute runs the clock.
func (c *Clock) Execute() {
	if c.Interval > 0 {
		now := time.Now()

		if now.Sub(c.lastTick) > time.Duration(c.Interval)*duration {
			c.lastTick = now
			c.Ticks++
			if c.DCPU != nil && c.Message > 0 {
				c.DCPU.Interrupt(c.Message)
			}
		}
	}
}

// GetID returns the Clock id.
func (c *Clock) GetID() uint32 {
	return id
}

// GetManufacturerID returns the Clock manufacturer id.
func (c *Clock) GetManufacturerID() uint32 {
	return 0
}

// GetVersion returns the Clock version.
func (c *Clock) GetVersion() uint16 {
	return version
}

// HandleHardwareInterrupt handles messages from the DCPU.
func (c *Clock) HandleHardwareInterrupt() {
	switch {
	case c.DCPU == nil:
		return

	case c.DCPU.RegisterA == 0:
		c.Interval = c.DCPU.RegisterB
		c.Ticks = 0

	case c.DCPU.RegisterA == 1:
		c.DCPU.RegisterC = c.Ticks

	case c.DCPU.RegisterA == 2:
		c.Message = c.DCPU.RegisterB
	}
}
<commit_msg>Make an enum for Clock hardware interrupt values.<commit_after>package dcpu

import "time"

// Clock implements Generic Clock (compatible).
type Clock struct {
	DCPU     *DCPU
	Interval uint16
	Message  uint16
	Ticks    uint16

	lastTick time.Time
}

const (
	duration     = time.Second / frequency
	frequency    = 60
	clockID      = 0x12d0b402
	clockVersion = 0x0001
)

const (
	clockSetInterval = iota
	clockGetTicks
	clockSetInterruptMessage
)

// Execute runs the clock.
func (c *Clock) Execute() {
	if c.Interval > 0 {
		now := time.Now()

		if now.Sub(c.lastTick) > time.Duration(c.Interval)*duration {
			c.lastTick = now
			c.Ticks++
			if c.DCPU != nil && c.Message > 0 {
				c.DCPU.Interrupt(c.Message)
			}
		}
	}
}

// GetID returns the Clock id.
func (c *Clock) GetID() uint32 {
	return clockID
}

// GetManufacturerID returns the Clock manufacturer id.
func (c *Clock) GetManufacturerID() uint32 {
	return 0
}

// GetVersion returns the Clock version.
func (c *Clock) GetVersion() uint16 {
	return clockVersion
}

// HandleHardwareInterrupt handles messages from the DCPU.
func (c *Clock) HandleHardwareInterrupt() {
	if c.DCPU == nil {
		return
	}

	switch c.DCPU.RegisterA {
	case clockSetInterval:
		c.Interval = c.DCPU.RegisterB
		c.Ticks = 0

	case clockGetTicks:
		c.DCPU.RegisterC = c.Ticks

	case clockSetInterruptMessage:
		c.Message = c.DCPU.RegisterB
	}
}

{'fraction_non_alphanumeric': 0.11038961038961038, 'fraction_numerical': 0.02406417112299465, 'mean_word_length': 3.137440758293839, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5535651', 'n_tokens_mistral': 1052, 'n_tokens_neox': 947, 'n_words': 262}