% testgen.m
%
% Matlab script for generating irsim test vectors.
%
% 2007/05/30  Written  (BB)
% 2020/11/24  real2twos replaced by dec2bin (Ziyuan)

%===== Set these
NumValues       = 100;
ModeValues      = 1;            % 0:reverse-order 99-00, 1:random order,
                                %    00-49 and 78-127
ModeOutput      = 1;            % print to screen if 1
FileNameOut     = 'test.cmd';

%===== Prep things
clear data;

% output to screen or file
if ModeOutput == 1
  Fid = 1;
else
  Fid = fopen(FileNameOut, 'w');
end

%===== Generate values
%data = rand(1, NumValues);
%data = floor(data*127.99);

if ModeValues == 0
  data = [(NumValues-1):-1:0];

elseif ModeValues == 1
  data = [0:49 78:127];
  for k=1:NumValues*10;                           % 10 is arbitrary
    a = floor(rand(1,1) * (NumValues-0.01)) + 1;  % generate random pointer
    b = floor(rand(1,1) * (NumValues-0.01)) + 1;  % generate random pointer
    temp        = data(a);                        % swap them
    data(a)     = data(b);                        % swap them
    data(b)     = temp;                           % swap them
  end

else
  fprintf(1, 'Error: invalid ModeValues\n');
  return;
end

%plot(data);  return;    % check data

%===== Print commands

% ADD RESET

% print out lots of single-clock commands
fprintf(Fid, '| Begin entering data into processor array\n');
for k=1:(NumValues),
  fprintf(Fid, '| data(%i) = %i\n', k, data(k));
  % real2twos replaced by dec2bin
  fprintf(Fid, 'chip_in_data = %s\n', dec2bin(data(k), 8, 0));
  fprintf(Fid, '1clk\n');
  fprintf(Fid, '\n');
end

% print out lots of single-clock commands
fprintf(Fid, '| Begin clocks to push data through processor array\n');
for k=1:(NumValues+5),
  fprintf(Fid, '1clk\n');
end

