PSP: Program Segment Prefix

 This structure is created for each program that DOS executes.

  Offset Size Contents
  ▀▀▀▀▀▀ ▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  +0       2  wInt20       INT 20H instruction (cd 20) (old way to exit)
  +2       2  wNextSeg     Segment addr just beyond end of program image
  +4       1  res1         (reserved)
  +5       5  abDispatch   FAR CALL to DOS function dispatcher (obs)
 +0aH      4  pfTerminate  terminate address.       See INT 22H
 +0eH      4  pfCtlBrk     Ctrl-Break handler address   INT 23H
 +12H      4  pfCritErr    Critical Error handler addr  INT 24H
 +16H     22  res2         DOS reserved area
           2  wParentPsp   ◄undoc► segment of parent's PSP
 +2cH      2  wEnvSeg      segment address of DOS environment
 +2eH     46  res3         DOS reserved area (handle table, et al.)
 +5cH     16  rFCB_1       an unopened FCB for 1st cmd parameter
 +6cH     20  rFCB_2       an unopened FCB for 2nd cmd parameter
 +80H      1  bCmdTailLen  count of characters in command tail at 81H (also
                           default setting for the DTA)
 +81H     127 abCmdTail    characters from DOS command line
          256              size of a PspRec structure

      wInt20  An obsolete way to terminate a program is to JMP here.
    wNextSeg  Segment address of the paragraph just above the end of the
              program.  This can be used to calculate the size of the load
              block (by subtracting the segment of the PSP itself).  Memory
              at this address is NOT free for use.
  abDispatch  An obsolete way to call DOS fns was to JMP here.

 pfTerminate  On exit, DOS copies this to INT 22H vector
   pfCtrlBrk  On exit, DOS copies this to INT 23H vector
   pfCritErr  On exit, DOS copies this to INT 24H vector

  wParentPsp  This undocumented 2-byte field at (offset 16H) contains the
              segment of the parent process's PSP (usually COMMAND.COM).  By
              tracing backward along this chain, you can locate a wParentPsp
              which is the same as the PSP in which it resides.  The wEnvSeg
              in that PSP points to the master environment, and careful
              manipulation of that data area will make changes to the
              DOS Environment that are remembered after your program exits
              (just changing your own copy of the environment will only
              affect you and your own spawns).

     wEnvSeg  At program startup, DOS creates a copy of the DOS Environment
              area and places its segment address in this field.

      rFCB_1  The first filename in the command tail is formatted into an
              unopened FCB and placed here.
      rFCB_1  The second filename (note: no path info, so rarely used)

 bCmdTailLen  The length of the command-line text tail.
              Also: The default address of the DTA is here (PSP:0080)
   abCmdTail  The text of command-line parameters, not including the command
              name (except I/O redirection info has been removed).  A CR
              (0dH) is appended, but not included in aCmdTailLen.

   Notes: ■ When a program starts running, DS and ES point to the start of
            that program's PSP.  You may also obtain the PSP address via
            fn 51H.

          ■ The PSP segment address is used as the "process ID" in fns 50H,
            51H, and 62H; it is used as the wOwnerID in an MemBlockRec.

          ■ Use the PSP information to parse filenames and options from the
            command line tail, learn how much RAM is available, find the
            environment etc.   See Program Startup & Exit.

See Also: Program Startup & Exit
          Process Control Functions
          TSR Functions
          Data Structures