Exemplo n.º 1
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 */
        }
Exemplo n.º 2
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;
                            }
                        }
                }
        }
Exemplo n.º 3
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");
            }
        }
Exemplo n.º 4
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;
                        }
                    }
                }
            }
        }