function tclcmd = mixedmanchestercmds(varargin)
% MIXEDMANCHESTERCMDS - Creates Tcl commands for Mixed Manchester Model
%   The returned cell array can be passed as parameters ('cmd') to
%   VSIMULINK.  This will launch ModelSim, build the VHDL design and 
%   also has the commands for cosimulation with MIXEDMANCHESTERMODEL.MDL
%
%   MIXEDMANCHESTERCMDS(Property,Value)
%   
%   Property :
%
%   'ProjDir'- Specify where to run the HDL simulator.  If unspecified, the
%        'TEMPDIR', a temporary directory will be created in which the HDL
%        simulator will run. 
%
%   Examples:
%   1. After opening mixedmanchester.mdl in Shared mode type the following
%   command in the MATLAB command window.
%   >>vsim('tclstart',mixedmanchestercmds)    "or"
%   >>vsim('tclstart',mixedmanchestercmds('ProjDir','c:\tmp\'))
%
%   See also VSIMULINK

%   Copyright 2003-2009 The MathWorks, Inc.
%
p = inputParser;              % Creating an instance of inputParser class.
p.addOptional('ProjDir','');  % This creates an optional parameter-value pair.
p.parse(varargin{:});         % Calling the parse method of the object to read and validate each argument.
projdir = p.Results.ProjDir;  % Saving ProjDir parameter value to projdir.

srcfile1 = fullfile(matlabroot,'toolbox','edalink','extensions','modelsim','modelsimdemos','vlog','manchester','statecnt.v');
srcfile2 = fullfile(matlabroot,'toolbox','edalink','extensions','modelsim','modelsimdemos','vlog','manchester','iqconv.v');
srcfile3 = fullfile(matlabroot,'toolbox','edalink','extensions','modelsim','modelsimdemos','vlog','manchester','decoder.v');
srcfile4 = fullfile(matlabroot,'toolbox','edalink','extensions','modelsim','modelsimdemos','vhdl','manchester','manchester.vhd');

unixsrcfile1 = ['"' strrep(srcfile1,'\','/') '"']; 
unixsrcfile2 = ['"' strrep(srcfile2,'\','/') '"']; 
unixsrcfile3 = ['"' strrep(srcfile3,'\','/') '"']; 
unixsrcfile4 = ['"' strrep(srcfile4,'\','/') '"']; 

if isempty(projdir)
    if strcmp(computer,'PCWIN'),
        projdir = tempdir;
    else
        projdir = tempname;
        mkdir(tempdir,strrep(projdir,tempdir,''));
    end
end
unixprojdir = strrep(projdir,'\','/'); 

tclcmd = { 
           ['cd ',unixprojdir],...            
            'vlib work',... %create library (if necessary)
           ['vlog ' unixsrcfile1],...
           ['vlog ' unixsrcfile2],...
           ['vlog ' unixsrcfile3],...           
           ['vcom -performdefaultbinding ' unixsrcfile4],...           
           'vsimulink  work.manchester' ...
           % originally done here, but moved to Tcl before 
           % 'force sim:/manchester/enable 1 0',...  
           % 'force sim:/manchester/reset 1 0, 0 1000 ns',...
         };
