#!/usr/bin/perl -w
#############################################################################
# Generates the values for the readout orders of registers NTRO and NRRO.
# The values 0-3 correspond to the input ports 0-4. The value 4 represents
# the internal data.
#
# Example usage:  ./ni-order.pl 1 0 4 3
#                 will create the value 0x0001FE21
#
# 12.10.2004  Jan de Cuveland, Rolf Schneider
#############################################################################
use strict;

my $result = 0x0003FFFF;
my $prev = -1;

for (@ARGV) {
  if ($prev == -1) {
    $result = 0x0003FFF8 + $_;
  } else {
    $result = $result & ~(7 << (3 * $prev + 3)) | ($_ << (3 * $prev + 3));
  }
  $prev = $_;
}

printf "0x%08x\n", $result;
