Exemple #1
0
        public int ReadRecord(out bool binary, out byte[] mrecord) /* reads a record as array of 6-bit value from tape-file, retun -1:ende of input file 0: EOF marker read, 1: record read; binary=true: binary record false: bcd record */
        {
            int b;                                                 /* current character */

            mrecord = null;
            binary  = false;

            if (stored)        /* fist byte of record already read? */
            {
                b      = last; /* use it */
                stored = false;
            }
            else
            {
                b = f.ReadByte();        /* read byte */
            }
            if (b < 0)                   /* end of media ? */
            {
                return(-1);              /* EOM */
            }
            recpos.Push(f.Position - 1); /* store startposition of record for backspace*/
            if ((b & 128) == 0)          /* The first byte of a records must have bit 7 set */
            {
                throw new InvalidDataException("TapeFile:Bit 7 not set at record start");
            }
            List <byte> trecord = new List <byte>()
            {
                (byte)(b & 127)
            };                                                         /* remove record start marker, store character */

            do
            {
                b = f.ReadByte();
                if (b < 0 || (b & 128) != 0) /* next record or EOF */
                {
                    stored = true;           /* set flag */
                    last   = b;              /* store value for next call*/
                    break;
                }
                trecord.Add((byte)b);
            }while (true);
            TapeConverter.FromTape(trecord.ToArray(), out binary, out mrecord);
            if (!binary && mrecord.Length == 1 && mrecord[0] == 15)
            {
                return(0); /* EOF */
            }
            return(1);     /* no EOF */
        }
Exemple #2
0
 public void WriteRecord(bool binary, byte[] mrecord)
 {
     if (stored && last != -1)
     {
         f.Seek(-1, SeekOrigin.Current);
     }
     stored = false;
     TapeConverter.ToTape(binary, mrecord, out byte[] trecord);
     recpos.Push(f.Position);
     trecord[0] |= 0x80;          /* add record marker */
     f.Write(trecord, 0, trecord.Length);
     if (f.Position != f.Length)  /* not at end of file? */
     {
         f.SetLength(f.Position); /* cut remaining parts */
     }
 }
Exemple #3
0
 public void WriteRecord(bool binary, byte[] mrecord)
 {
     if (stored && last != -1)           /* first byte of record already read ? */
     {
         f.Seek(-1, SeekOrigin.Current); /* go back to start of record */
     }
     stored = false;
     TapeConverter.ToTape(binary, mrecord, out byte[] trecord); /* convert to tape format, generate parity */
     recpos.Push(f.Position);                                   /* store startpos of record on stack */
     trecord[0] |= 0x80;                                        /* add record marker */
     f.Write(trecord, 0, trecord.Length);
     if (f.Position != f.Length)                                /* currently not at end of the tape-file? */
     {
         f.SetLength(f.Position);                               /* cut remaining parts of the file */
     }
 }