module Sound.MED.Raw.MMDARexxTrigCmd where

import Sound.MED.Basic.Amiga

data MMDARexxTrigCmd = MMDARexxTrigCmd
  { next     :: Maybe MMDARexxTrigCmd
  , cmdnum   :: UBYTE
  , pad      :: UBYTE
  , cmdtype  :: WORD
  , cmd      :: [ UBYTE ]
  , port     :: [ UBYTE ]
  , cmd_len  :: UWORD
  , port_len :: UWORD
  }
  deriving (Show)

peek :: MEM -> PTR -> IO MMDARexxTrigCmd
peek m p = do
  next'''    <- peekPTR m p
  next'      <- peek m $? next'''
  cmdnum'    <- peekUBYTE m (p+4)
  pad'       <- peekUBYTE m (p+5)
  cmdtype'   <- peekWORD  m (p+6)
  cmd''      <- peekPTR   m (p+8)
  port''     <- peekPTR   m (p+12)
  cmd_len'   <- peekUWORD m (p+16)
  port_len'  <- peekUWORD m (p+18)
  cmd'       <- mapM (peekUBYTE m) $ pointerRangeGenCheck cmd'' 1 (cmd_len'+1)
  port'      <- mapM (peekUBYTE m) $ pointerRangeGenCheck port'' 1 (port_len'+1)
  return $ MMDARexxTrigCmd
    next' cmdnum' pad' cmdtype' cmd' port' cmd_len' port_len'