home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / pcmag / vol6n01.arc / DIREX.ASM next >
Assembly Source File  |  1987-12-13  |  31KB  |  643 lines

  1.         TARGET EQU 0D8H 
  2.         SOURCE EQU 0B0H
  3. CODE_SEG        SEGMENT
  4.         ASSUME  CS:CODE_SEG,DS:CODE_SEG,ES:CODE_SEG
  5.         ORG     100H
  6. START:  JMP     DIREX
  7.         PROMPT DB 'D=Delete P=Protect U=Unprotect C=Copy <Space>=Mark'
  8.                DB ' N=New Dir Q=Quit$'
  9.         COPY_PROMPT     DB      'Pathname to copy marked files to: $'
  10.         NEW_DIR_PROMPT  DB      'New Pathname: $'
  11.         FULL_MSG        DB      '*        TARGET DISK FULL!          *$'
  12.         DEL_MSG         DB      'Delete Marked Files (Y/N)? $'
  13.         COPY_FLAG       DB      0       ;Set when doing copies.
  14.         D1_FLAG         DB      0       ;In DISPLAY, not DSPLAY@
  15.         DISP_FLAG       DB      0       ;Set when intial display done.
  16.         FULL_FLAG       DB      0       ;Disk Full Flag.
  17.         NOFILE_FLAG     DB      0       ;1-->No filename given.
  18.         SOURCE_HANDLE   DW      0       ;Source File Handle.
  19.         TARGET_HANDLE   DW      0       ;Target File Handle.
  20.         SOURCE_PATH_END DW      0B0H    ;End of Path -- put filenames here.
  21.         TARGET_PATH_END DW      0DBH    ;Same for Target.
  22.         TEST_PATH_END   DW      0       ;Same for Target.
  23.         BYTES_READ      DW      ?       ;Bytes read -- for copy.
  24.         BYTES_ASKED     DW      ?       ;Bytes requested to be read.
  25.         MARKED  DB      ?               ;File Marked? 
  26.         ATTRIB  DB      7               ;Screen Attribute.
  27.         WILDCARDS       DB      '*.*',0
  28.         CURSOR_X        DB      ?       ;Reverse Vid. Cursor position X
  29.         CURSOR_Y        DB      ?       ;Same for Y.
  30.         TEMPX           DB      ?       ;Temporary storage for x,y positions.
  31.         TEMPY           DB      ?
  32.         FILENAME        DB      10 DUP(0)       ;Store given filname here.
  33.                         DB  "Copyright 1986 Ziff-Davis Publishing Co.",1Ah
  34.                     DB  "Programmed by Steven Holzner",1Ah
  35.  
  36.  
  37.  
  38. DIREX   PROC    NEAR
  39.         CALL    DISPLAY                 ;Setup -- put dir on screen.
  40.         MOV     SI,SOURCE_PATH_END      ;Light up first filename.
  41.         CALL    GET_FILE_NAME
  42. TOPPER: MOV     ATTRIB,70H
  43.         CALL    COLOR
  44. TOP:    MOV     AH,0                    ;Read a character w/o echo.
  45.         INT     16H
  46.  
  47. SPACE:  CMP     AL,20H                  ;Space? Mark a file?
  48.         JNE     RIGHT                   ;No, check cursor keys
  49.         MOV     AH,8                    ;Yes.
  50.         MOV     BX,0                    ;Check if file marked.
  51.         ADD     CURSOR_X,12             ;Read byte just after filname
  52.         CALL    SET_CURSOR              ; from the screen.
  53.         INT     10H                     
  54.         CMP     AL,0FFH                 ;Marked? (Yes if FFH)
  55.         JE      OPP                     ;Yes.
  56.         MOV     AL,0FFH                 ;No, mark.
  57.         JMP     PPO
  58. OPP:    MOV     AL,0                    ;Unmark, move 0 to last byte.
  59. PPO:    MOV     AH,10
  60.         MOV     CX,1
  61.         INT     10H
  62.         SUB     CURSOR_X,12             ;Reset cursor to beginning of filename.
  63.         CALL    SET_CURSOR
  64.         JMP     TOP                     ;And start over.
  65.  
  66. RIGHT:  CMP     AH,4DH                  ;Right cursor key?
  67.         JNE     LEFT                    ;No, try left.
  68.         MOV     ATTRIB,7                ;Unmark current file if we can.
  69.         CALL    COLOR
  70.         CALL    INC_CURSOR              ;Move to next filename.
  71.         MOV     ATTRIB,70H 
  72.         CALL    COLOR                   ;And highlight it.
  73.         JMP     TOP                     ;Start over.
  74.  
  75. LEFT:   CMP     AH,4BH                  ;Left cursor key?
  76.         JNE     UP                      ;No, try up key.
  77.         MOV     DL,CURSOR_X             ;Yes, move one filename left.
  78.         MOV     DH,CURSOR_Y
  79.         MOV     ATTRIB,7                ;First unmark current filename.
  80.         CALL    COLOR
  81.         SUB     DL,13
  82.         JNC     OK                      ;Can we move left?
  83.         MOV     DL,5*13                 ;No, wrap back.
  84.         SUB     DH,1
  85.         JNC     OK                      ;Make sure not over top of screen.
  86.         MOV     DL,CURSOR_X             ;If so, do not change marked file.
  87.         MOV     DH,CURSOR_Y
  88. OK:     MOV     CURSOR_X,DL
  89.         MOV     CURSOR_Y,DH             ;Load changed cursor positions
  90.         CALL    SET_CURSOR              ; and light up new filename.
  91.         MOV     ATTRIB,70H
  92.         CALL    COLOR
  93.         JMP     TOP                     ;And start over.
  94.  
  95. UP:     CMP     AH,48H                  ;An Up key?
  96.         JNE     DOWN                    ;No, try down.
  97.         MOV     DL,CURSOR_X             ;Yes, get highlit position.
  98.         MOV     DH,CURSOR_Y
  99.         MOV     ATTRIB,7                ;Unmark current filename.
  100.         CALL    COLOR
  101.         SUB     DH,1                    ;Can we go up?
  102.         JNC     NOTTOP                  ;Yes.
  103.         ADD     DH,1                    ;No.
  104. NOTTOP: MOV     CURSOR_X,DL             ;Set new cursor position.
  105.         MOV     CURSOR_Y,DH
  106.         CALL    SET_CURSOR
  107.         MOV     ATTRIB,70H              ;And highlight new filename.
  108.         CALL    COLOR
  109.         JMP     TOP                     ;And start over.
  110.  
  111. DOWN:   CMP     AH,50H                  ;Was this a down cursor key?
  112.         JNE     LETTERS                 ;No, try letters (C,N,D,U,P)
  113.         MOV     ATTRIB,7                ;Yes, unmark current filename.
  114.         CALL    COLOR
  115.         INC     CURSOR_Y                ;Are we past bottom if we INC Y?
  116.         CALL    SET_CURSOR
  117.         MOV     SI,SOURCE_PATH_END
  118.         CALL    GET_FILE_NAME
  119.         CMP     BYTE PTR DS:[SI],' '    ;Is there a filename there?
  120.         JA      GO                      ;If yes, go.
  121. NOGO:   DEC     CURSOR_Y                ;If no, retain old position.
  122.         CALL    SET_CURSOR
  123. GO:     MOV     ATTRIB,70H
  124.         CALL    COLOR                   ;Highlight this file.
  125.         JMP     TOP
  126.  
  127. LETTERS:CMP     AL,'Z'                  ;Convert to lower case
  128.         JL      GOL
  129.         SUB     AL,'a'-'A'
  130. GOL:    CMP     AL,'Q'                  ;Is this a 'Q' to quit?
  131.         JNE     DEL                     ;No, try 'D'.
  132.         MOV     CX,25                   ;Clear the screen.
  133.         MOV     CURSOR_X,0              
  134.         MOV     CURSOR_Y,0
  135.         CALL    SET_CURSOR              
  136. WIPE2:  PUSH    CX                      
  137.         CALL    SET_CURSOR
  138.         MOV     CX,80
  139.         MOV     AH,9                    ;Use Service 9
  140.         MOV     BX,7
  141.         MOV     AL,0
  142.         INT     10H                     ;With INT 10H.
  143.         POP     CX
  144.         INC     CURSOR_Y                ;Keep going on this line.
  145.         LOOP    WIPE2                   ;Loop over all 25 lines.
  146.         MOV     CURSOR_X,0              
  147.         MOV     CURSOR_Y,0
  148.         CALL    SET_CURSOR              
  149.         JMP     OUT                     ;Quit.
  150.  
  151. DEL:    CMP     AL,'D'                  ;Is this a 'D'?
  152.         JE      OKD                     ;Yes.
  153.         JMP     PRO                     ;No, Try 'P'.
  154. OKD:    MOV     ATTRIB,7
  155.         CALL    COLOR                   ;Unhighlight current filename.
  156.         MOV     CURSOR_X,0
  157.         MOV     CURSOR_Y,24
  158.         CALL    SET_CURSOR              ;Reset cursor to beginning.
  159.         MOV     AH,9
  160.         MOV     CX,80                   ;Print Del prompt.
  161.         MOV     AL,' '                  ;First, clear prompt line.
  162.         MOV     BX,7
  163.         INT     10H
  164.         MOV     CURSOR_X,0
  165.         MOV     CURSOR_Y,24
  166.         CALL    SET_CURSOR
  167.         MOV     AH,9
  168.         MOV     DX,OFFSET DEL_MSG
  169.         INT     21H
  170.         MOV     AH,1                    ;Get a response.
  171.         INT     21H                     ;Convert to upper case.
  172.         CMP     AL,'Z'
  173.         JL      CHECKY
  174.         SUB     AL,'a'-'A'
  175. CHECKY: CMP     AL,'Y'                  ;Was this a 'Y'?
  176.         JE      GODEL                   ;Yes, Delete!
  177.         CALL    DSPLAY2                 ;No, highlight current file and 
  178.         MOV     ATTRIB,70H              ; start over.
  179.         CALL    COLOR
  180.         JMP     TOP
  181. GODEL:  MOV     CURSOR_X,0              ;Delete here.
  182.         MOV     CURSOR_Y,0              ;Start at beginning.
  183.         CALL    SET_CURSOR
  184. LOOPD:  CALL    GET_MARKED_FILE         ;Loop over all marked files.
  185.         MOV     DX,SOURCE               ;Point to source string.
  186.         MOV     AH,41H                  ;Delete!
  187.         INT     21H
  188.         CALL    INC_CURSOR              ;Move to next file.
  189.         CMP     DX,0FFH                 ;Is there one?
  190.         JE      FIND                    ;Yes.
  191.         CMP     CX,0FFH                 ;No, start over, refresh display.
  192.         JNE     LOOPD
  193. FIND:   CALL    DSPLAY2
  194.         MOV     ATTRIB,70H              ;Highlight first file.
  195.         CALL    COLOR
  196.         JMP     TOP
  197. PRO:    CMP     AL,'P'                  ;Is this a 'P'?
  198.         JNE     UNPRO                   ;No, try 'U'.
  199.         MOV     ATTRIB,7                ;Yes, Unhighlight current file.
  200.         CALL    COLOR
  201.         MOV     CURSOR_X,0              ;Start at beginning of all files.
  202.         MOV     CURSOR_Y,0
  203.         CALL    SET_CURSOR
  204. LOOPP:  CALL    GET_MARKED_FILE         ;Loop over all marked files.
  205.         MOV     DX,SOURCE
  206.         MOV     AH,43H                  ;And Protect them.
  207.         MOV     AL,01
  208.         MOV     CX,1
  209.         INT     21H
  210.         CALL    INC_CURSOR              ;Move on to next filename.
  211.         CMP     DX,0FFH                 ;If there is one.    
  212.         JE      FINP                    ;If not, leave.
  213.         CMP     CX,0FFH
  214.         JNE     LOOPP                   ;If so, loop again.
  215. FINP:   CALL    DSPLAY2                 ;Refresh screen.
  216.         MOV     ATTRIB,70H              ;And highlight the first filename.
  217.         CALL    COLOR
  218.         JMP     TOP                     ;And start over.
  219. UNPRO:  CMP     AL,'U'                  ;Was this a 'U'?
  220.         JNE     COPY                    ;No, try 'C' for Copy.
  221.         MOV     ATTRIB,7                ;Yes, unhighlight current file.
  222.         CALL    COLOR
  223.         MOV     CURSOR_X,0              ;Start at beginning of all files.
  224.         MOV     CURSOR_Y,0
  225.         CALL    SET_CURSOR
  226. LOOPU:  CALL    GET_MARKED_FILE         ;Loop over all marked files.
  227.         MOV     DX,SOURCE               ;Point to found file.
  228.         MOV     AH,43H                  ;And Unprotect it.
  229.         MOV     AL,01
  230.         MOV     CX,0                    ;CX=0 --> Unprotect.
  231.         INT     21H
  232.         CALL    INC_CURSOR              ;Point to next filename.
  233.         CMP     DX,0FFH                 ;If there is one.
  234.         JE      FINU                    ;If not, refresh screen and start over.
  235.         CMP     CX,0FFH
  236.         JNE     LOOPU
  237. FINU:   CALL    DSPLAY2                 ;Refresh screen.
  238.         MOV     ATTRIB,70H              ;Highlight first file.
  239.         CALL    COLOR                   ;And start over.
  240.         JMP     TOP
  241. COPY:   CMP     AL,'C'                  ;Was this a 'C'?
  242.         JE      GOC                     ;Yes, Copy!
  243.         JMP     NEW_DIR                 ;No, try 'N' for New directory.
  244. GOC:    MOV     FULL_FLAG,0             ;Set Disk full flag to false.
  245.         MOV     ATTRIB,7                ;Unhighlight current file
  246.         CALL    COLOR                   ; if we can.
  247.         MOV     CURSOR_X,0              ;Type out copy prompt.
  248.         MOV     CURSOR_Y,24
  249.         CALL    SET_CURSOR              ;First, clear prompt line.
  250.         MOV     AH,9
  251.         MOV     CX,80
  252.         MOV     AL,' '
  253.         MOV     BX,7
  254.         INT     10H
  255.         MOV     CURSOR_X,0
  256.         MOV     CURSOR_Y,24             ;Type out copy prompt.
  257.         CALL    SET_CURSOR
  258.         MOV     AH,9                    ;With the string printing service.
  259.         MOV     DX,OFFSET COPY_PROMPT   ;Ask for new pathname.
  260.         INT     21H
  261.         MOV     AH,0AH                  ;Put it at TARGET location.
  262.         MOV     BX,TARGET-2             ;With a buffered read-in.
  263.         MOV     DX,TARGET-2
  264.         MOV     BYTE PTR [BX],32        ;32 bytes max.
  265.         INT     21H
  266.         MOV     SI,TARGET               ;Check now for final '\'.
  267. TRANS:  CMP     BYTE PTR [SI],13        ;If it is missing, put it in.
  268.         JE      SLASH2
  269.         INC     SI
  270.         JMP     TRANS
  271. SLASH2: CMP     BYTE PTR [SI-1],'\'     ;Was a '\' at the end?
  272.         JE      FILER2                  ;Yes.
  273.         MOV     BYTE PTR [SI],'\'       ;Put '\' in at end of pathname.
  274.         INC     SI
  275. FILER2: MOV     TARGET_PATH_END,SI      ;Store end of pathname so we
  276.         MOV     ATTRIB,7                ; can put filenames at end of it.
  277.         CALL    COLOR                   ;Unhighlight current file if we can.
  278.         MOV     CURSOR_X,0
  279.         MOV     CURSOR_Y,0
  280.         CALL    SET_CURSOR
  281. LOOPC:  MOV     COPY_FLAG,1             ;Set Copy flag (so GET_MARKED_FILE
  282.         CALL    GET_MARKED_FILE         ; will fill in TARGET too).
  283.         MOV     COPY_FLAG,0             ;Loop over all marked files.
  284.         CMP     CX,0FFH                 ;If there are any.
  285.         JNE     OPEN
  286.         JMP     FINC
  287. OPEN:   MOV     DX,SOURCE               ;Now to open source and target.
  288.         MOV     AX,3D00H
  289.         INT     21H
  290.         JC      BOTC                    ;Unless there is an error.
  291.         MOV     SOURCE_HANDLE,AX        ;Open source, store handle.
  292.         MOV     DX,TARGET               ;Open target.
  293.         MOV     AH,3CH
  294.         MOV     CX,0
  295.         INT     21H
  296.         JC      BOTC
  297.         MOV     TARGET_HANDLE,AX        ;And store its handle too.
  298. STUFF:  MOV     DX,OFFSET DATA          ;We will use the end of the prog
  299.         MOV     CX,61*1024              ; for data. 62K at once.
  300.         MOV     AH,3FH                  ;Prepare to read in as much as we can.
  301.         MOV     BX,SOURCE_HANDLE        ;From the source.
  302.         INT     21H
  303.         MOV     BYTES_READ,AX           ;How much was actually read?
  304.         MOV     CX,AX                   ;Put # bytes read into CX for write.
  305.         MOV     BYTES_ASKED,CX          ;Store to check later.
  306.         MOV     AH,40H                  ;Here's the write!
  307.         MOV     BX,TARGET_HANDLE        ;Get target handle.
  308.         MOV     DX,OFFSET DATA          ;Point DS:DX.
  309.         INT     21H
  310.         CMP     AX,BYTES_ASKED          ;See if bytes written agrees with what 
  311.         JNE     FULL                    ; what was asked. If not, full disk.
  312.         CMP     BYTES_READ,61*1024      ;If OK, did we actually get 62K?
  313.         JE      STUFF                   ;If so, go back for more.
  314.         JMP     BOTC                    ;If not, done with this file, close.
  315. FULL:   MOV     CURSOR_X,0              ;Here the disk is full, put up message.
  316.         MOV     CURSOR_Y,24
  317.         CALL    SET_CURSOR
  318.         LEA     DX,FULL_MSG
  319.         MOV     AH,9
  320.         INT     21H
  321.         MOV     FULL_FLAG,1             ;Close files, set flag so we can delete
  322.         MOV     CURSOR_X,0              ; partially copied file in Target.
  323.         MOV     CURSOR_Y,0
  324.         CALL    SET_CURSOR              ;Move cursor back to top.
  325. BOTC:   MOV     AH,3EH                  ;Close files.
  326.         MOV     BX,SOURCE_HANDLE
  327.         INT     21H
  328.         MOV     AH,3EH                  ;Using Service 3EH.
  329.         MOV     BX,TARGET_HANDLE
  330.         INT     21H
  331.         CMP     FULL_FLAG,1             ;Was this a disk-full case?
  332.         JNE     NOTFULL                 ;No, do another file.
  333.         MOV     DX,TARGET               ;Yes, now that files are closed, delete
  334.         MOV     AH,41H                  ; partially copied file in target 
  335.         INT     21H                     ; pathname.
  336.         JMP     TOPPER                  ;Go back to top but don't wipe out Disk
  337. NOTFULL:CALL    INC_CURSOR              ; Full message.
  338.         CMP     DX,0FFH                 ;Point to next file if there is one.
  339.         JE      FINC                    ;There isn't, finish up copy.
  340.         JMP     LOOPC                   ;There is, start next copy.
  341. FINC:   CALL    DSPLAY2                 ;Refresh screen.
  342.         MOV     ATTRIB,70H              ;Highlight first file.
  343.         CALL    COLOR
  344.         JMP     TOP                     ;And start over.
  345. NEW_DIR:CMP     AL,'N'                  ;Was this a 'N'? New Dir?
  346.         JE      GON                     ;Yes.
  347.         JMP     TOP                     ;No, ignore whatever was typed.
  348. GON:    MOV     ATTRIB,7                ;Unhighlight current filename
  349.         CALL    COLOR                   ; if we can (can't if marked).
  350.         MOV     CURSOR_X,0
  351.         MOV     CURSOR_Y,24
  352.         CALL    SET_CURSOR              ;Get set for 'New Dir: ' prompt.
  353.         MOV     AH,9                    ;Use String Print Service.
  354.         MOV     CX,80                   ;First clear prompt line.
  355.         MOV     AL,' '
  356.         MOV     BX,7
  357.         INT     10H                     ;Using INT 10H.
  358.         MOV     CURSOR_X,0
  359.         MOV     CURSOR_Y,24
  360.         CALL    SET_CURSOR
  361.         MOV     AH,9                    ;Print out New Dir prompt here.
  362.         MOV     DX,OFFSET NEW_DIR_PROMPT
  363.         INT     21H
  364.         MOV     AH,0AH                  ;Now use buffered input to beginning
  365.         MOV     BX,80H                  ; of DTA (where the first pathname
  366.         MOV     DX,80H                  ; went anyway).
  367.         MOV     BYTE PTR [BX],32        ;32 bytes max.
  368.         INT     21H
  369.         JMP     DIREX                   ;And start ALL over.
  370. OUT:    INT     20H                     ;Finish for 'Q'.
  371. DIREX   ENDP
  372.  
  373. GET_MARKED_FILE PROC    NEAR    ;This sets up SOURCE and TARGET.
  374.         ;CX=FF --> No more to be found.
  375. BEGI:   MOV     AH,8            ;Prepare to read mark byte from screen.
  376.         ADD     CURSOR_X,12     ;Right after the filename -- in screen
  377.         CALL    SET_CURSOR      ; buffer!
  378.         MOV     BX,0
  379.         INT     10H             ;Read mark byte.
  380.         SUB     CURSOR_X,12     ;And immediately reset cursor.
  381.         CALL    SET_CURSOR
  382.         CMP     AL,0FFH         ;Is this file marked?
  383.         JE      FINI            ;Yes, have found it, return.
  384.         CALL    INC_CURSOR      ;No, check next file.
  385.         CMP     DX,0FFH         ;Any more files left to check?
  386.         JNE     BEGI            ;Yes, loop again.
  387.         MOV     CX,0FFH         ;No, no more to be found, set the flag.
  388.         JMP     OUTER           ;And exit.
  389. FINI:   MOV     CX,0            ;Set CX=0 --> more available.
  390.         MOV     SI,SOURCE_PATH_END
  391.         CALL    GET_FILE_NAME   ;Set up SOURCE.
  392.         CMP     COPY_FLAG,1     ;Is this a copy? Should we set up TARGET too?
  393.         JNE     OUTER           ;No.
  394.         MOV     SI,TARGET_PATH_END  ;Yes.
  395.         CALL    GET_FILE_NAME
  396. OUTER:  RET                     ;And return.
  397. GET_MARKED_FILE ENDP
  398.  
  399. GET_FILE_NAME   PROC    NEAR
  400.         ;Call with DS:SI as address to put filename at.
  401.         PUSH    CX              ;Push what is used.
  402.         PUSH    SI
  403.         PUSH    WORD PTR CURSOR_X
  404.         MOV     AH,8            ;Prepare to read from screen.
  405.         MOV     BX,0
  406.         MOV     CX,12           ;Twelve possible letters.
  407. LOOPB:  MOV     AH,8            ;Loop and read 'em.
  408.         INT     10H
  409.         INC     CURSOR_X        ;Move to next screen position.
  410.         CALL    SET_CURSOR
  411.         MOV     DS:[SI],AL      ;Store this byte at location we are supposed 
  412.         INC     SI              ; to build filename at.
  413.         LOOP    LOOPB           ;Loop again until done.
  414.         MOV     BYTE PTR DS:[SI],0      ;Make it an ASCIIZ string.
  415.         POP     WORD PTR CURSOR_X       ;And now restore all.
  416.         POP     SI
  417.         CALL    SET_CURSOR
  418.         POP     CX
  419.         RET                     ;Return to calling program.
  420. GET_FILE_NAME   ENDP
  421.  
  422. COLOR   PROC    NEAR            ;Highlights and Unhighlights filenames.
  423.         PUSH    CX              ;If file is marked, will NOT Unhighlight.
  424.         PUSH    WORD PTR CURSOR_X
  425.         MOV     CX,12           ;Twelve characters in filename.
  426.         CMP     ATTRIB,7        ;Are we unmarking?
  427.         JNE     HERE            ;No.
  428.         MOV     AH,8            ;Yes, check if file is marked.
  429.         ADD     CURSOR_X,12     ;Read in mark byte from screen directly.
  430.         CALL    SET_CURSOR
  431.         MOV     BX,0
  432.         INT     10H
  433.         SUB     CURSOR_X,12     ;And reset cursor at once.
  434.         CALL    SET_CURSOR
  435.         CMP     AL,0FFH         ;Was this a marked file?
  436.         JE      FINE            ;Yes, leave w/o unmarking.
  437. HERE:   MOV     BX,0            ;No, move new ATTRIB into place.
  438.         MOV     AH,8            ;Prepare to write to screen.
  439.         INT     10H
  440.         PUSH    CX
  441.         MOV     CX,1
  442.         MOV     BL,ATTRIB       ;Write with attribute ATTRIB.
  443.         MOV     AH,9            ;With Service 9.
  444.         INT     10H
  445.         POP     CX
  446.         INC     CURSOR_X        ;Move on to next letter.
  447.         CALL    SET_CURSOR
  448.         LOOP    HERE            ;And go back until we're done.
  449. FINE:   POP     WORD PTR CURSOR_X
  450.         CALL    SET_CURSOR      ;Finish and return.
  451.         POP     CX
  452.         RET
  453. COLOR   ENDP
  454.  
  455. DISPLAY PROC    NEAR            ;Puts filenames on the screen.
  456.         MOV     DI,SOURCE       ;Was a pathname specified originally?
  457.         MOV     D1_FLAG,1
  458.         MOV     SI,82H
  459.         MOV     SOURCE_PATH_END,SOURCE
  460.         MOV     BX,80H
  461.         CMP     BYTE PTR [BX],0 ;Not if this byte is a 0.
  462.         JE      DSPLAY2         ;No need to check on '\'.                     
  463. TRANS2: CMP     BYTE PTR [SI],13        ;Make this an ASCIIZ string.
  464.         JE      PUT0            
  465.         MOVSB                           ;Transfer byte by byte to SOURCE.
  466.         CMP     BYTE PTR [SI-1],'\'     ;Is this the end of a pathname?
  467.         JE      STOR                    ;Yes, mark position.
  468.         CMP     BYTE PTR [SI-1],':'     ;Is this a ":" -- also end of pathname.
  469.         JNE     TRANS2                  ;No, keep checking.
  470. STOR:   MOV     SOURCE_PATH_END,DI      ;Store end of pathname here.
  471.         
  472.         PUSH    SI                      ;POSSIBLE end of pathname discovered.
  473.         PUSH    DI                      ;Save the "filename" that comes after.
  474.         LEA     DI,FILENAME
  475.         MOV     CX,10                   ;First clear the storage area.
  476.         MOV     AL,0                    ;With 0s.
  477. REP     STOSB
  478.         LEA     DI,FILENAME             ;SI is already set.
  479.         MOV     CX,9                    ;Transfer from [SI] to [DI].
  480. ONEBY:  CMP     BYTE PTR [SI],13        ;End of "filename"?
  481.         JNE     MOVE                    ;No, move this byte too.
  482.         MOV     BYTE PTR [DI],0         ;Yes, make FILENAME ASCIIZ.
  483.         JMP     SHORT FIN0
  484. MOVE:   MOVSB                           ;Transfer 1 byte.
  485.         LOOP    ONEBY                   ;And keep going until "filename" done.
  486. FIN0:   POP     DI
  487.         POP     SI                      ;Restore SI and DI.
  488.  
  489.         JMP     TRANS2
  490. PUT0:   MOV     BYTE PTR [DI],0         ;Put the Z in ASCIIZ.
  491.         MOV     TEST_PATH_END,DI        ;Save this in case no filename given.
  492.  
  493.         MOV     NOFILE_FLAG,0           ;For DISPLAY, set NOFILE_FLAG to 0.
  494.         JMP     CHKFIL
  495. DSPLAY2:MOV     D1_FLAG,0               ;Set D1_FLAG.
  496.         CMP     FILENAME,0              ;=0 if no filename given.
  497.         JNE     CHKFIL
  498.         MOV     NOFILE_FLAG,1           ;Set NOFILE_FLAG.
  499.  
  500. CHKFIL: MOV     CX,25                   ; can put other filenames at end.
  501.         MOV     CURSOR_X,0              ;Start at beginning of screen.
  502.         MOV     CURSOR_Y,0
  503.         CALL    SET_CURSOR              ;Set cursor to match.
  504. WIPE:   PUSH    CX                      ;Wipe the screen.
  505.         CALL    SET_CURSOR
  506.         MOV     CX,80
  507.         MOV     AH,9                    ;Use Service 9
  508.         MOV     BX,7
  509.         MOV     AL,0
  510.         INT     10H                     ;With INT 10H.
  511.         POP     CX
  512.         INC     CURSOR_Y                ;Keep going on this line.
  513.         LOOP    WIPE                    ;Loop over all 25 lines.
  514.         MOV     CURSOR_X,6              ;Set up for prompt.
  515.         MOV     CURSOR_Y,24
  516.         CALL    SET_CURSOR              ;Put the general prompt on.
  517.         MOV     AH,9
  518.         MOV     DX,OFFSET PROMPT
  519.         INT     21H
  520.         MOV     CURSOR_X,0              ;Reset to beginning of the screen.
  521.         MOV     CURSOR_Y,0
  522.         CALL    SET_CURSOR
  523.         MOV     DI,TEST_PATH_END                              
  524.         CMP     NOFILE_FLAG,1           ;If no filename given, skip first search
  525.         JE      TSLASH
  526.         CMP     BYTE PTR [DI-1],'\'     ;Was a filename given?
  527.         JE      NOFILE          
  528.         CMP     D1_FLAG,1               ;Are we doing DISPLAY or DSPLAY2?
  529.         JE      PUTA                    ;In DISPLAY, filename all set.
  530.         CMP     FILENAME,0              ;Did FILENAME find files first time?
  531.         JE      PUTA
  532.         MOV     CX,10
  533.         MOV     SI,OFFSET FILENAME      ;Use FILENAME instead of WILCARDS.
  534.         MOV     DI,SOURCE_PATH_END
  535. REP     MOVSB
  536. PUTA:   MOV     AH,4EH                  ;Search for matches to filename.
  537.         MOV     DX,SOURCE               ;QQQ
  538.         INT     21H                     ;Was a filename given?
  539.         JNC     MATCH1                  ;Yes, no need for wildcards.
  540. NOFILE: MOV     FILENAME,0              ;No given filename worked in DISPLAY.
  541. TSLASH: CMP     TEST_PATH_END,0         ;Any pathname characters typed?
  542.         JNE     SLASH                   ;Yes, check '\'
  543.         MOV     SOURCE_PATH_END,SOURCE  ;No, use SOURCE to load wildcards at.
  544.         MOV     DI,SOURCE_PATH_END      ;Set up widcards -- *.* -- at end of 
  545.         JMP     PUTW                    ; SOURCE.
  546. SLASH:  MOV     DI,TEST_PATH_END     
  547.         MOV     SOURCE_PATH_END,DI
  548.         CMP     BYTE PTR [DI-1],'\'     ;If there is no '\',
  549.         JE      PUTW                    ; put one in.
  550.         MOV     BYTE PTR [DI],'\'
  551.         INC     DI   
  552.         INC     SOURCE_PATH_END         ;INC DI and Path_End by adding '\'.
  553. PUTW:   MOV     CX,4                    
  554.         MOV     SI,OFFSET WILDCARDS     
  555. REP     MOVSB                           ;Move *.* into place.
  556. SRC:    MOV     AH,4EH                  ;Search for matches to wildcard
  557.         MOV     DX,SOURCE
  558.         INT     21H                     ;Look for match.
  559.         JC      ENDER                   ;If error, leave.
  560. MATCH1: MOV     DX,0
  561.         MOV     AH,2
  562.         INT     10H
  563.         CALL    PRINT                   ;Print out filename with PRINT.
  564.         MOV     CX,120                  ;120 files max.
  565. LOOPER: MOV     AH,4FH                  ;Search for next match, if there is one.
  566.         INT     21H
  567.         JC      ENDER                   ;If none, leave.
  568.         MOV     DISP_FLAG,0FFH          ;This is a DISPLAY, do not check for
  569.         CALL    INC_CURSOR              ; empty screen ahead of highlight.
  570.         MOV     DISP_FLAG,0             ;Use DISP_FLAG as signal to INC_CURSOR.
  571.         CALL    PRINT
  572.         MOV     DX,OFFSET SOURCE        ;Get ready for search.
  573.         LOOP    LOOPER
  574. ENDER:  MOV     CURSOR_X,0              ;Set cursor to top of screen when done.
  575.         MOV     CURSOR_Y,0
  576.         CALL    SET_CURSOR
  577.         RET
  578. DISPLAY ENDP
  579.  
  580. INC_CURSOR      PROC    NEAR            ;This moves the highlight to the next
  581.         PUSH    CX                      ;filename on the screen.
  582.         MOV     DL,CURSOR_X             ;Where are we now?
  583.         MOV     DH,CURSOR_Y
  584.         MOV     TEMPX,DL                ;Store in temporary locations.
  585.         MOV     TEMPY,DH
  586.         ADD     DL,13                   ;See if we can move to the right.
  587.         CMP     DL,75                   ;Past edge of screen?
  588.         JL      FIN                     ;No, go ahead.
  589.         MOV     DL,0                    ;Yes, wrap around.
  590.         INC     DH
  591. FIN:    MOV     CURSOR_X,DL             ;Store new positions.
  592.         MOV     CURSOR_Y,DH
  593.         MOV     DX,0                    ;Return OK signal.
  594.         CALL    SET_CURSOR              ;And set new cursor.
  595.         CMP     DISP_FLAG,0             ;Is this a DISPLAY?
  596.         JNE     SET                     ;Yes, don't check if we are pointing to
  597.         MOV     SI,SOURCE_PATH_END      ; a filename.
  598.         CALL    GET_FILE_NAME           ;Are we pointing to a filename?
  599.         CMP     BYTE PTR DS:[SI],' '
  600.         JA      SET                     ;Yes.
  601.         SUB     CURSOR_X,13             ;No, move back one position.
  602.         CMP     CURSOR_X,0
  603.         JG      LEAV                    ;And exit.
  604.         MOV     DL,TEMPX
  605.         MOV     CURSOR_X,DL             ;Restore temporary (original) positions.
  606.         MOV     DH,TEMPY
  607.         MOV     CURSOR_Y,DH
  608. LEAV:   CALL    SET_CURSOR              ;CURSOR_X and CURSOR_Y all set, now
  609.         MOV     DX,0FFH                 ; actually do set cursor.
  610. SET:    POP     CX
  611.         RET                             ;And Return.
  612. INC_CURSOR      ENDP
  613.                                         ;This sets cursor location on screen.
  614. SET_CURSOR      PROC    NEAR
  615.         PUSH    AX                      ;Save AX.
  616.         MOV     DL,CURSOR_X             ;Get position cursor should be at.
  617.         MOV     DH,CURSOR_Y
  618.         MOV     AH,2
  619.         INT     10H                     ;Use Service 2, INT 10H, and move it 
  620.         POP     AX                      ; there.
  621.         RET                             ;And return.
  622. SET_CURSOR      ENDP
  623.  
  624. PRINT   PROC    NEAR                    ;This prints out filenames.
  625.         PUSH    CX
  626.         MOV     DX,80H+30               ;Point to name.
  627.         MOV     BX,DX
  628.         MOV     CX,13
  629. LOOPA:  CMP     BYTE PTR [BX],0         ;Is it a 0?
  630.         JE      FOUND                   ;Yes, end of filename found.
  631.         INC     BX
  632.         LOOP    LOOPA
  633. FOUND:  MOV     BYTE PTR DS:[BX+1],'$'  ;Put '$' in place.
  634.         MOV     AH,9                    ;Use String Print.
  635.         INT     21H
  636.         POP     CX
  637.         RET                             ;Return.
  638. PRINT   ENDP
  639. DATA:                                   ;Will store 62K of data for copies
  640. CODE_SEG        ENDS                    ; after this point.
  641.         END     START
  642.  
  643.