module Sound.MED.Raw.MMD1NoteData where

import Sound.MED.Basic.Amiga

import Data.Bits ((.&.))

data MMD1NoteData = MMD1NoteData
  { note       :: UBYTE
  , instrument :: UBYTE
  , command    :: UBYTE
  , databyte   :: UBYTE
  }
  deriving (Show)

peek :: MEM -> PTR -> IO MMD1NoteData
peek m p = do
  byte1 <- peekUBYTE m (p + 0)
  byte2 <- peekUBYTE m (p + 1)
  byte3 <- peekUBYTE m (p + 2)
  byte4 <- peekUBYTE m (p + 3)
  let nnnnnnn     = byte1 .&. 0x7F
  let iiiiii      = byte2 .&. 0x3F
  let cccccccc    = byte3 .&. 0xFF
  let dddddddd    = byte4 .&. 0xFF
  let note'       = nnnnnnn
  let instrument' = iiiiii
  let command'    = cccccccc
  let databyte'   = dddddddd
  return $ MMD1NoteData
    note' instrument' command' databyte'