               JOB  READ TEST TAPE ROUTINE                                 5300F
               CTL  221
     *
     * This encompasses 5300E and 5310E from the diagnostics.
     * It assumes the Autocoder loader clears core, so it doesn't
     * need to postpone loading the tape loader.
     *
     nrtape    equ  1           tape drive to read
     nwtape    equ  1           tape drive to write
     *
     * This is the tape loader, which is written in the first tape block.
     *
     * A branch to here is planted in 1-5 before the block is written,
     * so this is where the diagnostic tape starts executing when it
     * is loaded.
     *
               ORG  1280
 1280begldr    H    *&1         begin the loader here
 1284          SW   gmwm
     *
     * Programs come here to load detail records or the next program.
     * This has to be at 1288 because the trailer card after each
     * program meddles with the program's read routine to plant a
     * branch to here.
     *
 1288load      CS   81          ensure no gmwm in 1-81
 1292          RTW  nrtape,1
 1300          LCA  gmwm&1      set gmwm after input
 1304          BER  rtaper
 1309          BEF  rtapef
 1314          BCE  load,80,A   title card of program?
 1322          SW   1273
 1326          C    76,1276     check if desired/excluded block
 1333          BSS  goeq,F
 1338          BU   377         run test if not excluded
 1343          B    load        load the next one
 1347goeq      BU   load        load next one if this one is not desired
 1362          B    377         run test if desired one
 1356rtaper    BSP  nrtape      error during read
 1361          NOP              patch in a halt here if you feel like it
 1362          B    load
 1366rtapef    RWD  nrtape      end-of-file during read
 1371          NOP              patch in a halt here if you feel like it
 1372          B    load
               DCW  #22
     *
     * This GMWM not only stops the writing of blocks to tape, but
     * it also tells the trailer card after a program to go to the
     * write-the-program routine at ,wprog, after loading the program,
     * instead of running it.
     *
     * It has to be at 1398.
     * 
 1398gmwm      DCW  @}@
               JOB  WRITE TEST TAPE ROUTINE                                5300F
     *
     * Here's the code to load the programs and write the tape.
     *
     * The first record on the tape is the tape read routine.
     *
     * Before each program there is an 80-character record with ,A, in
     * column 80, which is the set-word-mark card from the program deck.
     * The program ID number is in columns 73-76, and the version in 77.
     *
     * Then the program itself as a 1250-character record.
     *
     * Then the program's detail records, if any, as 80-character records.
     *
     * All records are written with word marks.
     *
               org  1514
     start     h    *&3         start to skip punching sample trailer
               p                start reset to punch sample trailer
               h
               cs   180         clear sample trailer
               rwd  nwtape
               lca  kbegld&4,5  setup entry to the tape loader
     detail    cw   switch      setup to read detail and headers
     write     wtw  nwtape,1    write a block
               ber  wtaper
               bef  wtapef
               nop              includes next instr if next has no wm
     switch    r    1           loads a program deck if it has a wm
     *
     * Read detail and header cards and write to tape
     *
               blc  finish
               cs   81          clear 1-81
               sw   1
               r                read detail card
               lca  gmwm,81
               bce  prog,80,a   program header card?
               b    write       no, just write it
     *
     * Set up to write a program instead of detail cards
     *
     prog      sw   switch      setup to load the program
               b    write       write the program header
     *
     * Come back here after loading the program.
     * This must be at 1604 because that's the address in
     * the trailer card of each program.
     *
     wprog     lca  gmwm,1250
               mcw  kb,81       ,b, instead of gm in 81
               b    detail      write the program
     *
     * Tape error and eof routines
     *
     wtaper    bsp  nwtape      backspace over bad spot
               skp  nwtape      write 3 inches of blank tape
               b    write       try again
     wtapef    nop  666         end of reel, set A and B regs
               h
               b    wtapef      stuck here, nothing else to do
     *
     * No more cards
     *
     finish    wtm  nwtape      write tape mark
               rwd  nwtape      rewind but don't unload
     done      nop  111         set A and B regs
               h
     kb        b    done
     kbegld    bin  begldr,
               job  trailer card                                           5300F
     *
     * Here's the trailer card, offset by 100.
     * When it's executed, there are already word marks in
     * 1, 8 and 12.
     *
               org  101
     trailr    sw   wm4-100,wm5-100
               sw   wm6-100
               sw   wm7-100,wm8-100
     wm4       bce  wm6-100,gmwm,}  loading to tape?
     wm5       b    400             no, run the program
     wm6       lca  goload-100,352  meddle with program's read routine
     wm7       b    wprog           go to tape write routine
     wm8       bin  load,
     goload    equ  *
               dc   #2
               dc   @program title here      @
               dc   @####r@
               dc   @ 00@
               end  start
