-- GENERATED by C->Haskell Compiler, version 0.28.1 Switcheroo, 1 April 2016 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "src/Termbox/Internal.chs" #-}
-- | Lowest-level termbox bindings. No creativity here, just a 1:1 mapping.
-- Some of the enums are hand-written (source copied from generated module) so
-- I can insert haddocks.

{-# language InstanceSigs #-}

module Termbox.Internal where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import qualified Foreign.Storable as C2HSImp





import Data.Char (ord)
import Data.Word
import Foreign
import Foreign.C
import Prelude hiding (mod)

--------------------------------------------------------------------------------
-- Constants
--------------------------------------------------------------------------------

_INPUT_CURRENT, _INPUT_ESC, _INPUT_ALT, _INPUT_MOUSE :: Int
_HIDE_CURSOR :: Int
_BOLD, _UNDERLINE, _REVERSE :: Word16
_DEFAULT, _BLACK, _RED, _GREEN, _YELLOW, _BLUE, _MAGENTA, _CYAN, _WHITE :: Word16

_INPUT_CURRENT = 0
{-# LINE 26 "src/Termbox/Internal.chs" #-}

_INPUT_ESC     = 1
{-# LINE 27 "src/Termbox/Internal.chs" #-}

_INPUT_ALT     = 2
{-# LINE 28 "src/Termbox/Internal.chs" #-}

_INPUT_MOUSE   = 4
{-# LINE 29 "src/Termbox/Internal.chs" #-}


_HIDE_CURSOR   = -1
{-# LINE 31 "src/Termbox/Internal.chs" #-}


_BOLD          = 0x100
{-# LINE 33 "src/Termbox/Internal.chs" #-}

_UNDERLINE     = 0x200
{-# LINE 34 "src/Termbox/Internal.chs" #-}

_REVERSE       = 0x400
{-# LINE 35 "src/Termbox/Internal.chs" #-}


_DEFAULT       = 0x0
{-# LINE 37 "src/Termbox/Internal.chs" #-}

_BLACK         = 0x1
{-# LINE 38 "src/Termbox/Internal.chs" #-}

_RED           = 0x2
{-# LINE 39 "src/Termbox/Internal.chs" #-}

_GREEN         = 0x3
{-# LINE 40 "src/Termbox/Internal.chs" #-}

_YELLOW        = 0x4
{-# LINE 41 "src/Termbox/Internal.chs" #-}

_BLUE          = 0x5
{-# LINE 42 "src/Termbox/Internal.chs" #-}

_MAGENTA       = 0x6
{-# LINE 43 "src/Termbox/Internal.chs" #-}

_CYAN          = 0x7
{-# LINE 44 "src/Termbox/Internal.chs" #-}

_WHITE         = 0x8
{-# LINE 45 "src/Termbox/Internal.chs" #-}


--------------------------------------------------------------------------------
-- Enums
--------------------------------------------------------------------------------

data EventType = EventKey
               | EventResize
               | EventMouse
instance Enum EventType where
  succ EventKey = EventResize
  succ EventResize = EventMouse
  succ EventMouse = error "EventType.succ: EventMouse has no successor"

  pred EventResize = EventKey
  pred EventMouse = EventResize
  pred EventKey = error "EventType.pred: EventKey has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from EventMouse

  fromEnum EventKey = 1
  fromEnum EventResize = 2
  fromEnum EventMouse = 3

  toEnum 1 = EventKey
  toEnum 2 = EventResize
  toEnum 3 = EventMouse
  toEnum unmatched = error ("EventType.toEnum: Cannot match " ++ show unmatched)

{-# LINE 57 "src/Termbox/Internal.chs" #-}


data InitResult = PipeTrapError
                | FailedToOpenTTY
                | UnsupportedTerminal
                | InitOk
instance Enum InitResult where
  succ PipeTrapError = FailedToOpenTTY
  succ FailedToOpenTTY = UnsupportedTerminal
  succ UnsupportedTerminal = InitOk
  succ InitOk = error "InitResult.succ: InitOk has no successor"

  pred FailedToOpenTTY = PipeTrapError
  pred UnsupportedTerminal = FailedToOpenTTY
  pred InitOk = UnsupportedTerminal
  pred PipeTrapError = error "InitResult.pred: PipeTrapError has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from InitOk

  fromEnum PipeTrapError = (-3)
  fromEnum FailedToOpenTTY = (-2)
  fromEnum UnsupportedTerminal = (-1)
  fromEnum InitOk = 0

  toEnum (-3) = PipeTrapError
  toEnum (-2) = FailedToOpenTTY
  toEnum (-1) = UnsupportedTerminal
  toEnum 0 = InitOk
  toEnum unmatched = error ("InitResult.toEnum: Cannot match " ++ show unmatched)

{-# LINE 66 "src/Termbox/Internal.chs" #-}


data Key = KeyCtrlTilde
         | KeyCtrl2
         | KeyCtrlA
         | KeyCtrlB
         | KeyCtrlC
         | KeyCtrlD
         | KeyCtrlE
         | KeyCtrlF
         | KeyCtrlG
         | KeyBackspace
         | KeyCtrlH
         | KeyTab
         | KeyCtrlI
         | KeyCtrlJ
         | KeyCtrlK
         | KeyCtrlL
         | KeyEnter
         | KeyCtrlM
         | KeyCtrlN
         | KeyCtrlO
         | KeyCtrlP
         | KeyCtrlQ
         | KeyCtrlR
         | KeyCtrlS
         | KeyCtrlT
         | KeyCtrlU
         | KeyCtrlV
         | KeyCtrlW
         | KeyCtrlX
         | KeyCtrlY
         | KeyCtrlZ
         | KeyEsc
         | KeyCtrlLsqBracket
         | KeyCtrl3
         | KeyCtrl4
         | KeyCtrlBackslash
         | KeyCtrl5
         | KeyCtrlRsqBracket
         | KeyCtrl6
         | KeyCtrl7
         | KeyCtrlSlash
         | KeyCtrlUnderscore
         | KeySpace
         | KeyBackspace2
         | KeyCtrl8
         | KeyMouseWheelDown
         | KeyMouseWheelUp
         | KeyMouseRelease
         | KeyMouseMiddle
         | KeyMouseRight
         | KeyMouseLeft
         | KeyArrowRight
         | KeyArrowLeft
         | KeyArrowDown
         | KeyArrowUp
         | KeyPageDn
         | KeyPageUp
         | KeyEnd
         | KeyHome
         | KeyDelete
         | KeyInsert
         | KeyF12
         | KeyF11
         | KeyF10
         | KeyF9
         | KeyF8
         | KeyF7
         | KeyF6
         | KeyF5
         | KeyF4
         | KeyF3
         | KeyF2
         | KeyF1
  deriving (Show)
instance Enum Key where
  succ KeyCtrlTilde = KeyCtrlA
  succ KeyCtrl2 = KeyCtrlA
  succ KeyCtrlA = KeyCtrlB
  succ KeyCtrlB = KeyCtrlC
  succ KeyCtrlC = KeyCtrlD
  succ KeyCtrlD = KeyCtrlE
  succ KeyCtrlE = KeyCtrlF
  succ KeyCtrlF = KeyCtrlG
  succ KeyCtrlG = KeyBackspace
  succ KeyBackspace = KeyTab
  succ KeyCtrlH = KeyTab
  succ KeyTab = KeyCtrlJ
  succ KeyCtrlI = KeyCtrlJ
  succ KeyCtrlJ = KeyCtrlK
  succ KeyCtrlK = KeyCtrlL
  succ KeyCtrlL = KeyEnter
  succ KeyEnter = KeyCtrlN
  succ KeyCtrlM = KeyCtrlN
  succ KeyCtrlN = KeyCtrlO
  succ KeyCtrlO = KeyCtrlP
  succ KeyCtrlP = KeyCtrlQ
  succ KeyCtrlQ = KeyCtrlR
  succ KeyCtrlR = KeyCtrlS
  succ KeyCtrlS = KeyCtrlT
  succ KeyCtrlT = KeyCtrlU
  succ KeyCtrlU = KeyCtrlV
  succ KeyCtrlV = KeyCtrlW
  succ KeyCtrlW = KeyCtrlX
  succ KeyCtrlX = KeyCtrlY
  succ KeyCtrlY = KeyCtrlZ
  succ KeyCtrlZ = KeyEsc
  succ KeyEsc = KeyCtrl4
  succ KeyCtrlLsqBracket = KeyCtrl4
  succ KeyCtrl3 = KeyCtrl4
  succ KeyCtrl4 = KeyCtrl5
  succ KeyCtrlBackslash = KeyCtrl5
  succ KeyCtrl5 = KeyCtrl6
  succ KeyCtrlRsqBracket = KeyCtrl6
  succ KeyCtrl6 = KeyCtrl7
  succ KeyCtrl7 = KeySpace
  succ KeyCtrlSlash = KeySpace
  succ KeyCtrlUnderscore = KeySpace
  succ KeySpace = KeyBackspace2
  succ KeyBackspace2 = KeyMouseWheelDown
  succ KeyCtrl8 = KeyMouseWheelDown
  succ KeyMouseWheelDown = KeyMouseWheelUp
  succ KeyMouseWheelUp = KeyMouseRelease
  succ KeyMouseRelease = KeyMouseMiddle
  succ KeyMouseMiddle = KeyMouseRight
  succ KeyMouseRight = KeyMouseLeft
  succ KeyMouseLeft = KeyArrowRight
  succ KeyArrowRight = KeyArrowLeft
  succ KeyArrowLeft = KeyArrowDown
  succ KeyArrowDown = KeyArrowUp
  succ KeyArrowUp = KeyPageDn
  succ KeyPageDn = KeyPageUp
  succ KeyPageUp = KeyEnd
  succ KeyEnd = KeyHome
  succ KeyHome = KeyDelete
  succ KeyDelete = KeyInsert
  succ KeyInsert = KeyF12
  succ KeyF12 = KeyF11
  succ KeyF11 = KeyF10
  succ KeyF10 = KeyF9
  succ KeyF9 = KeyF8
  succ KeyF8 = KeyF7
  succ KeyF7 = KeyF6
  succ KeyF6 = KeyF5
  succ KeyF5 = KeyF4
  succ KeyF4 = KeyF3
  succ KeyF3 = KeyF2
  succ KeyF2 = KeyF1
  succ KeyF1 = error "Key.succ: KeyF1 has no successor"

  pred KeyCtrlA = KeyCtrlTilde
  pred KeyCtrlB = KeyCtrlA
  pred KeyCtrlC = KeyCtrlB
  pred KeyCtrlD = KeyCtrlC
  pred KeyCtrlE = KeyCtrlD
  pred KeyCtrlF = KeyCtrlE
  pred KeyCtrlG = KeyCtrlF
  pred KeyBackspace = KeyCtrlG
  pred KeyCtrlH = KeyCtrlG
  pred KeyTab = KeyBackspace
  pred KeyCtrlI = KeyBackspace
  pred KeyCtrlJ = KeyTab
  pred KeyCtrlK = KeyCtrlJ
  pred KeyCtrlL = KeyCtrlK
  pred KeyEnter = KeyCtrlL
  pred KeyCtrlM = KeyCtrlL
  pred KeyCtrlN = KeyEnter
  pred KeyCtrlO = KeyCtrlN
  pred KeyCtrlP = KeyCtrlO
  pred KeyCtrlQ = KeyCtrlP
  pred KeyCtrlR = KeyCtrlQ
  pred KeyCtrlS = KeyCtrlR
  pred KeyCtrlT = KeyCtrlS
  pred KeyCtrlU = KeyCtrlT
  pred KeyCtrlV = KeyCtrlU
  pred KeyCtrlW = KeyCtrlV
  pred KeyCtrlX = KeyCtrlW
  pred KeyCtrlY = KeyCtrlX
  pred KeyCtrlZ = KeyCtrlY
  pred KeyEsc = KeyCtrlZ
  pred KeyCtrlLsqBracket = KeyCtrlZ
  pred KeyCtrl3 = KeyCtrlZ
  pred KeyCtrl4 = KeyEsc
  pred KeyCtrlBackslash = KeyEsc
  pred KeyCtrl5 = KeyCtrl4
  pred KeyCtrlRsqBracket = KeyCtrl4
  pred KeyCtrl6 = KeyCtrl5
  pred KeyCtrl7 = KeyCtrl6
  pred KeyCtrlSlash = KeyCtrl6
  pred KeyCtrlUnderscore = KeyCtrl6
  pred KeySpace = KeyCtrl7
  pred KeyBackspace2 = KeySpace
  pred KeyCtrl8 = KeySpace
  pred KeyMouseWheelDown = KeyBackspace2
  pred KeyMouseWheelUp = KeyMouseWheelDown
  pred KeyMouseRelease = KeyMouseWheelUp
  pred KeyMouseMiddle = KeyMouseRelease
  pred KeyMouseRight = KeyMouseMiddle
  pred KeyMouseLeft = KeyMouseRight
  pred KeyArrowRight = KeyMouseLeft
  pred KeyArrowLeft = KeyArrowRight
  pred KeyArrowDown = KeyArrowLeft
  pred KeyArrowUp = KeyArrowDown
  pred KeyPageDn = KeyArrowUp
  pred KeyPageUp = KeyPageDn
  pred KeyEnd = KeyPageUp
  pred KeyHome = KeyEnd
  pred KeyDelete = KeyHome
  pred KeyInsert = KeyDelete
  pred KeyF12 = KeyInsert
  pred KeyF11 = KeyF12
  pred KeyF10 = KeyF11
  pred KeyF9 = KeyF10
  pred KeyF8 = KeyF9
  pred KeyF7 = KeyF8
  pred KeyF6 = KeyF7
  pred KeyF5 = KeyF6
  pred KeyF4 = KeyF5
  pred KeyF3 = KeyF4
  pred KeyF2 = KeyF3
  pred KeyF1 = KeyF2
  pred KeyCtrlTilde = error "Key.pred: KeyCtrlTilde has no predecessor"
  pred KeyCtrl2 = error "Key.pred: KeyCtrl2 has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from KeyF1

  fromEnum KeyCtrlTilde = 0
  fromEnum KeyCtrl2 = 0
  fromEnum KeyCtrlA = 1
  fromEnum KeyCtrlB = 2
  fromEnum KeyCtrlC = 3
  fromEnum KeyCtrlD = 4
  fromEnum KeyCtrlE = 5
  fromEnum KeyCtrlF = 6
  fromEnum KeyCtrlG = 7
  fromEnum KeyBackspace = 8
  fromEnum KeyCtrlH = 8
  fromEnum KeyTab = 9
  fromEnum KeyCtrlI = 9
  fromEnum KeyCtrlJ = 10
  fromEnum KeyCtrlK = 11
  fromEnum KeyCtrlL = 12
  fromEnum KeyEnter = 13
  fromEnum KeyCtrlM = 13
  fromEnum KeyCtrlN = 14
  fromEnum KeyCtrlO = 15
  fromEnum KeyCtrlP = 16
  fromEnum KeyCtrlQ = 17
  fromEnum KeyCtrlR = 18
  fromEnum KeyCtrlS = 19
  fromEnum KeyCtrlT = 20
  fromEnum KeyCtrlU = 21
  fromEnum KeyCtrlV = 22
  fromEnum KeyCtrlW = 23
  fromEnum KeyCtrlX = 24
  fromEnum KeyCtrlY = 25
  fromEnum KeyCtrlZ = 26
  fromEnum KeyEsc = 27
  fromEnum KeyCtrlLsqBracket = 27
  fromEnum KeyCtrl3 = 27
  fromEnum KeyCtrl4 = 28
  fromEnum KeyCtrlBackslash = 28
  fromEnum KeyCtrl5 = 29
  fromEnum KeyCtrlRsqBracket = 29
  fromEnum KeyCtrl6 = 30
  fromEnum KeyCtrl7 = 31
  fromEnum KeyCtrlSlash = 31
  fromEnum KeyCtrlUnderscore = 31
  fromEnum KeySpace = 32
  fromEnum KeyBackspace2 = 127
  fromEnum KeyCtrl8 = 127
  fromEnum KeyMouseWheelDown = 65508
  fromEnum KeyMouseWheelUp = 65509
  fromEnum KeyMouseRelease = 65510
  fromEnum KeyMouseMiddle = 65511
  fromEnum KeyMouseRight = 65512
  fromEnum KeyMouseLeft = 65513
  fromEnum KeyArrowRight = 65514
  fromEnum KeyArrowLeft = 65515
  fromEnum KeyArrowDown = 65516
  fromEnum KeyArrowUp = 65517
  fromEnum KeyPageDn = 65518
  fromEnum KeyPageUp = 65519
  fromEnum KeyEnd = 65520
  fromEnum KeyHome = 65521
  fromEnum KeyDelete = 65522
  fromEnum KeyInsert = 65523
  fromEnum KeyF12 = 65524
  fromEnum KeyF11 = 65525
  fromEnum KeyF10 = 65526
  fromEnum KeyF9 = 65527
  fromEnum KeyF8 = 65528
  fromEnum KeyF7 = 65529
  fromEnum KeyF6 = 65530
  fromEnum KeyF5 = 65531
  fromEnum KeyF4 = 65532
  fromEnum KeyF3 = 65533
  fromEnum KeyF2 = 65534
  fromEnum KeyF1 = 65535

  toEnum 0 = KeyCtrlTilde
  toEnum 1 = KeyCtrlA
  toEnum 2 = KeyCtrlB
  toEnum 3 = KeyCtrlC
  toEnum 4 = KeyCtrlD
  toEnum 5 = KeyCtrlE
  toEnum 6 = KeyCtrlF
  toEnum 7 = KeyCtrlG
  toEnum 8 = KeyBackspace
  toEnum 9 = KeyTab
  toEnum 10 = KeyCtrlJ
  toEnum 11 = KeyCtrlK
  toEnum 12 = KeyCtrlL
  toEnum 13 = KeyEnter
  toEnum 14 = KeyCtrlN
  toEnum 15 = KeyCtrlO
  toEnum 16 = KeyCtrlP
  toEnum 17 = KeyCtrlQ
  toEnum 18 = KeyCtrlR
  toEnum 19 = KeyCtrlS
  toEnum 20 = KeyCtrlT
  toEnum 21 = KeyCtrlU
  toEnum 22 = KeyCtrlV
  toEnum 23 = KeyCtrlW
  toEnum 24 = KeyCtrlX
  toEnum 25 = KeyCtrlY
  toEnum 26 = KeyCtrlZ
  toEnum 27 = KeyEsc
  toEnum 28 = KeyCtrl4
  toEnum 29 = KeyCtrl5
  toEnum 30 = KeyCtrl6
  toEnum 31 = KeyCtrl7
  toEnum 32 = KeySpace
  toEnum 127 = KeyBackspace2
  toEnum 65508 = KeyMouseWheelDown
  toEnum 65509 = KeyMouseWheelUp
  toEnum 65510 = KeyMouseRelease
  toEnum 65511 = KeyMouseMiddle
  toEnum 65512 = KeyMouseRight
  toEnum 65513 = KeyMouseLeft
  toEnum 65514 = KeyArrowRight
  toEnum 65515 = KeyArrowLeft
  toEnum 65516 = KeyArrowDown
  toEnum 65517 = KeyArrowUp
  toEnum 65518 = KeyPageDn
  toEnum 65519 = KeyPageUp
  toEnum 65520 = KeyEnd
  toEnum 65521 = KeyHome
  toEnum 65522 = KeyDelete
  toEnum 65523 = KeyInsert
  toEnum 65524 = KeyF12
  toEnum 65525 = KeyF11
  toEnum 65526 = KeyF10
  toEnum 65527 = KeyF9
  toEnum 65528 = KeyF8
  toEnum 65529 = KeyF7
  toEnum 65530 = KeyF6
  toEnum 65531 = KeyF5
  toEnum 65532 = KeyF4
  toEnum 65533 = KeyF3
  toEnum 65534 = KeyF2
  toEnum 65535 = KeyF1
  toEnum unmatched = error ("Key.toEnum: Cannot match " ++ show unmatched)

{-# LINE 144 "src/Termbox/Internal.chs" #-}


data Mod = ModNone
         | ModAlt
instance Enum Mod where
  succ ModNone = ModAlt
  succ ModAlt = error "Mod.succ: ModAlt has no successor"

  pred ModAlt = ModNone
  pred ModNone = error "Mod.pred: ModNone has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from ModAlt

  fromEnum ModNone = 0
  fromEnum ModAlt = 1

  toEnum 0 = ModNone
  toEnum 1 = ModAlt
  toEnum unmatched = error ("Mod.toEnum: Cannot match " ++ show unmatched)

{-# LINE 151 "src/Termbox/Internal.chs" #-}


data OutputMode = OutputModeCurrent
                | OutputModeNormal
                | OutputMode256
                | OutputMode216
                | OutputModeGrayscale
instance Enum OutputMode where
  succ OutputModeCurrent = OutputModeNormal
  succ OutputModeNormal = OutputMode256
  succ OutputMode256 = OutputMode216
  succ OutputMode216 = OutputModeGrayscale
  succ OutputModeGrayscale = error "OutputMode.succ: OutputModeGrayscale has no successor"

  pred OutputModeNormal = OutputModeCurrent
  pred OutputMode256 = OutputModeNormal
  pred OutputMode216 = OutputMode256
  pred OutputModeGrayscale = OutputMode216
  pred OutputModeCurrent = error "OutputMode.pred: OutputModeCurrent has no predecessor"

  enumFromTo from to = go from
    where
      end = fromEnum to
      go v = case compare (fromEnum v) end of
                 LT -> v : go (succ v)
                 EQ -> [v]
                 GT -> []

  enumFrom from = enumFromTo from OutputModeGrayscale

  fromEnum OutputModeCurrent = 0
  fromEnum OutputModeNormal = 1
  fromEnum OutputMode256 = 2
  fromEnum OutputMode216 = 3
  fromEnum OutputModeGrayscale = 4

  toEnum 0 = OutputModeCurrent
  toEnum 1 = OutputModeNormal
  toEnum 2 = OutputMode256
  toEnum 3 = OutputMode216
  toEnum 4 = OutputModeGrayscale
  toEnum unmatched = error ("OutputMode.toEnum: Cannot match " ++ show unmatched)

{-# LINE 162 "src/Termbox/Internal.chs" #-}


--------------------------------------------------------------------------------
-- Types
--------------------------------------------------------------------------------

sizeofCell :: Int
sizeofCell =
  8
{-# LINE 170 "src/Termbox/Internal.chs" #-}


alignofCell :: Int
alignofCell =
  4
{-# LINE 174 "src/Termbox/Internal.chs" #-}


getCellCh :: Ptr a -> IO Char
getCellCh =
  fmap (toEnum . fromIntegral) . (\ptr -> do {C2HSImp.peekByteOff ptr 0 :: IO C2HSImp.CUInt})
{-# LINE 178 "src/Termbox/Internal.chs" #-}


getCellFg :: Ptr a -> IO Word16
getCellFg =
  fmap fromIntegral . (\ptr -> do {C2HSImp.peekByteOff ptr 4 :: IO C2HSImp.CUShort})
{-# LINE 182 "src/Termbox/Internal.chs" #-}


getCellBg :: Ptr a -> IO Word16
getCellBg =
  fmap fromIntegral . (\ptr -> do {C2HSImp.peekByteOff ptr 6 :: IO C2HSImp.CUShort})
{-# LINE 186 "src/Termbox/Internal.chs" #-}


setCellCh :: Ptr a -> Char -> IO ()
setCellCh p =
  (\ptr val -> do {C2HSImp.pokeByteOff ptr 0 (val :: C2HSImp.CUInt)}) p . fromIntegral . fromEnum

setCellFg :: Ptr a -> Word16 -> IO ()
setCellFg p =
  (\ptr val -> do {C2HSImp.pokeByteOff ptr 4 (val :: C2HSImp.CUShort)}) p . fromIntegral

setCellBg :: Ptr a -> Word16 -> IO ()
setCellBg p =
  (\ptr val -> do {C2HSImp.pokeByteOff ptr 6 (val :: C2HSImp.CUShort)}) p . fromIntegral

data Event
  = Event !EventType Mod Key Char Int Int Int Int

instance Storable Event where
  sizeOf :: Event -> Int
  sizeOf _ =
    24
{-# LINE 206 "src/Termbox/Internal.chs" #-}


  alignment :: Event -> Int
  alignment _ =
    4
{-# LINE 210 "src/Termbox/Internal.chs" #-}


  peek :: Ptr Event -> IO Event
  peek p =
    Event
      <$> ((toEnum . fromIntegral) <$> (\ptr -> do {C2HSImp.peekByteOff ptr 0 :: IO C2HSImp.CUChar}) p)
      <*> ((toEnum . fromIntegral) <$> (\ptr -> do {C2HSImp.peekByteOff ptr 1 :: IO C2HSImp.CUChar}) p)
      <*> ((toEnum . fromIntegral) <$> (\ptr -> do {C2HSImp.peekByteOff ptr 2 :: IO C2HSImp.CUShort}) p)
      <*> ((toEnum . fromIntegral) <$> (\ptr -> do {C2HSImp.peekByteOff ptr 4 :: IO C2HSImp.CUInt}) p)
      <*> (fromIntegral <$> (\ptr -> do {C2HSImp.peekByteOff ptr 8 :: IO C2HSImp.CInt}) p)
      <*> (fromIntegral <$> (\ptr -> do {C2HSImp.peekByteOff ptr 12 :: IO C2HSImp.CInt}) p)
      <*> (fromIntegral <$> (\ptr -> do {C2HSImp.peekByteOff ptr 16 :: IO C2HSImp.CInt}) p)
      <*> (fromIntegral <$> (\ptr -> do {C2HSImp.peekByteOff ptr 20 :: IO C2HSImp.CInt}) p)

  poke :: Ptr Event -> Event -> IO ()
  poke p (Event typ mod key ch w h x y) = do
    (\ptr val -> do {C2HSImp.pokeByteOff ptr 0 (val :: C2HSImp.CUChar)}) p (fromIntegral (fromEnum typ))
    (\ptr val -> do {C2HSImp.pokeByteOff ptr 1 (val :: C2HSImp.CUChar)}) p (fromIntegral (fromEnum mod))
    (\ptr val -> do {C2HSImp.pokeByteOff ptr 2 (val :: C2HSImp.CUShort)}) p (fromIntegral (fromEnum key))
    (\ptr val -> do {C2HSImp.pokeByteOff ptr 4 (val :: C2HSImp.CUInt)}) p (fromIntegral (fromEnum ch))
    (\ptr val -> do {C2HSImp.pokeByteOff ptr 8 (val :: C2HSImp.CInt)}) p (fromIntegral w)
    (\ptr val -> do {C2HSImp.pokeByteOff ptr 12 (val :: C2HSImp.CInt)}) p (fromIntegral h)
    (\ptr val -> do {C2HSImp.pokeByteOff ptr 16 (val :: C2HSImp.CInt)}) p (fromIntegral x)
    (\ptr val -> do {C2HSImp.pokeByteOff ptr 20 (val :: C2HSImp.CInt)}) p (fromIntegral y)

type EventPtr = C2HSImp.Ptr (Event)
{-# LINE 235 "src/Termbox/Internal.chs" #-}


--------------------------------------------------------------------------------
-- Functions
--------------------------------------------------------------------------------

changeCell :: (Int) -> (Int) -> (Char) -> (Word16) -> (Word16) -> IO ()
changeCell a1 a2 a3 a4 a5 =
  let {a1' = fromIntegral a1} in
  let {a2' = fromIntegral a2} in
  let {a3' = charToUInt a3} in
  let {a4' = fromIntegral a4} in
  let {a5' = fromIntegral a5} in
  changeCell'_ a1' a2' a3' a4' a5' >>
  return ()

{-# LINE 244 "src/Termbox/Internal.chs" #-}


clear :: IO ()
clear =
  clear'_ >>
  return ()

{-# LINE 249 "src/Termbox/Internal.chs" #-}


height :: IO ((Int))
height =
  height'_ >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 254 "src/Termbox/Internal.chs" #-}


init :: IO ((InitResult))
init =
  init'_ >>= \res ->
  let {res' = (toEnum . fromIntegral) res} in
  return (res')

{-# LINE 259 "src/Termbox/Internal.chs" #-}


peekEvent :: (EventPtr) -> (Int) -> IO ((Int))
peekEvent a1 a2 =
  let {a1' = id a1} in
  let {a2' = fromIntegral a2} in
  peekEvent'_ a1' a2' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 264 "src/Termbox/Internal.chs" #-}


pollEvent :: (EventPtr) -> IO ((Int))
pollEvent a1 =
  let {a1' = id a1} in
  pollEvent'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 269 "src/Termbox/Internal.chs" #-}


present :: IO ()
present =
  present'_ >>
  return ()

{-# LINE 274 "src/Termbox/Internal.chs" #-}


selectInputMode :: (Int) -> IO ((Int))
selectInputMode a1 =
  let {a1' = fromIntegral a1} in
  selectInputMode'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 279 "src/Termbox/Internal.chs" #-}


selectOutputMode :: (OutputMode) -> IO ((OutputMode))
selectOutputMode a1 =
  let {a1' = (fromIntegral . fromEnum) a1} in
  selectOutputMode'_ a1' >>= \res ->
  let {res' = (toEnum . fromIntegral) res} in
  return (res')

{-# LINE 284 "src/Termbox/Internal.chs" #-}


setClearAttributes :: (Word16) -> (Word16) -> IO ()
setClearAttributes a1 a2 =
  let {a1' = fromIntegral a1} in
  let {a2' = fromIntegral a2} in
  setClearAttributes'_ a1' a2' >>
  return ()

{-# LINE 289 "src/Termbox/Internal.chs" #-}


setCursor :: (Int) -> (Int) -> IO ()
setCursor a1 a2 =
  let {a1' = fromIntegral a1} in
  let {a2' = fromIntegral a2} in
  setCursor'_ a1' a2' >>
  return ()

{-# LINE 294 "src/Termbox/Internal.chs" #-}


shutdown :: IO ()
shutdown =
  shutdown'_ >>
  return ()

{-# LINE 299 "src/Termbox/Internal.chs" #-}


width :: IO ((Int))
width =
  width'_ >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 304 "src/Termbox/Internal.chs" #-}


--------------------------------------------------------------------------------
-- Misc.
--------------------------------------------------------------------------------

charToUInt :: Char -> CUInt
charToUInt =
  fromIntegral . ord

foreign import ccall safe "Termbox/Internal.chs.h tb_change_cell"
  changeCell'_ :: (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CUInt -> (C2HSImp.CUShort -> (C2HSImp.CUShort -> (IO ()))))))

foreign import ccall safe "Termbox/Internal.chs.h tb_clear"
  clear'_ :: (IO ())

foreign import ccall safe "Termbox/Internal.chs.h tb_height"
  height'_ :: (IO C2HSImp.CInt)

foreign import ccall safe "Termbox/Internal.chs.h tb_init"
  init'_ :: (IO C2HSImp.CInt)

foreign import ccall safe "Termbox/Internal.chs.h tb_peek_event"
  peekEvent'_ :: ((EventPtr) -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))

foreign import ccall safe "Termbox/Internal.chs.h tb_poll_event"
  pollEvent'_ :: ((EventPtr) -> (IO C2HSImp.CInt))

foreign import ccall safe "Termbox/Internal.chs.h tb_present"
  present'_ :: (IO ())

foreign import ccall safe "Termbox/Internal.chs.h tb_select_input_mode"
  selectInputMode'_ :: (C2HSImp.CInt -> (IO C2HSImp.CInt))

foreign import ccall safe "Termbox/Internal.chs.h tb_select_output_mode"
  selectOutputMode'_ :: (C2HSImp.CInt -> (IO C2HSImp.CInt))

foreign import ccall safe "Termbox/Internal.chs.h tb_set_clear_attributes"
  setClearAttributes'_ :: (C2HSImp.CUShort -> (C2HSImp.CUShort -> (IO ())))

foreign import ccall safe "Termbox/Internal.chs.h tb_set_cursor"
  setCursor'_ :: (C2HSImp.CInt -> (C2HSImp.CInt -> (IO ())))

foreign import ccall safe "Termbox/Internal.chs.h tb_shutdown"
  shutdown'_ :: (IO ())

foreign import ccall safe "Termbox/Internal.chs.h tb_width"
  width'_ :: (IO C2HSImp.CInt)