home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / txtutl / lst60asm.arc / LIST60.ASM
Encoding:
Assembly Source File  |  1986-04-08  |  35.8 KB  |  1,041 lines

  1.         Page    80,132
  2.         Title   LIST --- Display contents of ASCII file
  3.  
  4.         Comment |
  5.  
  6. Command LIST
  7. ----------------
  8.  
  9.  Purpose:  To display the contents of an ASCII file, line by
  10.            line, with operator positioning commands.
  11.  
  12.  Format:   LIST  [d:][path]filename[.ext]
  13.  
  14.  Remarks:  An ASCII file of any size may be listed.
  15.  
  16.         On the COMMAND line, enter a letter or control key:-
  17.  
  18.         Letter(s)       Control key     Function
  19.         -----------     ------------    ------------------------
  20.                         Enter           continue to next page
  21.         Q, X            ESCape          terminate and exit to DOS
  22.         T               HOME            restart from first block (top)
  23.         B               END             skip to end of file (bottom)
  24.         D               PgDn            scroll down one page
  25.         U               PgUp            scroll up one page
  26.         H or ?          F1              list commands (HELP)
  27.         L               left arrow      scroll left 20 columns
  28.         R               right arrow     scroll right 20 columns
  29.         P               up arrow        up one (previous) line
  30.         N               down arrow      down one (next) line
  31.  
  32.         /text                           find 'text'
  33.         A               F3              find next occurance of 'text'
  34.  
  35.                         ctl-HOME        restart from CURRENT block
  36.                         ctl-PgUp        restart from first block (TOP)
  37.                         ctl-PgDn        skip to end of file (BOTTOM)
  38.                         ctl-left-arrow  reset scroll to column 1
  39.  
  40.                         F1              Help
  41.                         F3              Find next
  42.                         F10             Exit
  43.         ALT S                           Strip/Don't strip MSBit             -DS
  44.         ALT C                           Display/Don't display chars 0-31    -DS
  45.  
  46.  Restrictions:
  47.         All positioning is relative to the current block in
  48.         storage. The size of the block depends on the amount of
  49.         memory available, up to 64K.
  50.  
  51.         The maximum record length currently allowed is 255.
  52.  
  53.         Logical records (ending in LF and/or CR) are placed
  54.         into the DOS screen buffer - mono or color display.
  55.         (patched, prior version didn't accept records ending in CR only)    -DS
  56.  
  57.         PC-DOS Version 2.0 or later is required.
  58.  
  59.         ANSI.SYS is NOT required.
  60.  
  61.  Scanning for text:
  62.         To scan for a character string, type a slash (/)
  63.         followed by one or more (up to 32) characters. The
  64.         scan text, but not the slash, is displayed on the
  65.         command line. The entire file, from the current line,
  66.         is scanned.
  67.  
  68.         If the text is found, the line containing it is displayed
  69.         as a blinking line.
  70.  
  71.         If the text is NOT found, an error message is displayed
  72.         and the display remains unchanged.
  73.  
  74.  Screen attributes:
  75.         There are three classes of attributes used. One for
  76.         normal display lines - lines 2 to 24, another for
  77.         special lines - lines 1 and 25, and a third for the
  78.         background color.
  79.  
  80.         These attributes may be changed by using DEBUG:
  81.  
  82.          at offset 11C = 09     ;special lines, hi-lighted or lt.blue
  83.          at offset 11D = 02     ;normal lines, green
  84.          at offset 11E = 00     ;background, black
  85.  
  86.         If these values don't match, you have a different version.
  87.         ----------------------------------------------------------
  88.  
  89.         Written by Vernon Buerg for the IBM PC using DOS 2.0,
  90.         and is supplied for public domain use. Not for sale or hire.
  91.  
  92.         Commands ALT S and ALT C added by David Schwartz, Jan. 1985     -DS
  93.         Change: non-displayed control characters no longer occupy a     -DS
  94.                 screen display space.                                   -DS
  95.  
  96.         Version 6.0, Jan. 23, 1985 ( Version 1.5, June 2, 1984)         -DS
  97. |
  98.         Page
  99.  
  100. Bios    Segment At 40h                  ;DOS data area
  101.         Db      16 Dup (?)
  102. Flag    Dw      ?                       ;Hardware features
  103.         Db      56 Dup (?)
  104. Cols    Dw      ?                       ;Columns on screen
  105.         Db      23 Dup (?)
  106. A6845   Dw      ?                       ;Base addr for active card
  107. Bios    Ends
  108.  
  109.  
  110. Cseg    Segment Para Public 'CODE'
  111.         Assume  CS:Cseg,DS:Cseg,ES:Nothing
  112.         Org     100h
  113. List    Proc    Far
  114.         Mov     DX,Offset Stackx        ;Local stack
  115.         Mov     SP,DX
  116.         Push    DS                      ;Standard linkage
  117.         Xor     AX,AX                   ; for DOS return
  118.         Push    AX
  119.         Mov     AH,30h                  ;Check for
  120.         Int     21h                     ; DOS 2.0 or later
  121.         Cmp     AL,2
  122.         Jb      TooBad
  123.         Jmp     Start
  124.  
  125. TooBad: Mov     DX,Offset Sorry         ;Say Version 2 required
  126.         Mov     AH,9
  127.         Int     21h
  128.         Ret
  129.         Page
  130. ;       Constants and work areas
  131.  
  132. Special Db      09h                     ;Attribute for attention
  133. Normal  Db      02h                     ;Normal display attribute
  134. Foregrd Db      07h                     ;Fill attribute
  135. Blink   Equ     0Fh                     ;Hilite for FIND (143h blinks)
  136.  
  137. CR      Equ     0Dh
  138. LF      Equ     0Ah
  139. EOF     Equ     1Ah
  140. Eor     Equ     1                       ;End-of-record
  141. Nodata  Equ     2                       ;null record
  142.  
  143. Crt_Col Dw      0                       ;Columns for display monitor
  144. Crt_Buf Dw      0                       ;Addr of display buffer
  145. Crt_Prt Dw      0                       ;Addr of display port
  146.  
  147. Index   Dw      0                       ;Current record address
  148. Reclen  Dw      0                       ; length
  149. Row     Db      2                       ; display row
  150. Col     Db      1                       ; display column
  151. Attr    Db      02h                     ; screen attribute
  152. Blknum  Db      0                       ; block number
  153. Scroll  Dw      0                       ;Scroll left/right amount
  154. First   Dw      0                       ;Ptr to top line on screen
  155. Current Dw      0                       ;Ptr to top after UP one
  156. Last    Dw      0                       ;Ptr to last record
  157.  
  158. Recaddr Dw      0                       ;addr of i/o buffer
  159. Handle  Dw      0                       ;File handle from open
  160. Psize   Dw      16                      ;Size of a paragraph
  161. Blksize Dw      0                       ;File read size
  162.  
  163. Switch1 Db      0
  164. Switch2 Db      0
  165. Numlf   Db      1                       ;line feed count
  166. Numcr   Db      0                       ;C/R count
  167.  
  168. char_msk  db     07fh                  ; character mask (7Fh or FFh)        -DS
  169. min_disp  db     ' '                   ;lowest ord char to display(0 or ' ')-DS
  170.  
  171. TextMax Db      32                      ;Keyboard buffer
  172. TextLen Db      0
  173. TextBuf Db      32 Dup (0)              ;Scan text
  174.  
  175. Prompt  Db      'Command:'
  176. Spaces  Db      32 Dup (32)             ;Scan text entered
  177.         Db      'Keys: PgUp PgDn Arrows ESC=exit ?=Help '
  178. Pr_Len  Equ     This Byte - Prompt
  179.  
  180. TextMsg Db      '*** Text not found ***'
  181. EofMsg  Db      '   *** End-of-file ***'
  182. EofLen  Equ     This Byte - EofMsg
  183.  
  184. Work    Db      'LIST '                 ;current logical record             -DS
  185. Keyin   Db      64                      ;keyboard buffer size
  186. Keyout  Db      0                       ; and length read
  187. Filenm  Db      76 Dup (0)              ;d:path\filename.ext
  188.  
  189. Askfile Db      13,10,'Enter filename: $'
  190. Openmsg Db      '  Open failed, return code='
  191. Opencod Dw      '00'
  192.         Db      '$'
  193. Code2   Db      'File not found $'
  194. Code3   Db      'Path not found $'
  195. Code4   Db      'Too many files $'
  196. Code5   Db      'Access denied  $'
  197. Sorry   Db      Cr,Lf,'Sorry, DOS 2.0 or later required',Cr,Lf,'$'
  198.  
  199.         Org     offset Work+256
  200. Workx   Equ     $-Work
  201. Stack   Db      64 Dup (0)              ;may overlay above constants
  202. Stackx  Equ     $
  203.  
  204.         Page
  205. ;
  206. ;       Command letters and keys
  207.  
  208. What1   Db      13,32,27,81     ;Cr,Sp,Esc,Q
  209.         Db      68,85,63,72     ;D,U,?,H
  210.         Db      47,82,76,84     ;/,R,L,T
  211.         Db      80,65,78,88     ;P,A,N,X
  212.         Db      66              ;B
  213. Num1    Equ     $-What1                 ;How many letters
  214.  
  215. What2   Db      77,75,73,81     ;->,<-,PgUp,PgDn
  216.         Db      71,72,61,80     ;HOME,^,F3,v
  217.         Db      59,68,79,119    ;F1,F10,END,^HOME
  218.         Db      115,132,118     ;^<-,^PgUp,^PgDn
  219.           db     46,31                 ; ALT C, ALT S                       ;-DS
  220. Num2    Db      $-What2                 ;Number of control keys
  221.  
  222. Where1  Dw      Offset NxtPage,Offset NxtPage,Offset Close, Offset Close
  223.         Dw      Offset NxtPage,Offset Back,   Offset Got_H, Offset Got_H
  224.         Dw      Offset Got_S,  Offset Right,  Offset Left,  Offset Top
  225.         Dw      Offset Up1,    Offset Got_Rs, Offset Down1, Offset Close
  226.         Dw      Offset Bottom
  227.  
  228. Where2  Dw      Offset Right,  Offset Left,   Offset Back,  Offset NxtPage
  229.         Dw      Offset Top,    Offset Up1,    Offset Got_Rs,Offset Down1
  230.         Dw      Offset Got_H,  Offset Close,  Offset Bottom,Offset Home
  231.         Dw      Offset Scroll0,Offset Top,    Offset Bottom
  232.         dw      Offset ctrl, Offset strip                           ;-DS
  233.         Page
  234.                                ; HelpMsg updated                     -DS
  235. HelpMsg Db      CR,9,'LIST 1.5(6.0) by Vernon Buerg (Mod by DS)'
  236.         Db      CR,LF
  237.         Db      CR,LF,9,'Commands and keys:'
  238.         Db      CR,LF
  239.         Db      CR,LF,9,'DY or Space ',9,9,'continue to next page'
  240.         Db      CR,LF,9,'ESC, Q, X or F10',9,' terminate'
  241.         Db      CR,LF,9,'HOME, T or Ctl PgUp',9,' restart from Top of file'
  242.         Db      CR,LF,9,'END, B or Ctl PgDn',9,' skip to Bottom of file'
  243.         Db      CR,LF,9,'Ctl Home     ',9,9,' restart from top of block'
  244.         Db      CR,LF,9,'PgDn or D    ',9,9,' scroll Down one page'
  245.         Db      CR,LF,9,'PgUp or U    ',9,9,' scroll Up one page'
  246.         Db      CR,LF,9,'H, ? or F1   ',9,9,' list Help for keys'
  247.         Db      CR,LF,9,'D or L      ',9,9,'scroll Left 20 columns'
  248.         Db      CR,LF,9,'D or R      ',9,9,'scroll Right 20 columns'
  249.         Db      CR,LF,9,'Ctl D       ',9,9,'reset scroll to column 1'
  250.         Db      CR,LF,9,' or P       ',9,9,'Previous, up one line'
  251.         Db      CR,LF,9,' or N       ',9,9,'Next, down one line'
  252.         Db      CR,LF,9,'/text        ',9,9,' find text'
  253.         Db      CR,LF,9,'A or F3      ',9,9,' find text Again'
  254.         db      CR,LF,9,"ALT S        ",9,9," do/don't Strip parity bit"
  255.         db         " (toggle)"
  256.         db      CR,LF,9,"ALT C        ",9,9," do/don't display Control "
  257.         db         " chars"
  258.  
  259.         db         " (toggle)"
  260.         Db      '$'
  261.  
  262.         Page
  263. ;
  264. ;       Initialization
  265.  
  266. Start:  Mov     BX,PgmSize              ;Length of Cseg and Stack
  267.         Mov     AH,4Ah                  ;Modify allocated memory
  268.         Int     21h                     ; using ES from entry
  269.  
  270.         Call    GetParm                 ;Get filename from command line
  271. Openit: Call    Open
  272.         Jz      Init
  273.         Ret
  274.  
  275. Close:  Mov     BX,Handle               ;End of job
  276.         Mov     AH,3Eh                  ;Close a file handle
  277.         Int     21h
  278.  
  279.         Mov     AX,0600h                ;Clear the screen
  280.         Sub     BL,BL
  281.         Mov     BH,Foregrd
  282.         Sub     CX,CX                   ;Screen begin
  283.         Mov     DX,184Fh                ; and end
  284.         Int     10h
  285.         Ret                             ;Return to DOS
  286.  
  287.         Page
  288. ;
  289. ; Allocate memory for file buffer
  290.  
  291. Init:   Mov     BX,1000h                ;Try for 64K more
  292. GetMem: Mov     AH,48h                  ;Allocate memory
  293.         Int     21h
  294.         Jc      GetMem                  ;Get what there is
  295.  
  296.         Mov     RecAddr,AX              ;Save segment addr
  297.         Mov     AX,BX                   ;Paragraphs available
  298.         Sub     AX,32                   ; less one sector
  299.         Mul     Psize                   ; as bytes available
  300.         Mov     Blksize,AX              ; and as file read size
  301.  
  302.         Call    InitCrt                 ;Get CRT buffer constants
  303.  
  304.         Call    Set1                    ;Display title line
  305.  
  306.         Call    Set25                   ;Display prompt line
  307.  
  308.         Page
  309. ;
  310. ; Extract next logical record for display
  311.  
  312. Read1:  Call    ReadBlk                 ;Load next block
  313.         Mov     BL,Normal
  314.         Mov     Attr,BL
  315.         Jnz     Read2
  316.         Jmp     AtEnd
  317.  
  318. Read2:  Dec     Row                     ;Spot for incomplete record
  319.         Cmp     Numlf,0                 ;record ended in LF?
  320.         Je      GetNext                 ;no, have col/row
  321.         Inc     Row                     ;yes, row stays where it is
  322.         Mov     Col,1                   ; and in column 1
  323.  
  324. GetNext:
  325.         Mov     AX,Index                ;Is record in buffer?
  326.         Cmp     AX,Last
  327.         Jb      GotNext
  328.         Jmp     AtEnd
  329. GotNext:
  330.         Call    ListOne                 ;Display next logical record
  331.         Mov     CX,Reclen
  332.         Add     Col,CL                  ;For end-of-block
  333.         Mov     DH,Row
  334.         Cmp     DH,25                   ;Exceeded screen?
  335.         Jne     TestEor                 ; no, read next record
  336.         Cmp     NumLF,0                 ;Ended in LF?
  337.         Jne     Wait
  338.  
  339. TEstEor:Jmp Read2                       ;End-of-records?
  340.  
  341. Wait:   Mov     AH,0                    ;Wait and read console
  342.         Int     16h
  343.  
  344.         Mov     SI,Offset Spaces        ;Clear prompt line
  345.         Call    Msg25
  346.         Page
  347. ;
  348. ; Process keyboard (command) input
  349.  
  350.         Cmp     AL,27                   ;ESCape to exit?
  351.         Jne     Chk00
  352.         Jmp     Close
  353.  
  354. Chk00:  Cmp     AL,0                    ;Control char?
  355.         Jne     Chk_97                  ; no, a letter
  356.         Xchg    AL,AH                   ; yes, get extended code
  357.         Mov     DI,Offset What2
  358.         Mov     BP,Offset Where2
  359.         Mov     CL,Num2
  360.         Jmp     Short Control
  361.  
  362. Chk_97: Cmp     AL,97                   ;Lower case?
  363.         Jl      Upper
  364.         Sub     AL,32                   ;Yes, make upper
  365.  
  366. Upper:  Mov     DI,Offset What1         ;Letter table
  367.         Mov     BP,Offset Where1        ;Where-to-go list
  368.         Mov     CL,Num1                 ;Number of entries
  369.  
  370. Control:Mov     SI,DI                   ;Find letter/code
  371.         Mov     CH,0                    ;Number in list
  372.         Push    DS
  373.         Pop     ES
  374.         Repnz   Scasb
  375.         Jne     Wait                    ; if not found
  376.         Dec     DI                      ;Point to letter/code
  377.         Sub     DI,SI                   ;Offset into list
  378.         Shl     DI,1                    ; times word size
  379.         Mov     BX,Word Ptr DS:[DI][BP]
  380.         Jmp     BX                      ;Go to routine
  381.  
  382. Right:  Cmp     Scroll,220              ;right arrow
  383.         Jb      Got77
  384.         Jmp     Wait
  385. Got77:  Add     Scroll,20
  386.         Jmp     BackUp
  387.  
  388. Scroll0:Mov     Scroll,0                ;ctrl-left-arrow
  389.         Jmp     BackUp
  390.  
  391. Left:   Cmp     Scroll,0                ;left arrow
  392.         Jne     Got75
  393.         Jmp     Wait
  394. Got75:  Sub     Scroll,20
  395.         Jmp     BackUp
  396.  
  397. Got_Rs: Call    ReScan                  ;F3 for re-scan
  398.         Jmp     NxtPage
  399.  
  400. Got_H:  Call    Help                    ;List key functions
  401.         Call    Back1
  402.         Jmp     Wait
  403.  
  404. strip:    xor    char_msk,080h         ; toggle stripping MSB               -DS
  405.           call   Back1                 ;                                    -DS
  406.           jmp    NxtPage               ;                                    -DS
  407.  
  408. ctrl:     xor    min_disp,020h         ; toggle display of chars 0-31       -DS
  409.           call   Back1                 ;                                    -DS
  410.           jmp    NxtPage               ;                                    -DS
  411.  
  412. Got_S:  Call    Scan                    ;Find text
  413.         Jmp     NxtPage
  414.  
  415.         Page
  416. NxtPage:                                ;Advance to next "page"
  417.         Mov     AX,Index
  418.         Cmp     AX,Last                 ;At end of file?
  419.         Jae     BWait
  420.         Mov     Current,AX
  421.         Mov     DH,2                    ;Restart at row 2
  422.         Mov     Row,DH
  423.         Call    Clear                   ;Clear screen
  424.         Jmp     TestEor
  425.         Page
  426. ; Scroll up one line
  427.  
  428. Up1:    Cmp     First,0                 ;Already at top?
  429.         Jne     Up12                    ; no, scroll up one more
  430. Bwait:  Jmp     AtEnd                   ; yes, ignore it
  431.  
  432. Up12:   Call    Scroll_Up               ;Display down one line
  433.         Mov     AX,Index                ; to empty top line
  434.         Mov     Current,AX              ;Save bottom line ptr
  435.         Mov     AX,First
  436.         Mov     Index,AX
  437.         Call    UpOne
  438.         Mov     Row,2
  439.         Mov     Col,1
  440.         Call    ListOne
  441.         Mov     AX,Current
  442.         Mov     Index,AX
  443.         Call    UpOne
  444.         Jmp     Wait
  445.  
  446. Home:   Mov     Index,0                 ;Restart from top of block
  447.         Jmp     NxtPage
  448.  
  449.  
  450. AtEnd:  Mov     SI,Offset EofMsg        ;say End-of-file
  451.         Call    Msg25
  452.         Jmp     Wait
  453.  
  454. Bottom: Mov     AX,Last                 ;Position to last record
  455.         Mov     Index,AX
  456.         Jmp     BackUp
  457.  
  458. Top:    Sub     CX,CX                   ;Restart
  459.         Mov     AL,0                    ; from beginning
  460.         Sub     DX,DX
  461.         Mov     AH,42h                  ;Reposition file
  462.         Mov     BX,Handle
  463.         Int     21h
  464.         Call    Clear
  465.         Mov     Row,2
  466.         Mov     Col,1
  467.         Mov     First,0
  468.         Mov     Blknum,0
  469.         Jmp     Read1
  470.  
  471. ; Scroll Up one page
  472.  
  473. Back:   Call    Back1                   ;Back up to top of page
  474. BackUp: Call    Back1                   ; or to previous page
  475.         Jmp     Nxtpage
  476.  
  477. ; Scroll down one line
  478.  
  479. Down1:  Mov     AX,Index                ;Current line
  480.         Cmp     AX,Last                 ;At end of file?
  481.         Jb      Down2
  482.         Jmp     AtEnd
  483.  
  484. Down2:  Mov     Current,AX
  485.         Mov     AX,First
  486.         Mov     Index,AX
  487.         Call    GetRec                  ;Set new first ptr
  488.         Mov     AX,Index
  489.  
  490. Down3:  Call    Scroll_Dn               ;Move display up one line
  491.         Mov     AX,Index
  492.         Mov     First,AX
  493.         Mov     AX,Current
  494.         Mov     Index,AX
  495.         Mov     Row,24
  496.         Mov     Col,1
  497.         Jmp     GetNext
  498.  
  499. ; Scroll Up one page
  500.  
  501. Back1   Proc    Near
  502.         Mov     CX,23                   ;Back to current page
  503. Back0:  Call    UpOne
  504.         Loop    Back0
  505.         Mov     Col,1
  506.         Ret
  507. Back1   Endp
  508.  
  509. ; Scroll up one line
  510.  
  511. UpOne   Proc    Near                    ;Position to previous line
  512.         Push    CX
  513.         Mov     CX,2
  514.         Cmp     Index,0                 ;Already at top?
  515.         Je      Up1d                    ; yes, no change
  516. Up1a:   Mov     ES,Recaddr              ;Buffer start
  517. Up1b:   Mov     DI,Index                ;Offset into buffer
  518.         Cmp     ES:Byte Ptr[DI],LF      ;A line feed?
  519.         Je      Up1c
  520.         Dec     Index
  521.         Jnz     Up1b                    ;Out of buffer?
  522. Up1e:   Mov     Index,0                 ; yes, stop at top
  523.         Jmp     Up1d
  524.  
  525. Up1c:   Dec     Index                   ;Passed CR
  526.         Jz      Up1d
  527.         Loop    Up1b
  528.         Inc     Index                   ;Skip over LF
  529. Up1d:   Pop     CX
  530.         Ret
  531. UpOne   Endp
  532.         Page
  533. ;
  534. ;       Place Records into Screen Buffer
  535.  
  536.         Assume  CS:Cseg,DS:Cseg,ES:Nothing
  537. Display Proc    Near
  538.         Push    AX
  539.         Push    BX
  540.         Push    CX                      ;Line length
  541.         Push    DX                      ;Row,col
  542.         Push    DI
  543.         Push    ES
  544.         Push    SI                      ;Addr of record
  545.  
  546.         Sub     AX,AX
  547.         Mov     AL,DH                   ;get row
  548.         Sub     DH,DH
  549.         Mov     DI,DX                   ; and column
  550.         Dec     DI                      ;adjust for zero offset
  551.         Dec     AX
  552.         Cmp     CX,0                    ;Skip null strings
  553.         Jng     Dsp9
  554.         Cmp     CX,80                   ;Can only display 80
  555.         Jbe     Dsp1                    ; cols at a time
  556.         Mov     CX,80
  557.  
  558. Dsp1:   Mul     Crt_Col                 ;AX = row * chars per line
  559.         Add     DI,AX                   ;DI = chars from start of screen
  560.         Shl     DI,1                    ;adjust for attribute bytes
  561.  
  562.         Mov     DX,Crt_Prt              ;Addr of card status port
  563.         Mov     ES,Crt_Buf              ;Addr of display buffer
  564.  
  565.         Mov     BH,Attr                 ;Display attribute
  566. Dsp2:   Lodsb                           ;Next character
  567. dsp2a:  Cmp     AL,min_disp            ;Don't bother with chars < min_disp -DS
  568.         Jae     Dsp3                   ;                                   -DS
  569.         Jmp     Dsp4                   ;                                   -DS
  570.  
  571. Dsp3:   Mov     BL,AL                   ;Char and attr
  572.         Call    Displa
  573. Dsp4:   Loop    Dsp2
  574.  
  575. Dsp9:   Pop     SI
  576.         Pop     ES
  577.         Pop     DI
  578.         Pop     DX
  579.         Pop     CX
  580.         Pop     BX
  581.         Pop     AX
  582.         Ret
  583.  
  584. ;  Wait for horzontal retrace
  585.  
  586. Displa: In      AL,DX                   ;Port status
  587.         Test    AL,1                    ;Is it low?
  588.         Jnz     Displa                  ; no, keep checking
  589.         Cli                             ; yes, turn off interrupts
  590. Disphi: In      AL,DX                   ;Get status
  591.         Test    AL,1                    ;Is it high?
  592.         Jz      Disphi                  ; no, keep checking
  593.  
  594.         Mov     AX,BX                   ;Attrib and char
  595.         Stosw                           ; to display buffer
  596.         Sti
  597.         Ret
  598.  
  599. Display Endp
  600.         Page
  601. ;
  602. ; Display next logical record
  603.  
  604. ListOne Proc    Near
  605.         Cmp     Row,2
  606.         Jne     List1
  607.         Mov     AX,Index
  608.         Mov     First,AX                ;Ptr to current top line
  609. List1:  Call    GetRec                  ;Return logical record
  610.         Mov     CX,Reclen               ;Record size
  611.         Sub     CL,Numlf                ; less LF
  612.         Sub     CL,Numcr                ; less CR
  613.         Mov     Reclen,CX
  614.         Or      CX,CX                   ;blank line?
  615.         Jz      List9                   ;yes, increment row only
  616.  
  617.         Mov     SI,Offset Work          ;Addr of record
  618.         Cmp     Row,2                   ;Is row valid?
  619.         Jae     List2
  620.         Mov     Row,2
  621. List2:  Mov     DH,Row                  ;destination row
  622.         Mov     DL,Col                  ; and column
  623.         Add     SI,Scroll
  624.         Sub     CX,Scroll
  625.         Call    Display                 ;put into screen buffer
  626.  
  627. List9:  Inc     Row                     ;Bump to next row
  628.         Mov     BL,Normal               ; restore attribute
  629.         Mov     Attr,BL
  630.         Ret
  631. ListOne Endp
  632.         Page
  633. ;
  634. ;       GetRec - Extract next logical record
  635. ;
  636. ; Scan the buffer for special characters and copy wanted
  637. ; data to field WORK. A logical record ends in an LF and/or CR.
  638. ; Tabs are expanded and x'0F' is deleted.
  639.  
  640. GetRec  Proc    Near
  641.         Push    ES
  642.         Push    CX
  643.         Push    SI
  644.         Push    DI
  645.  
  646. GetR:   Test    Switch1,Eor             ;Found end of file?
  647.         Jz      GetR0
  648.         Mov     AX,Last                 ; yes, set ptr to EOF
  649.         Mov     Index,AX
  650.         Call    ReadBlk                 ;Try for next block
  651.         Jnz     GetR0
  652.         Jmp     GetRd
  653.  
  654. GetR0:  Sub     DI,DI                   ;Record size/output offset
  655.         Mov     Word Ptr NumLF,DI       ;zero NUMLF and NUMCR
  656.         And     Switch2,0FFh-Nodata
  657.         Mov     ES,RecAddr              ;Set buffer segment addr
  658.  
  659. GetR2:  Mov     SI,Index                ;Current input offset
  660.         Mov     AL,ES:[SI]              ;Copy a char
  661.         Cmp     AL,Eof                  ;End of file?
  662.         Jne     GetR3
  663.         Mov     Reclen,DI
  664.         Or      Switch1,Eor             ;Indicate end-of-file
  665.         Jmp     GetR
  666.  
  667. GetR3:  And     AL,char_msk             ;mask character                    -DS
  668.         Cmp     AL,09h                  ;Is it TAB?
  669.         Jne     GetR4
  670.         Mov     CX,DI                   ;Current work size
  671.         Add     CX,8                    ;Round to 8-bytes
  672.         And     CX,0FFF8h
  673.         Sub     CX,DI                   ;Number of blanks
  674. GetR3b: Mov     Work[DI],' '            ; to insert
  675.         Inc     DI
  676.         Loop    GetR3b
  677.         Inc     Index                   ;Bump input offset
  678.         Jmp     GetR2                   ; and get next char
  679.  
  680. GetR4:                                  ;                                  -DS
  681.         Mov     Work[DI],AL             ;Copy character
  682.         Inc     DI                      ;Incr output offset
  683.         Inc     Index                   ; and input offset
  684.         Cmp     AL,Cr                   ;Is it a CR?
  685.         Jne     GetR5
  686.         Inc     NumCR                   ;Yes, incr count
  687.         cmp     ES:byte ptr[SI+1],LF    ;patch for records that end        -DS
  688.         je      GetR6                  ; in CR only                        -DS
  689.         mov     byte ptr work[di-1],LF ;                                   -DS
  690.         dec     NumCR                  ;                                   -DS
  691.         Inc     NumLF                  ;                                   -DS
  692.         Jmp     GetR8                  ;                                   -DS
  693.  
  694. GetR5:  Cmp     AL,' '
  695.         Je      GetR7
  696.         Cmp     AL,Lf                   ;Is it line feed?
  697.         Jne     GetR6
  698.         Inc     NumLF                   ;Yes, incr count
  699.         Jmp     GetR8
  700.  
  701. GetR6:  Or      Switch2,Nodata          ;Non-space found
  702.  
  703. GetR7:  Cmp     DI,255                  ;Record too big?
  704.         Je      GetR8                   ;Chop record at 255 bytes
  705.         Jmp     GetR2
  706.  
  707. GetR8:  Mov     Reclen,DI
  708.         Cmp     Work,0Fh                ;If record begins with "sun"
  709.         Jne     GetR9                   ; symbol, skip it
  710.         Jmp     GetR0
  711.  
  712. GetR9:  Test    Switch2,Nodata          ;If all blank
  713.         Jnz     GetRd
  714.         Jmp     GetR0                   ; read another one
  715.  
  716. GetRd:  Pop     DI
  717.         Pop     SI
  718.         Pop     CX
  719.         Pop     ES
  720.         Ret
  721. GetRec Endp
  722.  
  723.         Page
  724. ;
  725. ; Read a block
  726.  
  727. ReadBlk Proc    Near
  728.         Mov     Switch1,0               ;reset EOR flag
  729.         Mov     BX,Handle               ;get file handle from open
  730.         Mov     CX,Blksize              ;bytes to read
  731.         Push    DS
  732.         Mov     DS,RecAddr              ;addr of gotten memory
  733.         Sub     DX,DX                   ; with zero offset
  734.         Mov     AH,3Fh
  735.         Int     21H                     ;read a block
  736.         Pop     DS
  737.  
  738.         Or      AX,AX                   ;Any bytes read?
  739.         Jz      ReadB2                  ; no, return with ZF
  740.         Mov     Last,AX                 ; yes, set record pointers
  741.         Mov     Index,0
  742.         Mov     First,0
  743.         Mov     Current,0
  744.         Inc     Blknum
  745.         Mov     DI,Last                 ;Append EOF to buffer
  746.         Mov     ES,RecAddr
  747.         Mov     Byte Ptr ES:[DI],1Ah
  748. ReadB2: Ret
  749. Readblk Endp
  750.  
  751.         Page
  752. ;
  753. ; Scan for text entered after slash (/)
  754.  
  755. ReScan  Proc
  756.         Push    DI
  757.         Push    SI
  758.         Push    DS
  759.         Pop     ES
  760.         Jmp     Scan1
  761.  
  762. Scan:   Push    DI
  763.         Push    SI
  764.         Push    DS
  765.         Pop     ES
  766.         Mov     TextMax,32              ;Max string length
  767.         Mov     DX,Offset TextMax
  768.         Mov     AH,0Ah                  ;Read console
  769.         Int     21h
  770.  
  771. Scan1:  Sub     CX,CX
  772.         Or      CL,TextLen              ;Get and test length
  773.         Jz      NoMatch                 ; none, return as is
  774.         Mov     AX,First                ;Start with current screen
  775.         Mov     Index,AX
  776.         Call    GetRec                  ;Skip top line
  777.  
  778. Scan3:  Call    GetRec                  ;Read next logical record
  779.         Test    Switch1,Eor             ;End of data?
  780.         Jnz     NoMatch                 ; yes, NOT FOUND
  781.         Mov     AX,Index                ;Current record ptr
  782.         Cmp     AX,Last                 ;Beyond buffer?
  783.         Jae     NoMatch                 ; yes, NOT FOUND
  784.         Mov     CX,RecLen
  785.         Sub     CL,TextLen              ;Columns to search
  786.         Jle     Scan3
  787.  
  788.         Mov     AL,TextBuf              ;Scan for first char in record
  789.         Mov     DI,Offset Work          ;Current record data
  790.         Repnz   Scasb
  791.         Jne     Scan3                   ; not found
  792.         Cmp     TextLen,1               ;Whole thing done?
  793.         Je      Match
  794.         Sub     CH,CH
  795.         Mov     CL,TextLen              ;Search for rest of it
  796.         Dec     CL
  797.         Mov     SI,Offset TextBuf+1
  798.         Repe    Cmpsb
  799.         Jne     Scan3
  800.         Or      CX,CX                   ;Found it?
  801.         Jnz     Scan3                   ; no, try next record
  802.  
  803. Match:  Call    Set25                   ;Restore prompt line
  804.         Mov     Attr,Blink              ; and blink
  805.         Call    UpOne
  806.         Jmp     Scaned
  807.  
  808. NoMatch:Mov     AX,First                ;Not found,
  809.         Mov     Index,AX                ; restart at last page
  810.         Call    Set25                   ;Restore prompt line
  811.  
  812.         Mov     SI,Offset TextMsg       ;Say TEXT NOT FOUND
  813.         Add     Special,128             ;Make it blink
  814.         Call    Msg25
  815.         Sub     Special,128
  816.         Mov     Switch1,0
  817.         Mov     Col,1
  818.  
  819. Scaned: Pop     SI
  820.         Pop     DI
  821.         Ret
  822. ReScan  Endp
  823.         Page
  824. ;
  825. ; Clear screen or records window
  826.  
  827. Clear   Proc    Near                    ;Clear entire screen
  828.         Push    AX
  829.         Push    BX
  830.         Push    CX
  831.         Push    DX
  832.  
  833.         Mov     AX,0600h
  834.         Mov     BH,Foregrd
  835.         Jmp     Scroller
  836.  
  837. Scroll_Dn:                              ;Scroll list window down
  838.         Push    AX
  839.         Push    BX
  840.         Push    CX
  841.         Push    DX
  842.  
  843.         Mov     AX,0601h
  844.         Mov     BH,Foregrd
  845.         Jmp     Scroller
  846.  
  847. Scroll_Up:                              ;Scroll list window up
  848.         Push    AX
  849.         Push    BX
  850.         Push    CX
  851.         Push    DX
  852.  
  853.         Mov     AX,0701h
  854.         Mov     BH,Foregrd
  855. Scroller:
  856.         Mov     CX,0100h                ;Screen begin
  857.         Mov     DX,174Fh                ; and end
  858.         Int     10h
  859.  
  860.         Pop     DX
  861.         Pop     CX
  862.         Pop     BX
  863.         Pop     AX
  864.         Ret
  865. Clear   Endp
  866.         Page
  867. ;
  868. ;       Set top title line
  869.  
  870. Set1    Proc    Near
  871.         Mov     AX,0600h                ;Clear the screen
  872.         Sub     BL,BL
  873.         Mov     BH,Foregrd
  874.         Sub     CX,CX                   ;Screen begin
  875.         Mov     DX,184Fh                ; and end
  876.         Int     10h
  877.  
  878.         Mov     Word Ptr Work+5,0000h   ;Title in work area                 -DS
  879.         Mov     DH,1                    ;Row 1
  880.         Mov     DL,DH                   ;Column 1
  881.         Mov     SI,Offset Work
  882.         Mov     CX,79                   ;Length
  883.         Mov     BL,Special              ;Hi-intensity or yellow
  884.         Mov     Attr,BL
  885.         Call    Display
  886.         Ret
  887. Set1    Endp
  888.  
  889. ;       Set prompt line
  890.  
  891. Set25   Proc    Near
  892.         Push    DI
  893.         Push    SI
  894.         Mov     DH,25                   ;set row
  895.         Mov     DL,1                    ; and column
  896.         Mov     CX,Pr_Len               ; length
  897.         Mov     BL,Special
  898.         Mov     Attr,BL
  899.         Mov     SI,Offset Prompt
  900.         Call    Display
  901.  
  902.         Mov     AH,2                    ;Set cursor position
  903.         Mov     DX,1808h                ; to row 25, col 9
  904.         Mov     BX,0                    ; page zero
  905.         Int     10H
  906.         Pop     SI
  907.         Pop     DI
  908.         Ret
  909. Set25   Endp
  910.  
  911. ;       Display message on prompt line
  912.  
  913. Msg25   Proc    Near                    ;SI - Ptr to msg text
  914.         Mov     DH,25                   ;Clear message area
  915.         Mov     DL,10                   ; its column
  916.         Mov     CX,EofLen               ; length
  917.         Mov     BL,Special              ;Hi-intensity or yellow
  918.         Mov     Attr,BL
  919.         Call    Display
  920.         Mov     BL,Normal
  921.         Mov     Attr,BL
  922.         Ret
  923. Msg25   Endp
  924.  
  925. ;
  926. ; Initialize display constants
  927.  
  928. InitCrt Proc    Near
  929.         Push    ES
  930.         Mov     AX,Bios                 ;Point to BIOS data
  931.         Mov     ES,AX
  932.         Mov     CX,ES:Cols              ;Save display columns
  933.         Mov     Crt_Col,CX
  934.         Mov     DX,ES:A6845             ;Save card base addr
  935.         Add     DX,6                    ; point to status port
  936.         Mov     Crt_Prt,DX
  937.         Mov     Crt_Buf,0B800h          ;Default to color card
  938.         Mov     BX,ES:Flag
  939.         And     BX,30h
  940.         Cmp     BX,30h                  ;Is it mono card?
  941.         Jne     CrtSet                  ; no, set for color
  942.         Mov     Crt_Buf,0B000h          ; yes, point to mono buffer
  943. CrtSet: Pop     ES
  944.         Ret
  945. InitCrt Endp
  946.         Page
  947. ;
  948. ; HELP - Display command key usage
  949.  
  950. Help    Proc    Near                    ;Describe the commands
  951.         Call    Clear
  952.         Mov     DX,0200h                ;Position cursor
  953.         Mov     AH,2
  954.         Sub     BH,BH
  955.         Mov     BL,Foregrd
  956.         Int     10h
  957.         Mov     DX,Offset HelpMsg       ;List the text lines
  958.         Mov     AH,9
  959.         Int     21h
  960.         Mov     AH,2                    ;restore position
  961.         Mov     DX,1808h                ; to row 25, col 9
  962.         Sub     BX,BX
  963.         Int     10H
  964.         Ret
  965. Help    Endp
  966.         Page
  967. ;
  968. ; Get file name from command line
  969.  
  970. GetParm Proc    Near
  971.         Xor     AX,AX                   ;For COM, CS=DS=ES
  972.         Xor     CX,CX
  973.         Mov     AL,Byte Ptr DS:[80h]    ;Gather file name from command line
  974.         Or      CX,AX                   ;Any supplied?
  975.         Jz      GetFile                 ; no, ask for it
  976.         Mov     DI,Offset Filenm        ; yes, point to target
  977.         Mov     SI,81h                  ;Offset to parm in PSP
  978. Blanks: Lodsb
  979.         Cmp     AL,' '                  ;Skip any blanks
  980.         Je      Skipit
  981.         Stosb                           ;Copy parm to FileNm
  982. Skipit: Loop    Blanks
  983.         Ret
  984.  
  985. GetFile:
  986.         Mov     DX,Offset AskFile       ;Prompt for file name
  987.         Mov     AH,9
  988.         Int     21H
  989.         Mov     AH,0AH                  ;Buffered kybd input DOS req
  990.         Mov     DX,Offset Keyin
  991.         Int     21h
  992.  
  993.         Sub     BL,BL
  994.         Or      BL,Keyout               ;Number of chars read
  995.         Jz      GetFile                 ; none, ask for name
  996.         Mov     Filenm[BX],0            ;Overlay CR to make ASCIIZ name
  997.         Ret
  998. GetParm Endp
  999.  
  1000. ;  Open the file to list
  1001.  
  1002. Open    Proc    Near
  1003.         Mov     OpenCod,0               ;Reset open return code
  1004.         Mov     DX,Offset Filenm        ;OPEN file
  1005.         Mov     AL,0                    ; for read only
  1006.         Mov     AH,3DH
  1007.         Int     21H
  1008.         Mov     Handle,AX               ;save file handle
  1009.         Jnc     Opened                  ;if OPEN okay
  1010.  
  1011.         Mov     OpenCod,AX
  1012.         Cmp     AL,2                    ;Check code to be
  1013.         Jl      Error                   ; within our messages
  1014.         Cmp     AL,5
  1015.         Ja      Error
  1016.         Sub     BX,BX                   ;For message index
  1017.         Mov     BL,AL
  1018.         Mov     CL,4
  1019.         Shl     BX,CL
  1020.         Lea     DX,Code2-32[BX]         ;Point to msg text
  1021.         Jmp     Error2
  1022.  
  1023. Error:  Aam                             ;Other return codes
  1024.         Xchg    AL,AH
  1025.         Or      OpenCod,AX
  1026.         Mov     DX,Offset OpenMsg
  1027.  
  1028. Error2: Mov     AH,9
  1029.         Int     21H                     ;say OPEN FAILED
  1030. Opened: Cmp     OpenCod,0
  1031.         Ret
  1032. Open    Endp
  1033.  
  1034. List    Endp
  1035.  
  1036. PgmSize Equ     ($-Cseg+16)/16          ;Program size in paragraphs
  1037.  
  1038. cseg    ends
  1039.         end     List
  1040.  
  1041.