A/WRITETAPE/A                       Date.   7.7.52 

    Purpose: To punching writing tapes using the
             warning character K for punching proper.
             specified by false cues leading to directory
             lines in 33L.  
             
    Cue: $ E W G : E E Z
          
    Principal lines: [/E] = @ / / :
                     [/A] = V S T A
             
    Magnetic Storage: variable     Electronic Storage: S0 S1
    
    Stores Altered: /K EK AK :K B2 B2 B3 B4 B5
    
    Effects: This routine punches the punching proper to 
             create a writing tape. 
    
             steering tape: (=input tape)
    
                  C C C C ....
                  Q S WRITE
                  K A K @ destination_sequence        
                  K V S @ $ E W G : E E Z
                  Y
                  Q title
                  Y
                  
              Will generate this writing tape:
    
                  ///////////// ... 
 		  CCCCCC ...
                  Q title                              
                  //// KAK@ des1 des2 KPK@ chk1 chk2   
                  K/#T
                  dat0 dat1 dat2 dat3 dat4 dat5 dat6 dat7
                  dat8 dat9 da10 da11 da12 da13 da14 da15
                  KT#T
                  da16 da17 da18 da19 da20 da21 da22 da23
                  da24 da25 da26 da27 da28 da29 da30 da31
                  K/DT
                  da32 da33 da34 da35 da36 da37 da38 da39
                  da40 da41 da42 da43 da44 da45 da46 da47
                  KTDT
                  da48 da49 da50 da50 da51 da53 da54 da55
                  da56 da57 da58 da59 da60 da61 da62 da63
                  //// Z/// $$$$ $$$$ //// //// //// ////

             
    Library Progs - Bodleian Special Collection 
    MS. Eng. misc. b. 260-C.43.pdf
    p99

    NOTE by Roberto Sancho: 

    The explanations on Programmers handbook are quite confusing. 
    Lets sumarize here that this routine do.
    
    The purpose of WRITETAPE is to *DUMP* a given half track from 
    drum to a punched tape. This punched is called a "writing tape". 

    The writing tape contains
	- a title that will be printed when processing the tape
	- The destination sequence to store the data back on 
          original drum's half track (from which it was dumped)
        - a checksum of data  
        - 64 words of data for the half track

    To restore the data back from tape back to drum, the routine 
    WRITE should be used

    
    [Routine WRITETAPE/A               ]  
    
    [Col /          E ]                   [Col @          A ]                     
                                                                                  
    | E//: | / | @//: |                   | /KTA | / | VSTA |                                             
    | ///: | E | MK/A |                   | H//: | E | F:QO |                     
    | VSTA | @ | E:LG |                   | J:QO | @ | A:QG |                                            
    | H//: | A | P//T |                   | N//: | A | /#QC |                                            
    | Z:WO | : | I//: |                   | ://: | : | A:QG |                                            
    | V:/C | S | E:HG |                   | E:QG | S | ME/O |                                            
    | $EZO | I | $//T |                   | /@/: | I | "ETA |                                            
    | VET/ | U | E:YG |                   | ME/O | U | BEQO |                     
    | GK/S | # | A//T |                   | U:QO | # | AKT/ |                                            
    | VKTA | D | GKT/ |                   | H@/J | D | OETA |                                            
    | N//: | R | W:TC |                   | OE/H | R | FEQB |                                            
    | ://: | J | E:ZG |                   | AKT/ | J | CAWO |                     
    | $ELO | N | K//T |                   | VSTA | N | U:HO |                     
    | VK/N | F | NS/P |                   | "EQO | F | WA/P |                     
    | VK/A | C | Z/// |                   | LSQB | C | PE// |                     
    | U//I | K | V:/C |                   | NS/P | K | LAQO |                     
    | @//: | T | /:ZO |                   | DA// | T | FEQB |                     
    | MK/A | Z | /:YO |                   | VST/ | Z | A:/P |                     
    | E:LG | L | WE/P |                   | VATR | L | KA/P |                     
    | R//T | W | Y/// |                   | @KTJ | W | CEQO |                     
 (*)| E:YO | H |      |                   | VKTA | H | QEQB |                     
    | U:HO | Y |      |                   | X:/C | Y | DST/ |                     
    | M//: | P | //// |                   | $S/N | P | OETA |                                        
    | ://: | Q | KAK@ |                   | H:TR | Q | GETA |                                        
    | E:HG | O | @@// |                   | VKTJ | O | META |                                        
    | //W/ | B | JA/P |                   | VKTA | B | K@QO |                                        
    | VKTA | G | KPK@ |                   | $K/: | G | T@/P |                                        
    | DSWG | " | GA/P |                   | VA/: | " |      |                                        
    | $ELO | M | X$$$ |                   | /KT/ | M | $@WG |                     
    | VK/N | X | Y/// |                   | VSTA | X | :EEZ |                     
    | VK/A | V | K/#T |                   | MAT/ | V | E//: |                     
    | O//I | $ | A/// |                   | NS/P | $ | $$E/ |                     
                                                                                  
    Tape: WRITETAPE A ONE                 Tape: WRITETAPE A TWO                   
    Destination Sequence: KAK@///#:EEZ    Destination Sequence: KAK@//E#:EEZ      
          
    [End]

    Note: on original listing, there was a typo on instruction 
    marked with (*): It was E:YP that references instruction TP
    that is not defined. After some debugging, the correct
    instruction is identified as E:YO (B5=1)
    

    
    0  //  E//:   
    1  E/  ///:   
    2  @/  VSTA   
    3  A/  H//:   Printer set letter shift
    4  :/  Z:WO   B3=256 
    5  S/  V:/C   D=//// ///E
    6  I/  $EZO   B1=3
    7  U/  VET/   
    8  #/  GK/S   
    9  D/  VKTA   
   10  R/  N//:   Print <cr>
   11  J/  ://:   Print <lf>
   12  N/  $ELO   B2=3
   13  F/  VK/N   
   14  C/  VK/A   
   15  K/  U//I   
   16  T/  @//:   Print char
   17  Z/  MK/A   
   18  L/  E:LG   decr B2
   19  W/  R//T   if (B2>=0) goto 13 -> print 4 chars
   20  H/  E:YP   changed to be B5=1 (E:YO)  
   21  Y/  U:HO   B4=8 
 
   22  P/  M//:   Print <cr>
   23  Q/  ://:   print <lf>
   24  O/  E:HG   decr B4 <- num of data values in KAK line remaining to be issued
   25  B/  //W/   A=[B3]=//// KAK@
   26  G/  VKTA   [VK]=AL
   27  "/  DSWG   incr B3 
   28  M/  $ELO   B2=3 -> chars to print form A
   29  X/  VK/N   Shift -> AM=///K AK@/
   30  V/  VK/A   [VK]=AM, AM=0
   31  $/  O//I   AL<->AM        
                  
   32  /E  @//:   Print char
   33  EE  MK/A   
   34  @E  E:LG   decr B2
   35  AE  P//T   if (B2>=0) goto 29 -> print 4 chars
   36  :E  I//:   Print space
   37  SE  E:HG   decr B4
   38  IE  $//T   if (B4>=0) goto 25 -> print 8 values
   39  UE  E:YG   decr B5
   40  #E  A//T   if (B5>=0) goto 
   41  DE  GKT/   AL=[GK]
   42  RE  W:TC   A=A+/T// ////
   43  JE  E:ZG   decr B1
   44  NE  K//T   if (B1>=0) goto 8
   45  FE  NS/P   goto 111
   46  CE  Z///   

   47  KE  V:/C   D=//// ///E
   48  TE  /:ZO   B1=0 
   49  ZE  /:YO   B5=0
   50  LE  WE/P   goto 22

   51  WE  Y///   
   52  HE         
   53  YE         
   54  PE  ////   
   55  QE  KAK@   
   56  OE  @@//   
   57  BE  JA/P   
   58  GE  KPK@   
   59  "E  GA/P   
   60  ME  X$$$   
   61  XE  Y///   
   62  VE  K/#T   
   63  $E  A///       
                  
   64  /@  /KTA   Entry: Save link in [/K]=AL
   65  E@  H//:   Printer set letter shift
   66  @@  J:QO   B7=32
   67  A@  N//:   Print <CR>
   68  :@  ://:   Print <LF>
   69  S@  E:QG   decr B7 - print 32x'/' chars
   70  I@  /@/:   Print '/'
   71  U@  ME/O   if (B>=0) goto 69
   
   72  #@  U:QO   B7=8
   73  D@  H@/J   AM=AM+[H@]=VKTA X:/C -> to print 8x'C' (the last char)
   74  R@  OE/H   if (AM>=0) goto 67
   
   75  J@  AKT/   A=destination of routine set in [AK] before calling WRITETAPE
   76  N@  VSTA   set new cue [VS]= ///# A///
   77  F@  "EQO   B7=GA/P
   78  C@  LSQB   [LS]=B7 -> patch RCS to goto 81 instrad of loading routine from cue
   79  K@  NS/P   call RCS: check if false cue. if so, read directory and form the true cue in [VS]
                            then goto 81 instead of loading and executing it
   80  T@  DA//   
   81  Z@  VST/   A=[VS] get true cue of track 
   82  L@  VATR   A=A AND .... $$E/
   83  W@  @KTJ   A=A XOR .... ///#
   84  H@  VKTA   [VK]=save new cue as .... ...# -> will load to S4
   85  Y@  X:/C   D=//T/ ////
   86  P@  $S/N   
   87  Q@  H:TR   
   88  O@  VKTJ   
   89  B@  VKTA   
   90  G@  $K/:   Read Track from cue to tube S4
   91  "@  VA/:   Read again PERM into S2 to undo patch 
   92  M@  /KT/   AL=link on routine entry 
   93  X@  VSTA   [VS]=cue -> set return link
   94  V@  MAT/   AL=cue to WRITETAPE entry at $@ (addr 96)
   95  $@  NS/P   goto RCS -> return to INPUT to continue processing input steeing tape
                  as [VS] is set to WRITETAPE addr 96
                  INPUT will process the Q U routine name up to next Y warning char
                  The Y warning char will follos [VS] cue and then goto addr 96
   96  /A  VSTA   Entry 2: Save return link in [VS]=AL (point to INPUT)

   97  EA  F:QO   B7=64 words to process in S4 to calculate the checksum
   98  @A  A:QG   B7=B7-2
   99  AA  /#QC   AL=AL+[B7+256]
  100  :A  A:QG   B7=B7-2
  101  SA  ME/O   if (B>=0) goto 99

  102  IA  "ETA   Save checksum in ["E], clear A
  103  UA  BEQO   B7=JA/P
  104  #A  AKT/   A=[AK]
  105  DA  OETA   Save in [OE] source track for data (from [AK]=///# A///)
  106  RA  FEQB   [FE]=B7 -> JA/P -> patch to XXX
  107  JA  CAWO   B3=54
  108  NA  U:HO   B4=8
  109  FA  WA/P   goto 47

  110  CA  PE//   
  111  KA  LAQO   B7=KA/P
  112  TA  FEQB   [FE]=B7
  113  ZA  A:/P   goto 3
  114  LA  KA/P   
  115  WA  CEQO   
  116  HA  QEQB   
  117  YA  DST/   
  118  PA  OETA   
  119  QA  GETA   
  120  OA  META   
  121  BA  K@QO   
  122  GA  T@/P   
  123  "A         
  124  MA  $@WG   
  125  XA  :EEZ   
  126  VA  E//:   
  127  $A  $$E/   
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
