import ctypes

ICD1553_DISPLAY_PIXEL_MIN = 0
ICD1553_DISPLAY_PIXEL_MAX = 483

class DisplayCoordHtpTarget(ctypes.Structure):
    _fields_ = [("raw", ctypes.c_uint16)]

    def get_display_coord_htp_target(self):
        return (self.raw >> 7) & 0x1FF

    def set_display_coord_htp_target(self, value):
        if not ICD1553_DISPLAY_PIXEL_MIN <= value <= ICD1553_DISPLAY_PIXEL_MAX:
            raise ValueError(f"Display coord value must be between {ICD1553_DISPLAY_PIXEL_MIN} and {ICD1553_DISPLAY_PIXEL_MAX}")
        self.raw &= ~(0x1FF << 7)
        self.raw |= (value << 7)

    def get_spare(self):
        return (self.raw >> 0) & 0x7F

    def set_spare(self, value):
        self.raw &= ~(0x7F << 0)
        self.raw |= (value << 0)