static void Main(string[] args) { if (args.Length != 2) { Console.Error.WriteLine("Usage: Tp2p7b input.tap output.tap"); return; } using (TapeReader r = new TapeReader(args[0], false)) using (TapeWriter w = new TapeWriter(args[1], true)) { int ret; while ((ret = r.ReadRecord(out bool binary, out byte[] mrecord)) >= 0) { if (ret == 0) { Console.WriteLine("Eof"); } else { Console.WriteLine("{0} record, length {1}", binary ? "binary" : "BCD", mrecord.Length); } if (ret == 0) { w.WriteEOF(); } else { w.WriteRecord(binary, mrecord); } } } return; }
static void Main(string[] args) { if (args.Length != 1) { Console.Error.WriteLine("Usage: ShowHCards input.cbn"); return; } using (TapeReader r = new TapeReader(args[0], true)) { int ret; while ((ret = r.ReadRecord(out bool binary, out byte[] mrecord)) >= 0) { if (ret == 0) { Console.WriteLine("\\Eof\\"); } else { if (mrecord.Length != 160 || !binary) { Console.Error.WriteLine("\\invalid {0} record with length={1}\\", binary?"binary":"BCD", mrecord.Length); } else { HollerithConverter.CBNToString(mrecord, 0, 80, out string s); Console.WriteLine(s.TrimEnd()); } } } } }
static void Main(string[] args) { if (args.Length > 2 || args.Length == 0) { Console.Error.WriteLine("Usage: ShowTape Tape.tap [linelength]"); return; } int lenght = -1; if (args.Length == 2) { if (!int.TryParse(args[1], out lenght)) { Console.Error.WriteLine("wrong linelength"); return; } } using (TapeReader r = new TapeReader(args[0], true)) { int rtype; while ((rtype = r.ReadRecord(out bool binary, out byte[] mrecord)) >= 0) { if (rtype == 0) { Printskipped(); Console.WriteLine("\\Eof\\"); } else if (binary) { numbin++; } else { Printskipped(); string line = BcdConverter.BcdToString(mrecord); if (lenght <= 0) { Console.WriteLine(line.TrimEnd()); } else { for (int i = 0; i < line.Length; i += lenght) { if (i + lenght < line.Length) { Console.WriteLine(line.Substring(i, lenght).TrimEnd()); } else { Console.WriteLine(line.Substring(i).TrimEnd()); } } } } } Printskipped(); } }
static void Main(string[] args) { if (args.Length != 1) { Console.Error.WriteLine("Usage: ShowBTape Tape.tap "); return; } using (TapeReader r = new TapeReader(args[0], true)) { int rtype; int file = 1; int record = 1; while ((rtype = r.ReadRecord(out bool binary, out byte[] mrecord)) >= 0) { if (rtype == 0) { Printskipped(); Console.WriteLine("\\Eof\\"); file++; record = 1; } else if (!binary) { numbcd++; } else { Printskipped(); for (int i = 0; i < mrecord.Length; i += 6) { Console.Write(" "); ulong x = 0; for (int j = i; j < i + 6; j++) { x <<= 6; if (j < mrecord.Length) { x |= mrecord[j]; } } W704 WRD = new W704 { LW = x }; Console.Write(" {0} {1}", Convert.ToString(i / 6, 8).PadLeft(5, '0'), WRD.ToString()); if (i == 0) { Console.Write(" File {0} Record {1}", file, record); } Console.WriteLine(); } } record++; } Printskipped(); } }
public Lister(TapeReader tp, string o) { tr = tp; dr = null; deck = new List <Card>(); hadnoorg = true; out_p = o; FirstAdr = 1000000; LastAdr = -1000000; }
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); } } }
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(); } } } } } }
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 */ }
static void Main(string[] args) { if (args.Length != 2) { Console.Error.WriteLine("Usage: CopyCards in.cbn[+in2.cbn ...] out.cbn"); return; } int retval = 0; string[] split = args[0].Split(new char[] { '+' }); using (TapeWriter w = new TapeWriter(args[1], true)) foreach (string rfile in split) { Console.WriteLine(rfile); 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 record"); return; } if (rrecord.Length != 160) { Console.Error.WriteLine("wrong record length"); return; } w.WriteRecord(binary, rrecord); } } Console.WriteLine(" {0} written", args[1]); }
static void Main(string[] args) { byte[] trecord = new byte[160]; if (args.Length != 2) { Console.Error.WriteLine("Usage: TapeExtract tapefile dir"); } string tape = args[0]; string dir = args[1] + "\\"; int count = 0; bool eof = false; using (StreamWriter tx = new StreamWriter(dir + "index.txt")) using (TapeReader r = new TapeReader(tape, true)) { rd = r; while (!eof && GetRecord(out bool binary, out byte[] mrecord) == 1) { if (binary || (mrecord.Length != 80 && mrecord.Length != 84)) { throw new Exception("wrong Control card"); } string descr = BcdConverter.BcdToString(mrecord).Substring(0, 80); tx.WriteLine(descr.TrimEnd()); descr = descr.Replace('/', '_'); descr = descr.Replace('.', '_'); descr = descr.Replace('+', '_'); string filename; if (descr[5] == ' ') { filename = dir + descr.Substring(3, 2).Trim() + "_" + descr.Substring(6, 5).Trim(); } else { filename = dir + descr.Substring(3, 8).Trim(); } filename += "_" + descr.Substring(20, 4).Trim() + "." + descr.Substring(33, 2).Trim(); using (TapeWriter wr = new TapeWriter(filename, true)) { bool lastrecord = false; do { int ret = GetRecord(out binary, out mrecord); if (ret != 1) { eof = true; lastrecord = true; } else { if (binary) { Deblock(mrecord, 160, out byte[][] orecord); if (orecord != null) { for (int i = 0; i < orecord.Length; i++) { wr.WriteRecord(true, orecord[i]); count++; } } } else { if (mrecord.Length == 80 || mrecord.Length == 84) { UngetRecord(binary, mrecord); lastrecord = true; } else { Deblock(mrecord, 80, out byte[][] orecord); if (orecord != null) { for (int i = 0; i < orecord.Length; i++) { HollerithConverter.BCDToCBN(orecord[i], 0, trecord); wr.WriteRecord(true, trecord); count++; } } } } } }while (!lastrecord); } } rd = null; } Console.WriteLine("{0} cards written", count); }
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; } } } }
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); }
static void Main(string[] args) { string[] skipine = new string[] { "0SHARE ASSEMBLER STATISTICS", "0TAPE TOTAL", " INP", " LIB", " COL", "0NUMBER OF ON-LINE INPUT RECORDS", "0NUMBER OF OFF-LINE PRINT RECORDS", "0NUMBER OF SYMBOLS" }; int skipline = 0; bool isadr; if (args.Length != 3) { Console.Error.WriteLine("Usage: SapSplit input.lst input.cbn output_dir"); return; } using (StreamReader r = new StreamReader(args[0])) using (TapeReader d = new TapeReader(args[1], true)) { Lister L = new Lister(d, args[2]); while (!r.EndOfStream) { string line = r.ReadLine().PadRight(114); if (line.Length > 120 && line.Substring(120, 4) == "Page") { L.Setpage(int.Parse(line.Substring(125))); } else { L.Nextline(); } if (skipline > 0) { if (!line.StartsWith(skipine[8 - skipline])) { throw new Exception("invalid line"); } skipline--; continue; } if (line.StartsWith(skipine[0])) { skipline = 7; continue; } if (line.Substring(6).StartsWith(" ")) { isadr = true; for (int i = 24; i <= 28; i++) { if (line[i] < '0' || line[i] > '7') { isadr = false; break; } } if (isadr) { int adr = Convert.ToInt32(line.Substring(24, 5), 8); switch (line.Substring(37, 3)) { case "ORG": L.ORG(adr); break; case "BES": L.BES(adr); break; case "BSS": L.BSS(adr); break; case "END": if (line[41] != ' ') { L.END(adr); } else { L.END(null); } break; } } } else { isadr = true; for (int i = 7; i <= 11; i++) { if (line[i] < '0' || line[i] > '7') { isadr = false; break; } } if (isadr) { bool uflag = line[1] == 'U'; int adr = Convert.ToInt32(line.Substring(7, 5), 8); bool neg = line[13] == '-'; if (line[15] == ' ' && line[21] == ' ' && line[23] == ' ') { line = line[14] + line.Substring(16, 5) + line[22] + line.Substring(24, 5); } else { line = line.Substring(14, 12); } if (uflag) { line = line.Replace(' ', '0'); } long val = Convert.ToInt64(line, 8); if (neg) { val |= 0x800000000L; } L.Putval(adr, val); } } } L.END(null); } }
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; } } } } }