module Sound.MED.Raw.MMD0Block where

import qualified Sound.MED.Raw.MMD0NoteData as MMD0NoteData
import Sound.MED.Raw.MMD0NoteData(MMD0NoteData)

import Sound.MED.Basic.Amiga

data MMD0Block = MMD0Block
  { numtracks :: UBYTE
  , lines     :: UBYTE -- NOTE: actual number of lines is one greater
  , notedata  :: [ [ MMD0NoteData ] ]
  }
  deriving (Show)

peek :: MEM -> PTR -> IO MMD0Block
peek m p = do
  numtracks'    <- peekUBYTE m (p + 0)
  lines'        <- peekUBYTE m (p + 1)
  notedata''    <- mapM (MMD0NoteData.peek m) $ pointerRangeGen2 (p+2) 3 numtracks' (lines'+1)
  let notedata' =  chunk numtracks' notedata''
  return $ MMD0Block
    numtracks' lines' notedata'