function [ countLineSpaceOut, LineSpaceStoreEn, LineVOut ]   = dataReadFSM(...
 hStartIn, hEndIn, vStartIn, vEndIn, validIn)
%#codegen

%% Output writes, LSB is update, MSB is enable.




persistent InFrame; 
persistent InLine;
persistent countLineSpace;
persistent LineOut;


if isempty(InFrame)
InFrame = false;
InLine = false;
countLineSpace = fi(0,0,COUNTVAL,0);
LineOut = false;
LineVOut = false;
Loading = false;
end

Loading = false;
LineSpaceStoreEn = false;


countLineSpaceOut = countLineSpace;
        
       if validIn
        
           if vStartIn
        %%% Start frame
          Loading = true;
          InFrame = true;
          LineSpaceStoreEn = false;
              if hStartIn
        %%% First line
         InFrame = true;
         InLine = true;
         LineSpaceStoreEn = false;
         LineOut = ~LineOut;
              else
                  %coder.internal.warning('video:HDLKernelMemory:vstarthstart');
         InLine  = false;
        end
          elseif InFrame && vEndIn
        %%% End frame
         InFrame  = false;
         LineSpaceStoreEn = false;
          
              if hEndIn
        %%% End line (last line) 
         InLine  = false;
         LineSpaceStoreEn = false;
%          LineOut = true;   
              else
                  %coder.internal.warning('video:HDLKernelMemory:vendhend');
              end
          elseif InFrame && hStartIn &&~InLine
          InLine = true;
            LineSpaceStoreEn = true;
            if LineOut
            LineOut = false;
            else
            LineOut = true;
            end
            
          elseif InFrame && InLine && hEndIn
         %%% End line (within frame)
         InLine  = false;
         LineSpaceStoreEn = false;
         countLineSpace(:) = 0; 
        end
        end

         if InFrame && ~InLine
        countLineSpace(:) = countLineSpace + 1;
        LineSpaceStoreEn = false;
        elseif ~InFrame && (hStartIn || hEndIn)
            %coder.internal.warning('video:HDLKernelMemory:lineoutsideframe');
        end
      
LineVOut(:) = LineOut;






