Пример #1
0
 static void Main(string[] args)
 {
     if (args.Length != 2)
     {
         Console.Error.WriteLine("Usage CleanDeck  n.cbn out.cbn");
         return;
     }
     using (TapeReader r = new TapeReader(args[0], true))
         using (TapeWriter w = new TapeWriter(args[1], true))
         {
             int retval;
             int cnt = 0;
             while ((retval = r.ReadRecord(out bool binary, out byte[] rrecord)) >= 0)
             {
                 cnt++;
                 if (retval == 0)
                 {
                     Console.Error.WriteLine("invalid EOF");
                     return;
                 }
                 if (!binary)
                 {
                     Console.Error.WriteLine("not binary");
                     return;
                 }
                 if (rrecord.Length != 160)
                 {
                     Console.Error.WriteLine("Wrong record length");
                     return;
                 }
                 CBNConverter.FromCBN(rrecord, out Card crd);
                 int i;
                 for (i = 0; i < 24; i++)
                 {
                     if (crd.C[i].LW != 0)
                     {
                         break;
                     }
                 }
                 if (i == 24)
                 {
                     continue; /* blank card */
                 }
                 if (crd.W9L.LW == 0xFFFFFFFFFL)
                 {
                     continue; /* 9L has all ones */
                 }
                 w.WriteRecord(true, rrecord);
             }
         }
 }
Пример #2
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.Error.WriteLine("Usage: ShowCards deck.cbn");
                return;
            }
            int cardno = 0;

            using (TapeReader r = new TapeReader(args[0], true))
            {
                int    rtype;
                string label;
                while ((rtype = r.ReadRecord(out bool binary, out byte[] mrecord)) >= 0)
                {
                    cardno++;
                    if (rtype == 0)
                    {
                        Console.WriteLine("EOF");
                    }
                    else
                    {
                        if (!binary)
                        {
                            Console.Error.WriteLine("not binary record");
                            return;
                        }
                        if (HollerithConverter.CBNToString(mrecord, 72, 8, out label) > 0)
                        {
                            label = "";
                        }
                        CBNConverter.FromCBN(mrecord, out Card crd);
                        for (int i = 0; i < 24; i++)
                        {
                            Console.Write("             {0}", crd.C[i].ToString());
                            if (i == 0)
                            {
                                Console.WriteLine("  Card {0} FUL {1}", cardno, label);
                            }
                            else
                            {
                                Console.WriteLine();
                            }
                        }
                    }
                }
            }
        }
Пример #3
0
        public DeckReader(TapeReader re, List <Card> d) /* constructor */
        {
            /* reads cards in CBN format from tape, and stores them to d */

            transferread = false;
            r            = re;
            deck         = d;
            if (r.ReadRecord(out bool binary, out byte[] mrecord) <= 0) /* read card */
            {
                throw new Exception("last card read");
            }
            CBNConverter.FromCBN(mrecord, out crd);   /* convert */

            t = BinaryCardConverter.GetCardType(crd); /* detect card type */
            n = 0;                                    /* nothing read yet */
            switch (t)                                /* evaluate type */
            {
            case BinaryCardConverter.CardType.Full:
                cur_adr = 0;     /* a full deck start at 0*/
                break;

            case BinaryCardConverter.CardType.Abs:
                cur_adr = (int)crd.W9L.A;     /* read start address */
                break;

            case BinaryCardConverter.CardType.Rel:
                cur_adr = (int)crd.W9L.A;     /* read start address */
                break;

            case BinaryCardConverter.CardType.Transfer:
            case BinaryCardConverter.CardType.RelTransfer:
                break;

            default:
                throw new InvalidDataException("invalid card");
            }
            deck.Add(crd); /* add card to deck */
        }
Пример #4
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.Error.WriteLine("Usage RemoveTransfercard in.cbn[+in2.cbn ...] out.cbn");
                return;
            }
            bool cardtypeset = false;
            bool tfound      = false;
            int  retval      = 0;

            BinaryCardConverter.CardType t0 = BinaryCardConverter.CardType.Full;
            string[] split = args[0].Split(new char[] { '+' });
            using (TapeWriter w = new TapeWriter(args[1], true))
                foreach (string rfile in split)
                {
                    using (TapeReader r = new TapeReader(rfile, true))
                        while ((retval = r.ReadRecord(out bool binary, out byte[] rrecord)) >= 0)
                        {
                            if (retval == 0)
                            {
                                Console.Error.WriteLine("invalid EOF");
                                return;
                            }
                            if (!binary)
                            {
                                Console.Error.WriteLine("not binary");
                                return;
                            }
                            if (rrecord.Length != 160)
                            {
                                Console.Error.WriteLine("Wrong record length");
                                return;
                            }
                            CBNConverter.FromCBN(rrecord, out Card crd);
                            BinaryCardConverter.CardType t = BinaryCardConverter.GetCardType(crd);
                            if (tfound)
                            {
                                Console.Error.WriteLine("Transfercard not at end");
                                return;
                            }
                            switch (t)
                            {
                            case BinaryCardConverter.CardType.Full:
                            case BinaryCardConverter.CardType.Abs:
                            case BinaryCardConverter.CardType.Rel:
                                if (cardtypeset && t0 != t)
                                {
                                    Console.Error.WriteLine("Card type change");
                                    return;
                                }
                                w.WriteRecord(binary, rrecord);
                                break;

                            case BinaryCardConverter.CardType.Transfer:
                                if (cardtypeset && t0 != BinaryCardConverter.CardType.Abs)
                                {
                                    Console.Error.WriteLine("Card type change");
                                    return;
                                }
                                Console.WriteLine("transfercard removed");
                                tfound = true;
                                break;

                            case BinaryCardConverter.CardType.RelTransfer:
                                if (cardtypeset && t0 != BinaryCardConverter.CardType.Rel)
                                {
                                    Console.Error.WriteLine("Card type change");
                                    return;
                                }
                                Console.WriteLine("Rel transfercard removed");
                                tfound = true;
                                break;

                            default:
                                Console.Error.WriteLine("wrong Card type");
                                return;
                            }
                            if (!cardtypeset)
                            {
                                t0          = t;
                                cardtypeset = true;
                            }
                        }
                }
        }
Пример #5
0
        static void Main(string[] args)
        {
            string[] loc1     = new string[] { "9L", "9R", "8L", "8R", "7L", "7R", "6L", "6R", "5L", "5R", "4L", "4R", "3L", "3R", "2L", "2R", "1L", "1R", "0L", "0R", "11L", "11R", "12L", "12R" };
            string[] loc2     = new string[] { "", "A", "T", "D", "P", "M", "S" };
            int[]    startbit = new int[]     { 0, 0, 15, 18, 33, 0, 35 };
            int[]    bitlen   = new[]         { 36, 15, 3, 15, 3, 35, 1 };
            if (args.Length != 3 && args.Length != 2)
            {
                Console.Error.WriteLine("Usage PatchCard location=value,... in.cbn [out.cbn]");
                Console.Error.Write("location is x or xy, where x=9L,9R ... 0L,0R, ... 12L,12R");
                Console.Error.WriteLine(" and y=A,T,D,P,M,S,1,2,...,36");
                Console.Error.WriteLine("value is octal number");
                return;
            }



            byte[] wrecord;
            using (TapeReader r = new TapeReader(args[1], true))
            {
                if (r.ReadRecord(out bool binary, out byte[] rrecord) != 1 || !binary)
                {
                    Console.Error.WriteLine("invalid input file");
                    return;
                }
                if (r.ReadRecord(out bool b2, out byte[] m2) != -1)
                {
                    Console.Error.WriteLine("not a single card file");
                    return;
                }
                CBNConverter.FromCBN(rrecord, out Card C);
                bool     cs   = BinaryCardConverter.VerifyChecksum(C);
                string[] lis1 = args[0].Split(new char[] { ',' });
                foreach (string a0 in lis1)
                {
                    string[] lis = a0.Split(new char[] { '=' });
                    if (lis.Length != 2)
                    {
                        Console.Error.WriteLine("= missing");
                        return;
                    }
                    string loc = lis[0].ToUpper();
                    int    pos = -1;
                    for (int i = 0; i < loc1.Length; i++)
                    {
                        if (loc.Length >= loc1[i].Length && loc.StartsWith(loc1[i]))
                        {
                            pos = i;
                            break;
                        }
                    }
                    if (pos == -1)
                    {
                        Console.Error.WriteLine("wrong location");
                        return;
                    }
                    loc = loc.Substring(loc1[pos].Length);
                    int type = -1;
                    int bpos = 0;
                    int blen = 0;
                    if (loc.Length > 0)
                    {
                        for (int i = 0; i < loc2.Length; i++)
                        {
                            if (loc == loc2[i])
                            {
                                type = i;
                                bpos = startbit[i];
                                blen = bitlen[i];
                                break;
                            }
                        }
                        if (type == -1)
                        {
                            if (!int.TryParse(loc, out int result) || result < 1 || result > 36)
                            {
                                Console.Error.WriteLine("wrong location");
                                return;
                            }
                            bpos = 36 - result;
                            blen = 1;
                        }
                    }
                    long  value = Convert.ToInt64(lis[1], 8);
                    ulong imask = ((1ul << 36) - 1ul) - (((1ul << blen) - 1ul) << bpos);
                    if (value < 0 || value >= (1 << blen))
                    {
                        Console.Error.WriteLine("wrong value");
                        return;
                    }
                    ulong uvalue = (ulong)value << bpos;

                    ulong oldvalue = C.C[pos].LW;
                    C.C[pos].LW = ((C.C[pos].LW & imask) | uvalue);
                    ulong newvalue = C.C[pos].LW;
                    Console.WriteLine("{0} updated from {1} to {2}", loc1[pos], Convert.ToString((long)oldvalue, 8).PadLeft(12, '0'), Convert.ToString((long)newvalue, 8).PadLeft(12, '0'));
                }
                if (cs)
                {
                    BinaryCardConverter.UpdateChecksum(C);
                    Console.WriteLine("Checksum updated");
                }
                wrecord = CBNConverter.ToCBN(C);
                Array.Copy(rrecord, 72 * 2, wrecord, 72 * 2, 8 * 2);
            }
            using (TapeWriter w = new TapeWriter(args[args.Length - 1], true))
                w.WriteRecord(true, wrecord);
        }
Пример #6
0
        public bool Read(out int adr, out long value) /* read  address and word from cards, return false transfercard read, then value=0, adr=transferaddress */
        {
            adr   = 0;
            value = 0;
            if (transferread)
            {
                throw new InvalidOperationException("transfercard alread read");
            }
            switch (t)
            {
            case BinaryCardConverter.CardType.Full:
                if (n == 24)     /* all words already read? */
                {
                    /* get next card */
                    if (r.ReadRecord(out bool binary, out byte[] mrecord) <= 0)
                    {
                        throw new Exception("last card read");
                    }

                    /* convert */
                    CBNConverter.FromCBN(mrecord, out crd);
                    deck.Add(crd);                               /* add to deck */
                    BinaryCardConverter.CardType tt = BinaryCardConverter.GetCardType(crd);
                    if (tt != BinaryCardConverter.CardType.Full) /* check card type */
                    {
                        Console.WriteLine("invalid card type {0})", tt);
                    }
                    n = 0;                 /* nothing read yet */
                }
                adr   = cur_adr;           /* get address */
                value = (long)crd.C[n].LW; /* get word */
                /* count  */
                n++;
                cur_adr++;
                return(true);    /* word from card read */

            case BinaryCardConverter.CardType.Abs:
                if (n == crd.W9L.D)                                             /* all words already read? */
                {
                    if (r.ReadRecord(out bool binary, out byte[] mrecord) <= 0) /* get next card */
                    {
                        throw new Exception("last card read");
                    }
                    CBNConverter.FromCBN(mrecord, out crd);                                 /* convert */
                    deck.Add(crd);                                                          /* add to deck */
                    BinaryCardConverter.CardType nt = BinaryCardConverter.GetCardType(crd); /* check card type */
                    if (nt == BinaryCardConverter.CardType.Transfer)                        /* transfercard ? */
                    {
                        adr          = (int)crd.W9L.A;                                      /* get transfer address */
                        value        = 0;                                                   /*  0 for transfercard */
                        transferread = true;                                                /* set flag */
                        return(false);                                                      /* transfercard read */
                    }
                    if (nt != t)                                                            /* type changed ?*/
                    {
                        throw new Exception("invalid card type");
                    }
                    n       = 0;               /* reset word counter */
                    cur_adr = (int)crd.W9L.A;  /* set address */
                }
                adr   = cur_adr;               /* get address */
                value = (long)crd.C[n + 2].LW; /* get word */
                n++;                           /* count */
                cur_adr++;
                return(true);                  /* word from card read */

            case BinaryCardConverter.CardType.Rel:
                if (n == crd.W9L.D)                                             /* all words already read? */
                {
                    if (r.ReadRecord(out bool binary, out byte[] mrecord) <= 0) /* get next card */
                    {
                        throw new Exception("last card read");
                    }
                    CBNConverter.FromCBN(mrecord, out crd);                                 /* convert */
                    deck.Add(crd);                                                          /* add to deck */
                    BinaryCardConverter.CardType nt = BinaryCardConverter.GetCardType(crd); /* check card type */
                    if (nt == BinaryCardConverter.CardType.RelTransfer)                     /* transfercard ? */
                    {
                        adr          = (int)crd.W9L.A;                                      /* get transfer address */
                        value        = 0;                                                   /*  0 for transfercard */
                        transferread = true;                                                /* set flag */
                        return(false);                                                      /* transfercard read */
                    }
                    if (nt != t)                                                            /* type changed ?*/
                    {
                        throw new Exception("invalid card type");
                    }
                    n       = 0;               /* reset word counter */
                    cur_adr = (int)crd.W9L.A;  /* set address */
                }
                adr   = cur_adr;               /* get address */
                value = (long)crd.C[n + 4].LW; /* get word */
                n++;                           /* count */
                cur_adr++;
                return(true);                  /* word from card read */

            case BinaryCardConverter.CardType.Transfer:
            case BinaryCardConverter.CardType.RelTransfer:
            {
                adr          = (int)crd.W9L.A; /* get transfer address */
                value        = 0;              /*  0 for transfercard */
                transferread = true;           /* set flag */
                return(false);                 /* transfercard read */
            }

            default:
                throw new InvalidDataException("invalid card");
            }
        }
Пример #7
0
        public void END(int?TransferAdr)
        {
            char tch = ' ';

            if (TransferAdr != null && dr == null)
            {
                deck = new List <Card>();
                dr   = new DeckReader(tr, deck);
                if (hadnoorg)
                {
                    startline = thisline;
                    startpage = thispage;
                }
            }
            if (dr != null)
            {
                if (dr.Cardtype() == 'R')
                {
                    TransferAdr = 0;
                }
                if ((TransferAdr != null && (!hadnoorg || TransferAdr != 0)))
                {
                    if (dr.Read(out int adr, out long value))
                    {
                        Console.WriteLine("Difference {0} {1}", thispage, thisline);
                        Console.WriteLine("Card {0} {1}", Convert.ToString(adr, 8).PadLeft(5, '0'), Convert.ToString(value, 8).PadLeft(12, '0'));
                        Console.WriteLine("List Transfer {0}", Convert.ToString((int)TransferAdr, 8).PadLeft(5, '0'));
                        Environment.Exit(-1);
                    }
                    else if (adr != TransferAdr)
                    {
                        Console.WriteLine("Difference {0} {1}", thispage, thisline);
                        Console.WriteLine("Card Transfer {0}", Convert.ToString(adr, 8).PadLeft(5, '0'));
                        Console.WriteLine("List Transfer {0}", Convert.ToString((int)TransferAdr, 8).PadLeft(5, '0'));
                        Environment.Exit(-1);
                    }
                    if (dr.Cardtype() != 'T')
                    {
                        tch = 'T';
                    }
                }
                if (!dr.CardEmpty())
                {
                    Console.WriteLine("Difference {0} {1}", thispage, thisline);
                    Console.WriteLine("more data on card");
                    Environment.Exit(-1);
                }
                string x = "";
                if (startpage != 0)
                {
                    x += string.Format("Page{0}", startpage);
                }
                x += string.Format("Line{0}", startline);
                x += "_";
                x += dr.Cardtype();
                if (tch != ' ')
                {
                    x += tch;
                }
                Console.Write("{0}:{1} {2} {3} {4}\n", x, deck.Count, Convert.ToString(FirstAdr, 8).PadLeft(5, '0'), Convert.ToString(LastAdr, 8).PadLeft(5, '0'), TransferAdr != null ? Convert.ToString((int)TransferAdr, 8).PadLeft(5, '0') : "");
                using (TapeWriter tw = new TapeWriter(out_p + x + ".cbn", true))
                    foreach (Card crd in deck)
                    {
                        tw.WriteRecord(true, CBNConverter.ToCBN(crd));
                    }
                deck.Clear();
                dr = null;
            }
            curadr   = 0;
            bssflag  = false;
            hadnoorg = true;

            FirstAdr = 1000000;
            LastAdr  = -1000000;
        }
Пример #8
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.Error.WriteLine("Usage: ShowCards deck.cbn");
                return;
            }
            int cardno = 0;

            using (TapeReader r = new TapeReader(args[0], true))
            {
                int    rtype;
                string label;
                while ((rtype = r.ReadRecord(out bool binary, out byte[] mrecord)) >= 0)
                {
                    cardno++;
                    if (rtype == 0)
                    {
                        Console.WriteLine("EOF");
                    }
                    else
                    {
                        if (!binary)
                        {
                            Console.Error.WriteLine("not binary record");
                            return;
                        }
                        if (HollerithConverter.CBNToString(mrecord, 72, 8, out label) > 0)
                        {
                            label = "";
                        }
                        CBNConverter.FromCBN(mrecord, out Card crd);
                        BinaryCardConverter.CardType t = BinaryCardConverter.GetCardType(crd);
                        switch (t)
                        {
                        case BinaryCardConverter.CardType.Full:
                            for (int i = 0; i < 24; i++)
                            {
                                Console.Write("             {0}", crd.C[i].ToString());
                                if (i == 0)
                                {
                                    Console.WriteLine("  Card {0} FUL {1}", cardno, label);
                                }
                                else
                                {
                                    Console.WriteLine();
                                }
                            }
                            break;

                        case BinaryCardConverter.CardType.Abs:
                            for (int i = 0; i < crd.W9L.D; i++)
                            {
                                Console.Write("       {0} {1}", Convert.ToString(crd.W9L.A + i, 8).PadLeft(5, '0'), crd.C[i + 2].ToString());
                                if (i == 0)
                                {
                                    Console.WriteLine(" Card {0} ABS {1}", cardno, label);
                                }
                                else
                                {
                                    Console.WriteLine();
                                }
                            }
                            break;

                        case BinaryCardConverter.CardType.Rel:
                            BinaryCardConverter.RelType[] rel = BinaryCardConverter.GetRelData(crd);
                            for (int i = 0; i < crd.W9L.D; i++)
                            {
                                char rd = ' ', ra = ' ';
                                switch (rel[i * 2])
                                {
                                case BinaryCardConverter.RelType.absolute:
                                    rd = ' ';
                                    break;

                                case BinaryCardConverter.RelType.relocatable_direct:
                                    rd = 'R';
                                    break;

                                case BinaryCardConverter.RelType.relocatable_complemented:
                                    rd = 'C';
                                    break;
                                }
                                switch (rel[i * 2 + 1])
                                {
                                case BinaryCardConverter.RelType.absolute:
                                    ra = ' ';
                                    break;

                                case BinaryCardConverter.RelType.relocatable_direct:
                                    ra = 'R';
                                    break;

                                case BinaryCardConverter.RelType.relocatable_complemented:
                                    ra = 'C';
                                    break;
                                }
                                Console.Write("   {0} {1} {2} {3}", rd, ra, Convert.ToString(crd.W9L.A + i, 8).PadLeft(5, '0'), crd.C[i + 4].ToString());
                                if (i == 0)
                                {
                                    Console.WriteLine(" Card {0} REL {1}", cardno, label);
                                }
                                else
                                {
                                    Console.WriteLine();
                                }
                            }
                            break;

                        case BinaryCardConverter.CardType.Transfer:
                            Console.WriteLine("               TRANSFER {0} Card {1} ABS {2}", Convert.ToString(crd.W9L.A, 8).PadLeft(5, '0'), cardno, label);
                            break;

                        case BinaryCardConverter.CardType.RelTransfer:
                            Console.WriteLine("               TRANSFER {0} Card {1} REL {2}", Convert.ToString(crd.W9L.A, 8).PadLeft(5, '0'), cardno, label);
                            break;

                        default:
                            Console.Error.WriteLine("Invalid Card Type");
                            return;
                        }
                    }
                }
            }
        }