home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / asm / MISC_ASM.ZIP / MORE.ASM < prev    next >
Encoding:
Assembly Source File  |  1987-02-18  |  6.1 KB  |  142 lines

  1. page ,132
  2. Title     MORE: reworked version of the DOS "more" utility
  3.  
  4. ;  by Tom Hanlin III    February 18, 1987
  5.  
  6.  
  7. Sseg                segment byte stack 'prog'    ; dummy stack segment
  8. Sseg                ends
  9.  
  10.  
  11. Cseg                segment byte public 'prog'
  12.                     assume cs:Cseg, ds:Cseg, ss:Sseg
  13.  
  14.                     org    100h
  15.  
  16. MAIN                proc   far
  17.                     mov    ah,30h
  18.                     int    21h                   ; get DOS version
  19.                     cmp    al,2                  ; is it DOS 2.0 or higher?
  20.                     jae    GoodDOSversion        ;   yes, continue
  21.  
  22.                     mov    dx,offset ErrorMsg1
  23.                     mov    ah,9
  24.                     int    21h                   ; display error message
  25. Done:               int    20h                   ; exit
  26.  
  27. GoodDOSversion:     mov    ah,0Fh
  28.                     int    10h                   ; get video mode
  29.                     mov    ScreenCols,ah         ; store columns/screen
  30.  
  31.                     mov    dx,offset CrLf
  32.                     mov    ah,9
  33.                     int    21h                   ; print a <CR><LF>
  34.  
  35. ; The below twiddling sees that we get our text from the original standard
  36. ; input, but that we input from the keyboard at "-- More --" prompts.
  37.                     xor    bx,bx                 ; stdin device handle
  38.                     mov    ah,45h
  39.                     int    21h                   ; duplicate handle
  40.                     mov    di,ax                 ; save new one
  41.                     mov    ah,3Eh
  42.                     int    21h                   ; close old one
  43.                     mov    bx,2                  ; stderr device handle
  44.                     mov    ah,45h
  45.                     int    21h                   ; duplicate handle
  46.  
  47. MoreLoop:           cld
  48.                     mov    dx,offset CrLf +3     ; for buffer, use 4K...
  49.                     mov    cx,4096               ; ...past the program end
  50.                     mov    bx,di                 ; old stdin file handle
  51.                     mov    ah,3Fh
  52.                     int    21h                   ; read from file
  53.                     jc     Done                  ;   exit on error
  54.                     or     ax,ax                 ; end of input?
  55.                     jz     Done                  ;   yes, exit
  56.                     mov    cx,ax                 ; chars actually gotten
  57.                     mov    si,dx                 ; buffer ptr
  58.  
  59. GetChr:             lodsb                        ; get a char from the buffer
  60.  
  61.                     mov    dh,Column             ; get column position
  62.  
  63.                     cmp    al,13                 ; check chr
  64.                     ja     NormalChr             ;   not control, so normal
  65.                     jne    NotCR                 ;   not <CR>, keep checking
  66.                     mov    dh,1                  ; reset column count
  67.                     jmp    short DisplayChr      ;   go display chr
  68.  
  69. NotCR:              cmp    al,10                 ; linefeed?
  70.                     jne    NotLF                 ;   no, keep checking
  71.                     inc    byte ptr Row          ; increment row count
  72.                     jmp    short DisplayChr      ;   go display chr
  73.  
  74. NotLF:              cmp    al,8                  ; backspace?
  75.                     jne    NotBS                 ;   no, keep checking
  76.                     cmp    dh,1                  ; can we backspace?
  77.                     je     NextChr               ;   no, ignore it
  78.                     dec    dh                    ; yes, do it
  79.                     jmp    short DisplayChr      ;   go display chr
  80.  
  81. NotBS:              cmp    al,9                  ; tab?
  82.                     jne    NotHT                 ;   no, keep checking
  83.                     add    dh,7                  ; move to next tab position
  84.                     and    dh,0F8h               ; keep in bounds
  85.                     inc    dh
  86.                     jmp    short DisplayChr      ;   go display chr
  87.  
  88. NotHT:              cmp    al,7                  ; bell?
  89.                     je     DisplayChr            ;   yes, go "display" it
  90.  
  91. NormalChr:          inc    dh                    ; increment column
  92.                     cmp    dh,ScreenCols         ; is it still on the screen?
  93.                     jbe    DisplayChr            ;   yes, display chr
  94.                     inc    byte ptr Row          ; move to next line
  95.                     mov    dh,1                  ; restart column count
  96.  
  97. DisplayChr:         mov    Column,dh             ; save new column position
  98.  
  99.                     mov    dl,al
  100.                     mov    ah,2
  101.                     int    21h                   ; display chr to stdout
  102.  
  103.                     mov    ah,Row                ; get current row
  104.                     cmp    ah,ScreenRows         ; is it still on the screen?
  105.                     jb     NextChr               ;   yes, move along...
  106.  
  107.                     mov    dx,offset PromptMsg
  108.                     mov    ah,9
  109.                     int    21h                   ; display prompt message
  110.  
  111.                     mov    ax,0C01h
  112.                     int    21h                   ; clear kbd and wait for key
  113.  
  114.                     mov    dx,offset CrLf        ; display a <CR><LF>
  115.                     mov    ah,9
  116.                     int    21h
  117.  
  118.                     mov    byte ptr Column,1     ; reset column
  119.                     mov    byte ptr Row,1        ; reset row
  120.  
  121.                     dec    si
  122.                     inc    cx
  123. NextChr:            loop   GetChrVec             ;   go through buffer
  124.                     jmp    MoreLoop              ;   load another buffer
  125. GetChrVec:          jmp    GetChr
  126. MAIN                endp
  127.  
  128.  
  129. ScreenRows   db 25                ; default to 25 lines per screen
  130. ScreenCols   db ?                 ; fill this in depending on screen mode
  131.  
  132. Column       db 1                 ; start at first column
  133. Row          db 1                 ; ...and first row
  134.  
  135. PromptMsg    db 13,"-- More --$"
  136. ErrorMsg1    db "MORE: Wrong DOS version"
  137. CrLf         db 13,10,"$"
  138.  
  139. Cseg                ends
  140.  
  141.                     end    MAIN
  142.