home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / usoftpd.zip / SHOW.ASM < prev    next >
Assembly Source File  |  1987-07-31  |  9KB  |  326 lines

  1.       PAGE      60,132
  2.       TITLE      SHOW
  3.  
  4. ; Program SHOW.ASM
  5. ; Purpose Text file displayer
  6. ; Input      File name from command line or prompt
  7. ; Output  Display file to screen
  8.  
  9.       DOSSEG
  10.       .MODEL  small
  11.  
  12.       INCLUDE dos.inc
  13.       INCLUDE bios.inc
  14.  
  15.       .STACK  100h
  16.  
  17.       .DATA
  18.  
  19. ; Status line
  20.  
  21.       PUBLIC  statline,linenum
  22. statline  DB      " Line:         "
  23. statfile  DB      " File:                "
  24. stathelp  DB      " Quit: ESC    Move:   PGUP PGDN HOME END "
  25. linenum      DW      1
  26.  
  27. ; Variables for    screen handling
  28.  
  29.       PUBLIC  cell,rows,columns,vidadr,statatr,scrnatr,cga
  30. cell      LABEL      WORD        ; Cell (character and attribute)
  31. char      DB      " "        ; Initialize to    space
  32. attr      DB      ?        ; Attribute
  33.  
  34. columns      EQU      80        ; Number of columns
  35. rows      DW      24        ; Number of rows - status line takes one more
  36. mode      DB      ?        ; Initial mode
  37. pag      DB      ?        ; Initial display page
  38. newvid      DB      0        ; Video    change flag
  39. cga      DB      1        ; CGA flag - default yes
  40.  
  41. vidadr      DW      0B800h    ; Video    buffer address - default CGA
  42. mono      EQU      0B000h    ; Monochrome address
  43. statatr      DB      030h        ; Color    default    - black    on cyan
  44. bwstat      EQU      070h        ; B&W default -    black on white
  45. scrnatr      DB      017h        ; Color    default    - white    on blue
  46. bwscrn      EQU      007h        ; B&W default -    white on black
  47.  
  48. ; Variables for    buffer and file    handling
  49.  
  50.       PUBLIC  buffer,pbuffer,sbuffer,fsize,namebuf
  51. buffer      LABEL      DWORD
  52. pbuffer      DW      0        ; Position in buffer (offset)
  53. sbuffer      DW      ?        ; Base of buffer (segment)
  54. lbuffer      DW      ?        ; Length of buffer
  55. fhandle      DW      ?        ; Holds    file handle on open
  56. fsize      DW      ?        ; File size after dosopen
  57.  
  58. prompt      DB      13,10,13,10,"Enter filename: $"
  59. prompt2      DB      13,10,"File problem. Try again? $"
  60. namebuf      DB      66,?
  61. filename  DB      66 DUP (0)        ; Buffer for file name
  62.  
  63. err1      DB      13,10,"Must have DOS 2.0 or higher",13,10,"$"
  64. err2      DB      13,10,"File too big",13,10,"$"
  65.  
  66. ; Call table
  67.  
  68. exkeys      DB      71,72,73,79,80,81    ; Extended key codes
  69. lexkeys      EQU      $-exkeys        ; Table    of keys
  70. extable      DW      homek
  71.       DW      upk
  72.       DW      pgupk
  73.       DW      endk
  74.       DW      downk
  75.       DW      pgdnk
  76.       DW      nonek
  77.  
  78.       .CODE
  79.       EXTRN      pager:PROC,isEGA:PROC    ; Routines in other module
  80. start:      mov      ax,@DATA        ; Initialize data segment
  81.       mov      ds,ax
  82.  
  83.       cli                ; Turn off interrupts
  84.       mov      ss,ax            ; Make SS and
  85.       mov      sp,OFFSET STACK    ;   SP relative    to DGROUP
  86.       sti
  87.  
  88. ; Adjust memory    allocation
  89.  
  90.       mov      bx,sp            ; Convert stack    pointer    to paragraphs
  91.       mov      cl,4            ;   to get stack size
  92.       shr      bx,cl
  93.       add      ax,bx            ; Add SS to get    end of program
  94.       mov      bx,es            ; Get start of program
  95.       sub      ax,bx            ; Subtract start from end
  96.       @ModBlok ax            ; Release memory after program
  97.  
  98. ; Allocate dynamic memory for file buffer
  99.  
  100.       @GetBlok 0FFFh        ; Try to allocate 64K
  101.       mov      sbuffer,ax        ; Save buffer segment
  102.       mov      lbuffer,bx        ; Save actual length allocated
  103.  
  104. ; Check    DOS
  105.  
  106.       @GetVer            ; Get DOS version
  107.       cmp      al,2            ; Requires DOS 2.0
  108.       jge      video
  109.       @DispStr err1            ;   else error and quit
  110.       int      20h
  111.  
  112. ; Adjust for current mode and and video    adapter
  113.  
  114. video:      call      isEGA            ; EGA (or VGA)?
  115.       or      ax,ax            ; If 0 must be CGA or MA
  116.       je      modechk        ; Leave    default
  117.       mov      rows,ax        ; Load rows
  118.       dec      cga            ; Not CGA
  119.  
  120. modechk:  @GetMode            ; Get video mode
  121.       mov      mode,al        ; Save initial mode and    page
  122.       mov      pag,bh
  123.       mov      dl,al            ; Work on copy
  124.       cmp      dl,7            ; Is it    mono 7?
  125.       je      loadmono        ; Yes? Set mono
  126.       cmp      dl,15            ; Is it    mono 15?
  127.       jne      graphchk        ; No? Check graphics
  128. loadmono: mov      vidadr,mono        ; Load mono address
  129.       mov      statatr,bwstat    ; Set B&W defaults for status line
  130.       mov      scrnatr,bwscrn    ;   and    screen background
  131.       dec      cga            ; Not CGA
  132.       cmp      al,15            ; Is it    mono 15?
  133.       jne      cmdchk        ; No? Done
  134.       mov      dl,7            ; Yes? Set standard mono
  135.       jmp      SHORT    chmode
  136.  
  137. graphchk: cmp      dl,7            ; 7 or higher?
  138.       jg      color            ; 8 to 14 are color (7 and 15 done)
  139.       cmp      dl,4            ; 4 or higher?
  140.       jg      bnw            ; 5 and    6 are probably black and white
  141.       je      color            ; 4 is color
  142.       test      dl,1            ; Even?
  143.       jz      bnw            ; 0 and    2 are black and    white
  144. color:                    ; 1 and    3 are color
  145.       cmp      dl,3            ; 3?
  146.       je      cmdchk        ; Yes? Done
  147.       mov      dl,3            ; Change mode to 3
  148.       jmp      SHORT    chmode
  149.  
  150. bnw:      mov      statatr,bwstat    ; Set B&W defaults for status line
  151.       mov      scrnatr,bwscrn    ;   and    screen background
  152.       cmp      dl,2            ; 2?
  153.       je      cmdchk        ; Yes? Done
  154.       mov      dl,2            ; Make it 2
  155.  
  156. chmode:      @SetMode dl            ; Set video mode
  157.       @SetPage 0            ; Set video page
  158.       mov      newvid,1        ; Set flag
  159.  
  160. ; Try to open command line file
  161.  
  162. cmdchk:      mov      bl,es:[80h]        ; Get length
  163.       sub      bh,bh
  164.       mov      WORD PTR es:[bx+81h],0; Convert to ASCIIZ
  165.       push      ds
  166.       @OpenFil 82h,0,es        ; Open argument
  167.       pop      ds
  168.       jc      getname        ; If error, get    from prompt
  169.       mov      fhandle,ax        ;   else save handle
  170.       push      ds
  171.       @GetFirst 82h,,es        ; Let DOS convert to file name
  172.       pop      ds
  173.       jnc      opened        ; If OK    file is    open
  174.  
  175. ; Prompt for file
  176.  
  177. getname:  @DispStr prompt        ; Prompt for file
  178.       @GetStr namebuf,0        ; Get response as ASCIIZ
  179.       @OpenFil filename,0        ; Try to open response
  180.       jc      badfile        ; If successful, continue
  181.       mov      fhandle,ax        ; Save handle
  182.       @GetFirst filename        ; Let DOS convert to file name
  183.       jnc      opened        ; If OK, file is opened
  184.  
  185. badfile:  @DispStr prompt2        ;    else prompt to try    again
  186.       @GetKey 0,1,0
  187.       and      al,11011111b        ; Convert key to uppercase
  188.       cmp      al,"Y"        ; If yes,
  189.       je      getname        ;   try    again
  190.       jmp      quit            ;   else quit
  191.  
  192. ; Copy file name to status line
  193.  
  194. opened:      mov      si,9Eh        ; Load FCB as as source
  195.       mov      di,OFFSET statfile[7]    ; Load status line as destination
  196.       mov      al,es:[si]        ; Load first byte
  197.       inc      si
  198. copy:      mov      [di],al        ; Save and load    bytes until 0
  199.       inc      di
  200.       mov      al,es:[si]
  201.       inc      si
  202.       or      al,al            ; Check    for 0
  203.       loopne  copy
  204.  
  205. ; Check    file size
  206.  
  207.       @GetFilSz fhandle        ; Get file size
  208.  
  209.       or      dx,dx            ; Larger than 64K?
  210.       jne      big            ; Yes? Too big
  211.       mov      fsize,ax        ; Save file size
  212.       mov      cx,4            ; Convert to paragraphs
  213.       shr      ax,cl
  214.       cmp      ax,lbuffer        ; Is it    larger than buffer
  215.       jle      fileread        ; No? Continue
  216.  
  217. big:      @DispStr err2            ;   else error
  218.       @Exit      2
  219.  
  220. fileread: push      ds
  221.       @Read      buffer,fsize,fhandle    ; Read file
  222.       pop      ds
  223.       jnc      readok        ; If no    read error continue
  224.       jmp      getname        ;   else try again
  225.  
  226. ; Search back for EOF marker and adjust    if necessary
  227.  
  228. readok:      mov      di,ax            ; Load file length
  229.       push      es            ; Save ES and load buffer segment
  230.       mov      es,sbuffer
  231.       std                ; Look backward    for 255    characters
  232.       mov      cx,0FFh
  233.       mov      al,1Ah        ; Search for EOF marker
  234.       repne      scasb
  235.       cld
  236.       jcxz      noeof            ; If none, we're OK
  237.       inc      di            ;   else adjust    and save file size
  238.       mov      fsize,di
  239.  
  240. noeof:      pop      es
  241.       @SetCurPos 0,43        ; Turn off cursor by moving off    screen
  242.  
  243. ; Display first    page
  244.  
  245.       xor      ax,ax            ; Start    at 0
  246.       push      ax
  247. firstpg:  call      pager
  248.  
  249. ; Handle keys
  250.  
  251. nextkey:  @GetKey 0,0,0            ; Get a    key
  252. nextkey2: cmp      al,0            ; Is it    a null?
  253.       je      extended        ; Yes? Must be extended    code
  254.  
  255.       cmp      al,27            ; Is it    ESCAPE?
  256.       jne      nextkey        ; No? Ignore unknown command
  257.  
  258. quit:      @ClosFil fhandle        ; Yes? Close file
  259.       @FreeBlok sbuffer        ; Release buffer
  260.       cmp      newvid,1        ; Restore video?
  261.       jne      thatsall        ; No?
  262.       @SetMode mode            ; Restore video    mode, page, and    cursor
  263.       @SetPage pag
  264. thatsall: mov      dx,rows        ; Load last row    and first column
  265.       xchg      dl,dh
  266.       mov      cx,dx            ; Make row the same
  267.       mov      dl,79
  268.       @Scroll 0            ; Clear    last line
  269.       sub      dl,dl
  270.       @SetCurPos            ; Set cursor
  271.  
  272.       @Exit      0            ; Quit
  273.  
  274. extended: @GetKey 0,0,0            ; Get extended code
  275.       push      es
  276.       push      ds            ; Load DS into ES
  277.       pop      es
  278.       mov      di,OFFSET exkeys    ; Load address and length of key list
  279.       mov      cx,lexkeys+1
  280.       repne      scasb            ; Find position
  281.       pop      es
  282.       sub      di,(OFFSET exkeys)+1    ; Point    to key
  283.       shl      di,1            ; Adjust pointer for word addresses
  284.       call      extable[di]        ; Call procedure
  285.       jmp      nextkey
  286.  
  287. homek:      mov      pbuffer,0        ; HOME - set position to 0
  288.       push      pbuffer
  289.       mov      linenum,1
  290.       call      pager
  291.       retn
  292.  
  293. upk:      mov      ax,-1            ; UP - scroll back 1 line
  294.       push      ax
  295.       call      pager
  296.       retn
  297.  
  298. pgupk:      mov      ax,rows        ; PGUP - Page back
  299.       neg      ax
  300.       push      ax
  301.       call      pager
  302.       retn
  303.  
  304. endk:      mov      ax,fsize        ; END -    Get last byte of file
  305.       mov      pbuffer,ax        ; Make it the file position
  306.       mov      linenum,-1        ; Set illegal line number as flag
  307.       mov      ax,rows        ; Page back
  308.       neg      ax
  309.       push      ax
  310.       call      pager
  311.       retn
  312.  
  313. downk:      mov      ax,1            ; DOWN - scroll    forward    1 line
  314.       push      ax
  315.       call      pager
  316.       retn
  317.  
  318. pgdnk:      push      rows            ; PGDN - page forward
  319.       call      pager
  320.       retn
  321.  
  322. nonek:      retn                ; Ignore unknown key
  323.  
  324.       END     start
  325.  
  326.