home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / UTILITY / DIR / PUSH_POP.ZIP / DIRS11B.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-07-21  |  7.8 KB  |  229 lines

  1. ;*************************  DIRS.ASM  ************************************
  2. ;
  3. ;    DIRS.ASM version 1.1b
  4. ;    
  5. ;    Usage:
  6. ;        DIRS
  7. ;    Purpose: This program will list the directories on a stack
  8. ;        created with the PUSHD v. 1.2 command.  Directories are
  9. ;        listed in order from the top of the stack to the
  10. ;        bottom.
  11. ;    Preconditions: 
  12. ;        1) PUSHD must be hooked to interrupt 13.
  13. ;        2) PUSHD must have the same commands from beginning
  14. ;         to after definition of push6d, so that it knows how
  15. ;         to access the resident code of PUSHD.  (This includes
  16. ;         the fact that there are 6 locations for directory storage
  17. ;         which are 67 bytes in size.)
  18. ;        3) PUSHD must have the signature "PUSHD VERSION 1.1".
  19. ;        4) PUSHD must look for 7788 in ax and 7789 in bx for
  20. ;         a call to int 13.
  21. ;        5) PUSHD must put the value of 7789 into ax and 7788
  22. ;         into bx upon calling int 13 by DIRS, if PUSHD is installed.
  23. ;        6) PUSHD will set the data segment to be equal to the data
  24. ;         segment that PUSHD used to install itself.
  25. ;        7) ds:[nextpush] (ds of PUSHD installation) must hold
  26. ;         the location of the next empty directory stack location.
  27. ;    Postconditions: 
  28. ;        1) The list of directories on the stack will be    printed out on
  29. ;         the standard output OR
  30. ;        2) An appropiate error message will be printed out on standard
  31. ;         error.
  32. ;        3) An error code will be generated.
  33. ;    Error codes:
  34. ;        0) Successful termination.
  35. ;          254) No Directories on the stack.
  36. ;          255) PUSHD is not installed.
  37. ;    Version changes:
  38. ;        1.1b July 21, 1990
  39. ;         Removed commented-out commands from Toad Hall version.
  40. ;        1.1a July 19, 1990
  41. ;         Toad Hall tweaking (much thanks to David Kirshbaum).
  42. ;    Future Enhancements:
  43. ;        1) Make DIRS a .EXE file.
  44. ;        2) Add a help option, ?, from the command line.
  45. ;
  46. ;    Created by:
  47. ;      (from ideas based in UNIX and from PC Magazine's pushdir/popdir)
  48. ;        William P. Sarra
  49. ;            CIS:71041,347
  50. ;            arpa: sarra@TOPAZ.RUTGERS.EDU
  51. ;    uucp: ...{ames,cbosgd, harvard, moss}!rutgers!topaz.rutgers.edu!sarra
  52. ;
  53. ;*****************************************************************************
  54.  
  55. MAIN    group   CSEG
  56. CSEG    segment public  para    'code'
  57.         assume  CS:MAIN,DS:MAIN,ES:MAIN,SS:MAIN
  58.  
  59. org     80h
  60. cmd_line        label   byte
  61.  
  62. org     100h            ;.COM file
  63.  
  64. Begin:  jmp     Start   ;program starts here
  65.  
  66. signature       db      'PUSHD VERSION 1.1'
  67. ;SIG_LEN        equ    $-signature
  68.  
  69. savedint13      dd     ?        ;used to be identical to pushd
  70.  
  71. nextpush        dw     offset MAIN:push1d     ;next place to save a dir
  72.  
  73. push1d  db     67 dup (0)       ;directory storage
  74. push2d  db     67 dup (0)
  75. push3d  db     67 dup (0)
  76. push4d  db     67 dup (0)
  77. push5d  db     67 dup (0)
  78. push6d  db     67 dup (0)
  79.  
  80. ;up to here must be EXACTLY identical in PUSHD, POPD and DIRS.
  81.  
  82. ;****************************************************************
  83. ;
  84. ;       Data Section.
  85. ;
  86. ;****************************************************************
  87.  
  88. notinstalled1   db      'PUSHD must be installed before DIRS'
  89.                 db      ' will do anything.',13,10
  90. NOTINSTALLED_LN equ     $-notinstalled1
  91.  
  92. emptymsg        db         'No directories on the stack.'
  93. cr_lf           db      13,10   ;share this                     v1.2
  94. EMPTYMSG_LEN        equ    $-emptymsg
  95.  
  96. CR_LF_LN        equ     $-cr_lf
  97.  
  98. ;***************************************************************
  99. ;
  100. ;       Code Starts.
  101. ;
  102. ;***************************************************************
  103.  
  104. Start:
  105.  
  106.         ;is PUSHD already installed ?
  107.  
  108.         mov     ax,7788h                        ;signature request
  109.         mov     bx,7789h                        ;signature request
  110.         mov     si,offset MAIN:signature        ;point DS:si to signature
  111.         int     13h                             ;is it installed ?
  112.  
  113.         assume  DS:nothing
  114.  
  115.         cmp     bx,7788h                ;were ax and bx switched ?
  116.         jne     NotInstalled            ;no
  117.         cmp     ax,7789h                ;were ax and bx switched ?
  118.         jz      IsInstalled             ;yes, continue                  v1.2
  119.  
  120. NotInstalled:
  121.  
  122.         ;here PUSHD was not previously installed so POPD can't do anything
  123.         ;useful so we just terminate with an error message.
  124.  
  125.         mov     dx,offset MAIN:notinstalled1    ;error message
  126.         mov     cx,NOTINSTALLED_LN
  127.         mov     al,0FFH                 ;ERRORLEVEL             v1.2
  128.         jmp     Msg_Term                ;display, terminate     v1.2
  129.  
  130. IsInstalled:
  131.  
  132.         ASSUME  DS:CSEG                 ;TSR's
  133.  
  134.         ;get address of previously saved directory
  135.  
  136.         mov     dx,DS:[nextpush]                ;get next location      v1.2
  137.         cmp     dx,offset MAIN:push1d           ;check for empty stack  v1.2
  138.         jnz     NotEmpty                        ;nope, continue         v1.2
  139.  
  140.         ;directory stack is empty -- print message and quit
  141.  
  142.         mov  dx,offset MAIN:emptymsg            ;error message
  143.         mov  cx,EMPTYMSG_LEN
  144.         mov     al,0FEH                 ;ERRORLEVEL             v1.2
  145.         jmp     short Msg_Term          ;display, terminate     v1.2
  146.  
  147. NotEmpty:
  148.  
  149. ;v1.2   Pick up some handy "constants"
  150.         mov     si,CS                   ;our CSEG               v1.2
  151.         mov     di,DS                   ;TSR's CSEG             v1.2
  152.  
  153.         mov     bp,offset MAIN:cr_lf    ;handy constant         v1.2
  154.         sub     dx,67                   ;get last pushed dir    v1.2
  155.  
  156. NotEmpty_Lup:
  157.  
  158.         ;handle the printing out of the stored directory.
  159.  
  160.         ASSUME  DS:CSEG         ;TSR's
  161.  
  162.         mov     cx,67           ;length of directory
  163.         mov     bx,1            ;write on stdout
  164.         mov     ah,40h          ;write to file/device
  165.         int     21h
  166.  
  167.         sub     dx,cx           ;- 67                           v1.2
  168.  
  169.         ;now print out a cr/lf pair at the end of the directory
  170.  
  171.         mov     DS,si                   ;our CSEG                       v1.2
  172.         ASSUME  DS:MAIN                 ;our CSEG
  173.  
  174.         xchg    dx,bp                   ;DS:DX=cr_lf, BP=saved DX       v1.2
  175.         mov     cx,CR_LF_LN
  176.         mov     bx,1                    ;stdout
  177.         mov     ah,40h                  ;write to file/device
  178.         int     21h
  179.  
  180.         mov     DS,di                   ;TSR's CSEG                     v1.2
  181.         ASSUME  DS:CSEG                 ;TSR's
  182.  
  183.         xchg    dx,bp                   ;BP=cr_lf addr, DX=current dir addr v1.2
  184.  
  185.         ;get next directory storage location and make sure it is
  186.         ;within the range of stored locations
  187.  
  188.         cmp     dx,offset MAIN:push1d   ;hit directory stack top yet?   v1.2
  189.         jge     NotEmpty_Lup            ;not yet, keep going            v1.2
  190.  
  191.         mov     ax,4c00h        ;terminate upon successful completion
  192.         int     21h
  193.  
  194. ;*************************************************************************
  195. ;
  196. ;    PROCEDURE:    Msg_Term
  197. ;
  198. ;    Purpose: This procedure will handle the printing of error messages
  199. ;        and termination with the correct errorlevel.
  200. ;    Preconditions: 
  201. ;        DX = error message address.
  202. ;        CX = error message length.
  203. ;        AL = ERRORLEVEL.
  204. ;    Postconditions: 
  205. ;        The program will be terminated with the appropriate
  206. ;         error message printed on standard error and with the
  207. ;         the errorlevel stored in al.
  208. ;
  209. ;***************************************************************************
  210.  
  211. Msg_Term        PROC    NEAR
  212. ;v1.2 Common code
  213.  
  214.         push    CS
  215.         pop     DS                      ;insure DS=CSEG
  216.  
  217.         push    ax                      ;save AL errorlevel
  218.         mov     bx,2                    ;stderr
  219.         mov     ah,40h                  ;dos function number
  220.         int     21h                     ;show message
  221.         pop     ax
  222.         mov     ah,4CH                  ;terminate process
  223.         int     21h
  224.  
  225. Msg_Term        ENDP
  226.  
  227. CSEG    ENDS
  228.         END     Begin
  229.