home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPMINFO / CPM22APP.LBR / CPM22011.AQP / CPM22011.APP
Text File  |  2000-06-30  |  13KB  |  214 lines

  1.                                       CP/M   V2.2
  2.                               Application Note 11 9/30/82
  3.                                    Chaining Programs
  4.  
  5.                           Copyright   1982 by Digital Research
  6.              CP/M and CP/NET are registered trademarks of Digital Research.
  7.                 MP/M II and PL/I-80 are trademarks of Digital Research.
  8.                                  Compiled October 1982
  9.  
  10.           Applicable products and version numbers:  CP/M    V2.2,  CP/NET    ,
  11.           and MP/M II   .
  12.  
  13.           Program:  CHAIN1.COM and CHAIN2.COM
  14.  
  15.                 Menu-driven applications can be written to  run  under  CP/M.
  16.           If  you  develop  applications  using  PL/I-80   , you can write the
  17.           programs as a set of overlays.  Often, the programs are  written  in
  18.           assembly  language,  or  require too much memory to make the overlay
  19.           feature of PL/I-80 appropriate.  Without using overlays,  there  are
  20.           only two effective methods of chaining under CP/M V2.2.
  21.  
  22.                 The first method uses the CP/M SUBMIT facility, in which  the
  23.           main  menu  program creates a SUBMIT file that lists the programs to
  24.           be chained.  The file must be written to drive A, and have the  name
  25.           $$$.SUB.
  26.  
  27.                 The SUBMIT file consists of compatible  lines,  exactly  like
  28.           those  you  type  at  the console, following the system prompt.  The
  29.           commands are placed in reverse order, so the  last  command  in  the
  30.           file  is the first to be executed.  Each command is placed in a 128-
  31.           byte record with the following format:
  32.  
  33.                   :n:C1:C2:...:cn:0:...:
  34.  
  35.                 The  first  byte  of  the  record  contains  the  number   of
  36.           characters  in  the command (n), followed by the characters (c1-cn),
  37.           and terminated with a zero.  The number of characters in the command
  38.           is  written  as a binary number and each character is represented in
  39.           ASCII format.  It does not matter what follows the terminating  zero
  40.           in  the  record.  For example, if the command was STAT*.*, the first
  41.           byte would be a binary  8,  followed  by  the  letters  STAT*.*  and
  42.           terminated with a zero.
  43.  
  44.                 The second  method  of  program  chaining  is  simpler.   You
  45.           include  a procedure in the menu program that loads the next program
  46.           and chains to it.  Each program that might chain to another  program
  47.           must include a copy of the procedure.  The procedure must first move
  48.           itself out of the way so that it is not overwritten by  the  program
  49.           it is loading.
  50.  
  51.               The example assembly language procedure is  written  to  link
  52.           with  PL/I-80 modules as an external procedure.  It can also be used
  53.           in an assembly language menu program.  To link to a PL/I-80 program,
  54.           the  following  entry  declaration  must  be included in the PL/I-80
  55.           program that does the chaining:è
  56.                   dcl chain entry (char(12));
  57.  
  58.                 The character 12 variable consists of the standard CP/M  File
  59.           Control  Block (FCB) format.  The format can be created in the PL/I-
  60.           80 program as a structure.  A char(12) variable can then be based at
  61.           the  same  address  as  the  structure  for interfacing to the chain
  62.           procedure.  (See the following PL/I-80 program.)
  63.  
  64.           Note:  the drive is not an ASCII  character,  but  a  binary  number
  65.           between 0 and 16, where 0 is the current default drive and 1 through
  66.           16 represent the CP/M drives A through P, respectively.
  67.  
  68.                   chain 1: proc options(main);
  69.                   /* chain subroutine tester */
  70.                      dcl 1 fcb static
  71.                       2 drive fixed(7) init(0),
  72.                       2 name char(8) init('CHAIN2');
  73.                       2 type char(3) init('COM'),
  74.                      dummy char(12) based(db),
  75.                      dp pointer,
  76.                     chain entry(char(12));
  77.                     put skip list('Chain Text program 1');
  78.                     dp = addr(fcb);
  79.                     call chain(dummy);
  80.                     put skip(2) list('Shouldn''t be here!!);
  81.                   end chain 1;
  82.  
  83.                 This program prints the message Chain  Test  program  1,  and
  84.           chains  to the program CHAIN2.COM on the default drive.  CHAIN2 is a
  85.           program identical to  CHAIN1,  except  that  it  prints  Chain  Test
  86.           Program 2 and chains to CHAIN1.COM.  CHAIN1 and CHAIN2 then continue
  87.           to chain back and forth to each other.
  88.  
  89.           Note:  any statements following the call to the chain procedure  are
  90.           not executed because the chain procedure never returns.
  91.  
  92.                 The  chain  procedure   consists   of   two   routines.    An
  93.           initialization  routine  initializes  the  FCB for the program to be
  94.           loaded.  Then, the initialization routine relocates the  loader  and
  95.           FCB to the very top of the Transient Program Area (TPA), immediately
  96.           below the BDOS, so it will not be overwritten by the loaded program.
  97.           The  loader  begins  at the label, code:, and ends at the end of the
  98.           FCB, at the statement, codelen equ $-code.
  99.  
  100.                 The loader routine sets the  DMA  address,  reads  a  sector,
  101.           checks  for  an  end-of-file,  increments  the  DMA addresses by 128
  102.           bytes, and repeats the process.  When the end-of-file  is  detected,
  103.           it jumps to the chained program.  The code is as follows:
  104.  
  105.                       public chain                         char(12)
  106.                       extrn      ?signal
  107.                       ,/* loads another COM file, and
  108.                       executes it */
  109.           bdos        equ      5è          openf       equ      15
  110.           readf       equ      20
  111.           dmaf        equ      26
  112.  
  113.                       cseq
  114.           chain.      mov e,m ! inx h ! mov d, m ! xchg    ;get first arg address
  115.                       lxi d, fcb ! mvi c, 12 ! call move   ;move string to FCB
  116.                       lxi d, fcb+12 ! mvi a, 0 ! mvi c, 21
  117.                       call fill                            ;zero rest of FCB
  118.                       lhld bdos+1 ! lxi b, -code$len
  119.                       dad b                                ;make space at
  120.                                                            ;top of TPA
  121.                       shld jmpr + 1                        ;jump address
  122.                       push h                               ;save code address
  123.                                                            ;for RET
  124.                       xchg ! lxi h, fcb-code ! dad d       ;make address of FCB
  125.                       shld FCBR+1                          ;and fix LXI
  126.                       push h                               ;save FCB
  127.                                                            ;destination address
  128.  
  129.                       lxi h, code ! mvi c, code$len
  130.                       call move                            ;dest in DE
  131.                       pop d                                ;recover address of FCB
  132.                       mvi c, openf ! call BDOS             ;open file
  133.                       inr a ! jz sig                       ;if any error,
  134.                                                            ;signal error
  135.                       pop h ! sphl ! push h                ;point stack to top
  136.                                                            ;of TPA
  137.                                                            ;and save code addr
  138.                       lxi h, 100h                          ;point to start of
  139.                                                            ;TPA
  140.                       ret                                  ;to loader "code"
  141.  
  142.           code:       push h ! xchg ! mvi c, dmaf
  143.                       call BDOS                            ;set the DMA address
  144.  
  145.           FCBR        lxi d, $-$ ! mvi c, readf !
  146.                       call BDOS                            ;read the next record
  147.                       ora a ! jnz 100h                     ;EOF -| start TPA
  148.                       pop h ! lxi d, 128 ! dad D           ;recover and bump DMA
  149.  
  150.           jmpr        jmp $-$                              ;jump to code
  151.           FCB:        ds       1                           ;drive code
  152.                       ds       8                           ;filename
  153.                       ds       3                           ;filetype
  154.                       ds       4                           ;control info
  155.                       ds       16                          ;disk map
  156.                       ds       1                           ;rrec
  157.           codelen     equ      $-code
  158.  
  159.           move:       ;c = # bytes, hi = source, de = desti-
  160.                       nation
  161.                       mov a,m ! stax d
  162.                       inx h ! inx d ! dcr c
  163.                       jnz moveè                      ret
  164.           fill:       ;a = byte to fill, c = # bytes, de = start ad-
  165.                       dress
  166.                       stax d ! inx d
  167.                       dcr c ! jnz fill
  168.                       ret
  169.           sig:        lxi h, siglist ! call ?signal ! jmp 0;signal error
  170.           siglist:                                         ;(fixed(6),
  171.                                                            ;bit(8),ptr,ptr)
  172.                       dw sigcode, sigsub, sigfil, message
  173.           sigcode     db      6                            ;undefined file
  174.                                                            ;error
  175.           sigsub      db      2                            ;arbitrary subcode
  176.                                                            ;for id
  177.           sigfil      dw     fpb                           ;ptr to file
  178.                                                            ;parameter block
  179.           message     dw     quack                         ;auxiliary
  180.                                                            ;operator message
  181.           fpb                                              ;PL/I fuke
  182.                                                            ;oaraneter bkicj
  183.           fcbptr      dw     FCB-1                         ;fcb-1
  184.           fpblst      dw      0                            ;(unused)ptr
  185.           column      dw      0                            ;current column
  186.                                                            ;fixed(15)
  187.           curline     dw      0                            ;current line
  188.                                                            ;fixed(15)
  189.           curpage     dw      0                            ;current page
  190.                                                            ;fixed(15)
  191.           currec      dw      0                            ;(unused)fixed(15)
  192.           lookchr     db      0                            ;look ahead char
  193.                                                            ;char(1)
  194.           ioend       dw      0                            ;i/o end address
  195.           iostk       dw      0                            ;user stack upon
  196.                                                            ;sio entry
  197.           spacer      ds      4                            ;spacer
  198.           linesz      dw      0                            ;line size
  199.                                                            ;fixed(15)
  200.           pagesz      dw      0                            ;page size
  201.                                                            ;fixed(15)
  202.           fixedsz     dw      0                            ;fixed size
  203.                                                            ;fixed(15)
  204.           blocksz     dw      0                            ;block size
  205.                                                            ;fixed(15)
  206.           filedes     dw      0                            ;block size
  207.                                                            ;fixed(15)
  208.           dtitle      db      0                            ;default title
  209.                                                            ;char(14)varying
  210.           quack       db      17,'Bad Chain Attempt',0     ;error message
  211.  
  212.                 Licensed  users  are  granted  the  right  to  include  these
  213.           modifications in CP/M, CP/NET and MP/M II software.
  214.