new :: StdGen -> ST s (Memory s)
new rndGen = do
    memory' <- newArray (0x000, 0xFFF) 0
    registers' <- newArray (0x0, 0xF) 0
    registerI' <- newSTRef 0
    delayTimer' <- newSTRef 0
    soundTimer' <- newSTRef 0
    pc' <- newSTRef 0x200
    sp' <- newSTRef 0
    stack' <- newArray (0x0, 0xF) 0
    eventState' <- newEventState
    videoMemory' <- newVideoMemory
    stdGen' <- newSTRef rndGen
    foldM_ (\a x -> do -- load font
            writeArray memory' a x
            return $ a + 1
           ) 0 font
    return Memory { memory = memory'
                  , registers = registers'
                  , registerI = registerI'
                  , delayTimer = delayTimer'
                  , soundTimer = soundTimer'
                  , pc = pc'
                  , sp = sp'
                  , stack = stack'
                  , eventState = eventState'
                  , videoMemory = videoMemory'
                  , stdGen = stdGen'
                  }
new :: StdGen -> ST s (Memory s)
new rndGen = do
    memory' <- newArray (0x000, 0xFFF) 0
    registers' <- newArray (0x0, 0xF) 0
    registerI' <- newSTRef 0
    delayTimer' <- newSTRef 0
    soundTimer' <- newSTRef 0
    pc' <- newSTRef 0x200
    sp' <- newSTRef 0
    stack' <- newArray (0x0, 0xF) 0
    eventState' <- newEventState
    videoMemory' <- newVideoMemory
    stdGen' <- newSTRef rndGen
    foldM_ (\a x -> do -- load font
            writeArray memory' a x
            return $ a + 1
           ) 0 font
    return Memory { memory = memory'
                  , registers = registers'
                  , registerI = registerI'
                  , delayTimer = delayTimer'
                  , soundTimer = soundTimer'
                  , pc = pc'
                  , sp = sp'
                  , stack = stack'
                  , eventState = eventState'
                  , videoMemory = videoMemory'
                  , stdGen = stdGen'
                  }
new rndGen = do
    memory' <- newArray (0x000, 0xFFF) 0
    registers' <- newArray (0x0, 0xF) 0
    registerI' <- newSTRef 0
    delayTimer' <- newSTRef 0
    soundTimer' <- newSTRef 0
    pc' <- newSTRef 0x200
    sp' <- newSTRef 0
    stack' <- newArray (0x0, 0xF) 0
    eventState' <- newEventState
    videoMemory' <- newVideoMemory
    stdGen' <- newSTRef rndGen
    foldM_ (\a x -> do -- load font
            writeArray memory' a x
            return $ a + 1
           ) 0 font
    return Memory { memory = memory'
                  , registers = registers'
                  , registerI = registerI'
                  , delayTimer = delayTimer'
                  , soundTimer = soundTimer'
                  , pc = pc'
                  , sp = sp'
                  , stack = stack'
                  , eventState = eventState'
                  , videoMemory = videoMemory'
                  , stdGen = stdGen'
                  }